1 // SPDX-License-Identifier: GPL-2.0 2 3 #include <vmlinux.h> 4 #include <bpf/bpf_helpers.h> 5 #include "bpf_misc.h" 6 7 #if defined(__TARGET_ARCH_x86) 8 9 int percpu_data SEC(".percpu"); 10 11 /* 12 * An ld_imm64 of a per-CPU map value is followed by a mov_percpu_addr that 13 * reuses the same register, so check that the add resolves into the register 14 * the address was loaded into, for every register. 15 */ 16 SEC("raw_tp") 17 __description("per-CPU address resolution") 18 __success 19 __arch_x86_64 20 __jited(" movabsq $0x{{.*}}, %rax") 21 __jited(" addq %gs:{{.*}}, %rax") 22 __jited(" movabsq $0x{{.*}}, %rdi") 23 __jited(" addq %gs:{{.*}}, %rdi") 24 __jited(" movabsq $0x{{.*}}, %rsi") 25 __jited(" addq %gs:{{.*}}, %rsi") 26 __jited(" movabsq $0x{{.*}}, %rdx") 27 __jited(" addq %gs:{{.*}}, %rdx") 28 __jited(" movabsq $0x{{.*}}, %rcx") 29 __jited(" addq %gs:{{.*}}, %rcx") 30 __jited(" movabsq $0x{{.*}}, %r8") 31 __jited(" addq %gs:{{.*}}, %r8") 32 __jited(" movabsq $0x{{.*}}, %rbx") 33 __jited(" addq %gs:{{.*}}, %rbx") 34 __jited(" movabsq $0x{{.*}}, %r13") 35 __jited(" addq %gs:{{.*}}, %r13") 36 __jited(" movabsq $0x{{.*}}, %r14") 37 __jited(" addq %gs:{{.*}}, %r14") 38 __jited(" movabsq $0x{{.*}}, %r15") 39 __jited(" addq %gs:{{.*}}, %r15") 40 __naked void percpu_addr(void) 41 { 42 asm volatile (" \ 43 r0 = %[percpu_data] ll; \ 44 r1 = %[percpu_data] ll; \ 45 r2 = %[percpu_data] ll; \ 46 r3 = %[percpu_data] ll; \ 47 r4 = %[percpu_data] ll; \ 48 r5 = %[percpu_data] ll; \ 49 r6 = %[percpu_data] ll; \ 50 r7 = %[percpu_data] ll; \ 51 r8 = %[percpu_data] ll; \ 52 r9 = %[percpu_data] ll; \ 53 r0 = 0; \ 54 exit; \ 55 " : 56 : __imm_addr(percpu_data) 57 : __clobber_all); 58 } 59 60 #else 61 62 SEC("raw_tp") 63 __description("percpu addr dummy") 64 __success 65 int dummy_test(void) 66 { 67 return 0; 68 } 69 70 #endif 71 72 char _license[] SEC("license") = "GPL"; 73