1*9f42204cSYonghong Song // SPDX-License-Identifier: GPL-2.0 2*9f42204cSYonghong Song /* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ 3*9f42204cSYonghong Song 4*9f42204cSYonghong Song #include <vmlinux.h> 5*9f42204cSYonghong Song #include <bpf/bpf_helpers.h> 6*9f42204cSYonghong Song #include "../test_kmods/bpf_testmod_kfunc.h" 7*9f42204cSYonghong Song #include "bpf_misc.h" 8*9f42204cSYonghong Song 9*9f42204cSYonghong Song #if defined(__BPF_FEATURE_STACK_ARGUMENT) 10*9f42204cSYonghong Song 11*9f42204cSYonghong Song SEC("tc") 12*9f42204cSYonghong Song __failure __msg("Unrecognized *(R11-8) type STRUCT") 13*9f42204cSYonghong Song int test_stack_arg_big(struct __sk_buff *skb) 14*9f42204cSYonghong Song { 15*9f42204cSYonghong Song struct prog_test_big_arg s = { .a = 1, .b = 2 }; 16*9f42204cSYonghong Song 17*9f42204cSYonghong Song return bpf_kfunc_call_stack_arg_big(1, 2, 3, 4, 5, s); 18*9f42204cSYonghong Song } 19*9f42204cSYonghong Song 20*9f42204cSYonghong Song SEC("socket") 21*9f42204cSYonghong Song __description("r11 in ALU instruction") 22*9f42204cSYonghong Song __failure __msg("R11 is invalid") 23*9f42204cSYonghong Song __naked void r11_alu_reject(void) 24*9f42204cSYonghong Song { 25*9f42204cSYonghong Song asm volatile ( 26*9f42204cSYonghong Song "r11 += 1;" 27*9f42204cSYonghong Song "r0 = 0;" 28*9f42204cSYonghong Song "exit;" 29*9f42204cSYonghong Song ::: __clobber_all); 30*9f42204cSYonghong Song } 31*9f42204cSYonghong Song 32*9f42204cSYonghong Song SEC("socket") 33*9f42204cSYonghong Song __description("r11 store with non-DW size") 34*9f42204cSYonghong Song __failure __msg("R11 is invalid") 35*9f42204cSYonghong Song __naked void r11_store_non_dw(void) 36*9f42204cSYonghong Song { 37*9f42204cSYonghong Song asm volatile ( 38*9f42204cSYonghong Song "*(u32 *)(r11 - 8) = r1;" 39*9f42204cSYonghong Song "r0 = 0;" 40*9f42204cSYonghong Song "exit;" 41*9f42204cSYonghong Song ::: __clobber_all); 42*9f42204cSYonghong Song } 43*9f42204cSYonghong Song 44*9f42204cSYonghong Song SEC("socket") 45*9f42204cSYonghong Song __description("r11 store with unaligned offset") 46*9f42204cSYonghong Song __failure __msg("R11 is invalid") 47*9f42204cSYonghong Song __naked void r11_store_unaligned(void) 48*9f42204cSYonghong Song { 49*9f42204cSYonghong Song asm volatile ( 50*9f42204cSYonghong Song "*(u64 *)(r11 - 4) = r1;" 51*9f42204cSYonghong Song "r0 = 0;" 52*9f42204cSYonghong Song "exit;" 53*9f42204cSYonghong Song ::: __clobber_all); 54*9f42204cSYonghong Song } 55*9f42204cSYonghong Song 56*9f42204cSYonghong Song SEC("socket") 57*9f42204cSYonghong Song __description("r11 store with positive offset") 58*9f42204cSYonghong Song __failure __msg("R11 is invalid") 59*9f42204cSYonghong Song __naked void r11_store_positive_off(void) 60*9f42204cSYonghong Song { 61*9f42204cSYonghong Song asm volatile ( 62*9f42204cSYonghong Song "*(u64 *)(r11 + 8) = r1;" 63*9f42204cSYonghong Song "r0 = 0;" 64*9f42204cSYonghong Song "exit;" 65*9f42204cSYonghong Song ::: __clobber_all); 66*9f42204cSYonghong Song } 67*9f42204cSYonghong Song 68*9f42204cSYonghong Song SEC("socket") 69*9f42204cSYonghong Song __description("r11 load with negative offset") 70*9f42204cSYonghong Song __failure __msg("R11 is invalid") 71*9f42204cSYonghong Song __naked void r11_load_negative_off(void) 72*9f42204cSYonghong Song { 73*9f42204cSYonghong Song asm volatile ( 74*9f42204cSYonghong Song "r0 = *(u64 *)(r11 - 8);" 75*9f42204cSYonghong Song "exit;" 76*9f42204cSYonghong Song ::: __clobber_all); 77*9f42204cSYonghong Song } 78*9f42204cSYonghong Song 79*9f42204cSYonghong Song SEC("socket") 80*9f42204cSYonghong Song __description("r11 load with non-DW size") 81*9f42204cSYonghong Song __failure __msg("R11 is invalid") 82*9f42204cSYonghong Song __naked void r11_load_non_dw(void) 83*9f42204cSYonghong Song { 84*9f42204cSYonghong Song asm volatile ( 85*9f42204cSYonghong Song "r0 = *(u32 *)(r11 + 8);" 86*9f42204cSYonghong Song "exit;" 87*9f42204cSYonghong Song ::: __clobber_all); 88*9f42204cSYonghong Song } 89*9f42204cSYonghong Song 90*9f42204cSYonghong Song SEC("socket") 91*9f42204cSYonghong Song __description("r11 store with zero offset") 92*9f42204cSYonghong Song __failure __msg("R11 is invalid") 93*9f42204cSYonghong Song __naked void r11_store_zero_off(void) 94*9f42204cSYonghong Song { 95*9f42204cSYonghong Song asm volatile ( 96*9f42204cSYonghong Song "*(u64 *)(r11 + 0) = r1;" 97*9f42204cSYonghong Song "r0 = 0;" 98*9f42204cSYonghong Song "exit;" 99*9f42204cSYonghong Song ::: __clobber_all); 100*9f42204cSYonghong Song } 101*9f42204cSYonghong Song 102*9f42204cSYonghong Song #else 103*9f42204cSYonghong Song 104*9f42204cSYonghong Song SEC("tc") 105*9f42204cSYonghong Song __description("stack_arg_fail: not supported, dummy test") 106*9f42204cSYonghong Song __success 107*9f42204cSYonghong Song int test_stack_arg_big(struct __sk_buff *skb) 108*9f42204cSYonghong Song { 109*9f42204cSYonghong Song return 0; 110*9f42204cSYonghong Song } 111*9f42204cSYonghong Song 112*9f42204cSYonghong Song #endif 113*9f42204cSYonghong Song 114*9f42204cSYonghong Song char _license[] SEC("license") = "GPL"; 115