* [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate
@ 2024-08-22 5:51 Mina Almasry
2024-08-22 15:34 ` Jakub Kicinski
2024-08-24 14:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Mina Almasry @ 2024-08-22 5:51 UTC (permalink / raw)
To: netdev, linux-kernel, linux-hyperv, bpf
Cc: Mina Almasry, Jay Vosburgh, Andy Gospodarek, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, K. Y. Srinivasan,
Haiyang Zhang, Wei Liu, Dexuan Cui, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend
When net devices propagate xdp configurations to slave devices,
we will need to perform a memory provider check to ensure we're
not binding xdp to a device using unreadable netmem.
Currently the ->ndo_bpf calls in a few places. Adding checks to all
these places would not be ideal.
Refactor all the ->ndo_bpf calls into one place where we can add this
check in the future.
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
v2:
- Don't refactor the calls in net/xdp/xsk_buff_pool.c and
kernel/bpf/offload.c (Jakub)
---
drivers/net/bonding/bond_main.c | 8 ++++----
drivers/net/hyperv/netvsc_bpf.c | 2 +-
include/linux/netdevice.h | 1 +
net/core/dev.c | 9 +++++++++
4 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f9633a6f8571..73f9416c6c1b 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2258,7 +2258,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
goto err_sysfs_del;
}
- res = slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp);
+ res = dev_xdp_propagate(slave_dev, &xdp);
if (res < 0) {
/* ndo_bpf() sets extack error message */
slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res);
@@ -2394,7 +2394,7 @@ static int __bond_release_one(struct net_device *bond_dev,
.prog = NULL,
.extack = NULL,
};
- if (slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp))
+ if (dev_xdp_propagate(slave_dev, &xdp))
slave_warn(bond_dev, slave_dev, "failed to unload XDP program\n");
}
@@ -5584,7 +5584,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
goto err;
}
- err = slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp);
+ err = dev_xdp_propagate(slave_dev, &xdp);
if (err < 0) {
/* ndo_bpf() sets extack error message */
slave_err(dev, slave_dev, "Error %d calling ndo_bpf\n", err);
@@ -5616,7 +5616,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
if (slave == rollback_slave)
break;
- err_unwind = slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp);
+ err_unwind = dev_xdp_propagate(slave_dev, &xdp);
if (err_unwind < 0)
slave_err(dev, slave_dev,
"Error %d when unwinding XDP program change\n", err_unwind);
diff --git a/drivers/net/hyperv/netvsc_bpf.c b/drivers/net/hyperv/netvsc_bpf.c
index 4a9522689fa4..e01c5997a551 100644
--- a/drivers/net/hyperv/netvsc_bpf.c
+++ b/drivers/net/hyperv/netvsc_bpf.c
@@ -183,7 +183,7 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog)
xdp.command = XDP_SETUP_PROG;
xdp.prog = prog;
- ret = vf_netdev->netdev_ops->ndo_bpf(vf_netdev, &xdp);
+ ret = dev_xdp_propagate(vf_netdev, &xdp);
if (ret && prog)
bpf_prog_put(prog);
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 614ec5d3d75b..f0ff269ce262 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3923,6 +3923,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
u8 dev_xdp_prog_count(struct net_device *dev);
+int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf);
u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);
int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
diff --git a/net/core/dev.c b/net/core/dev.c
index e7260889d4cb..165e9778d422 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9369,6 +9369,15 @@ u8 dev_xdp_prog_count(struct net_device *dev)
}
EXPORT_SYMBOL_GPL(dev_xdp_prog_count);
+int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)
+{
+ if (!dev->netdev_ops->ndo_bpf)
+ return -EOPNOTSUPP;
+
+ return dev->netdev_ops->ndo_bpf(dev, bpf);
+}
+EXPORT_SYMBOL_GPL(dev_xdp_propagate);
+
u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode)
{
struct bpf_prog *prog = dev_xdp_prog(dev, mode);
--
2.46.0.295.g3b9ea8a38a-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate
2024-08-22 5:51 [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate Mina Almasry
@ 2024-08-22 15:34 ` Jakub Kicinski
2024-08-24 14:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2024-08-22 15:34 UTC (permalink / raw)
To: Mina Almasry
Cc: netdev, linux-kernel, linux-hyperv, bpf, Jay Vosburgh,
Andy Gospodarek, David S. Miller, Eric Dumazet, Paolo Abeni,
K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend
On Thu, 22 Aug 2024 05:51:54 +0000 Mina Almasry wrote:
> When net devices propagate xdp configurations to slave devices,
> we will need to perform a memory provider check to ensure we're
> not binding xdp to a device using unreadable netmem.
>
> Currently the ->ndo_bpf calls in a few places. Adding checks to all
> these places would not be ideal.
>
> Refactor all the ->ndo_bpf calls into one place where we can add this
> check in the future.
LGTM! (if anyone is planning to review this please TAL, I'm thinking of
applying it a few hours before the full 24h period to let Mina post his
larger series today)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate
2024-08-22 5:51 [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate Mina Almasry
2024-08-22 15:34 ` Jakub Kicinski
@ 2024-08-24 14:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-24 14:30 UTC (permalink / raw)
To: Mina Almasry
Cc: netdev, linux-kernel, linux-hyperv, bpf, jv, andy, davem,
edumazet, kuba, pabeni, kys, haiyangz, wei.liu, decui, ast,
daniel, hawk, john.fastabend
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Thu, 22 Aug 2024 05:51:54 +0000 you wrote:
> When net devices propagate xdp configurations to slave devices,
> we will need to perform a memory provider check to ensure we're
> not binding xdp to a device using unreadable netmem.
>
> Currently the ->ndo_bpf calls in a few places. Adding checks to all
> these places would not be ideal.
>
> [...]
Here is the summary with links:
- [net-next,v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate
https://git.kernel.org/netdev/net-next/c/7d3aed652d09
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-24 14:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-22 5:51 [PATCH net-next v2] net: refactor ->ndo_bpf calls into dev_xdp_propagate Mina Almasry
2024-08-22 15:34 ` Jakub Kicinski
2024-08-24 14:30 ` patchwork-bot+netdevbpf
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).