All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>, linux-trace-kernel@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,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, 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, nsc@kernel.org,
	linux-kbuild@vger.kernel.org, ojeda@kernel.org, ardb@kernel.org,
	linux-efi@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev, shuah@kernel.org, indu.bhagat@oracle.com,
	jremus@linux.ibm.com, wnliu@google.com, dylanbhatch@google.com,
	gary@garyguo.net
Subject: Re: [RFC PATCH v1 01/11] unwind: Add Minimal DWARF CFI bytecode interpreter and KUnit tests
Date: Mon, 23 Nov 2026 00:11:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-228460@kernel.org> (raw)
In-Reply-To: <20261122235757.3456048-2-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] unwind: missing CONFIG_STACKTRACE dependency for
  dwarf_cfi_kunit.c
- [Medium] unwind: signed FDE range sign-extension in
  dwarf_cfi_eval_fde_streams()
- [Medium] unwind: high-order kmalloc() for FDE index table in
  dwarf_cfi_mod_alloc()
--

commit 31c297accf2da5579a418d80b5e8b6a08f8ba8e6
Author: Ian Rogers <irogers@google.com>

unwind: Add Minimal DWARF CFI bytecode interpreter and KUnit tests

This commit adds a bounded DWARF Call Frame Information (.eh_frame and
.eh_frame_hdr) bytecode interpreter, module FDE indexing helpers, and a
KUnit test suite.

> diff --git a/arch/Kconfig b/arch/Kconfig
> index 1163736de1f99..03399120aa8f7 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -500,6 +500,22 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
>  	  It uses the same command line parameters, and sysctl interface,
>  	  as the generic hardlockup detectors.
>  
> +config UNWIND_TABLES
> +	bool
> +
> +config UNWIND_DWARF_CFI
> +	bool
> +
> +config UNWIND_DWARF_CFI_KUNIT_TEST
> +	bool "KUnit tests for Minimal DWARF CFI unwinder" if !KUNIT_ALL_TESTS
> +	depends on KUNIT=y && UNWIND_DWARF_CFI
> +	default KUNIT_ALL_TESTS

[Severity: Medium]
Does UNWIND_DWARF_CFI_KUNIT_TEST fail to build when CONFIG_STACKTRACE is
disabled?

unwind_test_leaf() in kernel/unwind/dwarf_cfi_kunit.c unconditionally calls
stack_trace_save(), which include/linux/stacktrace.h only declares under
CONFIG_STACKTRACE.  In addition, test_live_kernel_stack_walk() guards
stack_trace_save_tsk_reliable() only with CONFIG_HAVE_RELIABLE_STACKTRACE,
so with CONFIG_STACKTRACE=n it calls the fallback stub returning -ENOSYS.
Either UNWIND_DWARF_CFI_KUNIT_TEST should depend on STACKTRACE, or the live
stack walk test should be guarded by IS_ENABLED(CONFIG_STACKTRACE).

> diff --git a/kernel/unwind/dwarf_cfi.c b/kernel/unwind/dwarf_cfi.c
> new file mode 100644
> index 0000000000000..3e474bce1ab5e
> --- /dev/null
> +++ b/kernel/unwind/dwarf_cfi.c

[ ... ]

> +static int dwarf_cfi_eval_fde_streams(struct dwarf_cfi_stream *cie_s,
> +				      struct dwarf_cfi_stream *fde_s,
> +				      unsigned long pc,
> +				      const struct dwarf_cfi_arch *arch,
> +				      struct dwarf_cfi_row *out_row)
> +{
> +	struct dwarf_cfi_cie cie;
> +	struct dwarf_cfi_row cie_row, row;
> +	unsigned long init_loc, pc_range, end_loc;
> +	int err;
> +
> +	err = dwarf_cfi_parse_cie(cie_s, arch, &cie, &cie_row);
> +	if (err)
> +		return err;
> +
> +	if (likely(cie.fde_enc == (DW_EH_PE_pcrel | DW_EH_PE_sdata4) &&
> +		   fde_s->pos + 8 <= fde_s->win_len)) {
> +		unsigned long faddr = cfi_stream_addr(fde_s);
> +		s32 rel = (s32)get_unaligned_le32(fde_s->buf + fde_s->pos);
> +		u32 rng = get_unaligned_le32(fde_s->buf + fde_s->pos + 4);
> +
> +		fde_s->pos += 8;
> +		init_loc = faddr + (long)rel;
> +		if (arch->ws == 4)
> +			init_loc = (u32)init_loc;
> +		pc_range = rng;
> +	} else {
> +		err = cfi_read_encoded_ptr(fde_s, cie.fde_enc, arch->ws,
> +					   /*datarel_base=*/0, &init_loc);
> +		if (err)
> +			return err;
> +		err = cfi_read_encoded_ptr(fde_s, cie.fde_enc & DW_EH_PE_FORM,
> +					   arch->ws, /*datarel_base=*/0,
> +					   &pc_range);
> +		if (err)
> +			return err;
> +	}
> +
> +	if (!pc_range || check_add_overflow(init_loc, pc_range, &end_loc))
> +		return -EINVAL;
> +	if (pc < init_loc || pc >= end_loc)
> +		return -ENOENT;

[Severity: Medium]
Can a negative FDE range in the slow path sign-extend into pc_range and
bypass the end_loc overflow check?

cie.fde_enc & DW_EH_PE_FORM preserves the signed encoding bit (0x08), so
unlike the fast path above (which reads rng as u32), cfi_read_encoded_ptr()
sign-extends negative sdata2, sdata4, sdata8, or sleb128 values to s64
before casting to unsigned long.  When the decoded value is negative with a
magnitude greater than init_loc (for example, init_loc = 0x400000 and a
range of -0x500000), init_loc + pc_range does not wrap unsigned long and
sets end_loc near ULONG_MAX, causing the FDE to match any pc >= init_loc.

[ ... ]

> +struct mod_dwarf_cfi_index *dwarf_cfi_mod_alloc(const void *eh_frame,
> +						size_t eh_frame_size,
> +						const struct dwarf_cfi_arch *arch)
> +{
> +	struct mod_dwarf_cfi_index *idx;
> +	unsigned int num_fdes = 0;
> +	unsigned long base;
> +
> +	if (!eh_frame || !eh_frame_size)
> +		return NULL;
> +
> +	base = (unsigned long)eh_frame;
> +	if (dwarf_cfi_scan_eh_frame_kmem(eh_frame, eh_frame_size, arch, base,
> +					 /*entries=*/NULL, /*max_entries=*/0,
> +					 &num_fdes) || !num_fdes)
> +		return NULL;
> +
> +	idx = kmalloc(struct_size(idx, entries, num_fdes), GFP_KERNEL);
> +	if (!idx)
> +		return NULL;
> +
> +	idx->num_fdes = num_fdes;
> +	idx->eh_frame = eh_frame;
> +	idx->eh_frame_size = eh_frame_size;
> +
> +	if (dwarf_cfi_scan_eh_frame_kmem(eh_frame, eh_frame_size, arch, base,
> +					 idx->entries, num_fdes, &num_fdes)) {
> +		kfree(idx);
> +		return NULL;
> +	}

[Severity: Medium]
Should dwarf_cfi_mod_alloc() use kvmalloc() and kvfree() instead of
kmalloc() and kfree()?

Each function in a module produces an 8-byte eh_frame_hdr_entry, so any
module with more than ~4,093 functions requires an allocation above
PAGE_ALLOC_COSTLY_ORDER (32 KiB on 4 KiB page systems), and large modules
such as amdgpu or i915 can need 64 KiB to 256+ KiB of physically contiguous
memory, risking compaction stalls or allocation failure under fragmentation.
dwarf_cfi_mod_free_rcu() already frees idx with kfree_rcu_mightsleep(),
which handles vmalloc pointers.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122235757.3456048-1-irogers@google.com?part=1

  reply	other threads:[~2026-11-23  0:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 23:57 [RFC PATCH v1 00/11] unwind: Minimal DWARF CFI stack unwinding for x86, arm64, and riscv Ian Rogers
2026-11-22 23:57 ` Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 01/11] unwind: Add Minimal DWARF CFI bytecode interpreter and KUnit tests Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:11   ` sashiko-bot [this message]
2026-11-23  0:40   ` bot+bpf-ci
2026-11-23  0:40     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 02/11] unwind_user: Support Minimal DWARF CFI user-space unwinding Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:11   ` sashiko-bot
2026-11-23  0:39   ` bot+bpf-ci
2026-11-23  0:39     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 03/11] scripts, unwind: Add build-time .eh_frame minifier Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:40   ` bot+bpf-ci
2026-11-23  0:40     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 04/11] objtool/ibt: Ignore .eh_frame relocations during ENDBR validation Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 05/11] x86/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:56   ` bot+bpf-ci
2026-11-23  0:56     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 06/11] arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:16   ` sashiko-bot
2026-11-22 23:57 ` [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:24   ` sashiko-bot
2026-11-23  0:56   ` bot+bpf-ci
2026-11-23  0:56     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 08/11] riscv: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:39   ` bot+bpf-ci
2026-11-23  0:39     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 09/11] riscv/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:24   ` sashiko-bot
2026-11-23  0:56   ` bot+bpf-ci
2026-11-23  0:56     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 10/11] selftests/perf_events: Add Minimal DWARF CFI deferred user unwind test Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:40   ` bot+bpf-ci
2026-11-23  0:40     ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 11/11] scripts: Add eh_frame_min.py .eh_frame coverage and size analyzer Ian Rogers
2026-11-22 23:57   ` Ian Rogers
2026-11-23  0:39   ` bot+bpf-ci
2026-11-23  0:39     ` bot+bpf-ci
2026-11-23  0:24 ` [RFC PATCH v1 00/11] unwind: Minimal DWARF CFI stack unwinding for x86, arm64, and riscv sashiko-bot

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=sashiko-outbox-228460@kernel.org \
    --to=sashiko-bot@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=gary@garyguo.net \
    --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-efi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --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=sashiko-reviews@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.