From nobody Wed Feb 11 22:55:57 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 44CAAC77B6E for ; Wed, 12 Apr 2023 18:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229968AbjDLSgy (ORCPT ); Wed, 12 Apr 2023 14:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbjDLSgu (ORCPT ); Wed, 12 Apr 2023 14:36:50 -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 92EA12D67 for ; Wed, 12 Apr 2023 11:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681324524; 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=sbo5K370N1ezyO8Oyot/jMfQT2LDllm8q8rGrWDuStg=; b=PyOmzWYK6kSoLKYLSegIWQIJAjODUkg+GvoAvB0EQL4hmZM4qkUiU9kRF5pchQmzxZ1Tuk z8AzcvibKyqicVs8i4U+cGl2D5jj0wsrDlxwvssLcQCUaVkgw/gKRaQsOK+YN4OuHluy9X SusAdfOcgjAPGs4aHOWzSqu36Juv4Ic= 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-519-2W7U_7cUP4eevsDphnyHfw-1; Wed, 12 Apr 2023 14:35:19 -0400 X-MC-Unique: 2W7U_7cUP4eevsDphnyHfw-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 5026F8996F3; Wed, 12 Apr 2023 18:35:18 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09C7740C20FA; Wed, 12 Apr 2023 18:35:18 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 23D69307372E8; Wed, 12 Apr 2023 20:35:17 +0200 (CEST) Subject: [PATCH bpf V9 1/6] selftests/bpf: xdp_hw_metadata remove bpf_printk and add counters From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= 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, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, linux-rdma@vger.kernel.org Date: Wed, 12 Apr 2023 20:35:17 +0200 Message-ID: <168132451707.317773.15960209122204110352.stgit@firesoul> In-Reply-To: <168132448251.317773.2526885806604122764.stgit@firesoul> References: <168132448251.317773.2526885806604122764.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 The tool xdp_hw_metadata can be used by driver developers implementing XDP-hints metadata kfuncs. Remove all bpf_printk calls, as the tool already transfers all the XDP-hints related information via metadata area to AF_XDP userspace process. Add counters for providing remaining information about failure and skipped packet events. Signed-off-by: Jesper Dangaard Brouer Acked-by: Stanislav Fomichev --- .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 36 ++++++++++++----= ---- tools/testing/selftests/bpf/xdp_hw_metadata.c | 4 ++ 2 files changed, 24 insertions(+), 16 deletions(-) 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..8a042343cb0c 100644 --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c @@ -12,6 +12,10 @@ struct { __type(value, __u32); } xsk SEC(".maps"); =20 +volatile __u64 pkts_skip =3D 0; +volatile __u64 pkts_fail =3D 0; +volatile __u64 pkts_redir =3D 0; + 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, @@ -26,7 +30,7 @@ int rx(struct xdp_md *ctx) struct udphdr *udp =3D NULL; struct iphdr *iph =3D NULL; struct xdp_meta *meta; - int ret; + int err; =20 data =3D (void *)(long)ctx->data; data_end =3D (void *)(long)ctx->data_end; @@ -46,17 +50,20 @@ int rx(struct xdp_md *ctx) udp =3D NULL; } =20 - if (!udp) + if (!udp) { + pkts_skip++; return XDP_PASS; + } =20 - if (udp->dest !=3D bpf_htons(9091)) + /* Forwarding UDP:9091 to AF_XDP */ + if (udp->dest !=3D bpf_htons(9091)) { + pkts_skip++; return XDP_PASS; + } =20 - bpf_printk("forwarding UDP:9091 to AF_XDP"); - - ret =3D bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta)); - if (ret !=3D 0) { - bpf_printk("bpf_xdp_adjust_meta returned %d", ret); + err =3D bpf_xdp_adjust_meta(ctx, -(int)sizeof(struct xdp_meta)); + if (err) { + pkts_fail++; return XDP_PASS; } =20 @@ -65,20 +72,19 @@ int rx(struct xdp_md *ctx) meta =3D data_meta; =20 if (meta + 1 > data) { - bpf_printk("bpf_xdp_adjust_meta doesn't appear to work"); + pkts_fail++; return XDP_PASS; } =20 - if (!bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp)) - bpf_printk("populated rx_timestamp with %llu", meta->rx_timestamp); - else + err =3D bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp); + if (err) 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 + err =3D bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash); + if (err) meta->rx_hash =3D 0; /* Used by AF_XDP as not avail signal */ =20 + pkts_redir++; return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS); } =20 diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/= selftests/bpf/xdp_hw_metadata.c index 1c8acb68b977..3b942ef7297b 100644 --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c @@ -212,7 +212,9 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq,= int server_fd) while (true) { errno =3D 0; ret =3D poll(fds, rxq + 1, 1000); - printf("poll: %d (%d)\n", ret, errno); + printf("poll: %d (%d) skip=3D%llu fail=3D%llu redir=3D%llu\n", + ret, errno, bpf_obj->bss->pkts_skip, + bpf_obj->bss->pkts_fail, bpf_obj->bss->pkts_redir); if (ret < 0) break; if (ret =3D=3D 0) From nobody Wed Feb 11 22:55:57 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 3541FC77B6E for ; Wed, 12 Apr 2023 18:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbjDLSg6 (ORCPT ); Wed, 12 Apr 2023 14:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbjDLSgv (ORCPT ); Wed, 12 Apr 2023 14:36:51 -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 E23EB3A98 for ; Wed, 12 Apr 2023 11:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681324531; 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=HL2+nZ3ony7g1DbggJ7CDo8uNVT9LxTWALi4pMFYEfg=; b=VJEEsmrqclCFaHckUB6ywD8q1ssBUx2w4rTLIp5AfO7cBCMUVQ+BqrByV5UipQkclpLk3u Q3LkVt/V4UardJp5kNwR5SJIlHrLOpLYlgdVvjk7FJnlHgvt1pobKWj7cXJ+xeaa23u6oD uq6NfCGS9tpwZ/jZpdZjTS7VaxfT5mE= 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-611-Lj9w-Z1SMoix1CmWWWIO0g-1; Wed, 12 Apr 2023 14:35:25 -0400 X-MC-Unique: Lj9w-Z1SMoix1CmWWWIO0g-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 B8EF8811E7C; Wed, 12 Apr 2023 18:35:23 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C47540C845F; Wed, 12 Apr 2023 18:35:23 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 35B53307372E8; Wed, 12 Apr 2023 20:35:22 +0200 (CEST) Subject: [PATCH bpf V9 2/6] xdp: rss hash types representation From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= 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, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, linux-rdma@vger.kernel.org Date: Wed, 12 Apr 2023 20:35:22 +0200 Message-ID: <168132452216.317773.14420724853580510802.stgit@firesoul> In-Reply-To: <168132448251.317773.2526885806604122764.stgit@firesoul> References: <168132448251.317773.2526885806604122764.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 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 contains both BITs for the L3/L4 types, and combinations to be used by drivers for their mapping tables. The enum xdp_rss_type_bits 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. Change signature for all xmo_rx_hash calls in drivers to make it compile. The RSS type implementations for each driver comes as separate patches. Fixes: 3d76a4d3d4e5 ("bpf: XDP metadata RX kfuncs") Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen Acked-by: Stanislav Fomichev --- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 3 + drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 3 + drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 3 + drivers/net/veth.c | 3 + include/linux/netdevice.h | 3 + include/net/xdp.h | 45 ++++++++++++++++++= ++++ net/core/xdp.c | 10 ++++- 7 files changed, 64 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ether= net/mellanox/mlx4/en_rx.c index 4b5e459b6d49..73d10aa4c503 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -681,7 +681,8 @@ 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; =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 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net= /ethernet/mellanox/mlx5/core/en/xdp.c index c5dae48b7932..efe609f8e3aa 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c @@ -169,7 +169,8 @@ 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) +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; =20 diff --git a/drivers/net/veth.c b/drivers/net/veth.c index c1178915496d..424e8876a16b 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1648,7 +1648,8 @@ static int veth_xdp_rx_timestamp(const struct xdp_md = *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; =20 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..a76c4ea203ea 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,50 @@ XDP_METADATA_KFUNC_xxx MAX_XDP_METADATA_KFUNC, }; =20 +enum xdp_rss_hash_type { + /* First part: Individual bits for L3/L4 types */ + 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 */ + + /* Second part: RSS hash type combinations used for driver HW mapping */ + 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_D= YNHDR, + XDP_RSS_TYPE_L4_IPV6_UDP_EX =3D XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_D= YNHDR, + XDP_RSS_TYPE_L4_IPV6_SCTP_EX =3D XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_D= YNHDR, +}; + #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..fb85aca81961 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -734,13 +734,21 @@ __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 used when calculating RSS hash value. The RSS type can be dec= oded + * via &enum xdp_rss_hash_type either matching on individual L3/L4 bits + * ``XDP_RSS_L*`` or by combined traditional *RSS Hashing Types* + * ``XDP_RSS_TYPE_L*``. * * 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) { return -EOPNOTSUPP; } From nobody Wed Feb 11 22:55:57 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 1456FC77B72 for ; Wed, 12 Apr 2023 18:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbjDLShI (ORCPT ); Wed, 12 Apr 2023 14:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjDLShC (ORCPT ); Wed, 12 Apr 2023 14:37:02 -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 C358740F2 for ; Wed, 12 Apr 2023 11:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681324534; 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=F4P5FHgst54Guyz7AOdIGfebsTZwoSbmDnoCPryHKKQ=; b=GwIeBZhm4HIw9JAY5D9+6YomtCafG2DmJ8FrSgtek99tI/SGszRoEcKW6EKIlhSfbOJWdg d9VcaytYZyjCd+uidOlqjKRG0V0yE55YdBwIxSIBBqDkN+KFMsUtVNt9rWlZEv3JpqwP23 N3I3aNmDIXpo7iOxUxQE3k2QsrFAvrA= 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-112-v-buBjvIPLev3p_EzpKltw-1; Wed, 12 Apr 2023 14:35:29 -0400 X-MC-Unique: v-buBjvIPLev3p_EzpKltw-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 96F513C10689; Wed, 12 Apr 2023 18:35:28 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CEA640C83A9; Wed, 12 Apr 2023 18:35:28 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 45987307372E8; Wed, 12 Apr 2023 20:35:27 +0200 (CEST) Subject: [PATCH bpf V9 3/6] mlx5: bpf_xdp_metadata_rx_hash add xdp rss hash type From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= 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, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, linux-rdma@vger.kernel.org Date: Wed, 12 Apr 2023 20:35:27 +0200 Message-ID: <168132452723.317773.17006189430871247933.stgit@firesoul> In-Reply-To: <168132448251.317773.2526885806604122764.stgit@firesoul> References: <168132448251.317773.2526885806604122764.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 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. Fixes: bc8d405b1ba9 ("net/mlx5e: Support RX XDP metadata") Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen Acked-by: Stanislav Fomichev --- drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c | 60 ++++++++++++++++++= ++++ include/linux/mlx5/device.h | 14 ++++- include/net/xdp.h | 2 + 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c b/drivers/net= /ethernet/mellanox/mlx5/core/en/xdp.c index efe609f8e3aa..d9d3b9e1f15a 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,15 +170,72 @@ static int mlx5e_xdp_rx_timestamp(const struct xdp_md= *ctx, u64 *timestamp) return 0; } =20 +/* 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)), +}; + +/* Invalid combinations will simply return zero, allows no boundary 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..1db19a9d26e3 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 a76c4ea203ea..76aa748e7923 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -460,10 +460,12 @@ 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_D= YNHDR, XDP_RSS_TYPE_L4_IPV6_UDP_EX =3D XDP_RSS_TYPE_L4_IPV6_UDP | XDP_RSS_L3_D= YNHDR, From nobody Wed Feb 11 22:55:57 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 C0F73C77B72 for ; Wed, 12 Apr 2023 18:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230243AbjDLSiB (ORCPT ); Wed, 12 Apr 2023 14:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjDLShh (ORCPT ); Wed, 12 Apr 2023 14:37:37 -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 EE3994490 for ; Wed, 12 Apr 2023 11:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681324538; 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=KMxLHr1nEJDBRCg1B8L488/y3xeAF5pIZJtw2W0lrWE=; b=SVHTqnwJuMrczY9I6lOsMP3bOhzCEjErPLUWrB6fXJPAh8y7er2HAw2mGLL0HAc4NffB40 3bBOIvfiiktBQadsVbRnti9mfkWI1NUijU6rTJvl4xiNiSRWL0CcrnRfIt4OLD6dZT0lvp ZdVNGXjSvm2Iy4yRxwh2wP7hz0LOAn0= 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-628-uEA3gRpPPjCm-pRWtlW3OA-1; Wed, 12 Apr 2023 14:35:34 -0400 X-MC-Unique: uEA3gRpPPjCm-pRWtlW3OA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80EE21C0690C; Wed, 12 Apr 2023 18:35:33 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A28347CD0; Wed, 12 Apr 2023 18:35:33 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 55231307372E8; Wed, 12 Apr 2023 20:35:32 +0200 (CEST) Subject: [PATCH bpf V9 4/6] veth: bpf_xdp_metadata_rx_hash add xdp rss hash type From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= 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, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, linux-rdma@vger.kernel.org Date: Wed, 12 Apr 2023 20:35:32 +0200 Message-ID: <168132453230.317773.15764647167518530046.stgit@firesoul> In-Reply-To: <168132448251.317773.2526885806604122764.stgit@firesoul> References: <168132448251.317773.2526885806604122764.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.5 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. Fixes: 306531f0249f ("veth: Support RX XDP metadata") Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen Acked-by: Stanislav Fomichev --- drivers/net/veth.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 424e8876a16b..e1b38fbf1dd9 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -1652,11 +1652,14 @@ static int veth_xdp_rx_hash(const struct xdp_md *ct= x, 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; } =20 From nobody Wed Feb 11 22:55:57 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 4FA8FC77B6E for ; Wed, 12 Apr 2023 18:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbjDLSiD (ORCPT ); Wed, 12 Apr 2023 14:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjDLShj (ORCPT ); Wed, 12 Apr 2023 14:37:39 -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 D2EC84EFD for ; Wed, 12 Apr 2023 11:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681324546; 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=cSVYWifKD7SQGSjuGFZiN+et2zmCoRo8LLSGhODudbI=; b=eYjzhbCZe23Gja2cwpK8D81DSopJymHizKtFwJci4SpfB8Ljo6AQ0oPPwmsyVFwjR1dKzK Osg88Ily2L4STwDdRLf0KW48aA10TRI2A3arPE3ggNEUy+Oc0eaNhplbGEhn/GtS32ze4o rmq8gcKNle8FLRq1c5iL0ssWd7MbEJU= 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-119-IbczlyyOObSkDDMDQ8yE3Q-1; Wed, 12 Apr 2023 14:35:39 -0400 X-MC-Unique: IbczlyyOObSkDDMDQ8yE3Q-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 92D0D800B23; Wed, 12 Apr 2023 18:35:38 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DB5940C20FA; Wed, 12 Apr 2023 18:35:38 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 64F69307372E8; Wed, 12 Apr 2023 20:35:37 +0200 (CEST) Subject: [PATCH bpf V9 5/6] mlx4: bpf_xdp_metadata_rx_hash add xdp rss hash type From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= 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, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, linux-rdma@vger.kernel.org Date: Wed, 12 Apr 2023 20:35:37 +0200 Message-ID: <168132453736.317773.2296218934638816233.stgit@firesoul> In-Reply-To: <168132448251.317773.2526885806604122764.stgit@firesoul> References: <168132448251.317773.2526885806604122764.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 via matching individual Completion Queue Entry (CQE) status bits. Fixes: ab46182d0dcb ("net/mlx4_en: Support RX XDP metadata") Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen Acked-by: Stanislav Fomichev --- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ether= net/mellanox/mlx4/en_rx.c index 73d10aa4c503..332472fe4990 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c @@ -685,11 +685,28 @@ 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 From nobody Wed Feb 11 22:55:57 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 CF0ADC77B6E for ; Wed, 12 Apr 2023 18:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230257AbjDLSiG (ORCPT ); Wed, 12 Apr 2023 14:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbjDLShj (ORCPT ); Wed, 12 Apr 2023 14:37:39 -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 971985599 for ; Wed, 12 Apr 2023 11:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681324549; 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=7uy//5CFgECnuuD4j8TxJzVmtCdrmPt1JIk+ut49L5s=; b=h6uobjmRi+5j5UF4gdjk3WHbOIAz9eEfjhMqV4vd/iJSOmE3ds9xIAn/3zehcaORL8sRbr jcdQJK/Sw95GEdeI7wSux8OzSJh4AaWvE28FsgejI6zC9pQFEF5DGYdrcA+WwhygJiLJ0J hEIikP6ItbdLTMrdOKIF4j9Gy2wvnvM= 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-339-npgSiJXBOSyiAduwrtNcDw-1; Wed, 12 Apr 2023 14:35:45 -0400 X-MC-Unique: npgSiJXBOSyiAduwrtNcDw-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 C7A6F884EC0; Wed, 12 Apr 2023 18:35:43 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.45.242.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6011C1415117; Wed, 12 Apr 2023 18:35:43 +0000 (UTC) Received: from [10.1.1.1] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 75A83307372E8; Wed, 12 Apr 2023 20:35:42 +0200 (CEST) Subject: [PATCH bpf V9 6/6] selftests/bpf: Adjust bpf_xdp_metadata_rx_hash for new arg From: Jesper Dangaard Brouer To: bpf@vger.kernel.org, Stanislav Fomichev , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= 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, tariqt@nvidia.com, saeedm@nvidia.com, leon@kernel.org, linux-rdma@vger.kernel.org Date: Wed, 12 Apr 2023 20:35:42 +0200 Message-ID: <168132454243.317773.18430532234572392637.stgit@firesoul> In-Reply-To: <168132448251.317773.2526885806604122764.stgit@firesoul> References: <168132448251.317773.2526885806604122764.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 Update BPF selftests to use the new RSS type argument for kfunc bpf_xdp_metadata_rx_hash. Signed-off-by: Jesper Dangaard Brouer Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen Acked-by: Stanislav Fomichev --- .../selftests/bpf/prog_tests/xdp_metadata.c | 2 ++ .../testing/selftests/bpf/progs/xdp_hw_metadata.c | 10 +++++----- 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 | 6 +++++- tools/testing/selftests/bpf/xdp_metadata.h | 4 ++++ 6 files changed, 23 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 8a042343cb0c..20652b55d91d 100644 --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c @@ -18,8 +18,8 @@ volatile __u64 pkts_redir =3D 0; =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) @@ -80,9 +80,9 @@ int rx(struct xdp_md *ctx) if (err) meta->rx_timestamp =3D 0; /* Used by AF_XDP as not avail signal */ =20 - err =3D bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash); - if (err) - meta->rx_hash =3D 0; /* Used by AF_XDP as not avail signal */ + err =3D bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type= ); + if (err < 0) + meta->rx_hash_err =3D err; /* Used by AF_XDP as no hash signal */ =20 pkts_redir++; 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 3b942ef7297b..987cf0db5ebc 100644 --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c @@ -141,7 +141,11 @@ 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); + if (meta->rx_hash_err < 0) + printf("No rx_hash err=3D%d\n", meta->rx_hash_err); + else + printf("rx_hash: 0x%X with 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..0c4624dc6f2f 100644 --- a/tools/testing/selftests/bpf/xdp_metadata.h +++ b/tools/testing/selftests/bpf/xdp_metadata.h @@ -12,4 +12,8 @@ struct xdp_meta { __u64 rx_timestamp; __u32 rx_hash; + union { + __u32 rx_hash_type; + __s32 rx_hash_err; + }; };