Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10498993rwr; Fri, 12 May 2023 08:55:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rJlwSA5AAXgmt2Exp0BhjdOb49lD412K1+lXCc8UVsxiEr8KbTwKKJ6YIMdzYO3RRqFXX X-Received: by 2002:a17:90a:3c8f:b0:247:bdd3:a039 with SMTP id g15-20020a17090a3c8f00b00247bdd3a039mr25182826pjc.8.1683906913400; Fri, 12 May 2023 08:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683906913; cv=none; d=google.com; s=arc-20160816; b=XjH8K8MQ0Uo/u5IUEwarUdRfd4n8C9vE237Cymf23J5UZyj9Q0FsvPYc1TR05GXTI4 HvzSbtp1pm4L2oRVESiBZzGNZJg0FJHW3bD36Twx5R2DLi+OI0ZFdJbsl1U2oLguH5Ps CJAt2l637YmsOqZgCIRA5++qXpnB4hR6Flp07ic9CFbWbAwtnnKHBKDbKLAsrv51ofmh B+VQiOLc40lxdrdtlVIkPBaKmemu4o/MiZLM6y/UXTTcCNW9eCBNsa58UVHPYRhJ4ejd 2tPw2ok9KAgDHz2vI6iiDrcPuC1+mOslp3lklOMc/VpRO/kFdChmXHY2u7YyNHbbNNWu 0DHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S0gZ6lLDc4yMlNFSQT+52VtBVOgY4QEFuEP5kgyv3Ug=; b=hmRih4iz7cDAav05MJoSvpqRNQOrTAAo7Pnj87XpeYPNJq2PdxXkUbM6VsBcqUgvmN GkNfn1kzUawZltaMDebyZa80GD/ZClIpjuPvFX/tQ64j/OBYh20ZFUSaErcKiBkOijnl NbG1uJOkQ3RDCKyCgEG5BXc+awjluz/vmCK6V8Boip0i60NgtS7b00kceSJX91ORuuQ6 vTKPfNUG0QnqcRI8SvvSrlfrJbm6lLQE3X7Kj529BlDJOyEeV93VOXHdpZiSLozVcYtq 3sjm79dAILHYx1VJQeRBf2VvRX6IUdvkF/Ow3XCW+r9qDTu5UXCgR4QshIV/5TWgDwId cR5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CJaToMac; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk10-20020a17090b224a00b00250a6b87c76si11574209pjb.142.2023.05.12.08.55.01; Fri, 12 May 2023 08:55:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CJaToMac; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241921AbjELPao (ORCPT + 99 others); Fri, 12 May 2023 11:30:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241972AbjELPaL (ORCPT ); Fri, 12 May 2023 11:30:11 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1117BE702; Fri, 12 May 2023 08:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683905374; x=1715441374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lrRJS0jP369ocGK4OM/oyS3+pmBq12NrPBpQcE0bU8o=; b=CJaToMacSeSP1eBor1kMx+dmf3EFVM1Pvk1zAZBcnwvi5ugX5+yPlC9F X74SDVP/GVtPS85JXtbzoUoX4FZXFWMTdrI/ZYG4ESA0Gf5Cp3xzkmtLS c75N5oMiSCdfzrv61EH5NR/COja1mWDmzWudZLbcmOe8O+Z+7ZxLp8L1h 6suYMOs7xIfFkTH24GaKtF8KLl4GcwxhnrDY9VDL1tfpXu3vIV6EJYEVC HbfugCvAoyWzD+KRhzdSO7WOcivAwX3VspzwKQjTjTe3wx669QbRaXsFr e40SoLU/I82pzHI/tPhASkM4zIsNC8jFyBlOXlz7ZITA3JiShk0N9NhZg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10708"; a="349653485" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="349653485" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2023 08:29:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10708"; a="1030124604" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="1030124604" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmsmga005.fm.intel.com with ESMTP; 12 May 2023 08:29:04 -0700 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id F37F935FB8; Fri, 12 May 2023 16:29:02 +0100 (IST) From: Larysa Zaremba To: bpf@vger.kernel.org Cc: Larysa Zaremba , Stanislav Fomichev , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Jakub Kicinski , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jiri Olsa , Jesse Brandeburg , Tony Nguyen , Anatoly Burakov , Jesper Dangaard Brouer , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org, Aleksander Lobakin Subject: [PATCH RESEND bpf-next 14/15] net, xdp: allow metadata > 32 Date: Fri, 12 May 2023 17:26:06 +0200 Message-Id: <20230512152607.992209-15-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230512152607.992209-1-larysa.zaremba@intel.com> References: <20230512152607.992209-1-larysa.zaremba@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aleksander Lobakin When using XDP hints, metadata sometimes has to be much bigger than 32 bytes. Relax the restriction, allow metadata larger than 32 bytes and make __skb_metadata_differs() work with bigger lengths. Now size of metadata is only limited by the fact it is stored as u8 in skb_shared_info, so maximum possible value is 255. Other important conditions, such as having enough space for xdp_frame building, are already checked in bpf_xdp_adjust_meta(). The requirement of having its length aligned to 4 bytes is still valid. Signed-off-by: Aleksander Lobakin Signed-off-by: Larysa Zaremba --- include/linux/skbuff.h | 13 ++++++++----- include/net/xdp.h | 7 ++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8ddb4af1a501..afcd372aecdf 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -4219,10 +4219,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)) @@ -4242,11 +4245,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.h b/include/net/xdp.h index 0fbd25616241..f48723250c7c 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -370,7 +370,12 @@ xdp_data_meta_unsupported(const struct xdp_buff *xdp) static inline bool xdp_metalen_invalid(unsigned long metalen) { - return (metalen & (sizeof(__u32) - 1)) || (metalen > 32); + typeof(metalen) meta_max; + + meta_max = type_max(typeof_member(struct skb_shared_info, meta_len)); + BUILD_BUG_ON(!__builtin_constant_p(meta_max)); + + return !IS_ALIGNED(metalen, sizeof(u32)) || metalen > meta_max; } struct xdp_attachment_info { -- 2.35.3