Re: [RFC PATCH v2 01/30] unwind: Add Minimal DWARF CFI bytecode interpreter

From: bot+bpf-ci

Date: Wed Nov 25 2026 - 02:05:36 EST


> unwind: Add Minimal DWARF CFI bytecode interpreter

TL;DR: Nits only: duplicated DWARF CFI parsing, register-check and CIE-lookup
code could share helpers, and the UNWIND_TABLES Kconfig move may belong in a
later patch or be explained. No bugs found.

> diff --git a/arch/Kconfig b/arch/Kconfig
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -500,6 +500,12 @@ 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_USER
> bool

This isn't a bug, but could the move of UNWIND_TABLES into arch/Kconfig go
in the patch that first selects it from another architecture, or could the
changelog say why it is needed here?

[ ... ]

> diff --git a/kernel/unwind/dwarf_cfi.c b/kernel/unwind/dwarf_cfi.c
> --- /dev/null
> +++ b/kernel/unwind/dwarf_cfi.c

[ ... ]

> +static __always_inline int
> +cfi_parse_indirect_cfa_expr(struct dwarf_cfi_stream *s, u32 expr_len,
> + const struct dwarf_cfi_arch *arch,
> + struct dwarf_cfi_row *row, bool is_user)
> +{
> + struct dwarf_cfi_stream es;
> + u8 expr_buf[8], op0, op_end;
> + enum dwarf_cfi_base base;
> + s32 off;
> + int err;
> +
> + if (expr_len < 3 || expr_len > 7)
> + return -EINVAL;
> + /* Prevent Spectre v1.1 speculative stack overflow of expr_buf[8] */
> + barrier_nospec();
> +
> + err = cfi_read_bytes(s, expr_buf, expr_len, is_user);
> + if (err)
> + return err;
> +
> + cfi_stream_init_kmem(&es, expr_buf, expr_len - 1);
> + err = cfi_read_u8(&es, &op0, /*is_user=*/false);
> + if (err)
> + return err;
> +
> + if (arch->fp_reg <= 31 && op0 == (u8)(DW_OP_breg0 + arch->fp_reg))
> + base = DWARF_CFI_BASE_FP_INDIRECT;
> + else if (arch->sp_reg <= 31 && op0 == (u8)(DW_OP_breg0 + arch->sp_reg))
> + base = DWARF_CFI_BASE_SP_INDIRECT;
> + else
> + return -EINVAL;
> +
> + err = cfi_read_sleb128_s32(&es, &off, /*is_user=*/false);
> + if (err || !cfi_stream_empty(&es, /*is_user=*/false))
> + return -EINVAL;

[ ... ]

> +static __always_inline int
> +cfi_parse_reg_expr(struct dwarf_cfi_stream *s, u32 reg, u32 expr_len,
> + const struct dwarf_cfi_arch *arch, u8 ra_reg,
> + struct dwarf_cfi_row *row, bool is_user)
> +{
> + struct dwarf_cfi_stream es;
> + u8 expr_buf[8], op0;
> + enum dwarf_cfi_rule rule;
> + s32 off;
> + int err;
> +
> + if (expr_len < 2 || expr_len > 6)
> + return -EINVAL;
> + /* Prevent Spectre v1.1 speculative stack overflow of expr_buf[8] */
> + barrier_nospec();
> +
> + err = cfi_read_bytes(s, expr_buf, expr_len, is_user);
> + if (err)
> + return err;
> +
> + cfi_stream_init_kmem(&es, expr_buf, expr_len);
> + err = cfi_read_u8(&es, &op0, /*is_user=*/false);
> + if (err)
> + return err;
> +
> + if (arch->fp_reg <= 31 && op0 == (u8)(DW_OP_breg0 + arch->fp_reg))
> + rule = DWARF_CFI_RULE_FP_OFFSET;
> + else if (arch->sp_reg <= 31 && op0 == (u8)(DW_OP_breg0 + arch->sp_reg))
> + rule = DWARF_CFI_RULE_SP_OFFSET;

This isn't a bug, but cfi_parse_indirect_cfa_expr() and cfi_parse_reg_expr()
share almost the same DW_OP_breg decode sequence, including the
barrier_nospec() bounds handling.

Could they use one helper that decodes the breg operand and offset, so each
caller only adds its own trailing check?

[ ... ]

> + if (hi == 0x80) {
> + /* DW_CFA_offset */
> + err = cfi_read_uleb128_u32(s, &uval, is_user);
> + if (err)
> + return err;
> + if (lo == arch->fp_reg || lo == cie->ra_reg ||
> + lo == arch->sp_reg) {
> + err = cfi_factored_offset(uval, cie->data_align, &off);
> + if (err)
> + return err;
> + cfi_apply_reg_rule(lo, DWARF_CFI_RULE_OFFSET,
> + off, arch, cie->ra_reg, row);
> + }
> + continue;
> + }

This isn't a bug, but could the repeated fp/ra/sp check in
dwarf_cfi_exec_insns() become a small inline helper such as
cfi_reg_is_tracked(reg, arch, cie->ra_reg)?

The same three-way test appears in the DW_CFA_offset, DW_CFA_offset_extended,
DW_CFA_offset_extended_sf, DW_CFA_GNU_negative_offset_extended,
DW_CFA_register, DW_CFA_val_offset, DW_CFA_val_offset_sf, DW_CFA_expression
and DW_CFA_val_expression cases, so the set of tracked registers would be
defined in one place.

[ ... ]

> + } else {
> + while (lo < hi) {
> + u32 mid = lo + (hi - lo) / 2;
> + const u8 *ent = table + (size_t)mid * ent_sz;
> + unsigned long e_pc = (unsigned long)ent +
> + (long)(s32)get_unaligned_le32(ent);
> +
> + if (e_pc <= pc)
> + lo = mid + 1;
> + else
> + hi = mid;
> + }
> + if (!lo)
> + return -ENOENT;
> + {
> + const u8 *fent = table + (size_t)(lo - 1) * ent_sz + 4;
> +
> + fde_addr = (unsigned long)fent +
> + (long)(s32)get_unaligned_le32(fent);
> + }
> + }

This isn't a bug, but could the kernel lookup in
dwarf_cfi_unwind_eh_frame_hdr() use eh_hdr_entry_addr() in one binary-search
loop, the way dwarf_cfi_unwind_user_eh_frame_hdr() does, rather than two
hand-written loops and the bare block around fent?

[ ... ]

> + if (cie_delta < 4 ||
> + (size_t)((p + 4) - eh_start) < cie_delta)
> + return -EINVAL;
> + cie = (p + 4) - cie_delta;
> + if (cie < eh_start || cie >= eh_end ||
> + (size_t)(eh_end - cie) < 8)
> + return -EINVAL;
> + cie_len = get_unaligned_le32(cie);
> + if (cie_len <= 4 || cie_len > DWARF_CFI_MAX_CIE_LEN ||
> + (size_t)(eh_end - cie) - 4 < (size_t)cie_len ||
> + get_unaligned_le32(cie + 4) != 0)
> + return -EINVAL;
> +
> + cfi_stream_init_kmem(&cie_s, cie + 8, cie_len - 4);

This isn't a bug, but could the CIE resolution here in
dwarf_cfi_scan_eh_frame_kmem() and the one in dwarf_cfi_eval_fde_kmem() share
a small __always_inline helper?

That way the module index scan and the evaluator could not drift apart on
which CIEs they accept.


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