From patchwork Thu Apr 11 01:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13625309 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 613D36996E; Thu, 11 Apr 2024 01:28: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=1712798921; cv=none; b=OLayARxkCw36yxJWTJ8EkGiP3d6um2AR5eIvIwDjg2MNl67oiYF9cYldCSWaJDD6Fd1iEhAvSKNZHqeYMqn8/7wB5O2yanNIvp13YkYFwWNHpGKH/FWywjxOxYjn7kSuBtzgUL3Z/FieyymbQD4jA/naz8O+153+0ULxAgOy4JU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798921; c=relaxed/simple; bh=OWzNRL9wTAL3ZZ/3fyuNRkKpjlzyc/9bE7pYUM6rX1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dcaORRjhe1GwgWV1NezKXnf/fk/IobBhlTXffJmEBt2ufTOrvRaPanhiujN2QjWWNRRyWN3ZhZCfwX3hOL2cUzxaD0/wkT/d/DnKXfum9wqjsOEqdqL0bNGBZSLHJunrg2eJGpieHMz7ZTG3UIx6J3mIJ/bHmwKt5k6Usyc0f+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UERWqJBi; 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="UERWqJBi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 849BDC43390; Thu, 11 Apr 2024 01:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712798920; bh=OWzNRL9wTAL3ZZ/3fyuNRkKpjlzyc/9bE7pYUM6rX1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UERWqJBi5H8rZNqahKJD6h/+wCu+IgGolpLkrQx8Jnsdg+BkNaoYWr6eLeDLNxeYg iE90uH1Gf6YSW+84gsgylZmXs+IJbJXpZkEHshClIgCCXiYZgb3fl4yFaF1itO8wjO cTor+cBEnhwuMbPDLhQNtOXHwj9eWDvWxXh0i/kdfwooHFcQjQCctE9SGyCHhKjYM8 eU4q1lxlyhepbHzzJFrBTZbRFG8wlmYf2lIzKHRHtybFBVZtHm9My2Tu2zrHTHrvwG batGVPTRw6CMIXfSkDIaAvXxp36Elayzhaf2oBaRsDbjissvaf2/on0DseuInICN57 EAzcI9NXCUD8A== 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 1/6] net: netdevsim: add some fake page pool use Date: Wed, 10 Apr 2024 18:28:10 -0700 Message-ID: <20240411012815.174400-2-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411012815.174400-1-kuba@kernel.org> References: <20240411012815.174400-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 Thu Apr 11 01:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13625310 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 9F07269D0A; Thu, 11 Apr 2024 01:28: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=1712798921; cv=none; b=YLnsT6jmlUKohjuseuCQQYjxs1qbriORnk0LnFkonw1Nc+qIM7Cwf2E/q4qx0asiSuUhfd1b/vA41lzEMMH/IeiSdtJj/3Hh/4z673oDkDIBBSXrWT7NEm+lCcSoF6OQNMsODIcIbPUCMJD8ZabzTKDWBjjGskU+QJxXbLpRCH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798921; c=relaxed/simple; bh=Vfp9UyJOM8kMpvSyXcIKRtaJ0zyB4mIgfD2CwgNCQVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fxnF1qgrYVawBIoR6jBbKHQxPStXfN7b6sqVIBAjzUHE9/PFuaMCQahqf6e/Gb/nBoT9aOfJPgCKB9AIPwCoKP9vEqQZde9qWstpXnQCDbkiX2dCxruWYcaxVxX7jHxd08JwEqWxyjfbLcHW4uN2QM3dfzsZg6uozGdopHNpd4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AdQeKtR+; 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="AdQeKtR+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DD4CC433F1; Thu, 11 Apr 2024 01:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712798921; bh=Vfp9UyJOM8kMpvSyXcIKRtaJ0zyB4mIgfD2CwgNCQVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AdQeKtR+qCBjWICspR0vy/IahEeGkhri/1IP/Gv7WxC6maxfhizZ0c06v5oB/h1m3 rh13c1Wd9g838zzQtciVKPfcZoADvLEbYVWB0ryher0n5Po6r5O85BtZKctzW0bXpe V6GkV3X1fPr7TnQ+LVYxmo2z6EIBmbfuaOId4GwrCvmvJT4wXUGnJAUCWBzBFHHhLS n13jvbNa7lGbNMb3zktVsFdryeXlfTRE/1+ydOKfwUh7epEnp834uHo79qk2AlIllH o54mM9zpbuqUL2d7eFeMUT9wpspNjQ71fRU5+cM4mzMQUQ2UFWV2f+OrHSKDgrPNr5 ZGBS6hXOBbIyA== 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@gmail.com, jiri@resnulli.us Subject: [PATCH net-next 2/6] tools: ynl: don't return None for dumps Date: Wed, 10 Apr 2024 18:28:11 -0700 Message-ID: <20240411012815.174400-3-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411012815.174400-1-kuba@kernel.org> References: <20240411012815.174400-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 [] Signed-off-by: Jakub Kicinski Reviewed-by: Donald Hunter --- CC: donald.hunter@gmail.com 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 Thu Apr 11 01:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13625311 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 8356873171; Thu, 11 Apr 2024 01:28: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=1712798922; cv=none; b=sC38ZbWp/dcKuDT0+8JOzWu5a1i8tweIO/6LHtuSlEx4ygq3QDwv/g52kKvk/6s1SbUbptCHm0AfNEeSI8kALgJfgqRnCHcNWb0EbtU3PeU42PK8vudDvcP3M7LS2iozXboN+mEAW2wYX8055JSaKTKoEEINRIQIBzGCJOBrFTU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798922; c=relaxed/simple; bh=Nc//R23kY+H8e6cmo3oUSxdKd7WcTbsgmfEiJlWrS7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QA6r1rAeHZ8gltdPRP6oPZ1asSyCk8sctAf20vorKXifPDVk3o2StGrCAZb0X6EWJI3vUflkMB4X/WElWxM50Kx8dm7216gcpLva75kXnuPXiayAnwYMOV4hLqiRti1EMqOE8mU2z3XL7PPYE2jLsnADiHywpGYQZVtGnB8kLUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b8HCLEYN; 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="b8HCLEYN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0B8DC43330; Thu, 11 Apr 2024 01:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712798922; bh=Nc//R23kY+H8e6cmo3oUSxdKd7WcTbsgmfEiJlWrS7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b8HCLEYNCaS+fmwPyXQXurckLZj/gsPQryrvcqrU0vldac0IXeKwb6vOyNI/2HcMe N01wnL3XYmcOD+UZ524YtNgpGp9Qopxr4f25d1Fj9pBUD1g5MbskllTyTkOwvZmES8 wj715FLSv5ICoKYsCGv/UqQg+0rCtx7qOnmX34mLbHCM/8i7diRUoiraiByubYgi1U JVVOtUH54UvoVmbsg1/89u2XS1zhR0CfD8Vsg3+MUmQ0mfUX7Yk01/ACtCdmaSYLag /VWB1I6ps2WC0hEqX8mpjiy2ioP9cZeBlPVIzMbvSstcdCu9QJnKobcRNP/G30Pxpq GEwcwDI4IqgfQ== 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 3/6] selftests: net: print report check location in python tests Date: Wed, 10 Apr 2024 18:28:12 -0700 Message-ID: <20240411012815.174400-4-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411012815.174400-1-kuba@kernel.org> References: <20240411012815.174400-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 Signed-off-by: Jakub Kicinski Reviewed-by: Petr Machata --- 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..5838aadd95a7 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(" ".join([str(a) for a in 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 Thu Apr 11 01:28:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13625312 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 A764D74BF4; Thu, 11 Apr 2024 01:28: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=1712798922; cv=none; b=I7Runz0F0jsYzFpAfCfv/gn5/qK+HV1n4svxdnj+6rNUK9zzKavAgD4QVoO7q7cXPKxXfwuAAVAJVigUv7JtPIVmDYHnszpdw8iIA9fYZTT1sYPbuKPrLw1Uan6tx7RqYtMm3jAjfzZIlAUrr+0/kaUWHpwHrwYThb1d0BasIu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798922; c=relaxed/simple; bh=q5ZxAEbUk4C1HZCRmIzc2uhxryfpIrMHKHvTDR9QIKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VqdMzPZsxR+lOU8/hTxBnx01AJNDB5OCGgEKbsvL1fdZEOHT2zTEOsET4wIXHPmA0GzD6Gr1sYEHj+UxKqMEN+GgQZJu44hMizYwaA919tXneUlHB/qlxSA72INHbzLN7LuD4isF+sYW3Xdw4MQAVm68cmqOJPip+jZd6nBuoc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JO4KNTz2; 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="JO4KNTz2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FDADC43399; Thu, 11 Apr 2024 01:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712798922; bh=q5ZxAEbUk4C1HZCRmIzc2uhxryfpIrMHKHvTDR9QIKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JO4KNTz2UCOau7bGpUAGulsPluWCqfpim1erlvGqfVNRFl5/y8xZ03yMAm38BFqaA S1C3UOzOTShZGk8rnX8XlzAr/W5RYz8Is/1uEfAGWgDgHYRS+g9UEaXt/spRN/1Mfg 82Lc/Ge47LoF+Hy+1Uu18kFh0V73djZR265uRGhMakIZ0faVLpEaxAMQSTw4TUxGdb Xw0N8EtP9HWjrn/StZZl5AdO8GRXbtnclOV2hsmf30Ma0qP6TEH1Bmmplj0D4uvewg 9sN5W275R+mZqRh9lq2bHpjShif2GIEPAeQoNsrvoMSJGFtLWa82/MIbrgBQErtd1m +IozHT5RJCcgw== 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 4/6] selftests: net: print full exception on failure Date: Wed, 10 Apr 2024 18:28:13 -0700 Message-ID: <20240411012815.174400-5-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411012815.174400-1-kuba@kernel.org> References: <20240411012815.174400-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. Signed-off-by: Jakub Kicinski Reviewed-by: Petr Machata --- 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 5838aadd95a7..6e1f4685669c 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 Thu Apr 11 01:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13625313 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 334B7762CD; Thu, 11 Apr 2024 01:28: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=1712798923; cv=none; b=RiY2scWKiZ+vZ76D1nwbHeDcWRd0KnDTJ2OP3d73f+3zuztZmUV1mb2HYPy2IrkNvjdamsw57rVIM4L07diTLpfy3CRTUwGAP2ToJ5/tVLZfdM4C5HAIp09tSL5y5OIPekLxAFABBvBY97iRV6P7uRgfWK3ZgHZnyf2X5Z962tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798923; c=relaxed/simple; bh=JaunFt0T0EWCKUbeAop3W25lSE226TwTe55Aql+rUIQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ukw+mKoyvyXnRZ+4Jc/+oT2sLuCN3fTLsItUBMdN59WW4L+Gqr0suVV6gYwZSA5RU5Ndi62CoJQWFbLE5GMYn0XdAHypskGYc/smz4vVj/3nfHprNxndh5Xg3x+g4Xyu6EeJ6EP8EwxGt8tkSXJejP4Bb6GkFuMhZjcR4Riulok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aHMSyPci; 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="aHMSyPci" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF98DC433C7; Thu, 11 Apr 2024 01:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712798923; bh=JaunFt0T0EWCKUbeAop3W25lSE226TwTe55Aql+rUIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aHMSyPciwY1kaKuqLFb8Ze54R0VnWohQUjALfWp5g1PAsRWn/HShprw4PK2ZIlQIj a2dzZstQZX0YDqdv04CTzvRKxnMR1ipugO/YXQ2yF9Cxwq/EGDoTHEFY/1GMA+DTz5 PEBwKy3feaqUYf892uWt0LgBZ3MgNOXmPzziSA2TlQeNNagBXjHOwX0EmNRFrLcN+H d3y/+GsgNB5VY2iL6peFfPc3kLQaNJY9k/1TNtvFpxpZNDa4FouITmPvjx1hD/Ha/j bpLTq6Acr4jc7b03Uu5P+14w3Z/dJN5STZJfZuzUFEFSbbXfojN1XUpjuzKt15/Auw jYesWwr/WpR1w== 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 5/6] selftests: net: support use of NetdevSimDev under "with" in python Date: Wed, 10 Apr 2024 18:28:14 -0700 Message-ID: <20240411012815.174400-6-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411012815.174400-1-kuba@kernel.org> References: <20240411012815.174400-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. Signed-off-by: Jakub Kicinski Reviewed-by: Petr Machata --- 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 Thu Apr 11 01:28:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13625314 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 1185D73171; Thu, 11 Apr 2024 01:28: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=1712798924; cv=none; b=fU3ozhB2FDeIYfeXnQQTPrVTcej1ekc5fYRSPO7i/AMXFlcUFMGKQLXdWUL2URcA1vEyfgJ5vIZstnnog9iFo6EjSlx+J23hVUxU0V5d+8Zgoz7uzRmR3CYR63Mx1bA0HdrS9xvVAzDumKD1XKz4hmTOVjt+4/MW8BXlpNNHTxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712798924; c=relaxed/simple; bh=Dt+N9TSEXMGWfFEH27py4ZfTIinmlfGwSEEGHIQSoco=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ca6QUUYCgZe0CiWgAOiOtoodCBuTr1Jft+84/d2ldo0cyBAXyzNeTVi0Yx79zfTmZ/HQETpZxUFj+63NTAKDv2pX2BNLS9yM4V9Qo3kMtDfSaAjXu5RxLFkVDQGlBSEzSqOGuBkisTGL996c+5N2qU4KSr9Ghp7Px8QFarg2s2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OahLLZf9; 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="OahLLZf9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DD33C43399; Thu, 11 Apr 2024 01:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712798923; bh=Dt+N9TSEXMGWfFEH27py4ZfTIinmlfGwSEEGHIQSoco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OahLLZf9vIOhO54V3vzzapGnETus+wNJxWrh0o6K9C/DD+j6CFQkiTeNtgSesU0ew Sp8mHBAKH9DIoGkaGLZiF5DiFrp2CDjT/D1ez8S+rv209hRf4qZNZi9ZuadGT3mxtB Z5siQ24JPWXU3CE+6ejbCLiN2JyK03rYTEAx1TGbaV90mY/9o3dvNXlbqIHzaTWCDL f9BOX4P46d7pMre2MASQUktBJ3/9RF19dwL9AH2uPBs+jdN6NeQBdT3zkSKNi6VlIW vPFYQuvebdxwbMMS9q2+K6FxO0syrRrt9pQVgA9buBVQa37zoIP+umbpEZFs1AknK2 tUvd5V08ce1sQ== 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 6/6] selftests: net: exercise page pool reporting via netlink Date: Wed, 10 Apr 2024 18:28:15 -0700 Message-ID: <20240411012815.174400-7-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411012815.174400-1-kuba@kernel.org> References: <20240411012815.174400-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 --- tools/testing/selftests/net/lib/py/nsim.py | 7 ++ tools/testing/selftests/net/nl_netdev.py | 79 +++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/lib/py/nsim.py b/tools/testing/selftests/net/lib/py/nsim.py index 94aa32f59fdb..1fd50a308408 100644 --- a/tools/testing/selftests/net/lib/py/nsim.py +++ b/tools/testing/selftests/net/lib/py/nsim.py @@ -28,6 +28,13 @@ 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 up(self): + ip("link set dev {} up".format(self.ifname)) + + def down(self): + ip("link set dev {} down".format(self.ifname)) 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..afc510c044ce 100755 --- a/tools/testing/selftests/net/nl_netdev.py +++ b/tools/testing/selftests/net/nl_netdev.py @@ -1,7 +1,8 @@ #!/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, NetdevFamily, NetdevSimDev, ip def empty_check(nf) -> None: @@ -15,9 +16,83 @@ 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] + + # No page pools when down + nsim.down() + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + ksft_eq(len(pp_list), 0) + + # Up, empty page pool appears + nsim.up() + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + ksft_ge(len(pp_list), 0) + refs = sum([pp["inflight"] for pp in pp_list]) + ksft_eq(refs, 0) + + # Down, it disappears, again + nsim.down() + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + ksft_eq(len(pp_list), 0) + + # Up, allocate a page + nsim.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 + nsim.down() + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + ksft_eq(len(pp_list), 1) + refs = sum([pp["inflight"] for pp in pp_list if pp.get("ifindex") == nsim.ifindex]) + ksft_eq(refs, 1) + undetached = [pp for pp in pp_list if "detach-time" not in pp] + ksft_eq(len(undetached), 0) + + # New pp can get created, and we'll have two + nsim.up() + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + attached = [pp for pp in pp_list if "detach-time" not in pp] + undetached = [pp for pp in pp_list if "detach-time" in pp] + ksft_eq(len(attached), 1) + ksft_eq(len(undetached), 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 + for i in range(50): + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + if len(pp_list) == 1: + break + time.sleep(0.05) + ksft_eq(len(pp_list), 1) + + # And down... + nsim.down() + pp_list = nf.page_pool_get({}, dump=True) + pp_list = [pp for pp in pp_list if pp.get("ifindex") == nsim.ifindex] + ksft_eq(len(pp_list), 0) + + # Last, leave the page hanging for destroy, nothing to check + # we're trying to exercise the orphaning path in the kernel + nsim.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__":