From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mail.toke.dk (Postfix) with ESMTPS id 7F6BD982D5C for ; Tue, 28 Jun 2022 21:49:37 +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=RW2fzVxS DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445777; x=1687981777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZoktIBH2DcbAQq3Yb1c6s52MpIMxZuvptyzwO9VbH6M=; b=RW2fzVxSQW4RcaS8R0zzDOGI6E9IlH23AbqgkLhPakFoDiNwYu6Fblc7 lVpdyrJxUjnAbFOrDKwYlMZokTwrtwJGi/zjMHY2SdJIukBuciyigGUoU dqhIt22rDApSqKDP0Ivuq2xNafRvLnoDwYfDshopHy9yV3kYMUWtVPXdK QO5jwQBLo6flQP7R60uaSQB3X3VzkTFmGSh0BhZzbhSWIykVpUOSjr3De zZ4w7MSkw+NrQA8Mkhi2IUbOCLovY6otDYZHwBPbiqWPRwvROmTlLuY1L joUGEFmR4fDY6hDEAqRWdfje9foogwyRrvsv7DGmb+D6hUGbarWrgjIn/ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="270595962" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="270595962" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="767288101" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga005.jf.intel.com with ESMTP; 28 Jun 2022 12:49:23 -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 25SJmr9L022013; Tue, 28 Jun 2022 20:49:22 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:41 +0200 Message-Id: <20220628194812.1453059-22-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: 3CWEGHZRUUVSBK22LMGLBHQK6YHLATFD X-Message-ID-Hash: 3CWEGHZRUUVSBK22LMGLBHQK6YHLATFD 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 21/52] net, xdp: allow metadata > 32 List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hardware/driver-prepended XDP metadata might be much bigger than 32 bytes, especially if it includes a piece of a descriptor. Relax the restriction and allow metadata larger than 32 bytes and make __skb_metadata_differs() work with bigger lengths. The new restriction is pretty much mechanical -- skb_shared_info::meta_len is a u8 and XDP_PACKET_HEADROOM is 256 (minus `sizeof(struct xdp_frame)`). The requirement of having its length aligned to 4 bytes is still valid. Signed-off-by: Alexander Lobakin --- include/linux/skbuff.h | 13 ++++++++----- include/net/xdp_meta.h | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 82edf0359ab3..a825ea7f375d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -4096,10 +4096,13 @@ static inline bool __skb_metadata_differs(const struct sk_buff *skb_a, { const void *a = skb_metadata_end(skb_a); const void *b = skb_metadata_end(skb_b); - /* Using more efficient varaiant than plain call to memcmp(). */ -#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && BITS_PER_LONG == 64 u64 diffs = 0; + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || + BITS_PER_LONG != 64) + goto slow; + + /* Using more efficient variant than plain call to memcmp(). */ switch (meta_len) { #define __it(x, op) (x -= sizeof(u##op)) #define __it_diff(a, b, op) (*(u##op *)__it(a, op)) ^ (*(u##op *)__it(b, op)) @@ -4119,11 +4122,11 @@ static inline bool __skb_metadata_differs(const struct sk_buff *skb_a, fallthrough; case 4: diffs |= __it_diff(a, b, 32); break; + default: +slow: + return memcmp(a - meta_len, b - meta_len, meta_len); } return diffs; -#else - return memcmp(a - meta_len, b - meta_len, meta_len); -#endif } static inline bool skb_metadata_differs(const struct sk_buff *skb_a, diff --git a/include/net/xdp_meta.h b/include/net/xdp_meta.h index e1f3df9ceb93..3a40189d71c6 100644 --- a/include/net/xdp_meta.h +++ b/include/net/xdp_meta.h @@ -5,6 +5,7 @@ #define __LINUX_NET_XDP_META_H__ #include +#include /* Drivers not supporting XDP metadata can use this helper, which * rejects any room expansion for metadata as a result. @@ -21,9 +22,27 @@ xdp_data_meta_unsupported(const struct xdp_buff *xdp) return unlikely(xdp->data_meta > xdp->data); } +/** + * xdp_metalen_invalid -- check if the length of a frame's metadata is valid + * @metalen: the length of the frame's metadata + * + * skb_shared_info::meta_len is of 1 byte long, thus it can't be longer than + * 255, but this always can change. XDP_PACKET_HEADROOM is 256, and this is a + * UAPI. sizeof(struct xdp_frame) is reserved since xdp_frame is being placed + * at xdp_buff::data_hard_start whilst being constructed on XDP_REDIRECT. + * The 32-bit alignment requirement is arbitrary, kept for simplicity and, + * sometimes, speed. + */ static inline bool xdp_metalen_invalid(unsigned long metalen) { - return (metalen & (sizeof(__u32) - 1)) || (metalen > 32); + typeof(metalen) max; + + max = min_t(typeof(max), + (typeof_member(struct skb_shared_info, meta_len))~0UL, + XDP_PACKET_HEADROOM - sizeof(struct xdp_frame)); + BUILD_BUG_ON(!__builtin_constant_p(max)); + + return (metalen & (sizeof(u32) - 1)) || metalen > max; } #endif /* __LINUX_NET_XDP_META_H__ */ -- 2.36.1