Commit 7d3aed65 authored by Mina Almasry's avatar Mina Almasry Committed by David S. Miller

net: refactor ->ndo_bpf calls into dev_xdp_propagate

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: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarMina Almasry <almasrymina@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f9db28bb
...@@ -2253,7 +2253,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev, ...@@ -2253,7 +2253,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
goto err_sysfs_del; goto err_sysfs_del;
} }
res = slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp); res = dev_xdp_propagate(slave_dev, &xdp);
if (res < 0) { if (res < 0) {
/* ndo_bpf() sets extack error message */ /* ndo_bpf() sets extack error message */
slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res); slave_dbg(bond_dev, slave_dev, "Error %d calling ndo_bpf\n", res);
...@@ -2389,7 +2389,7 @@ static int __bond_release_one(struct net_device *bond_dev, ...@@ -2389,7 +2389,7 @@ static int __bond_release_one(struct net_device *bond_dev,
.prog = NULL, .prog = NULL,
.extack = 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"); slave_warn(bond_dev, slave_dev, "failed to unload XDP program\n");
} }
...@@ -5579,7 +5579,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog, ...@@ -5579,7 +5579,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
goto err; goto err;
} }
err = slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp); err = dev_xdp_propagate(slave_dev, &xdp);
if (err < 0) { if (err < 0) {
/* ndo_bpf() sets extack error message */ /* ndo_bpf() sets extack error message */
slave_err(dev, slave_dev, "Error %d calling ndo_bpf\n", err); slave_err(dev, slave_dev, "Error %d calling ndo_bpf\n", err);
...@@ -5611,7 +5611,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog, ...@@ -5611,7 +5611,7 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
if (slave == rollback_slave) if (slave == rollback_slave)
break; break;
err_unwind = slave_dev->netdev_ops->ndo_bpf(slave_dev, &xdp); err_unwind = dev_xdp_propagate(slave_dev, &xdp);
if (err_unwind < 0) if (err_unwind < 0)
slave_err(dev, slave_dev, slave_err(dev, slave_dev,
"Error %d when unwinding XDP program change\n", err_unwind); "Error %d when unwinding XDP program change\n", err_unwind);
......
...@@ -183,7 +183,7 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog) ...@@ -183,7 +183,7 @@ int netvsc_vf_setxdp(struct net_device *vf_netdev, struct bpf_prog *prog)
xdp.command = XDP_SETUP_PROG; xdp.command = XDP_SETUP_PROG;
xdp.prog = prog; xdp.prog = prog;
ret = vf_netdev->netdev_ops->ndo_bpf(vf_netdev, &xdp); ret = dev_xdp_propagate(vf_netdev, &xdp);
if (ret && prog) if (ret && prog)
bpf_prog_put(prog); bpf_prog_put(prog);
......
...@@ -3925,6 +3925,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -3925,6 +3925,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); int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
u8 dev_xdp_prog_count(struct net_device *dev); 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); 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); int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
......
...@@ -9370,6 +9370,15 @@ u8 dev_xdp_prog_count(struct net_device *dev) ...@@ -9370,6 +9370,15 @@ u8 dev_xdp_prog_count(struct net_device *dev)
} }
EXPORT_SYMBOL_GPL(dev_xdp_prog_count); 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) u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode)
{ {
struct bpf_prog *prog = dev_xdp_prog(dev, mode); struct bpf_prog *prog = dev_xdp_prog(dev, mode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment