]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/xsk: fix too-many-frags multi-buffer Tx test
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Sun, 19 Jul 2026 13:56:08 +0000 (15:56 +0200)
committerJakub Kicinski <kuba@kernel.org>
Fri, 24 Jul 2026 22:12:14 +0000 (15:12 -0700)
The too-many-frags test describes a packet that is valid from the Tx
ring ownership point of view, but invalid for transmission because it
exceeds the supported number of fragments.

Keep the generated Tx descriptors valid so that __send_pkts() accounts
them as outstanding descriptors that must be reclaimed through the CQ.
Then mark the corresponding Rx packet invalid so the test still does
not expect the oversized packet to appear on the receive side.

Add a valid synchronization packet after the oversized packet so the
test can verify that the Tx path drains the bad packet and resumes at
the next packet boundary.

Reviewed-by: Jason Xing <kernelxing@tencent.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20260719135609.147823-6-maciej.fijalkowski@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/bpf/prog_tests/test_xsk.c

index 6eb9096d084c018d46dabb5554381322288d4220..de17dd48f176489bf9c30242d07f4681cd010089 100644 (file)
@@ -2270,7 +2270,7 @@ int testapp_too_many_frags(struct test_spec *test)
                max_frags += 1;
        }
 
-       pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
+       pkts = calloc(2 * max_frags + 3, sizeof(struct pkt));
        if (!pkts)
                return TEST_FAILURE;
 
@@ -2288,24 +2288,30 @@ int testapp_too_many_frags(struct test_spec *test)
        }
        pkts[max_frags].options = 0;
 
-       /* An invalid packet with the max amount of frags but signals packet
-        * continues on the last frag
-        */
-       for (i = max_frags + 1; i < 2 * max_frags + 1; i++) {
+       /* An invalid packet with the max + 1 amount of frags */
+       for (i = max_frags + 1; i < 2 * max_frags + 2; i++) {
                pkts[i].len = MIN_PKT_SIZE;
                pkts[i].options = XDP_PKT_CONTD;
-               pkts[i].valid = false;
+               pkts[i].valid = true;
        }
+       pkts[2 * max_frags + 1].options = 0;
 
        /* Valid packet for synch */
-       pkts[2 * max_frags + 1].len = MIN_PKT_SIZE;
-       pkts[2 * max_frags + 1].valid = true;
+       pkts[2 * max_frags + 2].len = MIN_PKT_SIZE;
+       pkts[2 * max_frags + 2].valid = true;
 
-       if (pkt_stream_generate_custom(test, pkts, 2 * max_frags + 2)) {
+       if (pkt_stream_generate_custom(test, pkts, 2 * max_frags + 3)) {
                free(pkts);
                return TEST_FAILURE;
        }
 
+       /* The generated Tx stream must keep the too-big packet valid so that
+        * __send_pkts() accounts its descriptors in outstanding_tx. The Rx
+        * stream, however, must not expect this packet on the wire.
+        */
+       test->ifobj_rx->xsk->pkt_stream->pkts[2].valid = false;
+       test->ifobj_rx->xsk->pkt_stream->nb_valid_entries--;
+
        ret = testapp_validate_traffic(test);
        free(pkts);
        return ret;