[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180627024615.17856-2-saeedm@mellanox.com>
Date: Tue, 26 Jun 2018 19:46:10 -0700
From: Saeed Mahameed <saeedm@....mellanox.co.il>
To: Jesper Dangaard Brouer <brouer@...hat.com>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
Daniel Borkmann <borkmann@...earbox.net>
Cc: neerav.parikh@...el.com, pjwaskiewicz@...il.com,
ttoukan.linux@...il.com, Tariq Toukan <tariqt@...lanox.com>,
alexander.h.duyck@...el.com, peter.waskiewicz.jr@...el.com,
Opher Reviv <opher@...lanox.com>,
Rony Efraim <ronye@...lanox.com>, netdev@...r.kernel.org,
Saeed Mahameed <saeedm@...lanox.com>
Subject: [RFC bpf-next 1/6] net: xdp: Add support for meta data flags requests
A user space application can request to enable a specific set of meta data
to be reported in every xdp buffer provided to the xdp program.
When meta_data flags are required, XDP devices must respond to
XDP_QUERY_META_FLAGS command with all the meta data flags the device
actually supports, and the kernel will cross check them with the
requested flags, in case of discrepancy the xdp install will fail.
If the flags are supported, the device must guarantee to deliver all RX
packets with only the meta data requested in meta data_flags on
xdp_install operation.
The following flags are added, and can be provided by the netlink xdp
flags field.
+#define XDP_FLAGS_META_HASH (1U << 16)
+#define XDP_FLAGS_META_FLOW_MARK (1U << 17)
+#define XDP_FLAGS_META_VLAN (1U << 18)
+#define XDP_FLAGS_META_CSUM_COMPLETE (1U << 19)
The format, device delivery methods and XDP program access to such meta
data is discussed in a later patch.
TODO: use a different flags field for XDP meta data, to make sure we
have more free bits.
Signed-off-by: Saeed Mahameed <saeedm@...lanox.com>
---
include/linux/netdevice.h | 9 +++++++++
include/uapi/linux/if_link.h | 16 +++++++++++++++-
net/core/dev.c | 20 ++++++++++++++++++++
3 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 3ec9850c7936..fc8b6ce48a0f 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -812,6 +812,10 @@ enum bpf_netdev_command {
* is equivalent to XDP_ATTACHED_DRV.
*/
XDP_QUERY_PROG,
+ /* Query Supported XDP_FLAGS_META_*, Called before new XDP program setup
+ * and only if meta_flags were requested by the user to validate if the
+ * device supports the requested flags, if not program setup will fail */
+ XDP_QUERY_META_FLAGS,
/* BPF program for offload callbacks, invoked at program load time. */
BPF_OFFLOAD_VERIFIER_PREP,
BPF_OFFLOAD_TRANSLATE,
@@ -842,6 +846,11 @@ struct netdev_bpf {
/* flags with which program was installed */
u32 prog_flags;
};
+ /* XDP_QUERY_META_FLAGS */
+ struct {
+ /* TODO u64 */
+ u32 meta_flags;
+ };
/* BPF_OFFLOAD_VERIFIER_PREP */
struct {
struct bpf_prog *prog;
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index cf01b6824244..dfb1e26bacef 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -911,8 +911,22 @@ enum {
#define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \
XDP_FLAGS_DRV_MODE | \
XDP_FLAGS_HW_MODE)
+
+/* TODO : add new netlink xdp u64 meta_flags
+ * for meta data only
+ */
+#define XDP_FLAGS_META_HASH (1U << 16)
+#define XDP_FLAGS_META_MARK (1U << 17)
+#define XDP_FLAGS_META_VLAN (1U << 18)
+#define XDP_FLAGS_META_CSUM_COMPLETE (1U << 19)
+#define XDP_FLAGS_META_ALL (XDP_FLAGS_META_HASH | \
+ XDP_FLAGS_META_MARK | \
+ XDP_FLAGS_META_VLAN | \
+ XDP_FLAGS_META_CSUM_COMPLETE)
+
#define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \
- XDP_FLAGS_MODES)
+ XDP_FLAGS_MODES | \
+ XDP_FLAGS_META_ALL)
/* These are stored into IFLA_XDP_ATTACHED on dump. */
enum {
diff --git a/net/core/dev.c b/net/core/dev.c
index a5aa1c7444e6..8a5cc2c731ec 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7295,6 +7295,21 @@ static u8 __dev_xdp_attached(struct net_device *dev, bpf_op_t bpf_op)
return xdp.prog_attached;
}
+static bool __dev_xdp_meta_supported(struct net_device *dev,
+ bpf_op_t bpf_op, u32 meta_flags)
+{
+ struct netdev_bpf xdp = {};
+
+ /* Backward compatible, all devices support no meta_flags */
+ if (!meta_flags)
+ return true;
+
+ xdp.command = XDP_QUERY_META_FLAGS;
+ bpf_op(dev, &xdp);
+
+ return ((xdp.meta_flags & meta_flags) == meta_flags);
+}
+
static int dev_xdp_install(struct net_device *dev, bpf_op_t bpf_op,
struct netlink_ext_ack *extack, u32 flags,
struct bpf_prog *prog)
@@ -7362,12 +7377,17 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
bpf_chk = generic_xdp_install;
if (fd >= 0) {
+ u32 meta_flags = (flags & XDP_FLAGS_META_ALL);
+
if (bpf_chk && __dev_xdp_attached(dev, bpf_chk))
return -EEXIST;
if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) &&
__dev_xdp_attached(dev, bpf_op))
return -EBUSY;
+ if (!__dev_xdp_meta_supported(dev, bpf_op, meta_flags))
+ return -EINVAL;
+
prog = bpf_prog_get_type_dev(fd, BPF_PROG_TYPE_XDP,
bpf_op == ops->ndo_bpf);
if (IS_ERR(prog))
--
2.17.0
Powered by blists - more mailing lists