linux-stable/arch/x86
Hou Tao 7c05e7f3e7 bpf: Support inlining bpf_kptr_xchg() helper
The motivation of inlining bpf_kptr_xchg() comes from the performance
profiling of bpf memory allocator benchmark. The benchmark uses
bpf_kptr_xchg() to stash the allocated objects and to pop the stashed
objects for free. After inling bpf_kptr_xchg(), the performance for
object free on 8-CPUs VM increases about 2%~10%. The inline also has
downside: both the kasan and kcsan checks on the pointer will be
unavailable.

bpf_kptr_xchg() can be inlined by converting the calling of
bpf_kptr_xchg() into an atomic_xchg() instruction. But the conversion
depends on two conditions:
1) JIT backend supports atomic_xchg() on pointer-sized word
2) For the specific arch, the implementation of xchg is the same as
   atomic_xchg() on pointer-sized words.

It seems most 64-bit JIT backends satisfies these two conditions. But
as a precaution, defining a weak function bpf_jit_supports_ptr_xchg()
to state whether such conversion is safe and only supporting inline for
64-bit host.

For x86-64, it supports BPF_XCHG atomic operation and both xchg() and
atomic_xchg() use arch_xchg() to implement the exchange, so enabling the
inline of bpf_kptr_xchg() on x86-64 first.

Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20240105104819.3916743-2-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2024-01-23 14:40:21 -08:00
..
boot x86/cleanups changes for v6.8: 2024-01-08 17:23:32 -08:00
coco - Add support managing TDX host hardware 2024-01-18 13:41:48 -08:00
configs hardening updates for v6.7-rc1 2023-10-30 19:09:55 -10:00
crypto This update includes the following changes: 2024-01-10 12:23:43 -08:00
entry asm-generic cleanups for 6.8 2024-01-10 18:13:44 -08:00
events Performance events changes for v6.8 are: 2024-01-08 19:37:20 -08:00
hyperv x86/cleanups changes for v6.8: 2024-01-08 17:23:32 -08:00
ia32
include - Add support managing TDX host hardware 2024-01-18 13:41:48 -08:00
kernel RTC for 6.8 2024-01-18 17:25:39 -08:00
kvm Generic: 2024-01-17 13:03:37 -08:00
lib header cleanups for 6.8 2024-01-10 16:43:55 -08:00
math-emu
mm Many singleton patches against the MM code. The patch series which 2024-01-09 11:18:47 -08:00
net bpf: Support inlining bpf_kptr_xchg() helper 2024-01-23 14:40:21 -08:00
pci pci-v6.8-changes 2024-01-17 16:23:17 -08:00
platform x86/cleanups changes for v6.8: 2024-01-08 17:23:32 -08:00
power
purgatory
ras
realmode x86/cleanups changes for v6.8: 2024-01-08 17:23:32 -08:00
tools x86/build changes for v6.8: 2024-01-08 17:22:02 -08:00
um This pull request contains the following changes for UML: 2024-01-17 10:44:34 -08:00
video fbdev: Replace fb_pgprotect() with pgprot_framebuffer() 2023-10-12 09:20:46 +02:00
virt x86/mce: Differentiate real hardware #MCs from TDX erratum ones 2023-12-12 08:46:46 -08:00
xen x86/cleanups changes for v6.8: 2024-01-08 17:23:32 -08:00
.gitignore
Kbuild
Kconfig IOMMU Updates for Linux v6.8 2024-01-18 15:16:57 -08:00
Kconfig.assembler
Kconfig.cpu x86/Kconfig: Rework CONFIG_X86_PAE dependency 2023-12-19 13:03:06 +01:00
Kconfig.debug
Makefile Kbuild updates for v6.7 2023-11-04 08:07:19 -10:00
Makefile.postlink kbuild: remove ARCH_POSTLINK from module builds 2023-10-28 21:10:08 +09:00
Makefile.um
Makefile_32.cpu