Re: [PATCH bpf v2 2/2] selftests/bpf: Check per-CPU address resolution per register
Eduard Zingerman <[email protected]>
| Newsgroups | org.kernel.vger.stable,org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 2026-08-14 at 13:32 -0700, Vineet Gupta wrote:
...
> +/*
> + * An ld_imm64 of a per-CPU map value is followed by a mov_percpu_addr that
> + * reuses the same register, so the register the address lands in decides how
> + * the JIT encodes the add. On x86 R5, R7, R8 and R9 are the extended
> + * registers, whose high bit needs REX.R because the destination sits in
> + * ModRM.reg. Check one program per extended register, since getting the
> + * prefix wrong resolves the address into whichever register shares the low
> + * three bits instead.
> + */
> +
> +SEC("raw_tp")
> +__description("per-CPU address into r5")
> +__success
> +__arch_x86_64
> +__jited(" addq %gs:{{.*}}, %r8")
> +__naked void percpu_addr_into_r5(void)
> +{
> + asm volatile (" \
> + r5 = %[percpu_data] ll; \
> + r0 = *(u32 *)(r5 + 0); \
> + exit; \
> +" :
> + : __imm_addr(percpu_data)
> + : __clobber_all);
> +}
Thank you for adding the tests.
Maybe save some space by just packing it as a single test?
__jited(" addq %gs:{{.*}}, %...")
__jited(" addq %gs:{{.*}}, %...")
__jited(" addq %gs:{{.*}}, %...")
__jited(" addq %gs:{{.*}}, %...")
__jited(" addq %gs:{{.*}}, %...")
r0 = %[percpu_data] ll; \
r1 = %[percpu_data] ll; \
r2 = %[percpu_data] ll; \
r3 = %[percpu_data] ll; \
r4 = %[percpu_data] ll; \
r5 = %[percpu_data] ll; \
r6 = %[percpu_data] ll; \
r7 = %[percpu_data] ll; \
r8 = %[percpu_data] ll; \
r9 = %[percpu_data] ll; \
More compact and no need to describe in length why only R{5,7,8,9} are selected.
...