From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796471159; b=qwvt1T0LG1BzYWyOraKh7VfNa1K0lFAL/SPQa6qaPVM40wEPQ6hJwzHD+LX808A4kFkF VvdGB26zdIJCY6uVkxXzwP3UYviJQZVnE/tZviaiaK/1APZGWHbwTQvV3dNoojpJtowmy jTJjH3dNBiegnmOwvyfFkU1nSmuNeAZ4ilYuI7piUQHvEeuNmo0pdgWIuns6ZamSKtSJn ReRDJMltVFDP5GeGSaqbQ+wMPaHcESgOS1vb1RVTpHWxaKqU/NUYTuFsyXcvHUFdLfDCd OTRxDv9pnga7xGF5tf9re3H3yfoyQov814XtkfgHq9venDKPfDgWx1RrbddkK/RiRmg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796471159; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From: X-Google-Original-From:Date:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=eDsT/jA62Q47cN8PeDZl/ZZ5NSnrh7hFw280o/Fj0Bg=; b=t+YF9pe/93ZwFKJIZjXOowFDMHxxlWUB8rjEoR58aOMN4HFkGxLrlALsfU4hOlEBqxyJ +TAzInue/lAws7EUpW86drtTmJZ/fRs3wXiPMIBmfp3V/BWpK7LLLUpfxSH+gUAThn4Bw 8KlubDhMtTgh6HxQleJBsj7LOh7++zSDhrAxmmS1b9oeCHJn22zHZE4+2nLxwOq4jbthO g1ujXHCzaAXyGMTneszQ9f2wsWV2XMLzNhh0mv3gGZBVjtElJlB9f+T4y5xnSRACRCZoQ dqHbqv4La+CWLPVKZ9kQeM53BrN7192hrIEOnu2nts8JrFnlAmGbarNRMke3w/gPVfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BfxKf25v; arc=none smtp.remote-ip=209.85.221.53 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B68FA606A322 for ; Sat, 5 Dec 2026 11:45:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B68FA606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BfxKf25v Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-4ac109a8a12so1005761f8f.3 for ; Sat, 05 Dec 2026 03:45:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796471157; x=1797075957; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=eDsT/jA62Q47cN8PeDZl/ZZ5NSnrh7hFw280o/Fj0Bg=; b=BfxKf25vtwB0U5aT96OgZmPY6O6twRiscv/1L2eVBWM0q2I0VOBqP0LTXIKz5RWxIR wUN8ShCZjTA0J82g/mXNvMkrCNd2vGkqsgat2XlMy/1pK78WRs11vL8yohzOTdDBreZA a8Ct7jyAbZbkXj17PincWOFYI24VMSwo9qcs+Pw5sZBu5eIA6NBhDMBRof7uKUL/0/LX XSr74JMCSxIsn9fkySCCaWwMXDbt7S1DCWx3RcDhkdpSPW87klFK9SHSqIewzWY5BxSG ihN8LhV9vxxf2VvqxAJ2EHWhobnyQ4G7seUCYnMxPVdFclGKR18av6NQNc7eNU9uN4wI 01UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796471157; x=1797075957; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=eDsT/jA62Q47cN8PeDZl/ZZ5NSnrh7hFw280o/Fj0Bg=; b=KDbYdmzAjM6aR75eOFG7+yxksHv1TCx6R9+CXtUVyg7xyl6JmjGbh5URUiGvUmRrVK FNuhzEROIHQoa5TJSILj4ccm65GOK88zPzuM89Bqf7nS4TZJVor7/uxucuSr4k8s2F5c sy5mvivpbsP07EgrpUqc+1xv7arssKynsOzTwGCTkV+KCHksQyUra00jOKbJK+u129l/ eu3g2qUk8QKNJCNWAEFcgqEc0njt8+ZLvKVt3YxXb8bKxaJkzJXIulOpr/Bg2hJ1H+qq 2pXOpO3vtBjBknOdsAh/akk0VinI0nFz5SwFQGREppSZDow+0Qbz1zWB4H4TqKBeBpe9 c9qA== X-Gm-Message-State: AB4q+uFogrIQzFwkJUUang/pV+GOvVs8ckk0KcC+wfKgIPUSK75/LueM qUw7ky7VFvsQCxg4Bu64OKy497i97Kn1LCTZVOI3AT8GsdywWAJXsK+x X-Gm-Gg: AZFdTZeOKBCed4cZvtrPEpN4ru0v/JaT0T7N8e/YbjHkRkaFxsuyCHjI2R2dF6HaAYS kol41UX30x/ZSHWByKYE19bdZChYNYBr48Xdm4Cu3exnKU8CLiguh2CaxXsWXF1WbGyKR3tmsz5 L/mTLefyWa//UJ33yq1i/BQwyt92seVsj+jPtrEbyKXgVXxvXaAX86YpmZeBb6joc1Lbw+uAJK1 EVASlapL6Tw4PA9OEw8hFFeI7KQXPFshDtJL3MgFVSzpp6Lduw4c0T2hydQq7+BZ9niBWH1LV9N XLuwHQpveMNa7jjp6rMzGz/zrUaeUKzYkheW32YwAcpXtGMGdmm/GgPyZfcOBg24aBusXxNYdLq a09aisLhrDag+h2fyXl9KLw747i6pklRK7UsCliw4gmtJc2HTNikSF/iVgU5tZrsh+9xNJfhn5T qrRjx6QEA9JS5JZ1nIY7b7tqaSsY7cIZTbLY6syn0kbOAlYlmxzg2y1v851TsX36g162tSeI+MM nifknD1bH8MSdBmF0CQzw3yYH3iRjyR9gS4lGzId2dv9KqQ4XsOYz5YmoAQ5eU7Ejglx+cFztCu RvdpqD6Ado/mg93zaqmYLA== X-Received: by 2002:a05:6000:4501:b0:4b4:2ce4:6dc1 with SMTP id ffacd0b85a97d-4d1ea4b3fb9mr7549283f8f.44.1796471156930; Sat, 05 Dec 2026 03:45:56 -0800 (PST) Received: from krava ([2a02:8308:a00c:e200::25dc]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d16e0b0c8csm10419898f8f.2.2026.12.05.03.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 03:45:56 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Sat, 5 Dec 2026 12:45:53 +0100 To: Anton Protopopov Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Emil Tsalapatis , Ihor Solodrai , John Fastabend , Viktor Malik Subject: Re: [PATCH v2 bpf-next 3/4] libbpf: Look up the functions of a module first Message-ID: References: <20261204154705.1411391-1-a.s.protopopov@gmail.com> <20261204154705.1411391-4-a.s.protopopov@gmail.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204154705.1411391-4-a.s.protopopov@gmail.com> On Fri, Dec 04, 2026 at 03:47:02PM +0000, Anton Protopopov wrote: > For "mod:func" libbpf looks func up in the BTF of the module, and > that lookup searches the types of vmlinux first. If vmlinux has a > function of that name too, libbpf takes its ID, and the program > attaches to the module function with the vmlinux prototype. The > kernel now refuses this when the module has a function of its own of > that name. A glob of a tracing multi program for a module walks the > types of vmlinux too, and takes both IDs for such a name. > > Look up the function of the module first, and take the one of > vmlinux only if the module has no function of that name. The dedup > of BTF merges a module function of the same prototype into the > vmlinux one, which is then the type of the module function. nice, as Alexei noted, this change is still needed because of the duplicate ids check in the multi link attach, one nit below Acked-by: Jiri Olsa thanks, jirka > > Fixes: 8f8a024272f3 ("libbpf: support "module: Function" syntax for tracing programs") > Fixes: f2aa370dfe57 ("libbpf: Add support to create tracing multi link") > Signed-off-by: Anton Protopopov > --- > tools/lib/bpf/libbpf.c | 75 ++++++++++++++++++++++++++++-------------- > 1 file changed, 51 insertions(+), 24 deletions(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 8ed4786e0e51..72330598a0f8 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -11869,7 +11869,14 @@ static int find_btf_by_prefix_kind(const struct btf *btf, const char *prefix, > */ > if (ret < 0 || ret >= sizeof(btf_type_name)) > return -ENAMETOOLONG; > - return btf__find_by_name_kind(btf, btf_type_name, kind); > + /* > + * A function of a module first, then the one of vmlinux, which the > + * dedup of BTF merges a module function of the same prototype into > + */ > + ret = btf__find_by_name_kind_own(btf, btf_type_name, kind); > + if (ret > 0 || !btf__base_btf(btf)) > + return ret; > + return btf__find_by_name_kind(btf__base_btf(btf), btf_type_name, kind); > } > > static inline int find_attach_btf_id(struct btf *btf, const char *name, > @@ -13887,40 +13894,60 @@ bool btf_type_is_traceable_func(const struct btf *btf, const struct btf_type *t) > return true; > } > > +static int add_func_id_by_glob(const struct btf *btf, __u32 type_id, const char *pattern, > + bool skip_own, __u32 **ids, size_t *cap, size_t *cnt) > +{ > + const struct btf_type *t = btf__type_by_id(btf, type_id); > + const char *name; > + > + if (btf_kind(t) != BTF_KIND_FUNC) > + return 0; > + name = btf__name_by_offset(btf, t->name_off); > + if (!name || !glob_match(name, pattern)) > + return 0; > + if (!btf_type_is_traceable_func(btf, t)) > + return 0; > + if (skip_own && btf__find_by_name_kind_own(btf, name, BTF_KIND_FUNC) > 0) > + return 0; > + > + if (libbpf_ensure_mem((void **) ids, cap, sizeof(**ids), *cnt + 1)) > + return -ENOMEM; > + (*ids)[(*cnt)++] = type_id; > + return 0; > +} > + > static int > collect_btf_func_ids_by_glob(const struct btf *btf, const char *pattern, __u32 **ids) > { > - __u32 type_id, nr_types = btf__type_cnt(btf); > + const struct btf *base_btf = btf__base_btf(btf); > + __u32 type_id, start_id, nr_types = btf__type_cnt(btf); > size_t cap = 0, cnt = 0; > + int err; > > if (!pattern) > return -EINVAL; > > - for (type_id = 1; type_id < nr_types; type_id++) { > - const struct btf_type *t = btf__type_by_id(btf, type_id); > - const char *name; > - int err; > - > - if (btf_kind(t) != BTF_KIND_FUNC) > - continue; > - name = btf__name_by_offset(btf, t->name_off); > - if (!name) > - continue; > - > - if (!glob_match(name, pattern)) > - continue; > - if (!btf_type_is_traceable_func(btf, t)) > - continue; > - > - err = libbpf_ensure_mem((void **) ids, &cap, sizeof(**ids), cnt + 1); > - if (err) { > - free(*ids); > - return -ENOMEM; > - } > - (*ids)[cnt++] = type_id; > + /* > + * The functions of a module first, then the ones of vmlinux, which the > + * dedup of BTF merges module functions of the same prototype into > + */ > + start_id = base_btf ? btf__type_cnt(base_btf) : 1; > + for (type_id = start_id; type_id < nr_types; type_id++) { > + err = add_func_id_by_glob(btf, type_id, pattern, false, ids, &cap, &cnt); nit, add_func_id_by_glob fails only with -ENOMEM, so we can drop err and return -ENOMEM directly on the error path > + if (err) > + goto err_out; > + } > + for (type_id = 1; type_id < start_id; type_id++) { > + err = add_func_id_by_glob(btf, type_id, pattern, true, ids, &cap, &cnt); > + if (err) > + goto err_out; > } > > return cnt; > + > +err_out: > + free(*ids); > + return err; > } > > static int collect_func_ids_by_glob(const struct bpf_program *prog, const char *pattern, __u32 **ids) > -- > 2.43.0 >