From patchwork Fri Apr 26 23:23:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 792988 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 229A03BBDC; Fri, 26 Apr 2024 23:24:04 +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=1714173845; cv=none; b=R/0Cd6/Pufj1zqHjFN0Lrc6cAw2VBf8Dpd3wf+Ye4apE3jaV6v+ih+CRcavTJz1YC70nwWIU19nwdTr2lQt66WE4MZJmeOKpVYVLZMqeTvLUFLPssaPbY+TmYFC8NA5jJsBZE4zpzJGsTzQZEFmvSg7UE6U8UDdw2uYesd7xqWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714173845; c=relaxed/simple; bh=mORTOztAviz6anBh5JZKiWwXRJ8TMklFXNQyvGi9kww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KauAGEPcumji5BS7v2NDNPtJHior+ca4MQXHwEgTtyx0F71fiwVh0kK9yObsAowdgXsJuDycf1oEcdlCPu2ZpMNSG1vgs+CFmI80giaEqFTCpU6PsVOJNwN6pHst0tvfIt2ECWIsSAtNz0qBd+FQUb+gQUmQJOOo95rV5yyyfDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ck2xVZBP; 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="ck2xVZBP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53CE0C32781; Fri, 26 Apr 2024 23:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714173844; bh=mORTOztAviz6anBh5JZKiWwXRJ8TMklFXNQyvGi9kww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ck2xVZBP/oc16lHGI+QqSwwyOcUaE2hxktIMS7IMcctdoYJL4FdMzrEm49J8l8j8B h8LCa8HsVXm/fWB95aEoT8ler3D7AMmhb4biaMolqaQiGfSpd3PRmey5uzRLebLTwA rn609d2W72Ya8xOnulKXUrEVoVPPUJzWXFOuHaUAcKNtxBTvj5S2MzZsJ25qqm/a40 qcNb6NyUV6lp3JIEw5YeJPgnxy7C1hXxAK0PjONXonbjx4cWN8dNL7r3tCgzRcwFi8 UkkadNl+yvbjMkW6OsijomdwfkEgmwMLuA50kQxe5uYqt1ciOa1fa0/EIIg2Sfb92k IjqHvht98yxcw== 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 , hawk@kernel.org, ilias.apalodimas@linaro.org Subject: [PATCH net-next 1/6] net: page_pool: support error injection Date: Fri, 26 Apr 2024 16:23:54 -0700 Message-ID: <20240426232400.624864-2-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426232400.624864-1-kuba@kernel.org> References: <20240426232400.624864-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(). Signed-off-by: Jakub Kicinski Acked-by: Jesper Dangaard Brouer --- 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 Fri Apr 26 23:23:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 792470 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 A60003C463; Fri, 26 Apr 2024 23:24:05 +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=1714173845; cv=none; b=hHGfrABnWzQA38bcizZwx0Q48drTztqBPaIpld27p2TgxEiV/BGsFiVlJZJlvZRfGgRM8haIp9oZ0//QiR8BD87ZF5R9Vygf+hvLIc36ySHXIJBbGqEizbTaus0KrizN3g1W9uBFwxhuan0aqVSPzHpKHs2C66ibVAFxlYMW0Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714173845; c=relaxed/simple; bh=R2MeTPPej4K2BQjN/dfOWT2R2ABVWvDqMSdtBKSl1zU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LtBPUGUmLAw32CvZYQlcO8TxacUgI+cC8C2Kn2FIPlMLV1ehxzq0LRrPUZm7hYsVGK5HY2/aElQKOnX4r7LPsjRMGZeSd1SX1r9XoDpOOSUeVIwTu7s/ovqyttR+yxsPrMQtcYNfnR7bL+PjAwm6+WvrR+MA1/iBDAjNeR6qJ00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=REsYpzzz; 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="REsYpzzz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1653C2BD11; Fri, 26 Apr 2024 23:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714173845; bh=R2MeTPPej4K2BQjN/dfOWT2R2ABVWvDqMSdtBKSl1zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REsYpzzzip2dW3wA8jvVnGqBElwgGZctDhxXVn0vCr02cgSAiww34/MT2opzB2T2o JHAJ1aipOn/Km6cTmtA6LnkhP6RjTUClhxuuuEsltv5ffLKg17cNzKVEd2wTWj11Sh Le1RooQq5FezBV3HkPHlvaNcR1rSLVG1f+QCoxoTh7W+jBr2jep1nZsDqL0RzSnbUd bnEG6usgsf4UGDtmOjBZ8ZTl0HHUFPHpyc1DcTfVWC+ci60boqqFP07P1M3gHmwk85 +Ps5qnx1WfYno8FLBu7L5dOqqeorzqvjTiSSKm1IB7gB/T3TD82LwQlZIxh6n8/rAB +x1AjIy8uu2Vg== 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 Subject: [PATCH net-next 2/6] selftests: drv-net-hw: support using Python from net hw tests Date: Fri, 26 Apr 2024 16:23:55 -0700 Message-ID: <20240426232400.624864-3-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426232400.624864-1-kuba@kernel.org> References: <20240426232400.624864-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. 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 Fri Apr 26 23:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 792987 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 D96F43D0C5; Fri, 26 Apr 2024 23:24:05 +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=1714173845; cv=none; b=SyPhez/UCGF+j7UrMfiQf7TAHINBQ2pFjwTh7JpXmboc49UqSbPx+2gJ+qH9psAxnHKZeqsU3hOT2ammZriv7NMcrQBA4C7UxVMt1OueEfRFI+KiOKJ2zvNmmTQS9QY28MdJxAxIXRxvvRYpABtiExVnODm4YQusKAi4iBIvW1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714173845; c=relaxed/simple; bh=JeQ35s6yBVRaqXvMkpIQzzUCCOzpP8v/SETOU7be0NM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VUyf17TaktCfGuDG6plHHceOmYdkzpo0MPb4G9NetvRLR/uu1z1lyf8saCyKRq4QjAV6kq3SfC7gKKdtyt96OzmXDp531mEqfrISSrQ+4Sa2j30Rw91SfkKL0fmh026mf3ZvZgqcaCwLvsMPK9imhU/1a8dRRMU6PgL4bdIOVBs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EdnUuhQz; 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="EdnUuhQz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EBECC32783; Fri, 26 Apr 2024 23:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714173845; bh=JeQ35s6yBVRaqXvMkpIQzzUCCOzpP8v/SETOU7be0NM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EdnUuhQzYNNkUdyy/FuZ8rGUOGKQpRGs8lGxvM2jvlan2+eTdOOxsOiFIrA/MWzAp 48BOgPuZYv5kerFtPvzpPbaLW4hwSjev2UnyYe1+ah1OjbphubS8jkcAG0cznXvtQx oP2U4UxlsHLK5CBr81g1x+do6gCnbQPdhes008pPlSdCbFbYRLleXzsmnGnXiAiu4i KHEjNFC8jgMPWyXcLjxnubu2bkAHWLUH0gCkHtMtrWCMj5xk4xw/ku2e0wPOIDN6Dl priG1yLlZk6j8As+YQe/ptk9gJwvucEiAakdZ2C+db0vwismGTQE+J2lYGwDpi3JOQ aaE4e+FolUA+w== 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 Subject: [PATCH net-next 3/6] selftests: net: py: extract tool logic Date: Fri, 26 Apr 2024 16:23:56 -0700 Message-ID: <20240426232400.624864-4-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426232400.624864-1-kuba@kernel.org> References: <20240426232400.624864-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. Signed-off-by: Jakub Kicinski --- 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..11b588a2bb9d 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 = '-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 Fri Apr 26 23:23:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 792469 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 D1E593F9D4; Fri, 26 Apr 2024 23:24:06 +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=1714173846; cv=none; b=u1/B5QDkntd0cJ5w5bPqeg4ksnUp6r08QcTrX1Aha3czMCnw/twYFyx4KxaxREPYYBojLPybjzyIWvB6kIbqIKlsGpUx73i0vpQSB+LkvXvkZ+JrajQnafe0WgVu4fG20/PuoyK4F5Tu5M0qMXgda0AI52HihM+C8A/orFypRWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714173846; c=relaxed/simple; bh=5jqwXOyQToPv0k8xyfI1wlEGdOtc42g28NCgzOvVDRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CfRIp26Ot4bGFsUGpNUTBNF4MFkUEbVfckGTmZZRaFv8/iDMuv4Ye5di3rHdtK40UIrFB/7uzb3l9OHuzuWuvEY6MHmcWHhX/0xpcKaRV7a5f/iseu0vlHSzHVy3b8FVfbevFTk9NiFEYkJaRhkSyleHQ/7x07hWtC4Hsi0b7fU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sBCgt1oH; 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="sBCgt1oH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E81A6C2BD11; Fri, 26 Apr 2024 23:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714173846; bh=5jqwXOyQToPv0k8xyfI1wlEGdOtc42g28NCgzOvVDRk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBCgt1oHJ76eZVzfkjVox2yCO359uqbNxXAD3hChiMGH3MVj4l/ueFj8q0nY3Z0yP AW63pEvYBzFfA7LXMeN9mNAKjRYaKMJWBuKrpIxhBzHHet+t1Lt4YQtMKSs51MXAo2 V3muw2pL2x6ScezLv0cU29725cF/jbfg4U7TtXX3hGsR1cFJTWuQvP/cvRRpjWdTmn hwRbTKjvrWWFfVfHmsgWNPxbIUq3SdUUQIiUb61qGF1BMSgTysDltXNJvUa9mnUT/N /uHDlRVXKV0SpZMyhZIkG6Lh46fhoCG0b6+3D88Y/m2qZcgL1gHnQ6Uu/BFNgg5quO jM7UNJmfbAg0Q== 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 Subject: [PATCH net-next 4/6] selftests: net: py: avoid all ports < 10k Date: Fri, 26 Apr 2024 16:23:57 -0700 Message-ID: <20240426232400.624864-5-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426232400.624864-1-kuba@kernel.org> References: <20240426232400.624864-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. 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 11b588a2bb9d..074b792ec943 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 Fri Apr 26 23:23:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 792986 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 257103FB99; Fri, 26 Apr 2024 23:24:06 +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=1714173847; cv=none; b=j4t/oMsFlNrQvmHh/eY6KgWHkWAcg4OtBTy0w0xKoo+opQrlkpafX5g/9w8Q1iKkIE9k32ciIofIhOTBneyKWzQRQ70i7YHgY9sAQb2YpqXNNHpNpAXPkHW52fIA+jXU9DxM6i4fCVDU0HhyTFTmH1R+bnqVIfHfvPB96YoO/Io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714173847; c=relaxed/simple; bh=xtWhklSsxR+Wwpdusjmi/7VnELcfUQUxyVVhnNTi7ns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ootl31pdbaNLqSBLS0e5lXb/8JSrAH1mxBKtkGJwMj5mBnOxLSvkdA1SxfGSo6QQG+BOwl55wRDglUC6CXx6NsimZo0+bUm/m8RVcw8qQjwxjfRmcYgZYakzMguL0ZaNlae41pw+18gJraOZm7DYpiL1gG/3MH0StgbIUlPlPIY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h0P3/LWk; 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="h0P3/LWk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68C69C32781; Fri, 26 Apr 2024 23:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714173846; bh=xtWhklSsxR+Wwpdusjmi/7VnELcfUQUxyVVhnNTi7ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h0P3/LWkgWqD+k7ZqpVFqJOAVacLbllQAmtSogoYk3JjBhnPi9r8IaXpgb94hwaWe G82XvxvCeuUIbcY7tsuQfm00mpYaxAgcPJ4IUM+KGxuprf0g6QGq1ZQ5rrC+G5/2mt cdIPaPYkoepUa9U7kvLD346UVIO1enEmwPK1px4FbnXl9K6suNpNNzYULW5B8iVs7R yB3qlbaCEvUr/jFeKfDHIcqZwwcYNmRQWdLiKi/oYzSe5JMuxwuyxGIUbW4+2K58wd KjwQZvtV38GL5aGk8oOGtjE27cYr/FIQWrY8YTUr5RR+TG83MTvkKKPheD5qLlM5/p GzM9ATIlCulDA== 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 Subject: [PATCH net-next 5/6] selftests: drv-net: support generating iperf3 load Date: Fri, 26 Apr 2024 16:23:58 -0700 Message-ID: <20240426232400.624864-6-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426232400.624864-1-kuba@kernel.org> References: <20240426232400.624864-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. Signed-off-by: Jakub Kicinski --- .../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..2a2dbb1b4ad7 100644 --- a/tools/testing/selftests/drivers/net/lib/py/__init__.py +++ b/tools/testing/selftests/drivers/net/lib/py/__init__.py @@ -2,6 +2,7 @@ import sys from pathlib import Path +from .load import * KSFT_DIR = (Path(__file__).parent / "../../../..").resolve() 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 Fri Apr 26 23:23:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 792468 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 B1453405FC; Fri, 26 Apr 2024 23:24:07 +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=1714173847; cv=none; b=ViY9KSpa2Ia6RJS3WbyfK1iHUDefPVSGz8qBIZo1pENYmg9Gx4gnR24KBVsdoAT/Rv3Whmg1dyEKiPLEsuHlgzMVlThrCb2M/Wr4cAE20rbdMU6w4/olaTQ1AOaXmSYsf5xjcwL1EEa2SykXWQjjXDYKWi2kN6CFc9e+eRbhkX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714173847; c=relaxed/simple; bh=7ETbpcy2nNgCjTGG/EyrL+CKWN+94OvZvcCzxkxA0Pk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sd5PpDJID9nEhsHgWpVeDc/5pooTZYKVmRTcpz0XBFWIIUMgqNxN3AH8j2YHserQBGkZiax29x/JDJz0kI32XLbiQhCXMaiRftVSH1bQ/FJG+nCw3WqJIU9CqpR0DwGGCZO6L7NldSX8RhAi9/ZuCc9VipvwFkugF6YVyYL8reA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j//2XXaF; 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="j//2XXaF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E43F6C2BD10; Fri, 26 Apr 2024 23:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714173847; bh=7ETbpcy2nNgCjTGG/EyrL+CKWN+94OvZvcCzxkxA0Pk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j//2XXaF/yeRgyLy6fXDqwMOi72R47Ci0GlFiIiDwYSKGrh/7Gc106akco/xVXk94 pgwRfpbHyIE4nJL+NZijbhbOb8d+ALuO934Gvr8mKWyYrUsbPcLOWq1e2TvXTIuVQR oIhHQuAYnNG2GoKUO8RtYup8X+F4cUc6fMti8g+m91m6bv2GjgHcYMFloMitpmOnMP RWd9TcwCYN+sTlzRPznpsQbKnUnVVwDdNUQyks4JtK5iiKaxU7JnlCcBLYvNSpJ6Kf SjhMndPs5zHQZYJzPA6BrS0EZAtiTeOzCnbGSDnk8viDtBPiBM9fgoOYRcn9YYWk4+ X8ciJcApmW+cw== 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 Subject: [PATCH net-next 6/6] selftests: drv-net-hw: add test for memory allocation failures with page pool Date: Fri, 26 Apr 2024 16:23:59 -0700 Message-ID: <20240426232400.624864-7-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426232400.624864-1-kuba@kernel.org> References: <20240426232400.624864-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"). 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