Commit ce158e58 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

xdp: add reporting of offload mode

Extend the XDP_ATTACHED_* values to include offloaded mode.
Let drivers report whether program is installed in the driver
or the HW by changing the prog_attached field from bool to
u8 (type of the netlink attribute).

Exploit the fact that the value of XDP_ATTACHED_DRV is 1,
therefore since all drivers currently assign the mode with
double negation:
       mode = !!xdp_prog;
no drivers have to be modified.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cafa92ac
...@@ -809,7 +809,8 @@ enum xdp_netdev_command { ...@@ -809,7 +809,8 @@ enum xdp_netdev_command {
XDP_SETUP_PROG, XDP_SETUP_PROG,
XDP_SETUP_PROG_HW, XDP_SETUP_PROG_HW,
/* Check if a bpf program is set on the device. The callee should /* Check if a bpf program is set on the device. The callee should
* return true if a program is currently attached and running. * set @prog_attached to one of XDP_ATTACHED_* values, note that "true"
* is equivalent to XDP_ATTACHED_DRV.
*/ */
XDP_QUERY_PROG, XDP_QUERY_PROG,
}; };
...@@ -827,7 +828,7 @@ struct netdev_xdp { ...@@ -827,7 +828,7 @@ struct netdev_xdp {
}; };
/* XDP_QUERY_PROG */ /* XDP_QUERY_PROG */
struct { struct {
bool prog_attached; u8 prog_attached;
u32 prog_id; u32 prog_id;
}; };
}; };
...@@ -3307,7 +3308,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -3307,7 +3308,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
typedef int (*xdp_op_t)(struct net_device *dev, struct netdev_xdp *xdp); typedef int (*xdp_op_t)(struct net_device *dev, struct netdev_xdp *xdp);
int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
int fd, u32 flags); int fd, u32 flags);
bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op, u32 *prog_id); u8 __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op, u32 *prog_id);
int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb); int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
int dev_forward_skb(struct net_device *dev, struct sk_buff *skb); int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
......
...@@ -903,6 +903,7 @@ enum { ...@@ -903,6 +903,7 @@ enum {
XDP_ATTACHED_NONE = 0, XDP_ATTACHED_NONE = 0,
XDP_ATTACHED_DRV, XDP_ATTACHED_DRV,
XDP_ATTACHED_SKB, XDP_ATTACHED_SKB,
XDP_ATTACHED_HW,
}; };
enum { enum {
......
...@@ -6934,8 +6934,7 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down) ...@@ -6934,8 +6934,7 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down)
} }
EXPORT_SYMBOL(dev_change_proto_down); EXPORT_SYMBOL(dev_change_proto_down);
bool __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op, u8 __dev_xdp_attached(struct net_device *dev, xdp_op_t xdp_op, u32 *prog_id)
u32 *prog_id)
{ {
struct netdev_xdp xdp; struct netdev_xdp xdp;
......
...@@ -1265,10 +1265,10 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id) ...@@ -1265,10 +1265,10 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)
*prog_id = generic_xdp_prog->aux->id; *prog_id = generic_xdp_prog->aux->id;
return XDP_ATTACHED_SKB; return XDP_ATTACHED_SKB;
} }
if (ops->ndo_xdp && __dev_xdp_attached(dev, ops->ndo_xdp, prog_id)) if (!ops->ndo_xdp)
return XDP_ATTACHED_DRV;
return XDP_ATTACHED_NONE; return XDP_ATTACHED_NONE;
return __dev_xdp_attached(dev, ops->ndo_xdp, prog_id);
} }
static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev) static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
......
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