diff mbox series

[net] tun: Fix xdp_rxq_info's queue_index when detaching

Message ID 1708398727-46308-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Accepted
Commit 2a770cdc4382b457ca3d43d03f0f0064f905a0d0
Delegated to: Netdev Maintainers
Headers show
Series [net] tun: Fix xdp_rxq_info's queue_index when detaching | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 956 this patch: 956
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 2 blamed authors not CCed: ast@kernel.org hawk@kernel.org; 7 maintainers not CCed: pabeni@redhat.com ast@kernel.org daniel@iogearbox.net john.fastabend@gmail.com edumazet@google.com bpf@vger.kernel.org hawk@kernel.org
netdev/build_clang success Errors and warnings before: 973 this patch: 973
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
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: 973 this patch: 973
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-23--03-00 (tests: 1457)

Commit Message

wangyunjian Feb. 20, 2024, 3:12 a.m. UTC
When a queue(tfile) is detached, we only update tfile's queue_index,
but do not update xdp_rxq_info's queue_index. This patch fixes it.

Fixes: 8bf5c4ee1889 ("tun: setup xdp_rxq_info")
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/tun.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Willem de Bruijn Feb. 20, 2024, 3:59 p.m. UTC | #1
Yunjian Wang wrote:
> When a queue(tfile) is detached, we only update tfile's queue_index,
> but do not update xdp_rxq_info's queue_index. This patch fixes it.
> 
> Fixes: 8bf5c4ee1889 ("tun: setup xdp_rxq_info")
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/tun.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index bc80fc1d576e..be37235af55d 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -652,6 +652,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
>  				   tun->tfiles[tun->numqueues - 1]);
>  		ntfile = rtnl_dereference(tun->tfiles[index]);
>  		ntfile->queue_index = index;
> +		ntfile->xdp_rxq.queue_index = index;
>  		rcu_assign_pointer(tun->tfiles[tun->numqueues - 1],
>  				   NULL);

Does it matter that this value is stale when undetached?

It is replaced in tun_attach if previously attached:

		/* Re-attach detached tfile, updating XDP queue_index */
                WARN_ON(!xdp_rxq_info_is_reg(&tfile->xdp_rxq));

                if (tfile->xdp_rxq.queue_index    != tfile->queue_index)
                        tfile->xdp_rxq.queue_index = tfile->queue_index;
wangyunjian Feb. 21, 2024, 2:40 a.m. UTC | #2
> -----Original Message-----
> From: Willem de Bruijn [mailto:willemdebruijn.kernel@gmail.com]
> Sent: Tuesday, February 20, 2024 11:59 PM
> To: wangyunjian <wangyunjian@huawei.com>;
> willemdebruijn.kernel@gmail.com; jasowang@redhat.com; kuba@kernel.org;
> davem@davemloft.net
> Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
> brouer@redhat.com; xudingke <xudingke@huawei.com>; wangyunjian
> <wangyunjian@huawei.com>
> Subject: Re: [PATCH net] tun: Fix xdp_rxq_info's queue_index when detaching
> 
> Yunjian Wang wrote:
> > When a queue(tfile) is detached, we only update tfile's queue_index,
> > but do not update xdp_rxq_info's queue_index. This patch fixes it.
> >
> > Fixes: 8bf5c4ee1889 ("tun: setup xdp_rxq_info")
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  drivers/net/tun.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/tun.c b/drivers/net/tun.c index
> > bc80fc1d576e..be37235af55d 100644
> > --- a/drivers/net/tun.c
> > +++ b/drivers/net/tun.c
> > @@ -652,6 +652,7 @@ static void __tun_detach(struct tun_file *tfile, bool
> clean)
> >  				   tun->tfiles[tun->numqueues - 1]);
> >  		ntfile = rtnl_dereference(tun->tfiles[index]);
> >  		ntfile->queue_index = index;
> > +		ntfile->xdp_rxq.queue_index = index;
> >  		rcu_assign_pointer(tun->tfiles[tun->numqueues - 1],
> >  				   NULL);
> 
> Does it matter that this value is stale when undetached?

Yes, the detach tfile'queue_index is not important because the re-attach will update.
But this patch is to fix the 'ntfile'(that replaces the detach tfile)'s queue_index, it is wrong.

Thanks
> 
> It is replaced in tun_attach if previously attached:
> 
> 		/* Re-attach detached tfile, updating XDP queue_index */
>                 WARN_ON(!xdp_rxq_info_is_reg(&tfile->xdp_rxq));
> 
>                 if (tfile->xdp_rxq.queue_index    != tfile->queue_index)
>                         tfile->xdp_rxq.queue_index = tfile->queue_index;
Willem de Bruijn Feb. 21, 2024, 3:03 p.m. UTC | #3
wangyunjian wrote:
> 
> 
> > -----Original Message-----
> > From: Willem de Bruijn [mailto:willemdebruijn.kernel@gmail.com]
> > Sent: Tuesday, February 20, 2024 11:59 PM
> > To: wangyunjian <wangyunjian@huawei.com>;
> > willemdebruijn.kernel@gmail.com; jasowang@redhat.com; kuba@kernel.org;
> > davem@davemloft.net
> > Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org;
> > brouer@redhat.com; xudingke <xudingke@huawei.com>; wangyunjian
> > <wangyunjian@huawei.com>
> > Subject: Re: [PATCH net] tun: Fix xdp_rxq_info's queue_index when detaching
> > 
> > Yunjian Wang wrote:
> > > When a queue(tfile) is detached, we only update tfile's queue_index,
> > > but do not update xdp_rxq_info's queue_index. This patch fixes it.
> > >
> > > Fixes: 8bf5c4ee1889 ("tun: setup xdp_rxq_info")
> > > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > > ---
> > >  drivers/net/tun.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c index
> > > bc80fc1d576e..be37235af55d 100644
> > > --- a/drivers/net/tun.c
> > > +++ b/drivers/net/tun.c
> > > @@ -652,6 +652,7 @@ static void __tun_detach(struct tun_file *tfile, bool
> > clean)
> > >  				   tun->tfiles[tun->numqueues - 1]);
> > >  		ntfile = rtnl_dereference(tun->tfiles[index]);
> > >  		ntfile->queue_index = index;
> > > +		ntfile->xdp_rxq.queue_index = index;
> > >  		rcu_assign_pointer(tun->tfiles[tun->numqueues - 1],
> > >  				   NULL);
> > 
> > Does it matter that this value is stale when undetached?
> 
> Yes, the detach tfile'queue_index is not important because the re-attach will update.
> But this patch is to fix the 'ntfile'(that replaces the detach tfile)'s queue_index, it is wrong.

Oh yes. This looks correct to me. Let's cc: the author of the patch listed as Fixed too.

> 
> Thanks
> > 
> > It is replaced in tun_attach if previously attached:
> > 
> > 		/* Re-attach detached tfile, updating XDP queue_index */
> >                 WARN_ON(!xdp_rxq_info_is_reg(&tfile->xdp_rxq));
> > 
> >                 if (tfile->xdp_rxq.queue_index    != tfile->queue_index)
> >                         tfile->xdp_rxq.queue_index = tfile->queue_index;
patchwork-bot+netdevbpf@kernel.org Feb. 24, 2024, 12:30 a.m. UTC | #4
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 20 Feb 2024 11:12:07 +0800 you wrote:
> When a queue(tfile) is detached, we only update tfile's queue_index,
> but do not update xdp_rxq_info's queue_index. This patch fixes it.
> 
> Fixes: 8bf5c4ee1889 ("tun: setup xdp_rxq_info")
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/tun.c | 1 +
>  1 file changed, 1 insertion(+)

Here is the summary with links:
  - [net] tun: Fix xdp_rxq_info's queue_index when detaching
    https://git.kernel.org/netdev/net/c/2a770cdc4382

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index bc80fc1d576e..be37235af55d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -652,6 +652,7 @@  static void __tun_detach(struct tun_file *tfile, bool clean)
 				   tun->tfiles[tun->numqueues - 1]);
 		ntfile = rtnl_dereference(tun->tfiles[index]);
 		ntfile->queue_index = index;
+		ntfile->xdp_rxq.queue_index = index;
 		rcu_assign_pointer(tun->tfiles[tun->numqueues - 1],
 				   NULL);