From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Yuya Kusakabe <yuya.kusakabe@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Jason Wang <jasowang@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.19 27/66] virtio_net: Add XDP meta data support
Date: Mon, 12 Apr 2021 10:40:33 +0200 [thread overview]
Message-ID: <20210412083959.009036799@linuxfoundation.org> (raw)
In-Reply-To: <20210412083958.129944265@linuxfoundation.org>
From: Yuya Kusakabe <yuya.kusakabe@gmail.com>
[ Upstream commit 503d539a6e417b018616bf3060e0b5814fafce47 ]
Implement support for transferring XDP meta data into skb for
virtio_net driver; before calling into the program, xdp.data_meta points
to xdp.data, where on program return with pass verdict, we call
into skb_metadata_set().
Tested with the script at
https://github.com/higebu/virtio_net-xdp-metadata-test.
Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/bpf/20200225033212.437563-2-yuya.kusakabe@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index d41d5f63f211..0b1c6a8906b9 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -383,7 +383,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
struct receive_queue *rq,
struct page *page, unsigned int offset,
unsigned int len, unsigned int truesize,
- bool hdr_valid)
+ bool hdr_valid, unsigned int metasize)
{
struct sk_buff *skb;
struct virtio_net_hdr_mrg_rxbuf *hdr;
@@ -405,6 +405,7 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
else
hdr_padded_len = sizeof(struct padded_vnet_hdr);
+ /* hdr_valid means no XDP, so we can copy the vnet header */
if (hdr_valid)
memcpy(hdr, p, hdr_len);
@@ -417,6 +418,11 @@ static struct sk_buff *page_to_skb(struct virtnet_info *vi,
copy = skb_tailroom(skb);
skb_put_data(skb, p, copy);
+ if (metasize) {
+ __skb_pull(skb, metasize);
+ skb_metadata_set(skb, metasize);
+ }
+
len -= copy;
offset += copy;
@@ -462,10 +468,6 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi,
struct virtio_net_hdr_mrg_rxbuf *hdr;
int err;
- /* virtqueue want to use data area in-front of packet */
- if (unlikely(xdpf->metasize > 0))
- return -EOPNOTSUPP;
-
if (unlikely(xdpf->headroom < vi->hdr_len))
return -EOVERFLOW;
@@ -656,6 +658,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
unsigned int delta = 0;
struct page *xdp_page;
int err;
+ unsigned int metasize = 0;
len -= vi->hdr_len;
stats->bytes += len;
@@ -695,8 +698,8 @@ static struct sk_buff *receive_small(struct net_device *dev,
xdp.data_hard_start = buf + VIRTNET_RX_PAD + vi->hdr_len;
xdp.data = xdp.data_hard_start + xdp_headroom;
- xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + len;
+ xdp.data_meta = xdp.data;
xdp.rxq = &rq->xdp_rxq;
orig_data = xdp.data;
act = bpf_prog_run_xdp(xdp_prog, &xdp);
@@ -707,6 +710,7 @@ static struct sk_buff *receive_small(struct net_device *dev,
/* Recalculate length in case bpf program changed it */
delta = orig_data - xdp.data;
len = xdp.data_end - xdp.data;
+ metasize = xdp.data - xdp.data_meta;
break;
case XDP_TX:
stats->xdp_tx++;
@@ -752,6 +756,9 @@ static struct sk_buff *receive_small(struct net_device *dev,
memcpy(skb_vnet_hdr(skb), buf, vi->hdr_len);
} /* keep zeroed vnet hdr since packet was changed by bpf */
+ if (metasize)
+ skb_metadata_set(skb, metasize);
+
err:
return skb;
@@ -772,8 +779,8 @@ static struct sk_buff *receive_big(struct net_device *dev,
struct virtnet_rq_stats *stats)
{
struct page *page = buf;
- struct sk_buff *skb = page_to_skb(vi, rq, page, 0, len,
- PAGE_SIZE, true);
+ struct sk_buff *skb =
+ page_to_skb(vi, rq, page, 0, len, PAGE_SIZE, true, 0);
stats->bytes += len - vi->hdr_len;
if (unlikely(!skb))
@@ -805,6 +812,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
unsigned int truesize;
unsigned int headroom = mergeable_ctx_to_headroom(ctx);
int err;
+ unsigned int metasize = 0;
head_skb = NULL;
stats->bytes += len - vi->hdr_len;
@@ -851,8 +859,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
data = page_address(xdp_page) + offset;
xdp.data_hard_start = data - VIRTIO_XDP_HEADROOM + vi->hdr_len;
xdp.data = data + vi->hdr_len;
- xdp_set_data_meta_invalid(&xdp);
xdp.data_end = xdp.data + (len - vi->hdr_len);
+ xdp.data_meta = xdp.data;
xdp.rxq = &rq->xdp_rxq;
act = bpf_prog_run_xdp(xdp_prog, &xdp);
@@ -860,24 +868,27 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
switch (act) {
case XDP_PASS:
+ metasize = xdp.data - xdp.data_meta;
+
/* recalculate offset to account for any header
- * adjustments. Note other cases do not build an
- * skb and avoid using offset
+ * adjustments and minus the metasize to copy the
+ * metadata in page_to_skb(). Note other cases do not
+ * build an skb and avoid using offset
*/
- offset = xdp.data -
- page_address(xdp_page) - vi->hdr_len;
+ offset = xdp.data - page_address(xdp_page) -
+ vi->hdr_len - metasize;
- /* recalculate len if xdp.data or xdp.data_end were
- * adjusted
+ /* recalculate len if xdp.data, xdp.data_end or
+ * xdp.data_meta were adjusted
*/
- len = xdp.data_end - xdp.data + vi->hdr_len;
+ len = xdp.data_end - xdp.data + vi->hdr_len + metasize;
/* We can only create skb based on xdp_page. */
if (unlikely(xdp_page != page)) {
rcu_read_unlock();
put_page(page);
- head_skb = page_to_skb(vi, rq, xdp_page,
- offset, len,
- PAGE_SIZE, false);
+ head_skb = page_to_skb(vi, rq, xdp_page, offset,
+ len, PAGE_SIZE, false,
+ metasize);
return head_skb;
}
break;
@@ -933,7 +944,8 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
goto err_skb;
}
- head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog);
+ head_skb = page_to_skb(vi, rq, page, offset, len, truesize, !xdp_prog,
+ metasize);
curr_skb = head_skb;
if (unlikely(!curr_skb))
--
2.30.2
next prev parent reply other threads:[~2021-04-12 8:43 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-12 8:40 [PATCH 4.19 00/66] 4.19.187-rc1 review Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 01/66] ALSA: aloop: Fix initialization of controls Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 02/66] ASoC: intel: atom: Stop advertising non working S24LE support Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 03/66] nfc: fix refcount leak in llcp_sock_bind() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 04/66] nfc: fix refcount leak in llcp_sock_connect() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 05/66] nfc: fix memory " Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 06/66] nfc: Avoid endless loops caused by repeated llcp_sock_connect() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 07/66] xen/evtchn: Change irq_info lock to raw_spinlock_t Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 08/66] net: ipv6: check for validity before dereferencing cfg->fc_nlinfo.nlh Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 09/66] ia64: fix user_stack_pointer() for ptrace() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 10/66] nds32: flush_dcache_page: use page_mapping_file to avoid races with swapoff Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 11/66] ocfs2: fix deadlock between setattr and dio_end_io_write Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 12/66] fs: direct-io: fix missing sdio->boundary Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 13/66] parisc: parisc-agp requires SBA IOMMU driver Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 14/66] parisc: avoid a warning on u8 cast for cmpxchg on u8 pointers Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 15/66] ARM: dts: turris-omnia: configure LED[2]/INTn pin as interrupt pin Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 16/66] batman-adv: initialize "struct batadv_tvlv_tt_vlan_data"->reserved field Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 17/66] ice: Increase control queue timeout Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 18/66] net: hso: fix null-ptr-deref during tty device unregistration Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 19/66] net: ensure mac header is set in virtio_net_hdr_to_skb() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 20/66] net: sched: sch_teql: fix null-pointer dereference Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 21/66] net-ipv6: bugfix - raw & sctp - switch to ipv6_can_nonlocal_bind() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 22/66] usbip: add sysfs_lock to synchronize sysfs code paths Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 23/66] usbip: stub-dev " Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 24/66] usbip: vudc " Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 25/66] usbip: synchronize event handler with " Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 26/66] i2c: turn recovery error on init to debug Greg Kroah-Hartman
2021-04-12 8:40 ` Greg Kroah-Hartman [this message]
2021-04-12 8:40 ` [PATCH 4.19 28/66] virtio_net: Do not pull payload in skb->head Greg Kroah-Hartman
2021-04-12 9:12 ` Michael S. Tsirkin
2021-04-12 8:40 ` [PATCH 4.19 29/66] xfrm: interface: fix ipv4 pmtu check to honor ip header df Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 30/66] regulator: bd9571mwv: Fix AVS and DVFS voltage range Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 31/66] net: xfrm: Localize sequence counter per network namespace Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 32/66] ASoC: wm8960: Fix wrong bclk and lrclk with pll enabled for some chips Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 33/66] i40e: Added Asym_Pause to supported link modes Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 34/66] i40e: Fix kernel oops when i40e driver removes VFs Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 35/66] amd-xgbe: Update DMA coherency values Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 36/66] sch_red: fix off-by-one checks in red_check_params() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 37/66] gianfar: Handle error code at MAC address change Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 38/66] cxgb4: avoid collecting SGE_QBASE regs during traffic Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 39/66] net:tipc: Fix a double free in tipc_sk_mcast_rcv Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 40/66] ARM: dts: imx6: pbab01: Set vmmc supply for both SD interfaces Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 41/66] net/ncsi: Avoid channel_monitor hrtimer deadlock Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 42/66] ASoC: sunxi: sun4i-codec: fill ASoC card owner Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 43/66] soc/fsl: qbman: fix conflicting alignment attributes Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 44/66] clk: fix invalid usage of list cursor in register Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 45/66] clk: fix invalid usage of list cursor in unregister Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 46/66] workqueue: Move the position of debug_work_activate() in __queue_work() Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 47/66] s390/cpcmd: fix inline assembly register clobbering Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 48/66] net/mlx5: Fix placement of log_max_flow_counter Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 49/66] net/mlx5: Fix PBMC register mapping Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 50/66] RDMA/cxgb4: check for ipv6 address properly while destroying listener Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 51/66] clk: socfpga: fix iomem pointer cast on 64-bit Greg Kroah-Hartman
2021-04-12 8:40 ` [PATCH 4.19 52/66] net: sched: bump refcount for new action in ACT replace mode Greg Kroah-Hartman
2021-04-13 10:37 ` Sudip Mukherjee
2021-04-12 8:40 ` [PATCH 4.19 53/66] cfg80211: remove WARN_ON() in cfg80211_sme_connect Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 54/66] net: tun: set tun->dev->addr_len during TUNSETLINK processing Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 55/66] drivers: net: fix memory leak in atusb_probe Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 56/66] drivers: net: fix memory leak in peak_usb_create_dev Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 57/66] net: mac802154: Fix general protection fault Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 58/66] net: ieee802154: nl-mac: fix check on panid Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 59/66] net: ieee802154: fix nl802154 del llsec key Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 60/66] net: ieee802154: fix nl802154 del llsec dev Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 61/66] net: ieee802154: fix nl802154 add llsec key Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 62/66] net: ieee802154: fix nl802154 del llsec devkey Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 63/66] net: ieee802154: forbid monitor for set llsec params Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 64/66] net: ieee802154: forbid monitor for del llsec seclevel Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 65/66] net: ieee802154: stop dump llsec params for monitors Greg Kroah-Hartman
2021-04-12 8:41 ` [PATCH 4.19 66/66] Revert "cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath." Greg Kroah-Hartman
2021-04-12 22:08 ` [PATCH 4.19 00/66] 4.19.187-rc1 review Guenter Roeck
2021-04-13 1:37 ` Shuah Khan
2021-04-13 5:41 ` Naresh Kamboju
2021-04-13 8:47 ` Pavel Machek
2021-04-13 10:40 ` Sudip Mukherjee
2021-04-14 2:50 ` Samuel Zou
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=20210412083959.009036799@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=daniel@iogearbox.net \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=yuya.kusakabe@gmail.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).