1 // SPDX-License-Identifier: GPL-2.0 2 #include <vmlinux.h> 3 #include <bpf/bpf_helpers.h> 4 #include "bpf_misc.h" 5 6 /* Used for testing map name. */ 7 int loong SEC(".percpu.looooooooong"); 8 int data3 SEC(".data.percpu"); 9 int data2 SEC(".percpu.data"); 10 11 int run; 12 /* cpu_id as array to verify map value resizing. */ 13 int cpu_id[1] SEC(".percpu"); 14 int data SEC(".percpu") = -1; 15 int nums[7] SEC(".percpu"); 16 bool set SEC(".percpu") = false; 17 struct { 18 char set; 19 int i; 20 int nums[7]; 21 } struct_data SEC(".percpu") = { 22 .set = 0, 23 .i = -1, 24 }; 25 26 SEC("raw_tp/task_rename") 27 __auxiliary 28 int update_percpu_data(void *ctx) 29 { 30 struct_data.nums[6] = 0xc0de; 31 struct_data.set = 1; 32 struct_data.i = 1; 33 nums[6] = 0xc0de; 34 data = 1; 35 run++; 36 set = true; 37 cpu_id[0] = bpf_get_smp_processor_id(); 38 return 0; 39 } 40 41 static const char fmt[] SEC(".percpu.fmt") = "data %d\n"; 42 43 SEC("?kprobe") 44 __failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string") 45 int verifier_strncmp(void *ctx) 46 { 47 return bpf_strncmp("test", 5, fmt); 48 } 49 50 SEC("?kprobe") 51 __failure __msg("R{{[0-9]+}} points to percpu_array map which cannot be used as const string") 52 int verifier_snprintf(void *ctx) 53 { 54 u64 args[] = { data }; 55 char buf[128]; 56 int len; 57 58 len = bpf_snprintf(buf, sizeof(buf), fmt, args, sizeof(args)); 59 if (len > 0) 60 bpf_printk("snprintf: %s\n", buf); 61 return 0; 62 } 63 64 char _license[] SEC("license") = "GPL"; 65