From: Björn Töpel <bjorn.topel@xxxxxxxxx> Similar to query a driver for a loaded XDP program, each driver need to check the attachment flags when a program is loaded. E.g., if an XDP program was loaded without explicit flags (fallback mode), it must be reloaded/removed without explicit flags. This commit moves that check to generic code as well. Signed-off-by: Björn Töpel <bjorn.topel@xxxxxxxxx> --- net/core/dev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 8e9f5693a7da..bb5fbb395596 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8075,8 +8075,8 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, const struct net_device_ops *ops = dev->netdev_ops; xdp_query_prog_t query, check; struct bpf_prog *prog = NULL; + bool offload, expl; bpf_op_t bpf_op; - bool offload; int err; ASSERT_RTNL(); @@ -8124,6 +8124,14 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, } } + expl = dev->xdp.explicit_mode; + if (!offload && query(dev) && !!expl ^ !!(flags & XDP_FLAGS_MODES)) { + NL_SET_ERR_MSG(extack, "program loaded with different flags"); + if (prog) + bpf_prog_put(prog); + return -EBUSY; + } + err = dev_xdp_install(dev, bpf_op, extack, flags, prog); if (err < 0 && prog) bpf_prog_put(prog); -- 2.20.1