mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: puranjay@kernel.org,bpf@vger.kernel.org
Cc: puranjay@kernel.org,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,martin.lau@linux.dev,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,tj@kernel.org,void@manifault.com,arighi@nvidia.com,changwoo@igalia.com,sched-ext@lists.linux.dev,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 2/3] selftests/bpf: Test fetching AND/OR/XOR atomics in arena
Date: Thu, 24 Sep 2026 16:55:49 +0000 (UTC)	[thread overview]
Message-ID: <aaa76b3ec5eb32105dfcc066b46c985e71d70839d58fbf5d8a258c9fa317fdb1@mail.kernel.org> (raw)
In-Reply-To: <20260924160354.531101-3-puranjay@kernel.org>

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

> diff --git a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
> index 1ad5d03d07ad..42061e70e1a3 100644
> --- a/tools/testing/selftests/bpf/prog_tests/arena_atomics.c
> +++ b/tools/testing/selftests/bpf/prog_tests/arena_atomics.c

[ ... ]

> diff --git a/tools/testing/selftests/bpf/progs/arena_atomics.c b/tools/testing/selftests/bpf/progs/arena_atomics.c
> index 73bc2b835f3f..9a3eee526cc9 100644
> --- a/tools/testing/selftests/bpf/progs/arena_atomics.c
> +++ b/tools/testing/selftests/bpf/progs/arena_atomics.c

[ ... ]

> @@ -213,6 +198,64 @@ int xchg(const void *ctx)
>  	return 0;
>  }
>
> +__u64 __arena_global fetch_src_r0_value = 0x110;
> +__u64 __arena_global fetch_src_r0_result = 0;
> +__u64 __arena_global fetch_dst_r0_value = 0x110;
> +__u64 __arena_global fetch_dst_r0_result = 0;
> +__u64 __arena_global fetch_dst_r0_readback = 0;
> +
> +/*
> + * A fetching OR with the operand in r0, and one with the arena pointer in r0.
> + * The x86 JIT needs RAX for its CMPXCHG loop and substitutes BPF_REG_AX for
> + * whichever of the two is r0, so both have to keep working. Hand-written
> + * because clang picks its own registers and will not reliably emit either.
> + */
> +SEC("raw_tp/sys_enter")
> +int fetch_r0(const void *ctx)
> +{
> +	if (pid != (bpf_get_current_pid_tgid() >> 32))
> +		return 0;
> +#if defined(ENABLE_ATOMICS_TESTS) && defined(__BPF_FEATURE_ADDR_SPACE_CAST)
> +	asm volatile (
> +	"r1 = %[fetch_src_r0_value] ll;"
> +	"r1 = addr_space_cast(r1, 0x0, 0x1);"

[ ... ]

> @@ -221,15 +264,20 @@ int uaf(const void *ctx)
>  {
>  	if (pid != (bpf_get_current_pid_tgid() >> 32))
>  		return 0;
> -#if defined(ENABLE_ATOMICS_TESTS) && !defined(__TARGET_ARCH_arm64) && \
> -    !defined(__TARGET_ARCH_x86)
> +/*
> + * arm64 stays excluded as it has been since this test was added: its JIT only
> + * accepts arena RMW atomics when LSE is present, which is a run-time property.
> + * The rest of the file shares that dependency without a guard, so on a non-LSE
> + * arm64 the whole skeleton already fails to load.
> + */
> +#if defined(ENABLE_ATOMICS_TESTS) && !defined(__TARGET_ARCH_arm64)
>  	__u32 __arena *page32;
>  	__u64 __arena *page64;
>  	void __arena *page;
>
>  	page = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
>  	bpf_arena_free_pages(&arena, page, 1);
> -	uaf_recovery_fails = 24;
> +	uaf_recovery_fails = 26;

[ ... ]

> +
> +	/*
> +	 * The x86 JIT needs RAX for the CMPXCHG loop it lowers a fetching
> +	 * AND/OR/XOR into, and substitutes BPF_REG_AX for r0 when r0 is either
> +	 * operand. Only then does the fault fixup have to name that register,
> +	 * so spell both forms out: clang picks its own and never produces them.
> +	 */
> +	asm volatile (
> +	"r0 = %[page];"
> +	"r0 = addr_space_cast(r0, 0x0, 0x1);"
> +	"r1 = 1;"
> +	".8byte %[fetch_dst_r0];"
> +	: : [page]"r"(page64),
> +	    __imm_insn(fetch_dst_r0,
> +		       BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_0, BPF_REG_1, 0))
> +	: "r0", "r1", "memory");
> +	uaf_recovery_fails -= 1;
> +
> +	asm volatile (
> +	"r1 = %[page];"
> +	"r1 = addr_space_cast(r1, 0x0, 0x1);"
> +	"r0 = 1;"
> +	".8byte %[fetch_src_r0];"
> +	: : [page]"r"(page64),
> +	    __imm_insn(fetch_src_r0,
> +		       BPF_ATOMIC_OP(BPF_DW, BPF_OR | BPF_FETCH, BPF_REG_1, BPF_REG_0, 0))
> +	: "r0", "r1", "memory");
> +	uaf_recovery_fails -= 1;
>  #endif

Would this build with clang 18 or earlier?  Both new asm blocks in uaf()
use the textual addr_space_cast syntax, but uaf() is only guarded by
ENABLE_ATOMICS_TESTS and !__TARGET_ARCH_arm64.  It does not check for
__BPF_FEATURE_ADDR_SPACE_CAST.

Every other use of textual addr_space_cast in this file is under that
guard: fetch_r0() above at the new code, and load_acquire/store_release
elsewhere.  The addr_space_cast asm syntax and __BPF_FEATURE_ADDR_SPACE_CAST
both arrived in LLVM 19, so with clang 18 the integrated assembler would
reject the unknown mnemonic and arena_atomics.bpf.o would fail to build.

Before this patch uaf() was plain C and was compiled out on x86, so the
asm never reached older clang there.


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

  parent reply	other threads:[~2026-09-24 16:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 16:03 [PATCH bpf-next v2 0/3] bpf, x86: Support " Puranjay Mohan
2026-09-24 16:03 ` [PATCH bpf-next v2 1/3] " Puranjay Mohan
2026-09-24 16:03 ` [PATCH bpf-next v2 2/3] selftests/bpf: Test " Puranjay Mohan
2026-09-24 16:29   ` Alexei Starovoitov
2026-09-24 16:55   ` bot+bpf-ci [this message]
2026-09-24 16:03 ` [PATCH bpf-next v2 3/3] sched_ext: Stop citing the x86 JIT for the cmask cmpxchg loop Puranjay Mohan
2026-09-24 16:30   ` Alexei Starovoitov
2026-09-24 16:33     ` Puranjay Mohan

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=aaa76b3ec5eb32105dfcc066b46c985e71d70839d58fbf5d8a258c9fa317fdb1@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=changwoo@igalia.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=puranjay@kernel.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    --cc=yonghong.song@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

all inboxes | Powered by JetHome®