From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mail.toke.dk (Postfix) with ESMTPS id 1BF159C63B4 for ; Fri, 25 Nov 2022 18:53:16 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yh5ezbI+ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669398795; 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: in-reply-to:in-reply-to:references:references; bh=UxymgvoRb75YnJ81c1gkcFnYTyArrxEPhdaiOtE1h3M=; b=Yh5ezbI+rKtxFM+BgC9OHIwOZgN5C5+0OTSAoewZuwt3QnIUPUs+7HT6IdKJf8pK73qaj7 lVheTTEkhEBJcwFKjQeRul/53h3sm9zA5ih9y8MUBpvE/8lBWKqV0Ho0YMoCO7hPfOCtPw Nl0IK8esMAx+xQqUlsbCzDBz4mQ4gXE= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-629-vziMybIyOyC0jIxbBkoNKw-1; Fri, 25 Nov 2022 12:53:11 -0500 X-MC-Unique: vziMybIyOyC0jIxbBkoNKw-1 Received: by mail-ej1-f72.google.com with SMTP id hr21-20020a1709073f9500b007b29ccd1228so2513410ejc.16 for ; Fri, 25 Nov 2022 09:53:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UxymgvoRb75YnJ81c1gkcFnYTyArrxEPhdaiOtE1h3M=; b=ctOxx3QUR6gQO0kZZvlrPLudGN0AAkyPsAlSQOmYC5IAgfmsZiUDLARtirrKVHG9C7 uleQSR8MG8ZersT34EhfdcYiQuCzL2mXmCfhjPFwVowHU6UnNeZjPAJ67BmM4aeNGLvs ZdwgbwM/tkEcDrimhPl4E9ZvjXutm1FIyAQmxeDvLYTrrPPdjsOaBfTMh6cFPK8W0zEe qffDx5fw7bVzU5hWlJFH22/rKSKu8nOuMVKIVFF/qvbzPcC62CvJxAvNzkRACl7PBVSR ds2fT2OXehNHtPjsFSiOqgGwYduw4A7im5TIYKAyFkO8hPmN1nrxgZwty1IdQWpukU1h OLLg== X-Gm-Message-State: ANoB5pl0lQRsOy3DGaZppjq078/P34rkGvjrH9KX/MapLpH2+nKS+unT dVg6i106SD9PQZ0brB+nW8M9+eim0mFEhJD6Yp36bJOq4tZV5iFqx4jw2RbvQ9J4f3qNT2GKtOi gElyQ6gVAbIUNIV6xDz62 X-Received: by 2002:a05:6402:5406:b0:467:4b3d:f2ed with SMTP id ev6-20020a056402540600b004674b3df2edmr19275524edb.101.1669398787602; Fri, 25 Nov 2022 09:53:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf5R8pWavkI3tbvmohJtTsOG5ZrCTcOHNS6Z8g5HUL9eMSaRf2lfX9ce0BuGT57XtBntrtFBSA== X-Received: by 2002:a05:6402:5406:b0:467:4b3d:f2ed with SMTP id ev6-20020a056402540600b004674b3df2edmr19275310edb.101.1669398784850; Fri, 25 Nov 2022 09:53:04 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id e22-20020a50ec96000000b00461aca1c7b6sm2027996edr.6.2022.11.25.09.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 09:53:04 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 2D30B7EB86B; Fri, 25 Nov 2022 18:53:02 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Stanislav Fomichev , bpf@vger.kernel.org In-Reply-To: <20221121182552.2152891-3-sdf@google.com> References: <20221121182552.2152891-1-sdf@google.com> <20221121182552.2152891-3-sdf@google.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Fri, 25 Nov 2022 18:53:02 +0100 Message-ID: <87mt8e2a69.fsf@toke.dk> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Message-ID-Hash: 3LQ3OJGBRG3MNNF37CHHLUVJM7BJ6YT5 X-Message-ID-Hash: 3LQ3OJGBRG3MNNF37CHHLUVJM7BJ6YT5 X-MailFrom: toke@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org X-Mailman-Version: 3.3.7 Precedence: list Subject: [xdp-hints] Re: [PATCH bpf-next v2 2/8] bpf: XDP metadata RX kfuncs List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Stanislav Fomichev writes: > There is an ndo handler per kfunc, the verifier replaces a call to the > generic kfunc with a call to the per-device one. > > For XDP, we define a new kfunc set (xdp_metadata_kfunc_ids) which > implements all possible metatada kfuncs. Not all devices have to > implement them. If kfunc is not supported by the target device, > the default implementation is called instead. BTW, this "the default implementation is called instead" bit is not included in this version... :) [...] > +#ifdef CONFIG_DEBUG_INFO_BTF > +BTF_SET8_START(xdp_metadata_kfunc_ids) > +#define XDP_METADATA_KFUNC(name, str) BTF_ID_FLAGS(func, str, 0) > +XDP_METADATA_KFUNC_xxx > +#undef XDP_METADATA_KFUNC > +BTF_SET8_END(xdp_metadata_kfunc_ids) > + > +static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = { > + .owner = THIS_MODULE, > + .set = &xdp_metadata_kfunc_ids, > +}; > + > +u32 xdp_metadata_kfunc_id(int id) > +{ > + return xdp_metadata_kfunc_ids.pairs[id].id; > +} > +EXPORT_SYMBOL_GPL(xdp_metadata_kfunc_id); So I was getting some really weird values when testing (always getting a timestamp value of '1'), and it turns out to be because this way of looking up the ID doesn't work: The set is always sorted by the BTF ID, not the order it was defined. Which meant that the mapping code got the functions mixed up, and would call a different one instead (so the timestamp value I was getting was really the return value of rx_hash_enabled()). I fixed it by building a secondary lookup table as below; feel free to incorporate that (or if you can come up with a better way, go ahead!). -Toke diff --git a/net/core/xdp.c b/net/core/xdp.c index e43f7d4ef4cf..dc0a9644dacc 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -738,6 +738,15 @@ XDP_METADATA_KFUNC_xxx #undef XDP_METADATA_KFUNC BTF_SET8_END(xdp_metadata_kfunc_ids) +static struct xdp_metadata_kfunc_map { + const char *fname; + u32 btf_id; +} xdp_metadata_kfunc_lookup_map[MAX_XDP_METADATA_KFUNC] = { +#define XDP_METADATA_KFUNC(name, str) { .fname = __stringify(str) }, +XDP_METADATA_KFUNC_xxx +#undef XDP_METADATA_KFUNC +}; + static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = { .owner = THIS_MODULE, .set = &xdp_metadata_kfunc_ids, @@ -745,13 +754,41 @@ static const struct btf_kfunc_id_set xdp_metadata_kfunc_set = { u32 xdp_metadata_kfunc_id(int id) { - return xdp_metadata_kfunc_ids.pairs[id].id; + return xdp_metadata_kfunc_lookup_map[id].btf_id; } EXPORT_SYMBOL_GPL(xdp_metadata_kfunc_id); static int __init xdp_metadata_init(void) { - return register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &xdp_metadata_kfunc_set); + const struct btf *btf; + int i, j, ret; + + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &xdp_metadata_kfunc_set); + if (ret) + return ret; + + btf = bpf_get_btf_vmlinux(); + + for (i = 0; i < MAX_XDP_METADATA_KFUNC; i++) { + u32 btf_id = xdp_metadata_kfunc_ids.pairs[i].id; + const struct btf_type *t; + const char *name; + + t = btf_type_by_id(btf, btf_id); + if (WARN_ON_ONCE(!t || !t->name_off)) + continue; + + name = btf_name_by_offset(btf, t->name_off); + + for (j = 0; j < MAX_XDP_METADATA_KFUNC; j++) { + if (!strcmp(name, xdp_metadata_kfunc_lookup_map[j].fname)) { + xdp_metadata_kfunc_lookup_map[j].btf_id = btf_id; + break; + } + } + } + + return 0; } late_initcall(xdp_metadata_init); #else /* CONFIG_DEBUG_INFO_BTF */