Commit graph

30 commits

Author SHA1 Message Date
Björn Töpel
cff8c6599f riscv, bpf: Sign-extend return values
[ Upstream commit 2f1b0d3d733169eb11680bfa97c266ae5e757148 ]

The RISC-V architecture does not expose sub-registers, and hold all
32-bit values in a sign-extended format [1] [2]:

  | The compiler and calling convention maintain an invariant that all
  | 32-bit values are held in a sign-extended format in 64-bit
  | registers. Even 32-bit unsigned integers extend bit 31 into bits
  | 63 through 32. Consequently, conversion between unsigned and
  | signed 32-bit integers is a no-op, as is conversion from a signed
  | 32-bit integer to a signed 64-bit integer.

While BPF, on the other hand, exposes sub-registers, and use
zero-extension (similar to arm64/x86).

This has led to some subtle bugs, where a BPF JITted program has not
sign-extended the a0 register (return value in RISC-V land), passed
the return value up the kernel, e.g.:

  | int from_bpf(void);
  |
  | long foo(void)
  | {
  |    return from_bpf();
  | }

Here, a0 would be 0xffff_ffff, instead of the expected
0xffff_ffff_ffff_ffff.

Internally, the RISC-V JIT uses a5 as a dedicated register for BPF
return values.

Keep a5 zero-extended, but explicitly sign-extend a0 (which is used
outside BPF land). Now that a0 (RISC-V ABI) and a5 (BPF ABI) differs,
a0 is only moved to a5 for non-BPF native calls (BPF_PSEUDO_CALL).

Fixes: 2353ecc6f91f ("bpf, riscv: add BPF JIT for RV64G")
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://github.com/riscv/riscv-isa-manual/releases/download/riscv-isa-release-056b6ff-2023-10-02/unpriv-isa-asciidoc.pdf # [2]
Link: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/download/draft-20230929-e5c800e661a53efe3c2678d71a306323b60eb13b/riscv-abi.pdf # [2]
Link: https://lore.kernel.org/bpf/20231004120706.52848-2-bjorn@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-08 11:25:45 +01:00
Pu Lehui
b70b089e66 riscv, bpf: Factor out emit_call for kernel and bpf context
[ Upstream commit 0fd1fd0104954380477353aea29c347e85dff16d ]

The current emit_call function is not suitable for kernel function call as
it store return value to bpf R0 register. We can separate it out for common
use. Meanwhile, simplify judgment logic, that is, fixed function address
can use jal or auipc+jalr, while the unfixed can use only auipc+jalr.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Björn Töpel <bjorn@rivosinc.com>
Acked-by: Björn Töpel <bjorn@rivosinc.com>
Link: https://lore.kernel.org/bpf/20230215135205.1411105-3-pulehui@huaweicloud.com
Stable-dep-of: 2f1b0d3d7331 ("riscv, bpf: Sign-extend return values")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-08 11:25:45 +01:00
Gabriel2392
bcec93dfdf Revert "a53x: Get, fix, build and load zfs as module"
This reverts commit d647d8588c15ccd1a8fa96d20fed65b6c5c61f9d.
2024-10-04 20:09:30 -03:00
Gabriel
ea8931ae2b config: Enable CONFIG_USB_MON 2024-10-04 20:09:30 -03:00
Gabriel
eb2211b3d8 config: Enable CONFIG_PID_NS 2024-10-04 20:09:30 -03:00
Gabriel
80e4b2d56f a53x: Enable CONFIG_USER_NS 2024-10-04 20:09:30 -03:00
Gabriel2392
707896531b a53x: Get, fix, build and load zfs as module 2024-10-04 20:09:30 -03:00
Gabriel2392
0e1e7afdf9 crypto/zram: Add lz4fast algorithm
> Up to 3 times faster than default lz4
> Uses LZ4_compress_fast level 32
2024-10-04 20:09:29 -03:00
Gabriel2392
f0e1d81647 Add build stuff 2024-06-15 16:48:05 -03:00
Gabriel
7370a77c88 a53x: enable squashfs, btrfs and xfs 2024-06-15 16:43:02 -03:00
Gabriel2392
d04378f078 Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
Gabriel2392
c58c7488b1 Add rtl8821au drivers
From https://github.com/morrownr/8821au-20210708 with fixes from https://github.com/aircrack-ng/rtl8812au and some other fixes for clang / 5.10 android kernel.
2024-06-15 16:29:05 -03:00
Gabriel2392
ec54855c0d config: Enable CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 2024-06-15 16:28:49 -03:00
TALU
2a549c0e64 Revert "arm64: sigcontext: use standard __uint128_t type for vregs in struct fpsimd_context."
This reverts commit 447dabc1fedbafb1f9894e0c3054bf546a1af913
as it causes this issue with the Android build system:

out/soong/.intermediates/vendor/lineage/build/soong/generated_kernel_includes/ge
n/usr/include/asm/sigcontext.h:53:2: error: unknown type name '__uint128_t'
        __uint128_t vregs[32];
        ^
1 error generated.
2024-06-15 16:28:48 -03:00
roynatech2544
79d88bc5f0 ARM64: boot: dts: Use always-y
always is deprecated
2024-06-15 16:28:20 -03:00
Gabriel2392
8ed10b410f dts: Remove useless dtbs 2024-06-15 16:27:09 -03:00
Linux4
8c7c9710ce ARM64: dts: Fix multi string separation 2024-06-15 16:25:47 -03:00
roynatech2544
34a6e2f931 ARM64: boot: Select Image as default target 2024-06-15 16:21:19 -03:00
Gabriel2392
2efbd45726 configs: Disable Mali debugging 2024-06-15 16:21:18 -03:00
Gabriel2392
b31296d247 configs/drivers: Disable all sec_debug related stuff 2024-06-15 16:21:18 -03:00
Gabriel2392
4014f44f37 configs: Disable STACKPROTECTOR* 2024-06-15 16:21:18 -03:00
Gabriel2392
10f91eca87 configs: Disable CONFIG_LOCALVERSION_AUTO 2024-06-15 16:21:18 -03:00
Gabriel2392
5b70558bfb configs: Enable r38 Mali driver 2024-06-15 16:21:18 -03:00
Jesse Chan
291e406356 defconfig: disable CONFIG_CRYPTO_FIPS 2024-06-15 16:21:18 -03:00
roynatech2544
1fcebcf001 ARM64: configs: Turn off CONFIG_HEADERS_INSTALL
We dont need kernel headers
- Also enable CONFIG_DEBUG_SECTION_MISMATCH
2024-06-15 16:21:18 -03:00
erfanoabdi
dc32d2987c drivers: Nuke kperfmon 2024-06-15 16:21:16 -03:00
Rob Burton
c453e653ba security: samsung: defex_lsm: nuke 2024-06-15 16:20:49 -03:00
BlackMesa123
adc8f9c501 ARM64: configs: a53x_defconfig: Disable Knox/Security related features 2024-06-15 16:19:51 -03:00
Gabriel2392
c81e3117dd Make a copy of defconfig 2024-06-15 16:16:19 -03:00
Gabriel2392
7ed7ee9edf Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00