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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/wq_failures.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) 2024 Benjamin Tissoires
  3  */
  4 
  5 #include "bpf_experimental.h"
  6 #include <bpf/bpf_helpers.h>
  7 #include "bpf_misc.h"
  8 #include "../bpf_testmod/bpf_testmod_kfunc.h"
  9 
 10 char _license[] SEC("license") = "GPL";
 11 
 12 struct elem {
 13         struct bpf_wq w;
 14 };
 15 
 16 struct {
 17         __uint(type, BPF_MAP_TYPE_ARRAY);
 18         __uint(max_entries, 2);
 19         __type(key, int);
 20         __type(value, struct elem);
 21 } array SEC(".maps");
 22 
 23 struct {
 24         __uint(type, BPF_MAP_TYPE_LRU_HASH);
 25         __uint(max_entries, 4);
 26         __type(key, int);
 27         __type(value, struct elem);
 28 } lru SEC(".maps");
 29 
 30 /* callback for non sleepable workqueue */
 31 static int wq_callback(void *map, int *key, void *value)
 32 {
 33         bpf_kfunc_common_test();
 34         return 0;
 35 }
 36 
 37 /* callback for sleepable workqueue */
 38 static int wq_cb_sleepable(void *map, int *key, void *value)
 39 {
 40         bpf_kfunc_call_test_sleepable();
 41         return 0;
 42 }
 43 
 44 SEC("tc")
 45 /* test that bpf_wq_init takes a map as a second argument
 46  */
 47 __log_level(2)
 48 __flag(BPF_F_TEST_STATE_FREQ)
 49 __failure
 50 __msg(": (85) call bpf_wq_init#") /* anchor message */
 51 __msg("pointer in R2 isn't map pointer")
 52 long test_wq_init_nomap(void *ctx)
 53 {
 54         struct bpf_wq *wq;
 55         struct elem *val;
 56         int key = 0;
 57 
 58         val = bpf_map_lookup_elem(&array, &key);
 59         if (!val)
 60                 return -1;
 61 
 62         wq = &val->w;
 63         if (bpf_wq_init(wq, &key, 0) != 0)
 64                 return -3;
 65 
 66         return 0;
 67 }
 68 
 69 SEC("tc")
 70 /* test that the workqueue is part of the map in bpf_wq_init
 71  */
 72 __log_level(2)
 73 __flag(BPF_F_TEST_STATE_FREQ)
 74 __failure
 75 __msg(": (85) call bpf_wq_init#") /* anchor message */
 76 __msg("workqueue pointer in R1 map_uid=0 doesn't match map pointer in R2 map_uid=0")
 77 long test_wq_init_wrong_map(void *ctx)
 78 {
 79         struct bpf_wq *wq;
 80         struct elem *val;
 81         int key = 0;
 82 
 83         val = bpf_map_lookup_elem(&array, &key);
 84         if (!val)
 85                 return -1;
 86 
 87         wq = &val->w;
 88         if (bpf_wq_init(wq, &lru, 0) != 0)
 89                 return -3;
 90 
 91         return 0;
 92 }
 93 
 94 SEC("?tc")
 95 __log_level(2)
 96 __failure
 97 /* check that the first argument of bpf_wq_set_callback()
 98  * is a correct bpf_wq pointer.
 99  */
100 __msg(": (85) call bpf_wq_set_callback_impl#") /* anchor message */
101 __msg("arg#0 doesn't point to a map value")
102 long test_wrong_wq_pointer(void *ctx)
103 {
104         int key = 0;
105         struct bpf_wq *wq;
106 
107         wq = bpf_map_lookup_elem(&array, &key);
108         if (!wq)
109                 return 1;
110 
111         if (bpf_wq_init(wq, &array, 0))
112                 return 2;
113 
114         if (bpf_wq_set_callback((void *)&wq, wq_callback, 0))
115                 return 3;
116 
117         return -22;
118 }
119 
120 SEC("?tc")
121 __log_level(2)
122 __failure
123 /* check that the first argument of bpf_wq_set_callback()
124  * is a correct bpf_wq pointer.
125  */
126 __msg(": (85) call bpf_wq_set_callback_impl#") /* anchor message */
127 __msg("off 1 doesn't point to 'struct bpf_wq' that is at 0")
128 long test_wrong_wq_pointer_offset(void *ctx)
129 {
130         int key = 0;
131         struct bpf_wq *wq;
132 
133         wq = bpf_map_lookup_elem(&array, &key);
134         if (!wq)
135                 return 1;
136 
137         if (bpf_wq_init(wq, &array, 0))
138                 return 2;
139 
140         if (bpf_wq_set_callback((void *)wq + 1, wq_cb_sleepable, 0))
141                 return 3;
142 
143         return -22;
144 }
145 

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