From patchwork Mon Apr 29 14:44:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13647069 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AD5B7EF04; Mon, 29 Apr 2024 14:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401873; cv=none; b=ibVhF+i+wZR/p+FkM+kyRCOBQuvuuQ+CRGw+VdEptCrqzI3oNdN7VtiGaG2Z+u96j6UZmudFbKzgzXMoDIWUbbWPqs8qUwtpGs+fTsmPzswf2xA+ek7vvIymaVrQXMLDSUxCrTtzKBiH0VQ7H2pQ9Pf/tfeHLayXo1oagYLgOVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401873; c=relaxed/simple; bh=q2yvj/F84Q34toXFpS8iHIkK9/vno+r8OjUyh0QYzwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iu3n0cvWjBBbfmhzDmIcLw5AD/HISk9eK3U6BUDbQE0YSkJbQYyVQY0UEKu2l8zo0YguNbZCM6j9xThkHqYAZwY/1AeFZ78rqy/R+NwcvSXBBvLIRbL8l3qG7pgQgYaRzblOe00/lVVgBeZ8eQDZ4wyFnvTXaTlZDmuujEV88yI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GvaWLrpT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GvaWLrpT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85FE3C116B1; Mon, 29 Apr 2024 14:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714401872; bh=q2yvj/F84Q34toXFpS8iHIkK9/vno+r8OjUyh0QYzwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GvaWLrpTkGAW7m7VXRKCed4IlTCPHY6n5d4nk+hJb1okIDldo5xdqNqsW4dAJ76EV WoTdpIDdaDPkuxYyPOsBZuz3Dhbc4jCp5CrJoJ6iZMFG5LTicNLXiotNOay32o0CZ9 LVRHeQ5JE0VxyKSS9aiuFZdPF89uhC73sZp8JZKrJ2uILPQ1FUqKVfSgCqBvdSYsLH pw/Kf3YMXfKJUp4hqiWnayJS4P1zgtxXtp3cOCOHulMAYRtQYTf5xS8zhRA8p+5/G1 PI/tE7RDkC5Iju9207HaH1wNeN8h1tFIBccF6QDhOCNd/EsFfb3qE8VeyOpGtfTtIE fA4tGi4jZCpYQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com, Jakub Kicinski , Willem de Bruijn , hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH net-next v2 1/6] net: page_pool: support error injection Date: Mon, 29 Apr 2024 07:44:21 -0700 Message-ID: <20240429144426.743476-2-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429144426.743476-1-kuba@kernel.org> References: <20240429144426.743476-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Because of caching / recycling using the general page allocation failures to induce errors in page pool allocation is very hard. Add direct error injection support to page_pool_alloc_pages(). Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- CC: hawk@kernel.org CC: ilias.apalodimas@linaro.org --- net/core/page_pool.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 273c24429bce..8bcc7014a61a 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -5,6 +5,7 @@ * Copyright (C) 2016 Red Hat, Inc. */ +#include #include #include #include @@ -550,6 +551,7 @@ struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp) return page; } EXPORT_SYMBOL(page_pool_alloc_pages); +ALLOW_ERROR_INJECTION(page_pool_alloc_pages, NULL); /* Calculate distance between two u32 values, valid if distance is below 2^(31) * https://en.wikipedia.org/wiki/Serial_number_arithmetic#General_Solution From patchwork Mon Apr 29 14:44:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13647070 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC6B27FBC8; Mon, 29 Apr 2024 14:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401874; cv=none; b=jdD/x9H1O7aIsv8Z9P45xgfidtOvKf305yJZdfMmEUanDHO/lHgpybC8EiQriyiQvUpbq34ARh2nReDnDoY1zEoiinrxR5hwk9TEcVo7iNpExTPRmEBo/r6iWEL6boi8zEhvhGFC5JQuFAgGkkogpF2zhpYtMEY99vIyPmN0On8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401874; c=relaxed/simple; bh=p2z2h5vG0yu/HelbmuJbgpX2U46xn4dXGiCYIuFOtIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FP5gp11K3kqlWxY9BBWDAfx5mO/XuGdYIi4GDG18vqSI4YW3YQ8O1QNExcF92UvlNKapGd1ZW/XsrvRmGpAJcr7UPIh/IGvrqy/5uy1Rh4CtX19gU6i0I7ZNCeVS60GbvIg6Mm8OT77XUzbd2jdFl5ra3e3QZuaawAwozPnAk4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g+YRdmvw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g+YRdmvw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B84AC4AF1D; Mon, 29 Apr 2024 14:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714401873; bh=p2z2h5vG0yu/HelbmuJbgpX2U46xn4dXGiCYIuFOtIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+YRdmvwTPsx9/FKHCY5jH3/TloKkj7yXBHHX2blXUuMx1gwIqv3B/Dd1lQJsxncr 2yVVBo0YxpJ/GB5bVX4BpSbnZeeReCLAWj8HWLBRIVH1z/9dkoW18Ek1W2BGDel5+I lIzCI0QaUtykiw3F+D1URh4JWJ4JpvmjjaxegKj/Kv8jA2mFfKBVvCk6dlKu5K9oqb reH1MRZdpZ4tIsVzuvSBHxH/7ZYdOGM66XRxaOqe17A2I+9yo/AH2XL4u/g7N9T7c+ xGTTOyid3cNbW0HFH28uEKvLtXpXW7gvtGv9ik9IsRbMlisI4+FM37oOK9A7LrR6KS NGMViSkLujIFw== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com, Jakub Kicinski , Willem de Bruijn Subject: [PATCH net-next v2 2/6] selftests: drv-net-hw: support using Python from net hw tests Date: Mon, 29 Apr 2024 07:44:22 -0700 Message-ID: <20240429144426.743476-3-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429144426.743476-1-kuba@kernel.org> References: <20240429144426.743476-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We created a separate directory for HW-only tests, recently. Glue in the Python test library there, Python is a bit annoying when it comes to using library code located "lower" in the directory structure. Reuse the Env class, but let tests require non-nsim setup. Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/Makefile | 2 +- tools/testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/lib/py/__init__.py | 16 ++++++++++++++++ .../testing/selftests/drivers/net/lib/py/env.py | 10 ++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/drivers/net/hw/lib/py/__init__.py diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 2c940e9c4ced..9039f3709aff 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -119,7 +119,7 @@ TARGETS_HOTPLUG = cpu-hotplug TARGETS_HOTPLUG += memory-hotplug # Networking tests want the net/lib target, include it automatically -ifneq ($(filter net drivers/net,$(TARGETS)),) +ifneq ($(filter net drivers/net drivers/net/hw,$(TARGETS)),) ifeq ($(filter net/lib,$(TARGETS)),) INSTALL_DEP_TARGETS := net/lib endif diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 2259a39a70ed..95f32158b095 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -16,6 +16,7 @@ TEST_FILES := \ # TEST_INCLUDES := \ + $(wildcard lib/py/*.py ../lib/py/*.py) \ ../../../net/lib.sh \ ../../../net/forwarding/lib.sh \ ../../../net/forwarding/ipip_lib.sh \ diff --git a/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py new file mode 100644 index 000000000000..b582885786f5 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/lib/py/__init__.py @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 + +import sys +from pathlib import Path + +KSFT_DIR = (Path(__file__).parent / "../../../../..").resolve() + +try: + sys.path.append(KSFT_DIR.as_posix()) + from net.lib.py import * + from drivers.net.lib.py import * +except ModuleNotFoundError as e: + ksft_pr("Failed importing `net` library from kernel sources") + ksft_pr(str(e)) + ktap_result(True, comment="SKIP") + sys.exit(4) diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py index e2ab637e56dc..5c8f695b2536 100644 --- a/tools/testing/selftests/drivers/net/lib/py/env.py +++ b/tools/testing/selftests/drivers/net/lib/py/env.py @@ -2,7 +2,7 @@ import os from pathlib import Path -from lib.py import KsftSkipEx +from lib.py import KsftSkipEx, KsftXfailEx from lib.py import cmd, ip from lib.py import NetNS, NetdevSimDev from .remote import Remote @@ -76,7 +76,7 @@ from .remote import Remote nsim_v4_pfx = "192.0.2." nsim_v6_pfx = "2001:db8::" - def __init__(self, src_path): + def __init__(self, src_path, nsim_test=None): self.env = _load_env_file(src_path) @@ -88,7 +88,10 @@ from .remote import Remote self._ns_peer = None if "NETIF" in self.env: + if nsim_test is True: + raise KsftXfailEx("Test only works on netdevsim") self._check_env() + self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0] self.v4 = self.env.get("LOCAL_V4") @@ -98,6 +101,9 @@ from .remote import Remote kind = self.env["REMOTE_TYPE"] args = self.env["REMOTE_ARGS"] else: + if nsim_test is False: + raise KsftXfailEx("Test does not work on netdevsim") + self.create_local() self.dev = self._ns.nsims[0].dev From patchwork Mon Apr 29 14:44:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13647071 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C89F80603; Mon, 29 Apr 2024 14:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401874; cv=none; b=hxQSOKrT8qq8gpCJ9nrMmVMtzObN9AWkVz3qK8grjHbitZiQZokblmY/AOjQia4lVxHuQ/owHBrvakzYIFEIWQWU59covZdj17y03ecgVaNyHrwE/ufE7pp6lZoSvErleC8r6kT7NRiFO3bIcM2dyNpXxBbaxo/Z0ATiL3gblKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401874; c=relaxed/simple; bh=6jqd5U+F65l8v2GGjV8nPwQfU+VslA3x6+xTZifk+uE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GBNYnUBh1x5idJhUOfS/Jy5TpCqLIUbyn5cJEQe2Rp4bNQ5pE7AqVcP00bJGqTQl4p1exTwVWK6+nt4PvJyTxdALTIYcG7hkgJatB8j0yGl1QBsEVSXMQGFnxU1kOd7HesB7yy/tLuieVu3xJTdi2rh6gRcIsjLWcpS55dPR0jc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZRJsI3rF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZRJsI3rF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93751C4AF1B; Mon, 29 Apr 2024 14:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714401873; bh=6jqd5U+F65l8v2GGjV8nPwQfU+VslA3x6+xTZifk+uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZRJsI3rFs7z+B3TDyYNYxFbUYeFhNmmG7H+Ss6UBnWUoY4nyU3LXqoj6OOYxfe5U0 SFIvvm28VVI2ESFAMFFG7a4xgWQzI8w5L1afBBporFsg4gLsz0w+/FvrMJ2/WYIkbx K+1/3G0vGcgyohS7U/FMOjf+E7w/5INm2ntKXaeNGjPdyLuQM7RHCPK7juflHDOI6+ FySFuHrCbNjSkgis0XriLpXtcMKTLEiclDKTXGbabs8TDwa6N9huLZioKp1ytjMPFs jOVvoLwLdqVRqEvtsKKCHeasZXBxlVJt2APjny0Iyfj7JCkOfxgN00MFX34YcTuiAE E8VPo5MrLBkEA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com, Jakub Kicinski , Willem de Bruijn Subject: [PATCH net-next v2 3/6] selftests: net: py: extract tool logic Date: Mon, 29 Apr 2024 07:44:23 -0700 Message-ID: <20240429144426.743476-4-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429144426.743476-1-kuba@kernel.org> References: <20240429144426.743476-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The main use of the ip() wrapper over cmd() is that it can parse JSON. cmd("ip -j link show") will return stdout as a string, and test has to call json.loads(). With ip("link show", json=True) the return value will be already parsed. More tools (ethtool, bpftool etc.) support the --json switch. To avoid having to wrap all of them individually create a tool() helper. Switch from -j to --json (for ethtool). While at it consume the netns attribute at the ip() level. Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- v2: - use consistent quote type - use format string to force string conversion of NetNS class --- tools/testing/selftests/net/lib/py/utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index d3715e6c21f2..4930a90a64ea 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -56,10 +56,10 @@ import time return self.process(terminate=self.terminate) -def ip(args, json=None, ns=None, host=None): - cmd_str = "ip " +def tool(name, args, json=None, ns=None, host=None): + cmd_str = name + ' ' if json: - cmd_str += '-j ' + cmd_str += '--json ' cmd_str += args cmd_obj = cmd(cmd_str, ns=ns, host=host) if json: @@ -67,6 +67,12 @@ import time return cmd_obj +def ip(args, json=None, ns=None, host=None): + if ns: + args = f'-netns {ns} ' + args + return tool('ip', args, json=json, host=host) + + def rand_port(): """ Get unprivileged port, for now just random, one day we may decide to check if used. From patchwork Mon Apr 29 14:44:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13647072 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB1937EEF2; Mon, 29 Apr 2024 14:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401874; cv=none; b=qdGrTn7sUMKkzCbwpLDvFBegW0836c965rwy+78Xxrfqsz1QmkPcOKFaTqvFCeFvhyypvt+JQg0KBeypQzyk+IE2Fj27ub0hvPVETV1bYp/LBP6qb5wa0Bs976oi++TYUPeMjbZ4UTExfIGoexm3Vik9UxvyoqlBznFNp5njg1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401874; c=relaxed/simple; bh=A5ZREJgKCRvW7P1Icrpp2yG+uJX4Xa3NZeRS99O14WY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uBFRstHucVionRxi4PF2sB6LS/tx57DYfCSUMuLpsh1Wv9L+O15+ez3uyGhVJgkZqnHHp6QRpwWxRt5BESHImWirkz69FDVEKBx6QytFGskbGyQ1ThYHu7Z0F1vF6QoHGNxlPVXWenRDoPrl775eISqnxFs6/Qm3vjFbBKCuolQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MuwsAiRF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MuwsAiRF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16AA9C4AF50; Mon, 29 Apr 2024 14:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714401874; bh=A5ZREJgKCRvW7P1Icrpp2yG+uJX4Xa3NZeRS99O14WY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MuwsAiRFAwfnlKzjtVTRCjm2Sm4797RqSAEgd4srfb0hfTVzaq8x2pO4tMxbe0/yx Z8nzvbr0c6yN2dqdvNzg3elmDuoiZsQ6dQe7cpDlMlEdtFgV7OIEN24RYUKacPtY/w 5DsnDjdS3LgUoC+obr1KMNXc0MwdeFTzy4e4dwOuHiqdD7HwbUuvXcAe4XrQK2BE5i igfYpSpYt54IWjdlqHbQEsMsUXZhnuA5aVaWfBUY5TuHmpr3E8ZR/qHp2mv4gJ6Suz PwyDmSwg29Jy+Qtn1MMD1saj8m9lIJoBYFqmOt35EakX9OVcPE7kLFhNVD6a6+D8+8 /OkNvkNBkOxKg== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com, Jakub Kicinski , Willem de Bruijn Subject: [PATCH net-next v2 4/6] selftests: net: py: avoid all ports < 10k Date: Mon, 29 Apr 2024 07:44:24 -0700 Message-ID: <20240429144426.743476-5-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429144426.743476-1-kuba@kernel.org> References: <20240429144426.743476-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When picking TCP ports to use, avoid all below 10k. This should lower the chance of collision or running afoul whatever random policies may be on the host. Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/py/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index 4930a90a64ea..b57d467afd0f 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -77,7 +77,7 @@ import time """ Get unprivileged port, for now just random, one day we may decide to check if used. """ - return random.randint(1024, 65535) + return random.randint(10000, 65535) def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadline=5): From patchwork Mon Apr 29 14:44:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13647073 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 117157F484; Mon, 29 Apr 2024 14:44:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401875; cv=none; b=Wa1478ay59Uv0HM7HDCZf+8FSkikiiE7DFUfCL2nCmm9Qq8CVjFr/s9Fw/Fo5Lt/GbDB7AmxXlTVUbGdAiTkxmrgJ/KF5eNuaPmTV47bz5/64TMCfm36t8d5pfPGS/5MnTaS99Fk/Dx8mc/0j7liCq7qXbrGXaSOYRE96Ay4gdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401875; c=relaxed/simple; bh=9ZJmaESfiWUDYEEn0PcnEMJclTrwEH+GHbRxg7JtARU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y3LQFLhTYywQrOFdtSPOWRBxyPNb2/scWe1S1m5pzT4R5ptLNSQwzfvEYVTmurSr2m9xl3Z58UPKsEw3WoWhObKHLQaPjPcyq1dhmRO2BHm4TbiPi1eLHVzxYSQetr2j4MQfMBewCBysdKaF53zXhv1n0Uo3KyrF99JRqQSpSKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NDCKh/uj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NDCKh/uj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90896C4AF1A; Mon, 29 Apr 2024 14:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714401874; bh=9ZJmaESfiWUDYEEn0PcnEMJclTrwEH+GHbRxg7JtARU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NDCKh/uj7vzoQTFH9W6Uaztn3RBoR+mjNJplkg7QGh9xXUcfNNUcLFHRMU7FUVS9S 6dEj97vglHhfPCC8qaPS6s+9JWLSADkjQFQ4Y/ABHxiokbl4od4k//qMdP/qtFXOx1 cDjT9bBo0FsAhCPb8NmHiA15von29CeOhD4U+c4nBTEJsrOyS+l/I5EpwEd4zfbEj7 5ng29kIYIQ0jy9tVaB/Lx8XFlzn1hemHxuJ8Wbxa/DPm6AtEV487vNmue0eplsjLX1 xmevuulp+wBDbJCqDcgr6IWj/Ay8IySxf7qxl2fryI58qg/egGexvq6VWOswMVfOSk YeBqDDa7kzYgQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com, Jakub Kicinski , Willem de Bruijn Subject: [PATCH net-next v2 5/6] selftests: drv-net: support generating iperf3 load Date: Mon, 29 Apr 2024 07:44:25 -0700 Message-ID: <20240429144426.743476-6-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429144426.743476-1-kuba@kernel.org> References: <20240429144426.743476-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While we are not very interested in testing performance it's useful to be able to generate a lot of traffic. iperf is the simplest way of getting relatively high PPS. Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- v2: - fix import order in __init__.py --- .../selftests/drivers/net/lib/py/__init__.py | 1 + .../selftests/drivers/net/lib/py/load.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/lib/py/load.py diff --git a/tools/testing/selftests/drivers/net/lib/py/__init__.py b/tools/testing/selftests/drivers/net/lib/py/__init__.py index 4789c1a4282d..401e70f7f136 100644 --- a/tools/testing/selftests/drivers/net/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py @@ -15,4 +15,5 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve() sys.exit(4) from .env import * +from .load import * from .remote import Remote diff --git a/tools/testing/selftests/drivers/net/lib/py/load.py b/tools/testing/selftests/drivers/net/lib/py/load.py new file mode 100644 index 000000000000..abdb677bdb1c --- /dev/null +++ b/tools/testing/selftests/drivers/net/lib/py/load.py @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-2.0 + +import time + +from lib.py import ksft_pr, cmd, ip, rand_port, wait_port_listen + +class GenerateTraffic: + def __init__(self, env): + env.require_cmd("iperf3", remote=True) + + self.env = env + + port = rand_port() + self._iperf_server = cmd(f"iperf3 -s -p {port}", background=True) + wait_port_listen(port) + time.sleep(0.1) + self._iperf_client = cmd(f"iperf3 -c {env.addr} -P 16 -p {port} -t 86400", + background=True, host=env.remote) + + # Wait for traffic to ramp up + pkt = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"] + for _ in range(50): + time.sleep(0.1) + now = ip("-s link show dev " + env.ifname, json=True)[0]["stats64"]["rx"]["packets"] + if now - pkt > 1000: + return + pkt = now + self.stop(verbose=True) + raise Exception("iperf3 traffic did not ramp up") + + def stop(self, verbose=None): + self._iperf_client.process(terminate=True) + if verbose: + ksft_pr(">> Client:") + ksft_pr(self._iperf_client.stdout) + ksft_pr(self._iperf_client.stderr) + self._iperf_server.process(terminate=True) + if verbose: + ksft_pr(">> Server:") + ksft_pr(self._iperf_server.stdout) + ksft_pr(self._iperf_server.stderr) From patchwork Mon Apr 29 14:44:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13647074 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D96D781745; Mon, 29 Apr 2024 14:44:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401875; cv=none; b=uqRihtv2FBQ+CcR1PE/HKwzYNKyQ+qy753nJ7SEJ+lZMGH2grbwCpGZsgTlt5yATYqJRMp9EdxmZJsPo93yBQDrLetN7Znsv3fQQjEYf+CfEeNFoLgLuNX6lylEDRPR7s1tn8BGuAEqMgP1l09jg0O2gqj2BNgjoZLVnJD/Hz+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714401875; c=relaxed/simple; bh=SDllwCyBkau8KID+VjwwqBdxYX2WiKlosdaB+BB7p/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKdfjpbuy0Mq5F9HzVJEFVuBrBQ3uJGIrWr3MTLfi4X5FKWPTFMQ3iFWqO3g6iFQLkMYjRE8Azhe+SEV+KhOKn3MsZevjNIba7yMPKec8nYqPjfj7SnzbJhwMZfWvXLM0ca5hNs9R3VlCV6OuaWOrjiHx13ReU156hmCoyczKBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ozb+9x6H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ozb+9x6H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1697AC4AF48; Mon, 29 Apr 2024 14:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714401875; bh=SDllwCyBkau8KID+VjwwqBdxYX2WiKlosdaB+BB7p/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ozb+9x6HnAzQG16hdeefNf56zilC9JvKfEzK5pOAl+oKkEArFfh7WPscf08oi9Fki ADLUDcpEmyYWpicYIEreXOouiWxp4/NIA1F1jM7wY4GubKKr2VwpDhN/gtOM/hcm3s 9fUSVxVVt6e/qoIhiGY1gV/FwBX5uXQB4ulK8Y370Ic9Cvw+OjAGOHKMG80ico/qTN fwBN2myeDsG7xxZqwQ3qlMgiMPK5jsc0U6teiMq0GSjLB0QHR0vxqtseJIGC/c0/T0 Ct82LM5RWIP2QG2rEcmSA+h4OFl/Ppo4qVC6ODdc53qNQc9Rza1GENMVg8C8IOHT7v TAgODWs1WNN5Q== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com, Jakub Kicinski , Willem de Bruijn Subject: [PATCH net-next v2 6/6] selftests: drv-net-hw: add test for memory allocation failures with page pool Date: Mon, 29 Apr 2024 07:44:26 -0700 Message-ID: <20240429144426.743476-7-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240429144426.743476-1-kuba@kernel.org> References: <20240429144426.743476-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Bugs in memory allocation failure paths are quite common. Add a test exercising those paths based on qstat and page pool failure hook. Running on bnxt: # ./drivers/net/hw/pp_alloc_fail.py KTAP version 1 1..1 # ethtool -G change retval: success ok 1 pp_alloc_fail.test_pp_alloc # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0 I initially wrote this test to validate commit be43b7489a3c ("net/mlx5e: RX, Fix page_pool allocation failure recovery for striding rq") but mlx5 still doesn't have qstat. So I run it on bnxt, and while bnxt survives I found the problem fixed in commit 730117730709 ("eth: bnxt: fix counting packets discarded due to OOM and netpoll"). Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- .../testing/selftests/drivers/net/hw/Makefile | 1 + .../selftests/drivers/net/hw/pp_alloc_fail.py | 129 ++++++++++++++++++ tools/testing/selftests/net/lib/py/ksft.py | 4 + 3 files changed, 134 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py diff --git a/tools/testing/selftests/drivers/net/hw/Makefile b/tools/testing/selftests/drivers/net/hw/Makefile index 95f32158b095..1dd732855d76 100644 --- a/tools/testing/selftests/drivers/net/hw/Makefile +++ b/tools/testing/selftests/drivers/net/hw/Makefile @@ -9,6 +9,7 @@ TEST_PROGS = \ hw_stats_l3.sh \ hw_stats_l3_gre.sh \ loopback.sh \ + pp_alloc_fail.py \ # TEST_FILES := \ diff --git a/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py b/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py new file mode 100755 index 000000000000..026d98976c35 --- /dev/null +++ b/tools/testing/selftests/drivers/net/hw/pp_alloc_fail.py @@ -0,0 +1,129 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import time +import os +from lib.py import ksft_run, ksft_exit, ksft_pr +from lib.py import KsftSkipEx, KsftFailEx +from lib.py import NetdevFamily, NlError +from lib.py import NetDrvEpEnv +from lib.py import cmd, tool, GenerateTraffic + + +def _write_fail_config(config): + for key, value in config.items(): + with open("/sys/kernel/debug/fail_function/" + key, "w") as fp: + fp.write(str(value) + "\n") + + +def _enable_pp_allocation_fail(): + if not os.path.exists("/sys/kernel/debug/fail_function"): + raise KsftSkipEx("Kernel built without function error injection (or DebugFS)") + + if not os.path.exists("/sys/kernel/debug/fail_function/page_pool_alloc_pages"): + with open("/sys/kernel/debug/fail_function/inject", "w") as fp: + fp.write("page_pool_alloc_pages\n") + + _write_fail_config({ + "verbose": 0, + "interval": 511, + "probability": 100, + "times": -1, + }) + + +def _disable_pp_allocation_fail(): + if not os.path.exists("/sys/kernel/debug/fail_function"): + return + + if os.path.exists("/sys/kernel/debug/fail_function/page_pool_alloc_pages"): + with open("/sys/kernel/debug/fail_function/inject", "w") as fp: + fp.write("\n") + + _write_fail_config({ + "probability": 0, + "times": 0, + }) + + +def test_pp_alloc(cfg, netdevnl): + def get_stats(): + return netdevnl.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0] + + def check_traffic_flowing(): + stat1 = get_stats() + time.sleep(1) + stat2 = get_stats() + if stat2['rx-packets'] - stat1['rx-packets'] < 15000: + raise KsftFailEx("Traffic seems low:", stat2['rx-packets'] - stat1['rx-packets']) + + + try: + stats = get_stats() + except NlError as e: + if e.nl_msg.error == -95: + stats = {} + else: + raise + if 'rx-alloc-fail' not in stats: + raise KsftSkipEx("Driver does not report 'rx-alloc-fail' via qstats") + + set_g = False + traffic = None + try: + traffic = GenerateTraffic(cfg) + + check_traffic_flowing() + + _enable_pp_allocation_fail() + + s1 = get_stats() + time.sleep(3) + s2 = get_stats() + + if s2['rx-alloc-fail'] - s1['rx-alloc-fail'] < 1: + raise KsftSkipEx("Allocation failures not increasing") + if s2['rx-alloc-fail'] - s1['rx-alloc-fail'] < 100: + raise KsftSkipEx("Allocation increasing too slowly", s2['rx-alloc-fail'] - s1['rx-alloc-fail'], + "packets:", s2['rx-packets'] - s1['rx-packets']) + + # Basic failures are fine, try to wobble some settings to catch extra failures + check_traffic_flowing() + g = tool("ethtool", "-g " + cfg.ifname, json=True)[0] + if 'rx' in g and g["rx"] * 2 <= g["rx-max"]: + new_g = g['rx'] * 2 + elif 'rx' in g: + new_g = g['rx'] // 2 + else: + new_g = None + + if new_g: + set_g = cmd(f"ethtool -G {cfg.ifname} rx {new_g}", fail=False).ret == 0 + if set_g: + ksft_pr("ethtool -G change retval: success") + else: + ksft_pr("ethtool -G change retval: did not succeed", new_g) + else: + ksft_pr("ethtool -G change retval: did not try") + + time.sleep(0.1) + check_traffic_flowing() + finally: + _disable_pp_allocation_fail() + if traffic: + traffic.stop() + time.sleep(0.1) + if set_g: + cmd(f"ethtool -G {cfg.ifname} rx {g['rx']}") + + +def main() -> None: + netdevnl = NetdevFamily() + with NetDrvEpEnv(__file__, nsim_test=False) as cfg: + + ksft_run([test_pp_alloc], args=(cfg, netdevnl, )) + ksft_exit() + + +if __name__ == "__main__": + main() diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index f84e9fdd0032..4769b4eb1ea1 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -11,6 +11,10 @@ KSFT_RESULT = None KSFT_RESULT_ALL = True +class KsftFailEx(Exception): + pass + + class KsftSkipEx(Exception): pass