From nobody Thu Apr 2 18:53:51 2026 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 489513A6EE5 for ; Thu, 26 Mar 2026 20:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557823; cv=none; b=l/dhAfsXIF+5U/H3Xr14+gWL+YBO4WxZEkrIj9dF0tKl7YTogCkW8xII3dBmtSy0Zm7RuS8YtTV5eFgOMADhhrxBCmtsstxWIFM1C191hL5GIUagspSSfHO5t6ZhSnQEujXfakfdGrqFkcjVFJXf+zyx314/cyh+Y3xDubF4TYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774557823; c=relaxed/simple; bh=egOiypsJwjF8/djFU7mQxlppV2Rai+dGuGmpTuFy1W8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uRRGoBBV6lvpDJUr2q8AF5T/CkKo1EqS5cla3PY03UhkzVkAUqBMetRUm/D3dMtuizhJV9Atd/OtnA/N00zL7Cr/Y2dwPbewkdD8gK0bPjrKxsLo/VCldN0SoULMhO+/5wRwtx9abkTezo30UnjWH6UdEpKn8huES6EhUHL677M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k55tI3hk; arc=none smtp.client-ip=209.85.215.182 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.b="k55tI3hk" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c7412b07f22so1153355a12.0 for ; Thu, 26 Mar 2026 13:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774557821; x=1775162621; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ig5sdFszUgYcFHRRqi6hTRlPGGoN0upuWT6iWptjeag=; b=k55tI3hkB/gLrtGUwhFxDVOwPnH1TMdWh2RVsGiFj6cut1/4jPJAvik323Ycb0DYUN 6X8+Gw3lbecJLxKoGVADAdUGjv6TUNXSvE6FoD+NtLTHHGytGLC+yNRqxRnPucYFkP2t P5VXbMInXrrepTQJVb19RETCBz16lHFe68sBdSEnVh75MaZG0DX5H13YjcmpK8Axn4vs EFxh3uCr5QFUzGKDC8HqoK6TUrxn/mQUuJ2V/9l0U6BsDEJiPJ0TJVTDXhUGlsJRCpFZ FeR4FYnM3+TIG0AgWjRdeIPhrNRcM745Buvo5ct+vNvyti6xmwi8J9vc9KBD6EN0afuZ DDZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774557821; x=1775162621; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ig5sdFszUgYcFHRRqi6hTRlPGGoN0upuWT6iWptjeag=; b=PaUhMpjJJVMKYoo7EvugySAZPUerqvCYNUjbtbtPRvjbzxj7KKDLXNsSoWI/9UXpUU /JN9KI7Watf9reWbymhb2s86u3WjhOqVQTUosSgDqIMT5xN0tyhzYW+jUuH+hEddm8tu L/JW+s1V5Uo9OW6+X+w74NK01SPeHKVQtbMw7v595fp2hLnO0aoVOa+d2I34eKDr/vVY rjxKSll6RhFFd5Se9GrgYxiYLRb16jnWnf8LnBxOmaKfIKmCiee0DqrUgDzyxI6mk7IZ f5ktRH8i2tQ4R+GJCLL1c4xb4iCkJddBOkSmSUuiQYkKLb/rz4aOmDP1VkjamoGBjI8O tuOg== X-Gm-Message-State: AOJu0YwAmzOsykKa9cxh16kEIBCtuMaYyclfVcf3mf2KrBr5B4SGEw6N u3JO2vf13//6y+iQwatvE16e4zWrPxGusndkezAHycA057ovmDTzM+zG X-Gm-Gg: ATEYQzzTNzJ7WDaQB7S42ogSUgNHN1zjsx5FbPlZdxtkHvevtmHXOp/SBXPFhQJUYoY 1I5Nw1iIk1Jxk4fKkOsVPppzTXE0QJtyMAkYykgLJ4dlKsf4eEKVFeMhS06pQcdA6kJ+RLG0Z9v DpV5W5TNlW/5vVGKnzG4+1wCgAy4EHcdWDN3ahAOqwrIlKvNuC4wPqm+mcdti6Urhdj+mPvOe4N qja9Ccz/dMfAw1/7i8e3ZmnhzMTlG2Z1YmfhWv99PacoAzDtWtwifiBy84/JiKfutp05D9o714K L1jFrq39HSdkW9QP9BmzM243VsdZV5UfChoFtJ4SNEVIuqlL9sOsq5Pu/CnR3sjX0iSuqvCJrZW x3s/FFqLBRW/itDB7vHMnpSDg2rDP/nCsbglIEaVnPkyqlpH7MQfZqtYXCytLiM3u7qLgzRffu5 kH59e8vDeRAMxZ/VjzSOywXuW/HbdeniQLAyfjoEOHaNIyGl9sL8oWkHR1cKE3BJpGfktbtbkdN 1I= X-Received: by 2002:a17:902:d4cb:b0:2b0:6ba2:3d78 with SMTP id d9443c01a7336-2b0c48136a4mr28286055ad.3.1774557821400; Thu, 26 Mar 2026 13:43:41 -0700 (PDT) Received: from mi-HP-ProDesk-680-G6-PCI-Microtower-PC.mioffice.cn ([43.224.245.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b0bc90d2cdsm46885085ad.75.2026.03.26.13.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 13:43:41 -0700 (PDT) From: zhidao su X-Google-Original-From: zhidao su To: bpf@vger.kernel.org Cc: linux-kernel@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, sched-ext@lists.linux.dev, zhidao su Subject: [PATCH] libbpf: resolve versioned kfuncs by exact name before essential-name lookup Date: Fri, 27 Mar 2026 04:43:35 +0800 Message-ID: <20260326204335.3756885-1-suzhidao@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some kfuncs use KF_IMPLICIT_ARGS and export both a base name (where the verifier strips the implicit aux parameter from the prototype) and a versioned name with additional user-visible parameters (e.g. scx_bpf_dsq_move_to_local vs scx_bpf_dsq_move_to_local___v2). When a BPF program declares a weak __ksym with a flavor suffix such as func___v2, libbpf strips the suffix to obtain the essential name and looks up the base entry first. For KF_IMPLICIT_ARGS kfuncs the base entry has fewer parameters (aux was stripped); the prototype compatibility check against the versioned declaration (which has the extra user parameter) then fails, and libbpf leaves the weak symbol unresolved even though a perfectly-matching versioned kernel entry exists. Fix by trying an exact-name lookup first when the symbol has an essential name (i.e. it has a flavor suffix). If the exact name is found in kernel BTF and its prototype is compatible, use it directly. Only fall through to the essential-name lookup when the exact name is absent or incompatible. Signed-off-by: zhidao su --- tools/lib/bpf/libbpf.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 0be7017800fe..80e495aebe68 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8630,6 +8630,40 @@ static int bpf_object__resolve_ksym_func_btf_id(stru= ct bpf_object *obj, =20 local_func_proto_id =3D ext->ksym.type_id; =20 + /* + * For kfuncs with a flavor suffix (e.g. "func___v2"), first try the + * exact name. If the exact name exists in kernel BTF and its + * prototype is compatible, use it directly. This is necessary for + * KF_IMPLICIT_ARGS kfuncs that export both a base name (with the + * implicit aux parameter stripped) and a versioned name with extra + * parameters: the essential-name lookup would find the base entry + * (fewer params) and fail the compat check, leaving the weak symbol + * unresolved even though the versioned kernel entry is a perfect + * match. + */ + if (ext->essent_name) { + struct module_btf *exact_mod_btf =3D NULL; + struct btf *exact_btf =3D NULL; + int exact_id; + + exact_id =3D find_ksym_btf_id(obj, ext->name, BTF_KIND_FUNC, + &exact_btf, &exact_mod_btf); + if (exact_id >=3D 0) { + kern_func =3D btf__type_by_id(exact_btf, exact_id); + kfunc_proto_id =3D kern_func->type; + ret =3D bpf_core_types_are_compat(obj->btf, + local_func_proto_id, + exact_btf, + kfunc_proto_id); + if (ret > 0) { + kern_btf =3D exact_btf; + mod_btf =3D exact_mod_btf; + kfunc_id =3D exact_id; + goto found; + } + } + } + kfunc_id =3D find_ksym_btf_id(obj, ext->essent_name ?: ext->name, BTF_KIN= D_FUNC, &kern_btf, &mod_btf); if (kfunc_id < 0) { @@ -8655,6 +8689,7 @@ static int bpf_object__resolve_ksym_func_btf_id(struc= t bpf_object *obj, return -EINVAL; } =20 +found: /* set index for module BTF fd in fd_array, if unset */ if (mod_btf && !mod_btf->fd_array_idx) { /* insn->off is s16 */ --=20 2.43.0