Lines Matching +full:t +full:- +full:head
1 // SPDX-License-Identifier: GPL-2.0-only
20 #include <linux/error-injection.h>
36 static void bpf_test_timer_enter(struct bpf_test_timer *t) in bpf_test_timer_enter() argument
40 t->time_start = ktime_get_ns(); in bpf_test_timer_enter()
43 static void bpf_test_timer_leave(struct bpf_test_timer *t) in bpf_test_timer_leave() argument
46 t->time_start = 0; in bpf_test_timer_leave()
50 static bool bpf_test_timer_continue(struct bpf_test_timer *t, int iterations, in bpf_test_timer_continue() argument
54 t->i += iterations; in bpf_test_timer_continue()
55 if (t->i >= repeat) { in bpf_test_timer_continue()
57 t->time_spent += ktime_get_ns() - t->time_start; in bpf_test_timer_continue()
58 do_div(t->time_spent, t->i); in bpf_test_timer_continue()
59 *duration = t->time_spent > U32_MAX ? U32_MAX : (u32)t->time_spent; in bpf_test_timer_continue()
66 *err = -EINTR; in bpf_test_timer_continue()
72 t->time_spent += ktime_get_ns() - t->time_start; in bpf_test_timer_continue()
73 bpf_test_timer_leave(t); in bpf_test_timer_continue()
75 bpf_test_timer_enter(t); in bpf_test_timer_continue()
82 t->i = 0; in bpf_test_timer_continue()
86 /* We put this struct at the head of each page with a context and frame
87 * initialised when the page is allocated, so we don't have to do this on each
116 #define TEST_XDP_FRAME_SIZE (PAGE_SIZE - sizeof(struct xdp_page_head))
121 struct xdp_page_head *head = in xdp_test_run_init_page() local
130 orig_ctx = xdp->orig_ctx; in xdp_test_run_init_page()
131 frm_len = orig_ctx->data_end - orig_ctx->data_meta; in xdp_test_run_init_page()
132 meta_len = orig_ctx->data - orig_ctx->data_meta; in xdp_test_run_init_page()
133 headroom -= meta_len; in xdp_test_run_init_page()
135 new_ctx = &head->ctx; in xdp_test_run_init_page()
136 frm = head->frame; in xdp_test_run_init_page()
137 data = head->data; in xdp_test_run_init_page()
138 memcpy(data + headroom, orig_ctx->data_meta, frm_len); in xdp_test_run_init_page()
140 xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq); in xdp_test_run_init_page()
142 new_ctx->data = new_ctx->data_meta + meta_len; in xdp_test_run_init_page()
145 frm->mem_type = new_ctx->rxq->mem.type; in xdp_test_run_init_page()
147 memcpy(&head->orig_ctx, new_ctx, sizeof(head->orig_ctx)); in xdp_test_run_init_page()
153 int err = -ENOMEM; in xdp_test_run_setup()
157 .pool_size = xdp->batch_size, in xdp_test_run_setup()
163 xdp->frames = kvmalloc_array(xdp->batch_size, sizeof(void *), GFP_KERNEL); in xdp_test_run_setup()
164 if (!xdp->frames) in xdp_test_run_setup()
165 return -ENOMEM; in xdp_test_run_setup()
167 xdp->skbs = kvmalloc_array(xdp->batch_size, sizeof(void *), GFP_KERNEL); in xdp_test_run_setup()
168 if (!xdp->skbs) in xdp_test_run_setup()
177 /* will copy 'mem.id' into pp->xdp_mem_id */ in xdp_test_run_setup()
178 err = xdp_reg_mem_model(&xdp->mem, MEM_TYPE_PAGE_POOL, pp); in xdp_test_run_setup()
182 xdp->pp = pp; in xdp_test_run_setup()
187 xdp_rxq_info_reg(&xdp->rxq, orig_ctx->rxq->dev, 0, 0); in xdp_test_run_setup()
188 xdp->rxq.mem.type = MEM_TYPE_PAGE_POOL; in xdp_test_run_setup()
189 xdp->rxq.mem.id = pp->xdp_mem_id; in xdp_test_run_setup()
190 xdp->dev = orig_ctx->rxq->dev; in xdp_test_run_setup()
191 xdp->orig_ctx = orig_ctx; in xdp_test_run_setup()
198 kvfree(xdp->skbs); in xdp_test_run_setup()
200 kvfree(xdp->frames); in xdp_test_run_setup()
206 xdp_unreg_mem_model(&xdp->mem); in xdp_test_run_teardown()
207 page_pool_destroy(xdp->pp); in xdp_test_run_teardown()
208 kfree(xdp->frames); in xdp_test_run_teardown()
209 kfree(xdp->skbs); in xdp_test_run_teardown()
212 static bool frame_was_changed(const struct xdp_page_head *head) in frame_was_changed() argument
218 return head->frame->data != head->orig_ctx.data || in frame_was_changed()
219 head->frame->flags != head->orig_ctx.flags; in frame_was_changed()
222 static bool ctx_was_changed(struct xdp_page_head *head) in ctx_was_changed() argument
224 return head->orig_ctx.data != head->ctx.data || in ctx_was_changed()
225 head->orig_ctx.data_meta != head->ctx.data_meta || in ctx_was_changed()
226 head->orig_ctx.data_end != head->ctx.data_end; in ctx_was_changed()
229 static void reset_ctx(struct xdp_page_head *head) in reset_ctx() argument
231 if (likely(!frame_was_changed(head) && !ctx_was_changed(head))) in reset_ctx()
234 head->ctx.data = head->orig_ctx.data; in reset_ctx()
235 head->ctx.data_meta = head->orig_ctx.data_meta; in reset_ctx()
236 head->ctx.data_end = head->orig_ctx.data_end; in reset_ctx()
237 xdp_update_frame_from_buff(&head->ctx, head->frame); in reset_ctx()
238 head->frame->mem_type = head->orig_ctx.rxq->mem.type; in reset_ctx()
254 return -ENOMEM; in xdp_recv_frames()
267 list_add_tail(&skb->list, &list); in xdp_recv_frames()
279 struct xdp_frame **frames = xdp->frames; in xdp_test_run_batch()
281 struct xdp_page_head *head; in xdp_test_run_batch() local
287 batch_sz = min_t(u32, repeat, xdp->batch_size); in xdp_test_run_batch()
295 page = page_pool_dev_alloc_pages(xdp->pp); in xdp_test_run_batch()
297 err = -ENOMEM; in xdp_test_run_batch()
301 head = phys_to_virt(page_to_phys(page)); in xdp_test_run_batch()
302 reset_ctx(head); in xdp_test_run_batch()
303 ctx = &head->ctx; in xdp_test_run_batch()
304 frm = head->frame; in xdp_test_run_batch()
305 xdp->frame_cnt++; in xdp_test_run_batch()
310 if (unlikely(ctx_was_changed(head))) { in xdp_test_run_batch()
320 /* we can't do a real XDP_TX since we're not in the in xdp_test_run_batch()
324 ri->tgt_index = xdp->dev->ifindex; in xdp_test_run_batch()
325 ri->map_id = INT_MAX; in xdp_test_run_batch()
326 ri->map_type = BPF_MAP_TYPE_UNSPEC; in xdp_test_run_batch()
330 ret = xdp_do_redirect_frame(xdp->dev, ctx, frm, prog); in xdp_test_run_batch()
350 ret = xdp_recv_frames(frames, nframes, xdp->skbs, xdp->dev); in xdp_test_run_batch()
366 struct bpf_test_timer t = {}; in bpf_test_run_xdp_live() local
376 bpf_test_timer_enter(&t); in bpf_test_run_xdp_live()
379 ret = xdp_test_run_batch(&xdp, prog, repeat - t.i); in bpf_test_run_xdp_live()
382 } while (bpf_test_timer_continue(&t, xdp.frame_cnt, repeat, &ret, time)); in bpf_test_run_xdp_live()
383 bpf_test_timer_leave(&t); in bpf_test_run_xdp_live()
396 struct bpf_test_timer t = {}; in bpf_test_run() local
406 return -ENOMEM; in bpf_test_run()
413 bpf_test_timer_enter(&t); in bpf_test_run()
427 } while (bpf_test_timer_continue(&t, 1, repeat, &ret, time)); in bpf_test_run()
429 bpf_test_timer_leave(&t); in bpf_test_run()
442 void __user *data_out = u64_to_user_ptr(kattr->test.data_out); in bpf_test_finish()
443 int err = -EFAULT; in bpf_test_finish()
449 if (kattr->test.data_size_out && in bpf_test_finish()
450 copy_size > kattr->test.data_size_out) { in bpf_test_finish()
451 copy_size = kattr->test.data_size_out; in bpf_test_finish()
452 err = -ENOSPC; in bpf_test_finish()
456 int len = sinfo ? copy_size - sinfo->xdp_frags_size : copy_size; in bpf_test_finish()
459 err = -ENOSPC; in bpf_test_finish()
470 for (i = 0; i < sinfo->nr_frags; i++) { in bpf_test_finish()
471 skb_frag_t *frag = &sinfo->frags[i]; in bpf_test_finish()
474 err = -ENOSPC; in bpf_test_finish()
478 data_len = min_t(u32, copy_size - offset, in bpf_test_finish()
491 if (copy_to_user(&uattr->test.data_size_out, &size, sizeof(size))) in bpf_test_finish()
493 if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) in bpf_test_finish()
495 if (copy_to_user(&uattr->test.duration, &duration, sizeof(duration))) in bpf_test_finish()
497 if (err != -ENOSPC) in bpf_test_finish()
553 return (long)arg->a; in bpf_fentry_test8()
614 refcount_dec(&p->cnt); in bpf_kfunc_call_test_release()
654 void __user *data_in = u64_to_user_ptr(kattr->test.data_in); in BTF_ID_FLAGS()
657 if (user_size > PAGE_SIZE - headroom - tailroom) in BTF_ID_FLAGS()
658 return ERR_PTR(-EINVAL); in BTF_ID_FLAGS()
663 return ERR_PTR(-ENOMEM); in BTF_ID_FLAGS()
667 return ERR_PTR(-EFAULT); in BTF_ID_FLAGS()
679 int b = 2, err = -EFAULT; in bpf_prog_test_run_tracing()
682 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_tracing()
683 return -EINVAL; in bpf_prog_test_run_tracing()
685 switch (prog->expected_attach_type) { in bpf_prog_test_run_tracing()
714 if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) in bpf_prog_test_run_tracing()
739 info->retval = bpf_prog_run(info->prog, info->ctx); in __bpf_prog_test_run_raw_tp()
749 void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); in bpf_prog_test_run_raw_tp()
750 __u32 ctx_size_in = kattr->test.ctx_size_in; in bpf_prog_test_run_raw_tp()
752 int cpu = kattr->test.cpu, err = 0; in bpf_prog_test_run_raw_tp()
755 /* doesn't support data_in/out, ctx_out, duration, or repeat */ in bpf_prog_test_run_raw_tp()
756 if (kattr->test.data_in || kattr->test.data_out || in bpf_prog_test_run_raw_tp()
757 kattr->test.ctx_out || kattr->test.duration || in bpf_prog_test_run_raw_tp()
758 kattr->test.repeat || kattr->test.batch_size) in bpf_prog_test_run_raw_tp()
759 return -EINVAL; in bpf_prog_test_run_raw_tp()
761 if (ctx_size_in < prog->aux->max_ctx_offset || in bpf_prog_test_run_raw_tp()
763 return -EINVAL; in bpf_prog_test_run_raw_tp()
765 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 && cpu != 0) in bpf_prog_test_run_raw_tp()
766 return -EINVAL; in bpf_prog_test_run_raw_tp()
779 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 || in bpf_prog_test_run_raw_tp()
788 err = -ENXIO; in bpf_prog_test_run_raw_tp()
796 copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32))) in bpf_prog_test_run_raw_tp()
797 err = -EFAULT; in bpf_prog_test_run_raw_tp()
805 void __user *data_in = u64_to_user_ptr(kattr->test.ctx_in); in bpf_ctx_init()
806 void __user *data_out = u64_to_user_ptr(kattr->test.ctx_out); in bpf_ctx_init()
807 u32 size = kattr->test.ctx_size_in; in bpf_ctx_init()
816 return ERR_PTR(-ENOMEM); in bpf_ctx_init()
828 return ERR_PTR(-EFAULT); in bpf_ctx_init()
838 void __user *data_out = u64_to_user_ptr(kattr->test.ctx_out); in bpf_ctx_finish()
839 int err = -EFAULT; in bpf_ctx_finish()
845 if (copy_size > kattr->test.ctx_size_out) { in bpf_ctx_finish()
846 copy_size = kattr->test.ctx_size_out; in bpf_ctx_finish()
847 err = -ENOSPC; in bpf_ctx_finish()
852 if (copy_to_user(&uattr->test.ctx_size_out, &size, sizeof(size))) in bpf_ctx_finish()
854 if (err != -ENOSPC) in bpf_ctx_finish()
861 * range_is_zero - test whether buffer is initialized
866 * This function returns true if the there is a non-zero byte
871 return !memchr_inv((u8 *)buf + from, 0, to - from); in range_is_zero()
876 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb; in convert___skb_to_skb()
881 /* make sure the fields we don't use are zeroed */ in convert___skb_to_skb()
883 return -EINVAL; in convert___skb_to_skb()
889 return -EINVAL; in convert___skb_to_skb()
897 return -EINVAL; in convert___skb_to_skb()
903 return -EINVAL; in convert___skb_to_skb()
911 return -EINVAL; in convert___skb_to_skb()
917 return -EINVAL; in convert___skb_to_skb()
923 return -EINVAL; in convert___skb_to_skb()
925 skb->mark = __skb->mark; in convert___skb_to_skb()
926 skb->priority = __skb->priority; in convert___skb_to_skb()
927 skb->skb_iif = __skb->ingress_ifindex; in convert___skb_to_skb()
928 skb->tstamp = __skb->tstamp; in convert___skb_to_skb()
929 memcpy(&cb->data, __skb->cb, QDISC_CB_PRIV_LEN); in convert___skb_to_skb()
931 if (__skb->wire_len == 0) { in convert___skb_to_skb()
932 cb->pkt_len = skb->len; in convert___skb_to_skb()
934 if (__skb->wire_len < skb->len || in convert___skb_to_skb()
935 __skb->wire_len > GSO_LEGACY_MAX_SIZE) in convert___skb_to_skb()
936 return -EINVAL; in convert___skb_to_skb()
937 cb->pkt_len = __skb->wire_len; in convert___skb_to_skb()
940 if (__skb->gso_segs > GSO_MAX_SEGS) in convert___skb_to_skb()
941 return -EINVAL; in convert___skb_to_skb()
942 skb_shinfo(skb)->gso_segs = __skb->gso_segs; in convert___skb_to_skb()
943 skb_shinfo(skb)->gso_size = __skb->gso_size; in convert___skb_to_skb()
944 skb_shinfo(skb)->hwtstamps.hwtstamp = __skb->hwtstamp; in convert___skb_to_skb()
951 struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb; in convert_skb_to___skb()
956 __skb->mark = skb->mark; in convert_skb_to___skb()
957 __skb->priority = skb->priority; in convert_skb_to___skb()
958 __skb->ingress_ifindex = skb->skb_iif; in convert_skb_to___skb()
959 __skb->ifindex = skb->dev->ifindex; in convert_skb_to___skb()
960 __skb->tstamp = skb->tstamp; in convert_skb_to___skb()
961 memcpy(__skb->cb, &cb->data, QDISC_CB_PRIV_LEN); in convert_skb_to___skb()
962 __skb->wire_len = cb->pkt_len; in convert_skb_to___skb()
963 __skb->gso_segs = skb_shinfo(skb)->gso_segs; in convert_skb_to___skb()
964 __skb->hwtstamp = skb_shinfo(skb)->hwtstamps.hwtstamp; in convert_skb_to___skb()
977 struct net *net = current->nsproxy->net_ns; in bpf_prog_test_run_skb()
978 struct net_device *dev = net->loopback_dev; in bpf_prog_test_run_skb()
979 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_skb()
980 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_skb()
989 if ((kattr->test.flags & ~BPF_F_TEST_SKB_CHECKSUM_COMPLETE) || in bpf_prog_test_run_skb()
990 kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_skb()
991 return -EINVAL; in bpf_prog_test_run_skb()
994 return -EINVAL; in bpf_prog_test_run_skb()
996 data = bpf_test_init(kattr, kattr->test.data_size_in, in bpf_prog_test_run_skb()
1008 switch (prog->type) { in bpf_prog_test_run_skb()
1027 return -ENOMEM; in bpf_prog_test_run_skb()
1036 return -ENOMEM; in bpf_prog_test_run_skb()
1038 skb->sk = sk; in bpf_prog_test_run_skb()
1043 if (ctx && ctx->ifindex > 1) { in bpf_prog_test_run_skb()
1044 dev = dev_get_by_index(net, ctx->ifindex); in bpf_prog_test_run_skb()
1046 ret = -ENODEV; in bpf_prog_test_run_skb()
1050 skb->protocol = eth_type_trans(skb, dev); in bpf_prog_test_run_skb()
1053 switch (skb->protocol) { in bpf_prog_test_run_skb()
1055 sk->sk_family = AF_INET; in bpf_prog_test_run_skb()
1057 sk->sk_rcv_saddr = ip_hdr(skb)->saddr; in bpf_prog_test_run_skb()
1058 sk->sk_daddr = ip_hdr(skb)->daddr; in bpf_prog_test_run_skb()
1063 sk->sk_family = AF_INET6; in bpf_prog_test_run_skb()
1065 sk->sk_v6_rcv_saddr = ipv6_hdr(skb)->saddr; in bpf_prog_test_run_skb()
1066 sk->sk_v6_daddr = ipv6_hdr(skb)->daddr; in bpf_prog_test_run_skb()
1083 if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) { in bpf_prog_test_run_skb()
1085 int len = skb->len - off; in bpf_prog_test_run_skb()
1087 skb->csum = skb_checksum(skb, off, len, 0); in bpf_prog_test_run_skb()
1088 skb->ip_summed = CHECKSUM_COMPLETE; in bpf_prog_test_run_skb()
1096 int nhead = HH_DATA_ALIGN(hh_len - skb_headroom(skb)); in bpf_prog_test_run_skb()
1099 ret = -ENOMEM; in bpf_prog_test_run_skb()
1106 if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) { in bpf_prog_test_run_skb()
1108 int len = skb->len - off; in bpf_prog_test_run_skb()
1113 if (csum_fold(skb->csum) != csum_fold(csum)) { in bpf_prog_test_run_skb()
1114 ret = -EBADMSG; in bpf_prog_test_run_skb()
1121 size = skb->len; in bpf_prog_test_run_skb()
1122 /* bpf program can never convert linear skb to non-linear */ in bpf_prog_test_run_skb()
1125 ret = bpf_test_finish(kattr, uattr, skb->data, NULL, size, retval, in bpf_prog_test_run_skb()
1131 if (dev && dev != net->loopback_dev) in bpf_prog_test_run_skb()
1148 if (xdp_md->egress_ifindex != 0) in xdp_convert_md_to_buff()
1149 return -EINVAL; in xdp_convert_md_to_buff()
1151 ingress_ifindex = xdp_md->ingress_ifindex; in xdp_convert_md_to_buff()
1152 rx_queue_index = xdp_md->rx_queue_index; in xdp_convert_md_to_buff()
1155 return -EINVAL; in xdp_convert_md_to_buff()
1158 device = dev_get_by_index(current->nsproxy->net_ns, in xdp_convert_md_to_buff()
1161 return -ENODEV; in xdp_convert_md_to_buff()
1163 if (rx_queue_index >= device->real_num_rx_queues) in xdp_convert_md_to_buff()
1168 if (!xdp_rxq_info_is_reg(&rxqueue->xdp_rxq)) in xdp_convert_md_to_buff()
1171 xdp->rxq = &rxqueue->xdp_rxq; in xdp_convert_md_to_buff()
1172 /* The device is now tracked in the xdp->rxq for later in xdp_convert_md_to_buff()
1177 xdp->data = xdp->data_meta + xdp_md->data; in xdp_convert_md_to_buff()
1182 return -EINVAL; in xdp_convert_md_to_buff()
1190 xdp_md->data = xdp->data - xdp->data_meta; in xdp_convert_buff_to_md()
1191 xdp_md->data_end = xdp->data_end - xdp->data_meta; in xdp_convert_buff_to_md()
1193 if (xdp_md->ingress_ifindex) in xdp_convert_buff_to_md()
1194 dev_put(xdp->rxq->dev); in xdp_convert_buff_to_md()
1200 bool do_live = (kattr->test.flags & BPF_F_TEST_XDP_LIVE_FRAMES); in bpf_prog_test_run_xdp()
1203 u32 linear_sz = kattr->test.data_size_in; in bpf_prog_test_run_xdp()
1204 u32 batch_size = kattr->test.batch_size; in bpf_prog_test_run_xdp()
1206 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_xdp()
1210 int i, ret = -EINVAL; in bpf_prog_test_run_xdp()
1214 if (prog->expected_attach_type == BPF_XDP_DEVMAP || in bpf_prog_test_run_xdp()
1215 prog->expected_attach_type == BPF_XDP_CPUMAP) in bpf_prog_test_run_xdp()
1216 return -EINVAL; in bpf_prog_test_run_xdp()
1218 if (kattr->test.flags & ~BPF_F_TEST_XDP_LIVE_FRAMES) in bpf_prog_test_run_xdp()
1219 return -EINVAL; in bpf_prog_test_run_xdp()
1221 if (bpf_prog_is_dev_bound(prog->aux)) in bpf_prog_test_run_xdp()
1222 return -EINVAL; in bpf_prog_test_run_xdp()
1228 return -E2BIG; in bpf_prog_test_run_xdp()
1232 return -EINVAL; in bpf_prog_test_run_xdp()
1240 /* There can't be user provided data before the meta data */ in bpf_prog_test_run_xdp()
1241 if (ctx->data_meta || ctx->data_end > kattr->test.data_size_in || in bpf_prog_test_run_xdp()
1242 ctx->data > ctx->data_end || in bpf_prog_test_run_xdp()
1243 unlikely(xdp_metalen_invalid(ctx->data)) || in bpf_prog_test_run_xdp()
1244 (do_live && (kattr->test.data_out || kattr->test.ctx_out))) in bpf_prog_test_run_xdp()
1247 headroom -= ctx->data; in bpf_prog_test_run_xdp()
1249 meta_sz = ctx->data; in bpf_prog_test_run_xdp()
1250 linear_sz = ctx->data_end; in bpf_prog_test_run_xdp()
1253 max_linear_sz = PAGE_SIZE - headroom - tailroom; in bpf_prog_test_run_xdp()
1257 if (do_live && kattr->test.data_size_in > linear_sz) in bpf_prog_test_run_xdp()
1260 if (kattr->test.data_size_in - meta_sz < ETH_HLEN) in bpf_prog_test_run_xdp()
1269 rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0); in bpf_prog_test_run_xdp()
1270 rxqueue->xdp_rxq.frag_size = PAGE_SIZE; in bpf_prog_test_run_xdp()
1271 xdp_init_buff(&xdp, rxqueue->xdp_rxq.frag_size, &rxqueue->xdp_rxq); in bpf_prog_test_run_xdp()
1280 if (unlikely(kattr->test.data_size_in > size)) { in bpf_prog_test_run_xdp()
1281 void __user *data_in = u64_to_user_ptr(kattr->test.data_in); in bpf_prog_test_run_xdp()
1283 while (size < kattr->test.data_size_in) { in bpf_prog_test_run_xdp()
1288 if (sinfo->nr_frags == MAX_SKB_FRAGS) { in bpf_prog_test_run_xdp()
1289 ret = -ENOMEM; in bpf_prog_test_run_xdp()
1295 ret = -ENOMEM; in bpf_prog_test_run_xdp()
1299 frag = &sinfo->frags[sinfo->nr_frags++]; in bpf_prog_test_run_xdp()
1301 data_len = min_t(u32, kattr->test.data_size_in - size, in bpf_prog_test_run_xdp()
1307 ret = -EFAULT; in bpf_prog_test_run_xdp()
1310 sinfo->xdp_frags_size += data_len; in bpf_prog_test_run_xdp()
1331 size = xdp.data_end - xdp.data_meta + sinfo->xdp_frags_size; in bpf_prog_test_run_xdp()
1342 for (i = 0; i < sinfo->nr_frags; i++) in bpf_prog_test_run_xdp()
1343 __free_page(skb_frag_page(&sinfo->frags[i])); in bpf_prog_test_run_xdp()
1352 /* make sure the fields we don't use are zeroed */ in verify_user_bpf_flow_keys()
1354 return -EINVAL; in verify_user_bpf_flow_keys()
1360 return -EINVAL; in verify_user_bpf_flow_keys()
1369 struct bpf_test_timer t = {}; in bpf_prog_test_run_flow_dissector() local
1370 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_flow_dissector()
1372 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_flow_dissector()
1381 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_flow_dissector()
1382 return -EINVAL; in bpf_prog_test_run_flow_dissector()
1385 return -EINVAL; in bpf_prog_test_run_flow_dissector()
1387 data = bpf_test_init(kattr, kattr->test.data_size_in, size, 0, 0); in bpf_prog_test_run_flow_dissector()
1405 flags = user_ctx->flags; in bpf_prog_test_run_flow_dissector()
1412 bpf_test_timer_enter(&t); in bpf_prog_test_run_flow_dissector()
1414 retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN, in bpf_prog_test_run_flow_dissector()
1416 } while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration)); in bpf_prog_test_run_flow_dissector()
1417 bpf_test_timer_leave(&t); in bpf_prog_test_run_flow_dissector()
1437 struct bpf_test_timer t = {}; in bpf_prog_test_run_sk_lookup() local
1440 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_sk_lookup()
1443 int ret = -EINVAL; in bpf_prog_test_run_sk_lookup()
1445 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_sk_lookup()
1446 return -EINVAL; in bpf_prog_test_run_sk_lookup()
1448 if (kattr->test.data_in || kattr->test.data_size_in || kattr->test.data_out || in bpf_prog_test_run_sk_lookup()
1449 kattr->test.data_size_out) in bpf_prog_test_run_sk_lookup()
1450 return -EINVAL; in bpf_prog_test_run_sk_lookup()
1460 return -EINVAL; in bpf_prog_test_run_sk_lookup()
1462 if (user_ctx->sk) in bpf_prog_test_run_sk_lookup()
1468 if (user_ctx->local_port > U16_MAX) { in bpf_prog_test_run_sk_lookup()
1469 ret = -ERANGE; in bpf_prog_test_run_sk_lookup()
1473 ctx.family = (u16)user_ctx->family; in bpf_prog_test_run_sk_lookup()
1474 ctx.protocol = (u16)user_ctx->protocol; in bpf_prog_test_run_sk_lookup()
1475 ctx.dport = (u16)user_ctx->local_port; in bpf_prog_test_run_sk_lookup()
1476 ctx.sport = user_ctx->remote_port; in bpf_prog_test_run_sk_lookup()
1480 ctx.v4.daddr = (__force __be32)user_ctx->local_ip4; in bpf_prog_test_run_sk_lookup()
1481 ctx.v4.saddr = (__force __be32)user_ctx->remote_ip4; in bpf_prog_test_run_sk_lookup()
1486 ctx.v6.daddr = (struct in6_addr *)user_ctx->local_ip6; in bpf_prog_test_run_sk_lookup()
1487 ctx.v6.saddr = (struct in6_addr *)user_ctx->remote_ip6; in bpf_prog_test_run_sk_lookup()
1492 ret = -EAFNOSUPPORT; in bpf_prog_test_run_sk_lookup()
1498 ret = -ENOMEM; in bpf_prog_test_run_sk_lookup()
1502 progs->items[0].prog = prog; in bpf_prog_test_run_sk_lookup()
1504 bpf_test_timer_enter(&t); in bpf_prog_test_run_sk_lookup()
1508 } while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration)); in bpf_prog_test_run_sk_lookup()
1509 bpf_test_timer_leave(&t); in bpf_prog_test_run_sk_lookup()
1514 user_ctx->cookie = 0; in bpf_prog_test_run_sk_lookup()
1516 if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { in bpf_prog_test_run_sk_lookup()
1517 ret = -EOPNOTSUPP; in bpf_prog_test_run_sk_lookup()
1521 user_ctx->cookie = sock_gen_cookie(ctx.selected_sk); in bpf_prog_test_run_sk_lookup()
1538 void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); in bpf_prog_test_run_syscall()
1539 __u32 ctx_size_in = kattr->test.ctx_size_in; in bpf_prog_test_run_syscall()
1544 /* doesn't support data_in/out, ctx_out, duration, or repeat or flags */ in bpf_prog_test_run_syscall()
1545 if (kattr->test.data_in || kattr->test.data_out || in bpf_prog_test_run_syscall()
1546 kattr->test.ctx_out || kattr->test.duration || in bpf_prog_test_run_syscall()
1547 kattr->test.repeat || kattr->test.flags || in bpf_prog_test_run_syscall()
1548 kattr->test.batch_size) in bpf_prog_test_run_syscall()
1549 return -EINVAL; in bpf_prog_test_run_syscall()
1551 if (ctx_size_in < prog->aux->max_ctx_offset || in bpf_prog_test_run_syscall()
1553 return -EINVAL; in bpf_prog_test_run_syscall()
1565 if (copy_to_user(&uattr->test.retval, &retval, sizeof(u32))) { in bpf_prog_test_run_syscall()
1566 err = -EFAULT; in bpf_prog_test_run_syscall()
1571 err = -EFAULT; in bpf_prog_test_run_syscall()
1581 if (user->in || user->out) in verify_and_copy_hook_state()
1582 return -EINVAL; in verify_and_copy_hook_state()
1584 if (user->net || user->sk || user->okfn) in verify_and_copy_hook_state()
1585 return -EINVAL; in verify_and_copy_hook_state()
1587 switch (user->pf) { in verify_and_copy_hook_state()
1590 switch (state->hook) { in verify_and_copy_hook_state()
1592 state->in = dev; in verify_and_copy_hook_state()
1595 state->in = dev; in verify_and_copy_hook_state()
1598 state->in = dev; in verify_and_copy_hook_state()
1599 state->out = dev; in verify_and_copy_hook_state()
1602 state->out = dev; in verify_and_copy_hook_state()
1605 state->out = dev; in verify_and_copy_hook_state()
1611 return -EINVAL; in verify_and_copy_hook_state()
1614 state->pf = user->pf; in verify_and_copy_hook_state()
1615 state->hook = user->hook; in verify_and_copy_hook_state()
1636 struct net *net = current->nsproxy->net_ns; in bpf_prog_test_run_nf()
1637 struct net_device *dev = net->loopback_dev; in bpf_prog_test_run_nf()
1642 u32 size = kattr->test.data_size_in; in bpf_prog_test_run_nf()
1643 u32 repeat = kattr->test.repeat; in bpf_prog_test_run_nf()
1652 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) in bpf_prog_test_run_nf()
1653 return -EINVAL; in bpf_prog_test_run_nf()
1656 return -EINVAL; in bpf_prog_test_run_nf()
1658 data = bpf_test_init(kattr, kattr->test.data_size_in, size, in bpf_prog_test_run_nf()
1681 ret = -ENOMEM; in bpf_prog_test_run_nf()
1690 ret = -EINVAL; in bpf_prog_test_run_nf()
1696 skb->protocol = eth_type_trans(skb, dev); in bpf_prog_test_run_nf()
1697 switch (skb->protocol) { in bpf_prog_test_run_nf()
1709 ret = -EPROTO; in bpf_prog_test_run_nf()
1715 skb->protocol = nfproto_eth(hook_state.pf); in bpf_prog_test_run_nf()