bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: sameehj@amazon.com
Cc: "Jesper Dangaard Brouer" <brouer@redhat.com>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Daniel Borkmann" <borkmann@iogearbox.net>,
	"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Alexander Duyck" <alexander.duyck@gmail.com>,
	"Jeff Kirsher" <jeffrey.t.kirsher@intel.com>,
	"David Ahern" <dsahern@gmail.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Saeed Mahameed" <saeedm@mellanox.com>,
	"Tariq Toukan" <tariqt@mellanox.com>
Subject: [PATCH net-next v4 09/33] veth: adjust hard_start offset on redirect XDP frames
Date: Thu, 14 May 2020 12:49:43 +0200	[thread overview]
Message-ID: <158945338331.97035.5923525383710752178.stgit@firesoul> (raw)
In-Reply-To: <158945314698.97035.5286827951225578467.stgit@firesoul>

When native XDP redirect into a veth device, the frame arrives in the
xdp_frame structure. It is then processed in veth_xdp_rcv_one(),
which can run a new XDP bpf_prog on the packet. Doing so requires
converting xdp_frame to xdp_buff, but the tricky part is that
xdp_frame memory area is located in the top (data_hard_start) memory
area that xdp_buff will point into.

The current code tried to protect the xdp_frame area, by assigning
xdp_buff.data_hard_start past this memory. This results in 32 bytes
less headroom to expand into via BPF-helper bpf_xdp_adjust_head().

This protect step is actually not needed, because BPF-helper
bpf_xdp_adjust_head() already reserve this area, and don't allow
BPF-prog to expand into it. Thus, it is safe to point data_hard_start
directly at xdp_frame memory area.

Cc: Toshiaki Makita <toshiaki.makita1@gmail.com>
Fixes: 9fc8d518d9d5 ("veth: Handle xdp_frames in xdp napi ring")
Reported-by: Mao Wenan <maowenan@huawei.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 drivers/net/veth.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index aece0e5eec8c..d5691bb84448 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -564,13 +564,15 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 					struct veth_stats *stats)
 {
 	void *hard_start = frame->data - frame->headroom;
-	void *head = hard_start - sizeof(struct xdp_frame);
 	int len = frame->len, delta = 0;
 	struct xdp_frame orig_frame;
 	struct bpf_prog *xdp_prog;
 	unsigned int headroom;
 	struct sk_buff *skb;
 
+	/* bpf_xdp_adjust_head() assures BPF cannot access xdp_frame area */
+	hard_start -= sizeof(struct xdp_frame);
+
 	rcu_read_lock();
 	xdp_prog = rcu_dereference(rq->xdp_prog);
 	if (likely(xdp_prog)) {
@@ -592,7 +594,6 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 			break;
 		case XDP_TX:
 			orig_frame = *frame;
-			xdp.data_hard_start = head;
 			xdp.rxq->mem = frame->mem;
 			if (unlikely(veth_xdp_tx(rq, &xdp, bq) < 0)) {
 				trace_xdp_exception(rq->dev, xdp_prog, act);
@@ -605,7 +606,6 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 			goto xdp_xmit;
 		case XDP_REDIRECT:
 			orig_frame = *frame;
-			xdp.data_hard_start = head;
 			xdp.rxq->mem = frame->mem;
 			if (xdp_do_redirect(rq->dev, &xdp, xdp_prog)) {
 				frame = &orig_frame;
@@ -629,7 +629,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 	rcu_read_unlock();
 
 	headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
-	skb = veth_build_skb(head, headroom, len, 0);
+	skb = veth_build_skb(hard_start, headroom, len, 0);
 	if (!skb) {
 		xdp_return_frame(frame);
 		stats->rx_drops++;



  parent reply	other threads:[~2020-05-14 10:49 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 10:48 [PATCH net-next v4 00/33] XDP extend with knowledge of frame size Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 01/33] xdp: add frame size to xdp_buff Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 02/33] bnxt: add XDP frame size to driver Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 03/33] sfc: add XDP frame size Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 04/33] mvneta: add XDP frame size to driver Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 05/33] net: netsec: Add support for XDP frame size Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 06/33] net: XDP-generic determining " Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 07/33] xdp: xdp_frame add member frame_sz and handle in convert_to_xdp_frame Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 08/33] xdp: cpumap redirect use frame_sz and increase skb_tailroom Jesper Dangaard Brouer
2020-05-14 10:49 ` Jesper Dangaard Brouer [this message]
2020-05-14 10:49 ` [PATCH net-next v4 10/33] veth: xdp using frame_sz in veth driver Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 11/33] dpaa2-eth: add XDP frame size Jesper Dangaard Brouer
2020-05-14 10:49 ` [PATCH net-next v4 12/33] hv_netvsc: add XDP frame size to driver Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 13/33] qlogic/qede: " Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 14/33] net: ethernet: ti: add XDP frame size to driver cpsw Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 15/33] ena: add XDP frame size to amazon NIC driver Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 16/33] mlx4: add XDP frame size and adjust max XDP MTU Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 17/33] net: thunderx: add XDP frame size Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 18/33] nfp: add XDP frame size to netronome driver Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 19/33] tun: add XDP frame size Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 20/33] vhost_net: also populate " Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 21/33] virtio_net: add XDP frame size in two code paths Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 22/33] ixgbe: fix XDP redirect on archs with PAGE_SIZE above 4K Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 23/33] ixgbe: add XDP frame size to driver Jesper Dangaard Brouer
2020-05-14 10:50 ` [PATCH net-next v4 24/33] ixgbevf: add XDP frame size to VF driver Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 25/33] i40e: add XDP frame size to driver Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 26/33] ice: " Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 27/33] xdp: for Intel AF_XDP drivers add XDP frame_sz Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 28/33] mlx5: rx queue setup time determine frame_sz for XDP Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 29/33] xdp: allow bpf_xdp_adjust_tail() to grow packet size Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 30/33] xdp: clear grow memory in bpf_xdp_adjust_tail() Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 31/33] bpf: add xdp.frame_sz in bpf_prog_test_run_xdp() Jesper Dangaard Brouer
2020-05-17  4:02   ` unstable xdp tests. Was: " Alexei Starovoitov
2020-05-18  9:52     ` Jesper Dangaard Brouer
2020-05-18 10:30       ` Jesper Dangaard Brouer
2020-05-18 19:19         ` Andrii Nakryiko
2020-05-14 10:51 ` [PATCH net-next v4 32/33] selftests/bpf: adjust BPF selftest for xdp_adjust_tail Jesper Dangaard Brouer
2020-05-14 10:51 ` [PATCH net-next v4 33/33] selftests/bpf: xdp_adjust_tail add grow tail tests Jesper Dangaard Brouer
2020-05-15  4:52 ` [PATCH net-next v4 00/33] XDP extend with knowledge of frame size Alexei Starovoitov

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=158945338331.97035.5923525383710752178.stgit@firesoul \
    --to=brouer@redhat.com \
    --cc=alexander.duyck@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=borkmann@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=sameehj@amazon.com \
    --cc=tariqt@mellanox.com \
    --cc=toke@redhat.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).