Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10473549rwr; Fri, 12 May 2023 08:34:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ZkDx05uRxxKVkzK/zwSMf8r68GCCuJAScTapgjV0y1v7UY/ncpv/03HraTo/M9Ty2Cz8A X-Received: by 2002:a17:90a:e7c7:b0:252:ad83:590e with SMTP id kb7-20020a17090ae7c700b00252ad83590emr3248006pjb.14.1683905652371; Fri, 12 May 2023 08:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683905652; cv=none; d=google.com; s=arc-20160816; b=Sb5chcZkTXKCu3bO6cYnGu4ISaUCbx4d5SQZaJa7UP1kjrl2q+3ekDFu5wRcbPcSML FhIXsSEq6jgjQVP4p/a1jrDQejUCdmeXPQim8WRcNUm/XoSCPztym0pVRR+Hcv6xSvvU TAGYRaEUUjab1EPyF8/bVcPixMh6w8SySFJH+cnwqJ7ihtxaSf1yN3GGY6yZmEBWToGM w0p/gIRA9DrFVIH1ZDN8SVr5YpxTuTZ3zT3Ml9uv0vVf5K+Tv57INAfN902XejbKhEkL qxERDs/BEK+dTcBRUU+qwVSRY7OML3ghI1f3G4uCzavkhUGjK2+G31wPSA6yZntfRBzB 4T8g== 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=GWTU4pPwKc0IvH8TuOgY5oXGhBfAxU1iBoUBnyTPp4CwHU1KLZTh7WWk5tmHTrqD40 q1ySllCKzvlymP95Ny+i5J9QqJ8HeU3E/Z4w4mrvMuW26C8FXCitPVC8Mx4InZurCANQ RjqJglWyQXHZA6UUOiRS2VF9Why6M/UsEmqZoXH7rmp6/1vn2Cwxn27rIJMLQPC+gGQ4 utgNdp9xU6+FVIRQ0MhS+bOx9KGdbsfQt2/g9Of0c3xoSDiJMDqm5Ai751Xv1+Jt1pR6 XnX299Y4i1Sz4QVMEwTD5ZmYXjXEn1fErADD831PmKXArlyIUKBdQP/a+JRQot8iNO/u 3J2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FHuXTcYs; 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 b12-20020a63714c000000b005203991145dsi9050492pgn.473.2023.05.12.08.33.57; Fri, 12 May 2023 08:34:12 -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=FHuXTcYs; 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 S241859AbjELPWa (ORCPT + 99 others); Fri, 12 May 2023 11:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241845AbjELPWT (ORCPT ); Fri, 12 May 2023 11:22:19 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A48EAFF; Fri, 12 May 2023 08:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683904908; x=1715440908; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lrRJS0jP369ocGK4OM/oyS3+pmBq12NrPBpQcE0bU8o=; b=FHuXTcYsaGyR9aUw0L0f2ywmxE4CddiIBMKRJHvkZSggqI2Qoy05McJh j8a+6UhCdZtqtaHM95b9P3R4xTA8dx/lATr+T4mkr1PrJfM+dqWDaOrfo rrgayRALeRZzhuDT7ljsjii/Po2IaC685LTW/BqBt42ECvwUUNqxaCSau 1kWrQu1xgs2rjRqBiRfz4cu1ZB2uc3BvN3KIfmBPPun72EciEJrNBWYHR CriEdKFXQn0AIqa+2THr5JVhqNagXdV+Gg5x+2HNlDH6g9CJYGNPfmSHN VR9mZl2PM17a0EXnsC70a089a0Nk4E9TeOy4KQQCsi52JBMwy7t2Vij+C Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10708"; a="353061277" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="353061277" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2023 08:20:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10708"; a="812114619" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="812114619" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmsmga002.fm.intel.com with ESMTP; 12 May 2023 08:20:51 -0700 Received: from lincoln.igk.intel.com (lincoln.igk.intel.com [10.102.21.235]) by irvmail002.ir.intel.com (Postfix) with ESMTP id E679036376; Fri, 12 May 2023 16:20:47 +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 14/15] net, xdp: allow metadata > 32 Date: Fri, 12 May 2023 17:16:38 +0200 Message-Id: <20230512151639.992033-15-larysa.zaremba@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230512151639.992033-1-larysa.zaremba@intel.com> References: <20230512151639.992033-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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