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: 12469103 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 39F30C4320E for ; Wed, 1 Sep 2021 10:48:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F7456101B for ; Wed, 1 Sep 2021 10:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237758AbhIAKs7 (ORCPT ); Wed, 1 Sep 2021 06:48:59 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469105 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 6EBD1C4320A for ; Wed, 1 Sep 2021 10:48:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58E576101B for ; Wed, 1 Sep 2021 10:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238264AbhIAKtB (ORCPT ); Wed, 1 Sep 2021 06:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238220AbhIAKs7 (ORCPT ); Wed, 1 Sep 2021 06:48:59 -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 08F76C061575; Wed, 1 Sep 2021 03:48:03 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 79-20020a1c0452000000b002e6cf79e572so4431280wme.1; Wed, 01 Sep 2021 03:48:02 -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=LBCLQ/6Mm7ekbNtZBIv/c8fxdC6nOz1HbQAiHRTgx0g=; b=ZEnjJcFYORGgT+J0wQVjra8VTmpsmi0pvnV6T5obZ+WpQhcUJWk7TCj7lgBFGncQ20 ht194BCbSifaEgmeO/RRS/X8nwaEeZUpyvZpWFKJjC8nG706dY2vv/UT3/O5UtNkNIho /Ff2+wZvVMl6AtQEHNk0ckyawFYcKpOt1iIwpcqjK+xIc+NjBV4xaNvDDiqDRz0PLa8k q/FntJaNlY7sqT2UyDC7QrUMIWfYDFEOfF0S2CToqp0MKEIdFQ6VXZBwcIt2h4AUz9nT /sVpaHITbrdFczpvmQU4tG5Y+r0RZ7H4050/QVMP/LNNumUt61JSl6k+8CbVwVNcPpOz sCIg== 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=LBCLQ/6Mm7ekbNtZBIv/c8fxdC6nOz1HbQAiHRTgx0g=; b=RFk9/3vIrDTR3UEjH4bU32zzAr8pUFMHRZfIYIkztIzH68n3siD7u6nKQX1izUsTjY u9eFjwger4X5NNdSo3dwmNpptn/SkDNb+qBIa+GV/t+I2HjjHYKVwcvgjHJXdgnrmRRo jxtj3aS6xY66gOo0+uQgWDsP/huf4Brp8TkIEddNLIMpMYsfGKmFIiR/V2sSDiXU3eJV nPt+qTd9InS5HtXWaICMy14Admi0XIe7tO3hn27u5Qz0bPsXVfABpIwje41gOgKE5DmM ePZannTgmp6r4mKrJYtTVrBJ2cdtGrU20i1L0Ph7UZvCh/cob4GrQHWJdcK20zlz+QKc j/eA== X-Gm-Message-State: AOAM533FRXY05Zi9a88QQ4RKQDk2o5IDbqyKMjw7HklxTWzN8kESHO8T 3lkiSJZi7uptt1y/kM9e0NY= X-Google-Smtp-Source: ABdhPJyuKOCq7Xaolvs9june/9UitI6/va9SBx01WJ0mzjULmMLCaEYZVXRkV6Nr/NJ6r1TjKjbMJw== X-Received: by 2002:a7b:cc0a:: with SMTP id f10mr9172896wmh.32.1630493281665; Wed, 01 Sep 2021 03:48:01 -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.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:01 -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 02/20] selftests: xsk: introduce type for thread function Date: Wed, 1 Sep 2021 12:47:14 +0200 Message-Id: <20210901104732.10956-3-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Introduce a typedef of the thread function so this can be passed to init_iface() in order to simplify that function. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend --- tools/testing/selftests/bpf/xdpxceiver.c | 25 ++++++++++++------------ tools/testing/selftests/bpf/xdpxceiver.h | 4 +++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 9639d8da516d..edf5b6cc6998 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -974,10 +974,9 @@ static void testapp_stats(void) print_ksft_result(); } -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) +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) { struct in_addr ip; @@ -993,15 +992,13 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, ifobj->dst_port = dst_port; ifobj->src_port = src_port; - if (vector == tx) { - ifobj->fv.vector = tx; - ifobj->func_ptr = worker_testapp_validate_tx; + if (vector == tx) ifdict_tx = ifobj; - } else { - ifobj->fv.vector = rx; - ifobj->func_ptr = worker_testapp_validate_rx; + else ifdict_rx = ifobj; - } + + ifobj->fv.vector = vector; + ifobj->func_ptr = func_ptr; } static void run_pkt_test(int mode, int type) @@ -1097,8 +1094,10 @@ int main(int argc, char **argv) parse_command_line(argc, argv); - init_iface(ifdict[tx], MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx); - init_iface(ifdict[rx], MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx); + init_iface(ifdict[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, + 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 de80516ac6c2..799d524eb425 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -116,6 +116,8 @@ struct pkt_stream { struct pkt *pkts; }; +typedef void *(*thread_func_t)(void *arg); + struct ifobject { char ifname[MAX_INTERFACE_NAME_CHARS]; char nsname[MAX_INTERFACES_NAMESPACE_CHARS]; @@ -123,8 +125,8 @@ struct ifobject { 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; + thread_func_t func_ptr; struct pkt_stream *pkt_stream; int ns_fd; u32 dst_ip; 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: 12469107 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 85B6BC432BE for ; Wed, 1 Sep 2021 10:48:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64BFD6101B for ; Wed, 1 Sep 2021 10:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238449AbhIAKtM (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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469109 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 329BAC4320E 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 1A09E6101B for ; Wed, 1 Sep 2021 10:48:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238508AbhIAKtM (ORCPT ); Wed, 1 Sep 2021 06:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238503AbhIAKtD (ORCPT ); Wed, 1 Sep 2021 06:49:03 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29F4BC0613D9; Wed, 1 Sep 2021 03:48:06 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u9so3759768wrg.8; Wed, 01 Sep 2021 03:48:06 -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=VYemDfoFJkbmNEC9H7yRs+ZUmABQpgI96O+Pn7J+DyY=; b=Og9YRqsrE55OIjZ5YByDdHuFagwuCDv75XoNTe++cZJ4CrM6DXMcIlONBC5c3GpE46 0ZWkN7bniPtg8Zc8UgRRJr1YMaw0KkwRyNWOAKeQK78+m8gP+WZz0b2b523h6oTVGSWG vZvKWINiy9DjgpYe1+LotrWaH4hDw5jhNiURPAXzaMNncnzES8Xg1u4R7redVVquJ+FP hugKUzr1IxUVsUsmp188ixXa7U+ssMtkRVVi9ye/qj6GvFwyDQp3eNmbH5vp/wh50bzE R6KYx37QC6tjwqEmPs5uOFykrY38DD1TQI7NeSuJ3m5fkg42cvXyqn09HHZ5ZX3/VINk sWzA== 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=VYemDfoFJkbmNEC9H7yRs+ZUmABQpgI96O+Pn7J+DyY=; b=n/tBc20O5PS9zB92RELO2GUL+pgI/iSPdOwzLC01zDadG2lbQBOa5qiWP1vp0HewWA M3ID7aBYJlwCdADiiLhg0BeL99FW4TNAuf8f4v3mdrlkpOVLRTAqyeHP1DmdyWOLeXId 8936rlNOFKXNE9MaA0CWFEjzpyinStv0g0xkuG2DAK1QfkQZ0ozpAghUGWbP0qaUUerZ kfyAGHxluJ2sngjWJpJbGkjt1wMQp/nZly006JVppPOWVG07N7+xnzXypvd/EZXH0hsb 1EYn4tn2hnY/A4kQDMW2DBlsMFMV+EfuqLy7OJB2GTsr6IPCbUoJGBkKHmQ3nWWwI4yk 9mqg== X-Gm-Message-State: AOAM531aEOszNYgxZLCHZuCLwsl9qzN3RRN2IDt9UPN9gVzGWMGuesR2 sQpFq0niLElQ6bFqsACo2fM= X-Google-Smtp-Source: ABdhPJzFdDgzoPRxuPuptatHyq1sWQ0WPRYnqaj3J+SQKSpKFI5AkkWx2ZJjEcBPjzDyEClFa3XM+g== X-Received: by 2002:a05:6000:1563:: with SMTP id 3mr36577936wrz.139.1630493284755; Wed, 01 Sep 2021 03:48:04 -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.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:04 -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 04/20] selftests: xsk: move num_frames and frame_headroom to xsk_umem_info Date: Wed, 1 Sep 2021 12:47:16 +0200 Message-Id: <20210901104732.10956-5-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Move the global variables num_frames and frame_headroom to struct xsk_umem_info. They describe properties of the umem so no reason for them to be global. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 20 ++++++++++---------- tools/testing/selftests/bpf/xdpxceiver.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index a6bcc7453860..56ee03fda2b3 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -241,7 +241,7 @@ static int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, .frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE, - .frame_headroom = frame_headroom, + .frame_headroom = umem->frame_headroom, .flags = XSK_UMEM__DEFAULT_FLAGS }; int ret; @@ -406,6 +406,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, 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])); + ifobj->umem_arr[j].num_frames = DEFAULT_PKT_CNT / 4; } } @@ -433,7 +434,7 @@ static struct pkt *pkt_stream_get_pkt(struct pkt_stream *pkt_stream, u32 pkt_nb) return &pkt_stream->pkts[pkt_nb]; } -static struct pkt_stream *pkt_stream_generate(u32 nb_pkts, u32 pkt_len) +static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb_pkts, u32 pkt_len) { struct pkt_stream *pkt_stream; u32 i; @@ -448,7 +449,7 @@ static struct pkt_stream *pkt_stream_generate(u32 nb_pkts, u32 pkt_len) pkt_stream->nb_pkts = nb_pkts; for (i = 0; i < nb_pkts; i++) { - pkt_stream->pkts[i].addr = (i % num_frames) * XSK_UMEM__DEFAULT_FRAME_SIZE; + pkt_stream->pkts[i].addr = (i % umem->num_frames) * XSK_UMEM__DEFAULT_FRAME_SIZE; pkt_stream->pkts[i].len = pkt_len; pkt_stream->pkts[i].payload = i; } @@ -766,7 +767,7 @@ static void tx_stats_validate(struct ifobject *ifobject) static void thread_common_ops(struct ifobject *ifobject, void *bufs) { - u64 umem_sz = num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; + u64 umem_sz = ifobject->umem->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, ret; @@ -885,9 +886,10 @@ static void testapp_validate_traffic(struct test_spec *test) exit_with_error(errno); if (stat_test_type == STAT_TEST_TX_INVALID) - pkt_stream = pkt_stream_generate(DEFAULT_PKT_CNT, XSK_UMEM__INVALID_FRAME_SIZE); + pkt_stream = pkt_stream_generate(test->ifobj_tx->umem, DEFAULT_PKT_CNT, + XSK_UMEM__INVALID_FRAME_SIZE); else - pkt_stream = pkt_stream_generate(DEFAULT_PKT_CNT, PKT_SIZE); + 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; @@ -988,12 +990,11 @@ static void testapp_stats(struct test_spec *test) /* reset defaults */ rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; - frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM; switch (stat_test_type) { case STAT_TEST_RX_DROPPED: - frame_headroom = XSK_UMEM__DEFAULT_FRAME_SIZE - - XDP_PACKET_HEADROOM - 1; + 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; @@ -1040,7 +1041,6 @@ static void run_pkt_test(struct test_spec *test, int mode, int type) second_step = 0; stat_test_type = -1; rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; - frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM; configured_mode = mode; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index e279aa893438..0d93a9e6c4f3 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -71,7 +71,6 @@ enum stat_test_type { static int configured_mode; static bool opt_pkt_dump; -static u32 num_frames = DEFAULT_PKT_CNT / 4; static bool second_step; static int test_type; @@ -81,12 +80,13 @@ 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; -static u32 frame_headroom; struct xsk_umem_info { struct xsk_ring_prod fq; struct xsk_ring_cons cq; struct xsk_umem *umem; + u32 num_frames; + u32 frame_headroom; void *buffer; }; 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: 12469111 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 DF8A2C43214 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 C865761053 for ; Wed, 1 Sep 2021 10:48:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238529AbhIAKtN (ORCPT ); Wed, 1 Sep 2021 06:49:13 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469119 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 4CCC6C43214 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 375DE6101B for ; Wed, 1 Sep 2021 10:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238503AbhIAKtP (ORCPT ); Wed, 1 Sep 2021 06:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238597AbhIAKtL (ORCPT ); Wed, 1 Sep 2021 06:49:11 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C693C0617AD; Wed, 1 Sep 2021 03:48:09 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n5so3732090wro.12; Wed, 01 Sep 2021 03:48:09 -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=Uaulvf/dGdDSmW0mxusxiglw2RgbgacnhYhdb6gP9+8=; b=HM/BJfmKQDj5rdztP1MTuE1iVYOND/Wu+FlEPN47rY26p8sp/hG13XxIUSGhqJcrMT Y8z4YxuoZM1UTZMTDkeF/ol06LtJaZHtgT3pvuJ6kv4dL/14Xqmu7Zv6cx6kakTXsX9F YiRH56EoLuGn5jmm5+q+q8YyvAox62lVG2KDncqKf1qcHnOMMYNt0m0tjN5ylb8bTPXn Tyx3XXG+jRstAQenENkD/P3sQ4FwbEsnjbourott6/RjmJY6veSQ77DADjUCJda1d2zO 6gysDSVv/c+hBvFAjmcnvDto2bejpuyOvho/Pv/43Z86aE0EsMvkVAQKXwy+Tm0L1CL2 F2ag== 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=Uaulvf/dGdDSmW0mxusxiglw2RgbgacnhYhdb6gP9+8=; b=REjLTK0THPLLKzMJ5jTCHtVMA/A1hkpRudqT6MDkFQel7KilFQVokti0ytwKSbirQz 9v+HNHxkBs56MDkLjGbzX1rUqFelDsAQBPCMdAvzj4iAqmjDWGC7NYq+CD5gLvSYxlRb gZEqpmmmQoFC/aMoR8XCjwIjRdq9iOdzCJtmiFc5FKkBcfBwE1eOg3RB1Vp1fgxMF7dM DDvB412rKwq49j0z/ZVP7FxKEj4zHb8GOTHkgj4X03R/Bg579m4+tOP04Y9a9kFBK+9v 9bewg4a1I3CKocmIe0geX6KqMX99TvyhTOmC/TCvAA4eGarn/SpVtY16bF7sa1lBYEgt ugRQ== X-Gm-Message-State: AOAM532xM32k1ahb9po45XGwI6LZIC4Zbzx8C2Rj2bXm+4DyTjb8tp7H yuHh1ZifKJ6fcqeXQ1aJ/nc= X-Google-Smtp-Source: ABdhPJzRmfhST8YXeCbe+om1NKk0maID0DyoXpkAYJw+z3HawYYc4+KwgVJ55cHvoLJlqXfDZcEA1g== X-Received: by 2002:adf:c381:: with SMTP id p1mr36884156wrf.163.1630493287885; Wed, 01 Sep 2021 03:48:07 -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.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:07 -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 06/20] selftests: xsk: make frame_size configurable Date: Wed, 1 Sep 2021 12:47:18 +0200 Message-Id: <20210901104732.10956-7-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Make the frame size configurable instead of it being hard coded to a default. This is a property of the umem and will make it possible to implement tests for different umem frame sizes in a later patch. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 11 ++++++----- tools/testing/selftests/bpf/xdpxceiver.h | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 28bf62c56190..79cf082a7581 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -240,7 +240,7 @@ static int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size struct xsk_umem_config cfg = { .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, - .frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE, + .frame_size = umem->frame_size, .frame_headroom = umem->frame_headroom, .flags = XSK_UMEM__DEFAULT_FLAGS }; @@ -264,7 +264,7 @@ static void xsk_populate_fill_ring(struct xsk_umem_info *umem) 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 * XSK_UMEM__DEFAULT_FRAME_SIZE; + *xsk_ring_prod__fill_addr(&umem->fq, idx++) = i * umem->frame_size; xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS); } @@ -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->umem_arr[j].frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE; ifobj->xsk_arr[j].rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; } } @@ -450,7 +451,7 @@ 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) * XSK_UMEM__DEFAULT_FRAME_SIZE; + 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; } @@ -768,7 +769,7 @@ static void tx_stats_validate(struct ifobject *ifobject) static void thread_common_ops(struct ifobject *ifobject, void *bufs) { - u64 umem_sz = ifobject->umem->num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; + 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; @@ -991,7 +992,7 @@ static void testapp_stats(struct test_spec *test) switch (stat_test_type) { case STAT_TEST_RX_DROPPED: - test->ifobj_rx->umem->frame_headroom = XSK_UMEM__DEFAULT_FRAME_SIZE - + test->ifobj_rx->umem->frame_headroom = test->ifobj_rx->umem->frame_size - XDP_PACKET_HEADROOM - 1; break; case STAT_TEST_RX_FULL: diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 09e4e015b1bf..bfd14190abfc 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -87,6 +87,7 @@ struct xsk_umem_info { u32 num_frames; u32 frame_headroom; void *buffer; + u32 frame_size; }; struct xsk_socket_info { From patchwork Wed Sep 1 10:47:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469113 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 CD25BC43216 for ; Wed, 1 Sep 2021 10:48:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8F6261053 for ; Wed, 1 Sep 2021 10:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238722AbhIAKtN (ORCPT ); Wed, 1 Sep 2021 06:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238616AbhIAKtL (ORCPT ); Wed, 1 Sep 2021 06:49:11 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2D21C0617AE; Wed, 1 Sep 2021 03:48:10 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id g138so1526420wmg.4; Wed, 01 Sep 2021 03:48:10 -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=0ixB0LYGzpliqsf1socDA0N46Acr6XB3D+s9pcpc6tY=; b=ejEZvm29I27jmqXIm9Roh6ukIF+9mF/t+FBt61jwq80F/1vYRpiepIc/ca6EVgDcDc g0ECNHJfsxeLTZESSxiHZmIrg9FHWEyWe0MEAU0yOmOmOveYVOw+QwEkg0m7xZXWqBc8 QYTUsAUhRGylR0ejmb5Gu8P30r7ytc1xVjN1qNgaObZIu+uHL9M0j9LwnZGhx8JOMvyJ rxPJEqmbOIOrHUngygKsRbaUCzWSfMXFq87TL1zKGgJU7YT3YnUzUlnFcj87N9qT2NDr UznbqkloEGi4t86LbxCQwsgwFXbr99Q5a+GfxVFimippRNYUDgHx/Ynl2weKOc87iKYN PluA== 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=0ixB0LYGzpliqsf1socDA0N46Acr6XB3D+s9pcpc6tY=; b=cx1I2n0Whu+2D/6uxsJYrolTmCFIqTyBIpGQxHr8Znxep6lvb3oQwropJtY47nnz5T ELOSqX0EmbJ4SCUSqYjtRhj3L1Dce1Mzk/DtzLv7OtMWyQRDjcPCKuJBLhuFdG/f+dkw SfaNS4WZor51/eTSC9bdG/SPY7PQt4rFhy+O/w/ooq6vmUDFD0A6Ki0qhga2kdKNDQ+e wRQEgGFVQa54IOsLRPb0Eg3EGFpyMFOBPMSn3cmP7sJ1r2VKmfQJSN61MCsPsNgmhxm9 ib5RwtPrdT2Xt+TclAKv0m0yW4MBpQLwFEy9hMjGDq0mLGbdQt27YbQYsJOBbeRi9vxJ 7yIQ== X-Gm-Message-State: AOAM533/cRE5iuSw39yx81sEnU8+AmLfhP79+YFHK7RNVN4lTf5U0CbP /gAWzLUpL+p5fMVQ5ZjW4So= X-Google-Smtp-Source: ABdhPJyEGQZmh4q+RejPQDBGcBPGxKT2T8irlEVAfEJOnySEOma3MaMVE4pSZ57BxYW2xj4aaQZR6A== X-Received: by 2002:a05:600c:2256:: with SMTP id a22mr9126822wmm.16.1630493289320; Wed, 01 Sep 2021 03:48:09 -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.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:08 -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 07/20] selftests: xsx: introduce test name in test spec Date: Wed, 1 Sep 2021 12:47:19 +0200 Message-Id: <20210901104732.10956-8-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Introduce the test name in the test specification. This so we can set the name locally in the test function and simplify the logic for printing out test results. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 49 ++++++++++++++---------- tools/testing/selftests/bpf/xdpxceiver.h | 2 + 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 79cf082a7581..8ef58081d4d2 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -112,13 +112,9 @@ static void __exit_with_error(int error, const char *file, const char *func, int #define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__) -#define print_ksft_result(void)\ - (ksft_test_result_pass("PASS: %s %s %s%s%s%s\n", configured_mode ? "DRV" : "SKB",\ - test_type == TEST_TYPE_POLL ? "POLL" : "NOPOLL",\ - test_type == TEST_TYPE_TEARDOWN ? "Socket Teardown" : "",\ - test_type == TEST_TYPE_BIDI ? "Bi-directional Sockets" : "",\ - test_type == TEST_TYPE_STATS ? "Stats" : "",\ - test_type == TEST_TYPE_BPF_RES ? "BPF RES" : "")) +#define print_ksft_result(test)\ + (ksft_test_result_pass("PASS: %s %s\n", configured_mode ? "DRV" : "SKB", \ + (test)->name)) static void memset32_htonl(void *dest, u32 val, u32 size) { @@ -428,6 +424,11 @@ static void test_spec_reset(struct test_spec *test) __test_spec_init(test, test->ifobj_tx, test->ifobj_rx); } +static void test_spec_set_name(struct test_spec *test, const char *name) +{ + strncpy(test->name, name, MAX_TEST_NAME_SIZE); +} + static struct pkt *pkt_stream_get_pkt(struct pkt_stream *pkt_stream, u32 pkt_nb) { if (pkt_nb >= pkt_stream->nb_pkts) @@ -880,8 +881,6 @@ 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; if (pthread_barrier_init(&barr, NULL, 2)) @@ -907,21 +906,17 @@ static void testapp_validate_traffic(struct test_spec *test) pthread_join(t1, NULL); pthread_join(t0, NULL); - - if (!(test_type == TEST_TYPE_TEARDOWN) && !bidi && !bpf && !(test_type == TEST_TYPE_STATS)) - print_ksft_result(); } static void testapp_teardown(struct test_spec *test) { int i; + test_spec_set_name(test, "TEARDOWN"); for (i = 0; i < MAX_TEARDOWN_ITER; i++) { testapp_validate_traffic(test); test_spec_reset(test); } - - print_ksft_result(); } static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2) @@ -942,6 +937,7 @@ static void swap_directions(struct ifobject **ifobj1, struct ifobject **ifobj2) static void testapp_bidi(struct test_spec *test) { + test_spec_set_name(test, "BIDIRECTIONAL"); for (int i = 0; i < MAX_BIDI_ITER; i++) { print_verbose("Creating socket\n"); testapp_validate_traffic(test); @@ -953,8 +949,6 @@ static void testapp_bidi(struct test_spec *test) } swap_directions(&test->ifobj_rx, &test->ifobj_tx); - - print_ksft_result(); } static void swap_xsk_resources(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx) @@ -973,6 +967,7 @@ 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); @@ -980,8 +975,6 @@ static void testapp_bpf_res(struct test_spec *test) swap_xsk_resources(test->ifobj_tx, test->ifobj_rx); second_step = true; } - - print_ksft_result(); } static void testapp_stats(struct test_spec *test) @@ -992,21 +985,28 @@ static void testapp_stats(struct test_spec *test) switch (stat_test_type) { case STAT_TEST_RX_DROPPED: + test_spec_set_name(test, "STAT_RX_DROPPED"); test->ifobj_rx->umem->frame_headroom = test->ifobj_rx->umem->frame_size - XDP_PACKET_HEADROOM - 1; break; case STAT_TEST_RX_FULL: + test_spec_set_name(test, "STAT_RX_FULL"); test->ifobj_rx->xsk->rxqsize = RX_FULL_RXQSIZE; break; case STAT_TEST_TX_INVALID: + test_spec_set_name(test, "STAT_TX_INVALID"); continue; + case STAT_TEST_RX_FILL_EMPTY: + test_spec_set_name(test, "STAT_RX_FILL_EMPTY"); + break; default: break; } testapp_validate_traffic(test); } - print_ksft_result(); + /* To only see the whole stat set being completed unless an individual test fails. */ + test_spec_set_name(test, "STATS"); } static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *src_mac, @@ -1066,10 +1066,19 @@ static void run_pkt_test(struct test_spec *test, int mode, int type) case TEST_TYPE_BPF_RES: testapp_bpf_res(test); break; - default: + case TEST_TYPE_NOPOLL: + test_spec_set_name(test, "RUN_TO_COMPLETION"); + testapp_validate_traffic(test); + break; + case TEST_TYPE_POLL: + test_spec_set_name(test, "POLL"); testapp_validate_traffic(test); break; + default: + break; } + + print_ksft_result(test); } static struct ifobject *ifobject_create(void) diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index bfd14190abfc..15eab31b3b32 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -22,6 +22,7 @@ #define MAX_INTERFACES_NAMESPACE_CHARS 10 #define MAX_SOCKS 1 #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 @@ -141,6 +142,7 @@ struct ifobject { struct test_spec { struct ifobject *ifobj_tx; struct ifobject *ifobj_rx; + char name[MAX_TEST_NAME_SIZE]; }; /*threads*/ 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: 12469115 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 A1FFFC00143 for ; Wed, 1 Sep 2021 10:48:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E7BD6101B for ; Wed, 1 Sep 2021 10:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238526AbhIAKtO (ORCPT ); Wed, 1 Sep 2021 06:49:14 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12469123 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 7F7F1C00143 for ; Wed, 1 Sep 2021 10:48:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7067461053 for ; Wed, 1 Sep 2021 10:48:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238955AbhIAKtS (ORCPT ); Wed, 1 Sep 2021 06:49:18 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12469117 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 43099C4320E for ; Wed, 1 Sep 2021 10:48:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A80961053 for ; Wed, 1 Sep 2021 10:48:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238789AbhIAKtP (ORCPT ); Wed, 1 Sep 2021 06:49:15 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469121 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 7D46DC4320A 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 685D561053 for ; Wed, 1 Sep 2021 10:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238588AbhIAKtQ (ORCPT ); Wed, 1 Sep 2021 06:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238369AbhIAKtN (ORCPT ); Wed, 1 Sep 2021 06:49:13 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94923C061575; Wed, 1 Sep 2021 03:48:16 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q11so3759151wrr.9; Wed, 01 Sep 2021 03:48:16 -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=oAGNrcNQYB84HhuUPlRuztgCCKVcBp6IrQtcuLVdXys=; b=g0gPYrAjEn/k9T34vrgJ+84475LkGmGMxziz3pbvQPaSLtv76lDJ0GleWfS3055dEl TOHtrMxS37EsJ+RmDA9QiUlJM2J/ySWeMKC8/mqvSGhpTktVvMyODtnOHzy7mYAMxbgC yhUrLtHVZyIrWlvIEEy9jaytqyqNiPy1KyHjENScNw6/xMqVEHWCesUxBCWrM4yj4NzW nTJGBj8HaLE6q7zevYCwhU4G5jsu1E3tFjlEIA4jIAJphkI7pA/0v9qk48E1Rua2MVTE AOOO3UUVHzhS3VWP589++NmMJBmWgDO8l6i02XaA1Tmezz5OgZVcOYywQHpIUMEb2HqV k3aQ== 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=oAGNrcNQYB84HhuUPlRuztgCCKVcBp6IrQtcuLVdXys=; b=KNjjPKDxob5FkCt+ciHBrXagZ6SbWsrVmU2ItiWWouq8giWj8ZiRJh4AArPF0FNLUC 9oVksIlSfxN+iNafuFJaALmkPtb9O1TUwGPbDZhUJ1iMWRDJ49huMG8QsNkqZUwofLP7 Ifhl8oSb7qSGM8/w+fm7DHGD8emfdX30D21gU6koOdx0hTWHvqTdLZ5CZLpioFejSdge GuSDW/JOFLj/BRFZt1K6cPf6cowFUdNTgRav/OvSTn6dPwN84aoersOYwwj+1Ot3f2c2 B/mLm6WbI66dqdxLRcurO+LKlyI/JlLiDPcYZGCxee/UTDAWX0/gGz2TdL/5yXvPX/9O ulTA== X-Gm-Message-State: AOAM531lqpFMg59oolwAg3Mu8U1CR+CIKgnrOvtPL78ZYPn/XvDkfehv dta3cvv5wLDQifbfT9sDCpA= X-Google-Smtp-Source: ABdhPJySM4erWAWwCOFzvGXEiLMIqUlFLRnf1BQQZcNEr37bwYfNgzbXL2XRWioMfm9WEqPvwh09pw== X-Received: by 2002:a05:6000:1248:: with SMTP id j8mr37869580wrx.97.1630493295218; Wed, 01 Sep 2021 03:48:15 -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.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:14 -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 11/20] selftests: xsk: specify number of sockets to create Date: Wed, 1 Sep 2021 12:47:23 +0200 Message-Id: <20210901104732.10956-12-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Add the ability in the test specification to specify numbers of sockets to create. The default is one socket. This is then used to remove test specific if-statements around the bpf_res tests. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 59 +++++++++++------------- tools/testing/selftests/bpf/xdpxceiver.h | 2 +- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 0a3e28c9e2a9..06fa767191af 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -231,7 +231,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 int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size, int idx) +static int xsk_configure_umem(struct xsk_umem_info *umem, void *buffer, u64 size) { struct xsk_umem_config cfg = { .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, @@ -410,6 +410,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, test->ifobj_rx = ifobj_rx; test->current_step = 0; test->total_steps = 1; + test->nb_sockets = 1; } static void test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, @@ -770,46 +771,37 @@ static void tx_stats_validate(struct ifobject *ifobject) 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; + u32 i; ifobject->ns_fd = switch_namespace(ifobject->nsname); - if (test_type == TEST_TYPE_BPF_RES) - mmap_sz *= 2; - - bufs = mmap(NULL, mmap_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0); - if (bufs == MAP_FAILED) - exit_with_error(errno); + 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; - while (ctr++ < SOCK_RECONF_CTR) { - ret = xsk_configure_umem(&ifobject->umem_arr[0], bufs, umem_sz, 0); - if (ret) - exit_with_error(-ret); + bufs = mmap(NULL, umem_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0); + if (bufs == MAP_FAILED) + exit_with_error(errno); - ret = xsk_configure_socket(&ifobject->xsk_arr[0], &ifobject->umem_arr[0], - ifobject, 0); - if (!ret) - break; + while (ctr++ < SOCK_RECONF_CTR) { + int ret; - /* Retry Create Socket if it fails as xsk_socket__create() is asynchronous */ - if (ctr >= SOCK_RECONF_CTR) - exit_with_error(-ret); - usleep(USLEEP_MAX); - } + ret = xsk_configure_umem(&ifobject->umem_arr[i], bufs, umem_sz); + if (ret) + exit_with_error(-ret); - if (test_type == TEST_TYPE_BPF_RES) { - 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[i], &ifobject->umem_arr[i], + ifobject, i); + if (!ret) + break; - ret = xsk_configure_socket(&ifobject->xsk_arr[1], &ifobject->umem_arr[1], - ifobject, 1); - if (ret) - exit_with_error(-ret); + /* Retry if it fails as xsk_socket__create() is asynchronous */ + if (ctr >= SOCK_RECONF_CTR) + exit_with_error(-ret); + usleep(USLEEP_MAX); + } } ifobject->umem = &ifobject->umem_arr[0]; @@ -959,6 +951,7 @@ static void testapp_bpf_res(struct test_spec *test) { test_spec_set_name(test, "BPF_RES"); test->total_steps = 2; + test->nb_sockets = 2; testapp_validate_traffic(test); swap_xsk_resources(test->ifobj_tx, test->ifobj_rx); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index ea505a4cb8c0..c09b73fd9878 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_BPF_ITER 2 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \ sizeof(struct udphdr)) #define MIN_PKT_SIZE 64 @@ -137,6 +136,7 @@ struct test_spec { struct ifobject *ifobj_rx; u16 total_steps; u16 current_step; + u16 nb_sockets; char name[MAX_TEST_NAME_SIZE]; }; From patchwork Wed Sep 1 10:47:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469125 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 86BE9C432BE for ; Wed, 1 Sep 2021 10:48:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E3556101B for ; Wed, 1 Sep 2021 10:48:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239106AbhIAKtT (ORCPT ); Wed, 1 Sep 2021 06:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238489AbhIAKtP (ORCPT ); Wed, 1 Sep 2021 06:49:15 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12357C061575; Wed, 1 Sep 2021 03:48:18 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x6so3719080wrv.13; Wed, 01 Sep 2021 03:48:17 -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=NNBaqyo/7ZhbzjZjrYIN9gMRh6tHWawhWi2LjamABiA=; b=pljGBccuUErt3ueRXybMYmgik9fQ7/tphhojO49FYyUjMf36/z5X+3mg8RHjq+nRXS VU4sFaEQxsRDhF5NCuH4gj1krDO6seeR2EfpI2OSTtpQ0PGTSyNtzsep2Sx7zb570bwI e5mvd6OfkLN8MpYGywI5uI4qzDAnfxY1YKW4BKiuFQsAwFJUNr59ziItsmu6VZWgIUD1 SNPzLqQwbIpZNvCw5IlHEfqi6SRXQ3lN00ER6l2DqB9NFNKmGUO9R/mRbRs/S4PtSKMk oUUe6B5PlAkqYy3opVn2aZFvChLM0KEj+m9MXcIv5PuhfJGEO5x+eTyauU+DajssVWmc EfYQ== 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=NNBaqyo/7ZhbzjZjrYIN9gMRh6tHWawhWi2LjamABiA=; b=Va1S9OB5P7MTenLBiT5BK8OkoMD3C5aZ93573+5Ttl6XWqoh1ZrReFNQG5Eo9X9EWf 9kX6jig/TYrNIxb/DXiLxBHNLTw0jVs7UaMPsUa3YxazQMVBybhSdfq2QYe2C8JnOicv XewTvWj5bARXmpS+RelRCXtkaOoTzqSySpM/ySutCawjjmqgOxvstPPUEcqWkYkz4Csm IsjTk1Veuf6vbE6gMTH57je+1UJ3Kd/0Ejysb0mI/dT/CcslrLDn4nyaLRBQ+t/RkOMj 0ro2q5r6VC0GGmj9ez82RcHnKeNb2aaaEF/D+jqaqhjM4w+phyByZcNGArkqpK+8o2Vk oehA== X-Gm-Message-State: AOAM530Oj9URQSXUWhPqljuun/F4UdSFzhIuAn4DQnggxnmQj/opfgND mrMUjETEt0oan2kKPLqdVFI= X-Google-Smtp-Source: ABdhPJzff36FiR1lyxEGLYDbVtmdcICN7U2yHFiuq8Mdgil7N4JHN52YTCjF/e2kza+Pwo/zidtoQw== X-Received: by 2002:a5d:44ca:: with SMTP id z10mr9534364wrr.298.1630493296676; Wed, 01 Sep 2021 03:48:16 -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.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:16 -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 12/20] selftests: xsk: make xdp_flags and bind_flags local Date: Wed, 1 Sep 2021 12:47:24 +0200 Message-Id: <20210901104732.10956-13-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Make xdp_flags and bind_flags local instead of global by moving them into the interface object. These flags decide if the socket should be created in SKB mode or in DRV mode and therefore they are sticky and will survive a test_spec_reset. Since every test is first run in SKB mode then in DRV mode, this change only happens once. With this change, the configured_mode global variable can also be erradicated. The first test_spec_init() also becomes superfluous and can be eliminated. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 57 ++++++++++++------------ tools/testing/selftests/bpf/xdpxceiver.h | 6 +-- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 06fa767191af..3a1afece7c2c 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -112,9 +112,10 @@ static void __exit_with_error(int error, const char *file, const char *func, int #define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__) -#define print_ksft_result(test)\ - (ksft_test_result_pass("PASS: %s %s\n", configured_mode ? "DRV" : "SKB", \ - (test)->name)) +#define mode_string(test) (test)->ifobj_tx->xdp_flags & XDP_FLAGS_SKB_MODE ? "SKB" : "DRV" + +#define print_ksft_result(test) \ + (ksft_test_result_pass("PASS: %s %s\n", mode_string(test), (test)->name)) static void memset32_htonl(void *dest, u32 val, u32 size) { @@ -275,8 +276,8 @@ static int xsk_configure_socket(struct xsk_socket_info *xsk, struct xsk_umem_inf cfg.rx_size = xsk->rxqsize; cfg.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS; cfg.libbpf_flags = 0; - cfg.xdp_flags = xdp_flags; - cfg.bind_flags = xdp_bind_flags; + cfg.xdp_flags = ifobject->xdp_flags; + cfg.bind_flags = ifobject->bind_flags; txr = ifobject->tx_on ? &xsk->tx : NULL; rxr = ifobject->rx_on ? &xsk->rx : NULL; @@ -333,7 +334,8 @@ static bool validate_interface(struct ifobject *ifobj) return true; } -static void parse_command_line(struct test_spec *test, int argc, char **argv) +static void parse_command_line(struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, int argc, + char **argv) { struct ifobject *ifobj; u32 interface_nb = 0; @@ -351,9 +353,9 @@ static void parse_command_line(struct test_spec *test, int argc, char **argv) switch (c) { case 'i': if (interface_nb == 0) - ifobj = test->ifobj_tx; + ifobj = ifobj_tx; else if (interface_nb == 1) - ifobj = test->ifobj_rx; + ifobj = ifobj_rx; else break; @@ -414,9 +416,24 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, } static void test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, - struct ifobject *ifobj_rx) + struct ifobject *ifobj_rx, enum test_mode mode) { + u32 i; + memset(test, 0, sizeof(*test)); + + for (i = 0; i < MAX_INTERFACES; i++) { + struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx; + + ifobj->xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; + if (mode == TEST_MODE_SKB) + ifobj->xdp_flags |= XDP_FLAGS_SKB_MODE; + else + ifobj->xdp_flags |= XDP_FLAGS_DRV_MODE; + + ifobj->bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY; + } + __test_spec_init(test, ifobj_tx, ifobj_rx); } @@ -1011,27 +1028,13 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char * ifobj->func_ptr = func_ptr; } -static void run_pkt_test(struct test_spec *test, int mode, int type) +static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_type type) { test_type = type; /* reset defaults after potential previous test */ - xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; stat_test_type = -1; - configured_mode = mode; - - switch (mode) { - case (TEST_MODE_SKB): - xdp_flags |= XDP_FLAGS_SKB_MODE; - break; - case (TEST_MODE_DRV): - xdp_flags |= XDP_FLAGS_DRV_MODE; - break; - default: - break; - } - switch (test_type) { case TEST_TYPE_STATS: testapp_stats(test); @@ -1111,11 +1114,9 @@ int main(int argc, char **argv) if (!ifobj_rx) exit_with_error(ENOMEM); - test_spec_init(&test, ifobj_tx, ifobj_rx); - setlocale(LC_ALL, ""); - parse_command_line(&test, argc, argv); + parse_command_line(ifobj_tx, ifobj_rx, argc, argv); if (!validate_interface(ifobj_tx) || !validate_interface(ifobj_rx)) { usage(basename(argv[0])); @@ -1131,7 +1132,7 @@ int main(int argc, char **argv) for (i = 0; i < TEST_MODE_MAX; i++) for (j = 0; j < TEST_TYPE_MAX; j++) { - test_spec_init(&test, ifobj_tx, ifobj_rx); + test_spec_init(&test, ifobj_tx, ifobj_rx, i); run_pkt_test(&test, i, j); usleep(USLEEP_MAX); } diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index c09b73fd9878..7ed16128f2ad 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -68,14 +68,10 @@ enum stat_test_type { STAT_TEST_TYPE_MAX }; -static int configured_mode; static bool opt_pkt_dump; static int test_type; 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; struct xsk_umem_info { @@ -122,6 +118,8 @@ struct ifobject { int ns_fd; u32 dst_ip; u32 src_ip; + u32 xdp_flags; + u32 bind_flags; u16 src_port; u16 dst_port; bool tx_on; 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: 12469127 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 55C7EC43214 for ; Wed, 1 Sep 2021 10:48:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36A0561054 for ; Wed, 1 Sep 2021 10:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240013AbhIAKtU (ORCPT ); Wed, 1 Sep 2021 06:49:20 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469129 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 A4EB9C432BE for ; Wed, 1 Sep 2021 10:48:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91CAB61058 for ; Wed, 1 Sep 2021 10:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238900AbhIAKtW (ORCPT ); Wed, 1 Sep 2021 06:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234940AbhIAKtT (ORCPT ); Wed, 1 Sep 2021 06:49:19 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBC1CC0617AD; Wed, 1 Sep 2021 03:48:20 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n5so3732944wro.12; Wed, 01 Sep 2021 03:48:20 -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=jbvBnJlz9g2rVA7xQbLe387nO62ZOQvN08wBymbdl88=; b=pvggbBz8v+PIfPRv0vhCeSm9gJsnpp0Z+14xNpV8ZldqOz+yma8mH7/ASCCMoSQiZJ Q+97zVn5auWR7k748bpivGAbSuMXkfMEB5IfbOx7jhRnijarUj3LOsJGR1pgVRJPsHqM g7o8ArQXnIlc7C9RHWFKd/mlakMndwAr2dUpPnwEhNLUqg+PCBQlt1YqvRJKHy3uLm1q kQz5ftADWuciHPX9J6Hy4HYkmu6O2Lo9pA2dVsoqto5oVD88k42YTx9JG+Bo4pBZPdbL 5aubtSaerKL1j5QHpMJ8XJI9NWLsf54LicUO7yu75h6mUhg3feU4CNXTd7ilEypcwWtB LYLw== 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=jbvBnJlz9g2rVA7xQbLe387nO62ZOQvN08wBymbdl88=; b=dCrGnFC+0bKdfcjuQ/aRGn/Y82eNGmDtHuhp9D7WXrCLGVmTr7fZk4wgYBRYbYd0Ec rHonuamdhtDvZVxcmdgV4ujSJ4aDaIoAEuKUYk8vyc9oH/J4wlBX9TMVwvr5IaqjgfBO bSaVnlj1el11gD12Z3voXcGELbOehn5HKUqQpJJSicvnU0+yktSCTw4pJkDfnzi8JJ5k lRnzKpnFoIaldoItn6ScR18FV6fGSFfOJX9ZBnbgMS118LdDGpKreAAJGx1TwlHMsko1 R8nJKZ4iD7mA8bP3xiXioiPWbimM+PwaJ5u4h0wG7po/BqRIfbPqd+um5UGJpCRHjro9 kZew== X-Gm-Message-State: AOAM531OFDsNjt8K8yGU3RoWFp13yYP2MrQrpGE8GA4pLQvQzZrzYrAe GpdRfURWDfyJvsTCQKWe8ZMVhHiTfy9q//Xh X-Google-Smtp-Source: ABdhPJxAAywtj8PO2uZhlpFoS704y+63iiMdNW9pequimLREx/6qqSG8U+da+EJnP9Y5ssDUPEu8+w== X-Received: by 2002:adf:b318:: with SMTP id j24mr36761826wrd.84.1630493299468; Wed, 01 Sep 2021 03:48:19 -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.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:19 -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 14/20] selftests: xsk: eliminate MAX_SOCKS define Date: Wed, 1 Sep 2021 12:47:26 +0200 Message-Id: <20210901104732.10956-15-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Remove the MAX_SOCKS define as it always will be one for the forseable future and the code does not work for any other case anyway. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 18 +++++++++--------- tools/testing/selftests/bpf/xdpxceiver.h | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 5ea78c503741..0fb5cae974de 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -693,11 +693,11 @@ static void wait_for_tx_completion(struct xsk_socket_info *xsk) static void send_pkts(struct ifobject *ifobject) { - struct pollfd fds[MAX_SOCKS] = { }; + struct pollfd fds = { }; u32 pkt_cnt = 0; - fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); - fds[0].events = POLLOUT; + fds.fd = xsk_socket__fd(ifobject->xsk->xsk); + fds.events = POLLOUT; while (pkt_cnt < ifobject->pkt_stream->nb_pkts) { u32 sent; @@ -705,11 +705,11 @@ static void send_pkts(struct ifobject *ifobject) if (ifobject->use_poll) { int ret; - ret = poll(fds, 1, POLL_TMOUT); + ret = poll(&fds, 1, POLL_TMOUT); if (ret <= 0) continue; - if (!(fds[0].revents & POLLOUT)) + if (!(fds.revents & POLLOUT)) continue; } @@ -855,7 +855,7 @@ static void *worker_testapp_validate_rx(void *arg) { struct test_spec *test = (struct test_spec *)arg; struct ifobject *ifobject = test->ifobj_rx; - struct pollfd fds[MAX_SOCKS] = { }; + struct pollfd fds = { }; if (test->current_step == 1) thread_common_ops(test, ifobject); @@ -863,8 +863,8 @@ static void *worker_testapp_validate_rx(void *arg) if (stat_test_type != STAT_TEST_RX_FILL_EMPTY) xsk_populate_fill_ring(ifobject->umem); - fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); - fds[0].events = POLLIN; + fds.fd = xsk_socket__fd(ifobject->xsk->xsk); + fds.events = POLLIN; pthread_barrier_wait(&barr); @@ -872,7 +872,7 @@ static void *worker_testapp_validate_rx(void *arg) while (!rx_stats_are_valid(ifobject)) continue; else - receive_pkts(ifobject->pkt_stream, ifobject->xsk, fds); + receive_pkts(ifobject->pkt_stream, ifobject->xsk, &fds); if (test_type == TEST_TYPE_TEARDOWN) print_verbose("Destroying socket\n"); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 34ae4e4ea4ac..1e9a563380c8 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -20,7 +20,6 @@ #define MAX_INTERFACES 2 #define MAX_INTERFACE_NAME_CHARS 7 #define MAX_INTERFACES_NAMESPACE_CHARS 10 -#define MAX_SOCKS 1 #define MAX_SOCKETS 2 #define MAX_TEST_NAME_SIZE 32 #define MAX_TEARDOWN_ITER 10 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: 12469131 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 D610AC4320E for ; Wed, 1 Sep 2021 10:48:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BA9C561054 for ; Wed, 1 Sep 2021 10:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238536AbhIAKtW (ORCPT ); Wed, 1 Sep 2021 06:49:22 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469133 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 775F2C432BE for ; Wed, 1 Sep 2021 10:48:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 650B06101B for ; Wed, 1 Sep 2021 10:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238537AbhIAKt0 (ORCPT ); Wed, 1 Sep 2021 06:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240006AbhIAKtV (ORCPT ); Wed, 1 Sep 2021 06:49:21 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0DF4C061764; Wed, 1 Sep 2021 03:48:23 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q11so3759643wrr.9; Wed, 01 Sep 2021 03:48:23 -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=OMRZPkhzs2Tso7IAkMQmNQhRjRo6gmjZOdwKglemNcw=; b=C1RkSQQrgtsL/Z623JflzmGTa8GYZ0VjQzKu7Ocytw6LsBJYWIFkWscgObOTul8unf OJmDCFYT9jFsN7JXu15uatUSmOD0QRkQUKDCREYYKL/HUHjedXDHgj142fGSp4NG8fsK AIGGxg1+ZWHJHqOHpeqqqniI30741fhErjXThRJBAsLrJfczjwzT+BYNN3Z+W1otP7uY ZfzOyVoZHQCefYp7wl2/U88amZj1QF3GIoUP6A/9xPiN5+Th1aNumC5xtD3Z0VvhOMSQ MzOJubjgV9CZ35Aak2ttlUR8aaf1NRYYdjRIfm6Bs8LodWVHb6sCw8Rb0ei76pDHwVp0 HQ4Q== 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=OMRZPkhzs2Tso7IAkMQmNQhRjRo6gmjZOdwKglemNcw=; b=ofzHUeYafPHgtya+pNI6uEtQJuMowNQyHpPJvtbr66XTN7254FFFgn3YxO2XOcuf/Z YpBplEhamaIhQ+yUA6zEZYdahknvI2Ft47vwtNFCxFNyACBkJsjhoNekfdvu0iuaapgV wzVdRYThiyEL+rPrCtwRNnvnkjXynZD6zuyQ3Im65CPPxvQVYZumFxc6AH2tjOCY0y1s Gyq6KZAaWFnLo0ChW965P5w2TB4VFGN/Iu3CbL/rSEU3vTacPmy7AAP5j5JGvWjSpiY6 nQ9L4+GLcZYRJq7wwBVqIqrPHd01crNavqO9xFyB+lo2eHzztGW99t5reVjXkx6u4pZC AWxg== X-Gm-Message-State: AOAM5308PojPKywdB7v7MORrEUWziLon78Zz44fs/z4et+rvgZuchXKS i/tIjAcAIicQl6Zz1O3I7zY= X-Google-Smtp-Source: ABdhPJzDMBxFRaFV821ko8JE8rB5TrEmS2iUfNk0jer4jHq/gPtY5C3EpnLuszs3Rpbda53lcMfc4Q== X-Received: by 2002:a5d:464c:: with SMTP id j12mr35835693wrs.27.1630493302410; Wed, 01 Sep 2021 03:48:22 -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.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:22 -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 16/20] selftests: xsk: introduce replacing the default packet stream Date: Wed, 1 Sep 2021 12:47:28 +0200 Message-Id: <20210901104732.10956-17-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Introduce the concept of a default packet stream that is the set of packets sent by most tests. Then add the ability to replace it for a test that would like to send or receive something else through the use of the function pkt_stream_replace() and then restored with pkt_stream_restore_default(). These are then used to convert the STAT_TX_INVALID_TEST to use these new APIs. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 67 +++++++++++++++++------- tools/testing/selftests/bpf/xdpxceiver.h | 1 + 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 09d2854c10e6..d4aad4833754 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -390,6 +390,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; + ifobj->pkt_stream = test->pkt_stream_default; if (i == 0) { ifobj->rx_on = false; @@ -418,9 +419,12 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, static void test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, struct ifobject *ifobj_rx, enum test_mode mode) { + struct pkt_stream *pkt_stream; u32 i; + pkt_stream = test->pkt_stream_default; memset(test, 0, sizeof(*test)); + test->pkt_stream_default = pkt_stream; for (i = 0; i < MAX_INTERFACES; i++) { struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx; @@ -455,6 +459,19 @@ static struct pkt *pkt_stream_get_pkt(struct pkt_stream *pkt_stream, u32 pkt_nb) return &pkt_stream->pkts[pkt_nb]; } +static void pkt_stream_delete(struct pkt_stream *pkt_stream) +{ + free(pkt_stream->pkts); + free(pkt_stream); +} + +static void pkt_stream_restore_default(struct test_spec *test) +{ + pkt_stream_delete(test->ifobj_tx->pkt_stream); + test->ifobj_tx->pkt_stream = test->pkt_stream_default; + test->ifobj_rx->pkt_stream = test->pkt_stream_default; +} + static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb_pkts, u32 pkt_len) { struct pkt_stream *pkt_stream; @@ -483,6 +500,17 @@ static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb return pkt_stream; } +static void pkt_stream_replace(struct test_spec *test, u32 nb_pkts, u32 pkt_len) +{ + struct pkt_stream *pkt_stream; + + 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 struct pkt *pkt_generate(struct ifobject *ifobject, u32 pkt_nb) { struct pkt *pkt = pkt_stream_get_pkt(ifobject->pkt_stream, pkt_nb); @@ -557,7 +585,7 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, const struct xdp_desc *d if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { u32 seqnum = ntohl(*((u32 *)(data + PKT_HDR_SIZE))); - if (opt_pkt_dump && test_type != TEST_TYPE_STATS) + if (opt_pkt_dump) pkt_dump(data, PKT_SIZE); if (pkt->len != desc->len) { @@ -598,9 +626,6 @@ static void complete_pkts(struct xsk_socket_info *xsk, int batch_size) unsigned int rcvd; u32 idx; - if (!xsk->outstanding_tx) - return; - if (xsk_ring_prod__needs_wakeup(&xsk->tx)) kick_tx(xsk); @@ -831,6 +856,7 @@ static void thread_common_ops(struct test_spec *test, struct ifobject *ifobject) static void testapp_cleanup_xsk_res(struct ifobject *ifobj) { + print_verbose("Destroying socket\n"); xsk_socket__delete(ifobj->xsk->xsk); xsk_umem__delete(ifobj->umem->umem); } @@ -878,9 +904,6 @@ static void *worker_testapp_validate_rx(void *arg) else receive_pkts(ifobject->pkt_stream, ifobject->xsk, &fds); - if (test_type == TEST_TYPE_TEARDOWN) - print_verbose("Destroying socket\n"); - if (test->total_steps == test->current_step) testapp_cleanup_xsk_res(ifobject); pthread_exit(NULL); @@ -890,19 +913,11 @@ 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); - if (stat_test_type == STAT_TEST_TX_INVALID) - pkt_stream = pkt_stream_generate(test->ifobj_tx->umem, DEFAULT_PKT_CNT, - XSK_UMEM__INVALID_FRAME_SIZE); - else - 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 */ @@ -982,7 +997,9 @@ static void testapp_bpf_res(struct test_spec *test) static void testapp_stats(struct test_spec *test) { - for (int i = 0; i < STAT_TEST_TYPE_MAX; i++) { + int i; + + for (i = 0; i < STAT_TEST_TYPE_MAX; i++) { test_spec_reset(test); stat_test_type = i; @@ -991,21 +1008,27 @@ static void testapp_stats(struct test_spec *test) test_spec_set_name(test, "STAT_RX_DROPPED"); test->ifobj_rx->umem->frame_headroom = test->ifobj_rx->umem->frame_size - XDP_PACKET_HEADROOM - 1; + testapp_validate_traffic(test); break; case STAT_TEST_RX_FULL: test_spec_set_name(test, "STAT_RX_FULL"); test->ifobj_rx->xsk->rxqsize = RX_FULL_RXQSIZE; + testapp_validate_traffic(test); break; case STAT_TEST_TX_INVALID: test_spec_set_name(test, "STAT_TX_INVALID"); - continue; + pkt_stream_replace(test, DEFAULT_PKT_CNT, XSK_UMEM__INVALID_FRAME_SIZE); + testapp_validate_traffic(test); + + pkt_stream_restore_default(test); + break; case STAT_TEST_RX_FILL_EMPTY: test_spec_set_name(test, "STAT_RX_FILL_EMPTY"); + testapp_validate_traffic(test); break; default: break; } - testapp_validate_traffic(test); } /* To only see the whole stat set being completed unless an individual test fails. */ @@ -1106,6 +1129,7 @@ int main(int argc, char **argv) { struct rlimit _rlim = { RLIM_INFINITY, RLIM_INFINITY }; struct ifobject *ifobj_tx, *ifobj_rx; + struct pkt_stream *pkt_stream_default; struct test_spec test; u32 i, j; @@ -1133,6 +1157,12 @@ int main(int argc, char **argv) init_iface(ifobj_rx, MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, worker_testapp_validate_rx); + test_spec_init(&test, ifobj_tx, ifobj_rx, 0); + pkt_stream_default = pkt_stream_generate(ifobj_tx->umem, DEFAULT_PKT_CNT, PKT_SIZE); + if (!pkt_stream_default) + exit_with_error(ENOMEM); + test.pkt_stream_default = pkt_stream_default; + ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); for (i = 0; i < TEST_MODE_MAX; i++) @@ -1142,6 +1172,7 @@ int main(int argc, char **argv) usleep(USLEEP_MAX); } + pkt_stream_delete(pkt_stream_default); ifobject_delete(ifobj_tx); ifobject_delete(ifobj_rx); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index c5baa7c5f560..e27fe348ae50 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -132,6 +132,7 @@ struct ifobject { struct test_spec { struct ifobject *ifobj_tx; struct ifobject *ifobj_rx; + struct pkt_stream *pkt_stream_default; u16 total_steps; u16 current_step; u16 nb_sockets; 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: 12469135 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 C726CC4320A for ; Wed, 1 Sep 2021 10:48:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF82F61053 for ; Wed, 1 Sep 2021 10:48:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237633AbhIAKt1 (ORCPT ); Wed, 1 Sep 2021 06:49:27 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469137 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 BB830C432BE for ; Wed, 1 Sep 2021 10:48:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A41A361053 for ; Wed, 1 Sep 2021 10:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239251AbhIAKt1 (ORCPT ); Wed, 1 Sep 2021 06:49:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238568AbhIAKtY (ORCPT ); Wed, 1 Sep 2021 06:49:24 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3D6CC0617AD; Wed, 1 Sep 2021 03:48:26 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so4448544wmi.0; Wed, 01 Sep 2021 03:48:26 -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=E0VDHvF43KRG9qTwuNBsy2uPOJgG0Rgbq3u/fTxBkl8=; b=X0lCHdO84ygpA0LlYFrTyhBQNL+wDjtzmkKmT61vpEpeTZJAQK4Y7QEfoBLOJh4kNG Rh59lgmqE14CCqePVRBlPw0OZoMRmN1ZeVOsaEBqqElD3hy6DPW+O5c3JI94LguHrJcd d5nbjpOpFh0YnWmF+cPgv311i0hJZpbNQdL6sL2MbXmw7ej7hctG/QsvDRzO5yiLHnL3 8JY+DWLb8/EqVw6YUn7HpJ8L3jaDpysRozp/N66BAtKsM+HhEX6yPHkyasjXVkFRdpRG iHyqTb7HF0Xoo5EXSSgQOSWpaHtgFvnKiwe2br3n+m8zU5ZW/nrjBOE8W07ooRWGE3K9 qggg== 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=E0VDHvF43KRG9qTwuNBsy2uPOJgG0Rgbq3u/fTxBkl8=; b=BF/3TVZC3btaHDQQMsYeJ3MA8SWn2nzvMnIFGWhgx/lVSTRU7FZ24b7W3ILLWDqENh /qTP/3u+SzRHt1mogiDO+V9LONMO6g56qBEfaiXRabDtDLsREqTyMucxQMd5Kzae8w2U nmo9OkvcVmbT3na/cBizCC1dC9SjvpUHK4CMuFoyyFLOhZ6xNF4vTzciLfzQhrO284Z2 nd2NqkNqx5Ng1sKCT+sB07bo5N6FYb2WpRZkT+fUjs+ZmZgGeRkeKo0ZgoIjJHlEWcJ5 NWzqTuao/OUUw8oG7DY+oaWkgOB66LWWDdsHLZMZHhcV9385i1yvrW4Q9npUeFpjToS5 HAbw== X-Gm-Message-State: AOAM533hZ5vdWdrec6LC1rK37Qg54UXaebdNvZKDNAJ6mMJQ5FEE+q0L oGRmt24u/wYmWnU/7tQC+gk= X-Google-Smtp-Source: ABdhPJxCJxObeemEEgip4mCAkGMLZAUztaNjWVRnf1FGaZfnPX7QWEdt4bLO164smdtm00AcdBxOZw== X-Received: by 2002:a05:600c:210a:: with SMTP id u10mr8856278wml.127.1630493305353; Wed, 01 Sep 2021 03:48:25 -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.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:24 -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 18/20] selftests: xsk: eliminate test specific if-statement in test runner Date: Wed, 1 Sep 2021 12:47:30 +0200 Message-Id: <20210901104732.10956-19-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Eliminate a test specific if-statement for the RX_FILL_EMTPY stats test that is present in the test runner. We can do this as we now have the use_addr_for_fill option. Just create and empty Rx packet stream and indicated that the test runner should use the addresses in that to populate the fill ring. As there are no packets in the stream, the fill ring will be empty and we will get the error stats that we want to test. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index a24068993cc3..d085033afd53 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -458,8 +458,10 @@ static void pkt_stream_delete(struct pkt_stream *pkt_stream) static void pkt_stream_restore_default(struct test_spec *test) { - pkt_stream_delete(test->ifobj_tx->pkt_stream); - test->ifobj_tx->pkt_stream = test->pkt_stream_default; + if (test->ifobj_tx->pkt_stream != test->pkt_stream_default) { + pkt_stream_delete(test->ifobj_tx->pkt_stream); + test->ifobj_tx->pkt_stream = test->pkt_stream_default; + } test->ifobj_rx->pkt_stream = test->pkt_stream_default; } @@ -931,8 +933,7 @@ static void *worker_testapp_validate_rx(void *arg) 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, ifobject->pkt_stream); + xsk_populate_fill_ring(ifobject->umem, ifobject->pkt_stream); fds.fd = xsk_socket__fd(ifobject->xsk->xsk); fds.events = POLLIN; @@ -1065,7 +1066,14 @@ static void testapp_stats(struct test_spec *test) break; case STAT_TEST_RX_FILL_EMPTY: test_spec_set_name(test, "STAT_RX_FILL_EMPTY"); + test->ifobj_rx->pkt_stream = pkt_stream_generate(test->ifobj_rx->umem, 0, + MIN_PKT_SIZE); + if (!test->ifobj_rx->pkt_stream) + exit_with_error(ENOMEM); + test->ifobj_rx->pkt_stream->use_addr_for_fill = true; testapp_validate_traffic(test); + + pkt_stream_restore_default(test); break; default: break; From patchwork Wed Sep 1 10:47:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12469141 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 1C568C4320A for ; Wed, 1 Sep 2021 10:48:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0832861053 for ; Wed, 1 Sep 2021 10:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238832AbhIAKtd (ORCPT ); Wed, 1 Sep 2021 06:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238998AbhIAKtZ (ORCPT ); Wed, 1 Sep 2021 06:49:25 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4534CC0612E7; Wed, 1 Sep 2021 03:48:28 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so4448597wmi.0; Wed, 01 Sep 2021 03:48:28 -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=pC4K1+Kx+97AZi9AKiFa4nn0KdwxFFa9/+MJ/bCrfqI=; b=fItHInoCrQkhT2/Ie1sjrOnptquoIVrkTwl68W5hoMpKVK07FZ4mqEGHG0fjvQvue0 qjfuhkpxa8UZfKWojgQuu2qCQrvJirKMl/QiLnX9po8AyHWS1UrXxUJpGxg/Hu4VtDKf We0R08eGJels2/wq38AEzdZM09E7iJEhLjFK1GGMCadejHczERw1++XqNk77Q+dlNKCO 3bG2hsakg0Ni+rxwjcDLjZFE/yfdcPAdINYAjJFBNjC/0p0oLwUeFsNvf8HuZPZLoaN+ cReO0RXfPfTWBbDMFR3SuhJxIzk/F5ShxRlZOQAxU3UpPAzLS9WgoPCm9tXc6t5yJrvS HE9Q== 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=pC4K1+Kx+97AZi9AKiFa4nn0KdwxFFa9/+MJ/bCrfqI=; b=OHmvr5i3l6bwWJWfvNYdGqs+8QKA9+PqHdgcK/fvE1UJmlm6q2GGUkWqu8bSaI2D3r 4OlC+Tbc6v9HXt9o9KvZJ9wjfcijohboMwYGzvoT9Hf3lpPhbBce0jJTVgKJFaLycU8f ZJp/ki4P4uM9FJNzMXZYnPchUnewUxUKfLrAVm5wtG2Z2ULOGYAqcfJxwGsDsXtm4EiI KkW+sSEU+vmMBbpw1HZIseoEF8tvQf0WiO8EkAhvuxg4Wyi7JTFiC6+EuLdS+R4YDcdR tjUqLZ5/qj12oZPireBhMuKt04XFFwyKeQ7HdZW5OqL8f7xW5DlvIpWs1JYSFVggd2pH XOQg== X-Gm-Message-State: AOAM5307mVNr4l4/MSaHpBDCalWmZ5TNPwa61wxrkn0TIaCUfIvdTn1k +fUiwpigF5aE1VoC5NANln4= X-Google-Smtp-Source: ABdhPJzVKJRpwfM0PvW7wACHOQcR3Z88jLBtIchCvMaWyMHgw0TfBWISwPNcS3egV8FYPIqbz7NvKw== X-Received: by 2002:a7b:c255:: with SMTP id b21mr8994699wmj.44.1630493306875; Wed, 01 Sep 2021 03:48:26 -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.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Sep 2021 03:48:26 -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 19/20] selftests: xsk: add tests for invalid xsk descriptors Date: Wed, 1 Sep 2021 12:47:31 +0200 Message-Id: <20210901104732.10956-20-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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Add tests for invalid xsk descriptors in the Tx ring. A number of handcrafted nasty invalid descriptors are created and submitted to the tx ring to check that they are validated correctly. Corener case valid ones are also sent. The tests are run for both aligned and unaligned mode. pkt_stream_set() is introduced to be able to create a hand-crafted packet stream where every single packet is specified in detail. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 143 ++++++++++++++++++++--- tools/testing/selftests/bpf/xdpxceiver.h | 7 +- 2 files changed, 131 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index d085033afd53..a4f6ce3a6b14 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -46,6 +46,8 @@ * then remove xsk sockets from queue 0 on both veth interfaces and * finally run a traffic on queues ids 1 * g. unaligned mode + * h. tests for invalid and corner case Tx descriptors so that the correct ones + * are discarded and let through, respectively. * * Total tests: 12 * @@ -394,7 +396,7 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx, 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])); - ifobj->umem_arr[j].num_frames = DEFAULT_PKT_CNT / 4; + ifobj->umem_arr[j].num_frames = DEFAULT_UMEM_BUFFERS; ifobj->umem_arr[j].frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE; ifobj->xsk_arr[j].rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; } @@ -450,6 +452,16 @@ static struct pkt *pkt_stream_get_pkt(struct pkt_stream *pkt_stream, u32 pkt_nb) return &pkt_stream->pkts[pkt_nb]; } +static struct pkt *pkt_stream_get_next_rx_pkt(struct pkt_stream *pkt_stream) +{ + while (pkt_stream->rx_pkt_nb < pkt_stream->nb_pkts) { + if (pkt_stream->pkts[pkt_stream->rx_pkt_nb].valid) + return &pkt_stream->pkts[pkt_stream->rx_pkt_nb++]; + pkt_stream->rx_pkt_nb++; + } + return NULL; +} + static void pkt_stream_delete(struct pkt_stream *pkt_stream) { free(pkt_stream->pkts); @@ -465,17 +477,31 @@ static void pkt_stream_restore_default(struct test_spec *test) test->ifobj_rx->pkt_stream = test->pkt_stream_default; } -static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb_pkts, u32 pkt_len) +static struct pkt_stream *__pkt_stream_alloc(u32 nb_pkts) { struct pkt_stream *pkt_stream; - u32 i; - pkt_stream = malloc(sizeof(*pkt_stream)); + pkt_stream = calloc(1, sizeof(*pkt_stream)); if (!pkt_stream) - exit_with_error(ENOMEM); + return NULL; pkt_stream->pkts = calloc(nb_pkts, sizeof(*pkt_stream->pkts)); - if (!pkt_stream->pkts) + if (!pkt_stream->pkts) { + free(pkt_stream); + return NULL; + } + + pkt_stream->nb_pkts = nb_pkts; + return pkt_stream; +} + +static struct pkt_stream *pkt_stream_generate(struct xsk_umem_info *umem, u32 nb_pkts, u32 pkt_len) +{ + struct pkt_stream *pkt_stream; + u32 i; + + pkt_stream = __pkt_stream_alloc(nb_pkts); + if (!pkt_stream) exit_with_error(ENOMEM); pkt_stream->nb_pkts = nb_pkts; @@ -525,6 +551,26 @@ static void pkt_stream_replace_half(struct test_spec *test, u32 pkt_len, u32 off test->ifobj_rx->pkt_stream = pkt_stream; } +static void pkt_stream_set(struct test_spec *test, struct pkt *pkts, u32 nb_pkts) +{ + struct pkt_stream *pkt_stream; + u32 i; + + pkt_stream = __pkt_stream_alloc(nb_pkts); + if (!pkt_stream) + exit_with_error(ENOMEM); + + test->ifobj_tx->pkt_stream = pkt_stream; + test->ifobj_rx->pkt_stream = pkt_stream; + + for (i = 0; i < nb_pkts; i++) { + pkt_stream->pkts[i].addr = pkts[i].addr; + pkt_stream->pkts[i].len = pkts[i].len; + pkt_stream->pkts[i].payload = i; + pkt_stream->pkts[i].valid = pkts[i].valid; + } +} + static struct pkt *pkt_generate(struct ifobject *ifobject, u32 pkt_nb) { struct pkt *pkt = pkt_stream_get_pkt(ifobject->pkt_stream, pkt_nb); @@ -535,6 +581,8 @@ static struct pkt *pkt_generate(struct ifobject *ifobject, u32 pkt_nb) if (!pkt) return NULL; + if (!pkt->valid || pkt->len < PKT_SIZE) + return pkt; data = xsk_umem__get_data(ifobject->umem->buffer, pkt->addr); udp_hdr = (struct udphdr *)(data + sizeof(struct ethhdr) + sizeof(struct iphdr)); @@ -596,19 +644,24 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, u64 addr, u32 len) return false; } + if (len < PKT_SIZE) { + /*Do not try to verify packets that are smaller than minimun size. */ + return true; + } + + if (pkt->len != len) { + ksft_test_result_fail + ("ERROR: [%s] expected length [%d], got length [%d]\n", + __func__, pkt->len, len); + return false; + } + if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { u32 seqnum = ntohl(*((u32 *)(data + PKT_HDR_SIZE))); if (opt_pkt_dump) pkt_dump(data, PKT_SIZE); - if (pkt->len != len) { - ksft_test_result_fail - ("ERROR: [%s] expected length [%d], got length [%d]\n", - __func__, pkt->len, len); - return false; - } - if (pkt->payload != seqnum) { ksft_test_result_fail ("ERROR: [%s] expected seqnum [%d], got seqnum [%d]\n", @@ -645,6 +698,15 @@ static void complete_pkts(struct xsk_socket_info *xsk, int batch_size) rcvd = xsk_ring_cons__peek(&xsk->umem->cq, batch_size, &idx); if (rcvd) { + if (rcvd > xsk->outstanding_tx) { + u64 addr = *xsk_ring_cons__comp_addr(&xsk->umem->cq, idx + rcvd - 1); + + ksft_test_result_fail("ERROR: [%s] Too many packets completed\n", + __func__); + ksft_print_msg("Last completion address: %llx\n", addr); + return; + } + xsk_ring_cons__release(&xsk->umem->cq, rcvd); xsk->outstanding_tx -= rcvd; } @@ -653,11 +715,10 @@ static void complete_pkts(struct xsk_socket_info *xsk, int batch_size) static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info *xsk, struct pollfd *fds) { - u32 idx_rx = 0, idx_fq = 0, rcvd, i, pkt_count = 0; - struct pkt *pkt; + struct pkt *pkt = pkt_stream_get_next_rx_pkt(pkt_stream); + u32 idx_rx = 0, idx_fq = 0, rcvd, i; int ret; - pkt = pkt_stream_get_pkt(pkt_stream, pkt_count++); while (pkt) { rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx); if (!rcvd) { @@ -685,13 +746,21 @@ static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info * const struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); u64 addr = desc->addr, orig; + if (!pkt) { + ksft_test_result_fail("ERROR: [%s] Received too many packets.\n", + __func__); + ksft_print_msg("Last packet has addr: %llx len: %u\n", + addr, desc->len); + return; + } + orig = xsk_umem__extract_addr(addr); addr = xsk_umem__add_offset_to_addr(addr); if (!is_pkt_valid(pkt, xsk->umem->buffer, addr, desc->len)) return; *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig; - pkt = pkt_stream_get_pkt(pkt_stream, pkt_count++); + pkt = pkt_stream_get_next_rx_pkt(pkt_stream); } xsk_ring_prod__submit(&xsk->umem->fq, rcvd); @@ -875,6 +944,7 @@ static void testapp_cleanup_xsk_res(struct ifobject *ifobj) { print_verbose("Destroying socket\n"); xsk_socket__delete(ifobj->xsk->xsk); + munmap(ifobj->umem->buffer, ifobj->umem->num_frames * ifobj->umem->frame_size); xsk_umem__delete(ifobj->umem->umem); } @@ -1118,6 +1188,33 @@ static bool testapp_unaligned(struct test_spec *test) return true; } +static void testapp_inv_desc(struct test_spec *test) +{ + struct pkt pkts[] = {{0, 0, 0, true}, /* Zero packet length and zero address allowed */ + /* Zero packet length allowed */ + {0x1000, 0, 0, true}, + /* Straddling the start of umem */ + {-2, PKT_SIZE, 0, false}, + /* Packet too large */ + {0x2000, XSK_UMEM__INVALID_FRAME_SIZE, 0, false}, + /* After umem ends */ + {UMEM_SIZE, PKT_SIZE, 0, false}, + /* Straddle the end of umem */ + {UMEM_SIZE - PKT_SIZE / 2, PKT_SIZE, 0, false}, + /* Straddle a page boundrary */ + {0x3000 - PKT_SIZE / 2, PKT_SIZE, 0, false}, + /* Valid packet for synch so that something is received */ + {0x4000, PKT_SIZE, 0, true}}; + + if (test->ifobj_tx->umem->unaligned_mode) { + /* Crossing a page boundrary allowed */ + pkts[6].valid = true; + } + pkt_stream_set(test, pkts, ARRAY_SIZE(pkts)); + testapp_validate_traffic(test); + pkt_stream_restore_default(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, thread_func_t func_ptr) @@ -1159,7 +1256,7 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_ case TEST_TYPE_BPF_RES: testapp_bpf_res(test); break; - case TEST_TYPE_NOPOLL: + case TEST_TYPE_RUN_TO_COMPLETION: test_spec_set_name(test, "RUN_TO_COMPLETION"); testapp_validate_traffic(test); break; @@ -1169,6 +1266,16 @@ 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_ALIGNED_INV_DESC: + test_spec_set_name(test, "ALIGNED_INV_DESC"); + 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; + test->ifobj_rx->umem->unaligned_mode = true; + testapp_inv_desc(test); + break; case TEST_TYPE_UNALIGNED: if (!testapp_unaligned(test)) return; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 129801eb013c..2d9efb89ea28 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -38,6 +38,8 @@ #define BATCH_SIZE 8 #define POLL_TMOUT 1000 #define DEFAULT_PKT_CNT (4 * 1024) +#define DEFAULT_UMEM_BUFFERS (DEFAULT_PKT_CNT / 4) +#define UMEM_SIZE (DEFAULT_UMEM_BUFFERS * XSK_UMEM__DEFAULT_FRAME_SIZE) #define RX_FULL_RXQSIZE 32 #define DEFAULT_OFFSET 256 #define XSK_UMEM__INVALID_FRAME_SIZE (XSK_UMEM__DEFAULT_FRAME_SIZE + 1) @@ -51,9 +53,11 @@ enum test_mode { }; enum test_type { - TEST_TYPE_NOPOLL, + TEST_TYPE_RUN_TO_COMPLETION, TEST_TYPE_POLL, TEST_TYPE_UNALIGNED, + TEST_TYPE_ALIGNED_INV_DESC, + TEST_TYPE_UNALIGNED_INV_DESC, TEST_TYPE_TEARDOWN, TEST_TYPE_BIDI, TEST_TYPE_STATS, @@ -104,6 +108,7 @@ struct pkt { struct pkt_stream { u32 nb_pkts; + u32 rx_pkt_nb; struct pkt *pkts; bool use_addr_for_fill; }; 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: 12469139 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 E0A26C432BE for ; Wed, 1 Sep 2021 10:48:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CED9561053 for ; Wed, 1 Sep 2021 10:48:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239957AbhIAKta (ORCPT ); Wed, 1 Sep 2021 06:49:30 -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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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,