Skip to content

Commit 1e46c09

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add the ability to use unaligned chunks in the AF_XDP umem. By relaxing where the chunks can be placed, it allows to use an arbitrary buffer size and place whenever there is a free address in the umem. Helps more seamless DPDK AF_XDP driver integration. Support for i40e, ixgbe and mlx5e, from Kevin and Maxim. 2) Addition of a wakeup flag for AF_XDP tx and fill rings so the application can wake up the kernel for rx/tx processing which avoids busy-spinning of the latter, useful when app and driver is located on the same core. Support for i40e, ixgbe and mlx5e, from Magnus and Maxim. 3) bpftool fixes for printf()-like functions so compiler can actually enforce checks, bpftool build system improvements for custom output directories, and addition of 'bpftool map freeze' command, from Quentin. 4) Support attaching/detaching XDP programs from 'bpftool net' command, from Daniel. 5) Automatic xskmap cleanup when AF_XDP socket is released, and several barrier/{read,write}_once fixes in AF_XDP code, from Björn. 6) Relicense of bpf_helpers.h/bpf_endian.h for future libbpf inclusion as well as libbpf versioning improvements, from Andrii. 7) Several new BPF kselftests for verifier precision tracking, from Alexei. 8) Several BPF kselftest fixes wrt endianess to run on s390x, from Ilya. 9) And more BPF kselftest improvements all over the place, from Stanislav. 10) Add simple BPF map op cache for nfp driver to batch dumps, from Jakub. 11) AF_XDP socket umem mapping improvements for 32bit archs, from Ivan. 12) Add BPF-to-BPF call and BTF line info support for s390x JIT, from Yauheni. 13) Small optimization in arm64 JIT to spare 1 insns for BPF_MOD, from Jerin. 14) Fix an error check in bpf_tcp_gen_syncookie() helper, from Petar. 15) Various minor fixes and cleanups, from Nathan, Masahiro, Masanari, Peter, Wei, Yue. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents f9bcfe2 + 593f191 commit 1e46c09

124 files changed

Lines changed: 3489 additions & 698 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/networking/af_xdp.rst‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ an example, if the UMEM is 64k and each chunk is 4k, then the UMEM has
153153

154154
Frames passed to the kernel are used for the ingress path (RX rings).
155155

156-
The user application produces UMEM addrs to this ring. Note that the
157-
kernel will mask the incoming addr. E.g. for a chunk size of 2k, the
158-
log2(2048) LSB of the addr will be masked off, meaning that 2048, 2050
159-
and 3000 refers to the same chunk.
156+
The user application produces UMEM addrs to this ring. Note that, if
157+
running the application with aligned chunk mode, the kernel will mask
158+
the incoming addr. E.g. for a chunk size of 2k, the log2(2048) LSB of
159+
the addr will be masked off, meaning that 2048, 2050 and 3000 refers
160+
to the same chunk. If the user application is run in the unaligned
161+
chunks mode, then the incoming addr will be left untouched.
160162

161163

162164
UMEM Completion Ring

‎arch/arm64/net/bpf_jit.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@
171171
/* Rd = Ra + Rn * Rm */
172172
#define A64_MADD(sf, Rd, Ra, Rn, Rm) aarch64_insn_gen_data3(Rd, Ra, Rn, Rm, \
173173
A64_VARIANT(sf), AARCH64_INSN_DATA3_MADD)
174+
/* Rd = Ra - Rn * Rm */
175+
#define A64_MSUB(sf, Rd, Ra, Rn, Rm) aarch64_insn_gen_data3(Rd, Ra, Rn, Rm, \
176+
A64_VARIANT(sf), AARCH64_INSN_DATA3_MSUB)
174177
/* Rd = Rn * Rm */
175178
#define A64_MUL(sf, Rd, Rn, Rm) A64_MADD(sf, Rd, A64_ZR, Rn, Rm)
176179

‎arch/arm64/net/bpf_jit_comp.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
409409
break;
410410
case BPF_MOD:
411411
emit(A64_UDIV(is64, tmp, dst, src), ctx);
412-
emit(A64_MUL(is64, tmp, tmp, src), ctx);
413-
emit(A64_SUB(is64, dst, dst, tmp), ctx);
412+
emit(A64_MSUB(is64, dst, dst, tmp, src), ctx);
414413
break;
415414
}
416415
break;
@@ -516,8 +515,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
516515
case BPF_ALU64 | BPF_MOD | BPF_K:
517516
emit_a64_mov_i(is64, tmp2, imm, ctx);
518517
emit(A64_UDIV(is64, tmp, dst, tmp2), ctx);
519-
emit(A64_MUL(is64, tmp, tmp, tmp2), ctx);
520-
emit(A64_SUB(is64, dst, dst, tmp), ctx);
518+
emit(A64_MSUB(is64, dst, dst, tmp, tmp2), ctx);
521519
break;
522520
case BPF_ALU | BPF_LSH | BPF_K:
523521
case BPF_ALU64 | BPF_LSH | BPF_K:

‎arch/s390/net/bpf_jit_comp.c‎

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ static void bpf_jit_epilogue(struct bpf_jit *jit, u32 stack_depth)
502502
* NOTE: Use noinline because for gcov (-fprofile-arcs) gcc allocates a lot of
503503
* stack space for the large switch statement.
504504
*/
505-
static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i)
505+
static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
506+
int i, bool extra_pass)
506507
{
507508
struct bpf_insn *insn = &fp->insnsi[i];
508509
int jmp_off, last, insn_count = 1;
@@ -1011,10 +1012,14 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i
10111012
*/
10121013
case BPF_JMP | BPF_CALL:
10131014
{
1014-
/*
1015-
* b0 = (__bpf_call_base + imm)(b1, b2, b3, b4, b5)
1016-
*/
1017-
const u64 func = (u64)__bpf_call_base + imm;
1015+
u64 func;
1016+
bool func_addr_fixed;
1017+
int ret;
1018+
1019+
ret = bpf_jit_get_func_addr(fp, insn, extra_pass,
1020+
&func, &func_addr_fixed);
1021+
if (ret < 0)
1022+
return -1;
10181023

10191024
REG_SET_SEEN(BPF_REG_5);
10201025
jit->seen |= SEEN_FUNC;
@@ -1283,7 +1288,8 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i
12831288
/*
12841289
* Compile eBPF program into s390x code
12851290
*/
1286-
static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp)
1291+
static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp,
1292+
bool extra_pass)
12871293
{
12881294
int i, insn_count;
12891295

@@ -1292,7 +1298,7 @@ static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp)
12921298

12931299
bpf_jit_prologue(jit, fp->aux->stack_depth);
12941300
for (i = 0; i < fp->len; i += insn_count) {
1295-
insn_count = bpf_jit_insn(jit, fp, i);
1301+
insn_count = bpf_jit_insn(jit, fp, i, extra_pass);
12961302
if (insn_count < 0)
12971303
return -1;
12981304
/* Next instruction address */
@@ -1311,14 +1317,22 @@ bool bpf_jit_needs_zext(void)
13111317
return true;
13121318
}
13131319

1320+
struct s390_jit_data {
1321+
struct bpf_binary_header *header;
1322+
struct bpf_jit ctx;
1323+
int pass;
1324+
};
1325+
13141326
/*
13151327
* Compile eBPF program "fp"
13161328
*/
13171329
struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
13181330
{
13191331
struct bpf_prog *tmp, *orig_fp = fp;
13201332
struct bpf_binary_header *header;
1333+
struct s390_jit_data *jit_data;
13211334
bool tmp_blinded = false;
1335+
bool extra_pass = false;
13221336
struct bpf_jit jit;
13231337
int pass;
13241338

@@ -1337,6 +1351,23 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
13371351
fp = tmp;
13381352
}
13391353

1354+
jit_data = fp->aux->jit_data;
1355+
if (!jit_data) {
1356+
jit_data = kzalloc(sizeof(*jit_data), GFP_KERNEL);
1357+
if (!jit_data) {
1358+
fp = orig_fp;
1359+
goto out;
1360+
}
1361+
fp->aux->jit_data = jit_data;
1362+
}
1363+
if (jit_data->ctx.addrs) {
1364+
jit = jit_data->ctx;
1365+
header = jit_data->header;
1366+
extra_pass = true;
1367+
pass = jit_data->pass + 1;
1368+
goto skip_init_ctx;
1369+
}
1370+
13401371
memset(&jit, 0, sizeof(jit));
13411372
jit.addrs = kcalloc(fp->len + 1, sizeof(*jit.addrs), GFP_KERNEL);
13421373
if (jit.addrs == NULL) {
@@ -1349,7 +1380,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
13491380
* - 3: Calculate program size and addrs arrray
13501381
*/
13511382
for (pass = 1; pass <= 3; pass++) {
1352-
if (bpf_jit_prog(&jit, fp)) {
1383+
if (bpf_jit_prog(&jit, fp, extra_pass)) {
13531384
fp = orig_fp;
13541385
goto free_addrs;
13551386
}
@@ -1361,12 +1392,14 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
13611392
fp = orig_fp;
13621393
goto free_addrs;
13631394
}
1395+
13641396
header = bpf_jit_binary_alloc(jit.size, &jit.prg_buf, 2, jit_fill_hole);
13651397
if (!header) {
13661398
fp = orig_fp;
13671399
goto free_addrs;
13681400
}
1369-
if (bpf_jit_prog(&jit, fp)) {
1401+
skip_init_ctx:
1402+
if (bpf_jit_prog(&jit, fp, extra_pass)) {
13701403
bpf_jit_binary_free(header);
13711404
fp = orig_fp;
13721405
goto free_addrs;
@@ -1375,12 +1408,24 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
13751408
bpf_jit_dump(fp->len, jit.size, pass, jit.prg_buf);
13761409
print_fn_code(jit.prg_buf, jit.size_prg);
13771410
}
1378-
bpf_jit_binary_lock_ro(header);
1411+
if (!fp->is_func || extra_pass) {
1412+
bpf_jit_binary_lock_ro(header);
1413+
} else {
1414+
jit_data->header = header;
1415+
jit_data->ctx = jit;
1416+
jit_data->pass = pass;
1417+
}
13791418
fp->bpf_func = (void *) jit.prg_buf;
13801419
fp->jited = 1;
13811420
fp->jited_len = jit.size;
1421+
1422+
if (!fp->is_func || extra_pass) {
1423+
bpf_prog_fill_jited_linfo(fp, jit.addrs + 1);
13821424
free_addrs:
1383-
kfree(jit.addrs);
1425+
kfree(jit.addrs);
1426+
kfree(jit_data);
1427+
fp->aux->jit_data = NULL;
1428+
}
13841429
out:
13851430
if (tmp_blinded)
13861431
bpf_jit_prog_release_other(fp, fp == orig_fp ?

‎drivers/net/ethernet/intel/i40e/i40e_main.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12530,7 +12530,8 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi,
1253012530
if (need_reset && prog)
1253112531
for (i = 0; i < vsi->num_queue_pairs; i++)
1253212532
if (vsi->xdp_rings[i]->xsk_umem)
12533-
(void)i40e_xsk_async_xmit(vsi->netdev, i);
12533+
(void)i40e_xsk_wakeup(vsi->netdev, i,
12534+
XDP_WAKEUP_RX);
1253412535

1253512536
return 0;
1253612537
}
@@ -12852,7 +12853,7 @@ static const struct net_device_ops i40e_netdev_ops = {
1285212853
.ndo_bridge_setlink = i40e_ndo_bridge_setlink,
1285312854
.ndo_bpf = i40e_xdp,
1285412855
.ndo_xdp_xmit = i40e_xdp_xmit,
12855-
.ndo_xsk_async_xmit = i40e_xsk_async_xmit,
12856+
.ndo_xsk_wakeup = i40e_xsk_wakeup,
1285612857
.ndo_dfwd_add_station = i40e_fwd_add,
1285712858
.ndo_dfwd_del_station = i40e_fwd_del,
1285812859
};

‎drivers/net/ethernet/intel/i40e/i40e_xsk.c‎

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
116116
return err;
117117

118118
/* Kick start the NAPI context so that receiving will start */
119-
err = i40e_xsk_async_xmit(vsi->netdev, qid);
119+
err = i40e_xsk_wakeup(vsi->netdev, qid, XDP_WAKEUP_RX);
120120
if (err)
121121
return err;
122122
}
@@ -190,7 +190,9 @@ int i40e_xsk_umem_setup(struct i40e_vsi *vsi, struct xdp_umem *umem,
190190
**/
191191
static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp)
192192
{
193+
struct xdp_umem *umem = rx_ring->xsk_umem;
193194
int err, result = I40E_XDP_PASS;
195+
u64 offset = umem->headroom;
194196
struct i40e_ring *xdp_ring;
195197
struct bpf_prog *xdp_prog;
196198
u32 act;
@@ -201,7 +203,10 @@ static int i40e_run_xdp_zc(struct i40e_ring *rx_ring, struct xdp_buff *xdp)
201203
*/
202204
xdp_prog = READ_ONCE(rx_ring->xdp_prog);
203205
act = bpf_prog_run_xdp(xdp_prog, xdp);
204-
xdp->handle += xdp->data - xdp->data_hard_start;
206+
offset += xdp->data - xdp->data_hard_start;
207+
208+
xdp->handle = xsk_umem_adjust_offset(umem, xdp->handle, offset);
209+
205210
switch (act) {
206211
case XDP_PASS:
207212
break;
@@ -262,7 +267,7 @@ static bool i40e_alloc_buffer_zc(struct i40e_ring *rx_ring,
262267
bi->addr = xdp_umem_get_data(umem, handle);
263268
bi->addr += hr;
264269

265-
bi->handle = handle + umem->headroom;
270+
bi->handle = xsk_umem_adjust_offset(umem, handle, umem->headroom);
266271

267272
xsk_umem_discard_addr(umem);
268273
return true;
@@ -299,7 +304,7 @@ static bool i40e_alloc_buffer_slow_zc(struct i40e_ring *rx_ring,
299304
bi->addr = xdp_umem_get_data(umem, handle);
300305
bi->addr += hr;
301306

302-
bi->handle = handle + umem->headroom;
307+
bi->handle = xsk_umem_adjust_offset(umem, handle, umem->headroom);
303308

304309
xsk_umem_discard_addr_rq(umem);
305310
return true;
@@ -420,23 +425,16 @@ static void i40e_reuse_rx_buffer_zc(struct i40e_ring *rx_ring,
420425
struct i40e_rx_buffer *old_bi)
421426
{
422427
struct i40e_rx_buffer *new_bi = &rx_ring->rx_bi[rx_ring->next_to_alloc];
423-
unsigned long mask = (unsigned long)rx_ring->xsk_umem->chunk_mask;
424-
u64 hr = rx_ring->xsk_umem->headroom + XDP_PACKET_HEADROOM;
425428
u16 nta = rx_ring->next_to_alloc;
426429

427430
/* update, and store next to alloc */
428431
nta++;
429432
rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
430433

431434
/* transfer page from old buffer to new buffer */
432-
new_bi->dma = old_bi->dma & mask;
433-
new_bi->dma += hr;
434-
435-
new_bi->addr = (void *)((unsigned long)old_bi->addr & mask);
436-
new_bi->addr += hr;
437-
438-
new_bi->handle = old_bi->handle & mask;
439-
new_bi->handle += rx_ring->xsk_umem->headroom;
435+
new_bi->dma = old_bi->dma;
436+
new_bi->addr = old_bi->addr;
437+
new_bi->handle = old_bi->handle;
440438

441439
old_bi->addr = NULL;
442440
}
@@ -471,7 +469,8 @@ void i40e_zca_free(struct zero_copy_allocator *alloc, unsigned long handle)
471469
bi->addr = xdp_umem_get_data(rx_ring->xsk_umem, handle);
472470
bi->addr += hr;
473471

474-
bi->handle = (u64)handle + rx_ring->xsk_umem->headroom;
472+
bi->handle = xsk_umem_adjust_offset(rx_ring->xsk_umem, (u64)handle,
473+
rx_ring->xsk_umem->headroom);
475474
}
476475

477476
/**
@@ -626,6 +625,15 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)
626625

627626
i40e_finalize_xdp_rx(rx_ring, xdp_xmit);
628627
i40e_update_rx_stats(rx_ring, total_rx_bytes, total_rx_packets);
628+
629+
if (xsk_umem_uses_need_wakeup(rx_ring->xsk_umem)) {
630+
if (failure || rx_ring->next_to_clean == rx_ring->next_to_use)
631+
xsk_set_rx_need_wakeup(rx_ring->xsk_umem);
632+
else
633+
xsk_clear_rx_need_wakeup(rx_ring->xsk_umem);
634+
635+
return (int)total_rx_packets;
636+
}
629637
return failure ? budget : (int)total_rx_packets;
630638
}
631639

@@ -681,6 +689,8 @@ static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget)
681689
i40e_xdp_ring_update_tail(xdp_ring);
682690

683691
xsk_umem_consume_tx_done(xdp_ring->xsk_umem);
692+
if (xsk_umem_uses_need_wakeup(xdp_ring->xsk_umem))
693+
xsk_clear_tx_need_wakeup(xdp_ring->xsk_umem);
684694
}
685695

686696
return !!budget && work_done;
@@ -759,19 +769,27 @@ bool i40e_clean_xdp_tx_irq(struct i40e_vsi *vsi,
759769
i40e_update_tx_stats(tx_ring, completed_frames, total_bytes);
760770

761771
out_xmit:
772+
if (xsk_umem_uses_need_wakeup(tx_ring->xsk_umem)) {
773+
if (tx_ring->next_to_clean == tx_ring->next_to_use)
774+
xsk_set_tx_need_wakeup(tx_ring->xsk_umem);
775+
else
776+
xsk_clear_tx_need_wakeup(tx_ring->xsk_umem);
777+
}
778+
762779
xmit_done = i40e_xmit_zc(tx_ring, budget);
763780

764781
return work_done && xmit_done;
765782
}
766783

767784
/**
768-
* i40e_xsk_async_xmit - Implements the ndo_xsk_async_xmit
785+
* i40e_xsk_wakeup - Implements the ndo_xsk_wakeup
769786
* @dev: the netdevice
770787
* @queue_id: queue id to wake up
788+
* @flags: ignored in our case since we have Rx and Tx in the same NAPI.
771789
*
772790
* Returns <0 for errors, 0 otherwise.
773791
**/
774-
int i40e_xsk_async_xmit(struct net_device *dev, u32 queue_id)
792+
int i40e_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags)
775793
{
776794
struct i40e_netdev_priv *np = netdev_priv(dev);
777795
struct i40e_vsi *vsi = np->vsi;

‎drivers/net/ethernet/intel/i40e/i40e_xsk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget);
1818

1919
bool i40e_clean_xdp_tx_irq(struct i40e_vsi *vsi,
2020
struct i40e_ring *tx_ring, int napi_budget);
21-
int i40e_xsk_async_xmit(struct net_device *dev, u32 queue_id);
21+
int i40e_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags);
2222

2323
#endif /* _I40E_XSK_H_ */

‎drivers/net/ethernet/intel/ixgbe/ixgbe_main.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10260,7 +10260,8 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
1026010260
if (need_reset && prog)
1026110261
for (i = 0; i < adapter->num_rx_queues; i++)
1026210262
if (adapter->xdp_ring[i]->xsk_umem)
10263-
(void)ixgbe_xsk_async_xmit(adapter->netdev, i);
10263+
(void)ixgbe_xsk_wakeup(adapter->netdev, i,
10264+
XDP_WAKEUP_RX);
1026410265

1026510266
return 0;
1026610267
}
@@ -10379,7 +10380,7 @@ static const struct net_device_ops ixgbe_netdev_ops = {
1037910380
.ndo_features_check = ixgbe_features_check,
1038010381
.ndo_bpf = ixgbe_xdp,
1038110382
.ndo_xdp_xmit = ixgbe_xdp_xmit,
10382-
.ndo_xsk_async_xmit = ixgbe_xsk_async_xmit,
10383+
.ndo_xsk_wakeup = ixgbe_xsk_wakeup,
1038310384
};
1038410385

1038510386
static void ixgbe_disable_txr_hw(struct ixgbe_adapter *adapter,

‎drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int ixgbe_clean_rx_irq_zc(struct ixgbe_q_vector *q_vector,
4242
void ixgbe_xsk_clean_rx_ring(struct ixgbe_ring *rx_ring);
4343
bool ixgbe_clean_xdp_tx_irq(struct ixgbe_q_vector *q_vector,
4444
struct ixgbe_ring *tx_ring, int napi_budget);
45-
int ixgbe_xsk_async_xmit(struct net_device *dev, u32 queue_id);
45+
int ixgbe_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags);
4646
void ixgbe_xsk_clean_tx_ring(struct ixgbe_ring *tx_ring);
4747

4848
#endif /* #define _IXGBE_TXRX_COMMON_H_ */

0 commit comments

Comments
 (0)