~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_ldsx_insn.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
  3 
  4 #include "vmlinux.h"
  5 #include <bpf/bpf_helpers.h>
  6 #include <bpf/bpf_tracing.h>
  7 
  8 #if (defined(__TARGET_ARCH_arm64) || defined(__TARGET_ARCH_x86) || \
  9      (defined(__TARGET_ARCH_riscv) && __riscv_xlen == 64) ||       \
 10      defined(__TARGET_ARCH_s390) || defined(__TARGET_ARCH_loongarch)) && \
 11      __clang_major__ >= 18
 12 const volatile int skip = 0;
 13 #else
 14 const volatile int skip = 1;
 15 #endif
 16 
 17 volatile const short val1 = -1;
 18 volatile const int val2 = -1;
 19 short val3 = -1;
 20 int val4 = -1;
 21 int done1, done2, ret1, ret2;
 22 
 23 SEC("?raw_tp/sys_enter")
 24 int rdonly_map_prog(const void *ctx)
 25 {
 26         if (done1)
 27                 return 0;
 28 
 29         done1 = 1;
 30         /* val1/val2 readonly map */
 31         if (val1 == val2)
 32                 ret1 = 1;
 33         return 0;
 34 
 35 }
 36 
 37 SEC("?raw_tp/sys_enter")
 38 int map_val_prog(const void *ctx)
 39 {
 40         if (done2)
 41                 return 0;
 42 
 43         done2 = 1;
 44         /* val1/val2 regular read/write map */
 45         if (val3 == val4)
 46                 ret2 = 1;
 47         return 0;
 48 
 49 }
 50 
 51 struct bpf_testmod_struct_arg_1 {
 52         int a;
 53 };
 54 
 55 long long int_member;
 56 
 57 SEC("?fentry/bpf_testmod_test_arg_ptr_to_struct")
 58 int BPF_PROG2(test_ptr_struct_arg, struct bpf_testmod_struct_arg_1 *, p)
 59 {
 60         /* probed memory access */
 61         int_member = p->a;
 62         return 0;
 63 }
 64 
 65 long long set_optlen, set_retval;
 66 
 67 SEC("?cgroup/getsockopt")
 68 int _getsockopt(volatile struct bpf_sockopt *ctx)
 69 {
 70         int old_optlen, old_retval;
 71 
 72         old_optlen = ctx->optlen;
 73         old_retval = ctx->retval;
 74 
 75         ctx->optlen = -1;
 76         ctx->retval = -1;
 77 
 78         /* sign extension for ctx member */
 79         set_optlen = ctx->optlen;
 80         set_retval = ctx->retval;
 81 
 82         ctx->optlen = old_optlen;
 83         ctx->retval = old_retval;
 84 
 85         return 0;
 86 }
 87 
 88 long long set_mark;
 89 
 90 SEC("?tc")
 91 int _tc(volatile struct __sk_buff *skb)
 92 {
 93         long long tmp_mark;
 94         int old_mark;
 95 
 96         old_mark = skb->mark;
 97 
 98         skb->mark = 0xf6fe;
 99 
100         /* narrowed sign extension for ctx member */
101 #if __clang_major__ >= 18
102         /* force narrow one-byte signed load. Otherwise, compiler may
103          * generate a 32-bit unsigned load followed by an s8 movsx.
104          */
105         asm volatile ("r1 = *(s8 *)(%[ctx] + %[off_mark])\n\t"
106                       "%[tmp_mark] = r1"
107                       : [tmp_mark]"=r"(tmp_mark)
108                       : [ctx]"r"(skb),
109                         [off_mark]"i"(offsetof(struct __sk_buff, mark)
110 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
111                         + sizeof(skb->mark) - 1
112 #endif
113                         )
114                       : "r1");
115 #else
116         tmp_mark = (char)skb->mark;
117 #endif
118         set_mark = tmp_mark;
119 
120         skb->mark = old_mark;
121 
122         return 0;
123 }
124 
125 char _license[] SEC("license") = "GPL";
126 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php