From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org,
prashantbhole.linux@gmail.com, brouer@redhat.com,
toke@redhat.com, daniel@iogearbox.net, john.fastabend@gmail.com,
ast@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
andriin@fb.com, dsahern@gmail.com,
David Ahern <dahern@digitalocean.com>
Subject: [PATCH v5 bpf-next 02/11] net: uapi for XDP programs in the egress path
Date: Tue, 12 May 2020 19:45:58 -0600 [thread overview]
Message-ID: <20200513014607.40418-3-dsahern@kernel.org> (raw)
In-Reply-To: <20200513014607.40418-1-dsahern@kernel.org>
From: David Ahern <dahern@digitalocean.com>
Running programs in the egress path, on skbs or xdp_frames, does not
require driver specific resources like Rx path. Accordingly, the
programs can be run in core code, so add xdp_egress_prog to net_device
to hold a reference to an attached program.
For UAPI, add XDP_FLAGS_EGRESS_MODE to specify attach is at egress, add
a new attach flag, XDP_ATTACHED_EGRESS_CORE, for reporting the attach
point at the core, egress level and add IFLA_XDP_EGRESS_PROG_ID
for reporting the program id. Add rtnl_xdp_prog_egress to fill in
link message with egress data.
Signed-off-by: David Ahern <dahern@digitalocean.com>
---
include/linux/netdevice.h | 1 +
include/uapi/linux/if_link.h | 6 +++++-
net/core/rtnetlink.c | 23 +++++++++++++++++++++--
tools/include/uapi/linux/if_link.h | 6 +++++-
4 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 5a8d40f1ffe2..594c13d4cd00 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1995,6 +1995,7 @@ struct net_device {
unsigned int real_num_rx_queues;
struct bpf_prog __rcu *xdp_prog;
+ struct bpf_prog __rcu *xdp_egress_prog;
unsigned long gro_flush_timeout;
int napi_defer_hard_irqs;
rx_handler_func_t __rcu *rx_handler;
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index a009365ad67b..de32a9e94d74 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -976,9 +976,11 @@ enum {
#define XDP_FLAGS_DRV_MODE (1U << 2)
#define XDP_FLAGS_HW_MODE (1U << 3)
#define XDP_FLAGS_REPLACE (1U << 4)
+#define XDP_FLAGS_EGRESS_MODE (1U << 5)
#define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \
XDP_FLAGS_DRV_MODE | \
- XDP_FLAGS_HW_MODE)
+ XDP_FLAGS_HW_MODE | \
+ XDP_FLAGS_EGRESS_MODE)
#define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \
XDP_FLAGS_MODES | XDP_FLAGS_REPLACE)
@@ -989,6 +991,7 @@ enum {
XDP_ATTACHED_SKB,
XDP_ATTACHED_HW,
XDP_ATTACHED_MULTI,
+ XDP_ATTACHED_EGRESS_CORE,
};
enum {
@@ -1001,6 +1004,7 @@ enum {
IFLA_XDP_SKB_PROG_ID,
IFLA_XDP_HW_PROG_ID,
IFLA_XDP_EXPECTED_FD,
+ IFLA_XDP_EGRESS_PROG_ID,
__IFLA_XDP_MAX,
};
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 2269199c5891..9084dfebc699 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -982,7 +982,7 @@ static size_t rtnl_xdp_size(void)
size_t xdp_size = nla_total_size(0) + /* nest IFLA_XDP */
nla_total_size(1) + /* XDP_ATTACHED */
nla_total_size(4) + /* XDP_PROG_ID (or 1st mode) */
- nla_total_size(4); /* XDP_<mode>_PROG_ID */
+ nla_total_size(4) * 2; /* XDP_<mode>_PROG_ID */
return xdp_size;
}
@@ -1402,6 +1402,18 @@ static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev)
return 0;
}
+static u32 rtnl_xdp_prog_egress(struct net_device *dev)
+{
+ const struct bpf_prog *prog;
+
+ ASSERT_RTNL();
+
+ prog = rtnl_dereference(dev->xdp_egress_prog);
+ if (!prog)
+ return 0;
+ return prog->aux->id;
+}
+
static u32 rtnl_xdp_prog_skb(struct net_device *dev)
{
const struct bpf_prog *generic_xdp_prog;
@@ -1474,6 +1486,12 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
IFLA_XDP_HW_PROG_ID, rtnl_xdp_prog_hw);
if (err)
goto err_cancel;
+ err = rtnl_xdp_report_one(skb, dev, &prog_id, &mode,
+ XDP_ATTACHED_EGRESS_CORE,
+ IFLA_XDP_EGRESS_PROG_ID,
+ rtnl_xdp_prog_egress);
+ if (err)
+ goto err_cancel;
err = nla_put_u8(skb, IFLA_XDP_ATTACHED, mode);
if (err)
@@ -2790,7 +2808,8 @@ static int do_setlink(const struct sk_buff *skb,
if (err < 0)
goto errout;
- if (xdp[IFLA_XDP_ATTACHED] || xdp[IFLA_XDP_PROG_ID]) {
+ if (xdp[IFLA_XDP_ATTACHED] || xdp[IFLA_XDP_PROG_ID] ||
+ xdp[IFLA_XDP_EGRESS_PROG_ID]) {
err = -EINVAL;
goto errout;
}
diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h
index cafedbbfefbe..1d61cb46a77c 100644
--- a/tools/include/uapi/linux/if_link.h
+++ b/tools/include/uapi/linux/if_link.h
@@ -964,9 +964,11 @@ enum {
#define XDP_FLAGS_DRV_MODE (1U << 2)
#define XDP_FLAGS_HW_MODE (1U << 3)
#define XDP_FLAGS_REPLACE (1U << 4)
+#define XDP_FLAGS_EGRESS_MODE (1U << 5)
#define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \
XDP_FLAGS_DRV_MODE | \
- XDP_FLAGS_HW_MODE)
+ XDP_FLAGS_HW_MODE | \
+ XDP_FLAGS_EGRESS_MODE)
#define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \
XDP_FLAGS_MODES | XDP_FLAGS_REPLACE)
@@ -977,6 +979,7 @@ enum {
XDP_ATTACHED_SKB,
XDP_ATTACHED_HW,
XDP_ATTACHED_MULTI,
+ XDP_ATTACHED_EGRESS_CORE,
};
enum {
@@ -989,6 +992,7 @@ enum {
IFLA_XDP_SKB_PROG_ID,
IFLA_XDP_HW_PROG_ID,
IFLA_XDP_EXPECTED_FD,
+ IFLA_XDP_EGRESS_PROG_ID,
__IFLA_XDP_MAX,
};
--
2.21.1 (Apple Git-122.3)
next prev parent reply other threads:[~2020-05-13 1:46 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 1:45 [PATCH v5 bpf-next 00/11] net: Add support for XDP in egress path David Ahern
2020-05-13 1:45 ` [PATCH v5 bpf-next 01/11] net: Refactor convert_to_xdp_frame David Ahern
2020-05-13 1:45 ` David Ahern [this message]
2020-05-13 1:45 ` [PATCH v5 bpf-next 03/11] net: Add XDP setup and query commands for Tx programs David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 04/11] net: Add BPF_XDP_EGRESS as a bpf_attach_type David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 05/11] xdp: Add xdp_txq_info to xdp_buff David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 06/11] net: set XDP egress program on netdevice David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 07/11] net: Support xdp in the Tx path for xdp_frames David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 08/11] libbpf: Add egress XDP support David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 09/11] bpftool: Add support for XDP egress David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 10/11] selftest: Add xdp_egress attach tests David Ahern
2020-05-13 1:46 ` [PATCH v5 bpf-next 11/11] samples/bpf: add XDP egress support to xdp1 David Ahern
2020-05-13 10:43 ` [PATCH v5 bpf-next 00/11] net: Add support for XDP in egress path Toke Høiland-Jørgensen
2020-05-13 19:37 ` David Ahern
2020-05-15 22:54 ` John Fastabend
2020-05-15 23:15 ` David Ahern
2020-05-18 18:10 ` John Fastabend
2020-05-18 23:52 ` David Ahern
2020-05-19 6:04 ` John Fastabend
2020-05-18 3:40 ` David Ahern
2020-05-18 9:08 ` Toke Høiland-Jørgensen
2020-05-18 14:44 ` David Ahern
2020-05-18 18:00 ` Toke Høiland-Jørgensen
2020-05-18 21:06 ` Daniel Borkmann
2020-05-19 0:02 ` David Ahern
2020-05-19 13:31 ` Daniel Borkmann
2020-05-19 14:21 ` Jesper Dangaard Brouer
2020-05-19 16:58 ` Lorenzo Bianconi
2020-05-19 14:52 ` Toke Høiland-Jørgensen
2020-05-19 16:37 ` David Ahern
2020-05-18 23:37 ` David Ahern
2020-05-18 21:23 ` Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200513014607.40418-3-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=brouer@redhat.com \
--cc=dahern@digitalocean.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=prashantbhole.linux@gmail.com \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).