History

Merge tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says: ==================== pull-request: bpf-next 2024-09-11 We've added 12 non-merge commits during the last 16 day(s) which contain a total of 20 files changed, 228 insertions(+), 30 deletions(-). There's a minor merge conflict in drivers/net/netkit.c: 00d066a4d4ed ("netdev_features: convert NETIF_F_LLTX to dev->lltx") d96608794889 ("netkit: Disable netpoll support") The main changes are: 1) Enable bpf_dynptr_from_skb for tp_btf such that this can be used to easily parse skbs in BPF programs attached to tracepoints, from Philo Lu. 2) Add a cond_resched() point in BPF's sock_hash_free() as there have been several syzbot soft lockup reports recently, from Eric Dumazet. 3) Fix xsk_buff_can_alloc() to account for queue_empty_descs which got noticed when zero copy ice driver started to use it, from Maciej Fijalkowski. 4) Move the xdp:xdp_cpumap_kthread tracepoint before cpumap pushes skbs up via netif_receive_skb_list() to better measure latencies, from Daniel Xu. 5) Follow-up to disable netpoll support from netkit, from Daniel Borkmann. 6) Improve xsk selftests to not assume a fixed MAX_SKB_FRAGS of 17 but instead gather the actual value via /proc/sys/net/core/max_skb_frags, also from Maciej Fijalkowski. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: sock_map: Add a cond_resched() in sock_hash_free() selftests/bpf: Expand skb dynptr selftests for tp_btf bpf: Allow bpf_dynptr_from_skb() for tp_btf tcp: Use skb__nullable in trace_tcp_send_reset selftests/bpf: Add test for __nullable suffix in tp_btf bpf: Support __nullable argument suffix for tp_btf bpf, cpumap: Move xdp:xdp_cpumap_kthread tracepoint before rcv selftests/xsk: Read current MAX_SKB_FRAGS from sysctl knob xsk: Bump xsk_queue::queue_empty_descs in xp_can_alloc() tcp_bpf: Remove an unused parameter for bpf_tcp_ingress() bpf, sockmap: Correct spelling skmsg.c netkit: Disable netpoll support Signed-off-by: Jakub Kicinski <kuba@kernel.org> ====================

Jakub Kicinski committed 2 years ago

Commit 3b7dc702 parents f1bcd48 b1339be20 files · +228 −30Browse files

Unified · Split

20 files
  1. drivers/net/netkit.c +1 −0
  2. include/trace/events/tcp.h +6 −6
  3. kernel/bpf/btf.c +3 −0
  4. kernel/bpf/cpumap.c +4 −2
  5. kernel/bpf/verifier.c +32 −4
  6. net/core/filter.c +2 −1
  7. net/core/skmsg.c +1 −1
  8. net/core/sock_map.c +1 −0
  9. net/ipv4/tcp_bpf.c +2 −2
  10. net/xdp/xsk_buff_pool.c +9 −1
  11. net/xdp/xsk_queue.h +0 −5
  12. tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h +6 −0
  13. tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +2 −0
  14. tools/testing/selftests/bpf/prog_tests/dynptr.c +35 −2
  15. tools/testing/selftests/bpf/prog_tests/tp_btf_nullable.c +14 −0
  16. tools/testing/selftests/bpf/progs/dynptr_fail.c +25 −0
  17. tools/testing/selftests/bpf/progs/dynptr_success.c +23 −0
  18. tools/testing/selftests/bpf/progs/test_tp_btf_nullable.c +24 −0
  19. tools/testing/selftests/bpf/xskxceiver.c +38 −5
  20. tools/testing/selftests/bpf/xskxceiver.h +0 −1
drivers/net/netkit.c+1−0
@@ -255,6 +255,7 @@ static void netkit_setup(struct net_device *dev) · 254 unmodified lines
255 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;255 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
256 dev->priv_flags |= IFF_PHONY_HEADROOM;256 dev->priv_flags |= IFF_PHONY_HEADROOM;
257 dev->priv_flags |= IFF_NO_QUEUE;257 dev->priv_flags |= IFF_NO_QUEUE;
258 dev->priv_flags |= IFF_DISABLE_NETPOLL;
258 dev->lltx = true;259 dev->lltx = true;
259 260
260 dev->ethtool_ops = &netkit_ethtool_ops;261 dev->ethtool_ops = &netkit_ethtool_ops;
include/trace/events/tcp.h+6−6
@@ -91,10 +91,10 @@ DEFINE_RST_REASON(FN, FN) · 90 unmodified lines
91TRACE_EVENT(tcp_send_reset,91TRACE_EVENT(tcp_send_reset,
92 92
93 TP_PROTO(const struct sock *sk,93 TP_PROTO(const struct sock *sk,
94 const struct sk_buff *skb,94 const struct sk_buff *skb__nullable,
95 const enum sk_rst_reason reason),95 const enum sk_rst_reason reason),
96 96
97 TP_ARGS(sk, skb, reason),97 TP_ARGS(sk, skb__nullable, reason),
98 98
99 TP_STRUCT__entry(99 TP_STRUCT__entry(
100 __field(const void *, skbaddr)100 __field(const void *, skbaddr)
@@ -106,7 +106,7 @@ TRACE_EVENT(tcp_send_reset, · 5 unmodified lines
106 ),106 ),
107 107
108 TP_fast_assign(108 TP_fast_assign(
109 __entry->skbaddr = skb;109 __entry->skbaddr = skb__nullable;
110 __entry->skaddr = sk;110 __entry->skaddr = sk;
111 /* Zero means unknown state. */111 /* Zero means unknown state. */
112 __entry->state = sk ? sk->sk_state : 0;112 __entry->state = sk ? sk->sk_state : 0;
@@ -118,13 +118,13 @@ TRACE_EVENT(tcp_send_reset, · 5 unmodified lines
118 const struct inet_sock *inet = inet_sk(sk);118 const struct inet_sock *inet = inet_sk(sk);
119 119
120 TP_STORE_ADDR_PORTS(__entry, inet, sk);120 TP_STORE_ADDR_PORTS(__entry, inet, sk);
121 } else if (skb) {121 } else if (skb__nullable) {
122 const struct tcphdr *th = (const struct tcphdr *)skb->data;122 const struct tcphdr *th = (const struct tcphdr *)skb__nullable->data;
123 /*123 /*
124 * We should reverse the 4-tuple of skb, so later124 * We should reverse the 4-tuple of skb, so later
125 * it can print the right flow direction of rst.125 * it can print the right flow direction of rst.
126 */126 */
127 TP_STORE_ADDR_PORTS_SKB(skb, th, entry->daddr, entry->saddr);127 TP_STORE_ADDR_PORTS_SKB(skb__nullable, th, entry->daddr, entry->saddr);
128 }128 }
129 __entry->reason = reason;129 __entry->reason = reason;
130 ),130 ),
kernel/bpf/btf.c+3−0
@@ -6525,6 +6525,9 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, · 6524 unmodified lines
6525 if (prog_args_trusted(prog))6525 if (prog_args_trusted(prog))
6526 info->reg_type |= PTR_TRUSTED;6526 info->reg_type |= PTR_TRUSTED;
6527 6527
6528 if (btf_param_match_suffix(btf, &args[arg], "__nullable"))
6529 info->reg_type |= PTR_MAYBE_NULL;
6530
6528 if (tgt_prog) {6531 if (tgt_prog) {
6529 enum bpf_prog_type tgt_type;6532 enum bpf_prog_type tgt_type;
6530 6533
kernel/bpf/cpumap.c+4−2
@@ -354,12 +354,14 @@ static int cpu_map_kthread_run(void *data) · 353 unmodified lines
354 354
355 list_add_tail(&skb->list, &list);355 list_add_tail(&skb->list, &list);
356 }356 }
357 netif_receive_skb_list(&list);
358 357
359 /* Feedback loop via tracepoint */358 /* Feedback loop via tracepoint.
359 * NB: keep before recv to allow measuring enqueue/dequeue latency.
360 */
360 trace_xdp_cpumap_kthread(rcpu->map_id, n, kmem_alloc_drops,361 trace_xdp_cpumap_kthread(rcpu->map_id, n, kmem_alloc_drops,
361 sched, &stats);362 sched, &stats);
362 363
364 netif_receive_skb_list(&list);
363 local_bh_enable(); /* resched point, may call do_softirq() */365 local_bh_enable(); /* resched point, may call do_softirq() */
364 }366 }
365 __set_current_state(TASK_RUNNING);367 __set_current_state(TASK_RUNNING);
kernel/bpf/verifier.c+32−4
@@ -28,6 +28,8 @@ · 27 unmodified lines
28#include <linux/cpumask.h>28#include <linux/cpumask.h>
29#include <linux/bpf_mem_alloc.h>29#include <linux/bpf_mem_alloc.h>
30#include <net/xdp.h>30#include <net/xdp.h>
31#include <linux/trace_events.h>
32#include <linux/kallsyms.h>
31 33
32#include "disasm.h"34#include "disasm.h"
33 35
@@ -21154,11 +21156,13 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, · 21120 unmodified lines
21154{21156{
21155 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;21157 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
21156 bool prog_tracing = prog->type == BPF_PROG_TYPE_TRACING;21158 bool prog_tracing = prog->type == BPF_PROG_TYPE_TRACING;
21159 char trace_symbol[KSYM_SYMBOL_LEN];
21157 const char prefix[] = "btf_trace_";21160 const char prefix[] = "btf_trace_";
21161 struct bpf_raw_event_map *btp;
21158 int ret = 0, subprog = -1, i;21162 int ret = 0, subprog = -1, i;
21159 const struct btf_type *t;21163 const struct btf_type *t;
21160 bool conservative = true;21164 bool conservative = true;
21161 const char *tname;21165 const char *tname, *fname;
21162 struct btf *btf;21166 struct btf *btf;
21163 long addr = 0;21167 long addr = 0;
21164 struct module *mod = NULL;21168 struct module *mod = NULL;
@@ -21289,10 +21293,34 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, · 124 unmodified lines
21289 return -EINVAL;21293 return -EINVAL;
21290 }21294 }
21291 tname += sizeof(prefix) - 1;21295 tname += sizeof(prefix) - 1;
21292 t = btf_type_by_id(btf, t->type);21296
21293 if (!btf_type_is_ptr(t))21297 /* The func_proto of "btf_trace_##tname" is generated from typedef without argument
21294 /* should never happen in valid vmlinux build */21298 * names. Thus using bpf_raw_event_map to get argument names.
21299 */
21300 btp = bpf_get_raw_tracepoint(tname);
21301 if (!btp)
21295 return -EINVAL;21302 return -EINVAL;
21303 fname = kallsyms_lookup((unsigned long)btp->bpf_func, NULL, NULL, NULL,
21304 trace_symbol);
21305 bpf_put_raw_tracepoint(btp);
21306
21307 if (fname)
21308 ret = btf_find_by_name_kind(btf, fname, BTF_KIND_FUNC);
21309
21310 if (!fname || ret < 0) {
21311 bpf_log(log, "Cannot find btf of tracepoint template, fall back to %s%s.\n",
21312 prefix, tname);
21313 t = btf_type_by_id(btf, t->type);
21314 if (!btf_type_is_ptr(t))
21315 /* should never happen in valid vmlinux build */
21316 return -EINVAL;
21317 } else {
21318 t = btf_type_by_id(btf, ret);
21319 if (!btf_type_is_func(t))
21320 /* should never happen in valid vmlinux build */
21321 return -EINVAL;
21322 }
21323
21296 t = btf_type_by_id(btf, t->type);21324 t = btf_type_by_id(btf, t->type);
21297 if (!btf_type_is_func_proto(t))21325 if (!btf_type_is_func_proto(t))
21298 /* should never happen in valid vmlinux build */21326 /* should never happen in valid vmlinux build */
net/core/filter.c+2−1
@@ -12063,7 +12063,7 @@ int bpf_dynptr_from_skb_rdonly(struct __sk_buff *skb, u64 flags, · 12062 unmodified lines
12063}12063}
12064 12064
12065BTF_KFUNCS_START(bpf_kfunc_check_set_skb)12065BTF_KFUNCS_START(bpf_kfunc_check_set_skb)
12066BTF_ID_FLAGS(func, bpf_dynptr_from_skb)12066BTF_ID_FLAGS(func, bpf_dynptr_from_skb, KF_TRUSTED_ARGS)
12067BTF_KFUNCS_END(bpf_kfunc_check_set_skb)12067BTF_KFUNCS_END(bpf_kfunc_check_set_skb)
12068 12068
12069BTF_KFUNCS_START(bpf_kfunc_check_set_xdp)12069BTF_KFUNCS_START(bpf_kfunc_check_set_xdp)
@@ -12112,6 +12112,7 @@ static int __init bpf_kfunc_init(void) · 42 unmodified lines
12112 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_XMIT, &bpf_kfunc_set_skb);12112 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_XMIT, &bpf_kfunc_set_skb);
12113 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_SEG6LOCAL, &bpf_kfunc_set_skb);12113 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_SEG6LOCAL, &bpf_kfunc_set_skb);
12114 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_NETFILTER, &bpf_kfunc_set_skb);12114 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_NETFILTER, &bpf_kfunc_set_skb);
12115 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_kfunc_set_skb);
12115 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &bpf_kfunc_set_xdp);12116 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &bpf_kfunc_set_xdp);
12116 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCK_ADDR,12117 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
12117 &bpf_kfunc_set_sock_addr);12118 &bpf_kfunc_set_sock_addr);
net/core/skmsg.c+1−1
@@ -293,7 +293,7 @@ out: · 292 unmodified lines
293 /* If we trim data a full sg elem before curr pointer update293 /* If we trim data a full sg elem before curr pointer update
294 * copybreak and current so that any future copy operations294 * copybreak and current so that any future copy operations
295 * start at new copy location.295 * start at new copy location.
296 * However trimed data that has not yet been used in a copy op296 * However trimmed data that has not yet been used in a copy op
297 * does not require an update.297 * does not require an update.
298 */298 */
299 if (!msg->sg.size) {299 if (!msg->sg.size) {
net/core/sock_map.c+1−0
@@ -1183,6 +1183,7 @@ static void sock_hash_free(struct bpf_map *map) · 1182 unmodified lines
1183 sock_put(elem->sk);1183 sock_put(elem->sk);
1184 sock_hash_free_elem(htab, elem);1184 sock_hash_free_elem(htab, elem);
1185 }1185 }
1186 cond_resched();
1186 }1187 }
1187 1188
1188 /* wait for psock readers accessing its map link */1189 /* wait for psock readers accessing its map link */
net/ipv4/tcp_bpf.c+2−2
@@ -30,7 +30,7 @@ void tcp_eat_skb(struct sock *sk, struct sk_buff *skb) · 29 unmodified lines
30}30}
31 31
32static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,32static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,
33 struct sk_msg *msg, u32 apply_bytes, int flags)33 struct sk_msg *msg, u32 apply_bytes)
34{34{
35 bool apply = apply_bytes;35 bool apply = apply_bytes;
36 struct scatterlist *sge;36 struct scatterlist *sge;
@@ -167,7 +167,7 @@ int tcp_bpf_sendmsg_redir(struct sock *sk, bool ingress, · 130 unmodified lines
167 if (unlikely(!psock))167 if (unlikely(!psock))
168 return -EPIPE;168 return -EPIPE;
169 169
170 ret = ingress ? bpf_tcp_ingress(sk, psock, msg, bytes, flags) :170 ret = ingress ? bpf_tcp_ingress(sk, psock, msg, bytes) :
171 tcp_bpf_push_locked(sk, msg, bytes, flags, false);171 tcp_bpf_push_locked(sk, msg, bytes, flags, false);
172 sk_psock_put(sk, psock);172 sk_psock_put(sk, psock);
173 return ret;173 return ret;
net/xdp/xsk_buff_pool.c+9−1
@@ -661,9 +661,17 @@ EXPORT_SYMBOL(xp_alloc_batch); · 660 unmodified lines
661 661
662bool xp_can_alloc(struct xsk_buff_pool *pool, u32 count)662bool xp_can_alloc(struct xsk_buff_pool *pool, u32 count)
663{663{
664 u32 req_count, avail_count;
665
664 if (pool->free_list_cnt >= count)666 if (pool->free_list_cnt >= count)
665 return true;667 return true;
666 return xskq_cons_has_entries(pool->fq, count - pool->free_list_cnt);668
669 req_count = count - pool->free_list_cnt;
670 avail_count = xskq_cons_nb_entries(pool->fq, req_count);
671 if (!avail_count)
672 pool->fq->queue_empty_descs++;
673
674 return avail_count >= req_count;
667}675}
668EXPORT_SYMBOL(xp_can_alloc);676EXPORT_SYMBOL(xp_can_alloc);
669 677
net/xdp/xsk_queue.h+0−5
@@ -306,11 +306,6 @@ static inline u32 xskq_cons_nb_entries(struct xsk_queue *q, u32 max) · 305 unmodified lines
306 return entries >= max ? max : entries;306 return entries >= max ? max : entries;
307}307}
308 308
309static inline bool xskq_cons_has_entries(struct xsk_queue *q, u32 cnt)
310{
311 return xskq_cons_nb_entries(q, cnt) >= cnt;
312}
313
314static inline bool xskq_cons_peek_addr_unchecked(struct xsk_queue *q, u64 *addr)309static inline bool xskq_cons_peek_addr_unchecked(struct xsk_queue *q, u64 *addr)
315{310{
316 if (q->cached_prod == q->cached_cons)311 if (q->cached_prod == q->cached_cons)
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h+6−0
@@ -34,6 +34,12 @@ DECLARE_TRACE(bpf_testmod_test_write_bare, · 33 unmodified lines
34 TP_ARGS(task, ctx)34 TP_ARGS(task, ctx)
35);35);
36 36
37/* Used in bpf_testmod_test_read() to test __nullable suffix */
38DECLARE_TRACE(bpf_testmod_test_nullable_bare,
39 TP_PROTO(struct bpf_testmod_test_read_ctx *ctx__nullable),
40 TP_ARGS(ctx__nullable)
41);
42
37#undef BPF_TESTMOD_DECLARE_TRACE43#undef BPF_TESTMOD_DECLARE_TRACE
38#ifdef DECLARE_TRACE_WRITABLE44#ifdef DECLARE_TRACE_WRITABLE
39#define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \45#define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c+2−0
@@ -356,6 +356,8 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj, · 355 unmodified lines
356 if (bpf_testmod_loop_test(101) > 100)356 if (bpf_testmod_loop_test(101) > 100)
357 trace_bpf_testmod_test_read(current, &ctx);357 trace_bpf_testmod_test_read(current, &ctx);
358 358
359 trace_bpf_testmod_test_nullable_bare(NULL);
360
359 /* Magic number to enable writable tp */361 /* Magic number to enable writable tp */
360 if (len == 64) {362 if (len == 64) {
361 struct bpf_testmod_test_writable_ctx writable = {363 struct bpf_testmod_test_writable_ctx writable = {
tools/testing/selftests/bpf/prog_tests/dynptr.c+35−2
@@ -9,6 +9,7 @@ · 8 unmodified lines
9enum test_setup_type {9enum test_setup_type {
10 SETUP_SYSCALL_SLEEP,10 SETUP_SYSCALL_SLEEP,
11 SETUP_SKB_PROG,11 SETUP_SKB_PROG,
12 SETUP_SKB_PROG_TP,
12};13};
13 14
14static struct {15static struct {
@@ -28,6 +29,7 @@ static struct { · 13 unmodified lines
28 {"test_dynptr_clone", SETUP_SKB_PROG},29 {"test_dynptr_clone", SETUP_SKB_PROG},
29 {"test_dynptr_skb_no_buff", SETUP_SKB_PROG},30 {"test_dynptr_skb_no_buff", SETUP_SKB_PROG},
30 {"test_dynptr_skb_strcmp", SETUP_SKB_PROG},31 {"test_dynptr_skb_strcmp", SETUP_SKB_PROG},
32 {"test_dynptr_skb_tp_btf", SETUP_SKB_PROG_TP},
31};33};
32 34
33static void verify_success(const char *prog_name, enum test_setup_type setup_type)35static void verify_success(const char *prog_name, enum test_setup_type setup_type)
@@ -35,7 +37,7 @@ static void verify_success(const char *prog_name, enum test_setup_type setup_typ · 1 unmodified line
35 struct dynptr_success *skel;37 struct dynptr_success *skel;
36 struct bpf_program *prog;38 struct bpf_program *prog;
37 struct bpf_link *link;39 struct bpf_link *link;
38 int err;40 int err;
39 41
40 skel = dynptr_success__open();42 skel = dynptr_success__open();
41 if (!ASSERT_OK_PTR(skel, "dynptr_success__open"))43 if (!ASSERT_OK_PTR(skel, "dynptr_success__open"))
@@ -47,7 +49,7 @@ static void verify_success(const char *prog_name, enum test_setup_type setup_typ · 5 unmodified lines
47 if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))49 if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
48 goto cleanup;50 goto cleanup;
49 51
50 bpf_program__set_autoload(prog, true);52 bpf_program__set_autoload(prog, true);
51 53
52 err = dynptr_success__load(skel);54 err = dynptr_success__load(skel);
53 if (!ASSERT_OK(err, "dynptr_success__load"))55 if (!ASSERT_OK(err, "dynptr_success__load"))
@@ -87,6 +89,37 @@ static void verify_success(const char *prog_name, enum test_setup_type setup_typ · 33 unmodified lines
87 89
88 break;90 break;
89 }91 }
92 case SETUP_SKB_PROG_TP:
93 {
94 struct __sk_buff skb = {};
95 struct bpf_object *obj;
96 int aux_prog_fd;
97
98 /* Just use its test_run to trigger kfree_skb tracepoint */
99 err = bpf_prog_test_load("./test_pkt_access.bpf.o", BPF_PROG_TYPE_SCHED_CLS,
100 &obj, &aux_prog_fd);
101 if (!ASSERT_OK(err, "prog_load sched cls"))
102 goto cleanup;
103
104 LIBBPF_OPTS(bpf_test_run_opts, topts,
105 .data_in = &pkt_v4,
106 .data_size_in = sizeof(pkt_v4),
107 .ctx_in = &skb,
108 .ctx_size_in = sizeof(skb),
109 );
110
111 link = bpf_program__attach(prog);
112 if (!ASSERT_OK_PTR(link, "bpf_program__attach"))
113 goto cleanup;
114
115 err = bpf_prog_test_run_opts(aux_prog_fd, &topts);
116 bpf_link__destroy(link);
117
118 if (!ASSERT_OK(err, "test_run"))
119 goto cleanup;
120
121 break;
122 }
90 }123 }
91 124
92 ASSERT_EQ(skel->bss->err, 0, "err");125 ASSERT_EQ(skel->bss->err, 0, "err");
tools/testing/selftests/bpf/prog_tests/tp_btf_nullable.c+14−0
@@ -0,0 +1,14 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include <test_progs.h>
4#include "test_tp_btf_nullable.skel.h"
5
6void test_tp_btf_nullable(void)
7{
8 if (!env.has_testmod) {
9 test__skip();
10 return;
11 }
12
13 RUN_TESTS(test_tp_btf_nullable);
14}
tools/testing/selftests/bpf/progs/dynptr_fail.c+25−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
6#include <stdbool.h>6#include <stdbool.h>
7#include <linux/bpf.h>7#include <linux/bpf.h>
8#include <bpf/bpf_helpers.h>8#include <bpf/bpf_helpers.h>
9#include <bpf/bpf_tracing.h>
9#include <linux/if_ether.h>10#include <linux/if_ether.h>
10#include "bpf_misc.h"11#include "bpf_misc.h"
11#include "bpf_kfuncs.h"12#include "bpf_kfuncs.h"
@@ -1254,6 +1255,30 @@ int skb_invalid_ctx(void *ctx) · 1242 unmodified lines
1254 return 0;1255 return 0;
1255}1256}
1256 1257
1258SEC("fentry/skb_tx_error")
1259__failure __msg("must be referenced or trusted")
1260int BPF_PROG(skb_invalid_ctx_fentry, void *skb)
1261{
1262 struct bpf_dynptr ptr;
1263
1264 /* this should fail */
1265 bpf_dynptr_from_skb(skb, 0, &ptr);
1266
1267 return 0;
1268}
1269
1270SEC("fexit/skb_tx_error")
1271__failure __msg("must be referenced or trusted")
1272int BPF_PROG(skb_invalid_ctx_fexit, void *skb)
1273{
1274 struct bpf_dynptr ptr;
1275
1276 /* this should fail */
1277 bpf_dynptr_from_skb(skb, 0, &ptr);
1278
1279 return 0;
1280}
1281
1257/* Reject writes to dynptr slot for uninit arg */1282/* Reject writes to dynptr slot for uninit arg */
1258SEC("?raw_tp")1283SEC("?raw_tp")
1259__failure __msg("potential write to dynptr at off=-16")1284__failure __msg("potential write to dynptr at off=-16")
tools/testing/selftests/bpf/progs/dynptr_success.c+23−0
@@ -5,6 +5,7 @@ · 4 unmodified lines
5#include <stdbool.h>5#include <stdbool.h>
6#include <linux/bpf.h>6#include <linux/bpf.h>
7#include <bpf/bpf_helpers.h>7#include <bpf/bpf_helpers.h>
8#include <bpf/bpf_tracing.h>
8#include "bpf_misc.h"9#include "bpf_misc.h"
9#include "bpf_kfuncs.h"10#include "bpf_kfuncs.h"
10#include "errno.h"11#include "errno.h"
@@ -544,3 +545,25 @@ int test_dynptr_skb_strcmp(struct __sk_buff *skb) · 533 unmodified lines
544 545
545 return 1;546 return 1;
546}547}
548
549SEC("tp_btf/kfree_skb")
550int BPF_PROG(test_dynptr_skb_tp_btf, void *skb, void *location)
551{
552 __u8 write_data[2] = {1, 2};
553 struct bpf_dynptr ptr;
554 int ret;
555
556 if (bpf_dynptr_from_skb(skb, 0, &ptr)) {
557 err = 1;
558 return 1;
559 }
560
561 /* since tp_btf skbs are read only, writes should fail */
562 ret = bpf_dynptr_write(&ptr, 0, write_data, sizeof(write_data), 0);
563 if (ret != -EINVAL) {
564 err = 2;
565 return 1;
566 }
567
568 return 1;
569}
tools/testing/selftests/bpf/progs/test_tp_btf_nullable.c+24−0
@@ -0,0 +1,24 @@
1// SPDX-License-Identifier: GPL-2.0
2
3#include "vmlinux.h"
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6#include "../bpf_testmod/bpf_testmod.h"
7#include "bpf_misc.h"
8
9SEC("tp_btf/bpf_testmod_test_nullable_bare")
10__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
11int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx)
12{
13 return nullable_ctx->len;
14}
15
16SEC("tp_btf/bpf_testmod_test_nullable_bare")
17int BPF_PROG(handle_tp_btf_nullable_bare2, struct bpf_testmod_test_read_ctx *nullable_ctx)
18{
19 if (nullable_ctx)
20 return nullable_ctx->len;
21 return 0;
22}
23
24char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/xskxceiver.c+38−5
@@ -324,6 +324,25 @@ out: · 323 unmodified lines
324 return zc_avail;324 return zc_avail;
325}325}
326 326
327#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
328static unsigned int get_max_skb_frags(void)
329{
330 unsigned int max_skb_frags = 0;
331 FILE *file;
332
333 file = fopen(MAX_SKB_FRAGS_PATH, "r");
334 if (!file) {
335 ksft_print_msg("Error opening %s\n", MAX_SKB_FRAGS_PATH);
336 return 0;
337 }
338
339 if (fscanf(file, "%u", &max_skb_frags) != 1)
340 ksft_print_msg("Error reading %s\n", MAX_SKB_FRAGS_PATH);
341
342 fclose(file);
343 return max_skb_frags;
344}
345
327static struct option long_options[] = {346static struct option long_options[] = {
328 {"interface", required_argument, 0, 'i'},347 {"interface", required_argument, 0, 'i'},
329 {"busy-poll", no_argument, 0, 'b'},348 {"busy-poll", no_argument, 0, 'b'},
@@ -2244,13 +2263,24 @@ static int testapp_poll_rxq_tmout(struct test_spec *test) · 1914 unmodified lines
2244 2263
2245static int testapp_too_many_frags(struct test_spec *test)2264static int testapp_too_many_frags(struct test_spec *test)
2246{2265{
2247 struct pkt pkts[2 * XSK_DESC__MAX_SKB_FRAGS + 2] = {};2266 struct pkt *pkts;
2248 u32 max_frags, i;2267 u32 max_frags, i;
2268 int ret;
2249 2269
2250 if (test->mode == TEST_MODE_ZC)2270 if (test->mode == TEST_MODE_ZC) {
2251 max_frags = test->ifobj_tx->xdp_zc_max_segs;2271 max_frags = test->ifobj_tx->xdp_zc_max_segs;
2252 else2272 } else {
2253 max_frags = XSK_DESC__MAX_SKB_FRAGS;2273 max_frags = get_max_skb_frags();
2274 if (!max_frags) {
2275 ksft_print_msg("Couldn't retrieve MAX_SKB_FRAGS from system, using default (17) value\n");
2276 max_frags = 17;
2277 }
2278 max_frags += 1;
2279 }
2280
2281 pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
2282 if (!pkts)
2283 return TEST_FAILURE;
2254 2284
2255 test->mtu = MAX_ETH_JUMBO_SIZE;2285 test->mtu = MAX_ETH_JUMBO_SIZE;
2256 2286
@@ -2280,7 +2310,10 @@ static int testapp_too_many_frags(struct test_spec *test) · 23 unmodified lines
2280 pkts[2 * max_frags + 1].valid = true;2310 pkts[2 * max_frags + 1].valid = true;
2281 2311
2282 pkt_stream_generate_custom(test, pkts, 2 * max_frags + 2);2312 pkt_stream_generate_custom(test, pkts, 2 * max_frags + 2);
2283 return testapp_validate_traffic(test);2313 ret = testapp_validate_traffic(test);
2314
2315 free(pkts);
2316 return ret;
2284}2317}
2285 2318
2286static int xsk_load_xdp_programs(struct ifobject *ifobj)2319static int xsk_load_xdp_programs(struct ifobject *ifobj)
tools/testing/selftests/bpf/xskxceiver.h+0−1
@@ -55,7 +55,6 @@ · 54 unmodified lines
55#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)55#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)
56#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)56#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)
57#define XSK_DESC__INVALID_OPTION (0xffff)57#define XSK_DESC__INVALID_OPTION (0xffff)
58#define XSK_DESC__MAX_SKB_FRAGS 18
59#define HUGEPAGE_SIZE (2 * 1024 * 1024)58#define HUGEPAGE_SIZE (2 * 1024 * 1024)
60#define PKT_DUMP_NB_TO_PRINT 1659#define PKT_DUMP_NB_TO_PRINT 16
61#define RUN_ALL_TESTS UINT_MAX60#define RUN_ALL_TESTS UINT_MAX

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t