BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc
@ 2026-11-18 19:40 Alan Maguire
  2026-11-18 20:12 ` bot+bpf-ci
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alan Maguire @ 2026-11-18 19:40 UTC (permalink / raw)
  To: ast
  Cc: daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song,
	jolsa, emil, ihor.solodrai, nathan, ndesaulniers, morbo,
	justinstitt, a.s.protopopov, bpf, Alan Maguire

PR #170968, “[AArch64] Treat NOP as a separate instruction” [1]
gave NOP its own instruction definition; LLVM 24 decodes
"1f 20 03 d5" as the opcode NOP. Earlier releases decode it
as HINT #0, which is what the arm64 table looks for. So the
test of the nop fails, text_arch_init() gives up and a kernel
with CONFIG_BPF_FMODRET_SCAN=y cannot be built:

  text_mc: LLVM 24.0.0git: 1f 20 03 d5 is NOP, length 4, nop 0 ...
      expected: nop 1 ...
  text_mc: LLVM 24.0.0git: the table of the arch does not fit it. ...
  FAILED: no decoder for the code of ELF machine 183

Add a pattern for NOP. An LLVM before this has no opcode of that name,
and a name which is missing is an error. So a pattern can now be
OPTIONAL: it is left out if this LLVM lacks the opcode. The pattern of
HINT #0 stays for the releases before, and the test shows that one of
the two matches.

With LLVM 24.0.0git the scan of an arm64 vmlinux finds no instruction
it cannot decode: 3385 of 65138 functions are tagged (the smaller
number of matches is due to CONFIG_KCSAN causing functions to be
marked as unsafe for fmod_ret).

[1] https://github.com/llvm/llvm-project/pull/170968

Fixes: 4dd950adacad ("resolve_btfids: Tag the functions that return errors")
Assisted-by: LLM
Signed-off-by: Alan Maguire <almagui@kernel.org>
---
 tools/bpf/resolve_btfids/text_mc.cpp     | 2 ++
 tools/bpf/resolve_btfids/text_mc.h       | 6 ++++++
 tools/bpf/resolve_btfids/text_mc_arm64.c | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/tools/bpf/resolve_btfids/text_mc.cpp b/tools/bpf/resolve_btfids/text_mc.cpp
index 57f45a4bed6f..69668f8b12d7 100644
--- a/tools/bpf/resolve_btfids/text_mc.cpp
+++ b/tools/bpf/resolve_btfids/text_mc.cpp
@@ -195,6 +195,8 @@ bool read_opcodes()
 		auto it = by_name.find(pattern->opcode);
 
 		if (it == by_name.end()) {
+			if (pattern->optional)
+				continue;
 			error() << "no opcode " << pattern->opcode << "\n";
 			ok = false;
 		} else if (pattern->kind == TEXT_RETURN) {
diff --git a/tools/bpf/resolve_btfids/text_mc.h b/tools/bpf/resolve_btfids/text_mc.h
index f2add1f45f4f..574d4a94afa6 100644
--- a/tools/bpf/resolve_btfids/text_mc.h
+++ b/tools/bpf/resolve_btfids/text_mc.h
@@ -50,6 +50,11 @@ struct mc_predicate {
  * has, and DEFS.
  * With NOP the instruction is a nop if the first predicate holds.
  *
+ * An opcode which this LLVM does not have is an error, unless the pattern is
+ * OPTIONAL: then it is left out. That is for an opcode which LLVM split off
+ * from another one in some release, while the pattern of the old one stays
+ * for the releases before. The tests show that one of the two matches.
+ *
  * A pattern of kind TEXT_RETURN names a return to the caller. isReturn() holds
  * for a return from an exception as well, which does not hand the return value
  * register to a caller. Without such a pattern it is an opcode like any other,
@@ -71,6 +76,7 @@ struct mc_pattern {
 	s64 value;
 	u32 defs;		/* of TEXT_OTHER */
 	bool nop;		/* of TEXT_OTHER */
+	bool optional;		/* the opcode is missing in some LLVM releases */
 	struct mc_predicate predicates[2];
 };
 
diff --git a/tools/bpf/resolve_btfids/text_mc_arm64.c b/tools/bpf/resolve_btfids/text_mc_arm64.c
index 5d2fa8a23a14..9cc41900fa4a 100644
--- a/tools/bpf/resolve_btfids/text_mc_arm64.c
+++ b/tools/bpf/resolve_btfids/text_mc_arm64.c
@@ -25,6 +25,8 @@ static const struct mc_pattern arm64_patterns[] = {
 	/* HINT: nop, bti, yield, wfe ... */
 	{ "HINT", TEXT_OTHER }, { "AUTIASP", TEXT_OTHER }, { "PRFMui", TEXT_OTHER },
 	{ "HINT", TEXT_OTHER, .nop = true, .predicates = { IMM(0, 0) } },	/* nop */
+	/* LLVM 24 decodes nop as NOP, not as HINT #0 */
+	{ "NOP", TEXT_OTHER, .nop = true, .optional = true },
 	{ "DMB", TEXT_OTHER }, { "MRS", TEXT_OTHER }, { "MSR", TEXT_OTHER },
 	{ "STLRB", TEXT_OTHER }, { "STLRW", TEXT_OTHER },
 	WX("LDXR", "", TEXT_OTHER), WX("STXR", "", TEXT_OTHER), WX("STLXR", "", TEXT_OTHER),
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc
  2026-11-18 19:40 [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc Alan Maguire
@ 2026-11-18 20:12 ` bot+bpf-ci
  2026-11-19  1:44 ` Alexei Starovoitov
  2026-11-19  1:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: bot+bpf-ci @ 2026-11-18 20:12 UTC (permalink / raw)
  To: almagui, ast
  Cc: daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song,
	jolsa, emil, ihor.solodrai, nathan, ndesaulniers, morbo,
	justinstitt, a.s.protopopov, bpf, almagui, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, mason, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 2132 bytes --]

> resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc

TL;DR: Commit message and code comment may name the wrong LLVM version: LLVM
22 and 23 seem to decode arm64 nop as NOP too, so "LLVM 24" should likely read
"LLVM 22 and later".

> resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc
>
> PR #170968, "[AArch64] Treat NOP as a separate instruction" [1]
> gave NOP its own instruction definition; LLVM 24 decodes
> "1f 20 03 d5" as the opcode NOP. Earlier releases decode it
> as HINT #0, which is what the arm64 table looks for.

Is this boundary accurate?  That LLVM change was merged to trunk when it
was 22.0.0git, and the release/22.x AArch64InstrInfo.td already has:

    def NOP : SystemNoOperands<0b000, "hint\t#0">;
    def : InstAlias<"nop", (NOP)>;

So it looks like the released LLVM 22 and 23 decode nop as NOP as well,
and only LLVM 17 to 21 decode it as HINT #0.  An arm64 build with
CONFIG_BPF_FMODRET_SCAN=y would then fail with LLVM 22 and 23 in the same
way as with 24.0.0git.

Could the subject and body say "LLVM 22 and later" instead of LLVM 24?

> diff --git a/tools/bpf/resolve_btfids/text_mc_arm64.c b/tools/bpf/resolve_btfids/text_mc_arm64.c
> --- a/tools/bpf/resolve_btfids/text_mc_arm64.c
> +++ b/tools/bpf/resolve_btfids/text_mc_arm64.c

[ ... ]

> @@ -25,6 +25,8 @@ static const struct mc_pattern arm64_patterns[] = {
>  	/* HINT: nop, bti, yield, wfe ... */
>  	{ "HINT", TEXT_OTHER }, { "AUTIASP", TEXT_OTHER }, { "PRFMui", TEXT_OTHER },
>  	{ "HINT", TEXT_OTHER, .nop = true, .predicates = { IMM(0, 0) } },	/* nop */
> +	/* LLVM 24 decodes nop as NOP, not as HINT #0 */

This isn't a bug, but the same version boundary applies to this comment.
Should it say LLVM 22 and later rather than LLVM 24?

> +	{ "NOP", TEXT_OTHER, .nop = true, .optional = true },
>  	{ "DMB", TEXT_OTHER }, { "MRS", TEXT_OTHER }, { "MSR", TEXT_OTHER },


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44386217738

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc
  2026-11-18 19:40 [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc Alan Maguire
  2026-11-18 20:12 ` bot+bpf-ci
@ 2026-11-19  1:44 ` Alexei Starovoitov
  2026-11-19  1:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2026-11-19  1:44 UTC (permalink / raw)
  To: Alan Maguire
  Cc: daniel, andrii, eddyz87, memxor, martin.lau, song, yonghong.song,
	jolsa, emil, ihor.solodrai, nathan, ndesaulniers, morbo,
	justinstitt, a.s.protopopov, bpf

On Wed, Nov 18, 2026 at 11:40 AM Alan Maguire <almagui@kernel.org> wrote:
>  		if (it == by_name.end()) {
> +			if (pattern->optional)
> +				continue;
>  			error() << "no opcode " << pattern->opcode << "\n";
>  			ok = false;

Thanks for the quick fix. Applied.

But should we go further and skip unknown names? Like:

diff --git a/tools/bpf/resolve_btfids/text_mc.cpp b/tools/bpf/resolve_btfids/text_mc.cpp
index 57f45a4..bfe9824 100644
--- a/tools/bpf/resolve_btfids/text_mc.cpp
+++ b/tools/bpf/resolve_btfids/text_mc.cpp
@@ -165,10 +165,9 @@ bool read_regs()
 	return ok;
 }
 
-bool read_opcodes()
+void read_opcodes()
 {
 	std::unordered_map<std::string_view, Opcode *> by_name;
-	bool ok = true;
 
 	d.opcodes.resize(d.MII->getNumOpcodes());
 	by_name.reserve(d.opcodes.size());
@@ -194,10 +193,9 @@ bool read_opcodes()
 	for (const mc_pattern *pattern = mc_arch.patterns; pattern->opcode; pattern++) {
 		auto it = by_name.find(pattern->opcode);
 
-		if (it == by_name.end()) {
-			error() << "no opcode " << pattern->opcode << "\n";
-			ok = false;
-		} else if (pattern->kind == TEXT_RETURN) {
+		if (it == by_name.end())
+			continue;
+		if (pattern->kind == TEXT_RETURN) {
 			it->second->is_return = true;
 		} else if (pattern->kind != TEXT_OTHER) {
 			it->second->patterns.push_back(pattern);
@@ -208,7 +206,6 @@ bool read_opcodes()
 				it->second->nop = pattern;
 		}
 	}
-	return ok;
 }
 
 const Reg &reg_of(const MCInst &inst, const Opcode &o, u8 nr, bool def)
@@ -422,12 +419,16 @@ bool run_tests()
 extern "C" const struct text_arch *text_arch_init(unsigned int machine)
 {
 	static text_arch arch = mc_arch.arch;
+	bool ok;
 
 	if (machine != mc_arch.machine) {
 		errs() << "text_mc: built for " << mc_arch.triple << ", not for ELF machine " << machine << "\n";
 		return nullptr;
 	}
-	if (!create() || !read_regs() || !read_opcodes() || !run_tests()) {
+	ok = create() && read_regs();
+	if (ok)
+		read_opcodes();
+	if (!ok || !run_tests()) {
 		error() << "the table of the arch does not fit it. Set LLVM_CONFIG to the "
 			   "llvm-config of another LLVM, or switch CONFIG_BPF_FMODRET_SCAN off\n";
 		return nullptr;
diff --git a/tools/bpf/resolve_btfids/text_mc.h b/tools/bpf/resolve_btfids/text_mc.h
index f2add1f..914a00a 100644
--- a/tools/bpf/resolve_btfids/text_mc.h
+++ b/tools/bpf/resolve_btfids/text_mc.h
@@ -13,8 +13,9 @@
  * It does not say what an instruction computes: the selection patterns are not
  * a part of it. And the headers with the enums of a target are not installed.
  * So opcodes and registers are given by name, as MCInstrInfo::getName() and
- * MCRegisterInfo::getName() return them, and looked up once. A name which this
- * LLVM does not have is an error.
+ * MCRegisterInfo::getName() return them, and looked up once. A register which
+ * this LLVM does not have is an error. A pattern for an opcode which it does
+ * not have is left out: each pattern has a test, which fails if it is missed.
  */
 
 /* A condition on the operands of an MCInst, like an MCInstPredicate of TableGen */
diff --git a/tools/bpf/resolve_btfids/text_mc_arm64.c b/tools/bpf/resolve_btfids/text_mc_arm64.c
index 5d2fa8a..31ca6e0 100644
--- a/tools/bpf/resolve_btfids/text_mc_arm64.c
+++ b/tools/bpf/resolve_btfids/text_mc_arm64.c
@@ -25,6 +25,7 @@ static const struct mc_pattern arm64_patterns[] = {
 	/* HINT: nop, bti, yield, wfe ... */
 	{ "HINT", TEXT_OTHER }, { "AUTIASP", TEXT_OTHER }, { "PRFMui", TEXT_OTHER },
 	{ "HINT", TEXT_OTHER, .nop = true, .predicates = { IMM(0, 0) } },	/* nop */
+	{ "NOP", TEXT_OTHER, .nop = true },	/* nop since llvm-project PR 170968 */
 	{ "DMB", TEXT_OTHER }, { "MRS", TEXT_OTHER }, { "MSR", TEXT_OTHER },
 	{ "STLRB", TEXT_OTHER }, { "STLRW", TEXT_OTHER },
 	WX("LDXR", "", TEXT_OTHER), WX("STXR", "", TEXT_OTHER), WX("STLXR", "", TEXT_OTHER),


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc
  2026-11-18 19:40 [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc Alan Maguire
  2026-11-18 20:12 ` bot+bpf-ci
  2026-11-19  1:44 ` Alexei Starovoitov
@ 2026-11-19  1:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-19  1:50 UTC (permalink / raw)
  To: Alan Maguire
  Cc: ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, nathan, ndesaulniers,
	morbo, justinstitt, a.s.protopopov, bpf

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Wed, 18 Nov 2026 19:40:30 +0000 you wrote:
> PR #170968, “[AArch64] Treat NOP as a separate instruction” [1]
> gave NOP its own instruction definition; LLVM 24 decodes
> "1f 20 03 d5" as the opcode NOP. Earlier releases decode it
> as HINT #0, which is what the arm64 table looks for. So the
> test of the nop fails, text_arch_init() gives up and a kernel
> with CONFIG_BPF_FMODRET_SCAN=y cannot be built:
> 
> [...]

Here is the summary with links:
  - [bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc
    https://git.kernel.org/bpf/bpf-next/c/f8c00958c5b9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19  1:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 19:40 [PATCH bpf-next] resolve_btfids: Match the arm64 NOP opcode for LLVM 24 in text_mc Alan Maguire
2026-11-18 20:12 ` bot+bpf-ci
2026-11-19  1:44 ` Alexei Starovoitov
2026-11-19  1:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox