From patchwork Thu Dec 19 03:28: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: 13914427 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 B48662AE72 for ; Thu, 19 Dec 2024 03:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734578915; cv=none; b=FgftW3H8BwnBuJIdkIZ8tNtL6MshD/Og6vn9GTzfM1RiuP8VsgCP5aiR2LdZiLX3lgDxq4OvKngfHAU6ivftVVdLjK6O+GzKR7kwowjxh7HVFoLJkZoqO9GBeOUa9uVqnvUvNPa8uhia4pmdh878LguyOPg1VUVgXnhhW4OwSlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734578915; c=relaxed/simple; bh=K98nzwZdrBaj6n5MfiOuK/XIM5QGN2s3GR+bpGzt0GA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=KcqSWn7IKNQY7qVK/zgrYOwQ5YbC2ujLRnFY5CB3AvNcRxpuJ4s+kLndMm2LOF7j/Ep8kxZqTSkTdCRJIuxpBj5b5J/RtB0z/xpEyNor45aVKbuHajSPbYxMyzdWv4MjlqCcLnkmxxT2cLfe044TEDhEuN3YamJwdtmqv9lkLH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XP9zd6fc; 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="XP9zd6fc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2CAFC4CED4; Thu, 19 Dec 2024 03:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734578915; bh=K98nzwZdrBaj6n5MfiOuK/XIM5QGN2s3GR+bpGzt0GA=; h=From:To:Cc:Subject:Date:From; b=XP9zd6fcs0rC1gN0mj6FauYc67SpBu4Hj2RAUJD7MfSJ32QxsChnPmwALMVChD5hk 51+lL/RJGgpGiHGnIvBSf2KjMP3pVYRY5oV4Ycg/hGeW+IP5dDLhYKj0SxTh5PipGw Z6T313QDJmGuQiS63X33inCKOvt1RwWYV709U4NK4zgpgYi0iEwTjO2R6u3n+BSFmn JGtCoCbKSRztWUc+HdetyCRu0V/Q0WSfgceirBBrX+A520WDYOn1h6WS3RJWQUGAsf CWputvfik0+DKx7tswqx1NGuY71TRR1qhftk/+WI6XDm5cpVQa6+SaB50+BIahZ66o +HSik99DPuNmQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, Jakub Kicinski , jdamato@fastly.com, almasrymina@google.com, sridhar.samudrala@intel.com, amritha.nambiar@intel.com Subject: [PATCH net v2 1/2] netdev-genl: avoid empty messages in napi get Date: Wed, 18 Dec 2024 19:28:32 -0800 Message-ID: <20241219032833.1165433-1-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 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 Empty netlink responses from do() are not correct (as opposed to dump() where not dumping anything is perfectly fine). We should return an error if the target object does not exist, in this case if the netdev is down we "hide" the NAPI instances. Fixes: 27f91aaf49b3 ("netdev-genl: Add netlink framework functions for napi") Signed-off-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- v2: - fix the locking v1: https://lore.kernel.org/20241218024305.823683-1-kuba@kernel.org CC: jdamato@fastly.com CC: almasrymina@google.com CC: sridhar.samudrala@intel.com CC: amritha.nambiar@intel.com --- net/core/netdev-genl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 2d3ae0cd3ad2..b0772d135efb 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -246,8 +246,12 @@ int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) rcu_read_unlock(); rtnl_unlock(); - if (err) + if (err) { goto err_free_msg; + } else if (!rsp->len) { + err = -ENOENT; + goto err_free_msg; + } return genlmsg_reply(rsp, info); From patchwork Thu Dec 19 03:28: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: 13914428 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 EEEC513AA38 for ; Thu, 19 Dec 2024 03:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734578916; cv=none; b=L2AzxKxv6paizM9Chcrz84jX1vBzbW9iKuZCP180o9YwSq0YNaHRkY4uy7175+8yxStpEDXp1zUQyCFuwY3lOctYygLzpB/QKoEUDjBrm+C2GBztWzshXsqbHQ97ZKSbcQ84FSj9cNssCuVxR2Jmy1hzjnN2LNQSJRjXYCyxSlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734578916; c=relaxed/simple; bh=awvvBD8hci1kx6hi2UiFqAE+XhnyA5OqaVkbmdQOcL0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWQFJ/dAgGC0iwV1zme3JNnhfSVuelOn83wpN1WTF3qNkD2+cLe81JgcoRYXzUakb2rrdv5Ky/b6iO1nofcrxq4G+AIublu6BYogZA9+S+LtkgrJyVVlbVk08eP96ZB3ASRA81mtk7jRHrAT8SC8+QDz2HnVrRHvbpsNH5Dl9GI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R1q1//G2; 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="R1q1//G2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DD32C4CEDC; Thu, 19 Dec 2024 03:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734578915; bh=awvvBD8hci1kx6hi2UiFqAE+XhnyA5OqaVkbmdQOcL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R1q1//G2O0Yd8WQzTk7RSx1l7FWEefexvF50ysE36UjwUdoj8ucKaJXiHXn0+nqIE HwQNbcHaUIU1PYc1zBmQiPiAwyPIMLaIzgpjao0ODaSnT5qPdBWQhUIckPo12GZxr2 4kL/oZ0CaTKPfes+1DMDNxdKCSGGeTaOkqLizRx53qB86I3U0xghLOsXN0dszhyC22 7jM4+GqdDC4zinnglN/zdvx8NBUGMthXsOmfmlXGK87keyWXGCqmJ7/5IM1Xp2FSTD wXX49J6Qc0n+p1MNl1iBV8n6ShlXywIOYNdBUYU/j8NCDDFqYX3gKHJVkNicm0c4Kv JnTQKVZDcqBFQ== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, Jakub Kicinski Subject: [PATCH net v2 2/2] selftests: drv-net: test empty queue and NAPI responses in netlink Date: Wed, 18 Dec 2024 19:28:33 -0800 Message-ID: <20241219032833.1165433-2-kuba@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219032833.1165433-1-kuba@kernel.org> References: <20241219032833.1165433-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 Make sure kernel doesn't respond to GETs for queues and NAPIs when link is down. Not with valid data, or with empty message, we want a ENOENT. Signed-off-by: Jakub Kicinski --- tools/testing/selftests/drivers/net/queues.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/drivers/net/queues.py b/tools/testing/selftests/drivers/net/queues.py index 9c5473abbd78..38303da957ee 100755 --- a/tools/testing/selftests/drivers/net/queues.py +++ b/tools/testing/selftests/drivers/net/queues.py @@ -1,10 +1,12 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 -from lib.py import ksft_run, ksft_exit, ksft_eq, KsftSkipEx -from lib.py import EthtoolFamily, NetdevFamily +from lib.py import ksft_disruptive, ksft_exit, ksft_run +from lib.py import ksft_eq, ksft_raises, KsftSkipEx +from lib.py import EthtoolFamily, NetdevFamily, NlError from lib.py import NetDrvEnv -from lib.py import cmd +from lib.py import cmd, defer, ip +import errno import glob @@ -59,9 +61,27 @@ import glob ksft_eq(queues, expected) +@ksft_disruptive +def check_down(cfg, nl) -> None: + # Check the NAPI IDs before interface goes down and hides them + napis = nl.napi_get({'ifindex': cfg.ifindex}, dump=True) + + ip(f"link set dev {cfg.dev['ifname']} down") + defer(ip, f"link set dev {cfg.dev['ifname']} up") + + with ksft_raises(NlError) as cm: + nl.queue_get({'ifindex': cfg.ifindex, 'id': 0, 'type': 'rx'}) + ksft_eq(cm.exception.nl_msg.error, -errno.ENOENT) + + if napis: + with ksft_raises(NlError) as cm: + nl.napi_get({'id': napis[0]['id']}) + ksft_eq(cm.exception.nl_msg.error, -errno.ENOENT) + + def main() -> None: with NetDrvEnv(__file__, queue_count=100) as cfg: - ksft_run([get_queues, addremove_queues], args=(cfg, NetdevFamily())) + ksft_run([get_queues, addremove_queues, check_down], args=(cfg, NetdevFamily())) ksft_exit()