Lines Matching +full:t +full:- +full:head

1 // SPDX-License-Identifier: GPL-2.0-only
20 #include <linux/error-injection.h>
37 static void bpf_test_timer_enter(struct bpf_test_timer *t) in bpf_test_timer_enter() argument
41 if (t->mode == NO_PREEMPT) in bpf_test_timer_enter()
46 t->time_start = ktime_get_ns(); in bpf_test_timer_enter()
49 static void bpf_test_timer_leave(struct bpf_test_timer *t) in bpf_test_timer_leave() argument
52 t->time_start = 0; in bpf_test_timer_leave()
54 if (t->mode == NO_PREEMPT) in bpf_test_timer_leave()
61 static bool bpf_test_timer_continue(struct bpf_test_timer *t, int iterations, in bpf_test_timer_continue() argument
65 t->i += iterations; in bpf_test_timer_continue()
66 if (t->i >= repeat) { in bpf_test_timer_continue()
68 t->time_spent += ktime_get_ns() - t->time_start; in bpf_test_timer_continue()
69 do_div(t->time_spent, t->i); in bpf_test_timer_continue()
70 *duration = t->time_spent > U32_MAX ? U32_MAX : (u32)t->time_spent; in bpf_test_timer_continue()
77 *err = -EINTR; in bpf_test_timer_continue()
83 t->time_spent += ktime_get_ns() - t->time_start; in bpf_test_timer_continue()
84 bpf_test_timer_leave(t); in bpf_test_timer_continue()
86 bpf_test_timer_enter(t); in bpf_test_timer_continue()
93 t->i = 0; in bpf_test_timer_continue()
97 /* We put this struct at the head of each page with a context and frame
98 * initialised when the page is allocated, so we don't have to do this on each
127 #define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head))
132 struct xdp_page_head *head = in xdp_test_run_init_page() local
141 orig_ctx = xdp->orig_ctx; in xdp_test_run_init_page()
142 frm_len = orig_ctx->data_end - orig_ctx->data_meta; in xdp_test_run_init_page()
143 meta_len = orig_ctx->data - orig_ctx->data_meta; in xdp_test_run_init_page()
144 headroom -= meta_len; in xdp_test_run_init_page()
146 new_ctx = &head->ctx; in xdp_test_run_init_page()
147 frm = head->frame; in xdp_test_run_init_page()
148 data = head->data; in xdp_test_run_init_page()
149 memcpy(data + headroom, orig_ctx->data_meta, frm_len); in xdp_test_run_init_page()
151 xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq); in xdp_test_run_init_page()
153 new_ctx->data = new_ctx->data_meta + meta_len; in xdp_test_run_init_page()
156 frm->mem_type = new_ctx->rxq->mem.type; in xdp_test_run_init_page()
158 memcpy(&head->orig_ctx, new_ctx, sizeof(head->orig_ctx)); in xdp_test_run_init_page()
164 int err = -ENOMEM; in xdp_test_run_setup()
168 .pool_size = xdp->batch_size, in xdp_test_run_setup()
174 xdp->frames = kvmalloc_array(xdp->batch_size, sizeof(void *), GFP_KERNEL); in xdp_test_run_setup()
175 if (!xdp->frames) in xdp_test_run_setup()
176 return -ENOMEM; in xdp_test_run_setup()
178 xdp->skbs = kvmalloc_array(xdp->batch_size, sizeof(void *), GFP_KERNEL); in xdp_test_run_setup()
179 if (!xdp->skbs) in xdp_test_run_setup()
188 /* will copy 'mem.id' into pp->xdp_mem_id */ in xdp_test_run_setup()
189 err = xdp_reg_mem_model(&xdp->mem, MEM_TYPE_PAGE_POOL, pp); in xdp_test_run_setup()
193 xdp->pp = pp; in xdp_test_run_setup()
198 xdp_rxq_info_reg(&xdp->rxq, orig_ctx->rxq->dev, 0, 0); in xdp_test_run_setup()
199 xdp->rxq.mem.type = MEM_TYPE_PAGE_POOL; in xdp_test_run_setup()
200 xdp->rxq.mem.id = pp->xdp_mem_id; in xdp_test_run_setup()
201 xdp->dev = orig_ctx->rxq->dev; in xdp_test_run_setup()
202 xdp->orig_ctx = orig_ctx; in xdp_test_run_setup()
209 kvfree(xdp->skbs); in xdp_test_run_setup()
211 kvfree(xdp->frames); in xdp_test_run_setup()
217 xdp_unreg_mem_model(&xdp->mem); in xdp_test_run_teardown()
218 page_pool_destroy(xdp->pp); in xdp_test_run_teardown()
219 kfree(xdp->frames); in xdp_test_run_teardown()
220 kfree(xdp->skbs); in xdp_test_run_teardown()
223 static bool frame_was_changed(const struct xdp_page_head *head) in frame_was_changed() argument
229 return head->frame->data != head->orig_ctx.data || in frame_was_changed()
230 head->frame->flags != head->orig_ctx.flags; in frame_was_changed()
233 static bool ctx_was_changed(struct xdp_page_head *head) in ctx_was_changed() argument
235 return head->orig_ctx.data != head->ctx.data || in ctx_was_changed()
236 head->orig_ctx.data_meta != head->ctx.data_meta || in ctx_was_changed()
237 head->orig_ctx.data_end != head->ctx.data_end; in ctx_was_changed()
240 static void reset_ctx(struct xdp_page_head *head) in reset_ctx() argument
242 if (likely(!frame_was_changed(head) && !ctx_was_changed(head))) in reset_ctx()
245 head->ctx.data = head->orig_ctx.data; in reset_ctx()
246 head->ctx.data_meta = head->orig_ctx.data_meta; in reset_ctx()
247 head->ctx.data_end = head->orig_ctx.data_end; in reset_ctx()
248 xdp_update_frame_from_buff(&head->ctx, head->frame); in reset_ctx()
249 head->frame->mem_type = head->orig_ctx.rxq->mem.type; in reset_ctx()
265 return -ENOMEM; in xdp_recv_frames()
278 list_add_tail(&skb->list, &list); in xdp_recv_frames()
290 struct xdp_frame **frames = xdp->frames; in xdp_test_run_batch()
292 struct xdp_page_head *head; in xdp_test_run_batch() local
298 batch_sz = min_t(u32, repeat, xdp->batch_size); in xdp_test_run_batch()
306 page = page_pool_dev_alloc_pages(xdp->pp); in xdp_test_run_batch()
308 err = -ENOMEM; in xdp_test_run_batch()
312 head = phys_to_virt(page_to_phys(page)); in xdp_test_run_batch()
313 reset_ctx(head); in xdp_test_run_batch()
314 ctx = &head->ctx; in xdp_test_run_batch()
315 frm = head->frame; in xdp_test_run_batch()
316 xdp->frame_cnt++; in xdp_test_run_batch()
321 if (unlikely(ctx_was_changed(head))) { in xdp_test_run_batch()
331 /* we can't do a real XDP_TX since we're not in the in xdp_test_run_batch()
335 ri->tgt_index = xdp->dev->ifindex; in xdp_test_run_batch()
336 ri->map_id = INT_MAX; in xdp_test_run_batch()
337 ri->map_type = BPF_MAP_TYPE_UNSPEC; in xdp_test_run_batch()
341 ret = xdp_do_redirect_frame(xdp->dev, ctx, frm, prog); in xdp_test_run_batch()
361 ret = xdp_recv_frames(frames, nframes, xdp->skbs, xdp->dev); in xdp_test_run_batch()
377 struct bpf_test_timer t = { .mode = NO_MIGRATE }; in bpf_test_run_xdp_live() local
387 bpf_test_timer_enter(&t); in bpf_test_run_xdp_live()
390 ret = xdp_test_run_batch(&xdp, prog, repeat - t.i); in bpf_test_run_xdp_live()
393 } while (bpf_test_timer_continue(&t, xdp.frame_cnt, repeat, &ret, time)); in bpf_test_run_xdp_live()
394 bpf_test_timer_leave(&t); in bpf_test_run_xdp_live()
407 struct bpf_test_timer t = { NO_MIGRATE }; in bpf_test_run() local
417 return -ENOMEM; in bpf_test_run()
424 bpf_test_timer_enter(&t); in bpf_test_run()
438 } while (bpf_test_timer_continue(&t, 1, repeat, &ret, time)); in bpf_test_run()
440 bpf_test_timer_leave(&t); in bpf_test_run()
453 void __user *data_out = u64_to_user_ptr(kattr->test.data_out); in bpf_test_finish()
454 int err = -EFAULT; in bpf_test_finish()
460 if (kattr->test.data_size_out && in bpf_test_finish()
461 copy_size > kattr->test.data_size_out) { in bpf_test_finish()
462 copy_size = kattr->test.data_size_out; in bpf_test_finish()
463 err = -ENOSPC; in bpf_test_finish()
467 int len = sinfo ? copy_size - sinfo->xdp_frags_size : copy_size; in bpf_test_finish()
470 err = -ENOSPC; in bpf_test_finish()
481 for (i = 0; i < sinfo->nr_frags; i++) { in bpf_test_finish()
482 skb_frag_t *frag = &sinfo->frags[i]; in bpf_test_finish()
485 err = -ENOSPC; in bpf_test_finish()
489 data_len = min_t(u32, copy_size - offset, in bpf_test_finish()
502 if (copy_to_user(&uattr->test.data_size_out, &size, sizeof(size))) in bpf_test_finish()
504 if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) in bpf_test_finish()
506 if (copy_to_user(&uattr->test.duration, &duration, sizeof(duration))) in bpf_test_finish()
508 if (err != -ENOSPC) in bpf_test_finish()
564 return (long)arg->a; in bpf_fentry_test8()
620 refcount_dec(&p->cnt); in bpf_kfunc_call_test_release()
660 void __user *data_in = u64_to_user_ptr(kattr->test.data_in); in BTF_ID_FLAGS()
663 if (user_size < ETH_HLEN || user_size > PAGE_SIZE - headroom - tailroom) in BTF_ID_FLAGS()
664 return ERR_PTR(-EINVAL); in BTF_ID_FLAGS()
669 return ERR_PTR(-ENOMEM); in BTF_ID_FLAGS()
673 return ERR_PTR(-EFAULT); in BTF_ID_FLAGS()
685 int b = 2, err = -EFAULT; in bpf_prog_test_run_tracing()
688 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_tracing()
689 return -EINVAL; in bpf_prog_test_run_tracing()
691 switch (prog->expected_attach_type) { in bpf_prog_test_run_tracing()
719 if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) in bpf_prog_test_run_tracing()
744 info->retval = bpf_prog_run(info->prog, info->ctx); in __bpf_prog_test_run_raw_tp()
754 void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); in bpf_prog_test_run_raw_tp()
755 __u32 ctx_size_in = kattr->test.ctx_size_in; in bpf_prog_test_run_raw_tp()
757 int cpu = kattr->test.cpu, err = 0; in bpf_prog_test_run_raw_tp()
760 /* doesn't support data_in/out, ctx_out, duration, or repeat */ in bpf_prog_test_run_raw_tp()
761 if (kattr->test.data_in || kattr->test.data_out || in bpf_prog_test_run_raw_tp()
762 kattr->test.ctx_out || kattr->test.duration || in bpf_prog_test_run_raw_tp()
763 kattr->test.repeat || kattr->test.batch_size) in bpf_prog_test_run_raw_tp()
764 return -EINVAL; in bpf_prog_test_run_raw_tp()
766 if (ctx_size_in < prog->aux->max_ctx_offset || in bpf_prog_test_run_raw_tp()
768 return -EINVAL; in bpf_prog_test_run_raw_tp()
770 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 && cpu != 0) in bpf_prog_test_run_raw_tp()
771 return -EINVAL; in bpf_prog_test_run_raw_tp()
784 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 || in bpf_prog_test_run_raw_tp()
793 err = -ENXIO; in bpf_prog_test_run_raw_tp()
801 copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32))) in bpf_prog_test_run_raw_tp()
802 err = -EFAULT; in bpf_prog_test_run_raw_tp()
810 void __user *data_in = u64_to_user_ptr(kattr->test.ctx_in); in bpf_ctx_init()
811 void __user *data_out = u64_to_user_ptr(kattr->test.ctx_out); in bpf_ctx_init()
812 u32 size = kattr->test.ctx_size_in; in bpf_ctx_init()
821 return ERR_PTR(-ENOMEM); in bpf_ctx_init()
833 return ERR_PTR(-EFAULT); in bpf_ctx_init()
843 void __user *data_out = u64_to_user_ptr(kattr->test.ctx_out); in bpf_ctx_finish()
844 int err = -EFAULT; in bpf_ctx_finish()
850 if (copy_size > kattr->test.ctx_size_out) { in bpf_ctx_finish()
851 copy_size = kattr->test.ctx_size_out; in bpf_ctx_finish()
852 err = -ENOSPC; in bpf_ctx_finish()
857 if (copy_to_user(&uattr->test.ctx_size_out, &size, sizeof(size))) in bpf_ctx_finish()
859 if (err != -ENOSPC) in bpf_ctx_finish()
866 * range_is_zero - test whether buffer is initialized
871 * This function returns true if the there is a non-zero byte
876 return !memchr_inv((u8 *)buf + from, 0, to - from); in range_is_zero()
881 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb; in convert___skb_to_skb()
886 /* make sure the fields we don't use are zeroed */ in convert___skb_to_skb()
888 return -EINVAL; in convert___skb_to_skb()
894 return -EINVAL; in convert___skb_to_skb()
902 return -EINVAL; in convert___skb_to_skb()
908 return -EINVAL; in convert___skb_to_skb()
916 return -EINVAL; in convert___skb_to_skb()
922 return -EINVAL; in convert___skb_to_skb()
928 return -EINVAL; in convert___skb_to_skb()
930 skb->mark = __skb->mark; in convert___skb_to_skb()
931 skb->priority = __skb->priority; in convert___skb_to_skb()
932 skb->skb_iif = __skb->ingress_ifindex; in convert___skb_to_skb()
933 skb->tstamp = __skb->tstamp; in convert___skb_to_skb()
934 memcpy(&cb->data, __skb->cb, QDISC_CB_PRIV_LEN); in convert___skb_to_skb()
936 if (__skb->wire_len == 0) { in convert___skb_to_skb()
937 cb->pkt_len = skb->len; in convert___skb_to_skb()
939 if (__skb->wire_len < skb->len || in convert___skb_to_skb()
940 __skb->wire_len > GSO_LEGACY_MAX_SIZE) in convert___skb_to_skb()
941 return -EINVAL; in convert___skb_to_skb()
942 cb->pkt_len = __skb->wire_len; in convert___skb_to_skb()
945 if (__skb->gso_segs > GSO_MAX_SEGS) in convert___skb_to_skb()
946 return -EINVAL; in convert___skb_to_skb()
947 skb_shinfo(skb)->gso_segs = __skb->gso_segs; in convert___skb_to_skb()
948 skb_shinfo(skb)->gso_size = __skb->gso_size; in convert___skb_to_skb()
949 skb_shinfo(skb)->hwtstamps.hwtstamp = __skb->hwtstamp; in convert___skb_to_skb()
956 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb; in convert_skb_to___skb()
961 __skb->mark = skb->mark; in convert_skb_to___skb()
962 __skb->priority = skb->priority; in convert_skb_to___skb()
963 __skb->ingress_ifindex = skb->skb_iif; in convert_skb_to___skb()
964 __skb->ifindex = skb->dev->ifindex; in convert_skb_to___skb()
965 __skb->tstamp = skb->tstamp; in convert_skb_to___skb()
966 memcpy(__skb->cb, &cb->data, QDISC_CB_PRIV_LEN); in convert_skb_to___skb()
967 __skb->wire_len = cb->pkt_len; in convert_skb_to___skb()
968 __skb->gso_segs = skb_shinfo(skb)->gso_segs; in convert_skb_to___skb()
969 __skb->hwtstamp = skb_shinfo(skb)->hwtstamps.hwtstamp; in convert_skb_to___skb()
982 struct net *net = current->nsproxy->net_ns; in bpf_prog_test_run_skb()
983 struct net_device *dev = net->loopback_dev; in bpf_prog_test_run_skb()
984 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_skb()
985 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_skb()
994 if ((kattr->test.flags & ~BPF_F_TEST_SKB_CHECKSUM_COMPLETE) || in bpf_prog_test_run_skb()
995 kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_skb()
996 return -EINVAL; in bpf_prog_test_run_skb()
998 data = bpf_test_init(kattr, kattr->test.data_size_in, in bpf_prog_test_run_skb()
1010 switch (prog->type) { in bpf_prog_test_run_skb()
1029 return -ENOMEM; in bpf_prog_test_run_skb()
1038 return -ENOMEM; in bpf_prog_test_run_skb()
1040 skb->sk = sk; in bpf_prog_test_run_skb()
1045 if (ctx && ctx->ifindex > 1) { in bpf_prog_test_run_skb()
1046 dev = dev_get_by_index(net, ctx->ifindex); in bpf_prog_test_run_skb()
1048 ret = -ENODEV; in bpf_prog_test_run_skb()
1052 skb->protocol = eth_type_trans(skb, dev); in bpf_prog_test_run_skb()
1055 switch (skb->protocol) { in bpf_prog_test_run_skb()
1057 sk->sk_family = AF_INET; in bpf_prog_test_run_skb()
1059 sk->sk_rcv_saddr = ip_hdr(skb)->saddr; in bpf_prog_test_run_skb()
1060 sk->sk_daddr = ip_hdr(skb)->daddr; in bpf_prog_test_run_skb()
1065 sk->sk_family = AF_INET6; in bpf_prog_test_run_skb()
1067 sk->sk_v6_rcv_saddr = ipv6_hdr(skb)->saddr; in bpf_prog_test_run_skb()
1068 sk->sk_v6_daddr = ipv6_hdr(skb)->daddr; in bpf_prog_test_run_skb()
1085 if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) { in bpf_prog_test_run_skb()
1087 int len = skb->len - off; in bpf_prog_test_run_skb()
1089 skb->csum = skb_checksum(skb, off, len, 0); in bpf_prog_test_run_skb()
1090 skb->ip_summed = CHECKSUM_COMPLETE; in bpf_prog_test_run_skb()
1098 int nhead = HH_DATA_ALIGN(hh_len - skb_headroom(skb)); in bpf_prog_test_run_skb()
1101 ret = -ENOMEM; in bpf_prog_test_run_skb()
1108 if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) { in bpf_prog_test_run_skb()
1110 int len = skb->len - off; in bpf_prog_test_run_skb()
1115 if (csum_fold(skb->csum) != csum_fold(csum)) { in bpf_prog_test_run_skb()
1116 ret = -EBADMSG; in bpf_prog_test_run_skb()
1123 size = skb->len; in bpf_prog_test_run_skb()
1124 /* bpf program can never convert linear skb to non-linear */ in bpf_prog_test_run_skb()
1127 ret = bpf_test_finish(kattr, uattr, skb->data, NULL, size, retval, in bpf_prog_test_run_skb()
1133 if (dev && dev != net->loopback_dev) in bpf_prog_test_run_skb()
1150 if (xdp_md->egress_ifindex != 0) in xdp_convert_md_to_buff()
1151 return -EINVAL; in xdp_convert_md_to_buff()
1153 ingress_ifindex = xdp_md->ingress_ifindex; in xdp_convert_md_to_buff()
1154 rx_queue_index = xdp_md->rx_queue_index; in xdp_convert_md_to_buff()
1157 return -EINVAL; in xdp_convert_md_to_buff()
1160 device = dev_get_by_index(current->nsproxy->net_ns, in xdp_convert_md_to_buff()
1163 return -ENODEV; in xdp_convert_md_to_buff()
1165 if (rx_queue_index >= device->real_num_rx_queues) in xdp_convert_md_to_buff()
1170 if (!xdp_rxq_info_is_reg(&rxqueue->xdp_rxq)) in xdp_convert_md_to_buff()
1173 xdp->rxq = &rxqueue->xdp_rxq; in xdp_convert_md_to_buff()
1174 /* The device is now tracked in the xdp->rxq for later in xdp_convert_md_to_buff()
1179 xdp->data = xdp->data_meta + xdp_md->data; in xdp_convert_md_to_buff()
1184 return -EINVAL; in xdp_convert_md_to_buff()
1192 xdp_md->data = xdp->data - xdp->data_meta; in xdp_convert_buff_to_md()
1193 xdp_md->data_end = xdp->data_end - xdp->data_meta; in xdp_convert_buff_to_md()
1195 if (xdp_md->ingress_ifindex) in xdp_convert_buff_to_md()
1196 dev_put(xdp->rxq->dev); in xdp_convert_buff_to_md()
1202 bool do_live = (kattr->test.flags & BPF_F_TEST_XDP_LIVE_FRAMES); in bpf_prog_test_run_xdp()
1204 u32 batch_size = kattr->test.batch_size; in bpf_prog_test_run_xdp()
1206 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_xdp()
1208 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_xdp()
1212 int i, ret = -EINVAL; in bpf_prog_test_run_xdp()
1216 if (prog->expected_attach_type == BPF_XDP_DEVMAP || in bpf_prog_test_run_xdp()
1217 prog->expected_attach_type == BPF_XDP_CPUMAP) in bpf_prog_test_run_xdp()
1218 return -EINVAL; in bpf_prog_test_run_xdp()
1220 if (kattr->test.flags & ~BPF_F_TEST_XDP_LIVE_FRAMES) in bpf_prog_test_run_xdp()
1221 return -EINVAL; in bpf_prog_test_run_xdp()
1223 if (bpf_prog_is_dev_bound(prog->aux)) in bpf_prog_test_run_xdp()
1224 return -EINVAL; in bpf_prog_test_run_xdp()
1230 return -E2BIG; in bpf_prog_test_run_xdp()
1234 return -EINVAL; in bpf_prog_test_run_xdp()
1242 /* There can't be user provided data before the meta data */ in bpf_prog_test_run_xdp()
1243 if (ctx->data_meta || ctx->data_end != size || in bpf_prog_test_run_xdp()
1244 ctx->data > ctx->data_end || in bpf_prog_test_run_xdp()
1245 unlikely(xdp_metalen_invalid(ctx->data)) || in bpf_prog_test_run_xdp()
1246 (do_live && (kattr->test.data_out || kattr->test.ctx_out))) in bpf_prog_test_run_xdp()
1249 headroom -= ctx->data; in bpf_prog_test_run_xdp()
1252 max_data_sz = 4096 - headroom - tailroom; in bpf_prog_test_run_xdp()
1266 rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0); in bpf_prog_test_run_xdp()
1267 rxqueue->xdp_rxq.frag_size = headroom + max_data_sz + tailroom; in bpf_prog_test_run_xdp()
1268 xdp_init_buff(&xdp, rxqueue->xdp_rxq.frag_size, &rxqueue->xdp_rxq); in bpf_prog_test_run_xdp()
1276 if (unlikely(kattr->test.data_size_in > size)) { in bpf_prog_test_run_xdp()
1277 void __user *data_in = u64_to_user_ptr(kattr->test.data_in); in bpf_prog_test_run_xdp()
1279 while (size < kattr->test.data_size_in) { in bpf_prog_test_run_xdp()
1284 if (sinfo->nr_frags == MAX_SKB_FRAGS) { in bpf_prog_test_run_xdp()
1285 ret = -ENOMEM; in bpf_prog_test_run_xdp()
1291 ret = -ENOMEM; in bpf_prog_test_run_xdp()
1295 frag = &sinfo->frags[sinfo->nr_frags++]; in bpf_prog_test_run_xdp()
1297 data_len = min_t(u32, kattr->test.data_size_in - size, in bpf_prog_test_run_xdp()
1303 ret = -EFAULT; in bpf_prog_test_run_xdp()
1306 sinfo->xdp_frags_size += data_len; in bpf_prog_test_run_xdp()
1327 size = xdp.data_end - xdp.data_meta + sinfo->xdp_frags_size; in bpf_prog_test_run_xdp()
1338 for (i = 0; i < sinfo->nr_frags; i++) in bpf_prog_test_run_xdp()
1339 __free_page(skb_frag_page(&sinfo->frags[i])); in bpf_prog_test_run_xdp()
1348 /* make sure the fields we don't use are zeroed */ in verify_user_bpf_flow_keys()
1350 return -EINVAL; in verify_user_bpf_flow_keys()
1356 return -EINVAL; in verify_user_bpf_flow_keys()
1365 struct bpf_test_timer t = { NO_PREEMPT }; in bpf_prog_test_run_flow_dissector() local
1366 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_flow_dissector()
1368 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_flow_dissector()
1377 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_flow_dissector()
1378 return -EINVAL; in bpf_prog_test_run_flow_dissector()
1381 return -EINVAL; in bpf_prog_test_run_flow_dissector()
1383 data = bpf_test_init(kattr, kattr->test.data_size_in, size, 0, 0); in bpf_prog_test_run_flow_dissector()
1401 flags = user_ctx->flags; in bpf_prog_test_run_flow_dissector()
1408 bpf_test_timer_enter(&t); in bpf_prog_test_run_flow_dissector()
1410 retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN, in bpf_prog_test_run_flow_dissector()
1412 } while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration)); in bpf_prog_test_run_flow_dissector()
1413 bpf_test_timer_leave(&t); in bpf_prog_test_run_flow_dissector()
1433 struct bpf_test_timer t = { NO_PREEMPT }; in bpf_prog_test_run_sk_lookup() local
1436 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_sk_lookup()
1439 int ret = -EINVAL; in bpf_prog_test_run_sk_lookup()
1441 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_sk_lookup()
1442 return -EINVAL; in bpf_prog_test_run_sk_lookup()
1444 if (kattr->test.data_in || kattr->test.data_size_in || kattr->test.data_out || in bpf_prog_test_run_sk_lookup()
1445 kattr->test.data_size_out) in bpf_prog_test_run_sk_lookup()
1446 return -EINVAL; in bpf_prog_test_run_sk_lookup()
1456 return -EINVAL; in bpf_prog_test_run_sk_lookup()
1458 if (user_ctx->sk) in bpf_prog_test_run_sk_lookup()
1464 if (user_ctx->local_port > U16_MAX) { in bpf_prog_test_run_sk_lookup()
1465 ret = -ERANGE; in bpf_prog_test_run_sk_lookup()
1469 ctx.family = (u16)user_ctx->family; in bpf_prog_test_run_sk_lookup()
1470 ctx.protocol = (u16)user_ctx->protocol; in bpf_prog_test_run_sk_lookup()
1471 ctx.dport = (u16)user_ctx->local_port; in bpf_prog_test_run_sk_lookup()
1472 ctx.sport = user_ctx->remote_port; in bpf_prog_test_run_sk_lookup()
1476 ctx.v4.daddr = (__force __be32)user_ctx->local_ip4; in bpf_prog_test_run_sk_lookup()
1477 ctx.v4.saddr = (__force __be32)user_ctx->remote_ip4; in bpf_prog_test_run_sk_lookup()
1482 ctx.v6.daddr = (struct in6_addr *)user_ctx->local_ip6; in bpf_prog_test_run_sk_lookup()
1483 ctx.v6.saddr = (struct in6_addr *)user_ctx->remote_ip6; in bpf_prog_test_run_sk_lookup()
1488 ret = -EAFNOSUPPORT; in bpf_prog_test_run_sk_lookup()
1494 ret = -ENOMEM; in bpf_prog_test_run_sk_lookup()
1498 progs->items[0].prog = prog; in bpf_prog_test_run_sk_lookup()
1500 bpf_test_timer_enter(&t); in bpf_prog_test_run_sk_lookup()
1504 } while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration)); in bpf_prog_test_run_sk_lookup()
1505 bpf_test_timer_leave(&t); in bpf_prog_test_run_sk_lookup()
1510 user_ctx->cookie = 0; in bpf_prog_test_run_sk_lookup()
1512 if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { in bpf_prog_test_run_sk_lookup()
1513 ret = -EOPNOTSUPP; in bpf_prog_test_run_sk_lookup()
1517 user_ctx->cookie = sock_gen_cookie(ctx.selected_sk); in bpf_prog_test_run_sk_lookup()
1534 void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); in bpf_prog_test_run_syscall()
1535 __u32 ctx_size_in = kattr->test.ctx_size_in; in bpf_prog_test_run_syscall()
1540 /* doesn't support data_in/out, ctx_out, duration, or repeat or flags */ in bpf_prog_test_run_syscall()
1541 if (kattr->test.data_in || kattr->test.data_out || in bpf_prog_test_run_syscall()
1542 kattr->test.ctx_out || kattr->test.duration || in bpf_prog_test_run_syscall()
1543 kattr->test.repeat || kattr->test.flags || in bpf_prog_test_run_syscall()
1544 kattr->test.batch_size) in bpf_prog_test_run_syscall()
1545 return -EINVAL; in bpf_prog_test_run_syscall()
1547 if (ctx_size_in < prog->aux->max_ctx_offset || in bpf_prog_test_run_syscall()
1549 return -EINVAL; in bpf_prog_test_run_syscall()
1561 if (copy_to_user(&uattr->test.retval, &retval, sizeof(u32))) { in bpf_prog_test_run_syscall()
1562 err = -EFAULT; in bpf_prog_test_run_syscall()
1567 err = -EFAULT; in bpf_prog_test_run_syscall()
1577 if (user->in || user->out) in verify_and_copy_hook_state()
1578 return -EINVAL; in verify_and_copy_hook_state()
1580 if (user->net || user->sk || user->okfn) in verify_and_copy_hook_state()
1581 return -EINVAL; in verify_and_copy_hook_state()
1583 switch (user->pf) { in verify_and_copy_hook_state()
1586 switch (state->hook) { in verify_and_copy_hook_state()
1588 state->in = dev; in verify_and_copy_hook_state()
1591 state->in = dev; in verify_and_copy_hook_state()
1594 state->in = dev; in verify_and_copy_hook_state()
1595 state->out = dev; in verify_and_copy_hook_state()
1598 state->out = dev; in verify_and_copy_hook_state()
1601 state->out = dev; in verify_and_copy_hook_state()
1607 return -EINVAL; in verify_and_copy_hook_state()
1610 state->pf = user->pf; in verify_and_copy_hook_state()
1611 state->hook = user->hook; in verify_and_copy_hook_state()
1632 struct net *net = current->nsproxy->net_ns; in bpf_prog_test_run_nf()
1633 struct net_device *dev = net->loopback_dev; in bpf_prog_test_run_nf()
1638 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_nf()
1639 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_nf()
1648 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_nf()
1649 return -EINVAL; in bpf_prog_test_run_nf()
1652 return -EINVAL; in bpf_prog_test_run_nf()
1654 data = bpf_test_init(kattr, kattr->test.data_size_in, size, in bpf_prog_test_run_nf()
1677 ret = -ENOMEM; in bpf_prog_test_run_nf()
1686 ret = -EINVAL; in bpf_prog_test_run_nf()
1692 skb->protocol = eth_type_trans(skb, dev); in bpf_prog_test_run_nf()
1693 switch (skb->protocol) { in bpf_prog_test_run_nf()
1705 ret = -EPROTO; in bpf_prog_test_run_nf()
1711 skb->protocol = nfproto_eth(hook_state.pf); in bpf_prog_test_run_nf()