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 07/33] xdp: xdp_frame add member frame_sz and handle in convert_to_xdp_frame
Date: Thu, 14 May 2020 12:49:33 +0200 [thread overview]
Message-ID: <158945337313.97035.10015729316710496600.stgit@firesoul> (raw)
In-Reply-To: <158945314698.97035.5286827951225578467.stgit@firesoul>
Use hole in struct xdp_frame, when adding member frame_sz, which keeps
same sizeof struct (32 bytes)
Drivers ixgbe and sfc had bug cases where the necessary/expected
tailroom was not reserved. This can lead to some hard to catch memory
corruption issues. Having the drivers frame_sz this can be detected when
packet length/end via xdp->data_end exceed the xdp_data_hard_end
pointer, which accounts for the reserved the tailroom.
When detecting this driver issue, simply fail the conversion with NULL,
which results in feedback to driver (failing xdp_do_redirect()) causing
driver to drop packet. Given the lack of consistent XDP stats, this can
be hard to troubleshoot. And given this is a driver bug, we want to
generate some more noise in form of a WARN stack dump (to ID the driver
code that inlined convert_to_xdp_frame).
Inlining the WARN macro is problematic, because it adds an asm
instruction (on Intel CPUs ud2) what influence instruction cache
prefetching. Thus, introduce xdp_warn and macro XDP_WARN, to avoid this
and at the same time make identifying the function and line of this
inlined function easier.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
include/net/xdp.h | 14 +++++++++++++-
net/core/xdp.c | 8 ++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/include/net/xdp.h b/include/net/xdp.h
index a764af4ae0ea..3094fccf5a88 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -89,7 +89,8 @@ struct xdp_frame {
void *data;
u16 len;
u16 headroom;
- u16 metasize;
+ u32 metasize:8;
+ u32 frame_sz:24;
/* Lifetime of xdp_rxq_info is limited to NAPI/enqueue time,
* while mem info is valid on remote CPU.
*/
@@ -104,6 +105,10 @@ static inline void xdp_scrub_frame(struct xdp_frame *frame)
frame->dev_rx = NULL;
}
+/* Avoids inlining WARN macro in fast-path */
+void xdp_warn(const char *msg, const char *func, const int line);
+#define XDP_WARN(msg) xdp_warn(msg, __func__, __LINE__)
+
struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
/* Convert xdp_buff to xdp_frame */
@@ -124,6 +129,12 @@ struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)
if (unlikely((headroom - metasize) < sizeof(*xdp_frame)))
return NULL;
+ /* Catch if driver didn't reserve tailroom for skb_shared_info */
+ if (unlikely(xdp->data_end > xdp_data_hard_end(xdp))) {
+ XDP_WARN("Driver BUG: missing reserved tailroom");
+ return NULL;
+ }
+
/* Store info in top of packet */
xdp_frame = xdp->data_hard_start;
@@ -131,6 +142,7 @@ struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)
xdp_frame->len = xdp->data_end - xdp->data;
xdp_frame->headroom = headroom - sizeof(*xdp_frame);
xdp_frame->metasize = metasize;
+ xdp_frame->frame_sz = xdp->frame_sz;
/* rxq only valid until napi_schedule ends, convert to xdp_mem_info */
xdp_frame->mem = xdp->rxq->mem;
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 4c7ea85486af..490b8f5fa8ee 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -11,6 +11,7 @@
#include <linux/slab.h>
#include <linux/idr.h>
#include <linux/rhashtable.h>
+#include <linux/bug.h>
#include <net/page_pool.h>
#include <net/xdp.h>
@@ -496,3 +497,10 @@ struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp)
return xdpf;
}
EXPORT_SYMBOL_GPL(xdp_convert_zc_to_xdp_frame);
+
+/* Used by XDP_WARN macro, to avoid inlining WARN() in fast-path */
+void xdp_warn(const char *msg, const char *func, const int line)
+{
+ WARN(1, "XDP_WARN: %s(line:%d): %s\n", func, line, msg);
+};
+EXPORT_SYMBOL_GPL(xdp_warn);
next prev 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 ` Jesper Dangaard Brouer [this message]
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 ` [PATCH net-next v4 09/33] veth: adjust hard_start offset on redirect XDP frames Jesper Dangaard Brouer
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=158945337313.97035.10015729316710496600.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).