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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/verifier_bitfield_write.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 
  3 #include <linux/bpf.h>
  4 #include <stdint.h>
  5 
  6 #include <bpf/bpf_helpers.h>
  7 #include <bpf/bpf_core_read.h>
  8 
  9 #include "bpf_misc.h"
 10 
 11 struct core_reloc_bitfields {
 12         /* unsigned bitfields */
 13         uint8_t         ub1: 1;
 14         uint8_t         ub2: 2;
 15         uint32_t        ub7: 7;
 16         /* signed bitfields */
 17         int8_t          sb4: 4;
 18         int32_t         sb20: 20;
 19         /* non-bitfields */
 20         uint32_t        u32;
 21         int32_t         s32;
 22 } __attribute__((preserve_access_index));
 23 
 24 SEC("tc")
 25 __description("single CO-RE bitfield roundtrip")
 26 __btf_path("btf__core_reloc_bitfields.bpf.o")
 27 __success
 28 __retval(3)
 29 int single_field_roundtrip(struct __sk_buff *ctx)
 30 {
 31         struct core_reloc_bitfields bitfields;
 32 
 33         __builtin_memset(&bitfields, 0, sizeof(bitfields));
 34         BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 3);
 35         return BPF_CORE_READ_BITFIELD(&bitfields, ub2);
 36 }
 37 
 38 SEC("tc")
 39 __description("multiple CO-RE bitfield roundtrip")
 40 __btf_path("btf__core_reloc_bitfields.bpf.o")
 41 __success
 42 __retval(0x3FD)
 43 int multiple_field_roundtrip(struct __sk_buff *ctx)
 44 {
 45         struct core_reloc_bitfields bitfields;
 46         uint8_t ub2;
 47         int8_t sb4;
 48 
 49         __builtin_memset(&bitfields, 0, sizeof(bitfields));
 50         BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 1);
 51         BPF_CORE_WRITE_BITFIELD(&bitfields, sb4, -1);
 52 
 53         ub2 = BPF_CORE_READ_BITFIELD(&bitfields, ub2);
 54         sb4 = BPF_CORE_READ_BITFIELD(&bitfields, sb4);
 55 
 56         return (((uint8_t)sb4) << 2) | ub2;
 57 }
 58 
 59 SEC("tc")
 60 __description("adjacent CO-RE bitfield roundtrip")
 61 __btf_path("btf__core_reloc_bitfields.bpf.o")
 62 __success
 63 __retval(7)
 64 int adjacent_field_roundtrip(struct __sk_buff *ctx)
 65 {
 66         struct core_reloc_bitfields bitfields;
 67         uint8_t ub1, ub2;
 68 
 69         __builtin_memset(&bitfields, 0, sizeof(bitfields));
 70         BPF_CORE_WRITE_BITFIELD(&bitfields, ub1, 1);
 71         BPF_CORE_WRITE_BITFIELD(&bitfields, ub2, 3);
 72 
 73         ub1 = BPF_CORE_READ_BITFIELD(&bitfields, ub1);
 74         ub2 = BPF_CORE_READ_BITFIELD(&bitfields, ub2);
 75 
 76         return (ub2 << 1) | ub1;
 77 }
 78 
 79 SEC("tc")
 80 __description("multibyte CO-RE bitfield roundtrip")
 81 __btf_path("btf__core_reloc_bitfields.bpf.o")
 82 __success
 83 __retval(0x21)
 84 int multibyte_field_roundtrip(struct __sk_buff *ctx)
 85 {
 86         struct core_reloc_bitfields bitfields;
 87         uint32_t ub7;
 88         uint8_t ub1;
 89 
 90         __builtin_memset(&bitfields, 0, sizeof(bitfields));
 91         BPF_CORE_WRITE_BITFIELD(&bitfields, ub1, 1);
 92         BPF_CORE_WRITE_BITFIELD(&bitfields, ub7, 16);
 93 
 94         ub1 = BPF_CORE_READ_BITFIELD(&bitfields, ub1);
 95         ub7 = BPF_CORE_READ_BITFIELD(&bitfields, ub7);
 96 
 97         return (ub7 << 1) | ub1;
 98 }
 99 
100 char _license[] SEC("license") = "GPL";
101 

~ [ 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