BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eduard Zingerman" <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 2/5] bpf: track upper 32-bit register halves' liveness in compute_live_registers()
Date: Sat, 01 Aug 2026 01:35:08 +0000	[thread overview]
Message-ID: <20260801013509.50C781F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731-static-zext-v2-2-da4aa161e8c5@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Skipping zero-extension for 32-bit kfunc arguments causes ABI violations on architectures that require the caller to extend 32-bit parameters.
--

--- Patch [2]: [PATCH bpf-next v2 2/5] bpf: track upper 32-bit register halves' liveness in compute_live_registers() ---
commit 2a034896228b7579bf93bf8ae2024cee100ebcba
Author: Eduard Zingerman <eddyz87@gmail.com>

bpf: track upper 32-bit register halves' liveness in compute_live_registers()

This commit extends compute_live_registers() to track the upper and lower 
register halves' liveness separately. It updates compute_insn_live_regs() 
to track these bits and infers whether the upper half of a parameter 
register is used by a kfunc call based on its BTF type size.

> diff --git a/kernel/bpf/liveness.c b/kernel/bpf/liveness.c
> index ff1e68cc4bd1c..d0bd94c60fee2 100644
> --- a/kernel/bpf/liveness.c
> +++ b/kernel/bpf/liveness.c

[ ... ]

> +static u32 call_use_mask(struct bpf_verifier_env *env, struct bpf_insn *insn)
> +{
> +	u32 i, use, size, reg_params_num;
> +	struct bpf_call_summary cs;
> +	const struct btf_param *p;
> +	const struct btf_type *t;
> +
> +	if (!bpf_get_call_summary(env, insn, &cs))
> +		/* e.g. a bpf-to-bpf call, assume that calls use full 64-bit for each param */
> +		return mask_widen(ALL_CALLER_SAVED_REGS & ~BIT(BPF_REG_0));
> +
> +	if (cs.func_proto) {
> +		use = 0;
> +		p = btf_params(cs.func_proto);
> +		reg_params_num = min(btf_type_vlen(cs.func_proto), MAX_BPF_FUNC_REG_ARGS);
> +		for (i = 0; i < reg_params_num; i++) {
> +			t = btf_type_by_id(cs.btf, p[i].type);
> +			if (IS_ERR(btf_resolve_size(cs.btf, t, &size)))
> +				goto fallback;
> +			use |= size <= sizeof(u32) ? reg32_mask(i + 1) : reg64_mask(i + 1);

[Severity: High]
Does this break the C ABI on architectures that require the caller to
zero-extend or sign-extend 32-bit parameters passed in 64-bit registers?

By only marking the lower 32 bits as used for smaller parameters with
reg32_mask, the upper 32 bits are marked as dead before the kfunc call.
Consequently, the verifier computes zext_dst = false for the instruction
that previously defined the argument.

This causes the JIT to skip inserting a BPF_ZEXT_REG instruction to clear
the upper 32 bits on architectures where bpf_jit_needs_zext() is true,
such as s390x and PowerPC64.

If a BPF program computes a 32-bit value and passes it to a kfunc expecting
a 32-bit parameter, the kfunc might operate on garbage data in the upper
32 bits.

> +		}
> +		return use;
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731-static-zext-v2-0-da4aa161e8c5@gmail.com?part=2

  reply	other threads:[~2026-08-01  1:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-01  1:09 [PATCH bpf-next v2 0/5] bpf: infer zext_dst based on static register liveness analysis Eduard Zingerman
2026-08-01  1:09 ` [PATCH bpf-next v2 1/5] bpf: do not print a newline after disassembly in bpf_verbose_insn() Eduard Zingerman
2026-08-01  1:09 ` [PATCH bpf-next v2 2/5] bpf: track upper 32-bit register halves' liveness in compute_live_registers() Eduard Zingerman
2026-08-01  1:35   ` sashiko-bot [this message]
2026-08-01  4:40     ` Eduard Zingerman
2026-08-01  1:09 ` [PATCH bpf-next v2 3/5] bpf: infer zext_dst based on static register liveness analysis Eduard Zingerman
2026-08-01  1:42   ` sashiko-bot
2026-08-01  5:41     ` Eduard Zingerman
2026-08-01  1:09 ` [PATCH bpf-next v2 4/5] bpf: simplify the bpf_is_reg64() Eduard Zingerman
2026-08-01  1:34   ` sashiko-bot
2026-08-01  1:09 ` [PATCH bpf-next v2 5/5] selftests/bpf: verify zext_dst annotations for various instructions Eduard Zingerman
2026-08-01  1:33   ` sashiko-bot
2026-08-01  4:24     ` Eduard Zingerman

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=20260801013509.50C781F00AC4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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