From nobody Mon Feb 9 19:25:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0924AC6FD1D for ; Thu, 30 Mar 2023 17:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbjC3RIr (ORCPT ); Thu, 30 Mar 2023 13:08:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231959AbjC3RIm (ORCPT ); Thu, 30 Mar 2023 13:08:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED33DD515 for ; Thu, 30 Mar 2023 10:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680196074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qjkKRVN5noire8SEYVg51bRUSjWpdWfSqBmXhZUzWcE=; b=TcNLcTDc/Kkcmo5A6kVrPF9QPjgfgaUMZXS3ooSuzqdtvKkwwd+38f77GJhyDNvyVmme+V UtnNcwyzDo7SqhR0x/t4gJ90EgIAQzWBUGaZZyyixx8tRm6kNswINXQXa4Ltqjo5EKVNFH ++kI2EGsloAr/nFkDaoVgJfVW0856Y4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-92-HlRW_yH8MzOx7Y2koHQdJw-1; Thu, 30 Mar 2023 13:07:48 -0400 X-MC-Unique: HlRW_yH8MzOx7Y2koHQdJw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1161801210; Thu, 30 Mar 2023 17:07:46 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 803AF202701E; Thu, 30 Mar 2023 17:07:46 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id C5B1830736C72; Thu, 30 Mar 2023 19:07:45 +0200 (CEST) Subject: [PATCH bpf RFC-V3 1/5] xdp: rss hash types representation From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, martin.lau@kernel.org, ast@kernel.org, daniel@iogearbox.net, alexandr.lobakin@intel.com, larysa.zaremba@intel.com, xdp-hints@xdp-project.net, anthony.l.nguyen@intel.com, yoong.siang.song@intel.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org, pabeni@redhat.com, jesse.brandeburg@intel.com, kuba@kernel.org, edumazet@google.com, john.fastabend@gmail.com, hawk@kernel.org, davem@davemloft.net Date: Thu, 30 Mar 2023 19:07:45 +0200 Message-ID: <168019606574.3557870.15629824904085210321.stgit@firesoul> In-Reply-To: <168019602958.3557870.9960387532660882277.stgit@firesoul> References: <168019602958.3557870.9960387532660882277.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The RSS hash type specifies what portion of packet data NIC hardware used when calculating RSS hash value. The RSS types are focused on Internet traffic protocols at OSI layers L3 and L4. L2 (e.g. ARP) often get hash value zero and no RSS type. For L3 focused on IPv4 vs. IPv6, and L4 primarily TCP vs UDP, but some hardware supports SCTP. Hardware RSS types are differently encoded for each hardware NIC. Most hardware represent RSS hash type as a number. Determining L3 vs L4 often requires a mapping table as there often isn't a pattern or sorting according to ISO layer. The patch introduce a XDP RSS hash type (enum xdp_rss_hash_type) that contain combinations to be used by drivers, which gets build up with bits from enum xdp_rss_type_bits. Both enum xdp_rss_type_bits and xdp_rss_hash_type get exposed to BPF via BTF, and it is up to the BPF-programmer to match using these defines. This proposal change the kfunc API bpf_xdp_metadata_rx_hash() adding a pointer value argument for provide the RSS hash type. Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen --- include/linux/netdevice.h | 3 ++- include/net/xdp.h | 46 +++++++++++++++++++++++++++++++++++++++++= ++++ net/core/xdp.c | 10 +++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 470085b121d3..c35f04f636f1 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1624,7 +1624,8 @@ struct net_device_ops { =20 struct xdp_metadata_ops { int (*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp); - int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash); + int (*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash, + enum xdp_rss_hash_type *rss_type); }; =20 /** diff --git a/include/net/xdp.h b/include/net/xdp.h index 41c57b8b1671..130091a55a6f 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -8,6 +8,7 @@ =20 #include /* skb_shared_info */ #include +#include =20 /** * DOC: XDP RX-queue information @@ -425,6 +426,51 @@ XDP_METADATA_KFUNC_xxx MAX_XDP_METADATA_KFUNC, }; =20 +enum xdp_rss_type_bits { + XDP_RSS_L3_IPV4 =3D BIT(0), + XDP_RSS_L3_IPV6 =3D BIT(1), + + /* The fixed (L3) IPv4 and IPv6 headers can both be followed by + * variable/dynamic headers, IPv4 called Options and IPv6 called + * Extension Headers. HW RSS type can contain this info. + */ + XDP_RSS_L3_DYNHDR =3D BIT(2), + + /* When RSS hash covers L4 then drivers MUST set XDP_RSS_L4 bit in + * addition to the protocol specific bit. This ease interaction with + * SKBs and avoids reserving a fixed mask for future L4 protocol bits. + */ + XDP_RSS_L4 =3D BIT(3), /* L4 based hash, proto can be unknown */ + XDP_RSS_L4_TCP =3D BIT(4), + XDP_RSS_L4_UDP =3D BIT(5), + XDP_RSS_L4_SCTP =3D BIT(6), + XDP_RSS_L4_IPSEC =3D BIT(7), /* L4 based hash include IPSEC SPI */ +}; + +/* RSS hash type combinations used for driver HW mapping */ +enum xdp_rss_hash_type { + XDP_RSS_TYPE_NONE =3D 0, + XDP_RSS_TYPE_L2 =3D XDP_RSS_TYPE_NONE, + + XDP_RSS_TYPE_L3_IPV4 =3D XDP_RSS_L3_IPV4, + XDP_RSS_TYPE_L3_IPV6 =3D XDP_RSS_L3_IPV6, + XDP_RSS_TYPE_L3_IPV4_OPT =3D XDP_RSS_L3_IPV4 | XDP_RSS_L3_DYNHDR, + XDP_RSS_TYPE_L3_IPV6_EX =3D XDP_RSS_L3_IPV6 | XDP_RSS_L3_DYNHDR, + + XDP_RSS_TYPE_L4_ANY =3D XDP_RSS_L4, + XDP_RSS_TYPE_L4_IPV4_TCP =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_TCP, + XDP_RSS_TYPE_L4_IPV4_UDP =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_UDP, + XDP_RSS_TYPE_L4_IPV4_SCTP =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_SCTP, + + XDP_RSS_TYPE_L4_IPV6_TCP =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_TCP, + XDP_RSS_TYPE_L4_IPV6_UDP =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_UDP, + XDP_RSS_TYPE_L4_IPV6_SCTP =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_SCTP, + + XDP_RSS_TYPE_L4_IPV6_TCP_EX =3D XDP_RSS_TYPE_L4_IPV6_TCP |XDP_RSS_L3_DYN= HDR, + XDP_RSS_TYPE_L4_IPV6_UDP_EX =3D XDP_RSS_TYPE_L4_IPV6_UDP |XDP_RSS_L3_DYN= HDR, + XDP_RSS_TYPE_L4_IPV6_SCTP_EX =3D XDP_RSS_TYPE_L4_IPV6_SCTP|XDP_RSS_L3_DYN= HDR, +}; + #ifdef CONFIG_NET u32 bpf_xdp_metadata_kfunc_id(int id); bool bpf_dev_bound_kfunc_id(u32 btf_id); diff --git a/net/core/xdp.c b/net/core/xdp.c index 528d4b37983d..38d2dee16b47 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -734,14 +734,22 @@ __bpf_kfunc int bpf_xdp_metadata_rx_timestamp(const s= truct xdp_md *ctx, u64 *tim * bpf_xdp_metadata_rx_hash - Read XDP frame RX hash. * @ctx: XDP context pointer. * @hash: Return value pointer. + * @rss_type: Return value pointer for RSS type. + * + * The RSS hash type (@rss_type) specifies what portion of packet headers = NIC + * hardware were used when calculating RSS hash value. The type combinati= ons + * are defined via &enum xdp_rss_hash_type and individual bits can be deco= ded + * via &enum xdp_rss_type_bits. * * Return: * * Returns 0 on success or ``-errno`` on error. * * ``-EOPNOTSUPP`` : means device driver doesn't implement kfunc * * ``-ENODATA`` : means no RX-hash available for this frame */ -__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *ha= sh) +__bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *ha= sh, + enum xdp_rss_hash_type *rss_type) { + BTF_TYPE_EMIT(enum xdp_rss_type_bits); return -EOPNOTSUPP; } From nobody Mon Feb 9 19:25:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00900C77B6F for ; Thu, 30 Mar 2023 17:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbjC3RI6 (ORCPT ); Thu, 30 Mar 2023 13:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbjC3RIs (ORCPT ); Thu, 30 Mar 2023 13:08:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 223B146B5 for ; Thu, 30 Mar 2023 10:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680196077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QsEJuXGS7h5UzWyfV3tZvj1EZ/1kj1uGT+GUV/uonTg=; b=hT/USVX2gGKPxYOS/J4b9UanXtijHEMSXG5iTUYLuXUvQfdb0ObE5igrTZx3lt3qFCj7hj 0EEm0ZnC2huRYfX8uE9NMLv4VGa5vS00CUqMokA8DSapQW+nA2PBf4F9sg2OWoScD3dJq7 byztNW9vXREtPGxwpcEu2Rdedh2XT9w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-464-PL9fhRh3OziV1AH8E_BKTA-1; Thu, 30 Mar 2023 13:07:53 -0400 X-MC-Unique: PL9fhRh3OziV1AH8E_BKTA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DC6F185A78B; Thu, 30 Mar 2023 17:07:52 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id C02412166B33; Thu, 30 Mar 2023 17:07:51 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id D3F9B30736C72; Thu, 30 Mar 2023 19:07:50 +0200 (CEST) Subject: [PATCH bpf RFC-V3 2/5] mlx5: bpf_xdp_metadata_rx_hash add xdp rss hash type From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, martin.lau@kernel.org, ast@kernel.org, daniel@iogearbox.net, alexandr.lobakin@intel.com, larysa.zaremba@intel.com, xdp-hints@xdp-project.net, anthony.l.nguyen@intel.com, yoong.siang.song@intel.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org, pabeni@redhat.com, jesse.brandeburg@intel.com, kuba@kernel.org, edumazet@google.com, john.fastabend@gmail.com, hawk@kernel.org, davem@davemloft.net Date: Thu, 30 Mar 2023 19:07:50 +0200 Message-ID: <168019607082.3557870.9567318700335733457.stgit@firesoul> In-Reply-To: <168019602958.3557870.9960387532660882277.stgit@firesoul> References: <168019602958.3557870.9960387532660882277.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type via mapping table. The mlx5 hardware can also identify and RSS hash IPSEC. This indicate hash includes SPI (Security Parameters Index) as part of IPSEC hash. Extend xdp core enum xdp_rss_hash_type with IPSEC hash type. Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen --- drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 63 ++++++++++++++++++= +++- include/linux/mlx5/device.h | 14 ++++- include/net/xdp.h | 3 + 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net= /ethernet/mellanox/mlx5/core/en/xdp.c index c5dae48b7932..0abfed0ff3e5 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c @@ -34,6 +34,7 @@ #include #include "en/xdp.h" #include "en/params.h" +#include =20 int mlx5e_xdp_max_mtu(struct mlx5e_params *params, struct mlx5e_xsk_param = *xsk) { @@ -169,14 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md= *ctx, u64 *timestamp) return 0; } =20 -static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash) +/* Mapping HW RSS Type bits CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 into 4-bit= s*/ +#define RSS_TYPE_MAX_TABLE 16 /* 4-bits max 16 entries */ +#define RSS_L4 GENMASK(1,0) +#define RSS_L3 GENMASK(3,2) /* Same as CQE_RSS_HTYPE_IP */ + +/* Valid combinations of CQE_RSS_HTYPE_IP + CQE_RSS_HTYPE_L4 sorted numeri= cal */ +enum mlx5_rss_hash_type { + RSS_TYPE_NO_HASH =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IP_NONE)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)), + RSS_TYPE_L3_IPV4 =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)), + RSS_TYPE_L4_IPV4_TCP =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)), + RSS_TYPE_L4_IPV4_UDP =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)), + RSS_TYPE_L4_IPV4_IPSEC =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV4)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)), + RSS_TYPE_L3_IPV6 =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_NONE)), + RSS_TYPE_L4_IPV6_TCP =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_TCP)), + RSS_TYPE_L4_IPV6_UDP =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_UDP)), + RSS_TYPE_L4_IPV6_IPSEC =3D (FIELD_PREP_CONST(RSS_L3, CQE_RSS_IPV6)| \ + FIELD_PREP_CONST(RSS_L4, CQE_RSS_L4_IPSEC)), +} mlx5_rss_hash_type; + +/* Invalid combinations will simply return zero, allows no boundry checks = */ +static const enum xdp_rss_hash_type mlx5_xdp_rss_type[RSS_TYPE_MAX_TABLE] = =3D { + [RSS_TYPE_NO_HASH] =3D XDP_RSS_TYPE_NONE, + [1] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ + [2] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ + [3] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ + [RSS_TYPE_L3_IPV4] =3D XDP_RSS_TYPE_L3_IPV4, + [RSS_TYPE_L4_IPV4_TCP] =3D XDP_RSS_TYPE_L4_IPV4_TCP, + [RSS_TYPE_L4_IPV4_UDP] =3D XDP_RSS_TYPE_L4_IPV4_UDP, + [RSS_TYPE_L4_IPV4_IPSEC]=3D XDP_RSS_TYPE_L4_IPV4_IPSEC, + [RSS_TYPE_L3_IPV6] =3D XDP_RSS_TYPE_L3_IPV6, + [RSS_TYPE_L4_IPV6_TCP] =3D XDP_RSS_TYPE_L4_IPV6_TCP, + [RSS_TYPE_L4_IPV6_UDP] =3D XDP_RSS_TYPE_L4_IPV6_UDP, + [RSS_TYPE_L4_IPV6_IPSEC]=3D XDP_RSS_TYPE_L4_IPV6_IPSEC, + [12] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ + [13] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ + [14] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ + [15] =3D XDP_RSS_TYPE_NONE, /* Implicit zero */ +}; + +static int mlx5e_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, + enum xdp_rss_hash_type *rss_type) { const struct mlx5e_xdp_buff *_ctx =3D (void *)ctx; + const struct mlx5_cqe64 *cqe =3D _ctx->cqe; + u32 hash_type, l4_type, ip_type, lookup; =20 if (unlikely(!(_ctx->xdp.rxq->dev->features & NETIF_F_RXHASH))) return -ENODATA; =20 - *hash =3D be32_to_cpu(_ctx->cqe->rss_hash_result); + *hash =3D be32_to_cpu(cqe->rss_hash_result); + + hash_type =3D cqe->rss_hash_type; + BUILD_BUG_ON(CQE_RSS_HTYPE_IP !=3D RSS_L3); /* same mask */ + ip_type =3D hash_type & CQE_RSS_HTYPE_IP; + l4_type =3D FIELD_GET(CQE_RSS_HTYPE_L4, hash_type); + lookup =3D ip_type | l4_type; + *rss_type =3D mlx5_xdp_rss_type[lookup]; + return 0; } =20 diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h index 71b06ebad402..27aa9ae10996 100644 --- a/include/linux/mlx5/device.h +++ b/include/linux/mlx5/device.h @@ -36,6 +36,7 @@ #include #include #include +#include =20 #if defined(__LITTLE_ENDIAN) #define MLX5_SET_HOST_ENDIANNESS 0 @@ -980,14 +981,23 @@ enum { }; =20 enum { - CQE_RSS_HTYPE_IP =3D 0x3 << 2, + CQE_RSS_HTYPE_IP =3D GENMASK(3,2), /* cqe->rss_hash_type[3:2] - IP destination selected for hash * (00 =3D none, 01 =3D IPv4, 10 =3D IPv6, 11 =3D Reserved) */ - CQE_RSS_HTYPE_L4 =3D 0x3 << 6, + CQE_RSS_IP_NONE =3D 0x0, + CQE_RSS_IPV4 =3D 0x1, + CQE_RSS_IPV6 =3D 0x2, + CQE_RSS_RESERVED =3D 0x3, + + CQE_RSS_HTYPE_L4 =3D GENMASK(7,6), /* cqe->rss_hash_type[7:6] - L4 destination selected for hash * (00 =3D none, 01 =3D TCP. 10 =3D UDP, 11 =3D IPSEC.SPI */ + CQE_RSS_L4_NONE =3D 0x0, + CQE_RSS_L4_TCP =3D 0x1, + CQE_RSS_L4_UDP =3D 0x2, + CQE_RSS_L4_IPSEC =3D 0x3, }; =20 enum { diff --git a/include/net/xdp.h b/include/net/xdp.h index 130091a55a6f..0260e680006a 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -461,14 +461,17 @@ enum xdp_rss_hash_type { XDP_RSS_TYPE_L4_IPV4_TCP =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_TCP, XDP_RSS_TYPE_L4_IPV4_UDP =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_UDP, XDP_RSS_TYPE_L4_IPV4_SCTP =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_SCTP, + XDP_RSS_TYPE_L4_IPV4_IPSEC =3D XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L= 4_IPSEC, =20 XDP_RSS_TYPE_L4_IPV6_TCP =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_TCP, XDP_RSS_TYPE_L4_IPV6_UDP =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_UDP, XDP_RSS_TYPE_L4_IPV6_SCTP =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_SCTP, + XDP_RSS_TYPE_L4_IPV6_IPSEC =3D XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L= 4_IPSEC, =20 XDP_RSS_TYPE_L4_IPV6_TCP_EX =3D XDP_RSS_TYPE_L4_IPV6_TCP |XDP_RSS_L3_DYN= HDR, XDP_RSS_TYPE_L4_IPV6_UDP_EX =3D XDP_RSS_TYPE_L4_IPV6_UDP |XDP_RSS_L3_DYN= HDR, XDP_RSS_TYPE_L4_IPV6_SCTP_EX =3D XDP_RSS_TYPE_L4_IPV6_SCTP|XDP_RSS_L3_DYN= HDR, + XDP_RSS_TYPE_L4_IPV6_IPSEC_EX=3D XDP_RSS_TYPE_L4_IPV6_IPSEC|XDP_RSS_L3_DY= NHDR, }; =20 #ifdef CONFIG_NET From nobody Mon Feb 9 19:25:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93DD3C6FD1D for ; Thu, 30 Mar 2023 17:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232180AbjC3RJC (ORCPT ); Thu, 30 Mar 2023 13:09:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232184AbjC3RIx (ORCPT ); Thu, 30 Mar 2023 13:08:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27BB7CDDC for ; Thu, 30 Mar 2023 10:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680196082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZoFlTLlLEFnWNA/e5RUGygzU5KPyB6B2U1PTeQjWe4=; b=WnwgCtqppdJ3oYYa9rQu5zfxaDug4Mwud25OD+uZ43Mbst0KcS2ZMQuLxp9zK+SnKMW9D6 3+OjuqkDo4XJCj/UcosW80MGtX6P3mz0WRAfVY5zMaDBRZKDWSUIowbiH3vtkmPE0Hxa4R 60URHSgIkWCPHi7rnWiCoPQJ2LxrduQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-452-aug2f9xDNsKg0k9hF4gfzg-1; Thu, 30 Mar 2023 13:07:58 -0400 X-MC-Unique: aug2f9xDNsKg0k9hF4gfzg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C643A101A54F; Thu, 30 Mar 2023 17:07:56 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 860244042AC0; Thu, 30 Mar 2023 17:07:56 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id E2D5430736C72; Thu, 30 Mar 2023 19:07:55 +0200 (CEST) Subject: [PATCH bpf RFC-V3 3/5] veth: bpf_xdp_metadata_rx_hash add xdp rss hash type From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, martin.lau@kernel.org, ast@kernel.org, daniel@iogearbox.net, alexandr.lobakin@intel.com, larysa.zaremba@intel.com, xdp-hints@xdp-project.net, anthony.l.nguyen@intel.com, yoong.siang.song@intel.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org, pabeni@redhat.com, jesse.brandeburg@intel.com, kuba@kernel.org, edumazet@google.com, john.fastabend@gmail.com, hawk@kernel.org, davem@davemloft.net Date: Thu, 30 Mar 2023 19:07:55 +0200 Message-ID: <168019607588.3557870.8079404138352729694.stgit@firesoul> In-Reply-To: <168019602958.3557870.9960387532660882277.stgit@firesoul> References: <168019602958.3557870.9960387532660882277.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type. The veth driver currently only support XDP-hints based on SKB code path. The SKB have lost information about the RSS hash type, by compressing the information down to a single bitfield skb->l4_hash, that only knows if this was a L4 hash value. In preparation for veth, the xdp_rss_hash_type have an L4 indication bit that allow us to return a meaningful L4 indication when working with SKB based packets. Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen --- drivers/net/veth.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index c1178915496d..f5381e7c9310 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1648,14 +1648,19 @@ static int veth_xdp_rx_timestamp(const struct xdp_m= d *ctx, u64 *timestamp) return 0; } =20 -static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash) +static int veth_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, + enum xdp_rss_hash_type *rss_type) + { struct veth_xdp_buff *_ctx =3D (void *)ctx; + struct sk_buff *skb =3D _ctx->skb; =20 - if (!_ctx->skb) + if (!skb) return -ENODATA; =20 - *hash =3D skb_get_hash(_ctx->skb); + *hash =3D skb_get_hash(skb); + *rss_type =3D skb->l4_hash ? XDP_RSS_TYPE_L4_ANY : XDP_RSS_TYPE_NONE; + return 0; } From nobody Mon Feb 9 19:25:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A368C6FD1D for ; Thu, 30 Mar 2023 17:09:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230209AbjC3RJz (ORCPT ); Thu, 30 Mar 2023 13:09:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbjC3RJ2 (ORCPT ); Thu, 30 Mar 2023 13:09:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6B315B8E for ; Thu, 30 Mar 2023 10:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680196120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZEaVmBgKlRrwoGWi/NgZd7GVisuKZ6nuXro4uZDEt98=; b=ZmyRCz40M1v+YIls8ZHcXRis9EU5j4ur2mopdSkFSAECSlylQROgBfAdRC6zzh5azlKIEv yaLeinh2A7TzYb0cZTst0xQ34OGKxp3aXyfGOGqg70ZRiRkrwfbEmDw6V1fFuoUeEeTP6X W2yqX1Mtp/N1g3cM7sLp0dizZcAG/p8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-384-X2d2XH2iOje-FwJDF9HbgA-1; Thu, 30 Mar 2023 13:08:05 -0400 X-MC-Unique: X2d2XH2iOje-FwJDF9HbgA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B77F3810B0E; Thu, 30 Mar 2023 17:08:02 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE2ED407D441; Thu, 30 Mar 2023 17:08:01 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id F1AC330736C72; Thu, 30 Mar 2023 19:08:00 +0200 (CEST) Subject: [PATCH bpf RFC-V3 4/5] mlx4: bpf_xdp_metadata_rx_hash add xdp rss hash type From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, martin.lau@kernel.org, ast@kernel.org, daniel@iogearbox.net, alexandr.lobakin@intel.com, larysa.zaremba@intel.com, xdp-hints@xdp-project.net, anthony.l.nguyen@intel.com, yoong.siang.song@intel.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org, pabeni@redhat.com, jesse.brandeburg@intel.com, kuba@kernel.org, edumazet@google.com, john.fastabend@gmail.com, hawk@kernel.org, davem@davemloft.net Date: Thu, 30 Mar 2023 19:08:00 +0200 Message-ID: <168019608094.3557870.11753259102366277974.stgit@firesoul> In-Reply-To: <168019602958.3557870.9960387532660882277.stgit@firesoul> References: <168019602958.3557870.9960387532660882277.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update API for bpf_xdp_metadata_rx_hash() with arg for xdp rss hash type via matching indiviual Completion Queue Entry (CQE) status bits. Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen --- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 22 ++++++++++++++++++++-- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ether= net/mellanox/mlx4/en_rx.c index 4b5e459b6d49..d3f46d8b4160 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -681,14 +681,32 @@ int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx= , u64 *timestamp) return 0; } =20 -int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash) +int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, + enum xdp_rss_hash_type *rss_type) { struct mlx4_en_xdp_buff *_ctx =3D (void *)ctx; + struct mlx4_cqe *cqe =3D _ctx->cqe; + enum xdp_rss_hash_type xht =3D 0; + __be16 status; =20 if (unlikely(!(_ctx->dev->features & NETIF_F_RXHASH))) return -ENODATA; =20 - *hash =3D be32_to_cpu(_ctx->cqe->immed_rss_invalid); + *hash =3D be32_to_cpu(cqe->immed_rss_invalid); + status =3D cqe->status; + if (status & cpu_to_be16(MLX4_CQE_STATUS_TCP)) + xht =3D XDP_RSS_L4_TCP; + if (status & cpu_to_be16(MLX4_CQE_STATUS_UDP)) + xht =3D XDP_RSS_L4_UDP; + if (status & cpu_to_be16(MLX4_CQE_STATUS_IPV4|MLX4_CQE_STATUS_IPV4F)) + xht |=3D XDP_RSS_L3_IPV4; + if (status & cpu_to_be16(MLX4_CQE_STATUS_IPV6)) { + xht |=3D XDP_RSS_L3_IPV6; + if (cqe->ipv6_ext_mask) + xht |=3D XDP_RSS_L3_DYNHDR; + } + *rss_type =3D xht; + return 0; } =20 diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h b/drivers/net/eth= ernet/mellanox/mlx4/mlx4_en.h index 544e09b97483..4ac4d883047b 100644 --- a/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4_en.h @@ -798,7 +798,8 @@ int mlx4_en_netdev_event(struct notifier_block *this, =20 struct xdp_md; int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp); -int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash); +int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash, + enum xdp_rss_hash_type *rss_type); =20 /* * Functions for time stamping From nobody Mon Feb 9 19:25:39 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD8CCC6FD1D for ; Thu, 30 Mar 2023 17:09:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbjC3RJW (ORCPT ); Thu, 30 Mar 2023 13:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232215AbjC3RJF (ORCPT ); Thu, 30 Mar 2023 13:09:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D776195 for ; Thu, 30 Mar 2023 10:08:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680196093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bSAIg+VQz7pDyr1tmWltn+wlC+zEEhL6e8qNwdj8hqQ=; b=ROuaT3SDMQsyDN7AEUOmcQ2uZoRLKXwll32QbANwojsWunAIQ5n7ulVrKysRoLyWEA+y1E WkMJMj0/Kqe38Vs4gKpvtshyD0lS7/2qjOnvSUibUXD3Y8RAuE1YfPz+IM6nyfaMn5xTSj N/u/bi55cb7JqIYneWLuiNT7Tuz/UMo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-261-7dlY1MtQN3CqUPOVkfBPlA-1; Thu, 30 Mar 2023 13:08:09 -0400 X-MC-Unique: 7dlY1MtQN3CqUPOVkfBPlA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5895B3811F21; Thu, 30 Mar 2023 17:08:07 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA01A14171C3; Thu, 30 Mar 2023 17:08:06 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 0CC0A30736C72; Thu, 30 Mar 2023 19:08:06 +0200 (CEST) Subject: [PATCH bpf RFC-V3 5/5] selftests/bpf: Adjust bpf_xdp_metadata_rx_hash for new arg From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, martin.lau@kernel.org, ast@kernel.org, daniel@iogearbox.net, alexandr.lobakin@intel.com, larysa.zaremba@intel.com, xdp-hints@xdp-project.net, anthony.l.nguyen@intel.com, yoong.siang.song@intel.com, boon.leong.ong@intel.com, intel-wired-lan@lists.osuosl.org, pabeni@redhat.com, jesse.brandeburg@intel.com, kuba@kernel.org, edumazet@google.com, john.fastabend@gmail.com, hawk@kernel.org, davem@davemloft.net Date: Thu, 30 Mar 2023 19:08:06 +0200 Message-ID: <168019608600.3557870.7120119859607204078.stgit@firesoul> In-Reply-To: <168019602958.3557870.9960387532660882277.stgit@firesoul> References: <168019602958.3557870.9960387532660882277.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen --- .../selftests/bpf/prog_tests/xdp_metadata.c | 2 ++ .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 14 +++++++++----- tools/testing/selftests/bpf/progs/xdp_metadata.c | 6 +++--- tools/testing/selftests/bpf/progs/xdp_metadata2.c | 7 ++++--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 2 +- tools/testing/selftests/bpf/xdp_metadata.h | 1 + 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/= testing/selftests/bpf/prog_tests/xdp_metadata.c index aa4beae99f4f..8c5e98da9ae9 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c @@ -273,6 +273,8 @@ static int verify_xsk_metadata(struct xsk *xsk) if (!ASSERT_NEQ(meta->rx_hash, 0, "rx_hash")) return -1; =20 + ASSERT_EQ(meta->rx_hash_type, 0, "rx_hash_type"); + xsk_ring_cons__release(&xsk->rx, 1); refill_rx(xsk, comp_addr); =20 diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/te= sting/selftests/bpf/progs/xdp_hw_metadata.c index 4c55b4d79d3d..7b3fc12e96d6 100644 --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c @@ -14,8 +14,8 @@ struct { =20 extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, __u64 *timestamp) __ksym; -extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, - __u32 *hash) __ksym; +extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash, + enum xdp_rss_hash_type *rss_type) __ksym; =20 SEC("xdp") int rx(struct xdp_md *ctx) @@ -74,10 +74,14 @@ int rx(struct xdp_md *ctx) else meta->rx_timestamp =3D 0; /* Used by AF_XDP as not avail signal */ =20 - if (!bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash)) - bpf_printk("populated rx_hash with %u", meta->rx_hash); - else + if (!bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type)) { + bpf_printk("populated rx_hash:0x%X type:0x%X", + meta->rx_hash, meta->rx_hash_type); + if (!(meta->rx_hash_type & XDP_RSS_L4)) + bpf_printk("rx_hash low quality L3 hash type"); + } else { meta->rx_hash =3D 0; /* Used by AF_XDP as not avail signal */ + } =20 return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS); } diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testi= ng/selftests/bpf/progs/xdp_metadata.c index 77678b034389..d151d406a123 100644 --- a/tools/testing/selftests/bpf/progs/xdp_metadata.c +++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c @@ -21,8 +21,8 @@ struct { =20 extern int bpf_xdp_metadata_rx_timestamp(const struct xdp_md *ctx, __u64 *timestamp) __ksym; -extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, - __u32 *hash) __ksym; +extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash, + enum xdp_rss_hash_type *rss_type) __ksym; =20 SEC("xdp") int rx(struct xdp_md *ctx) @@ -56,7 +56,7 @@ int rx(struct xdp_md *ctx) if (timestamp =3D=3D 0) meta->rx_timestamp =3D 1; =20 - bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash); + bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type); =20 return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS); } diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata2.c b/tools/test= ing/selftests/bpf/progs/xdp_metadata2.c index cf69d05451c3..85f88d9d7a78 100644 --- a/tools/testing/selftests/bpf/progs/xdp_metadata2.c +++ b/tools/testing/selftests/bpf/progs/xdp_metadata2.c @@ -5,17 +5,18 @@ #include #include =20 -extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, - __u32 *hash) __ksym; +extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash, + enum xdp_rss_hash_type *rss_type) __ksym; =20 int called; =20 SEC("freplace/rx") int freplace_rx(struct xdp_md *ctx) { + enum xdp_rss_hash_type type =3D 0; u32 hash =3D 0; /* Call _any_ metadata function to make sure we don't crash. */ - bpf_xdp_metadata_rx_hash(ctx, &hash); + bpf_xdp_metadata_rx_hash(ctx, &hash, &type); called++; return XDP_PASS; } diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/= selftests/bpf/xdp_hw_metadata.c index 1c8acb68b977..4ca29e0c9646 100644 --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c @@ -141,7 +141,7 @@ static void verify_xdp_metadata(void *data) meta =3D data - sizeof(*meta); =20 printf("rx_timestamp: %llu\n", meta->rx_timestamp); - printf("rx_hash: %u\n", meta->rx_hash); + printf("rx_hash: 0x%X RSS type:0x%X\n", meta->rx_hash, meta->rx_hash_type= ); } =20 static void verify_skb_metadata(int fd) diff --git a/tools/testing/selftests/bpf/xdp_metadata.h b/tools/testing/sel= ftests/bpf/xdp_metadata.h index f6780fbb0a21..899da872fee1 100644 --- a/tools/testing/selftests/bpf/xdp_metadata.h +++ b/tools/testing/selftests/bpf/xdp_metadata.h @@ -12,4 +12,5 @@ struct xdp_meta { __u64 rx_timestamp; __u32 rx_hash; + __u32 rx_hash_type; };