From patchwork Fri Oct 30 12:13:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Weqaar Janjua X-Patchwork-Id: 315988 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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5778C4741F for ; Fri, 30 Oct 2020 12:14:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7591122227 for ; Fri, 30 Oct 2020 12:14:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eD7q7WNC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726486AbgJ3MOk (ORCPT ); Fri, 30 Oct 2020 08:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgJ3MOh (ORCPT ); Fri, 30 Oct 2020 08:14:37 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F13C0613D2; Fri, 30 Oct 2020 05:14:37 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id i16so810574wrv.1; Fri, 30 Oct 2020 05:14:36 -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=rUFViTUnY+kgYImFFGX/ElRXc1tRT3Fz4yeUpO6dpm8=; b=eD7q7WNCJwZDteaNeRC0DIwsweHyqHcGhqj4ou3o7ChzlLFIF+44wuZ8wB7g+ynIzW cg/SH96s7CWXXLbN6EMBjYk40lTLN5RvYnbkjV3SFPPUuT1iUKlOoF07ZGwzhm03WFFA EQe3QazWtNAMY+DoGrQCVatoz9tyYQuAYYbtoJ/zny16Ilf8qzUGLtcJwDpfQJYoGnwL Q1sSn2fFl7FicY5O8WP/ucLm1WDU22oqfdstlv7+49bXKfsaxi76DRO8vmpJgxnaVQ+q DIbYmE1/Wa6+2+M3rIokXjZr+jk0XkfNusdkUCgsbVwLUzzlTtNEG0sIeYr0kLUbIFkA wGiQ== 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=rUFViTUnY+kgYImFFGX/ElRXc1tRT3Fz4yeUpO6dpm8=; b=eCl7EYeF16ND2XDHFrXEiqhBIeAtoVYZQWiY2SyqfH5W8au7K9n3QloikZsaHKXIk2 MIVuQJfwsI+CA7d/R4ymiXd2Q+aPQyHgIcti6jBRZug95lXzAg0EqA8KK2Z6hwG94ks/ IVGa2IRnRfDtgOQCS/vlYwrpwZrME+KzIdaV/Mo9TMwXoaHElfLG9vwF/4tzz+jvCOOH Y5yEFs3eoNVsrKECw0jT6rMOkfNN81/nzV29Xp44MS0xaH+BQddtfZGdNjxYuJZwarlP pxcOKoKrw3IO7dbpBSNUJ8g9ON8BwRjcwY19xWWDu2fW0eDM8Ak5C0W66i5mgcsPV3Jk LRdg== X-Gm-Message-State: AOAM531wDjnAGjxQy2kPi/PXbXaxqyDfZlXwjRWv7apytSj6N4yAKVVp Swz6deEUnXiiU4+AF+1FdCsWC9hmPJjJUCkilk0= X-Google-Smtp-Source: ABdhPJzxJbfPPlECdxc672x63KmTeRs0JMKEC7HxIKbkT92hUID98JsqTTD52jrVrtfpNLux6hhTiw== X-Received: by 2002:a5d:61c9:: with SMTP id q9mr2791022wrv.395.1604060075004; Fri, 30 Oct 2020 05:14:35 -0700 (PDT) Received: from kernel-dev.chello.ie ([80.111.136.190]) by smtp.gmail.com with ESMTPSA id 90sm10020925wrh.35.2020.10.30.05.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 05:14:34 -0700 (PDT) From: Weqaar Janjua X-Google-Original-From: Weqaar Janjua To: bpf@vger.kernel.org, netdev@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org, magnus.karlsson@gmail.com, bjorn.topel@intel.com Cc: Weqaar Janjua , shuah@kernel.org, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, anders.roxell@linaro.org, jonathan.lemon@gmail.com Subject: [PATCH bpf-next 1/5] selftests/xsk: xsk selftests framework Date: Fri, 30 Oct 2020 12:13:43 +0000 Message-Id: <20201030121347.26984-2-weqaar.a.janjua@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201030121347.26984-1-weqaar.a.janjua@intel.com> References: <20201030121347.26984-1-weqaar.a.janjua@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds AF_XDP selftests framework under selftests/xsk. Prerequisites setup by script TEST_PREREQUISITES.sh: Set up veth interfaces as per the topology shown in README: * setup two veth interfaces and one namespace ** veth in root namespace ** veth in af_xdp namespace ** namespace af_xdp * create a spec file veth.spec that includes this run-time configuration that is read by test scripts - filenames prefixed with TEST_XSK *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid conflict with any existing interface Signed-off-by: Weqaar Janjua --- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/xsk/Makefile | 10 ++ tools/testing/selftests/xsk/README | 72 +++++++++++ .../selftests/xsk/TEST_PREREQUISITES.sh | 53 ++++++++ tools/testing/selftests/xsk/TEST_XSK.sh | 15 +++ tools/testing/selftests/xsk/config | 1 + tools/testing/selftests/xsk/prereqs.sh | 119 ++++++++++++++++++ tools/testing/selftests/xsk/xskenv.sh | 33 +++++ 9 files changed, 305 insertions(+) create mode 100644 tools/testing/selftests/xsk/Makefile create mode 100644 tools/testing/selftests/xsk/README create mode 100755 tools/testing/selftests/xsk/TEST_PREREQUISITES.sh create mode 100755 tools/testing/selftests/xsk/TEST_XSK.sh create mode 100644 tools/testing/selftests/xsk/config create mode 100755 tools/testing/selftests/xsk/prereqs.sh create mode 100755 tools/testing/selftests/xsk/xskenv.sh diff --git a/MAINTAINERS b/MAINTAINERS index f281f8077de0..41c214375f9e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19127,6 +19127,7 @@ F: include/uapi/linux/if_xdp.h F: net/xdp/ F: samples/bpf/xdpsock* F: tools/lib/bpf/xsk* +F: tools/testing/selftests/xsk/ XEN BLOCK SUBSYSTEM M: Konrad Rzeszutek Wilk diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index d9c283503159..d9b1f7d4313b 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -67,6 +67,7 @@ TARGETS += tpm2 TARGETS += user TARGETS += vm TARGETS += x86 +TARGETS += xsk TARGETS += zram #Please keep the TARGETS list alphabetically sorted # Run "make quicktest=1 run_tests" or diff --git a/tools/testing/selftests/xsk/Makefile b/tools/testing/selftests/xsk/Makefile new file mode 100644 index 000000000000..6e0d657bc5e0 --- /dev/null +++ b/tools/testing/selftests/xsk/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +TEST_PROGS := TEST_PREREQUISITES.sh \ + TEST_XSK.sh +TEST_FILES := prereqs.sh xskenv.sh +TEST_TRANSIENT_FILES := veth.spec + +KSFT_KHDR_INSTALL := 1 +include ../lib.mk diff --git a/tools/testing/selftests/xsk/README b/tools/testing/selftests/xsk/README new file mode 100644 index 000000000000..a255b3050afc --- /dev/null +++ b/tools/testing/selftests/xsk/README @@ -0,0 +1,72 @@ +Copyright (c) 2020 Intel Corporation, Weqaar Janjua + +AF_XDP selftests based on veth + +# End-to-end AF_XDP over Veth test +# +# Topology: +# --------- +# ----------- +# _ | Process | _ +# / ----------- \ +# / | \ +# / | \ +# ----------- | ----------- +# | Thread1 | | | Thread2 | +# ----------- | ----------- +# | | | +# ----------- | ----------- +# | xskX | | | xskY | +# ----------- | ----------- +# | | | +# ----------- | ---------- +# | vethX | --------- | vethY | +# ----------- peer ---------- +# | | | +# namespaceX | namespaceY + +AF_XDP is an address family optimized for high performance packet processing, +it is XDP’s user-space interface. + +An AF_XDP socket is linked to a single UMEM which is a region of virtual +contiguous memory, divided into equal-sized frames. + +Refer to AF_XDP Kernel Documentation for detailed information: +https://www.kernel.org/doc/html/latest/networking/af_xdp.html + +Prerequisites setup by script TEST_PREREQUISITES.sh: + + Set up veth interfaces as per the topology shown ^^: + * setup two veth interfaces and one namespace + ** veth in root namespace + ** veth in af_xdp namespace + ** namespace af_xdp + * create a spec file veth.spec that includes this run-time configuration + that is read by test scripts - filenames prefixed with TEST_XSK_ + *** xxxx and yyyy are randomly generated 4 digit numbers used to avoid + conflict with any existing interface + +Kernel configuration: +--------------------- +See "config" file for recommended kernel config options. + +Turn on XDP sockets and veth support when compiling i.e. + Networking support --> + Networking options --> + [ * ] XDP sockets + +Executing Tests: +---------------- +Must run with CAP_NET_ADMIN capability. + +Run (summary only): + sudo make summary=1 run_tests + +Run (full color-coded output): + sudo make colorconsole=1 run_tests + +Run (full output without color-coding): + sudo make run_tests + +Clean: + make clean diff --git a/tools/testing/selftests/xsk/TEST_PREREQUISITES.sh b/tools/testing/selftests/xsk/TEST_PREREQUISITES.sh new file mode 100755 index 000000000000..cd542dbaf7ac --- /dev/null +++ b/tools/testing/selftests/xsk/TEST_PREREQUISITES.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +. prereqs.sh + +TEST_NAME="PREREQUISITES" + +URANDOM=/dev/urandom +[ ! -e "${URANDOM}" ] && { echo "${URANDOM} not found. Skipping tests."; test_exit 1 1; } + +VETH0_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4) +VETH0=ve${VETH0_POSTFIX} +VETH1_POSTFIX=$(cat ${URANDOM} | tr -dc '0-9' | fold -w 256 | head -n 1 | head --bytes 4) +VETH1=ve${VETH1_POSTFIX} +NS1=af_xdp${VETH1_POSTFIX} +IPADDR_VETH0=192.168.222.1/30 +IPADDR_VETH1=192.168.222.2/30 +MTU=1500 + +setup_vethPairs() { + echo "setting up ${VETH0}: root: ${IPADDR_VETH0}" + ip netns add ${NS1} + ip link add ${VETH0} type veth peer name ${VETH1} + ip addr add dev ${VETH0} ${IPADDR_VETH0} + echo "setting up ${VETH1}: ${NS1}: ${IPADDR_VETH1}" + ip link set ${VETH1} netns ${NS1} + ip netns exec ${NS1} ip addr add dev ${VETH1} ${IPADDR_VETH1} + ip netns exec ${NS1} ip link set ${VETH1} mtu ${MTU} + ip netns exec ${NS1} ip link set ${VETH1} up + ip link set ${VETH0} mtu ${MTU} + ip link set ${VETH0} up +} + +validate_root_exec +validate_veth_support ${VETH0} +validate_configs +setup_vethPairs + +retval=$? +if [ $retval -ne 0 ]; then + test_status $retval "${TEST_NAME}" + cleanup_exit ${VETH0} ${VETH1} ${NS1} + exit $retval +fi + +echo "${VETH0}:${VETH1},${NS1}" > ${SPECFILE} + +echo "Spec file created: ${SPECFILE}" + +test_status $retval "${TEST_NAME}" + +exit $retval diff --git a/tools/testing/selftests/xsk/TEST_XSK.sh b/tools/testing/selftests/xsk/TEST_XSK.sh new file mode 100755 index 000000000000..ad31b3e38b8f --- /dev/null +++ b/tools/testing/selftests/xsk/TEST_XSK.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +. prereqs.sh +. xskenv.sh + +TEST_NAME="XSK FRAMEWORK" + +test_status $ksft_pass "${TEST_NAME}" + +# Must be called in the last test to execute +cleanup_exit ${VETH0} ${VETH1} ${NS1} + +test_exit $ksft_pass 0 diff --git a/tools/testing/selftests/xsk/config b/tools/testing/selftests/xsk/config new file mode 100644 index 000000000000..80311f71266d --- /dev/null +++ b/tools/testing/selftests/xsk/config @@ -0,0 +1 @@ +CONFIG_VETH=m diff --git a/tools/testing/selftests/xsk/prereqs.sh b/tools/testing/selftests/xsk/prereqs.sh new file mode 100755 index 000000000000..4c20aec45d99 --- /dev/null +++ b/tools/testing/selftests/xsk/prereqs.sh @@ -0,0 +1,119 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +ksft_pass=0 +ksft_fail=1 +ksft_xfail=2 +ksft_xpass=3 +ksft_skip=4 + +GREEN='\033[0;92m' +YELLOW='\033[0;93m' +RED='\033[0;31m' +NC='\033[0m' +STACK_LIM=131072 +SPECFILE=veth.spec + +validate_root_exec() +{ + msg="skip all tests:" + if [ $UID != 0 ]; then + echo $msg must be run as root >&2 + test_exit $ksft_fail 2 + else + return $ksft_pass + fi +} + +validate_veth_support() +{ + msg="skip all tests:" + if [ $(ip link add $1 type veth 2>/dev/null; echo $?;) != 0 ]; then + echo $msg veth kernel support not available >&2 + test_exit $ksft_skip 1 + else + ip link del $1 + return $ksft_pass + fi +} + +validate_veth_spec_file() +{ + if [ ! -f ${SPECFILE} ]; then + test_exit $ksft_skip 1 + fi +} + +test_status() +{ + statusval=$1 + if [ -n "${colorconsole+set}" ]; then + if [ $statusval -eq 2 ]; then + echo -e "${YELLOW}$2${NC}: ${RED}FAIL${NC}" + elif [ $statusval -eq 1 ]; then + echo -e "${YELLOW}$2${NC}: ${RED}SKIPPED${NC}" + elif [ $statusval -eq 0 ]; then + echo -e "${YELLOW}$2${NC}: ${GREEN}PASS${NC}" + fi + else + if [ $statusval -eq 2 ]; then + echo -e "$2: FAIL" + elif [ $statusval -eq 1 ]; then + echo -e "$2: SKIPPED" + elif [ $statusval -eq 0 ]; then + echo -e "$2: PASS" + fi + fi +} + +test_exit() +{ + retval=$1 + if [ $2 -ne 0 ]; then + test_status $2 $(basename $0) + fi + exit $retval +} + +clear_configs() +{ + if [ $(ip netns show | grep $3 &>/dev/null; echo $?;) == 0 ]; then + [ $(ip netns exec $3 ip link show $2 &>/dev/null; echo $?;) == 0 ] && + { echo "removing link $2"; ip netns exec $3 ip link del $2; } + echo "removing ns $3" + ip netns del $3 + fi + #Once we delete a veth pair node, the entire veth pair is removed, + #this is just to be cautious just incase the NS does not exist then + #veth node inside NS won't get removed so we explicitly remove it + [ $(ip link show $1 &>/dev/null; echo $?;) == 0 ] && + { echo "removing link $1"; ip link del $1; } + if [ -f ${SPECFILE} ]; then + echo "removing spec file:" veth.spec + rm -f ${SPECFILE} + fi +} + +cleanup_exit() +{ + echo "cleaning up..." + clear_configs $1 $2 $3 +} + +validate_configs() +{ + [ ! $(type -P ip) ] && { echo "'ip' not found. Skipping tests."; test_exit $ksft_skip 1; } +} + +vethXDPgeneric() +{ + ip link set dev $1 xdpdrv off + ip netns exec $3 ip link set dev $2 xdpdrv off +} + +vethXDPnative() +{ + ip link set dev $1 xdpgeneric off + ip netns exec $3 ip link set dev $2 xdpgeneric off +} diff --git a/tools/testing/selftests/xsk/xskenv.sh b/tools/testing/selftests/xsk/xskenv.sh new file mode 100755 index 000000000000..afc10bbdfb50 --- /dev/null +++ b/tools/testing/selftests/xsk/xskenv.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +. prereqs.sh + +XSKDIR=xdpprogs +XSKOBJ=xdpxceiver +NUMPKTS=10000 + +validate_veth_spec_file + +VETH0=$(cat ${SPECFILE} | cut -d':' -f 1) +VETH1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 1) +NS1=$(cat ${SPECFILE} | cut -d':' -f 2 | cut -d',' -f 2) + +execxdpxceiver() +{ + local -a 'paramkeys=("${!'"$1"'[@]}")' copy + paramkeysstr=${paramkeys[*]} + + for index in $paramkeysstr; + do + current=$1"[$index]" + copy[$index]=${!current} + done + + if [ -f ./${XSKOBJ} ]; then + ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${copy[*]} -C ${NUMPKTS} + else + ./${XSKDIR}/${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${copy[*]} -C ${NUMPKTS} + fi +} From patchwork Fri Oct 30 12:13:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weqaar Janjua X-Patchwork-Id: 315987 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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B0EBC4363A for ; Fri, 30 Oct 2020 12:14:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76DCC2076E for ; Fri, 30 Oct 2020 12:14:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tLf3hXPn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726533AbgJ3MOn (ORCPT ); Fri, 30 Oct 2020 08:14:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgJ3MOj (ORCPT ); Fri, 30 Oct 2020 08:14:39 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59715C0613D5; Fri, 30 Oct 2020 05:14:39 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id b8so6256986wrn.0; Fri, 30 Oct 2020 05:14:39 -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=S7+2YlYexcf1AU0qOsB2/bovpOihknJOQtAdl1enaOE=; b=tLf3hXPnutrvK8FKC/fGQhfazCRZY9Yoo2HYgJoHng4lZYn+vq5hU3c5uyWuH7t1ke gZopjwQf+JzBzsVvyjBGXiqTi7/7cCpQDG2wNMEfm5PlsstRBhdY7TSDRBoJcvbuTTvW 0N+EOxHQ2fwfI1wDd5WHTZuqYP7Z64pyPUWMlq9k0ckgS7bCnXcxQKx5oUFawIBlpUsi E3QiiN+h3LW9cwbeNiqOUDcoo4U8qB5H7NtPlTO3ZKsI8DMprdPK1fj5eDXGvjQMGiH5 xA5SMUz5R9RaxFDD8LZN1eQidnSGfSHUoAz28a4fe45UqNbAxXp4HegbPYnkeW1YZItT CKnA== 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=S7+2YlYexcf1AU0qOsB2/bovpOihknJOQtAdl1enaOE=; b=HX98gajNZd4duJfBBs14MfDfYzG+zMWP5YMFRXYBYjJgZNVhVlTZ99iy+QittfJgwe JMHQqZWyfL8/Sci0mSo7GdbapugPc1urpwGFO+hrh7j9Mpj009wEGO1XaY/ylxzLGD2/ r9oSgB6W+kNYWbkLwd2L4XnPFB7hFQrB3bQ6GCd0aFduUkqriEuiCwiXpskUNwYcuTjO A3JKDSiTmcs8fFMZDivtfc3ej8vUU3Ly+MTC9JzUPSmPxQz7fDcVIFIZcrx9e314h3G/ Tjuc9/o1LKm/mVS36vViip7VtacU5f3Id6xdZtLzPtJuiwWG5Oic2DYtixz3FfhvauWM pXDQ== X-Gm-Message-State: AOAM530gRqeGadkL7OP26d/rqcbAPsHnFtgUxL64NwGSX/9nwhKiA4Or auEXD08h24aTWlM7lRcqgcIOgW2fQLbY3XcPzHk= X-Google-Smtp-Source: ABdhPJyvJFaeJthNQ00vU1zaOK/Th+z0uytT8g0oCH+iUP9IXyluxv5WOfuwDEI1GXhiJ462flE3DA== X-Received: by 2002:adf:9361:: with SMTP id 88mr2658680wro.37.1604060077431; Fri, 30 Oct 2020 05:14:37 -0700 (PDT) Received: from kernel-dev.chello.ie ([80.111.136.190]) by smtp.gmail.com with ESMTPSA id 90sm10020925wrh.35.2020.10.30.05.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 05:14:36 -0700 (PDT) From: Weqaar Janjua X-Google-Original-From: Weqaar Janjua To: bpf@vger.kernel.org, netdev@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org, magnus.karlsson@gmail.com, bjorn.topel@intel.com Cc: Weqaar Janjua , shuah@kernel.org, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, anders.roxell@linaro.org, jonathan.lemon@gmail.com Subject: [PATCH bpf-next 3/5] selftests/xsk: xsk selftests - DRV POLL, NOPOLL Date: Fri, 30 Oct 2020 12:13:45 +0000 Message-Id: <20201030121347.26984-4-weqaar.a.janjua@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201030121347.26984-1-weqaar.a.janjua@intel.com> References: <20201030121347.26984-1-weqaar.a.janjua@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Adds following tests: 2. AF_XDP DRV/Native mode Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes packets before SKB allocation. Provides better performance than SKB. Driver hook available just after DMA of buffer descriptor. a. nopoll b. poll * Only copy mode is supported because veth does not currently support zero-copy mode Signed-off-by: Weqaar Janjua --- tools/testing/selftests/xsk/Makefile | 4 +++- tools/testing/selftests/xsk/README | 11 +++++++++- .../selftests/xsk/TEST_XSK_DRV_NOPOLL.sh | 18 ++++++++++++++++ .../selftests/xsk/TEST_XSK_DRV_POLL.sh | 21 +++++++++++++++++++ .../selftests/xsk/TEST_XSK_SKB_POLL.sh | 3 --- .../selftests/xsk/xdpprogs/xdpxceiver.c | 11 ++++++++-- .../selftests/xsk/xdpprogs/xdpxceiver.h | 1 + 7 files changed, 62 insertions(+), 7 deletions(-) create mode 100755 tools/testing/selftests/xsk/TEST_XSK_DRV_NOPOLL.sh create mode 100755 tools/testing/selftests/xsk/TEST_XSK_DRV_POLL.sh diff --git a/tools/testing/selftests/xsk/Makefile b/tools/testing/selftests/xsk/Makefile index 63008cd90ab6..472d8975fa5a 100644 --- a/tools/testing/selftests/xsk/Makefile +++ b/tools/testing/selftests/xsk/Makefile @@ -8,7 +8,9 @@ XSKOBJ := xdpxceiver TEST_PROGS := TEST_PREREQUISITES.sh \ TEST_XSK_SKB_NOPOLL.sh \ - TEST_XSK_SKB_POLL.sh + TEST_XSK_SKB_POLL.sh \ + TEST_XSK_DRV_NOPOLL.sh \ + TEST_XSK_DRV_POLL.sh TEST_FILES := prereqs.sh xskenv.sh TEST_TRANSIENT_FILES := veth.spec TEST_PROGS_EXTENDED := $(XSKDIR)/$(XSKOBJ) diff --git a/tools/testing/selftests/xsk/README b/tools/testing/selftests/xsk/README index db507a0057c1..0088c136a0d1 100644 --- a/tools/testing/selftests/xsk/README +++ b/tools/testing/selftests/xsk/README @@ -64,7 +64,16 @@ The following tests are run: a. nopoll - soft-irq processing b. poll - using poll() syscall -Total tests: 2. +2. AF_XDP DRV/Native mode + Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes + packets before SKB allocation. Provides better performance than SKB. Driver + hook available just after DMA of buffer descriptor. + a. nopoll + b. poll + * Only copy mode is supported because veth does not currently support + zero-copy mode + +Total tests: 4. Flow: * Single process spawns two threads: Tx and Rx diff --git a/tools/testing/selftests/xsk/TEST_XSK_DRV_NOPOLL.sh b/tools/testing/selftests/xsk/TEST_XSK_DRV_NOPOLL.sh new file mode 100755 index 000000000000..420f33ad6d14 --- /dev/null +++ b/tools/testing/selftests/xsk/TEST_XSK_DRV_NOPOLL.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +. prereqs.sh +. xskenv.sh + +TEST_NAME="DRV NOPOLL" + +vethXDPnative ${VETH0} ${VETH1} ${NS1} + +params=("-N") +execxdpxceiver params + +retval=$? +test_status $retval "${TEST_NAME}" + +test_exit $retval 0 diff --git a/tools/testing/selftests/xsk/TEST_XSK_DRV_POLL.sh b/tools/testing/selftests/xsk/TEST_XSK_DRV_POLL.sh new file mode 100755 index 000000000000..05e6c0372074 --- /dev/null +++ b/tools/testing/selftests/xsk/TEST_XSK_DRV_POLL.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +. prereqs.sh +. xskenv.sh + +TEST_NAME="DRV POLL" + +vethXDPnative ${VETH0} ${VETH1} ${NS1} + +params=("-N" "-p") +execxdpxceiver params + +retval=$? +test_status $retval "${TEST_NAME}" + +# Must be called in the last test to execute +cleanup_exit ${VETH0} ${VETH1} ${NS1} + +test_exit $retval 0 diff --git a/tools/testing/selftests/xsk/TEST_XSK_SKB_POLL.sh b/tools/testing/selftests/xsk/TEST_XSK_SKB_POLL.sh index 4d314ed72cd8..a06582855d6e 100755 --- a/tools/testing/selftests/xsk/TEST_XSK_SKB_POLL.sh +++ b/tools/testing/selftests/xsk/TEST_XSK_SKB_POLL.sh @@ -15,7 +15,4 @@ execxdpxceiver params retval=$? test_status $retval "${TEST_NAME}" -# Must be called in the last test to execute -cleanup_exit ${VETH0} ${VETH1} ${NS1} - test_exit $retval 0 diff --git a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c index 9855a3b33fae..777f839bbd3a 100644 --- a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c +++ b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c @@ -49,7 +49,7 @@ 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\n", uut ? "" : "SKB", opt_poll ? "POLL" : "NOPOLL")) + (ksft_test_result_pass("PASS: %s %s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" : "NOPOLL")) static void pthread_init_mutex(void) { @@ -272,6 +272,7 @@ static struct option long_options[] = { {"queue", optional_argument, 0, 'q'}, {"poll", no_argument, 0, 'p'}, {"xdp-skb", no_argument, 0, 'S'}, + {"xdp-native", no_argument, 0, 'N'}, {"copy", no_argument, 0, 'c'}, {"debug", optional_argument, 0, 'D'}, {"tx-pkt-count", optional_argument, 0, 'C'}, @@ -287,6 +288,7 @@ static void usage(const char *prog) " -q, --queue=n Use queue n (default 0)\n" " -p, --poll Use poll syscall\n" " -S, --xdp-skb=n Use XDP SKB mode\n" + " -N, --xdp-native=n Enforce XDP DRV (native) mode\n" " -c, --copy Force copy mode\n" " -D, --debug Debug mode - dump packets L2 - L5\n" " -C, --tx-pkt-count=n Number of packets to send\n"; @@ -378,7 +380,7 @@ static void parse_command_line(int argc, char **argv) opterr = 0; for (;;) { - c = getopt_long(argc, argv, "i:q:pScDC:", long_options, &option_index); + c = getopt_long(argc, argv, "i:q:pSNcDC:", long_options, &option_index); if (c == -1) break; @@ -408,6 +410,11 @@ static void parse_command_line(int argc, char **argv) opt_xdp_bind_flags |= XDP_COPY; uut = ORDER_CONTENT_VALIDATE_XDP_SKB; break; + case 'N': + opt_xdp_flags |= XDP_FLAGS_DRV_MODE; + opt_xdp_bind_flags |= XDP_COPY; + uut = ORDER_CONTENT_VALIDATE_XDP_DRV; + break; case 'c': opt_xdp_bind_flags |= XDP_COPY; break; diff --git a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h index 385a01ab04c0..91ddc01836c9 100644 --- a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h +++ b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h @@ -45,6 +45,7 @@ typedef __u8 u8; enum TESTS { ORDER_CONTENT_VALIDATE_XDP_SKB = 0, + ORDER_CONTENT_VALIDATE_XDP_DRV = 1, }; u8 uut; From patchwork Fri Oct 30 12:13:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weqaar Janjua X-Patchwork-Id: 315986 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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46567C4742C for ; Fri, 30 Oct 2020 12:14:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB3A220702 for ; Fri, 30 Oct 2020 12:14:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RyvZ6h9M" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbgJ3MOt (ORCPT ); Fri, 30 Oct 2020 08:14:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726529AbgJ3MOm (ORCPT ); Fri, 30 Oct 2020 08:14:42 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22576C0613D2; Fri, 30 Oct 2020 05:14:42 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id s9so6201036wro.8; Fri, 30 Oct 2020 05:14:42 -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=8gk9rHR2BMpwjI4+s357QU13xZVLjB9WG8eIeUJDvO4=; b=RyvZ6h9MhShsv+26kLW0obcr2y0ACo7uQUgdB6i9tJRhwdebeLCB8MWwOIOmujE6/X 7griymeTzBcLqg8Dhuvb2YjyyWrW3dS8bMVG8oJJBfq0icPSla/8JuwD82ShCanR7OeB d4ztRZIR3htQ3kQNajDhYIhO6rooHpmUJxndnmuLYnzkdSmdfR8Ocg+MAYGzFtCmvsmm Kwax+pB892v5RChwA3M91eMJt7O3npsxpaiSvA1Vc1z2um1W9hJXFOD+TfTHg5RJ+4xM c2jzJalxyp3GkWl3zGFzIVWkGIBlu0Gs/Uf6DBAMXtujgZHl9MjLsVsIq4DaiTQnHC5A uZqA== 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=8gk9rHR2BMpwjI4+s357QU13xZVLjB9WG8eIeUJDvO4=; b=nX3jpUGMqFqxBQjt/V5rBWNbcZoCkfBl5hsyV9lOIsXFDgx1NX34d88P6soN6npjES IFJ43uFj971urKZ2mZya/rw1z+OzoRA+2HLQ8mW8vD/DCkwoPv8634fi3xzaJ26tz1nn VZQ341nZ3Zn7boOY8Ee5ZidBb8U+/pOxYFKrnzD9BGac3dSdiQQZi+GOKesPu8kL3rCr XZaUHTes2geqdKx4nNL8eFHBPvFkJr3mdrHslEmyIbFLa8Ft0Qy+3lwQf86wba77A6Bi 8fMG38w2A6R+c2yrsdQct0jU4QNMButZ/DHPz5YRzCygTHydhHjl95HSQUh/z5lEVL15 0Lrw== X-Gm-Message-State: AOAM533edbpuMcRg2q0kXQ4N1KyI98DHvP1kdCSTwv6UTcfvw5cqDLuD IvvEPlGuVu1a4oOmVo5pVsPcRCle0dP6/sUoRFQ= X-Google-Smtp-Source: ABdhPJw06oamBXEBESdF+n7rCiJTpR6UgPJGBEsDWfPPR27jPDWwhMd24aTcsq1JIy7C48OGD+P0zg== X-Received: by 2002:adf:f4c9:: with SMTP id h9mr2672802wrp.332.1604060080185; Fri, 30 Oct 2020 05:14:40 -0700 (PDT) Received: from kernel-dev.chello.ie ([80.111.136.190]) by smtp.gmail.com with ESMTPSA id 90sm10020925wrh.35.2020.10.30.05.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 05:14:39 -0700 (PDT) From: Weqaar Janjua X-Google-Original-From: Weqaar Janjua To: bpf@vger.kernel.org, netdev@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org, magnus.karlsson@gmail.com, bjorn.topel@intel.com Cc: Weqaar Janjua , shuah@kernel.org, skhan@linuxfoundation.org, linux-kselftest@vger.kernel.org, anders.roxell@linaro.org, jonathan.lemon@gmail.com Subject: [PATCH bpf-next 5/5] selftests/xsk: xsk selftests - Bi-directional Sockets - SKB, DRV Date: Fri, 30 Oct 2020 12:13:47 +0000 Message-Id: <20201030121347.26984-6-weqaar.a.janjua@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201030121347.26984-1-weqaar.a.janjua@intel.com> References: <20201030121347.26984-1-weqaar.a.janjua@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Adds following tests: 1. AF_XDP SKB mode d. Bi-directional Sockets Configure sockets as bi-directional tx/rx sockets, sets up fill and completion rings on each socket, tx/rx in both directions. Only nopoll mode is used 2. AF_XDP DRV/Native mode d. Bi-directional Sockets * Only copy mode is supported because veth does not currently support zero-copy mode Signed-off-by: Weqaar Janjua --- tools/testing/selftests/xsk/Makefile | 4 +- tools/testing/selftests/xsk/README | 7 +- .../xsk/TEST_XSK_DRV_BIDIRECTIONAL.sh | 22 +++++ .../selftests/xsk/TEST_XSK_DRV_TEARDOWN.sh | 3 - .../xsk/TEST_XSK_SKB_BIDIRECTIONAL.sh | 19 ++++ .../selftests/xsk/xdpprogs/xdpxceiver.c | 93 ++++++++++++++----- .../selftests/xsk/xdpprogs/xdpxceiver.h | 4 + 7 files changed, 124 insertions(+), 28 deletions(-) create mode 100755 tools/testing/selftests/xsk/TEST_XSK_DRV_BIDIRECTIONAL.sh create mode 100755 tools/testing/selftests/xsk/TEST_XSK_SKB_BIDIRECTIONAL.sh diff --git a/tools/testing/selftests/xsk/Makefile b/tools/testing/selftests/xsk/Makefile index 79d106b30922..550a9b0d81c4 100644 --- a/tools/testing/selftests/xsk/Makefile +++ b/tools/testing/selftests/xsk/Makefile @@ -12,7 +12,9 @@ TEST_PROGS := TEST_PREREQUISITES.sh \ TEST_XSK_DRV_NOPOLL.sh \ TEST_XSK_DRV_POLL.sh \ TEST_XSK_SKB_TEARDOWN.sh \ - TEST_XSK_DRV_TEARDOWN.sh + TEST_XSK_DRV_TEARDOWN.sh \ + TEST_XSK_SKB_BIDIRECTIONAL.sh \ + TEST_XSK_DRV_BIDIRECTIONAL.sh TEST_FILES := prereqs.sh xskenv.sh TEST_TRANSIENT_FILES := veth.spec TEST_PROGS_EXTENDED := $(XSKDIR)/$(XSKOBJ) diff --git a/tools/testing/selftests/xsk/README b/tools/testing/selftests/xsk/README index e2ae3c804bfb..b96ba9333782 100644 --- a/tools/testing/selftests/xsk/README +++ b/tools/testing/selftests/xsk/README @@ -66,6 +66,10 @@ The following tests are run: c. Socket Teardown Create a Tx and a Rx socket, Tx from one socket, Rx on another. Destroy both sockets, then repeat multiple times. Only nopoll mode is used + d. Bi-directional sockets + Configure sockets as bi-directional tx/rx sockets, sets up fill and + completion rings on each socket, tx/rx in both directions. Only nopoll + mode is used 2. AF_XDP DRV/Native mode Works on any netdevice with XDP_REDIRECT support, driver dependent. Processes @@ -74,10 +78,11 @@ The following tests are run: a. nopoll b. poll c. Socket Teardown + d. Bi-directional sockets * Only copy mode is supported because veth does not currently support zero-copy mode -Total tests: 6. +Total tests: 8. Flow: * Single process spawns two threads: Tx and Rx diff --git a/tools/testing/selftests/xsk/TEST_XSK_DRV_BIDIRECTIONAL.sh b/tools/testing/selftests/xsk/TEST_XSK_DRV_BIDIRECTIONAL.sh new file mode 100755 index 000000000000..6dca372f66cd --- /dev/null +++ b/tools/testing/selftests/xsk/TEST_XSK_DRV_BIDIRECTIONAL.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +#Includes +. prereqs.sh +. xskenv.sh + +TEST_NAME="DRV BIDIRECTIONAL SOCKETS" + +vethXDPnative ${VETH0} ${VETH1} ${NS1} + +params=("-N" "-B") +execxdpxceiver params + +retval=$? +test_status $retval "${TEST_NAME}" + +# Must be called in the last test to execute +cleanup_exit ${VETH0} ${VETH1} ${NS1} + +test_exit $retval 0 diff --git a/tools/testing/selftests/xsk/TEST_XSK_DRV_TEARDOWN.sh b/tools/testing/selftests/xsk/TEST_XSK_DRV_TEARDOWN.sh index 1867f3c07d74..554dd629faad 100755 --- a/tools/testing/selftests/xsk/TEST_XSK_DRV_TEARDOWN.sh +++ b/tools/testing/selftests/xsk/TEST_XSK_DRV_TEARDOWN.sh @@ -15,7 +15,4 @@ execxdpxceiver params retval=$? test_status $retval "${TEST_NAME}" -# Must be called in the last test to execute -cleanup_exit ${VETH0} ${VETH1} ${NS1} - test_exit $retval 0 diff --git a/tools/testing/selftests/xsk/TEST_XSK_SKB_BIDIRECTIONAL.sh b/tools/testing/selftests/xsk/TEST_XSK_SKB_BIDIRECTIONAL.sh new file mode 100755 index 000000000000..0b9594b38166 --- /dev/null +++ b/tools/testing/selftests/xsk/TEST_XSK_SKB_BIDIRECTIONAL.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright(c) 2020 Intel Corporation. + +#Includes +. prereqs.sh +. xskenv.sh + +TEST_NAME="SKB BIDIRECTIONAL SOCKETS" + +vethXDPgeneric ${VETH0} ${VETH1} ${NS1} + +params=("-S" "-B") +execxdpxceiver params + +retval=$? +test_status $retval "${TEST_NAME}" + +test_exit $retval 0 diff --git a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c index 6877b59f4534..b9d6a988dc07 100644 --- a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c +++ b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.c @@ -49,8 +49,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\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" :\ - "NOPOLL", opt_teardown ? "Socket Teardown" : "")) + (ksft_test_result_pass("PASS: %s %s %s%s\n", uut ? "DRV" : "SKB", opt_poll ? "POLL" :\ + "NOPOLL", opt_teardown ? "Socket Teardown" : "",\ + opt_bidi ? "Bi-directional Sockets" : "")) static void pthread_init_mutex(void) { @@ -256,8 +257,13 @@ static int xsk_configure_socket(struct ifobject *ifobject) cfg.xdp_flags = opt_xdp_flags; cfg.bind_flags = opt_xdp_bind_flags; - rxr = (ifobject->fv.vector == rx) ? &ifobject->xsk->rx : NULL; - txr = (ifobject->fv.vector == tx) ? &ifobject->xsk->tx : NULL; + if (!opt_bidi) { + rxr = (ifobject->fv.vector == rx) ? &ifobject->xsk->rx : NULL; + txr = (ifobject->fv.vector == tx) ? &ifobject->xsk->tx : NULL; + } else { + rxr = &ifobject->xsk->rx; + txr = &ifobject->xsk->tx; + } ret = xsk_socket__create(&ifobject->xsk->xsk, ifobject->ifname, opt_queue, ifobject->umem->umem, rxr, txr, &cfg); @@ -276,6 +282,7 @@ static struct option long_options[] = { {"xdp-native", no_argument, 0, 'N'}, {"copy", no_argument, 0, 'c'}, {"tear-down", no_argument, 0, 'T'}, + {"bidi", optional_argument, 0, 'B'}, {"debug", optional_argument, 0, 'D'}, {"tx-pkt-count", optional_argument, 0, 'C'}, {0, 0, 0, 0} @@ -293,6 +300,7 @@ static void usage(const char *prog) " -N, --xdp-native=n Enforce XDP DRV (native) mode\n" " -c, --copy Force copy mode\n" " -T, --tear-down Tear down sockets by repeatedly recreating them\n" + " -B, --bidi Bi-directional sockets test\n" " -D, --debug Debug mode - dump packets L2 - L5\n" " -C, --tx-pkt-count=n Number of packets to send\n"; ksft_print_msg(str, prog); @@ -383,7 +391,7 @@ static void parse_command_line(int argc, char **argv) opterr = 0; for (;;) { - c = getopt_long(argc, argv, "i:q:pSNcTDC:", long_options, &option_index); + c = getopt_long(argc, argv, "i:q:pSNcTBDC:", long_options, &option_index); if (c == -1) break; @@ -424,6 +432,9 @@ static void parse_command_line(int argc, char **argv) case 'T': opt_teardown = 1; break; + case 'B': + opt_bidi = 1; + break; case 'D': debug_pkt_dump = 1; break; @@ -733,22 +744,25 @@ static void *worker_testapp_validate(void *arg) struct generic_data *data = (struct generic_data *)malloc(sizeof(struct generic_data)); struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr)); struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data; - void *bufs; + void *bufs = NULL; pthread_attr_setstacksize(&attr, THREAD_STACK); - bufs = mmap(NULL, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (bufs == MAP_FAILED) - exit_with_error(errno); + if (!bidi_pass) { + bufs = mmap(NULL, num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE, + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (bufs == MAP_FAILED) + exit_with_error(errno); - if (strcmp(((struct ifobject *)arg)->nsname, "")) - switch_namespace(((struct ifobject *)arg)->ifdict_index); + if (strcmp(((struct ifobject *)arg)->nsname, "")) + switch_namespace(((struct ifobject *)arg)->ifdict_index); + } if (((struct ifobject *)arg)->fv.vector == tx) { int spinningrxctr = 0; - thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_tx); + if (!bidi_pass) + thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_tx); while (atomic_load(&spinning_rx) && spinningrxctr < SOCK_RECONF_CTR) { spinningrxctr++; @@ -778,7 +792,8 @@ static void *worker_testapp_validate(void *arg) struct pollfd fds[MAX_SOCKS] = { }; int ret; - thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_rx); + if (!bidi_pass) + thread_common_ops(arg, bufs, &sync_mutex_tx, &spinning_rx); ksft_print_msg("Interface [%s] vector [Rx]\n", ((struct ifobject *)arg)->ifname); xsk_populate_fill_ring(((struct ifobject *)arg)->umem); @@ -817,8 +832,10 @@ static void *worker_testapp_validate(void *arg) ksft_print_msg("Destroying socket\n"); } - xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk); - (void)xsk_umem__delete(((struct ifobject *)arg)->umem->umem); + if (!opt_bidi || (opt_bidi && bidi_pass)) { + xsk_socket__delete(((struct ifobject *)arg)->xsk->xsk); + (void)xsk_umem__delete(((struct ifobject *)arg)->umem->umem); + } pthread_exit(NULL); } @@ -827,11 +844,26 @@ static void testapp_validate(void) pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, THREAD_STACK); + if (opt_bidi && bidi_pass) { + pthread_init_mutex(); + if (!switching_notify) { + ksft_print_msg("Switching Tx/Rx vectors\n"); + switching_notify++; + } + } + pthread_mutex_lock(&sync_mutex); /*Spawn RX thread */ - if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[1])) - exit_with_error(errno); + if (!opt_bidi || (opt_bidi && !bidi_pass)) { + if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[1])) + exit_with_error(errno); + } else if (opt_bidi && bidi_pass) { + /*switch Tx/Rx vectors */ + ifdict[0]->fv.vector = rx; + if (pthread_create(&t0, &attr, worker_testapp_validate, (void *)ifdict[0])) + exit_with_error(errno); + } struct timespec max_wait = { 0, 0 }; @@ -845,8 +877,15 @@ static void testapp_validate(void) pthread_mutex_unlock(&sync_mutex); /*Spawn TX thread */ - if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[0])) - exit_with_error(errno); + if (!opt_bidi || (opt_bidi && !bidi_pass)) { + if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[0])) + exit_with_error(errno); + } else if (opt_bidi && bidi_pass) { + /*switch Tx/Rx vectors */ + ifdict[1]->fv.vector = tx; + if (pthread_create(&t1, &attr, worker_testapp_validate, (void *)ifdict[1])) + exit_with_error(errno); + } pthread_join(t1, NULL); pthread_join(t0, NULL); @@ -860,18 +899,19 @@ static void testapp_validate(void) free(pkt_buf); } - if (!opt_teardown) + if (!opt_teardown && !opt_bidi) print_ksft_result(); } static void testapp_sockets(void) { - for (int i = 0; i < MAX_TEARDOWN_ITER; i++) { + for (int i = 0; i < (opt_teardown ? MAX_TEARDOWN_ITER : MAX_BIDI_ITER); i++) { pkt_counter = 0; prev_pkt = -1; sigvar = 0; ksft_print_msg("Creating socket\n"); testapp_validate(); + opt_bidi ? bidi_pass++ : bidi_pass; } print_ksft_result(); @@ -940,7 +980,14 @@ int main(int argc, char **argv) ksft_set_plan(1); - opt_teardown ? testapp_sockets() : testapp_validate(); + if (!opt_teardown && !opt_bidi) { + testapp_validate(); + } else if (opt_teardown && opt_bidi) { + ksft_test_result_fail("ERROR: parameters -T and -B cannot be used together\n"); + ksft_exit_xfail(); + } else { + testapp_sockets(); + } for (int i = 0; i < MAX_INTERFACES; i++) free(ifdict[i]); diff --git a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h index 41fc62adad3b..d9b87a719e43 100644 --- a/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h +++ b/tools/testing/selftests/xsk/xdpprogs/xdpxceiver.h @@ -22,6 +22,7 @@ #define MAX_INTERFACES_NAMESPACE_CHARS 10 #define MAX_SOCKS 1 #define MAX_TEARDOWN_ITER 10 +#define MAX_BIDI_ITER 2 #define PKT_HDR_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \ sizeof(struct udphdr)) #define MIN_PKT_SIZE 64 @@ -52,12 +53,15 @@ enum TESTS { u8 uut; u8 debug_pkt_dump; u32 num_frames; +u8 switching_notify; +u8 bidi_pass; static u32 opt_xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static int opt_queue; static int opt_pkt_count; static int opt_poll; static int opt_teardown; +static int opt_bidi; static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE]; static u32 pkt_counter;