diff mbox series

[net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info

Message ID 20241126134707.253572-2-mail@tk154.de (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present fail Series targets non-next tree, but doesn't contain any Fixes tags
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 13 maintainers not CCed: kuba@kernel.org bpf@vger.kernel.org ast@kernel.org linux-arm-kernel@lists.infradead.org john.fastabend@gmail.com daniel@iogearbox.net hawk@kernel.org linux-mediatek@lists.infradead.org matthias.bgg@gmail.com pabeni@redhat.com edumazet@google.com andrew+netdev@lunn.ch angelogioacchino.delregno@collabora.com
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 11 this patch: 11
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-11-29--03-00 (tests: 792)

Commit Message

Til Kaiser Nov. 26, 2024, 1:41 p.m. UTC
Currently, the network device isn't set inside the xdp_rxq_info
of the mtk_rx_ring, which means that an XDP program attached to
the Mediathek ethernet driver cannot retrieve the index of the
interface that received the package since it's always 0 inside
the xdp_md struct.

This patch sets the network device pointer inside the
xdp_rxq_info struct, which is later used to initialize
the xdp_buff struct via xdp_init_buff.

This was tested using the following eBPF/XDP program attached
to a network interface of the mtk_eth_soc driver. As said before,
ingress_ifindex always had a value of zero. After applying the
patch, ingress_ifindex holds the correct interface index.

	#include <linux/bpf.h>
	#include <bpf/bpf_helpers.h>

	SEC("pass")
	int pass_func(struct xdp_md *xdp) {
    		bpf_printk("ingress_ifindex: %u",
			xdp->ingress_ifindex);

		return XDP_PASS;
	}

	char _license[] SEC("license") = "GPL";

Signed-off-by: Til Kaiser <mail@tk154.de>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Lorenzo Bianconi Nov. 26, 2024, 6:16 p.m. UTC | #1
> Currently, the network device isn't set inside the xdp_rxq_info
> of the mtk_rx_ring, which means that an XDP program attached to
> the Mediathek ethernet driver cannot retrieve the index of the
> interface that received the package since it's always 0 inside
> the xdp_md struct.
> 
> This patch sets the network device pointer inside the
> xdp_rxq_info struct, which is later used to initialize
> the xdp_buff struct via xdp_init_buff.
> 
> This was tested using the following eBPF/XDP program attached
> to a network interface of the mtk_eth_soc driver. As said before,
> ingress_ifindex always had a value of zero. After applying the
> patch, ingress_ifindex holds the correct interface index.
> 
> 	#include <linux/bpf.h>
> 	#include <bpf/bpf_helpers.h>
> 
> 	SEC("pass")
> 	int pass_func(struct xdp_md *xdp) {
>     		bpf_printk("ingress_ifindex: %u",
> 			xdp->ingress_ifindex);
> 
> 		return XDP_PASS;
> 	}
> 
> 	char _license[] SEC("license") = "GPL";
> 
> Signed-off-by: Til Kaiser <mail@tk154.de>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 53485142938c..9c6d4477e536 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2069,6 +2069,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
>  
>  		netdev = eth->netdev[mac];
>  		ppe_idx = eth->mac[mac]->ppe_idx;
> +		ring->xdp_q.dev = netdev;

I guess you can set it just before running xdp_init_buff(), but the change is fine.

Regards,
Lorenzo

>  
>  		if (unlikely(test_bit(MTK_RESETTING, &eth->state)))
>  			goto release_desc;
> -- 
> 2.47.1
> 
>
Ido Schimmel Nov. 27, 2024, 1:31 p.m. UTC | #2
On Tue, Nov 26, 2024 at 07:16:00PM +0100, Lorenzo Bianconi wrote:
> > Currently, the network device isn't set inside the xdp_rxq_info
> > of the mtk_rx_ring, which means that an XDP program attached to
> > the Mediathek ethernet driver cannot retrieve the index of the
> > interface that received the package since it's always 0 inside
> > the xdp_md struct.
> > 
> > This patch sets the network device pointer inside the
> > xdp_rxq_info struct, which is later used to initialize
> > the xdp_buff struct via xdp_init_buff.
> > 
> > This was tested using the following eBPF/XDP program attached
> > to a network interface of the mtk_eth_soc driver. As said before,
> > ingress_ifindex always had a value of zero. After applying the
> > patch, ingress_ifindex holds the correct interface index.
> > 
> > 	#include <linux/bpf.h>
> > 	#include <bpf/bpf_helpers.h>
> > 
> > 	SEC("pass")
> > 	int pass_func(struct xdp_md *xdp) {
> >     		bpf_printk("ingress_ifindex: %u",
> > 			xdp->ingress_ifindex);
> > 
> > 		return XDP_PASS;
> > 	}
> > 
> > 	char _license[] SEC("license") = "GPL";
> > 
> > Signed-off-by: Til Kaiser <mail@tk154.de>
> > ---
> >  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > index 53485142938c..9c6d4477e536 100644
> > --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > @@ -2069,6 +2069,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
> >  
> >  		netdev = eth->netdev[mac];
> >  		ppe_idx = eth->mac[mac]->ppe_idx;
> > +		ring->xdp_q.dev = netdev;
> 
> I guess you can set it just before running xdp_init_buff(), but the change is fine.

Lorenzo, is it legitimate to change rxq->dev post registration like
that?

I am asking because we have a similar problem [1]. In our case we also
register the rxq structure with a dummy netdev which is why XDP programs
see an ifindex of 0.

Thanks

[1] https://lore.kernel.org/netdev/ZzYR2ZJ1mGRq12VL@shredder/

> 
> Regards,
> Lorenzo
> 
> >  
> >  		if (unlikely(test_bit(MTK_RESETTING, &eth->state)))
> >  			goto release_desc;
> > -- 
> > 2.47.1
> > 
> >
Lorenzo Bianconi Nov. 27, 2024, 2:30 p.m. UTC | #3
> On Tue, Nov 26, 2024 at 07:16:00PM +0100, Lorenzo Bianconi wrote:
> > > Currently, the network device isn't set inside the xdp_rxq_info
> > > of the mtk_rx_ring, which means that an XDP program attached to
> > > the Mediathek ethernet driver cannot retrieve the index of the
> > > interface that received the package since it's always 0 inside
> > > the xdp_md struct.
> > > 
> > > This patch sets the network device pointer inside the
> > > xdp_rxq_info struct, which is later used to initialize
> > > the xdp_buff struct via xdp_init_buff.
> > > 
> > > This was tested using the following eBPF/XDP program attached
> > > to a network interface of the mtk_eth_soc driver. As said before,
> > > ingress_ifindex always had a value of zero. After applying the
> > > patch, ingress_ifindex holds the correct interface index.
> > > 
> > > 	#include <linux/bpf.h>
> > > 	#include <bpf/bpf_helpers.h>
> > > 
> > > 	SEC("pass")
> > > 	int pass_func(struct xdp_md *xdp) {
> > >     		bpf_printk("ingress_ifindex: %u",
> > > 			xdp->ingress_ifindex);
> > > 
> > > 		return XDP_PASS;
> > > 	}
> > > 
> > > 	char _license[] SEC("license") = "GPL";
> > > 
> > > Signed-off-by: Til Kaiser <mail@tk154.de>
> > > ---
> > >  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > > index 53485142938c..9c6d4477e536 100644
> > > --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > > +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> > > @@ -2069,6 +2069,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
> > >  
> > >  		netdev = eth->netdev[mac];
> > >  		ppe_idx = eth->mac[mac]->ppe_idx;
> > > +		ring->xdp_q.dev = netdev;
> > 
> > I guess you can set it just before running xdp_init_buff(), but the change is fine.
> 
> Lorenzo, is it legitimate to change rxq->dev post registration like
> that?
> 
> I am asking because we have a similar problem [1]. In our case we also
> register the rxq structure with a dummy netdev which is why XDP programs
> see an ifindex of 0.

to be honest I was thinking about it but I guess the dev pointer is just used
running the eBPF program.
@Jesper: any concern?

Regards,
Lorenzo

> 
> Thanks
> 
> [1] https://lore.kernel.org/netdev/ZzYR2ZJ1mGRq12VL@shredder/
> 
> > 
> > Regards,
> > Lorenzo
> > 
> > >  
> > >  		if (unlikely(test_bit(MTK_RESETTING, &eth->state)))
> > >  			goto release_desc;
> > > -- 
> > > 2.47.1
> > > 
> > > 
> 
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 53485142938c..9c6d4477e536 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2069,6 +2069,7 @@  static int mtk_poll_rx(struct napi_struct *napi, int budget,
 
 		netdev = eth->netdev[mac];
 		ppe_idx = eth->mac[mac]->ppe_idx;
+		ring->xdp_q.dev = netdev;
 
 		if (unlikely(test_bit(MTK_RESETTING, &eth->state)))
 			goto release_desc;