Skip to content

[PW_SID:958320] bpf, riscv64: Support load-acquire and store-release instructions#354

Closed
linux-riscv-bot wants to merge 9 commits into
workflow__riscv__fixesfrom
pw958320
Closed

[PW_SID:958320] bpf, riscv64: Support load-acquire and store-release instructions#354
linux-riscv-bot wants to merge 9 commits into
workflow__riscv__fixesfrom
pw958320

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 958320 applied to workflow__riscv__fixes

Name: bpf, riscv64: Support load-acquire and store-release instructions
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=958320
Version: 1

Linux RISC-V bot and others added 9 commits April 24, 2025 20:46
In preparation for supporting BPF load-acquire and store-release
instructions for architectures where bpf_jit_needs_zext() returns true
(e.g. riscv64), make insn_def_regno() handle load-acquires properly.

Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
We're planning to add support for the load-acquire and store-release
BPF instructions.  Define emit_load_<size>() and emit_store_<size>()
to enable/facilitate the (re)use of their code.

Tested-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
[yepeilin@google.com: cosmetic change to commit title]
Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Support BPF load-acquire (BPF_LOAD_ACQ) and store-release
(BPF_STORE_REL) instructions in the riscv64 JIT compiler.  For example,
consider the following 64-bit load-acquire (assuming little-endian):

  db 10 00 00 00 01 00 00  r1 = load_acquire((u64 *)(r1 + 0x0))
  95 00 00 00 00 00 00 00  exit

  opcode (0xdb): BPF_ATOMIC | BPF_DW | BPF_STX
  imm (0x00000100): BPF_LOAD_ACQ

The JIT compiler will emit an LD instruction followed by a FENCE R,RW
instruction for the above, e.g.:

  ld x7,0(x6)
  fence r,rw

Similarly, consider the following 16-bit store-release:

  cb 21 00 00 10 01 00 00  store_release((u16 *)(r1 + 0x0), w2)
  95 00 00 00 00 00 00 00  exit

  opcode (0xcb): BPF_ATOMIC | BPF_H | BPF_STX
  imm (0x00000110): BPF_STORE_REL

A FENCE RW,W instruction followed by an SH instruction will be emitted,
e.g.:

  fence rw,w
  sh x2,0(x4)

8-bit and 16-bit load-acquires are zero-extending (cf., LBU, LHU).  The
verifier always rejects misaligned load-acquires/store-releases (even if
BPF_F_ANY_ALIGNMENT is set), so the emitted load and store instructions
are guaranteed to be single-copy atomic.

Introduce primitives to emit the relevant (and the most common/used in
the kernel) fences, i.e. fences with R -> RW, RW -> W and RW -> RW.

Rename emit_atomic() to emit_atomic_rmw() to make it clear that it only
handles RMW atomics, and replace its is64 parameter to allow to perform
the required checks on the opsize (BPF_SIZE(code)).

Tested-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
[yepeilin@google.com: whitespace changes; cosmetic changes to commit
                      title and message]
Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Currently, the verifier inserts a zext instruction right after every 8-,
16- or 32-bit load-acquire, which is already zero-extending.  Skip such
redundant zext instructions.

While we are here, update that already-obsolete comment about "skip the
next instruction" in build_body().  Also change emit_atomic_rmw()'s
parameters to keep it consistent with emit_atomic_ld_st().

Note that checking 'insn[1]' relies on 'insn' not being the last
instruction, which should have been guaranteed by the verifier; we
already use 'insn[1]' elsewhere in the file for similar purposes.
Additionally, we don't check if 'insn[1]' is actually a zext for our
load-acquire's dst_reg, or some other registers - in other words, here
we are relying on the verifier to always insert a redundant zext right
after a 8/16/32-bit load-acquire, for its dst_reg.

Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Instead of open-coding the conditions, use
'#ifdef CAN_USE_LOAD_ACQ_STORE_REL' to guard the following tests:

  verifier_precision/bpf_load_acquire
  verifier_precision/bpf_store_release
  verifier_store_release/*

Note that, for the first two tests in verifier_precision.c, switching to
'#ifdef CAN_USE_LOAD_ACQ_STORE_REL' means also checking if
'__clang_major__ >= 18', which has already been guaranteed by the outer
'#if' check.

Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Currently, we pass 0x1234567890abcdef to __retval() for the following
two tests:

  verifier_load_acquire/load_acquire_64
  verifier_store_release/store_release_64

However, the upper 32 bits of that value are being ignored, since
__retval() expects an int.  Actually, the tests would still pass even if
I change '__retval(0x1234567890abcdef)' to e.g. '__retval(0x90abcdef)'.

Restructure the tests a bit to test the entire 64-bit values properly.
Do the same to their 8-, 16- and 32-bit variants as well to keep the
style consistent.

Fixes: ff3afe5 ("selftests/bpf: Add selftests for load-acquire and store-release instructions")
Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Verify that 8-, 16- and 32-bit load-acquires are zero-extending by using
immediate values with their highest bit set.  Do the same for the 64-bit
variant to keep the style consistent.

Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
…for riscv64

For riscv64, enable all BPF_{LOAD_ACQ,STORE_REL} selftests except the
arena_atomics/* ones (not guarded behind CAN_USE_LOAD_ACQ_STORE_REL),
since arena access is not yet supported.

Signed-off-by: Peilin Ye <yepeilin@google.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 112.34 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 987.21 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1297.29 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.86 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 22.04 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.75 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 66.99 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
kdoc
Desc: Detects for kdoc errors
Duration: 0.91 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
module-param
Desc: Detect module_param changes
Duration: 1.51 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[bpf-next,1/8] bpf/verifier: Handle BPF_LOAD_ACQ instructions in insn_def_regno()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 107.80 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 985.60 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1289.69 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.39 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.46 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.77 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 66.99 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[bpf-next,2/8] bpf, riscv64: Introduce emit_load_() and emit_store_()"
kdoc
Desc: Detects for kdoc errors
Duration: 0.93 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[bpf-next,6/8] selftests/bpf: Avoid passing out-of-range values to __retval()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 6: "[bpf-next,6/8] selftests/bpf: Avoid passing out-of-range values to __retval()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 106.11 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 897.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1168.50 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.60 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.66 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.72 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 66.86 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
kdoc
Desc: Detects for kdoc errors
Duration: 0.87 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 7: "[bpf-next,7/8] selftests/bpf: Verify zero-extension behavior in load-acquire tests"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.32 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 107.15 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 898.15 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1170.55 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 20.33 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.78 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.73 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 68.00 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
kdoc
Desc: Detects for kdoc errors
Duration: 0.80 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[bpf-next,8/8] selftests/bpf: Enable non-arena load-acquire/store-release selftests for riscv64"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__fixes branch 2 times, most recently from 4d9ad71 to 625be03 Compare May 6, 2025 09:20
@linux-riscv-bot linux-riscv-bot deleted the pw958320 branch May 7, 2025 04:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants