Skip to content

Commit 7eb83bf

Browse files
ameryhungMartin KaFai Lau
authored andcommitted
bpf: Make variables in bpf_prog_test_run_xdp less confusing
Change the variable naming in bpf_prog_test_run_xdp() to make the overall logic less confusing. As different modes were added to the function over the time, some variables got overloaded, making it hard to understand and changing the code becomes error-prone. Replace "size" with "linear_sz" where it refers to the size of metadata and data. If "size" refers to input data size, use test.data_size_in directly. Replace "max_data_sz" with "max_linear_sz" to better reflect the fact that it is the maximum size of metadata and data (i.e., linear_sz). Also, xdp_rxq.frags_size is always PAGE_SIZE, so just set it directly instead of subtracting headroom and tailroom and adding them back. Signed-off-by: Amery Hung <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 0e7a733 commit 7eb83bf

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

net/bpf/test_run.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,9 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
12071207
{
12081208
bool do_live = (kattr->test.flags & BPF_F_TEST_XDP_LIVE_FRAMES);
12091209
u32 tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
1210+
u32 retval = 0, duration, max_linear_sz, size;
1211+
u32 linear_sz = kattr->test.data_size_in;
12101212
u32 batch_size = kattr->test.batch_size;
1211-
u32 retval = 0, duration, max_data_sz;
1212-
u32 size = kattr->test.data_size_in;
12131213
u32 headroom = XDP_PACKET_HEADROOM;
12141214
u32 repeat = kattr->test.repeat;
12151215
struct netdev_rx_queue *rxqueue;
@@ -1246,7 +1246,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
12461246

12471247
if (ctx) {
12481248
/* There can't be user provided data before the meta data */
1249-
if (ctx->data_meta || ctx->data_end != size ||
1249+
if (ctx->data_meta || ctx->data_end != kattr->test.data_size_in ||
12501250
ctx->data > ctx->data_end ||
12511251
unlikely(xdp_metalen_invalid(ctx->data)) ||
12521252
(do_live && (kattr->test.data_out || kattr->test.ctx_out)))
@@ -1255,30 +1255,30 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
12551255
headroom -= ctx->data;
12561256
}
12571257

1258-
max_data_sz = PAGE_SIZE - headroom - tailroom;
1259-
if (size > max_data_sz) {
1260-
/* disallow live data mode for jumbo frames */
1261-
if (do_live)
1262-
goto free_ctx;
1263-
size = max_data_sz;
1264-
}
1258+
max_linear_sz = PAGE_SIZE - headroom - tailroom;
1259+
linear_sz = min_t(u32, linear_sz, max_linear_sz);
1260+
1261+
/* disallow live data mode for jumbo frames */
1262+
if (do_live && kattr->test.data_size_in > linear_sz)
1263+
goto free_ctx;
12651264

1266-
data = bpf_test_init(kattr, size, max_data_sz, headroom, tailroom);
1265+
data = bpf_test_init(kattr, linear_sz, max_linear_sz, headroom, tailroom);
12671266
if (IS_ERR(data)) {
12681267
ret = PTR_ERR(data);
12691268
goto free_ctx;
12701269
}
12711270

12721271
rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
1273-
rxqueue->xdp_rxq.frag_size = headroom + max_data_sz + tailroom;
1272+
rxqueue->xdp_rxq.frag_size = PAGE_SIZE;
12741273
xdp_init_buff(&xdp, rxqueue->xdp_rxq.frag_size, &rxqueue->xdp_rxq);
1275-
xdp_prepare_buff(&xdp, data, headroom, size, true);
1274+
xdp_prepare_buff(&xdp, data, headroom, linear_sz, true);
12761275
sinfo = xdp_get_shared_info_from_buff(&xdp);
12771276

12781277
ret = xdp_convert_md_to_buff(ctx, &xdp);
12791278
if (ret)
12801279
goto free_data;
12811280

1281+
size = linear_sz;
12821282
if (unlikely(kattr->test.data_size_in > size)) {
12831283
void __user *data_in = u64_to_user_ptr(kattr->test.data_in);
12841284

0 commit comments

Comments
 (0)