diff mbox series

[net-next,2/2] veth: fix double napi enable

Message ID b90034c61b939d18cd7a201c547fb7ddffc91231.1668727939.git.pabeni@redhat.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series veth: a couple of fixes | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: davem@davemloft.net; 7 maintainers not CCed: hawk@kernel.org davem@davemloft.net edumazet@google.com daniel@iogearbox.net kuba@kernel.org ast@kernel.org john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Paolo Abeni Nov. 17, 2022, 11:33 p.m. UTC
While investigating a related issue I stumbled upon another
oops, reproducible as the follow:

ip link add type veth
ip link set dev veth0 xdp object <obj>
ip link set dev veth0 up
ip link set dev veth1 up

The first link up command will enable the napi instances on
veth1 and the second link up common will try again the same
operation, causing the oops.

This change addresses the issue explicitly checking the peer
is up before enabling its napi instances.

Fixes: 2e0de6366ac1 ("veth: Avoid drop packets when xdp_redirect performs")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 drivers/net/veth.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Heng Qi Nov. 18, 2022, 2:24 p.m. UTC | #1
> While investigating a related issue I stumbled upon another
> oops, reproducible as the follow:
>
> ip link add type veth
> ip link set dev veth0 xdp object <obj>
> ip link set dev veth0 up
> ip link set dev veth1 up
>
> The first link up command will enable the napi instances on
> veth1 and the second link up common will try again the same
> operation, causing the oops.
>
> This change addresses the issue explicitly checking the peer
> is up before enabling its napi instances.
>
> Fixes: 2e0de6366ac1 ("veth: Avoid drop packets when xdp_redirect performs")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
>  drivers/net/veth.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 1384134f7100..d541183e0c66 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -1343,7 +1343,8 @@ static int veth_open(struct net_device *dev)
> 		if (err)
>  			return err;
>  		/* refer to the logic in veth_xdp_set() */
> -		if (!rtnl_dereference(peer_rq->napi)) {
> +		if (!rtnl_dereference(peer_rq->napi) &&
> +		    (peer->flags & IFF_UP)) {
>  			err = veth_napi_enable(peer);
>  			if (err)
>  				return err;

I have checked the conditions related to enabling and disabling napi for
veth pair. In general, we should check whether napi is disabled before
enabling it, and check whether napi is enabled before disabling it. I am
sorry that my previous test cases didn't do better, and we can work
completely with your patchset. As the your patch in link below does
https://lore.kernel.org/all/c59f4adcdd1296ee37cc6bca4d927b8c79158909.1668727939.git.pabeni@redhat.com/

Is this patch more uniform like the following:

--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1348,7 +1348,8 @@ static int veth_open(struct net_device *dev)
                        if (err)
                                return err;
                }
-       } else if (veth_gro_requested(dev) || peer_priv->_xdp_prog) {
+       } else if ((veth_gro_requested(dev) || peer_priv->_xdp_prog) &&
+                   !rtnl_dereference(priv->rq[0].napi)) {
                err = veth_napi_enable(dev);
                if (err)
                        return err;

Thanks.
diff mbox series

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 1384134f7100..d541183e0c66 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1343,7 +1343,8 @@  static int veth_open(struct net_device *dev)
 		if (err)
 			return err;
 		/* refer to the logic in veth_xdp_set() */
-		if (!rtnl_dereference(peer_rq->napi)) {
+		if (!rtnl_dereference(peer_rq->napi) &&
+		    (peer->flags & IFF_UP)) {
 			err = veth_napi_enable(peer);
 			if (err)
 				return err;