From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mail.toke.dk (Postfix) with ESMTPS id 65F79982EE2 for ; Tue, 28 Jun 2022 21:49:59 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JiKCDtMJ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445799; x=1687981799; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9Ah1nON265YzupnBokZWEAPrUTKFeqbKYbnG7bxwujc=; b=JiKCDtMJ5QFgbC8JJYdgIZRnx1Y1lNyqUUGTs1Hv5rCXtXTACM3B2+WX WQL1x9zhfAaZvoNkmA7ytHTPocr5fs/binGloOL5ac1DbDJK/Kw6/UnQ/ wIYqr6vukmLEPZAXWVNwufB6JJEh/3pH8Q+1fkyOdAtYwdR2SbwSKgM3j L4fX4V96svCAvesoFnN1rTG/oyD4mxF5mjYuEBJZCxYI/lcxZcSvSypnb EOO4zNtHi73wkVzDeIl99AR30LDtY+ErcsY80nrfFLr2MUAPHrrtmFYj7 DxrV+GQBr9iGN9hufah9XpF1hbbIyShb7iN2E+klP5ZPaEz4m7tlYJIDc A==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="307319711" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="307319711" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="594927639" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga007.fm.intel.com with ESMTP; 28 Jun 2022 12:49:53 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9h022013; Tue, 28 Jun 2022 20:49:51 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:48:03 +0200 Message-Id: <20220628194812.1453059-44-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NPCA77FAWOSKQ46TIVORLP3G2MGSZ4OM X-Message-ID-Hash: NPCA77FAWOSKQ46TIVORLP3G2MGSZ4OM X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 43/52] net, xdp: build XDP generic metadata on Generic (skb) XDP path List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Now that the core has the routine to make XDP generic metadata from the skb fields and &net_device stores meta_thresh, provide XDP generic metadata to BPF programs running on Generic/skb XDP path. skb fields are being updated from the metadata after BPF program exits (if it's still there). Signed-off-by: Alexander Lobakin --- net/bpf/dev.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/net/bpf/dev.c b/net/bpf/dev.c index 350ebdc783a0..f4187b357a0c 100644 --- a/net/bpf/dev.c +++ b/net/bpf/dev.c @@ -1,7 +1,20 @@ // SPDX-License-Identifier: GPL-2.0-only +#include #include +enum { + GENERIC_XDP_META_GEN, + + /* Must be last */ + GENERIC_XDP_META_NONE, + __GENERIC_XDP_META_NUM, +}; + +static const char * const generic_xdp_meta_types[__GENERIC_XDP_META_NUM] = { + [GENERIC_XDP_META_GEN] = "struct xdp_meta_generic", +}; + DEFINE_STATIC_KEY_FALSE(generic_xdp_needed_key); static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb) @@ -27,17 +40,33 @@ static struct netdev_rx_queue *netif_get_rxqueue(struct sk_buff *skb) return rxqueue; } +static void generic_xdp_handle_meta(struct xdp_buff *xdp, struct sk_buff *skb, + const struct xdp_attachment_info *info) +{ + if (xdp->data_end - xdp->data < READ_ONCE(info->meta_thresh)) + return; + + switch (READ_ONCE(info->drv_cookie)) { + case GENERIC_XDP_META_GEN: + xdp_build_meta_generic_from_skb(skb); + xdp->data_meta = skb_metadata_end(skb) - skb_metadata_len(skb); + break; + default: + break; + } +} + u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, struct bpf_prog *xdp_prog) { void *orig_data, *orig_data_end, *hard_start; struct net_device *dev = skb->dev; struct netdev_rx_queue *rxqueue; + u32 metalen, orig_metalen, act; bool orig_bcast, orig_host; u32 mac_len, frame_sz; __be16 orig_eth_type; struct ethhdr *eth; - u32 metalen, act; int off; /* The XDP program wants to see the packet starting at the MAC @@ -62,6 +91,9 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, orig_bcast = is_multicast_ether_addr_64bits(eth->h_dest); orig_eth_type = eth->h_proto; + generic_xdp_handle_meta(xdp, skb, &dev->xdp_info); + orig_metalen = xdp->data - xdp->data_meta; + act = bpf_prog_run_xdp(xdp_prog, xdp); /* check if bpf_xdp_adjust_head was used */ @@ -105,11 +137,15 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, case XDP_REDIRECT: case XDP_TX: __skb_push(skb, mac_len); - break; + fallthrough; case XDP_PASS: metalen = xdp->data - xdp->data_meta; - if (metalen) + if (metalen != orig_metalen) skb_metadata_set(skb, metalen); + if (metalen) + xdp_populate_skb_meta_generic(skb); + else if (orig_metalen) + skb_metadata_nocomp_clear(skb); break; } @@ -244,10 +280,15 @@ static void dev_disable_gro_hw(struct net_device *dev) static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp) { bool old = !!rtnl_dereference(dev->xdp_info.prog_rcu); - int ret = 0; + int ret; switch (xdp->command) { case XDP_SETUP_PROG: + ret = xdp_meta_match_id(generic_xdp_meta_types, xdp->btf_id); + if (ret < 0) + return ret; + + WRITE_ONCE(dev->xdp_info.drv_cookie, ret); xdp_attachment_setup_rcu(&dev->xdp_info, xdp); if (old && !xdp->prog) { @@ -257,6 +298,8 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp) dev_disable_lro(dev); dev_disable_gro_hw(dev); } + + ret = 0; break; default: -- 2.36.1