From patchwork Wed Sep 1 10:47:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B430CC432BE for ; Wed, 1 Sep 2021 10:48:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B47561053 for ; Wed, 1 Sep 2021 10:48:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237483AbhIAKtA (ORCPT ); Wed, 1 Sep 2021 06:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235980AbhIAKs6 (ORCPT ); Wed, 1 Sep 2021 06:48:58 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93738C061575; Wed, 1 Sep 2021 03:48:01 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id i3so1525732wmq.3; Wed, 01 Sep 2021 03:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P+ZLmHK8o50h7H6ArsMpxYYv/GLFJ6igApJFpx/tb64=; b=ggfr1e8usHkjR+62Bm3lYwucrC/klMDW4+K4XvGDb5pc5PzkfvAL3W+ezD+rqVVo7V E6n49l7qGhx8aDdLZtaON88FR8b9HotOBZu1og+YzudtCxoN9z4Cvu/On4NEMwNRGCvx pwpc3xfaC9mfqYnJAtg7LRsU2vqa52iV/xR/AlHHT8oSRYqX+XC7bYb6zQ8thi0qiLyX /+ofRV+1sL7x3AQiW44olGwCRqhm0H+pp+WAclViXAaZ27b8HPe0HRyyk/mwSV4LaCk6 XN+1BsEoAgB0zZTRxVA0ooJU1/67qyc9GcqvO1VU3BmSuIWyBtu8m9a9or/Rv8hwZYLf EtZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P+ZLmHK8o50h7H6ArsMpxYYv/GLFJ6igApJFpx/tb64=; b=jxS0HHqNQ4IpCgpgzyNKVlEtAIBc/S0poXNwJEDMes1b9H2+8g1Ic0Y/DmfTk3SoRy Dmjy22lBXdlOTi04nP59h5gODc3jvZTbxupZtT17DsaelD8kgT1iQDFl1jhs4VNoUTJ+ ja+vpQbQMNHG5pza9QJQnaNoBLqOI3Xha2EM5t2GITTC7px9+LFyYfxf6++LlLtfiZid KYUKHWczs85ekBNUFowqs515T+OhS37VuP3qhdN5fi85B8EMlkuA+ChIeI36HYn3qq6B c12+FEAuzeuHGy00w8RmmmlvIY4aZ3L2mCxNWHA5J8AMtm0kXUieDOdsrj6FZUHSUYIU Rx/Q== X-Gm-Message-State: AOAM530FOVBy7B7a82j5jE1P5XplcFcOMAlJLmnCpDjPaWGP5N2Ttr3P /Rxr+ZZXGOTfqosQpnU8ZPc= X-Google-Smtp-Source: ABdhPJwjvmIh7uzYYD5KA5JD+GBcZttOdqaF71MnS4FW3Vg9lKDEQebNRhc/a2Jbz+IbohhUp0JGXQ== X-Received: by 2002:a1c:4682:: with SMTP id t124mr9164350wma.168.1630493280208; Wed, 01 Sep 2021 03:48:00 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.47.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:47:59 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 01/20] selftests: xsk: simplify xsk and umem arrays Date: Wed, 1 Sep 2021 12:47:13 +0200 Message-Id: <20210901104732.10956-2-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Simplify the xsk_info and umem_info allocation by allocating them upfront in an array, instead of allocating an array of pointers to future creations of these. Allocating them upfront also has the advantage that configuration information can be stored in these structures instead of relying on global variables. With the previous structure, xsk_info and umem_info were created too late to be able to store most configuration information. This will be used to eliminate most global variables in later patches in this series. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend --- tools/testing/selftests/bpf/xdpxceiver.c | 78 ++++++++++-------------- tools/testing/selftests/bpf/xdpxceiver.h | 5 +- 2 files changed, 34 insertions(+), 49 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index f53ce2683f8d..9639d8da516d 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -235,7 +235,7 @@ static void gen_udp_csum(struct udphdr *udp_hdr, struct iphdr *ip_hdr) udp_csum(ip_hdr->saddr, ip_hdr->daddr, UDP_PKT_SIZE, IPPROTO_UDP, (u16 *)udp_hdr); } -static void xsk_configure_umem(struct ifobject *data, void *buffer, u64 size, int idx) +static int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size, int idx) { struct xsk_umem_config cfg = { .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, @@ -244,21 +244,15 @@ static void xsk_configure_umem(struct ifobject *data, void *buffer, u64 size, in .frame_headroom = frame_headroom, .flags = XSK_UMEM__DEFAULT_FLAGS }; - struct xsk_umem_info *umem; int ret; - umem = calloc(1, sizeof(struct xsk_umem_info)); - if (!umem) - exit_with_error(errno); - ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq, &cfg); if (ret) - exit_with_error(-ret); + return ret; umem->buffer = buffer; - - data->umem_arr[idx] = umem; + return 0; } static void xsk_populate_fill_ring(struct xsk_umem_info *umem) @@ -274,19 +268,14 @@ static void xsk_populate_fill_ring(struct xsk_umem_info *umem) xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS); } -static int xsk_configure_socket(struct ifobject *ifobject, int idx) +static int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem, + struct ifobject *ifobject, u32 qid) { struct xsk_socket_config cfg; - struct xsk_socket_info *xsk; struct xsk_ring_cons *rxr; struct xsk_ring_prod *txr; - int ret; - xsk = calloc(1, sizeof(struct xsk_socket_info)); - if (!xsk) - exit_with_error(errno); - - xsk->umem = ifobject->umem; + xsk->umem = umem; cfg.rx_size = rxqsize; cfg.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS; cfg.libbpf_flags = 0; @@ -301,14 +290,7 @@ static int xsk_configure_socket(struct ifobject *ifobject, int idx) txr = &xsk->tx; } - ret = xsk_socket__create(&xsk->xsk, ifobject->ifname, idx, - ifobject->umem->umem, rxr, txr, &cfg); - if (ret) - return 1; - - ifobject->xsk_arr[idx] = xsk; - - return 0; + return xsk_socket__create(&xsk->xsk, ifobject->ifname, qid, umem->umem, rxr, txr, &cfg); } static struct option long_options[] = { @@ -756,8 +738,7 @@ static void thread_common_ops(struct ifobject *ifobject, void *bufs) u64 umem_sz = num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; size_t mmap_sz = umem_sz; - int ctr = 0; - int ret; + int ctr = 0, ret; ifobject->ns_fd = switch_namespace(ifobject->nsname); @@ -769,31 +750,34 @@ static void thread_common_ops(struct ifobject *ifobject, void *bufs) exit_with_error(errno); while (ctr++ < SOCK_RECONF_CTR) { - xsk_configure_umem(ifobject, bufs, umem_sz, 0); - ifobject->umem = ifobject->umem_arr[0]; - ret = xsk_configure_socket(ifobject, 0); + ret = xsk_configure_umem(&ifobject->umem_arr[0], bufs, umem_sz, 0); + if (ret) + exit_with_error(-ret); + + ret = xsk_configure_socket(&ifobject->xsk_arr[0], &ifobject->umem_arr[0], + ifobject, 0); if (!ret) break; /* Retry Create Socket if it fails as xsk_socket__create() is asynchronous */ - usleep(USLEEP_MAX); if (ctr >= SOCK_RECONF_CTR) exit_with_error(-ret); + usleep(USLEEP_MAX); } - ifobject->umem = ifobject->umem_arr[0]; - ifobject->xsk = ifobject->xsk_arr[0]; - if (test_type == TEST_TYPE_BPF_RES) { - xsk_configure_umem(ifobject, (u8 *)bufs + umem_sz, umem_sz, 1); - ifobject->umem = ifobject->umem_arr[1]; - ret = xsk_configure_socket(ifobject, 1); + ret = xsk_configure_umem(&ifobject->umem_arr[1], (u8 *)bufs + umem_sz, umem_sz, 1); + if (ret) + exit_with_error(-ret); + + ret = xsk_configure_socket(&ifobject->xsk_arr[1], &ifobject->umem_arr[1], + ifobject, 1); + if (ret) + exit_with_error(-ret); } - ifobject->umem = ifobject->umem_arr[0]; - ifobject->xsk = ifobject->xsk_arr[0]; - print_verbose("Interface [%s] vector [%s]\n", - ifobject->ifname, ifobject->fv.vector == tx ? "Tx" : "Rx"); + ifobject->umem = &ifobject->umem_arr[0]; + ifobject->xsk = &ifobject->xsk_arr[0]; } static bool testapp_is_test_two_stepped(void) @@ -941,10 +925,10 @@ static void swap_xsk_res(void) xsk_umem__delete(ifdict_tx->umem->umem); xsk_socket__delete(ifdict_rx->xsk->xsk); xsk_umem__delete(ifdict_rx->umem->umem); - ifdict_tx->umem = ifdict_tx->umem_arr[1]; - ifdict_tx->xsk = ifdict_tx->xsk_arr[1]; - ifdict_rx->umem = ifdict_rx->umem_arr[1]; - ifdict_rx->xsk = ifdict_rx->xsk_arr[1]; + ifdict_tx->umem = &ifdict_tx->umem_arr[1]; + ifdict_tx->xsk = &ifdict_tx->xsk_arr[1]; + ifdict_rx->umem = &ifdict_rx->umem_arr[1]; + ifdict_rx->xsk = &ifdict_rx->xsk_arr[1]; } static void testapp_bpf_res(void) @@ -1071,11 +1055,11 @@ static struct ifobject *ifobject_create(void) if (!ifobj) return NULL; - ifobj->xsk_arr = calloc(2, sizeof(struct xsk_socket_info *)); + ifobj->xsk_arr = calloc(MAX_SOCKETS, sizeof(*ifobj->xsk_arr)); if (!ifobj->xsk_arr) goto out_xsk_arr; - ifobj->umem_arr = calloc(2, sizeof(struct xsk_umem_info *)); + ifobj->umem_arr = calloc(MAX_SOCKETS, sizeof(*ifobj->umem_arr)); if (!ifobj->umem_arr) goto out_umem_arr; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 7e49b9fbe25e..de80516ac6c2 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -21,6 +21,7 @@ #define MAX_INTERFACE_NAME_CHARS 7 #define MAX_INTERFACES_NAMESPACE_CHARS 10 #define MAX_SOCKS 1 +#define MAX_SOCKETS 2 #define MAX_TEARDOWN_ITER 10 #define MAX_BIDI_ITER 2 #define MAX_BPF_ITER 2 @@ -119,9 +120,9 @@ struct ifobject { char ifname[MAX_INTERFACE_NAME_CHARS]; char nsname[MAX_INTERFACES_NAMESPACE_CHARS]; struct xsk_socket_info *xsk; - struct xsk_socket_info **xsk_arr; - struct xsk_umem_info **umem_arr; + struct xsk_socket_info *xsk_arr; struct xsk_umem_info *umem; + struct xsk_umem_info *umem_arr; void *(*func_ptr)(void *arg); struct flow_vector fv; struct pkt_stream *pkt_stream; From patchwork Wed Sep 1 10:47:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6DB8C4320A for ; Wed, 1 Sep 2021 10:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D2696101B for ; Wed, 1 Sep 2021 10:48:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238453AbhIAKtM (ORCPT ); Wed, 1 Sep 2021 06:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238369AbhIAKtC (ORCPT ); Wed, 1 Sep 2021 06:49:02 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7E6DC061575; Wed, 1 Sep 2021 03:48:04 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id t15so3776100wrg.7; Wed, 01 Sep 2021 03:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IYnkjvotk/MpzM9rkR18s0IoSoRw+1ELJDU4lKnmO2E=; b=GFPr3eY7fzj58L81k6+CnvMxMGR2M2tJ/4dxV7StXRThGXfj1488pL9UAjrQvIZxdJ 432j13GOFmXuPAxzd/wmWF67oUgBgd2i6J08QyWWsQKgnNef6c1yuqS/mg631XTq4sPe 0uvsOW36yTMELIqTQoe9sTKdtxZdqmkqn5PdS/FGPwokGkPbkkOAISVFj04N+zeSc3N/ jpED7xZlTsyR7uOhy/uLHwOrN7jmwEKM2e1FkfH7yEDbglZC1jPqeXplowxX5BKtvQ3w CDfyHS5LM2G9MUwwtwQG/SebNxmvN2JSUGkU/9OfW1GoPjhEj+pBk56kDHTE23jia7gM MqHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IYnkjvotk/MpzM9rkR18s0IoSoRw+1ELJDU4lKnmO2E=; b=lf9TL2UlwUnypSY31eX/HFLJZ83/S7HxhzCoSdwmR/KeVryGwWkf6ggtM2xUPZsKiN XPQE3+47GNoIbLv5lEfdbFLboSYypxN96KdYVsQ5W/EAPyMhEnwCoP/jsUMSjp3nUVpc qa8J+O5b6cj522oh0V+787DaifuijXEaWCXGjO18HBPTMdvk6zlkB+X5TcKFRpr11PMh I5LDjUamhGlXIW6+O48rw1cBw/miPCE+miWX/fSrh6wJbgkMUmI8FsaSjAiV0Hf0bej1 c4ExEs60BxG3FJfcz16q3WtJFSf6j+dEEAK2iMY0P38SfLqbjLIBj9Hmhp16u/NnJSoW /FNQ== X-Gm-Message-State: AOAM532zoppjUZA0p/nXThP18X/LtB5fsekpnhyFJlWUctLx5TlEzaJl tfYbb2lx+FH/zzOa8STB03c= X-Google-Smtp-Source: ABdhPJzSvD02MU0iXjO/LIKBESUm4QQW79DQ4X9pE/D3ArisjJvlPTJmHBceBrWDjCnJ/zzM+J2/4g== X-Received: by 2002:adf:e0cc:: with SMTP id m12mr38725141wri.62.1630493283226; Wed, 01 Sep 2021 03:48:03 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:02 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 03/20] selftests: xsk: introduce test specifications Date: Wed, 1 Sep 2021 12:47:15 +0200 Message-Id: <20210901104732.10956-4-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Introduce a test specification to be able to concisely describe a test. Currently, a test is implemented by sprinkling test specific if statements here and there, which is not scalable or easy to understand. The end goal with this patch set is to come to the point in which a test is completely specified by a test specification that can easily be constructed in a single function so that new tests can be added without too much trouble. This test specification will be run by a test runner that has no idea about tests. It just executes the what test specification states. This patch introduces the test specification and, as a start, puts the two interface objects in there, one containing the packet stream to be sent and the other one the packet stream that is supposed to be received for a test to pass. The global variables containing these can then be eliminated. The following patches will convert each existing test into a test specification and add the needed fields into it and the functionality in the test runner that act on the test specification. At the end, the test runner should contain no test specific code and each test should be described in a single simple function. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 203 ++++++++++++++--------- tools/testing/selftests/bpf/xdpxceiver.h | 7 +- 2 files changed, 126 insertions(+), 84 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index edf5b6cc6998..a6bcc7453860 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -336,45 +336,43 @@ static int switch_namespace(const char *nsname) return nsfd; } -static int validate_interfaces(void) +static bool validate_interface(struct ifobject *ifobj) { - bool ret = true; - - for (int i = 0; i < MAX_INTERFACES; i++) { - if (!strcmp(ifdict[i]->ifname, "")) { - ret = false; - ksft_test_result_fail("ERROR: interfaces: -i , -i ,."); - } - } - return ret; + if (!strcmp(ifobj->ifname, "")) + return false; + return true; } -static void parse_command_line(int argc, char **argv) +static void parse_command_line(struct test_spec *test, int argc, char **argv) { - int option_index, interface_index = 0, c; + struct ifobject *ifobj; + u32 interface_nb = 0; + int option_index, c; opterr = 0; for (;;) { - c = getopt_long(argc, argv, "i:Dv", long_options, &option_index); + char *sptr, *token; + c = getopt_long(argc, argv, "i:Dv", long_options, &option_index); if (c == -1) break; switch (c) { case 'i': - if (interface_index == MAX_INTERFACES) + if (interface_nb == 0) + ifobj = test->ifobj_tx; + else if (interface_nb == 1) + ifobj = test->ifobj_rx; + else break; - char *sptr, *token; sptr = strndupa(optarg, strlen(optarg)); - memcpy(ifdict[interface_index]->ifname, - strsep(&sptr, ","), MAX_INTERFACE_NAME_CHARS); + memcpy(ifobj->ifname, strsep(&sptr, ","), MAX_INTERFACE_NAME_CHARS); token = strsep(&sptr, ","); if (token) - memcpy(ifdict[interface_index]->nsname, token, - MAX_INTERFACES_NAMESPACE_CHARS); - interface_index++; + memcpy(ifobj->nsname, token, MAX_INTERFACES_NAMESPACE_CHARS); + interface_nb++; break; case 'D': opt_pkt_dump = true; @@ -387,11 +385,44 @@ static void parse_command_line(int argc, char **argv) ksft_exit_xfail(); } } +} - if (!validate_interfaces()) { - usage(basename(argv[0])); - ksft_exit_xfail(); +static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, + struct ifobject *ifobj_rx) +{ + u32 i, j; + + for (i = 0; i < MAX_INTERFACES; i++) { + struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx; + + ifobj->umem = &ifobj->umem_arr[0]; + ifobj->xsk = &ifobj->xsk_arr[0]; + + if (i == tx) + ifobj->fv.vector = tx; + else + ifobj->fv.vector = rx; + + for (j = 0; j < MAX_SOCKETS; j++) { + memset(&ifobj->umem_arr[j], 0, sizeof(ifobj->umem_arr[j])); + memset(&ifobj->xsk_arr[j], 0, sizeof(ifobj->xsk_arr[j])); + } } + + test->ifobj_tx = ifobj_tx; + test->ifobj_rx = ifobj_rx; +} + +static void test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, + struct ifobject *ifobj_rx) +{ + memset(test, 0, sizeof(*test)); + __test_spec_init(test, ifobj_tx, ifobj_rx); +} + +static void test_spec_reset(struct test_spec *test) +{ + __test_spec_init(test, test->ifobj_tx, test->ifobj_rx); } static struct pkt *pkt_stream_get_pkt(struct pkt_stream *pkt_stream, u32 pkt_nb) @@ -842,8 +873,10 @@ static void *worker_testapp_validate_rx(void *arg) pthread_exit(NULL); } -static void testapp_validate(void) +static void testapp_validate_traffic(struct test_spec *test) { + struct ifobject *ifobj_tx = test->ifobj_tx; + struct ifobject *ifobj_rx = test->ifobj_rx; bool bidi = test_type == TEST_TYPE_BIDI; bool bpf = test_type == TEST_TYPE_BPF_RES; struct pkt_stream *pkt_stream; @@ -855,18 +888,18 @@ static void testapp_validate(void) pkt_stream = pkt_stream_generate(DEFAULT_PKT_CNT, XSK_UMEM__INVALID_FRAME_SIZE); else pkt_stream = pkt_stream_generate(DEFAULT_PKT_CNT, PKT_SIZE); - ifdict_tx->pkt_stream = pkt_stream; - ifdict_rx->pkt_stream = pkt_stream; + ifobj_tx->pkt_stream = pkt_stream; + ifobj_rx->pkt_stream = pkt_stream; /*Spawn RX thread */ - pthread_create(&t0, NULL, ifdict_rx->func_ptr, ifdict_rx); + pthread_create(&t0, NULL, ifobj_rx->func_ptr, ifobj_rx); pthread_barrier_wait(&barr); if (pthread_barrier_destroy(&barr)) exit_with_error(errno); /*Spawn TX thread */ - pthread_create(&t1, NULL, ifdict_tx->func_ptr, ifdict_tx); + pthread_create(&t1, NULL, ifobj_tx->func_ptr, ifobj_tx); pthread_join(t1, NULL); pthread_join(t0, NULL); @@ -875,80 +908,82 @@ static void testapp_validate(void) print_ksft_result(); } -static void testapp_teardown(void) +static void testapp_teardown(struct test_spec *test) { int i; for (i = 0; i < MAX_TEARDOWN_ITER; i++) { - print_verbose("Creating socket\n"); - testapp_validate(); + testapp_validate_traffic(test); + test_spec_reset(test); } print_ksft_result(); } -static void swap_vectors(struct ifobject *ifobj1, struct ifobject *ifobj2) +static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2) { - void *(*tmp_func_ptr)(void *) = ifobj1->func_ptr; - enum fvector tmp_vector = ifobj1->fv.vector; + thread_func_t tmp_func_ptr = (*ifobj1)->func_ptr; + enum fvector tmp_vector = (*ifobj1)->fv.vector; + struct ifobject *tmp_ifobj = (*ifobj1); - ifobj1->func_ptr = ifobj2->func_ptr; - ifobj1->fv.vector = ifobj2->fv.vector; + (*ifobj1)->func_ptr = (*ifobj2)->func_ptr; + (*ifobj1)->fv.vector = (*ifobj2)->fv.vector; - ifobj2->func_ptr = tmp_func_ptr; - ifobj2->fv.vector = tmp_vector; + (*ifobj2)->func_ptr = tmp_func_ptr; + (*ifobj2)->fv.vector = tmp_vector; - ifdict_tx = ifobj1; - ifdict_rx = ifobj2; + *ifobj1 = *ifobj2; + *ifobj2 = tmp_ifobj; } -static void testapp_bidi(void) +static void testapp_bidi(struct test_spec *test) { for (int i = 0; i < MAX_BIDI_ITER; i++) { print_verbose("Creating socket\n"); - testapp_validate(); + testapp_validate_traffic(test); if (!second_step) { print_verbose("Switching Tx/Rx vectors\n"); - swap_vectors(ifdict[1], ifdict[0]); + swap_directions(&test->ifobj_rx, &test->ifobj_tx); } second_step = true; } - swap_vectors(ifdict[0], ifdict[1]); + swap_directions(&test->ifobj_rx, &test->ifobj_tx); print_ksft_result(); } -static void swap_xsk_res(void) +static void swap_xsk_resources(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx) { - xsk_socket__delete(ifdict_tx->xsk->xsk); - xsk_umem__delete(ifdict_tx->umem->umem); - xsk_socket__delete(ifdict_rx->xsk->xsk); - xsk_umem__delete(ifdict_rx->umem->umem); - ifdict_tx->umem = &ifdict_tx->umem_arr[1]; - ifdict_tx->xsk = &ifdict_tx->xsk_arr[1]; - ifdict_rx->umem = &ifdict_rx->umem_arr[1]; - ifdict_rx->xsk = &ifdict_rx->xsk_arr[1]; + xsk_socket__delete(ifobj_tx->xsk->xsk); + xsk_umem__delete(ifobj_tx->umem->umem); + xsk_socket__delete(ifobj_rx->xsk->xsk); + xsk_umem__delete(ifobj_rx->umem->umem); + ifobj_tx->umem = &ifobj_tx->umem_arr[1]; + ifobj_tx->xsk = &ifobj_tx->xsk_arr[1]; + ifobj_rx->umem = &ifobj_rx->umem_arr[1]; + ifobj_rx->xsk = &ifobj_rx->xsk_arr[1]; } -static void testapp_bpf_res(void) +static void testapp_bpf_res(struct test_spec *test) { int i; for (i = 0; i < MAX_BPF_ITER; i++) { print_verbose("Creating socket\n"); - testapp_validate(); + testapp_validate_traffic(test); if (!second_step) - swap_xsk_res(); + swap_xsk_resources(test->ifobj_tx, test->ifobj_rx); second_step = true; } print_ksft_result(); } -static void testapp_stats(void) +static void testapp_stats(struct test_spec *test) { for (int i = 0; i < STAT_TEST_TYPE_MAX; i++) { + test_spec_reset(test); stat_test_type = i; /* reset defaults */ @@ -968,7 +1003,7 @@ static void testapp_stats(void) default: break; } - testapp_validate(); + testapp_validate_traffic(test); } print_ksft_result(); @@ -992,16 +1027,11 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char * ifobj->dst_port = dst_port; ifobj->src_port = src_port; - if (vector == tx) - ifdict_tx = ifobj; - else - ifdict_rx = ifobj; - ifobj->fv.vector = vector; ifobj->func_ptr = func_ptr; } -static void run_pkt_test(int mode, int type) +static void run_pkt_test(struct test_spec *test, int mode, int type) { test_type = type; @@ -1027,19 +1057,19 @@ static void run_pkt_test(int mode, int type) switch (test_type) { case TEST_TYPE_STATS: - testapp_stats(); + testapp_stats(test); break; case TEST_TYPE_TEARDOWN: - testapp_teardown(); + testapp_teardown(test); break; case TEST_TYPE_BIDI: - testapp_bidi(); + testapp_bidi(test); break; case TEST_TYPE_BPF_RES: - testapp_bpf_res(); + testapp_bpf_res(test); break; default: - testapp_validate(); + testapp_validate_traffic(test); break; } } @@ -1079,36 +1109,47 @@ static void ifobject_delete(struct ifobject *ifobj) int main(int argc, char **argv) { struct rlimit _rlim = { RLIM_INFINITY, RLIM_INFINITY }; - int i, j; + struct ifobject *ifobj_tx, *ifobj_rx; + struct test_spec test; + u32 i, j; if (setrlimit(RLIMIT_MEMLOCK, &_rlim)) exit_with_error(errno); - for (i = 0; i < MAX_INTERFACES; i++) { - ifdict[i] = ifobject_create(); - if (!ifdict[i]) - exit_with_error(ENOMEM); - } + ifobj_tx = ifobject_create(); + if (!ifobj_tx) + exit_with_error(ENOMEM); + ifobj_rx = ifobject_create(); + if (!ifobj_rx) + exit_with_error(ENOMEM); + + test_spec_init(&test, ifobj_tx, ifobj_rx); setlocale(LC_ALL, ""); - parse_command_line(argc, argv); + parse_command_line(&test, argc, argv); + + if (!validate_interface(ifobj_tx) || !validate_interface(ifobj_rx)) { + usage(basename(argv[0])); + ksft_exit_xfail(); + } - init_iface(ifdict[tx], MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx, + init_iface(ifobj_tx, MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx, worker_testapp_validate_tx); - init_iface(ifdict[rx], MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx, + init_iface(ifobj_rx, MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx, worker_testapp_validate_rx); ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); for (i = 0; i < TEST_MODE_MAX; i++) for (j = 0; j < TEST_TYPE_MAX; j++) { - run_pkt_test(i, j); + test_spec_init(&test, ifobj_tx, ifobj_rx); + run_pkt_test(&test, i, j); usleep(USLEEP_MAX); } - for (i = 0; i < MAX_INTERFACES; i++) - ifobject_delete(ifdict[i]); + ifobject_delete(ifobj_tx); + ifobject_delete(ifobj_rx); ksft_exit_pass(); return 0; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 799d524eb425..e279aa893438 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -137,9 +137,10 @@ struct ifobject { u8 src_mac[ETH_ALEN]; }; -static struct ifobject *ifdict[MAX_INTERFACES]; -static struct ifobject *ifdict_rx; -static struct ifobject *ifdict_tx; +struct test_spec { + struct ifobject *ifobj_tx; + struct ifobject *ifobj_rx; +}; /*threads*/ pthread_barrier_t barr; From patchwork Wed Sep 1 10:47:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 115DEC432BE for ; Wed, 1 Sep 2021 10:48:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE9946101B for ; Wed, 1 Sep 2021 10:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238804AbhIAKtP (ORCPT ); Wed, 1 Sep 2021 06:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238588AbhIAKtL (ORCPT ); Wed, 1 Sep 2021 06:49:11 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD32CC0617A8; Wed, 1 Sep 2021 03:48:07 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id i6so3835742wrv.2; Wed, 01 Sep 2021 03:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=obBkzebWL7uuIG+0NdExWZj3JRncqJP+NsVPCtUWNb8=; b=T9DokBKICl4BuLx8iUj8PQdRcCJsqmbEW7UHRxag1YTr9bdXJvvYMT90qVASENM0zf e2k6f+lbGRtoHR/yNrUvcXsZa0n8LWZJibWNV7lFGrc/CO9P+MpxdjhMhPIiTgIBv7Oc AVOBajKm9M5Il2SN/PmTMk5kVDA2d/9aif0KWJJ5MFuwqLqrNuP0p7H5zBfc82OmvFWc Kgm5T53UWxPTc/VK/9SuPU7ZqoW7UlDS8SMMkBWPUVuVLukuB90V/HghX/pUfLqeOes+ Ojqk3jr+2NlTbpIUYbADdEbBQ5lvQTeWtV/9J6Q6gFbxFEUEOT5WsRMC7XIe30N2LkEr iHwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=obBkzebWL7uuIG+0NdExWZj3JRncqJP+NsVPCtUWNb8=; b=EgVykYUZ6MAjrYTsnU7cnElDUuoPG01GQTvlAnMEZzWQvvRr6RWPx9byQSk4AuCp1r xLq5modWrPPMs/dRbuisMXFE8tlqhY6OJIfIOKrtmM6Doli1/rxz/YbuMhoQ75oVUJ4s a4lMemXjloCMbbignKRxjMRIxZrx85tOo+ag5mmRRtMmaW2RRNlWWxblxm1hjoFVziZx 6rT1FSkwQi7NBiaNzTq336pGts9m3ybI2ePMPuLNNKKk8bFaQg2ZsJiwdGa2XiSEkARg TwKxAijb6WsMC1aOjLcmkJnT1UIeRc3po20S4neHwQsJuSon21c30Py8opa4htbLsD2n CQUg== X-Gm-Message-State: AOAM532UipbPyzirfTZt4SoUkv3FzLo7xF4IvN+dwuKUQdTdP8OjZv8L YB9j8vEjthoww9NvzD5ZFcg= X-Google-Smtp-Source: ABdhPJyfXASWKgD5jqjEc0eP6PNDITKN/a/sJZbIbXqasjSzbbTMaozfhA8wBQMrapav4UNXTVECAw== X-Received: by 2002:adf:de8f:: with SMTP id w15mr36836167wrl.277.1630493286347; Wed, 01 Sep 2021 03:48:06 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:05 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 05/20] selftests: xsk: move rxqsize into xsk_socket_info Date: Wed, 1 Sep 2021 12:47:17 +0200 Message-Id: <20210901104732.10956-6-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Move the global variable rxqsize to struct xsk_socket_info as it describes the size of a ring in that struct. By default, it is set to the size dictated by libbpf. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 9 +++------ tools/testing/selftests/bpf/xdpxceiver.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 56ee03fda2b3..28bf62c56190 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -276,7 +276,7 @@ static int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_inf struct xsk_ring_prod *txr; xsk->umem = umem; - cfg.rx_size = rxqsize; + cfg.rx_size = xsk->rxqsize; cfg.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS; cfg.libbpf_flags = 0; cfg.xdp_flags = xdp_flags; @@ -407,6 +407,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, memset(&ifobj->umem_arr[j], 0, sizeof(ifobj->umem_arr[j])); memset(&ifobj->xsk_arr[j], 0, sizeof(ifobj->xsk_arr[j])); ifobj->umem_arr[j].num_frames = DEFAULT_PKT_CNT / 4; + ifobj->xsk_arr[j].rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; } } @@ -988,16 +989,13 @@ static void testapp_stats(struct test_spec *test) test_spec_reset(test); stat_test_type = i; - /* reset defaults */ - rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; - switch (stat_test_type) { case STAT_TEST_RX_DROPPED: test->ifobj_rx->umem->frame_headroom = XSK_UMEM__DEFAULT_FRAME_SIZE - XDP_PACKET_HEADROOM - 1; break; case STAT_TEST_RX_FULL: - rxqsize = RX_FULL_RXQSIZE; + test->ifobj_rx->xsk->rxqsize = RX_FULL_RXQSIZE; break; case STAT_TEST_TX_INVALID: continue; @@ -1040,7 +1038,6 @@ static void run_pkt_test(struct test_spec *test, int mode, int type) xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; second_step = 0; stat_test_type = -1; - rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; configured_mode = mode; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 0d93a9e6c4f3..09e4e015b1bf 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -79,7 +79,6 @@ static bool opt_verbose; static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY; static int stat_test_type; -static u32 rxqsize; struct xsk_umem_info { struct xsk_ring_prod fq; @@ -96,6 +95,7 @@ struct xsk_socket_info { struct xsk_umem_info *umem; struct xsk_socket *xsk; u32 outstanding_tx; + u32 rxqsize; }; struct flow_vector { From patchwork Wed Sep 1 10:47:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6047EC4320E for ; Wed, 1 Sep 2021 10:48:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49CE76101B for ; Wed, 1 Sep 2021 10:48:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239993AbhIAKtU (ORCPT ); Wed, 1 Sep 2021 06:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238624AbhIAKtL (ORCPT ); Wed, 1 Sep 2021 06:49:11 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162F6C0617AF; Wed, 1 Sep 2021 03:48:12 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id u15so1545202wmj.1; Wed, 01 Sep 2021 03:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+UtgQWxRuRa4KqJ5d42yoDTYxOmZXpdqTSuXxXkZPMQ=; b=qlgz9BQKgjp09WhettPa53X4gLlsRrtcw3deR9+1OkTkhFGMM0PU0Yw8Pe1O9PZLrI Y5udMnAhxxBHtkMdxcQjoCAFXGSFyQfTX+6tQd6EG5dWYN4sUMMo2+rPgNLvr0BiTRTM i2tiFBMiBsxNG7a9bvXA84m4M2c1uU1F5eXLPceH7P6dtt7j0BSMlWU1yLEQo3GaeS6J Aqb4HR6pLmMAigLI0yC34OAhSG35lCCtwLmRzoHAbb7kZkNOdKE6+kIDvzelW77IRjKz ICBccCl+ANNxc5PsHKSIUlFQbmUR+T0/a3Dm1LiCT8tpjrG7KRNLa+0kqkENA/dUQkgv s/Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+UtgQWxRuRa4KqJ5d42yoDTYxOmZXpdqTSuXxXkZPMQ=; b=ac/XtdBVFUxUQ0O9Q6Rm2VfzMedNVSgzlvWUMLnIVHekXYrE/8RPaiYOzn61rzHqUf GgRAs+ieSv/4Vcx117h1Ko8L+tSiM23yhYo/f0qD3LFnYLYZC7qU653VnshNWEQViXru Bv4IFyagtHN3LIcV0bqbnObzA2dlXUGQj3GM05QHzn8Co9EMTf95HL+/r1uvq8b150bd oY5OCJLBk1H9H/VFB/8bH+39NjYAt6xkrcS7Hm9RiLdlVBpv/SgoTfEIq+N6bBAXbFQu pxoDFDMP+17i3yIuKS4S5+1wllKFUokYvblCrs49onTIatjB55COuyW6RRSl/yQAwiDd V6AQ== X-Gm-Message-State: AOAM532Yr9laB2itAheJTk5qIWEweiU0Ra6B6MDIrSMSsTWhGOHYbY2m jfdQznXFjbzw3riwEgPLFTE= X-Google-Smtp-Source: ABdhPJwyWv/0nYwD4xPUYloVvWwNA/NOvid8Yo1zBLBorjJYy8S2dbGnMS15/PaYuHN9zG95/EDXLA== X-Received: by 2002:a7b:c7cc:: with SMTP id z12mr8771854wmk.108.1630493290732; Wed, 01 Sep 2021 03:48:10 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:10 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 08/20] selftests: xsk: add use_poll to ifobject Date: Wed, 1 Sep 2021 12:47:20 +0200 Message-Id: <20210901104732.10956-9-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Add a use_poll option to the ifobject so that we do not need to use a test specific if-statement in the test runner. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 5 ++++- tools/testing/selftests/bpf/xdpxceiver.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 8ef58081d4d2..9a98c45933c5 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -393,6 +393,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, ifobj->umem = &ifobj->umem_arr[0]; ifobj->xsk = &ifobj->xsk_arr[0]; + ifobj->use_poll = false; if (i == tx) ifobj->fv.vector = tx; @@ -684,7 +685,7 @@ static void send_pkts(struct ifobject *ifobject) while (pkt_cnt < ifobject->pkt_stream->nb_pkts) { u32 sent; - if (test_type == TEST_TYPE_POLL) { + if (ifobject->use_poll) { int ret; ret = poll(fds, 1, POLL_TMOUT); @@ -1071,6 +1072,8 @@ static void run_pkt_test(struct test_spec *test, int mode, int type) testapp_validate_traffic(test); break; case TEST_TYPE_POLL: + test->ifobj_tx->use_poll = true; + test->ifobj_rx->use_poll = true; test_spec_set_name(test, "POLL"); testapp_validate_traffic(test); break; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 15eab31b3b32..e02a4dd71bfb 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -135,6 +135,7 @@ struct ifobject { u32 src_ip; u16 src_port; u16 dst_port; + bool use_poll; u8 dst_mac[ETH_ALEN]; u8 src_mac[ETH_ALEN]; }; From patchwork Wed Sep 1 10:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99558C4320E for ; Wed, 1 Sep 2021 10:48:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F20C6101B for ; Wed, 1 Sep 2021 10:48:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239994AbhIAKtd (ORCPT ); Wed, 1 Sep 2021 06:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238637AbhIAKtL (ORCPT ); Wed, 1 Sep 2021 06:49:11 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8222AC0613A3; Wed, 1 Sep 2021 03:48:13 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 79-20020a1c0452000000b002e6cf79e572so4431668wme.1; Wed, 01 Sep 2021 03:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sxkrSYD9cgbDYCmPJ3kUKrpYLNcLTg8gLS7WNJCmpuA=; b=ovlix9wgmM4izcJ31H8cYytCWUUbnO/NoS5ARvY7xZGAdieIwaJCwmtt2RJWcgzpd5 pqgcCtRXZd5b8t8IhkItpCsbJ+BbnyvjQ0dJhmxqduWdaN+9F8+dp+6ENH41v086UmJm I7Oc73dFeCSGNd36CdNgEqWnbb/sqORsOWgLfGDLwjTGk+4zov0UZQCcyZmvV6gY8jVD KGkDarCYGlfgKKfusqiIMQ4yoGOS8qBWd6v1dxWv+eWGIxW3O3LzzSTxBD0UQE1/AJHr jX0TQCNnkQ5svxQWR2TsNo14QcssMku075dZ2yhidRVbhKzRdbCsZ85HGsiCUVZs+T7a bCuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sxkrSYD9cgbDYCmPJ3kUKrpYLNcLTg8gLS7WNJCmpuA=; b=q+MnSUm/nJkDHuw/cktsU5hIAMD6EogSZF960nd8H76PCjMAm7pqvPMXcw1zg2VpRG 3o6XlPBhrJ3wUfdOGnjqGrwB503AnsQ9PK2hcZqmfwUD2DpsSJyETLucnjaCEwpaZwZ3 jh79c15+m0M3J/C6OqmYxPySLMNrUD1MYQEmVI72whljfjFz/bqDD0jAhzNNBbgAv5UO jybZ8ZM27iAi4zXXV4xXtQB1FX9fZBj+perPKhkn0Z9RWG26WTIVQR/GbYygMQnelT5W nBqYgoy8b/dci+6p9I4HipBSV/UW8CYFsVbYtvXHMEVDP4jr6eSBu7sW708w71X2gl6R qDjw== X-Gm-Message-State: AOAM532UTu4+tiHTOHqQkKboh6IPDCe+tAojlqKC/qjiGF5vdomRnNG+ G137Cn1llPl4QQtMyUTy+Xh9CXrqJpODSi8t X-Google-Smtp-Source: ABdhPJym8pCk4iY6bd6hKxa3tF/rvfMh4DwpLqbGP1RkHYh1GkBBIsQdWsDYGVIwTJ3HQ1LIwEBaQA== X-Received: by 2002:a05:600c:a0b:: with SMTP id z11mr8974130wmp.147.1630493292131; Wed, 01 Sep 2021 03:48:12 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:11 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 09/20] selftests: xsk: introduce rx_on and tx_on in ifobject Date: Wed, 1 Sep 2021 12:47:21 +0200 Message-Id: <20210901104732.10956-10-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Introduce rx_on and tx_on in the ifobject so that we can describe if the thread should create a socket with only tx, rx, or both. This eliminates some test specific if statements from the code. We can also eliminate the flow vector structure now as this is fully specified by the tx_on and rx_on variables. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 34 ++++++++++-------------- tools/testing/selftests/bpf/xdpxceiver.h | 10 ++----- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 9a98c45933c5..a896d5845c0e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -278,14 +278,8 @@ static int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_inf cfg.xdp_flags = xdp_flags; cfg.bind_flags = xdp_bind_flags; - if (test_type != TEST_TYPE_BIDI) { - rxr = (ifobject->fv.vector == rx) ? &xsk->rx : NULL; - txr = (ifobject->fv.vector == tx) ? &xsk->tx : NULL; - } else { - rxr = &xsk->rx; - txr = &xsk->tx; - } - + txr = ifobject->tx_on ? &xsk->tx : NULL; + rxr = ifobject->rx_on ? &xsk->rx : NULL; return xsk_socket__create(&xsk->xsk, ifobject->ifname, qid, umem->umem, rxr, txr, &cfg); } @@ -395,10 +389,13 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, ifobj->xsk = &ifobj->xsk_arr[0]; ifobj->use_poll = false; - if (i == tx) - ifobj->fv.vector = tx; - else - ifobj->fv.vector = rx; + if (i == 0) { + ifobj->rx_on = false; + ifobj->tx_on = true; + } else { + ifobj->rx_on = true; + ifobj->tx_on = false; + } for (j = 0; j < MAX_SOCKETS; j++) { memset(&ifobj->umem_arr[j], 0, sizeof(ifobj->umem_arr[j])); @@ -923,14 +920,10 @@ static void testapp_teardown(struct test_spec *test) static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2) { thread_func_t tmp_func_ptr = (*ifobj1)->func_ptr; - enum fvector tmp_vector = (*ifobj1)->fv.vector; struct ifobject *tmp_ifobj = (*ifobj1); (*ifobj1)->func_ptr = (*ifobj2)->func_ptr; - (*ifobj1)->fv.vector = (*ifobj2)->fv.vector; - (*ifobj2)->func_ptr = tmp_func_ptr; - (*ifobj2)->fv.vector = tmp_vector; *ifobj1 = *ifobj2; *ifobj2 = tmp_ifobj; @@ -939,6 +932,8 @@ static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2) static void testapp_bidi(struct test_spec *test) { test_spec_set_name(test, "BIDIRECTIONAL"); + test->ifobj_tx->rx_on = true; + test->ifobj_rx->tx_on = true; for (int i = 0; i < MAX_BIDI_ITER; i++) { print_verbose("Creating socket\n"); testapp_validate_traffic(test); @@ -1012,7 +1007,7 @@ static void testapp_stats(struct test_spec *test) static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac, const char *dst_ip, const char *src_ip, const u16 dst_port, - const u16 src_port, enum fvector vector, thread_func_t func_ptr) + const u16 src_port, thread_func_t func_ptr) { struct in_addr ip; @@ -1028,7 +1023,6 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char * ifobj->dst_port = dst_port; ifobj->src_port = src_port; - ifobj->fv.vector = vector; ifobj->func_ptr = func_ptr; } @@ -1144,9 +1138,9 @@ int main(int argc, char **argv) ksft_exit_xfail(); } - init_iface(ifobj_tx, MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx, + init_iface(ifobj_tx, MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, worker_testapp_validate_tx); - init_iface(ifobj_rx, MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx, + init_iface(ifobj_rx, MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, worker_testapp_validate_rx); ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index e02a4dd71bfb..03ff52897d7b 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -100,13 +100,6 @@ struct xsk_socket_info { u32 rxqsize; }; -struct flow_vector { - enum fvector { - tx, - rx, - } vector; -}; - struct pkt { u64 addr; u32 len; @@ -127,7 +120,6 @@ struct ifobject { struct xsk_socket_info *xsk_arr; struct xsk_umem_info *umem; struct xsk_umem_info *umem_arr; - struct flow_vector fv; thread_func_t func_ptr; struct pkt_stream *pkt_stream; int ns_fd; @@ -135,6 +127,8 @@ struct ifobject { u32 src_ip; u16 src_port; u16 dst_port; + bool tx_on; + bool rx_on; bool use_poll; u8 dst_mac[ETH_ALEN]; u8 src_mac[ETH_ALEN]; From patchwork Wed Sep 1 10:47:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30C0AC43216 for ; Wed, 1 Sep 2021 10:48:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C45261054 for ; Wed, 1 Sep 2021 10:48:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240337AbhIAKtZ (ORCPT ); Wed, 1 Sep 2021 06:49:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238666AbhIAKtL (ORCPT ); Wed, 1 Sep 2021 06:49:11 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E986C061575; Wed, 1 Sep 2021 03:48:15 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id u9so3760475wrg.8; Wed, 01 Sep 2021 03:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F6ztmsfCuyf/euy3NnBbv+85iaiLweq/gL4Cay2GcwU=; b=Ky7qdDNN3z79k7fh9Oy0Jtw3NnDMHK88LiMnqBYG2a26fSVRBBUPqIAz6ITpGCQ+Yj LizV3x5RlqBFK7nwWtlDT9SVQZWQCNJIUb9CW2/h6GwQm8dMb8+6LFFcFroNRqbd0Ipg Aom9Se8JeNLEyXfyS1dv7bcME2+3LWbXp4mi60sBqQQzdBALMJp3ZO5xPaQaT9KvyupE JdFTrKWIbSKkMhJ+zFsvSv8LsB+v/fRxEAfd/qOCa/xUxRSUiGumDq0AZOP4/rm1qVoS WsWb3uujplu5fub8q8t4j90hDsBOsugIO4hF7MMSZwmkKJMmkNvDUdP7bUF+CKs4pIZD nO2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F6ztmsfCuyf/euy3NnBbv+85iaiLweq/gL4Cay2GcwU=; b=UZ9+1Gy6AGjxlUtr7VcXEKLKzAwRx45B3JVDr93gaMTkYPk3mKKgppdxzsEJId2kAC CzwrGcSl7QX8HpXpFS9a0qNuTKVdTLJK5m8DgJKgy/nIVnNN62Jy7kobG95r494ovNH5 lMJt5pIfiWRAwGbKwSP7n0unlaEfTFNwHoZgRWe4SEN8qn6tuFk28WgRxKZQ/PgRsU3T BKPrj+kTZMi13pQMNnMlAQn32cjQR+IL1l+JKBza9ItAVDHO4LI33tXsrZo8JCoVPoCl N73HMty7brwCL6Z2Xcxr4tfYU5Z7NGPiaHbqEbti34H5XL0+2VBq5LtH6Rlsax/KbOx6 jwOg== X-Gm-Message-State: AOAM532CEOOAnOaGvxTGDjCiB0m4OhvtNJlOGlNNL6VUbsiu3crFCHM9 EzeLbSp9rswuaLFw+pa9StM= X-Google-Smtp-Source: ABdhPJx8sRv3wR4d/1p1VGBiiQOoSdy77R7CgoNNVwQVccil4/50cRMYYetI7kqQ0XeCC4WkuEQWWA== X-Received: by 2002:adf:f2d1:: with SMTP id d17mr36537616wrp.381.1630493293611; Wed, 01 Sep 2021 03:48:13 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:13 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 10/20] selftests: xsk: replace second_step global variable Date: Wed, 1 Sep 2021 12:47:22 +0200 Message-Id: <20210901104732.10956-11-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Replace the second_step global variable with a test specification variable called total_steps that a test can be set to indicate how many times the packet stream should be sent without reinitializing any sockets. This eliminates test specific code in the test runner around the bidirectional test. The total_steps variable is 1 by default as most tests only need a single round of packets. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 77 +++++++++++------------- tools/testing/selftests/bpf/xdpxceiver.h | 4 +- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index a896d5845c0e..0a3e28c9e2a9 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -408,6 +408,8 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, test->ifobj_tx = ifobj_tx; test->ifobj_rx = ifobj_rx; + test->current_step = 0; + test->total_steps = 1; } static void test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, @@ -713,7 +715,7 @@ static bool rx_stats_are_valid(struct ifobject *ifobject) optlen = sizeof(stats); err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen); if (err) { - ksft_test_result_fail("ERROR: [%s] getsockopt(XDP_STATISTICS) error %u %s\n", + ksft_test_result_fail("ERROR Rx: [%s] getsockopt(XDP_STATISTICS) error %u %s\n", __func__, -err, strerror(-err)); return true; } @@ -754,7 +756,7 @@ static void tx_stats_validate(struct ifobject *ifobject) optlen = sizeof(stats); err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen); if (err) { - ksft_test_result_fail("ERROR: [%s] getsockopt(XDP_STATISTICS) error %u %s\n", + ksft_test_result_fail("ERROR Tx: [%s] getsockopt(XDP_STATISTICS) error %u %s\n", __func__, -err, strerror(-err)); return; } @@ -766,12 +768,13 @@ static void tx_stats_validate(struct ifobject *ifobject) __func__, stats.tx_invalid_descs, ifobject->pkt_stream->nb_pkts); } -static void thread_common_ops(struct ifobject *ifobject, void *bufs) +static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject) { u64 umem_sz = ifobject->umem->num_frames * ifobject->umem->frame_size; int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; size_t mmap_sz = umem_sz; int ctr = 0, ret; + void *bufs; ifobject->ns_fd = switch_namespace(ifobject->nsname); @@ -813,26 +816,19 @@ static void thread_common_ops(struct ifobject *ifobject, void *bufs) ifobject->xsk = &ifobject->xsk_arr[0]; } -static bool testapp_is_test_two_stepped(void) -{ - return (test_type != TEST_TYPE_BIDI && test_type != TEST_TYPE_BPF_RES) || second_step; -} - static void testapp_cleanup_xsk_res(struct ifobject *ifobj) { - if (testapp_is_test_two_stepped()) { - xsk_socket__delete(ifobj->xsk->xsk); - (void)xsk_umem__delete(ifobj->umem->umem); - } + xsk_socket__delete(ifobj->xsk->xsk); + xsk_umem__delete(ifobj->umem->umem); } static void *worker_testapp_validate_tx(void *arg) { - struct ifobject *ifobject = (struct ifobject *)arg; - void *bufs = NULL; + struct test_spec *test = (struct test_spec *)arg; + struct ifobject *ifobject = test->ifobj_tx; - if (!second_step) - thread_common_ops(ifobject, bufs); + if (test->current_step == 1) + thread_common_ops(test, ifobject); print_verbose("Sending %d packets on interface %s\n", ifobject->pkt_stream->nb_pkts, ifobject->ifname); @@ -841,18 +837,19 @@ static void *worker_testapp_validate_tx(void *arg) if (stat_test_type == STAT_TEST_TX_INVALID) tx_stats_validate(ifobject); - testapp_cleanup_xsk_res(ifobject); + if (test->total_steps == test->current_step) + testapp_cleanup_xsk_res(ifobject); pthread_exit(NULL); } static void *worker_testapp_validate_rx(void *arg) { - struct ifobject *ifobject = (struct ifobject *)arg; + struct test_spec *test = (struct test_spec *)arg; + struct ifobject *ifobject = test->ifobj_rx; struct pollfd fds[MAX_SOCKS] = { }; - void *bufs = NULL; - if (!second_step) - thread_common_ops(ifobject, bufs); + if (test->current_step == 1) + thread_common_ops(test, ifobject); if (stat_test_type != STAT_TEST_RX_FILL_EMPTY) xsk_populate_fill_ring(ifobject->umem); @@ -871,7 +868,8 @@ static void *worker_testapp_validate_rx(void *arg) if (test_type == TEST_TYPE_TEARDOWN) print_verbose("Destroying socket\n"); - testapp_cleanup_xsk_res(ifobject); + if (test->total_steps == test->current_step) + testapp_cleanup_xsk_res(ifobject); pthread_exit(NULL); } @@ -891,16 +889,17 @@ static void testapp_validate_traffic(struct test_spec *test) pkt_stream = pkt_stream_generate(test->ifobj_tx->umem, DEFAULT_PKT_CNT, PKT_SIZE); ifobj_tx->pkt_stream = pkt_stream; ifobj_rx->pkt_stream = pkt_stream; + test->current_step++; /*Spawn RX thread */ - pthread_create(&t0, NULL, ifobj_rx->func_ptr, ifobj_rx); + pthread_create(&t0, NULL, ifobj_rx->func_ptr, test); pthread_barrier_wait(&barr); if (pthread_barrier_destroy(&barr)) exit_with_error(errno); /*Spawn TX thread */ - pthread_create(&t1, NULL, ifobj_tx->func_ptr, ifobj_tx); + pthread_create(&t1, NULL, ifobj_tx->func_ptr, test); pthread_join(t1, NULL); pthread_join(t0, NULL); @@ -934,15 +933,12 @@ static void testapp_bidi(struct test_spec *test) test_spec_set_name(test, "BIDIRECTIONAL"); test->ifobj_tx->rx_on = true; test->ifobj_rx->tx_on = true; - for (int i = 0; i < MAX_BIDI_ITER; i++) { - print_verbose("Creating socket\n"); - testapp_validate_traffic(test); - if (!second_step) { - print_verbose("Switching Tx/Rx vectors\n"); - swap_directions(&test->ifobj_rx, &test->ifobj_tx); - } - second_step = true; - } + test->total_steps = 2; + testapp_validate_traffic(test); + + print_verbose("Switching Tx/Rx vectors\n"); + swap_directions(&test->ifobj_rx, &test->ifobj_tx); + testapp_validate_traffic(test); swap_directions(&test->ifobj_rx, &test->ifobj_tx); } @@ -961,16 +957,12 @@ static void swap_xsk_resources(struct ifobject *ifobj_tx, struct ifobject *ifobj static void testapp_bpf_res(struct test_spec *test) { - int i; - test_spec_set_name(test, "BPF_RES"); - for (i = 0; i < MAX_BPF_ITER; i++) { - print_verbose("Creating socket\n"); - testapp_validate_traffic(test); - if (!second_step) - swap_xsk_resources(test->ifobj_tx, test->ifobj_rx); - second_step = true; - } + test->total_steps = 2; + testapp_validate_traffic(test); + + swap_xsk_resources(test->ifobj_tx, test->ifobj_rx); + testapp_validate_traffic(test); } static void testapp_stats(struct test_spec *test) @@ -1032,7 +1024,6 @@ static void run_pkt_test(struct test_spec *test, int mode, int type) /* reset defaults after potential previous test */ xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; - second_step = 0; stat_test_type = -1; configured_mode = mode; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 03ff52897d7b..ea505a4cb8c0 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -24,7 +24,6 @@ #define MAX_SOCKETS 2 #define MAX_TEST_NAME_SIZE 32 #define MAX_TEARDOWN_ITER 10 -#define MAX_BIDI_ITER 2 #define MAX_BPF_ITER 2 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \ sizeof(struct udphdr)) @@ -72,7 +71,6 @@ enum stat_test_type { static int configured_mode; static bool opt_pkt_dump; -static bool second_step; static int test_type; static bool opt_verbose; @@ -137,6 +135,8 @@ struct ifobject { struct test_spec { struct ifobject *ifobj_tx; struct ifobject *ifobj_rx; + u16 total_steps; + u16 current_step; char name[MAX_TEST_NAME_SIZE]; }; From patchwork Wed Sep 1 10:47:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE228C4320A for ; Wed, 1 Sep 2021 10:48:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C84C56101B for ; Wed, 1 Sep 2021 10:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239045AbhIAKth (ORCPT ); Wed, 1 Sep 2021 06:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238840AbhIAKtQ (ORCPT ); Wed, 1 Sep 2021 06:49:16 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E808C061764; Wed, 1 Sep 2021 03:48:19 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id e26so1543550wmk.2; Wed, 01 Sep 2021 03:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y5WD1aKtaMyuh9hneT8MwIh2Gk7dZWu/fc+ZQakb7tI=; b=gGJXldUYNFNdQLRJ6Je7H5oJW5zFnHRoKezPQ3yORK09GTsSUYbMDlGXMY1WZTl/M+ HUTQLPOQoEmgRN9WqrwM8JnoUH/Yu3ynstx8qXsdlOHaZQIcmIl8lT1jUATylsKuox6R iGdwKIRSz4tYA3IAOY6DZ2DpHJ6VguWk1S7ACCHTSof3efE23gCSBOSiWaMBVaKkn82l 0oaaCW8gSMYitJiIyaJkedUavRX8RaHdZuQG3KHfdAdxoBakzFIUzoXmPIF1kAm1hrdb Kr3idkdykF6q/o+JWQLW8MOUJ+VHRTuTAk7UZSz5HURnCZtYoHF4HNI3IlIfW3eh1X7X lD1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y5WD1aKtaMyuh9hneT8MwIh2Gk7dZWu/fc+ZQakb7tI=; b=hhIQKzKuOpaTL7HgFcUbymeh2Fspfx+BvIA9pmxd/MbIOGCDMUMp1LzxgTaqC2+Uou dOr/W7AMZ42yZ2iF6u1RgwyiTE4Xd3XFO7Fts8gFn++rQWoLCvShuOqCYS7zz/1xAQhq zWo+5XR/r2rPo76ZbB3oFHYHPhatRLNIie1IHuu7DZL/rvnwBaZeRpoW07IzZnuDy2Ye J9HFzxXbTaA2YcDSScWsO4lxgaXtUWeaL15a2Nf2HQkZ5wNkqHClOhM/7xscErcv8PHo q/gmzgwirso6sS50+VKL0z3jAWqwxlCw6G+WGMLGETQoyTy5Vol0+N5hXMAWGhn3ABPs XZ9Q== X-Gm-Message-State: AOAM530rK2VZnHATZh9MqHjkBjdNjdREzGf20/H4aJ1Ip24ZRxhRi89m NlEowHjqPu4xgvnm3vN3EwU= X-Google-Smtp-Source: ABdhPJwp59ZjN1K9s76dCniY7jBHfPJgxTar2NiK+T0YIDY5NT0tt2A1Tf9SWZ91vmL/DyjbJUp2Cw== X-Received: by 2002:a7b:c255:: with SMTP id b21mr8994063wmj.44.1630493298087; Wed, 01 Sep 2021 03:48:18 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:17 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 13/20] selftests: xsx: make pthreads local scope Date: Wed, 1 Sep 2021 12:47:25 +0200 Message-Id: <20210901104732.10956-14-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Make the pthread_t variables local scope instead of global. No reason for them to be global. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 1 + tools/testing/selftests/bpf/xdpxceiver.h | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 3a1afece7c2c..5ea78c503741 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -887,6 +887,7 @@ static void testapp_validate_traffic(struct test_spec *test) struct ifobject *ifobj_tx = test->ifobj_tx; struct ifobject *ifobj_rx = test->ifobj_rx; struct pkt_stream *pkt_stream; + pthread_t t0, t1; if (pthread_barrier_init(&barr, NULL, 2)) exit_with_error(errno); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 7ed16128f2ad..34ae4e4ea4ac 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -138,8 +138,6 @@ struct test_spec { char name[MAX_TEST_NAME_SIZE]; }; -/*threads*/ pthread_barrier_t barr; -pthread_t t0, t1; #endif /* XDPXCEIVER_H */ From patchwork Wed Sep 1 10:47:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E312EC4320A for ; Wed, 1 Sep 2021 10:48:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C93A961054 for ; Wed, 1 Sep 2021 10:48:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240032AbhIAKtl (ORCPT ); Wed, 1 Sep 2021 06:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239191AbhIAKtT (ORCPT ); Wed, 1 Sep 2021 06:49:19 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50A73C0612E7; Wed, 1 Sep 2021 03:48:22 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id t15so3777315wrg.7; Wed, 01 Sep 2021 03:48:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hbt0Mg2tvtnST2dzdC4XVYXjIBjQHSXwsVrLWYPs1i4=; b=fSxAuXxEap6HoQREhMh2T3AMHb+8NzyHVhVeNXtzIbIhLzi7NaetZhCHnJpponozkK 6CxYJzSJHXIyWXi7ejtjqokPNNJIXd+8myAtrSB8rFoSOPyDxAuu4aTqkmzLkhGnUGm1 JqxhPSbO5LPyluFfHhjPUXUXsk/u5ArSIvKvuuGwdkzXezF172+74F9L+VS3qjv14ash 29eRimf0Gagu4l7CfMa7K+GwqUaVC2zeHcQMdthdKO0j54f75QyVB6H4R+7laRc42YoJ NqHGajqURqPRtP9p9NVqN0On1KkO+Wu89O7A33nMddvfo5xhxdJn8rwDhdWsSOkfEq3i JTMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hbt0Mg2tvtnST2dzdC4XVYXjIBjQHSXwsVrLWYPs1i4=; b=ZhQrJ5Hckgn4skEytEu41TETaWB7QorKB6S6FBYXioiGAxiUjNZcYy+tSat+kWwpkJ mKBvdHghLLhyq9Mh9efN4c6NXnvRqmuqg/4JRHR5e9r8n/FDfzpwFCt+3FufUWQOiv7h WXvg6eVitdExowYCs/7BtXY8MpesPsHFyjV+DDec/jr4SbDYzPtsEQ3THgUgjza/pm2N tQPHbAHizsHLKZ5LGE5CRmAXL+OQsGj7EgXPo5G1nfNUQmfaflwvnLpxNtdJ1A6wwiop Sl7nkIg6VbAwCIwBJvQOFFivQKX6UUyZhP9wd/djB2r98SlDr/p0QaJe6Dub0t1F8mIZ OO0w== X-Gm-Message-State: AOAM532ysptxnOfB55EETRiUtL7eczida7FzdRzqFb8+WsRVy8sekG6s cy1KBTE9oJbQSB/GsNUPfiY= X-Google-Smtp-Source: ABdhPJx5BUIrwF/xFjhTlPtPWRyZGbt38WJD+A7ivvwvAP7j9hZX10Qz2DmxN+wlgBPaBAe5lID+JA== X-Received: by 2002:adf:916f:: with SMTP id j102mr32752402wrj.422.1630493300965; Wed, 01 Sep 2021 03:48:20 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:20 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 15/20] selftests: xsk: allow for invalid packets Date: Wed, 1 Sep 2021 12:47:27 +0200 Message-Id: <20210901104732.10956-16-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Allow for invalid packets to be sent. These are verified by the Rx thread not to be received. Or put in another way, if they are received, the test will fail. This feature will be used to eliminate an if statement for a stats test and will also be used by other tests in later patches. The previous code could only deal with valid packets. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 16 ++++++++++------ tools/testing/selftests/bpf/xdpxceiver.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 0fb5cae974de..09d2854c10e6 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -473,6 +473,11 @@ static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb pkt_stream->pkts[i].addr = (i % umem->num_frames) * umem->frame_size; pkt_stream->pkts[i].len = pkt_len; pkt_stream->pkts[i].payload = i; + + if (pkt_len > umem->frame_size) + pkt_stream->pkts[i].valid = false; + else + pkt_stream->pkts[i].valid = true; } return pkt_stream; @@ -658,7 +663,7 @@ static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info * static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb) { struct xsk_socket_info *xsk = ifobject->xsk; - u32 i, idx; + u32 i, idx, valid_pkts = 0; while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) complete_pkts(xsk, BATCH_SIZE); @@ -673,14 +678,13 @@ static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb) tx_desc->addr = pkt->addr; tx_desc->len = pkt->len; pkt_nb++; + if (pkt->valid) + valid_pkts++; } xsk_ring_prod__submit(&xsk->tx, i); - if (stat_test_type != STAT_TEST_TX_INVALID) - xsk->outstanding_tx += i; - else if (xsk_ring_prod__needs_wakeup(&xsk->tx)) - kick_tx(xsk); - complete_pkts(xsk, i); + xsk->outstanding_tx += valid_pkts; + complete_pkts(xsk, BATCH_SIZE); return i; } diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 1e9a563380c8..c5baa7c5f560 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -96,6 +96,7 @@ struct pkt { u64 addr; u32 len; u32 payload; + bool valid; }; struct pkt_stream { From patchwork Wed Sep 1 10:47:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BD4DC43214 for ; Wed, 1 Sep 2021 10:48:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED82F6101B for ; Wed, 1 Sep 2021 10:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241833AbhIAKtr (ORCPT ); Wed, 1 Sep 2021 06:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240110AbhIAKtW (ORCPT ); Wed, 1 Sep 2021 06:49:22 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DCB7C0617A8; Wed, 1 Sep 2021 03:48:25 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id x2-20020a1c7c02000000b002e6f1f69a1eso4394770wmc.5; Wed, 01 Sep 2021 03:48:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3ThASeLs2skJFbRfloJioXQ83YLkiaCx8IRUThLWID0=; b=Rp2Ley9rMO3DQG0y1zJyivoQtDssm2kL/UU3tSwGK51f0dHSHoDqhoWlSAoWFp02Nh 47zIJr1cxpQn+1eUQLQSc+E0bk8DKIRJOenDwMggGKrBmvvDAhmYaa9U/8NQXiVpm7R7 btHEoxi5hDQLon/vemyidkOXYNc4HxcllCoe6ADdmEWhz6VIvur1xjROMbhU6ZpwxsJr tSvzrlv6uOo3SnbF3ZAJ4XBgP1K8il5R19SMcuj6wbBm3ZzX3gZrbf55xCzS9ITfIZfB 2SHW8mMOUtkdH4YWgb8rdgGsA06hkVktNby7HmF4d+GsAYQ3YNN6ETJbgFmh+gcEv2YT NBgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3ThASeLs2skJFbRfloJioXQ83YLkiaCx8IRUThLWID0=; b=DqVvdDb9pxEvVBO5e54k8PKZ7AFmfUrwJe7E5tvPNvVfEyQyBlH1kQOIyANdcjENlK e4n7Cv2hi8hobi6UBWC/YiQnxifvRNRLn3eOmxi8hURp1RkA6eGo2WpLseFor7t7FUUy rY7N36iJPaUoa9Bg41JqdJNVlNUACXKuHP4CJH9j1bnXi16fP2BtR8pBr4NQXtwwaXIz 7sx/kyOOu4kqTRh425V8Zh45E4GakwbHxrMMMFiTQGvOUcr+FxIhox3ezSHecue6eo4L vw5/CxnnTu6pN95VmA6EMcpZwZIhA3UwZpgFPoYoWi5jXuHuTK1ei0Se3GLsA6D+7KR6 U9AQ== X-Gm-Message-State: AOAM532t62Fk3Xwdlt3Kg+2dLx9Wqo65aE5geqHf28gR9CRM/sPorRSk AdbF7xo0t+7j4pSD9dAWFQpfBl1+LS0iUdrK X-Google-Smtp-Source: ABdhPJz/2MuFztBF6ceELgsgGpQgru0kJgdZ99K4jUXVL3aeYiIaoniKqE536Buu7ILlJBYDoUk/AQ== X-Received: by 2002:a1c:c918:: with SMTP id f24mr9292362wmb.61.1630493303933; Wed, 01 Sep 2021 03:48:23 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:23 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 17/20] selftests: xsk: add test for unaligned mode Date: Wed, 1 Sep 2021 12:47:29 +0200 Message-Id: <20210901104732.10956-18-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Add a test for unaligned mode in which packet buffers can be placed anywhere within the umem. Some packets are made to straddle page boundraries in order to check for correctness. On the Tx side, buffers are now allocated according to the addresses found in the packet stream. Thus, the placement of buffers can be controlled with the boolean use_addr_for_fill in the packet stream. One new pkt_stream insterface is introduced: pkt_stream_replace_half() that replaces every other packet in the default packet stream with the specified new packet. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 125 ++++++++++++++++++----- tools/testing/selftests/bpf/xdpxceiver.h | 4 + 2 files changed, 106 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index d4aad4833754..a24068993cc3 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -19,7 +19,7 @@ * Virtual Ethernet interfaces. * * For each mode, the following tests are run: - * a. nopoll - soft-irq processing + * a. nopoll - soft-irq processing in run-to-completion mode * b. poll - using poll() syscall * c. Socket Teardown * Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy @@ -45,6 +45,7 @@ * Configure sockets at indexes 0 and 1, run a traffic on queue ids 0, * then remove xsk sockets from queue 0 on both veth interfaces and * finally run a traffic on queues ids 1 + * g. unaligned mode * * Total tests: 12 * @@ -243,6 +244,9 @@ static int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size }; int ret; + if (umem->unaligned_mode) + cfg.flags |= XDP_UMEM_UNALIGNED_CHUNK_FLAG; + ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq, &cfg); if (ret) @@ -252,19 +256,6 @@ static int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size return 0; } -static void xsk_populate_fill_ring(struct xsk_umem_info *umem) -{ - int ret, i; - u32 idx = 0; - - ret = xsk_ring_prod__reserve(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS, &idx); - if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS) - exit_with_error(-ret); - for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS; i++) - *xsk_ring_prod__fill_addr(&umem->fq, idx++) = i * umem->frame_size; - xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS); -} - static int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_info *umem, struct ifobject *ifobject, u32 qid) { @@ -487,7 +478,8 @@ static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb pkt_stream->nb_pkts = nb_pkts; for (i = 0; i < nb_pkts; i++) { - pkt_stream->pkts[i].addr = (i % umem->num_frames) * umem->frame_size; + pkt_stream->pkts[i].addr = (i % umem->num_frames) * umem->frame_size + + DEFAULT_OFFSET; pkt_stream->pkts[i].len = pkt_len; pkt_stream->pkts[i].payload = i; @@ -500,6 +492,12 @@ static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb return pkt_stream; } +static struct pkt_stream *pkt_stream_clone(struct xsk_umem_info *umem, + struct pkt_stream *pkt_stream) +{ + return pkt_stream_generate(umem, pkt_stream->nb_pkts, pkt_stream->pkts[0].len); +} + static void pkt_stream_replace(struct test_spec *test, u32 nb_pkts, u32 pkt_len) { struct pkt_stream *pkt_stream; @@ -507,8 +505,22 @@ static void pkt_stream_replace(struct test_spec *test, u32 nb_pkts, u32 pkt_len) pkt_stream = pkt_stream_generate(test->ifobj_tx->umem, nb_pkts, pkt_len); test->ifobj_tx->pkt_stream = pkt_stream; test->ifobj_rx->pkt_stream = pkt_stream; +} - pkt_stream_delete(pkt_stream); +static void pkt_stream_replace_half(struct test_spec *test, u32 pkt_len, u32 offset) +{ + struct xsk_umem_info *umem = test->ifobj_tx->umem; + struct pkt_stream *pkt_stream; + u32 i; + + pkt_stream = pkt_stream_clone(umem, test->pkt_stream_default); + for (i = 0; i < test->pkt_stream_default->nb_pkts; i += 2) { + pkt_stream->pkts[i].addr = (i % umem->num_frames) * umem->frame_size + offset; + pkt_stream->pkts[i].len = pkt_len; + } + + test->ifobj_tx->pkt_stream = pkt_stream; + test->ifobj_rx->pkt_stream = pkt_stream; } static struct pkt *pkt_generate(struct ifobject *ifobject, u32 pkt_nb) @@ -572,9 +584,9 @@ static void pkt_dump(void *pkt, u32 len) fprintf(stdout, "---------------------------------------\n"); } -static bool is_pkt_valid(struct pkt *pkt, void *buffer, const struct xdp_desc *desc) +static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len) { - void *data = xsk_umem__get_data(buffer, desc->addr); + void *data = xsk_umem__get_data(buffer, addr); struct iphdr *iphdr = (struct iphdr *)(data + sizeof(struct ethhdr)); if (!pkt) { @@ -588,10 +600,10 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, const struct xdp_desc *d if (opt_pkt_dump) pkt_dump(data, PKT_SIZE); - if (pkt->len != desc->len) { + if (pkt->len != len) { ksft_test_result_fail ("ERROR: [%s] expected length [%d], got length [%d]\n", - __func__, pkt->len, desc->len); + __func__, pkt->len, len); return false; } @@ -673,7 +685,7 @@ static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info * orig = xsk_umem__extract_addr(addr); addr = xsk_umem__add_offset_to_addr(addr); - if (!is_pkt_valid(pkt, xsk->umem->buffer, desc)) + if (!is_pkt_valid(pkt, xsk->umem->buffer, addr, desc->len)) return; *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig; @@ -817,13 +829,16 @@ static void tx_stats_validate(struct ifobject *ifobject) static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject) { + int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; u32 i; ifobject->ns_fd = switch_namespace(ifobject->nsname); + if (ifobject->umem->unaligned_mode) + mmap_flags |= MAP_HUGETLB; + for (i = 0; i < test->nb_sockets; i++) { u64 umem_sz = ifobject->umem->num_frames * ifobject->umem->frame_size; - int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; u32 ctr = 0; void *bufs; @@ -881,6 +896,32 @@ static void *worker_testapp_validate_tx(void *arg) pthread_exit(NULL); } +static void xsk_populate_fill_ring(struct xsk_umem_info *umem, struct pkt_stream *pkt_stream) +{ + u32 idx = 0, i; + int ret; + + ret = xsk_ring_prod__reserve(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS, &idx); + if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS) + exit_with_error(ENOSPC); + for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS; i++) { + u64 addr; + + if (pkt_stream->use_addr_for_fill) { + struct pkt *pkt = pkt_stream_get_pkt(pkt_stream, i); + + if (!pkt) + break; + addr = pkt->addr; + } else { + addr = (i % umem->num_frames) * umem->frame_size + DEFAULT_OFFSET; + } + + *xsk_ring_prod__fill_addr(&umem->fq, idx++) = addr; + } + xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS); +} + static void *worker_testapp_validate_rx(void *arg) { struct test_spec *test = (struct test_spec *)arg; @@ -891,7 +932,7 @@ static void *worker_testapp_validate_rx(void *arg) thread_common_ops(test, ifobject); if (stat_test_type != STAT_TEST_RX_FILL_EMPTY) - xsk_populate_fill_ring(ifobject->umem); + xsk_populate_fill_ring(ifobject->umem, ifobject->pkt_stream); fds.fd = xsk_socket__fd(ifobject->xsk->xsk); fds.events = POLLIN; @@ -1035,6 +1076,40 @@ static void testapp_stats(struct test_spec *test) test_spec_set_name(test, "STATS"); } +/* Simple test */ +static bool hugepages_present(struct ifobject *ifobject) +{ + const size_t mmap_sz = 2 * ifobject->umem->num_frames * ifobject->umem->frame_size; + void *bufs; + + bufs = mmap(NULL, mmap_sz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_HUGETLB, -1, 0); + if (bufs == MAP_FAILED) + return false; + + munmap(bufs, mmap_sz); + return true; +} + +static bool testapp_unaligned(struct test_spec *test) +{ + if (!hugepages_present(test->ifobj_tx)) { + ksft_test_result_skip("No 2M huge pages present.\n"); + return false; + } + + test_spec_set_name(test, "UNALIGNED_MODE"); + test->ifobj_tx->umem->unaligned_mode = true; + test->ifobj_rx->umem->unaligned_mode = true; + /* Let half of the packets straddle a buffer boundrary */ + pkt_stream_replace_half(test, PKT_SIZE, test->ifobj_tx->umem->frame_size - 32); + test->ifobj_rx->pkt_stream->use_addr_for_fill = true; + testapp_validate_traffic(test); + + pkt_stream_restore_default(test); + return true; +} + static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac, const char *dst_ip, const char *src_ip, const u16 dst_port, const u16 src_port, thread_func_t func_ptr) @@ -1086,6 +1161,10 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ test_spec_set_name(test, "POLL"); testapp_validate_traffic(test); break; + case TEST_TYPE_UNALIGNED: + if (!testapp_unaligned(test)) + return; + break; default: break; } diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index e27fe348ae50..129801eb013c 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -39,6 +39,7 @@ #define POLL_TMOUT 1000 #define DEFAULT_PKT_CNT (4 * 1024) #define RX_FULL_RXQSIZE 32 +#define DEFAULT_OFFSET 256 #define XSK_UMEM__INVALID_FRAME_SIZE (XSK_UMEM__DEFAULT_FRAME_SIZE + 1) #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) @@ -52,6 +53,7 @@ enum test_mode { enum test_type { TEST_TYPE_NOPOLL, TEST_TYPE_POLL, + TEST_TYPE_UNALIGNED, TEST_TYPE_TEARDOWN, TEST_TYPE_BIDI, TEST_TYPE_STATS, @@ -81,6 +83,7 @@ struct xsk_umem_info { u32 frame_headroom; void *buffer; u32 frame_size; + bool unaligned_mode; }; struct xsk_socket_info { @@ -102,6 +105,7 @@ struct pkt { struct pkt_stream { u32 nb_pkts; struct pkt *pkts; + bool use_addr_for_fill; }; typedef void *(*thread_func_t)(void *arg); From patchwork Wed Sep 1 10:47:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 505470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ED74C432BE for ; Wed, 1 Sep 2021 10:48:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A21F6101B for ; Wed, 1 Sep 2021 10:48:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243229AbhIAKtw (ORCPT ); Wed, 1 Sep 2021 06:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238584AbhIAKt0 (ORCPT ); Wed, 1 Sep 2021 06:49:26 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A419AC061760; Wed, 1 Sep 2021 03:48:29 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id i3so1526611wmq.3; Wed, 01 Sep 2021 03:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w/EUsXdij3lSByOwN7tFJbAP26Euxi8J8qCeyd1PWMU=; b=qlb0H+nTRnwBTgGZDO4SUQ59o1cPMiA25U3w2BRdVFQdNw62AB1Rrbn/N1o9B0v5T6 /VfkV89FeqEwmJDI1WEhHL1CCUll+SKQK+9xnSVWPFFCbOEo0twTk3/vBtauQoYWx3H8 TpjrT30m9+L1QWCzBoTCt+ZOB3dSzbQ7A2cAv3DrzjSFTcerSVxetbhORcalXd4GCQ7D Uv2RfgHNsY5lYo9gP4oRtgXhUKXMhWnWXy/SuDTrYbRCDMQTy/SzEF6Y69s94vtaKqjC 3hD19uC18nTSKw3o8ZgzObPx1NatPlHAfWMus/jwJgA75dBbpzTHJviP4n3mQaN4Zvng zexg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w/EUsXdij3lSByOwN7tFJbAP26Euxi8J8qCeyd1PWMU=; b=bwhxzrHEwrdMZEE71fckzpj61NePV5O/NPoZjALR+obIIbPDBE/21U+mGfAbPYH8br v1JgDf0RvPvP4m8JWADM/QkgY1oXVSbBDVnPC86y17/odeX3UqUozaoJFZ6s/0KNQc3J Sc562fN6qEf3y+EEH3nF7IND0tOH5rt5Kw1gaOTQUom6w63B5P85eeWmc2CMmYElZ4BD PnUU7+5+kkc/QGiFkSwL/qjHmVrMtxydoahG6ZCHjd1RO7yshfE7LT5KoZidllCGs5CW kaFBxtJ8YJSsc/HiWuCCS8OJQ3xm9bkomVg0huXIciAV2ni3yrNlq0J5Xhh4dtNDVwn5 GjBw== X-Gm-Message-State: AOAM530CJEJDX9kvK5gEDUCYQh7M2c28sf8Y9cdtNRTxFY3T7gezUzqG svLHP0fTRvkl13FX78I/m20pRXT4U0dCy+gu X-Google-Smtp-Source: ABdhPJwi7+GmyjMmJkxgvGpjXP/yyjCa74pcsuZA//4/w0AjBXvrnrnIlx8PXa/S8s6VIczmSqaGwA== X-Received: by 2002:a05:600c:350d:: with SMTP id h13mr8776634wmq.38.1630493308309; Wed, 01 Sep 2021 03:48:28 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id r12sm21530843wrv.96.2021.09.01.03.48.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:27 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next 20/20] selftests: xsk: add tests for 2K frame size Date: Wed, 1 Sep 2021 12:47:32 +0200 Message-Id: <20210901104732.10956-21-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210901104732.10956-1-magnus.karlsson@gmail.com> References: <20210901104732.10956-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Magnus Karlsson Add tests for 2K frame size. Both a standard send and receive test and one testing for invalid descriptors when the frame size is 2K. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 23 +++++++++++++++++++++++ tools/testing/selftests/bpf/xdpxceiver.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index a4f6ce3a6b14..8e4cb781a3e3 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -48,6 +48,7 @@ * g. unaligned mode * h. tests for invalid and corner case Tx descriptors so that the correct ones * are discarded and let through, respectively. + * i. 2K frame size tests * * Total tests: 12 * @@ -1203,6 +1204,8 @@ static void testapp_inv_desc(struct test_spec *test) {UMEM_SIZE - PKT_SIZE / 2, PKT_SIZE, 0, false}, /* Straddle a page boundrary */ {0x3000 - PKT_SIZE / 2, PKT_SIZE, 0, false}, + /* Straddle a 2K boundrary */ + {0x3800 - PKT_SIZE / 2, PKT_SIZE, 0, true}, /* Valid packet for synch so that something is received */ {0x4000, PKT_SIZE, 0, true}}; @@ -1210,6 +1213,11 @@ static void testapp_inv_desc(struct test_spec *test) /* Crossing a page boundrary allowed */ pkts[6].valid = true; } + if (test->ifobj_tx->umem->frame_size == XSK_UMEM__DEFAULT_FRAME_SIZE / 2) { + /* Crossing a 2K frame size boundrary not allowed */ + pkts[7].valid = false; + } + pkt_stream_set(test, pkts, ARRAY_SIZE(pkts)); testapp_validate_traffic(test); pkt_stream_restore_default(test); @@ -1260,6 +1268,15 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ test_spec_set_name(test, "RUN_TO_COMPLETION"); testapp_validate_traffic(test); break; + case TEST_TYPE_RUN_TO_COMPLETION_2K_FRAME: + test_spec_set_name(test, "RUN_TO_COMPLETION_2K_FRAME_SIZE"); + test->ifobj_tx->umem->frame_size = 2048; + test->ifobj_rx->umem->frame_size = 2048; + pkt_stream_replace(test, DEFAULT_PKT_CNT, MIN_PKT_SIZE); + testapp_validate_traffic(test); + + pkt_stream_restore_default(test); + break; case TEST_TYPE_POLL: test->ifobj_tx->use_poll = true; test->ifobj_rx->use_poll = true; @@ -1270,6 +1287,12 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ test_spec_set_name(test, "ALIGNED_INV_DESC"); testapp_inv_desc(test); break; + case TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME: + test_spec_set_name(test, "ALIGNED_INV_DESC_2K_FRAME_SIZE"); + test->ifobj_tx->umem->frame_size = 2048; + test->ifobj_rx->umem->frame_size = 2048; + testapp_inv_desc(test); + break; case TEST_TYPE_UNALIGNED_INV_DESC: test_spec_set_name(test, "UNALIGNED_INV_DESC"); test->ifobj_tx->umem->unaligned_mode = true; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 2d9efb89ea28..5ac4a5e64744 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -54,9 +54,11 @@ enum test_mode { enum test_type { TEST_TYPE_RUN_TO_COMPLETION, + TEST_TYPE_RUN_TO_COMPLETION_2K_FRAME, TEST_TYPE_POLL, TEST_TYPE_UNALIGNED, TEST_TYPE_ALIGNED_INV_DESC, + TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME, TEST_TYPE_UNALIGNED_INV_DESC, TEST_TYPE_TEARDOWN, TEST_TYPE_BIDI,