diff mbox series

[ovs-dev,2/3] netdev-afxdp: Avoid removing of XDP program if not loaded.

Message ID 20191207144618.14124-3-i.maximets@ovn.org
State Accepted
Delegated to: Ilya Maximets
Headers show
Series dpif-netdev: Avoid infinite re-addition of misconfigured ports. | expand

Commit Message

Ilya Maximets Dec. 7, 2019, 2:46 p.m. UTC
'bpf_set_link_xdp_fd' generates netlink event regardless of actual
changes it does, so if-notifier will receive link update even if
there was no XDP program previously loaded on the interface.

OVS tries to remove XDP program if device configuration was not
successful triggering if-notifier that triggers bridge reconfiguration
and another attempt to add failed port.  And so on in the infinite
loop.

This patch avoids the issue by not removing XDP program if it wasn't
loaded.  Since loading of the XDP program is one of the last steps
of port configuration, this should help to avoid infinite re-addition
for most types of misconfiguration.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 lib/netdev-afxdp.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

William Tu Dec. 9, 2019, 8:44 p.m. UTC | #1
On Sat, Dec 07, 2019 at 03:46:17PM +0100, Ilya Maximets wrote:
> 'bpf_set_link_xdp_fd' generates netlink event regardless of actual
> changes it does, so if-notifier will receive link update even if
> there was no XDP program previously loaded on the interface.
> 
> OVS tries to remove XDP program if device configuration was not
> successful triggering if-notifier that triggers bridge reconfiguration
> and another attempt to add failed port.  And so on in the infinite
> loop.
> 
> This patch avoids the issue by not removing XDP program if it wasn't
> loaded.  Since loading of the XDP program is one of the last steps
> of port configuration, this should help to avoid infinite re-addition
> for most types of misconfiguration.
> 
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Thanks! this also fixes the issue reported from Eelco
about infinite loop when enable loading XDP program at
https://patchwork.ozlabs.org/patch/1199734/

Acked-by: William Tu <u9012063@gmail.com>

> ---
>  lib/netdev-afxdp.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c
> index ca2dfd005..bdabf97f4 100644
> --- a/lib/netdev-afxdp.c
> +++ b/lib/netdev-afxdp.c
> @@ -710,6 +710,19 @@ static void
>  xsk_remove_xdp_program(uint32_t ifindex, enum afxdp_mode mode)
>  {
>      uint32_t flags = xdp_modes[mode].xdp_flags | XDP_FLAGS_UPDATE_IF_NOEXIST;
> +    uint32_t ret, prog_id = 0;
> +
> +    /* Check whether XDP program is loaded. */
> +    ret = bpf_get_link_xdp_id(ifindex, &prog_id, flags);
> +    if (ret) {
> +        VLOG_ERR("Failed to get XDP prog id (%s)", ovs_strerror(errno));
> +        return;
> +    }
> +
> +    if (!prog_id) {
> +        VLOG_INFO("No XDP program is loaded at ifindex %d", ifindex);
> +        return;
> +    }
>  
>      bpf_set_link_xdp_fd(ifindex, -1, flags);
>  }
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c
index ca2dfd005..bdabf97f4 100644
--- a/lib/netdev-afxdp.c
+++ b/lib/netdev-afxdp.c
@@ -710,6 +710,19 @@  static void
 xsk_remove_xdp_program(uint32_t ifindex, enum afxdp_mode mode)
 {
     uint32_t flags = xdp_modes[mode].xdp_flags | XDP_FLAGS_UPDATE_IF_NOEXIST;
+    uint32_t ret, prog_id = 0;
+
+    /* Check whether XDP program is loaded. */
+    ret = bpf_get_link_xdp_id(ifindex, &prog_id, flags);
+    if (ret) {
+        VLOG_ERR("Failed to get XDP prog id (%s)", ovs_strerror(errno));
+        return;
+    }
+
+    if (!prog_id) {
+        VLOG_INFO("No XDP program is loaded at ifindex %d", ifindex);
+        return;
+    }
 
     bpf_set_link_xdp_fd(ifindex, -1, flags);
 }