History

xdp: add HW offload mode flag for installing programs

Add an installation-time flag for requesting that the program be installed only if it can be offloaded to HW. Internally new command for ndo_xdp is added, this way we avoid putting checks into drivers since they all return -EINVAL on an unknown command.

Jakub Kicinski committed 9 years ago

Commit ee5d0321 parent 32d60274 files · +13 −6Browse files

Unified · Split

4 files
  1. include/linux/netdevice.h +1 −0
  2. include/uapi/linux/if_link.h +5 −2
  3. net/core/dev.c +5 −2
  4. net/core/rtnetlink.c +2 −2
include/linux/netdevice.h+1−0
@@ -807,6 +807,7 @@ enum xdp_netdev_command { · 806 unmodified lines
807807 * when it is no longer used.
808808 */
809809 XDP_SETUP_PROG,
810+ XDP_SETUP_PROG_HW,
810811 /* Check if a bpf program is set on the device. The callee should
811812 * return true if a program is currently attached and running.
812813 */
include/uapi/linux/if_link.h+5−2
@@ -891,9 +891,12 @@ enum { · 890 unmodified lines
891891 #define XDP_FLAGS_UPDATE_IF_NOEXIST (1U << 0)
892892 #define XDP_FLAGS_SKB_MODE (1U << 1)
893893 #define XDP_FLAGS_DRV_MODE (1U << 2)
894+#define XDP_FLAGS_HW_MODE (1U << 3)
895+#define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \
896+ XDP_FLAGS_DRV_MODE | \
897+ XDP_FLAGS_HW_MODE)
894898 #define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \
895− XDP_FLAGS_SKB_MODE | \
896− XDP_FLAGS_DRV_MODE)
899+ XDP_FLAGS_MODES)
897900
898901 /* These are stored into IFLA_XDP_ATTACHED on dump. */
899902 enum {
net/core/dev.c+5−2
@@ -6957,7 +6957,10 @@ static int dev_xdp_install(struct net_device *dev, xdp_op_t xdp_op, · 6956 unmodified lines
69576957 struct netdev_xdp xdp;
69586958
69596959 memset(&xdp, 0, sizeof(xdp));
6960− xdp.command = XDP_SETUP_PROG;
6960+ if (flags & XDP_FLAGS_HW_MODE)
6961+ xdp.command = XDP_SETUP_PROG_HW;
6962+ else
6963+ xdp.command = XDP_SETUP_PROG;
69616964 xdp.extack = extack;
69626965 xdp.flags = flags;
69636966 xdp.prog = prog;
@@ -6985,7 +6988,7 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, · 21 unmodified lines
69856988 ASSERT_RTNL();
69866989
69876990 xdp_op = xdp_chk = ops->ndo_xdp;
6988− if (!xdp_op && (flags & XDP_FLAGS_DRV_MODE))
6991+ if (!xdp_op && (flags & (XDP_FLAGS_DRV_MODE | XDP_FLAGS_HW_MODE)))
69896992 return -EOPNOTSUPP;
69906993 if (!xdp_op || (flags & XDP_FLAGS_SKB_MODE))
69916994 xdp_op = generic_xdp_install;
net/core/rtnetlink.c+2−2
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 * Vitaly E. Lavrov RTA_OK arithmetics was wrong.
1717 */
1818
19+#include <linux/bitops.h>
1920 #include <linux/errno.h>
2021 #include <linux/module.h>
2122 #include <linux/types.h>
@@ -2253,8 +2254,7 @@ static int do_setlink(const struct sk_buff *skb, · 2231 unmodified lines
22532254 err = -EINVAL;
22542255 goto errout;
22552256 }
2256− if ((xdp_flags & XDP_FLAGS_SKB_MODE) &&
2257− (xdp_flags & XDP_FLAGS_DRV_MODE)) {
2257+ if (hweight32(xdp_flags & XDP_FLAGS_MODES) > 1) {
22582258 err = -EINVAL;
22592259 goto errout;
22602260 }