Skip to content

Commit 8367eb9

Browse files
tvyavahaborkmann
authored andcommitted
selftests/xsk: Move pkt_stream to the xsk_socket_info
Move the packet stream from the ifobject struct to the xsk_socket_info struct to enable the use of different streams for different sockets. This will facilitate the sending and receiving of data from multiple sockets simultaneously using the SHARED_XDP_UMEM feature. Signed-off-by: Tushar Vyavahare <tushar.vyavahare@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com> Link: https://lore.kernel.org/bpf/20230927135241.2287547-2-tushar.vyavahare@intel.com
1 parent 2147c8d commit 8367eb9

2 files changed

Lines changed: 38 additions & 35 deletions

File tree

tools/testing/selftests/bpf/xskxceiver.c

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static int __xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_i
260260
cfg.bind_flags = ifobject->bind_flags;
261261
if (shared)
262262
cfg.bind_flags |= XDP_SHARED_UMEM;
263-
if (ifobject->pkt_stream && ifobject->mtu > MAX_ETH_PKT_SIZE)
263+
if (ifobject->mtu > MAX_ETH_PKT_SIZE)
264264
cfg.bind_flags |= XDP_USE_SG;
265265

266266
txr = ifobject->tx_on ? &xsk->tx : NULL;
@@ -429,11 +429,9 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
429429
if (i == 0) {
430430
ifobj->rx_on = false;
431431
ifobj->tx_on = true;
432-
ifobj->pkt_stream = test->tx_pkt_stream_default;
433432
} else {
434433
ifobj->rx_on = true;
435434
ifobj->tx_on = false;
436-
ifobj->pkt_stream = test->rx_pkt_stream_default;
437435
}
438436

439437
memset(ifobj->umem, 0, sizeof(*ifobj->umem));
@@ -443,6 +441,10 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
443441
for (j = 0; j < MAX_SOCKETS; j++) {
444442
memset(&ifobj->xsk_arr[j], 0, sizeof(ifobj->xsk_arr[j]));
445443
ifobj->xsk_arr[j].rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
444+
if (i == 0)
445+
ifobj->xsk_arr[j].pkt_stream = test->tx_pkt_stream_default;
446+
else
447+
ifobj->xsk_arr[j].pkt_stream = test->rx_pkt_stream_default;
446448
}
447449
}
448450

@@ -557,17 +559,17 @@ static void pkt_stream_delete(struct pkt_stream *pkt_stream)
557559

558560
static void pkt_stream_restore_default(struct test_spec *test)
559561
{
560-
struct pkt_stream *tx_pkt_stream = test->ifobj_tx->pkt_stream;
561-
struct pkt_stream *rx_pkt_stream = test->ifobj_rx->pkt_stream;
562+
struct pkt_stream *tx_pkt_stream = test->ifobj_tx->xsk->pkt_stream;
563+
struct pkt_stream *rx_pkt_stream = test->ifobj_rx->xsk->pkt_stream;
562564

563565
if (tx_pkt_stream != test->tx_pkt_stream_default) {
564-
pkt_stream_delete(test->ifobj_tx->pkt_stream);
565-
test->ifobj_tx->pkt_stream = test->tx_pkt_stream_default;
566+
pkt_stream_delete(test->ifobj_tx->xsk->pkt_stream);
567+
test->ifobj_tx->xsk->pkt_stream = test->tx_pkt_stream_default;
566568
}
567569

568570
if (rx_pkt_stream != test->rx_pkt_stream_default) {
569-
pkt_stream_delete(test->ifobj_rx->pkt_stream);
570-
test->ifobj_rx->pkt_stream = test->rx_pkt_stream_default;
571+
pkt_stream_delete(test->ifobj_rx->xsk->pkt_stream);
572+
test->ifobj_rx->xsk->pkt_stream = test->rx_pkt_stream_default;
571573
}
572574
}
573575

@@ -674,9 +676,9 @@ static void pkt_stream_replace(struct test_spec *test, u32 nb_pkts, u32 pkt_len)
674676
struct pkt_stream *pkt_stream;
675677

676678
pkt_stream = pkt_stream_generate(test->ifobj_tx->umem, nb_pkts, pkt_len);
677-
test->ifobj_tx->pkt_stream = pkt_stream;
679+
test->ifobj_tx->xsk->pkt_stream = pkt_stream;
678680
pkt_stream = pkt_stream_generate(test->ifobj_rx->umem, nb_pkts, pkt_len);
679-
test->ifobj_rx->pkt_stream = pkt_stream;
681+
test->ifobj_rx->xsk->pkt_stream = pkt_stream;
680682
}
681683

682684
static void __pkt_stream_replace_half(struct ifobject *ifobj, u32 pkt_len,
@@ -686,11 +688,11 @@ static void __pkt_stream_replace_half(struct ifobject *ifobj, u32 pkt_len,
686688
struct pkt_stream *pkt_stream;
687689
u32 i;
688690

689-
pkt_stream = pkt_stream_clone(umem, ifobj->pkt_stream);
690-
for (i = 1; i < ifobj->pkt_stream->nb_pkts; i += 2)
691+
pkt_stream = pkt_stream_clone(umem, ifobj->xsk->pkt_stream);
692+
for (i = 1; i < ifobj->xsk->pkt_stream->nb_pkts; i += 2)
691693
pkt_set(umem, &pkt_stream->pkts[i], offset, pkt_len);
692694

693-
ifobj->pkt_stream = pkt_stream;
695+
ifobj->xsk->pkt_stream = pkt_stream;
694696
}
695697

696698
static void pkt_stream_replace_half(struct test_spec *test, u32 pkt_len, int offset)
@@ -702,12 +704,12 @@ static void pkt_stream_replace_half(struct test_spec *test, u32 pkt_len, int off
702704
static void pkt_stream_receive_half(struct test_spec *test)
703705
{
704706
struct xsk_umem_info *umem = test->ifobj_rx->umem;
705-
struct pkt_stream *pkt_stream = test->ifobj_tx->pkt_stream;
707+
struct pkt_stream *pkt_stream = test->ifobj_tx->xsk->pkt_stream;
706708
u32 i;
707709

708-
test->ifobj_rx->pkt_stream = pkt_stream_generate(umem, pkt_stream->nb_pkts,
709-
pkt_stream->pkts[0].len);
710-
pkt_stream = test->ifobj_rx->pkt_stream;
710+
test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(umem, pkt_stream->nb_pkts,
711+
pkt_stream->pkts[0].len);
712+
pkt_stream = test->ifobj_rx->xsk->pkt_stream;
711713
for (i = 1; i < pkt_stream->nb_pkts; i += 2)
712714
pkt_stream->pkts[i].valid = false;
713715
}
@@ -796,10 +798,10 @@ static void pkt_stream_generate_custom(struct test_spec *test, struct pkt *pkts,
796798
struct pkt_stream *pkt_stream;
797799

798800
pkt_stream = __pkt_stream_generate_custom(test->ifobj_tx, pkts, nb_pkts, true);
799-
test->ifobj_tx->pkt_stream = pkt_stream;
801+
test->ifobj_tx->xsk->pkt_stream = pkt_stream;
800802

801803
pkt_stream = __pkt_stream_generate_custom(test->ifobj_rx, pkts, nb_pkts, false);
802-
test->ifobj_rx->pkt_stream = pkt_stream;
804+
test->ifobj_rx->xsk->pkt_stream = pkt_stream;
803805
}
804806

805807
static void pkt_print_data(u32 *data, u32 cnt)
@@ -1007,7 +1009,7 @@ static int complete_pkts(struct xsk_socket_info *xsk, int batch_size)
10071009
static int receive_pkts(struct test_spec *test, struct pollfd *fds)
10081010
{
10091011
struct timeval tv_end, tv_now, tv_timeout = {THREAD_TMOUT, 0};
1010-
struct pkt_stream *pkt_stream = test->ifobj_rx->pkt_stream;
1012+
struct pkt_stream *pkt_stream = test->ifobj_rx->xsk->pkt_stream;
10111013
struct xsk_socket_info *xsk = test->ifobj_rx->xsk;
10121014
u32 idx_rx = 0, idx_fq = 0, rcvd, pkts_sent = 0;
10131015
struct ifobject *ifobj = test->ifobj_rx;
@@ -1139,7 +1141,7 @@ static int receive_pkts(struct test_spec *test, struct pollfd *fds)
11391141
static int __send_pkts(struct ifobject *ifobject, struct pollfd *fds, bool timeout)
11401142
{
11411143
u32 i, idx = 0, valid_pkts = 0, valid_frags = 0, buffer_len;
1142-
struct pkt_stream *pkt_stream = ifobject->pkt_stream;
1144+
struct pkt_stream *pkt_stream = ifobject->xsk->pkt_stream;
11431145
struct xsk_socket_info *xsk = ifobject->xsk;
11441146
struct xsk_umem_info *umem = ifobject->umem;
11451147
bool use_poll = ifobject->use_poll;
@@ -1283,7 +1285,7 @@ static int wait_for_tx_completion(struct xsk_socket_info *xsk)
12831285

12841286
static int send_pkts(struct test_spec *test, struct ifobject *ifobject)
12851287
{
1286-
struct pkt_stream *pkt_stream = ifobject->pkt_stream;
1288+
struct pkt_stream *pkt_stream = ifobject->xsk->pkt_stream;
12871289
bool timeout = !is_umem_valid(test->ifobj_rx);
12881290
struct pollfd fds = { };
12891291
u32 ret;
@@ -1347,8 +1349,8 @@ static int validate_rx_dropped(struct ifobject *ifobject)
13471349
* packet being invalid). Since the last packet may or may not have
13481350
* been dropped already, both outcomes must be allowed.
13491351
*/
1350-
if (stats.rx_dropped == ifobject->pkt_stream->nb_pkts / 2 ||
1351-
stats.rx_dropped == ifobject->pkt_stream->nb_pkts / 2 - 1)
1352+
if (stats.rx_dropped == ifobject->xsk->pkt_stream->nb_pkts / 2 ||
1353+
stats.rx_dropped == ifobject->xsk->pkt_stream->nb_pkts / 2 - 1)
13521354
return TEST_PASS;
13531355

13541356
return TEST_FAILURE;
@@ -1412,9 +1414,10 @@ static int validate_tx_invalid_descs(struct ifobject *ifobject)
14121414
return TEST_FAILURE;
14131415
}
14141416

1415-
if (stats.tx_invalid_descs != ifobject->pkt_stream->nb_pkts / 2) {
1417+
if (stats.tx_invalid_descs != ifobject->xsk->pkt_stream->nb_pkts / 2) {
14161418
ksft_print_msg("[%s] tx_invalid_descs incorrect. Got [%u] expected [%u]\n",
1417-
__func__, stats.tx_invalid_descs, ifobject->pkt_stream->nb_pkts);
1419+
__func__, stats.tx_invalid_descs,
1420+
ifobject->xsk->pkt_stream->nb_pkts);
14181421
return TEST_FAILURE;
14191422
}
14201423

@@ -1528,7 +1531,7 @@ static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject)
15281531
if (!ifobject->rx_on)
15291532
return;
15301533

1531-
xsk_populate_fill_ring(ifobject->umem, ifobject->pkt_stream, ifobject->use_fill_ring);
1534+
xsk_populate_fill_ring(ifobject->umem, ifobject->xsk->pkt_stream, ifobject->use_fill_ring);
15321535

15331536
ret = xsk_update_xskmap(ifobject->xskmap, ifobject->xsk->xsk);
15341537
if (ret)
@@ -1691,11 +1694,11 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i
16911694
if (ifobj2) {
16921695
if (pthread_barrier_init(&barr, NULL, 2))
16931696
exit_with_error(errno);
1694-
pkt_stream_reset(ifobj2->pkt_stream);
1697+
pkt_stream_reset(ifobj2->xsk->pkt_stream);
16951698
}
16961699

16971700
test->current_step++;
1698-
pkt_stream_reset(ifobj1->pkt_stream);
1701+
pkt_stream_reset(ifobj1->xsk->pkt_stream);
16991702
pkts_in_flight = 0;
17001703

17011704
signal(SIGUSR1, handler);
@@ -1852,8 +1855,8 @@ static int testapp_stats_tx_invalid_descs(struct test_spec *test)
18521855
static int testapp_stats_rx_full(struct test_spec *test)
18531856
{
18541857
pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
1855-
test->ifobj_rx->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem,
1856-
DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
1858+
test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem,
1859+
DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
18571860

18581861
test->ifobj_rx->xsk->rxqsize = DEFAULT_UMEM_BUFFERS;
18591862
test->ifobj_rx->release_rx = false;
@@ -1864,8 +1867,8 @@ static int testapp_stats_rx_full(struct test_spec *test)
18641867
static int testapp_stats_fill_empty(struct test_spec *test)
18651868
{
18661869
pkt_stream_replace(test, DEFAULT_UMEM_BUFFERS + DEFAULT_UMEM_BUFFERS / 2, MIN_PKT_SIZE);
1867-
test->ifobj_rx->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem,
1868-
DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
1870+
test->ifobj_rx->xsk->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem,
1871+
DEFAULT_UMEM_BUFFERS, MIN_PKT_SIZE);
18691872

18701873
test->ifobj_rx->use_fill_ring = false;
18711874
test->ifobj_rx->validation_func = validate_fill_empty;

tools/testing/selftests/bpf/xskxceiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct xsk_socket_info {
8787
struct xsk_ring_prod tx;
8888
struct xsk_umem_info *umem;
8989
struct xsk_socket *xsk;
90+
struct pkt_stream *pkt_stream;
9091
u32 outstanding_tx;
9192
u32 rxqsize;
9293
};
@@ -120,7 +121,6 @@ struct ifobject {
120121
struct xsk_umem_info *umem;
121122
thread_func_t func_ptr;
122123
validation_func_t validation_func;
123-
struct pkt_stream *pkt_stream;
124124
struct xsk_xdp_progs *xdp_progs;
125125
struct bpf_map *xskmap;
126126
struct bpf_program *xdp_prog;

0 commit comments

Comments
 (0)