* [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info @ 2024-11-26 13:41 Til Kaiser 2024-11-26 13:41 ` Til Kaiser 0 siblings, 1 reply; 6+ messages in thread From: Til Kaiser @ 2024-11-26 13:41 UTC (permalink / raw) To: nbd, sean.wang, Mark-MC.Lee, lorenzo; +Cc: netdev Hi, I have noticed on a Banana Pi BPI-R4 running OpenWrt that the ingress interface index is always 0 when I attach an eBPF/XDP program to one of its SFP ports or its switch in native/driver mode. Attached, you can find a fix/patch and a simple eBPF/XDP program I used for testing. Kind regards Til ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info 2024-11-26 13:41 [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info Til Kaiser @ 2024-11-26 13:41 ` Til Kaiser 2024-11-26 18:16 ` Lorenzo Bianconi 2024-12-03 3:16 ` Jakub Kicinski 0 siblings, 2 replies; 6+ messages in thread From: Til Kaiser @ 2024-11-26 13:41 UTC (permalink / raw) To: nbd, sean.wang, Mark-MC.Lee, lorenzo; +Cc: netdev, Til Kaiser 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; if (unlikely(test_bit(MTK_RESETTING, ð->state))) goto release_desc; -- 2.47.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info 2024-11-26 13:41 ` Til Kaiser @ 2024-11-26 18:16 ` Lorenzo Bianconi 2024-11-27 13:31 ` Ido Schimmel 2024-12-03 3:16 ` Jakub Kicinski 1 sibling, 1 reply; 6+ messages in thread From: Lorenzo Bianconi @ 2024-11-26 18:16 UTC (permalink / raw) To: Til Kaiser; +Cc: nbd, sean.wang, Mark-MC.Lee, lorenzo, netdev [-- Attachment #1: Type: text/plain, Size: 1814 bytes --] > 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, ð->state))) > goto release_desc; > -- > 2.47.1 > > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info 2024-11-26 18:16 ` Lorenzo Bianconi @ 2024-11-27 13:31 ` Ido Schimmel 2024-11-27 14:30 ` Lorenzo Bianconi 0 siblings, 1 reply; 6+ messages in thread From: Ido Schimmel @ 2024-11-27 13:31 UTC (permalink / raw) To: Lorenzo Bianconi Cc: Til Kaiser, nbd, sean.wang, Mark-MC.Lee, lorenzo, netdev, amcohen, aleksander.lobakin 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, ð->state))) > > goto release_desc; > > -- > > 2.47.1 > > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info 2024-11-27 13:31 ` Ido Schimmel @ 2024-11-27 14:30 ` Lorenzo Bianconi 0 siblings, 0 replies; 6+ messages in thread From: Lorenzo Bianconi @ 2024-11-27 14:30 UTC (permalink / raw) To: Ido Schimmel Cc: Lorenzo Bianconi, Til Kaiser, nbd, sean.wang, Mark-MC.Lee, netdev, amcohen, aleksander.lobakin, Jesper Dangaard Brouer [-- Attachment #1: Type: text/plain, Size: 2614 bytes --] > 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, ð->state))) > > > goto release_desc; > > > -- > > > 2.47.1 > > > > > > > > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info 2024-11-26 13:41 ` Til Kaiser 2024-11-26 18:16 ` Lorenzo Bianconi @ 2024-12-03 3:16 ` Jakub Kicinski 1 sibling, 0 replies; 6+ messages in thread From: Jakub Kicinski @ 2024-12-03 3:16 UTC (permalink / raw) To: Til Kaiser; +Cc: nbd, sean.wang, Mark-MC.Lee, lorenzo, netdev On Tue, 26 Nov 2024 14:41:54 +0100 Til Kaiser wrote: > [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info my $0.02: - not a fix, rxq is not a hard requirement for XDP support - if we want to do this we should record in the queue that netdev is "unstable" (new member?), it will make it easier to track the drivers with this behavior later on -- pw-bot: cr ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-12-03 3:17 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-11-26 13:41 [PATCH net] mediathek: mtk_eth_soc: fix netdev inside xdp_rxq_info Til Kaiser 2024-11-26 13:41 ` Til Kaiser 2024-11-26 18:16 ` Lorenzo Bianconi 2024-11-27 13:31 ` Ido Schimmel 2024-11-27 14:30 ` Lorenzo Bianconi 2024-12-03 3:16 ` Jakub Kicinski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).