From patchwork Fri Apr 12 14:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13627821 X-Patchwork-Delegate: kuba@kernel.org 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 AB79686259; Fri, 12 Apr 2024 14:14:41 +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=1712931281; cv=none; b=NumQXRW+/u47D3pSSz7q5adlOlTPLXz2nNNUYOkmCux1bk3y+f7VBKCZqWaFQiTbuv3TJBO33ZWHuQQ8LWhSaVuyBGrLPw3QWl6tvRjQNsFKSAVyTnEcVfWIqTMgcHx9t/aKIqrkdu+eSQyekO4gF464JU65ylcJswPUjz0mYMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931281; c=relaxed/simple; bh=OWzNRL9wTAL3ZZ/3fyuNRkKpjlzyc/9bE7pYUM6rX1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dJ7vL+wWRcBVkHukLNKffHx8Q5dHrH+3OiSSnujbHMXXxjt4q5hu0R8myjaKoFxHBlVfWduSbVVHhl/e6ZqBfhVE3e5aJBP0Mzv9JpWah9hOAL6oi6SKXDNBRXbdv1AF4Y+/hpcr81jK7rxBngaatH9MaTvL7gxM5Dr49sSC4OQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pXFbaClw; 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="pXFbaClw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0E82C2BD10; Fri, 12 Apr 2024 14:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931281; bh=OWzNRL9wTAL3ZZ/3fyuNRkKpjlzyc/9bE7pYUM6rX1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXFbaClwe2YidNi3mU94OEUefDiVSXDlVo5NtIrBuygy4NsfhIiPC0RZ5vtH0r/77 yYtJZDfSf8v4LTQGDYz04N3Ixr+QqQPED0GwYj4ij+306APjYNlaBz3Wxp+GQOS5V9 bupixDaynQtWXmmVXxT8Z0Vkk3UejjqrAz/HF/k1kBgFvfE4V5jPE6T4ywJ/VbCD10 or7jzd6+Vip51G1Uy6xlBmqiFP9X7OihGG3A8ZwgbBxn9Sv6F0howHiIL1v7EFfS5V k61u2E45BKokzWy0n4DxPziYVKObeXPdOGrW+sftgkRF/LPdMPvWMnzEIOuMzxG814 qCOwt2g2TbpvQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 1/6] net: netdevsim: add some fake page pool use Date: Fri, 12 Apr 2024 07:14:31 -0700 Message-ID: <20240412141436.828666-2-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add very basic page pool use so that we can exercise the netlink uAPI in a selftest. Page pool gets created on open, destroyed on close. But we control allocating of a single page thru debugfs. This page may survive past the page pool itself so that we can test orphaned page pools. Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/netdev.c | 93 +++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 4 ++ 2 files changed, 97 insertions(+) diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index d7ba447db17c..d127856f8f36 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -299,6 +300,29 @@ static int nsim_get_iflink(const struct net_device *dev) return iflink; } +static int nsim_open(struct net_device *dev) +{ + struct netdevsim *ns = netdev_priv(dev); + struct page_pool_params pp = { 0 }; + + pp.pool_size = 128; + pp.dev = &dev->dev; + pp.dma_dir = DMA_BIDIRECTIONAL; + pp.netdev = dev; + + ns->pp = page_pool_create(&pp); + return PTR_ERR_OR_ZERO(ns->pp); +} + +static int nsim_stop(struct net_device *dev) +{ + struct netdevsim *ns = netdev_priv(dev); + + page_pool_destroy(ns->pp); + + return 0; +} + static const struct net_device_ops nsim_netdev_ops = { .ndo_start_xmit = nsim_start_xmit, .ndo_set_rx_mode = nsim_set_rx_mode, @@ -318,6 +342,8 @@ static const struct net_device_ops nsim_netdev_ops = { .ndo_set_features = nsim_set_features, .ndo_get_iflink = nsim_get_iflink, .ndo_bpf = nsim_bpf, + .ndo_open = nsim_open, + .ndo_stop = nsim_stop, }; static const struct net_device_ops nsim_vf_netdev_ops = { @@ -378,6 +404,60 @@ static const struct netdev_stat_ops nsim_stat_ops = { .get_base_stats = nsim_get_base_stats, }; +static ssize_t +nsim_pp_hold_read(struct file *file, char __user *data, + size_t count, loff_t *ppos) +{ + struct netdevsim *ns = file->private_data; + char buf[3] = "n\n"; + + if (ns->page) + buf[0] = 'y'; + + return simple_read_from_buffer(data, count, ppos, buf, 2); +} + +static ssize_t +nsim_pp_hold_write(struct file *file, const char __user *data, + size_t count, loff_t *ppos) +{ + struct netdevsim *ns = file->private_data; + ssize_t ret; + bool val; + + ret = kstrtobool_from_user(data, count, &val); + if (ret) + return ret; + + rtnl_lock(); + ret = count; + if (val == !!ns->page) + goto exit; + + if (!netif_running(ns->netdev) && val) { + ret = -ENETDOWN; + } else if (val) { + ns->page = page_pool_dev_alloc_pages(ns->pp); + if (!ns->page) + ret = -ENOMEM; + } else { + page_pool_put_full_page(ns->page->pp, ns->page, false); + ns->page = NULL; + } + rtnl_unlock(); + +exit: + return count; +} + +static const struct file_operations nsim_pp_hold_fops = { + .open = simple_open, + .read = nsim_pp_hold_read, + .write = nsim_pp_hold_write, + .llseek = generic_file_llseek, + .owner = THIS_MODULE, +}; + static void nsim_setup(struct net_device *dev) { ether_setup(dev); @@ -485,6 +565,10 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) err = nsim_init_netdevsim_vf(ns); if (err) goto err_free_netdev; + + ns->pp_dfs = debugfs_create_file("pp_hold", 0600, nsim_dev_port->ddir, + ns, &nsim_pp_hold_fops); + return ns; err_free_netdev: @@ -497,6 +581,8 @@ void nsim_destroy(struct netdevsim *ns) struct net_device *dev = ns->netdev; struct netdevsim *peer; + debugfs_remove(ns->pp_dfs); + rtnl_lock(); peer = rtnl_dereference(ns->peer); if (peer) @@ -511,6 +597,13 @@ void nsim_destroy(struct netdevsim *ns) rtnl_unlock(); if (nsim_dev_port_is_pf(ns->nsim_dev_port)) nsim_exit_netdevsim(ns); + + /* Put this intentionally late to exercise the orphaning path */ + if (ns->page) { + page_pool_put_full_page(ns->page->pp, ns->page, false); + ns->page = NULL; + } + free_netdev(dev); } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 553c4b9b4f63..7664ab823e29 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -125,6 +125,10 @@ struct netdevsim { struct debugfs_u32_array dfs_ports[2]; } udp_ports; + struct page_pool *pp; + struct page *page; + struct dentry *pp_dfs; + struct nsim_ethtool ethtool; struct netdevsim __rcu *peer; }; From patchwork Fri Apr 12 14:14:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13627822 X-Patchwork-Delegate: kuba@kernel.org 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 4B1A18626D; Fri, 12 Apr 2024 14:14:41 +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=1712931282; cv=none; b=X6FU/TepBgpqwA/aa3drDoIkngySfOV9WCjiuUcSobKyOitTcFGMc3SkBcGHRG64zitKp6fYQXCY9nqxEODJPMjZt4cTB6mIaAWSMqfTwiF2Y6VpDN2fN9KgcWK3L8U5ZDWmMduZ4dXL1xQjr2i1nnweHvueMUIPenaiY62+X+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931282; c=relaxed/simple; bh=8BkxfNl3hd9M6SMm4rbkPdYQAOfcfQq2OyLXTwlHs5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CZcA8ujTsODtSaV/1HUMjbHlZbWEiuL+GSEKLWCdfoOoH5JM/A7GwHdpBv5CwMfFc6qf0fPRoxzMrwvceXuSuDrLn4FyuTdm/HCS4k7X8yr2mD0VyTUPvTYKaK6mQxaRNDL+qBd+ZIfCR5ECfuHL0QhMuGggRPH/G4r79YzKicw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qr8C/F80; 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="qr8C/F80" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61BD6C32783; Fri, 12 Apr 2024 14:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931281; bh=8BkxfNl3hd9M6SMm4rbkPdYQAOfcfQq2OyLXTwlHs5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qr8C/F80BCKzlhkmpbQ+LWalzFhxeRAgmBLJETWAm8Os8FJpUBwnj2Y/0g+eOP3Bg 07OMUI2AtMNg3U851iZZze3ICFHUIdUAWr3qMEShHQZusThKS+d9MeOjM2kA8GkzbK edKOZ5XHz2HI8MQH1p/u8HLN91tktkqPgmAQU0Ah1e11jHW/4SVFWNQg8RZDf2LTsZ /IwddFazxeMzGz1GUsmxkDIZMzbPNh8y+uIg0Eub6jAeQi+h68uOrhYY+sVwROGmpu aKeAPguN16sJIEVZRfm2GmsdV/6kx8rf6nLnbCp/9mBHnm4nEx7JMYcVPfV6YZ2hPz EbZr8DA2wqlTA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski , Donald Hunter , jiri@resnulli.us Subject: [PATCH net-next v2 2/6] tools: ynl: don't return None for dumps Date: Fri, 12 Apr 2024 07:14:32 -0700 Message-ID: <20240412141436.828666-3-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org YNL currently reports None for empty dump: $ cli.py ...netdev.yaml --dump page-pool-get None This doesn't matter for the CLI but when writing YNL based tests having to deal with either list or None is annoying. Limit the None conversion to non-dump ops: $ cli.py ...netdev.yaml --dump page-pool-get [] Reviewed-by: Donald Hunter Signed-off-by: Jakub Kicinski --- CC: jiri@resnulli.us --- tools/net/ynl/lib/ynl.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index 0ba5f6fb8747..a67f7b6fef92 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -995,9 +995,11 @@ genl_family_name_to_id = None rsp_msg.update(self._decode_struct(decoded.raw, op.fixed_header)) rsp.append(rsp_msg) + if dump: + return rsp if not rsp: return None - if not dump and len(rsp) == 1: + if len(rsp) == 1: return rsp[0] return rsp From patchwork Fri Apr 12 14:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13627823 X-Patchwork-Delegate: kuba@kernel.org 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 DC6008615F; Fri, 12 Apr 2024 14:14:42 +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=1712931283; cv=none; b=jXgAmN9fcFFIsSc+x4+Hl/sGSkUIRhvZ4HsT2nSBdrWNyFdyVjcMA3D5zKFr3r9r25K9MI4nDyZ0/zM1eZSczr22wlUUCgGxX3VLhi8mv5ooVYSzn3p6B2ZHSiVwi3FH/9rbfX4JOXtjgnlOxWYXFy8ro1Gmm+v8nBfvugZWE4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931283; c=relaxed/simple; bh=hPhQCHvhkEATSLUEgZyXF+5+mjJeaxY6UqwRPzblV1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ixN1hmf7pk90f03oPdE3N3tsCpo3vbdiwMtIBy2LFIq2y5TnQwDKsHXqbzysmvVuThG1r7WvPk62w1tR7sZ3DEKpoP0jCbP8WeVmLWfu8A2m8JT7dkD9SlcNx1HsVbWA+WVp2FqgCV/TWAIF6M5wc+3jiLfBRgcp6OTQMyllymk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aIXSmsCX; 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="aIXSmsCX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04F47C4AF10; Fri, 12 Apr 2024 14:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931282; bh=hPhQCHvhkEATSLUEgZyXF+5+mjJeaxY6UqwRPzblV1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aIXSmsCXpYSDwHjT/a9x1rXSj2rmyi1E3xtY1lKWKgx1C6iY8cT7pi0lQSHeH8oh2 fAeS5Qs6CYtDHMowiaQ9OjAc4bzW+xegmrzNcTm27hrLw5c3QgSojpSlk11tunbgTf BDLu1HhXQHBi8jO6eWF0gwsEwX6Yku7MU7QoOGtrpK6RqXE4ykvJ3/tWNq65sU+3sT 3AzWNpQKOgITOLY5yzXS8WO6T7a1RcG/b3yQO2xDi1ITYb1Pfx1DFw1hccvRmtjZCW RcC6FrLfzd1kMwv9n6ekykhpLt5Cbx74lz03lOxqitFg/BPIMV4h7hzEvume2Re1Hx 8Mpv62S/nzi6g== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 3/6] selftests: net: print report check location in python tests Date: Fri, 12 Apr 2024 07:14:33 -0700 Message-ID: <20240412141436.828666-4-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Developing Python tests is a bit annoying because when test fails we only print the fail message and no info about which exact check led to it. Print the location (the first line of this example is new): # At /root/ksft-net-drv/./net/nl_netdev.py line 38: # Check failed 0 != 10 not ok 3 nl_netdev.page_pool_check Reviewed-by: Petr Machata Signed-off-by: Jakub Kicinski --- v2: - pass *args from fail to pr --- tools/testing/selftests/net/lib/py/ksft.py | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index c7210525981c..b4b0bfff68b0 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 import builtins +import inspect from .consts import KSFT_MAIN_NAME KSFT_RESULT = None @@ -18,32 +19,34 @@ KSFT_RESULT = None print("#", *objs, **kwargs) +def _fail(*args): + global KSFT_RESULT + KSFT_RESULT = False + + frame = inspect.stack()[2] + ksft_pr("At " + frame.filename + " line " + str(frame.lineno) + ":") + ksft_pr(*args) + + def ksft_eq(a, b, comment=""): global KSFT_RESULT if a != b: - KSFT_RESULT = False - ksft_pr("Check failed", a, "!=", b, comment) + _fail("Check failed", a, "!=", b, comment) def ksft_true(a, comment=""): - global KSFT_RESULT if not a: - KSFT_RESULT = False - ksft_pr("Check failed", a, "does not eval to True", comment) + _fail("Check failed", a, "does not eval to True", comment) def ksft_in(a, b, comment=""): - global KSFT_RESULT if a not in b: - KSFT_RESULT = False - ksft_pr("Check failed", a, "not in", b, comment) + _fail("Check failed", a, "not in", b, comment) def ksft_ge(a, b, comment=""): - global KSFT_RESULT if a < b: - KSFT_RESULT = False - ksft_pr("Check failed", a, "<", b, comment) + _fail("Check failed", a, "<", b, comment) def ktap_result(ok, cnt=1, case="", comment=""): From patchwork Fri Apr 12 14:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13627824 X-Patchwork-Delegate: kuba@kernel.org 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 59CD31272C9; Fri, 12 Apr 2024 14:14:43 +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=1712931283; cv=none; b=dxL+qRHUFeQQD5Dv1Svt65Zf8/V05kTyfdXiF/xmm4cuHKhUXZPykKj4AamSD1Ju44NCv9o2Q9N8ivX9eWZpHWGn0/mWs9AnEsGr86bsyAQrhfWG/iBvjrph7Gg1DR5Fa9zO7UmnxCCkmYQXPmyTQygJ64l5uUp0fYYKNrNtsD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931283; c=relaxed/simple; bh=0MWRd4EmeqVTRPzqiaWIWceaTlo+U4X9A0S+WknwrN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rCGAVc61+POGrYtLMm9/VVnPOWxIgezJ2v3jJGUmTVVOQCdN+SWtZJiVbE2/LU2gNvZ3NgfuijJhdNF6QQv7/08/XwC1EpfrbTeOtnWPX9oxEMWF9uTWh4HQc4nh8Q0YdMz8aSO4bGNMIbMuRoHe23aN/NqotIsMEZhFUUL7l+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nunpo8eT; 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="Nunpo8eT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ABAFC2BD10; Fri, 12 Apr 2024 14:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931282; bh=0MWRd4EmeqVTRPzqiaWIWceaTlo+U4X9A0S+WknwrN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nunpo8eTnvGh5k74JHkzjc3g/coowjGKfESETpvOpdSpMXoovfr4UP+W8GFiPesym T1fM+lxsEeOxJS5WCiyWOcRygUi1e8Oo7n6bHAmcdPp2EbeB7GGUYZJNLD4mOJSb26 IXgRHH2ioK7ttgb+Vxm65l4vs0B6jCukJ9rLjcdIZkq9T+tuanElNR9qDZgeYhrRQz kuLSiruvxWM6ld1+tjDbJQ31pAsmZuW+QJot9ux7m/aVx2XQwbKrJvKZZr8bdwOs56 LeGbEy9kLOanqstFG3P1cOSVs9WG4TiirKCg13sTlTGPhHKX4X3mXqj2VuFr3Duz31 kXUvrihdr87TQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 4/6] selftests: net: print full exception on failure Date: Fri, 12 Apr 2024 07:14:34 -0700 Message-ID: <20240412141436.828666-5-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Instead of a summary line print the full exception. This makes debugging Python tests much easier. Reviewed-by: Petr Machata Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/py/ksft.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index b4b0bfff68b0..793e4761645e 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -2,6 +2,7 @@ import builtins import inspect +import traceback from .consts import KSFT_MAIN_NAME KSFT_RESULT = None @@ -85,7 +86,8 @@ KSFT_RESULT = None totals['xfail'] += 1 continue except Exception as e: - for line in str(e).split('\n'): + tb = traceback.format_exc() + for line in tb.strip().split('\n'): ksft_pr("Exception|", line) ktap_result(False, cnt, case) totals['fail'] += 1 From patchwork Fri Apr 12 14:14:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13627825 X-Patchwork-Delegate: kuba@kernel.org 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 A06FF127E05; Fri, 12 Apr 2024 14:14:43 +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=1712931283; cv=none; b=ihozPAVwbjOkh7s6K7CrvvLNYMHQpMp4n8ntS8iR5qpE7oq18qJ4/9vDkYG4R/Q+if/KzVP5j5aOQDvROE9ETfE86N9IMLQh4zSMY3O8wiplBPDPE2iaNrCo/xVNDyuMvVm6bQTm8RAU90P7hF2jMnjxw7zIrKixMJz5+kIb0Yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931283; c=relaxed/simple; bh=dP5QqOirl1uC9rGfoUuyH11xukDtaHTNOtiy2HvsIFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=riJ4j0uMbblvJg6nTEhRkCHmIAwvJDDiaIcDW0BoAfBJ8w4GAMeaT/3hn7j4NbyaqD5yol7msUXfT2UZP+5ZJNRGquLTC0ficHDrj3OjEEJrfoiukq26u0kR94gXcILmw/cIXYdm15RQYh5BsBAncjn4gDu4tS9yJPbatmidTXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hsvBjlft; 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="hsvBjlft" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EA00C32786; Fri, 12 Apr 2024 14:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931283; bh=dP5QqOirl1uC9rGfoUuyH11xukDtaHTNOtiy2HvsIFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hsvBjlftrazRQk2k+Gk5mzgpU/MJOkUgUnPILJTO/yLiXWGYVjbM+zjyWfZdWjXcs rNNybKPuOaaA9oPkYnzV3OvcklhQVs8C4xZSzFc2C+InKg1VokElhNphxtpKa+yaqp PJnimrIoZVZDJ856eUCdftF1oc4O0A1AbfwZwlM5MeZQQWPy5HIpYRiUzhwU4FG0xp EheWMhs8RFzrUoES3tEyCh9/uX/PZNaLU0XhieQE1VrhsZEkdeKvYXETuY5EDlamHd GJVw/uSgjuU41QuGWK615DkIn+5W6mpc9agfMZEo476ACvzYTwCN+IGRCIkq5FqwEL +4zcAVaBVLTWA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 5/6] selftests: net: support use of NetdevSimDev under "with" in python Date: Fri, 12 Apr 2024 07:14:35 -0700 Message-ID: <20240412141436.828666-6-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Using "with" on an entire driver test env is supported already, but it's also useful to use "with" on an individual nsim. Reviewed-by: Petr Machata Signed-off-by: Jakub Kicinski --- tools/testing/selftests/net/lib/py/nsim.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py index 97457aca7e08..94aa32f59fdb 100644 --- a/tools/testing/selftests/net/lib/py/nsim.py +++ b/tools/testing/selftests/net/lib/py/nsim.py @@ -84,6 +84,17 @@ from .utils import cmd, ip for port_index in range(port_count): self.nsims.append(self._make_port(port_index, ifnames[port_index])) + self.removed = False + + def __enter__(self): + return self + + def __exit__(self, ex_type, ex_value, ex_tb): + """ + __exit__ gets called at the end of a "with" block. + """ + self.remove() + def _make_port(self, port_index, ifname): return NetdevSim(self, port_index, ifname, self.ns) @@ -112,7 +123,9 @@ from .utils import cmd, ip raise Exception("netdevices did not appear within timeout") def remove(self): - self.ctrl_write("del_device", "%u" % (self.addr, )) + if not self.removed: + self.ctrl_write("del_device", "%u" % (self.addr, )) + self.removed = True def remove_nsim(self, nsim): self.nsims.remove(nsim) From patchwork Fri Apr 12 14:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13627826 X-Patchwork-Delegate: kuba@kernel.org 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 875B0127E1A; Fri, 12 Apr 2024 14:14:44 +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=1712931284; cv=none; b=UtUtgHD0eEXi+q9sFOawRBsKkiOVD55UDkMcENNPm6ASS3+asMlESWgFqsyh/utxrVmf8UpVf9NniPHyeLP3HtoFp94MOVq+3og4ZHtWjitMMbssm2TEHfOaRE7ag1yziLIbeQlw/HA6hOaggoiCM4C9TSCS29IC2a8exu8hxdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712931284; c=relaxed/simple; bh=a/xwDv1uI1eJafNxyFB3fcAD3BCfsSqkG8l2bCUThIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zsez1QACwutgbNm1jcGFsYFEmmsdkbdknsGFhqPLiV/4B2wwBgDQ3kEEaxH7xt8A9Cvhq9Z73efCJ80wFc2YhmRm8Zxn0udXYuMXWi6V0CIrzitlsKZXqLjI/RvMcPV6LrSPDRLTJgUm/GNRV21I5L5/JkhOAvDtv5vATvjPO/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WMOkwjqD; 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="WMOkwjqD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1E38C4AF0E; Fri, 12 Apr 2024 14:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712931284; bh=a/xwDv1uI1eJafNxyFB3fcAD3BCfsSqkG8l2bCUThIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WMOkwjqDeZMrtWjW+EuM5BRU0pg3VGxVxY+Q+U6Q4DpJ9kJ76D+Oh1d5MmDn4rH7X z1wEHdYOEm+O9623Vi4+U/qiGn9dIMNjGJ92bVwUT0TPf946y0D8NYiuARivdOHqVD 5aP1B/eof8Rh96k7F3sdyVA0GKA4Z+l3G7ujzlyLeLfGsQiDADuE/sbNX3J5c2l5OY vZo1KGjAPoQRxnvBYOk50bpICinlCgrDcFfeaj4wQo7p+ke4tJj5L8Ug1dtGn6GECC i5YTyKMtLFoPsmQltHQYm5LcS/IpQD9MyzB5YdG5iIwL9rrPJyuN5lubgjjPFtUE7S fa1QweTOEhVZA== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, Jakub Kicinski Subject: [PATCH net-next v2 6/6] selftests: net: exercise page pool reporting via netlink Date: Fri, 12 Apr 2024 07:14:36 -0700 Message-ID: <20240412141436.828666-7-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412141436.828666-1-kuba@kernel.org> References: <20240412141436.828666-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add a Python test for the basic ops. # ./net/nl_netdev.py KTAP version 1 1..3 ok 1 nl_netdev.empty_check ok 2 nl_netdev.lo_check ok 3 nl_netdev.page_pool_check # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Jakub Kicinski Reviewed-by: Petr Machata --- v2: - move up / down to the test - add helper for getting pp - add busy_wait helper - rename undeteched --- tools/testing/selftests/net/lib/py/ksft.py | 12 ++++ tools/testing/selftests/net/lib/py/nsim.py | 1 + tools/testing/selftests/net/nl_netdev.py | 76 +++++++++++++++++++++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/ksft.py b/tools/testing/selftests/net/lib/py/ksft.py index 793e4761645e..3769b9197213 100644 --- a/tools/testing/selftests/net/lib/py/ksft.py +++ b/tools/testing/selftests/net/lib/py/ksft.py @@ -2,6 +2,7 @@ import builtins import inspect +import time import traceback from .consts import KSFT_MAIN_NAME @@ -50,6 +51,17 @@ KSFT_RESULT = None _fail("Check failed", a, "<", b, comment) +def ksft_busy_wait(cond, sleep=0.005, deadline=1, comment=""): + end = time.monotonic() + deadline + while True: + if cond(): + return + if time.monotonic() > end: + _fail("Waiting for condition timed out", comment) + return + time.sleep(sleep) + + def ktap_result(ok, cnt=1, case="", comment=""): res = "" if not ok: diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py index 94aa32f59fdb..06896cdf7c18 100644 --- a/tools/testing/selftests/net/lib/py/nsim.py +++ b/tools/testing/selftests/net/lib/py/nsim.py @@ -28,6 +28,7 @@ from .utils import cmd, ip self.dfs_dir = "%s/ports/%u/" % (nsimdev.dfs_dir, port_index) ret = ip("-j link show dev %s" % ifname, ns=ns) self.dev = json.loads(ret.stdout)[0] + self.ifindex = self.dev["ifindex"] def dfs_write(self, path, val): self.nsimdev.dfs_write(f'ports/{self.port_index}/' + path, val) diff --git a/tools/testing/selftests/net/nl_netdev.py b/tools/testing/selftests/net/nl_netdev.py index 2b8b488fb419..6909b1760739 100755 --- a/tools/testing/selftests/net/nl_netdev.py +++ b/tools/testing/selftests/net/nl_netdev.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 -from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily +import time +from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, ksft_busy_wait +from lib.py import NetdevFamily, NetdevSimDev, ip def empty_check(nf) -> None: @@ -15,9 +17,79 @@ from lib.py import ksft_run, ksft_pr, ksft_eq, ksft_ge, NetdevFamily ksft_eq(len(lo_info['xdp-rx-metadata-features']), 0) +def page_pool_check(nf) -> None: + with NetdevSimDev() as nsimdev: + nsim = nsimdev.nsims[0] + + def up(): + ip(f"link set dev {nsim.ifname} up") + + def down(): + ip(f"link set dev {nsim.ifname} down") + + def get_pp(): + pp_list = nf.page_pool_get({}, dump=True) + return [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + + # No page pools when down + down() + ksft_eq(len(get_pp()), 0) + + # Up, empty page pool appears + up() + pp_list = get_pp() + ksft_ge(len(pp_list), 0) + refs = sum([pp["inflight"] for pp in pp_list]) + ksft_eq(refs, 0) + + # Down, it disappears, again + down() + pp_list = get_pp() + ksft_eq(len(pp_list), 0) + + # Up, allocate a page + up() + nsim.dfs_write("pp_hold", "y") + pp_list = nf.page_pool_get({}, dump=True) + refs = sum([pp["inflight"] for pp in pp_list if pp.get("ifindex") == nsim.ifindex]) + ksft_ge(refs, 1) + + # Now let's leak a page + down() + pp_list = get_pp() + ksft_eq(len(pp_list), 1) + refs = sum([pp["inflight"] for pp in pp_list]) + ksft_eq(refs, 1) + attached = [pp for pp in pp_list if "detach-time" not in pp] + ksft_eq(len(attached), 0) + + # New pp can get created, and we'll have two + up() + pp_list = get_pp() + attached = [pp for pp in pp_list if "detach-time" not in pp] + detached = [pp for pp in pp_list if "detach-time" in pp] + ksft_eq(len(attached), 1) + ksft_eq(len(detached), 1) + + # Free the old page and the old pp is gone + nsim.dfs_write("pp_hold", "n") + # Freeing check is once a second so we may need to retry + ksft_busy_wait(lambda: len(get_pp()) == 1, deadline=2) + + # And down... + down() + ksft_eq(len(get_pp()), 0) + + # Last, leave the page hanging for destroy, nothing to check + # we're trying to exercise the orphaning path in the kernel + up() + nsim.dfs_write("pp_hold", "y") + + def main() -> None: nf = NetdevFamily() - ksft_run([empty_check, lo_check], args=(nf, )) + ksft_run([empty_check, lo_check, page_pool_check], + args=(nf, )) if __name__ == "__main__":