mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: irogers@google.com,linux-kernel@vger.kernel.org,linux-trace-kernel@vger.kernel.org,linux-arch@vger.kernel.org
Cc: jpoimboe@kernel.org,rostedt@goodmis.org,peterz@infradead.org,mingo@redhat.com,tglx@kernel.org,bp@alien8.de,dave.hansen@linux.intel.com,x86@kernel.org,catalin.marinas@arm.com,will@kernel.org,mark.rutland@arm.com,linux-arm-kernel@lists.infradead.org,pjw@kernel.org,palmer@dabbelt.com,aou@eecs.berkeley.edu,alex@ghiti.fr,linux-riscv@lists.infradead.org,acme@kernel.org,namhyung@kernel.org,linux-perf-users@vger.kernel.org,mhiramat@kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,bpf@vger.kernel.org,nathan@kernel.org,llvm@lists.linux.dev,nsc@kernel.org,linux-kbuild@vger.kernel.org,ojeda@kernel.org,rust-for-linux@vger.kernel.org,ardb@kernel.org,linux-efi@vger.kernel.org,maz@kernel.org,oupton@kernel.org,kvmarm@lists.linux.dev,shuah@kernel.org,linux-kselftest@vger.kernel.org,indu.bhagat@oracle.com,jremus@linux.ibm.com,wnliu@google.com,dylanbhatch@google.com,irogers@google.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yongho
	ng.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [RFC PATCH v2 26/30] tools/unwind: Add standalone libLLVM Minimal DWARF CFI verifier
Date: Wed, 25 Nov 2026 07:06:22 +0000 (UTC)	[thread overview]
Message-ID: <4c1cf2d3c9f5248593453fd7749b58a25eb2a167caf209cd23935d59f10b2c11@mail.kernel.org> (raw)
In-Reply-To: <20261125061523.1540234-27-irogers@google.com>

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

> tools/unwind: Add standalone libLLVM Minimal DWARF CFI verifier

TL;DR:
- Makefile: possibly unreliable LLVM detection; wrong LLVM 21 requirement
  message
- C++ objects may not rebuild after dwarf_cfi_row changes, possibly causing
  stale-layout memory errors
- Mismatch diagnostics omit differing fields; misleading comment (nit)

> diff --git a/tools/unwind/Makefile b/tools/unwind/Makefile
> new file mode 100644
> --- /dev/null
> +++ b/tools/unwind/Makefile

[ ... ]

> +FEATURE_USER := .verify_cfi
> +FEATURE_TESTS := llvm
> +FEATURE_DISPLAY := llvm

Is feature-llvm reliable here?  FEATURE_TESTS is replaced with llvm, but
nothing calls $(call feature_check,llvm) before the later
"ifeq ($(feature-llvm),1)".

In tools/build/Makefile.feature, when test-all.bin builds,
$(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat))) sets
feature-llvm to 1 without compiling test-llvm.cpp, since test-all.c is C
and cannot include the C++ LLVM test.  On such a host the display can
print "llvm: [ on ]" whether or not LLVM is installed, and only the later
DWARFUnwindTable.h wildcard keeps the build from proceeding.

On hosts where test-all.bin fails, the slow path runs test-llvm.bin, which
links "llvm-config --libs Core BPF".  Can an LLVM built without the BPF
target, which verify_cfi does not need, make feature-llvm 0 and skip the
tool?

Would an explicit $(call feature_check,llvm), or dropping the
Makefile.feature probe in favour of the header check alone, make detection
consistent with the "when libLLVM is detected via
tools/build/Makefile.feature" wording in the commit message?

[ ... ]

> +ifeq ($(HAS_LIBLLVM),1)
> +all: $(OUTPUT)verify_cfi
> +else
> +all:
> +ifeq ($(REQUIRE_LLVM),1)
> +	$(error libLLVM 17+ development headers/libraries not found (LLVM_CONFIG=$(LLVM_CONFIG)))
> +else
> +	@echo "  SKIP    verify_cfi (libLLVM dev files not found; set LLVM_CONFIG=...)"
> +endif
> +endif

The real gate is:

    ifneq ($(wildcard $(LLVM_INCDIR)/llvm/DebugInfo/DWARF/LowLevel/DWARFUnwindTable.h),)

but that header does not exist before LLVM 21, and verify_cfi.cpp calls
llvm::dwarf::createUnwindTable().  On a host with LLVM 17-20 development
files installed, REQUIRE_LLVM=1 fails with "libLLVM 17+ development
headers/libraries not found (LLVM_CONFIG=llvm-config-18)", and the default
build prints "libLLVM dev files not found".  Both messages are wrong for
that case.

The same applies to LLVM_CONFIG_CANDIDATES, which lists llvm-config-20
through llvm-config-18 even though they can never pass the header check.
Should the message and the candidate list state LLVM 21 as the minimum?

> +$(OUTPUT)dwarf_cfi_host.o: dwarf_cfi_host.c dwarf_cfi_host.h $(KERNEL_CFI_DEPS)
> +	$(QUIET_CC)$(HOSTCC) $(SHIM_CFLAGS) -c $< -o $@
> +
> +$(OUTPUT)%.o: %.cpp $(wildcard *.hpp) dwarf_cfi_host.h
> +	$(QUIET_CXX)$(HOSTCXX) $(VERIFY_CXXFLAGS) -c $< -o $@

Is QUIET_CXX defined anywhere?  tools/scripts/Makefile.include defines
QUIET_CC, QUIET_LINK and QUIET_CLANG, but a grep for QUIET_CXX only finds
this line.  In a default build the C++ objects would echo the full
$(HOSTCXX) command line with every flag from llvm-config --cxxflags,
instead of a short "CXX" line.

Also, KERNEL_CFI_DEPS (including tools/include/linux/unwind_dwarf_cfi.h)
is only a prerequisite of dwarf_cfi_host.o.  verify_cfi.cpp allocates
struct dwarf_cfi_row and uses struct dwarf_cfi_arch and passes them to
dwarf_cfi_unwind_user_eh_frame_hdr() and dwarf_cfi_unwind_eh_frame_hdr().

If a developer changes struct dwarf_cfi_row and reruns make -C
tools/unwind, only dwarf_cfi_host.o is rebuilt, and verify_cfi.o keeps the
old layout.  Can the kernel code then write a larger dwarf_cfi_row into a
smaller C++ stack object, or read fields at different offsets?  Should
$(KERNEL_CFI_DEPS), or at least the unwind_dwarf_cfi.h copy, be a
prerequisite of the C++ rule too?

> diff --git a/tools/unwind/dwarf_cfi_host.h b/tools/unwind/dwarf_cfi_host.h
> new file mode 100644
> --- /dev/null
> +++ b/tools/unwind/dwarf_cfi_host.h

[ ... ]

> +/*
> + * Note: In C++ files using LLVM headers, include this header AFTER <llvm/...>
> + * headers (matching tools/perf/util/llvm-c-helpers.cpp) because
> + * tools/include/linux/compiler.h defines macros such as 'noinline' that
> + * conflict with LLVM attribute declarations.
> + */

This isn't a bug, but is this comment accurate?  This header never
includes compiler.h.  Its only include is:

    #include <linux/unwind_dwarf_cfi.h>

which resolves to tools/include/linux/unwind_dwarf_cfi.h, and that only
includes <linux/types.h>.  tools/include/linux/types.h includes
<stdbool.h>, <stddef.h>, <stdint.h>, <asm/types.h> and
<asm/posix_types.h>, so linux/compiler.h and its 'noinline' macro are not
reached from this header.

What this header does bring in is tools/include/linux/types.h, which
defines __must_check, __cold, __force, __user and __bitwise as macros.
Could the comment name the macros this header actually introduces, or be
dropped if there is no real ordering constraint?

> diff --git a/tools/unwind/verify_cfi.cpp b/tools/unwind/verify_cfi.cpp
> new file mode 100644
> --- /dev/null
> +++ b/tools/unwind/verify_cfi.cpp

[ ... ]

> +			if (err_u != 0 || !rowsEqual(krow_user, *exp)) {
> +				st.llvm_vs_kernel_mismatches++;
> +				char buf[200];
> +				snprintf(buf, sizeof(buf),
> +					 "PC=0x%" PRIx64 " err_u=%d kernel(cfa=%u:%d fp=%u:%d ra=%u:%d)"
> +					 " llvm(cfa=%u:%d fp=%u:%d ra=%u:%d)",
> +					 pc, err_u, krow_user.cfa_base,
> +					 krow_user.cfa_off, krow_user.fp_rule,
> +					 krow_user.fp_off, krow_user.ra_rule,
> +					 krow_user.ra_off, exp->cfa_base,
> +					 exp->cfa_off, exp->fp_rule,
> +					 exp->fp_off, exp->ra_rule,
> +					 exp->ra_off);
> +				recordIssue(st, opts, "llvm_vs_kernel_dwarf",
> +					    buf);
> +			}

[ ... ]

> +				if (err_k != err_u ||
> +				    (err_u == 0 &&
> +				     !rowsEqual(krow_kmem, krow_user)))
> +					st.kmem_vs_user_mismatches++;

Does this sample omit fields that rowsEqual() compares?  rowsEqual()
returns false when sp_rule, signal or ra_signed differ, when cfa_reg
differs under DWARF_CFI_BASE_REG, or when sp_off differs under
DWARF_CFI_RULE_OFFSET, but the sample only prints cfa_base:cfa_off,
fp_rule:fp_off and ra_rule:ra_off.

For example, if the kernel and LLVM disagree about ra_signed after
DW_CFA_AARCH64_negate_ra_state, the mismatch is counted and the tool
exits 1, but the sample reads:

    kernel(cfa=1:16 fp=1:-16 ra=1:-8) llvm(cfa=1:16 fp=1:-16 ra=1:-8)

which hides the field that actually differs.  The same holds for the
signal flag, sp_rule and the CFA register.

Similarly, a kmem-vs-user disagreement only increments
st.kmem_vs_user_mismatches and never calls recordIssue().  verifyFile()
then fails the file and prints only the count, with no PC, error codes or
rows.  Could the sample include sp_rule:sp_off, cfa_reg, signal and
ra_signed, and could the kmem path call recordIssue() with the PC,
err_k/err_u and both rows?


---
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/45561209846

  reply	other threads:[~2026-11-25  7:06 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:14 [RFC PATCH v2 00/30] unwind: Minimal DWARF CFI unwinding for user and kernel space Ian Rogers
2026-11-25  6:14 ` [RFC PATCH v2 01/30] unwind: Add Minimal DWARF CFI bytecode interpreter Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:14 ` [RFC PATCH v2 02/30] unwind: Add KUnit tests for Minimal DWARF CFI interpreter Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:14 ` [RFC PATCH v2 03/30] unwind_user: Support Minimal DWARF CFI user-space unwinding Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:14 ` [RFC PATCH v2 04/30] x86: unwind_user: Support Minimal DWARF CFI user unwinding Ian Rogers
2026-11-25  6:47   ` bot+bpf-ci
2026-11-25  6:14 ` [RFC PATCH v2 05/30] scripts: Add min_eh_frame build-time .eh_frame minifier Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:14 ` [RFC PATCH v2 06/30] kbuild: Wire up CONFIG_UNWINDER_DWARF_CFI_MINIFY object pass Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 07/30] objtool/ibt: Ignore .eh_frame relocations during ENDBR validation Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 08/30] vmlinux.lds.h: Allow architectures to emit custom RO_DATA sections Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 09/30] efi/libstub: Disable unwind tables in x86 and RISC-V EFI stubs Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 10/30] tracing: Skip internal ftrace frames under CONFIG_UNWINDER_DWARF_CFI Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 11/30] x86: Add DWARF CFI annotations to entry, ftrace, frame, and rethook Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 12/30] x86/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 13/30] lib/Kconfig.debug: Allow LATENCYTOP and fault-injection filter with DWARF CFI Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 14/30] arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 15/30] arm64: Add DWARF CFI annotations to entry, ftrace, EFI, BPF, and KASAN Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 16/30] arm64/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 17/30] riscv: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 18/30] riscv: Add DWARF CFI annotations to entry, ftrace, rethook, and BPF JIT Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 19/30] riscv/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 20/30] selftests/perf_events: Add Minimal DWARF CFI deferred user unwind test Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 21/30] scripts: Add eh_frame_min.py .eh_frame coverage and size analyzer Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 22/30] tools headers: Add linux/kmsan-checks.h copy from the kernel sources Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 23/30] tools headers: Add linux/nospec.h " Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 24/30] tools headers: Add linux/unwind_dwarf_cfi.h " Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 25/30] tools include: Add linux/uaccess.h stub for userspace tools Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 26/30] tools/unwind: Add standalone libLLVM Minimal DWARF CFI verifier Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci [this message]
2026-11-25  6:15 ` [RFC PATCH v2 27/30] tools/unwind: Add multi-arch symbolic instruction lifters for verify_cfi Ian Rogers
2026-11-25  7:05   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 28/30] tools/unwind: Add CFG instruction abstract execution oracle to verify_cfi Ian Rogers
2026-11-25  7:06   ` bot+bpf-ci
2026-11-25  6:15 ` [RFC PATCH v2 29/30] tools/unwind: Add x86-64 ORC cross-check " Ian Rogers
2026-11-25  6:15 ` [RFC PATCH v2 30/30] MAINTAINERS: Add DWARF CFI stack unwinding entry Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c1cf2d3c9f5248593453fd7749b58a25eb2a167caf209cd23935d59f10b2c11@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=acme@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=andrii@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=dylanbhatch@google.com \
    --cc=eddyz87@gmail.com \
    --cc=indu.bhagat@oracle.com \
    --cc=irogers@google.com \
    --cc=jpoimboe@kernel.org \
    --cc=jremus@linux.ibm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@kernel.org \
    --cc=maz@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=oupton@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    --cc=wnliu@google.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®