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
255255 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
256256 dev->priv_flags |= IFF_PHONY_HEADROOM;
257257 dev->priv_flags |= IFF_NO_QUEUE;
258+ dev->priv_flags |= IFF_DISABLE_NETPOLL;
258259 dev->lltx = true;
259260
260261 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
9191 TRACE_EVENT(tcp_send_reset,
9292
9393 TP_PROTO(const struct sock *sk,
94− const struct sk_buff *skb,
94+ const struct sk_buff *skb__nullable,
9595 const enum sk_rst_reason reason),
9696
97− TP_ARGS(sk, skb, reason),
97+ TP_ARGS(sk, skb__nullable, reason),
9898
9999 TP_STRUCT__entry(
100100 __field(const void *, skbaddr)
@@ -106,7 +106,7 @@ TRACE_EVENT(tcp_send_reset, · 5 unmodified lines
106106 ),
107107
108108 TP_fast_assign(
109− __entry->skbaddr = skb;
109+ __entry->skbaddr = skb__nullable;
110110 __entry->skaddr = sk;
111111 /* Zero means unknown state. */
112112 __entry->state = sk ? sk->sk_state : 0;
@@ -118,13 +118,13 @@ TRACE_EVENT(tcp_send_reset, · 5 unmodified lines
118118 const struct inet_sock *inet = inet_sk(sk);
119119
120120 TP_STORE_ADDR_PORTS(__entry, inet, sk);
121− } else if (skb) {
122− const struct tcphdr *th = (const struct tcphdr *)skb->data;
121+ } else if (skb__nullable) {
122+ const struct tcphdr *th = (const struct tcphdr *)skb__nullable->data;
123123 /*
124124 * We should reverse the 4-tuple of skb, so later
125125 * it can print the right flow direction of rst.
126126 */
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);
128128 }
129129 __entry->reason = reason;
130130 ),
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
65256525 if (prog_args_trusted(prog))
65266526 info->reg_type |= PTR_TRUSTED;
65276527
6528+ if (btf_param_match_suffix(btf, &args[arg], "__nullable"))
6529+ info->reg_type |= PTR_MAYBE_NULL;
6530+
65286531 if (tgt_prog) {
65296532 enum bpf_prog_type tgt_type;
65306533
kernel/bpf/cpumap.c+4−2
@@ -354,12 +354,14 @@ static int cpu_map_kthread_run(void *data) · 353 unmodified lines
354354
355355 list_add_tail(&skb->list, &list);
356356 }
357− netif_receive_skb_list(&list);
358357
359− /* Feedback loop via tracepoint */
358+ /* Feedback loop via tracepoint.
359+ * NB: keep before recv to allow measuring enqueue/dequeue latency.
360+ */
360361 trace_xdp_cpumap_kthread(rcpu->map_id, n, kmem_alloc_drops,
361362 sched, &stats);
362363
364+ netif_receive_skb_list(&list);
363365 local_bh_enable(); /* resched point, may call do_softirq() */
364366 }
365367 __set_current_state(TASK_RUNNING);
kernel/bpf/verifier.c+32−4
@@ -28,6 +28,8 @@ · 27 unmodified lines
2828 #include <linux/cpumask.h>
2929 #include <linux/bpf_mem_alloc.h>
3030 #include <net/xdp.h>
31+#include <linux/trace_events.h>
32+#include <linux/kallsyms.h>
3133
3234 #include "disasm.h"
3335
@@ -21154,11 +21156,13 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, · 21120 unmodified lines
2115421156 {
2115521157 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
2115621158 bool prog_tracing = prog->type == BPF_PROG_TYPE_TRACING;
21159+ char trace_symbol[KSYM_SYMBOL_LEN];
2115721160 const char prefix[] = "btf_trace_";
21161+ struct bpf_raw_event_map *btp;
2115821162 int ret = 0, subprog = -1, i;
2115921163 const struct btf_type *t;
2116021164 bool conservative = true;
21161− const char *tname;
21165+ const char *tname, *fname;
2116221166 struct btf *btf;
2116321167 long addr = 0;
2116421168 struct module *mod = NULL;
@@ -21289,10 +21293,34 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, · 124 unmodified lines
2128921293 return -EINVAL;
2129021294 }
2129121295 tname += sizeof(prefix) - 1;
21292− t = btf_type_by_id(btf, t->type);
21293− if (!btf_type_is_ptr(t))
21294− /* should never happen in valid vmlinux build */
21296+
21297+ /* The func_proto of "btf_trace_##tname" is generated from typedef without argument
21298+ * names. Thus using bpf_raw_event_map to get argument names.
21299+ */
21300+ btp = bpf_get_raw_tracepoint(tname);
21301+ if (!btp)
2129521302 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+
2129621324 t = btf_type_by_id(btf, t->type);
2129721325 if (!btf_type_is_func_proto(t))
2129821326 /* 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
1206312063 }
1206412064
1206512065 BTF_KFUNCS_START(bpf_kfunc_check_set_skb)
12066−BTF_ID_FLAGS(func, bpf_dynptr_from_skb)
12066+BTF_ID_FLAGS(func, bpf_dynptr_from_skb, KF_TRUSTED_ARGS)
1206712067 BTF_KFUNCS_END(bpf_kfunc_check_set_skb)
1206812068
1206912069 BTF_KFUNCS_START(bpf_kfunc_check_set_xdp)
@@ -12112,6 +12112,7 @@ static int __init bpf_kfunc_init(void) · 42 unmodified lines
1211212112 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_XMIT, &bpf_kfunc_set_skb);
1211312113 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_SEG6LOCAL, &bpf_kfunc_set_skb);
1211412114 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);
1211512116 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &bpf_kfunc_set_xdp);
1211612117 ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
1211712118 &bpf_kfunc_set_sock_addr);
net/core/skmsg.c+1−1
@@ -293,7 +293,7 @@ out: · 292 unmodified lines
293293 /* If we trim data a full sg elem before curr pointer update
294294 * copybreak and current so that any future copy operations
295295 * start at new copy location.
296− * However trimed data that has not yet been used in a copy op
296+ * However trimmed data that has not yet been used in a copy op
297297 * does not require an update.
298298 */
299299 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
11831183 sock_put(elem->sk);
11841184 sock_hash_free_elem(htab, elem);
11851185 }
1186+ cond_resched();
11861187 }
11871188
11881189 /* 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
3030 }
3131
3232 static 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)
3434 {
3535 bool apply = apply_bytes;
3636 struct scatterlist *sge;
@@ -167,7 +167,7 @@ int tcp_bpf_sendmsg_redir(struct sock *sk, bool ingress, · 130 unmodified lines
167167 if (unlikely(!psock))
168168 return -EPIPE;
169169
170− ret = ingress ? bpf_tcp_ingress(sk, psock, msg, bytes, flags) :
170+ ret = ingress ? bpf_tcp_ingress(sk, psock, msg, bytes) :
171171 tcp_bpf_push_locked(sk, msg, bytes, flags, false);
172172 sk_psock_put(sk, psock);
173173 return ret;
net/xdp/xsk_buff_pool.c+9−1
@@ -661,9 +661,17 @@ EXPORT_SYMBOL(xp_alloc_batch); · 660 unmodified lines
661661
662662 bool xp_can_alloc(struct xsk_buff_pool *pool, u32 count)
663663 {
664+ u32 req_count, avail_count;
665+
664666 if (pool->free_list_cnt >= count)
665667 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;
667675 }
668676 EXPORT_SYMBOL(xp_can_alloc);
669677
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
306306 return entries >= max ? max : entries;
307307 }
308308
309−static inline bool xskq_cons_has_entries(struct xsk_queue *q, u32 cnt)
310−{
311− return xskq_cons_nb_entries(q, cnt) >= cnt;
312−}
313−
314309 static inline bool xskq_cons_peek_addr_unchecked(struct xsk_queue *q, u64 *addr)
315310 {
316311 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
3434 TP_ARGS(task, ctx)
3535 );
3636
37+/* Used in bpf_testmod_test_read() to test __nullable suffix */
38+DECLARE_TRACE(bpf_testmod_test_nullable_bare,
39+ TP_PROTO(struct bpf_testmod_test_read_ctx *ctx__nullable),
40+ TP_ARGS(ctx__nullable)
41+);
42+
3743 #undef BPF_TESTMOD_DECLARE_TRACE
3844 #ifdef DECLARE_TRACE_WRITABLE
3945 #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
356356 if (bpf_testmod_loop_test(101) > 100)
357357 trace_bpf_testmod_test_read(current, &ctx);
358358
359+ trace_bpf_testmod_test_nullable_bare(NULL);
360+
359361 /* Magic number to enable writable tp */
360362 if (len == 64) {
361363 struct bpf_testmod_test_writable_ctx writable = {
tools/testing/selftests/bpf/prog_tests/dynptr.c+35−2
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 enum test_setup_type {
1010 SETUP_SYSCALL_SLEEP,
1111 SETUP_SKB_PROG,
12+ SETUP_SKB_PROG_TP,
1213 };
1314
1415 static struct {
@@ -28,6 +29,7 @@ static struct { · 13 unmodified lines
2829 {"test_dynptr_clone", SETUP_SKB_PROG},
2930 {"test_dynptr_skb_no_buff", SETUP_SKB_PROG},
3031 {"test_dynptr_skb_strcmp", SETUP_SKB_PROG},
32+ {"test_dynptr_skb_tp_btf", SETUP_SKB_PROG_TP},
3133 };
3234
3335 static 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
3537 struct dynptr_success *skel;
3638 struct bpf_program *prog;
3739 struct bpf_link *link;
38− int err;
40+ int err;
3941
4042 skel = dynptr_success__open();
4143 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
4749 if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
4850 goto cleanup;
4951
50− bpf_program__set_autoload(prog, true);
52+ bpf_program__set_autoload(prog, true);
5153
5254 err = dynptr_success__load(skel);
5355 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
8789
8890 break;
8991 }
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+ }
90123 }
91124
92125 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+
6+void 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
66 #include <stdbool.h>
77 #include <linux/bpf.h>
88 #include <bpf/bpf_helpers.h>
9+#include <bpf/bpf_tracing.h>
910 #include <linux/if_ether.h>
1011 #include "bpf_misc.h"
1112 #include "bpf_kfuncs.h"
@@ -1254,6 +1255,30 @@ int skb_invalid_ctx(void *ctx) · 1242 unmodified lines
12541255 return 0;
12551256 }
12561257
1258+SEC("fentry/skb_tx_error")
1259+__failure __msg("must be referenced or trusted")
1260+int 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+
1270+SEC("fexit/skb_tx_error")
1271+__failure __msg("must be referenced or trusted")
1272+int 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+
12571282 /* Reject writes to dynptr slot for uninit arg */
12581283 SEC("?raw_tp")
12591284 __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
55 #include <stdbool.h>
66 #include <linux/bpf.h>
77 #include <bpf/bpf_helpers.h>
8+#include <bpf/bpf_tracing.h>
89 #include "bpf_misc.h"
910 #include "bpf_kfuncs.h"
1011 #include "errno.h"
@@ -544,3 +545,25 @@ int test_dynptr_skb_strcmp(struct __sk_buff *skb) · 533 unmodified lines
544545
545546 return 1;
546547 }
548+
549+SEC("tp_btf/kfree_skb")
550+int 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+
9+SEC("tp_btf/bpf_testmod_test_nullable_bare")
10+__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
11+int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx)
12+{
13+ return nullable_ctx->len;
14+}
15+
16+SEC("tp_btf/bpf_testmod_test_nullable_bare")
17+int 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+
24+char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/xskxceiver.c+38−5
@@ -324,6 +324,25 @@ out: · 323 unmodified lines
324324 return zc_avail;
325325 }
326326
327+#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
328+static 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+
327346 static struct option long_options[] = {
328347 {"interface", required_argument, 0, 'i'},
329348 {"busy-poll", no_argument, 0, 'b'},
@@ -2244,13 +2263,24 @@ static int testapp_poll_rxq_tmout(struct test_spec *test) · 1914 unmodified lines
22442263
22452264 static int testapp_too_many_frags(struct test_spec *test)
22462265 {
2247− struct pkt pkts[2 * XSK_DESC__MAX_SKB_FRAGS + 2] = {};
2266+ struct pkt *pkts;
22482267 u32 max_frags, i;
2268+ int ret;
22492269
2250− if (test->mode == TEST_MODE_ZC)
2270+ if (test->mode == TEST_MODE_ZC) {
22512271 max_frags = test->ifobj_tx->xdp_zc_max_segs;
2252− else
2253− max_frags = XSK_DESC__MAX_SKB_FRAGS;
2272+ } else {
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;
22542284
22552285 test->mtu = MAX_ETH_JUMBO_SIZE;
22562286
@@ -2280,7 +2310,10 @@ static int testapp_too_many_frags(struct test_spec *test) · 23 unmodified lines
22802310 pkts[2 * max_frags + 1].valid = true;
22812311
22822312 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;
22842317 }
22852318
22862319 static int xsk_load_xdp_programs(struct ifobject *ifobj)
tools/testing/selftests/bpf/xskxceiver.h+0−1
@@ -55,7 +55,6 @@ · 54 unmodified lines
5555 #define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)
5656 #define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)
5757 #define XSK_DESC__INVALID_OPTION (0xffff)
58−#define XSK_DESC__MAX_SKB_FRAGS 18
5958 #define HUGEPAGE_SIZE (2 * 1024 * 1024)
6059 #define PKT_DUMP_NB_TO_PRINT 16
6160 #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