🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24907

[PATCH net-next] netdevsim: add debugfs knobs to fail net-shaper ops

#24907
From: Chenguang Zhao
Date: Tue, 01 Dec 2026 02:27
139 lines
12252 bytes
From: Chenguang Zhao <zhaochenguang@kylinos.cn>

nsim_shaper_set(), nsim_shaper_del() and nsim_shaper_group() always
return success, so the net-shaper core never rolls back a driver
failure against netdevsim. Add per-PF debugfs bools that make those
callbacks return -EINVAL.

Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
---
This patch adds a debugfs switch for each of netdevsim's set,
delete and group callbacks.

If we want to simulate a netshaper configuration failure, we can flip
the switch on by writing 1 into debugfs. For example:
  echo 1 > /sys/kernel/debug/netdevsim/netdevsim1/ports/0/fail_shaper_set

Once that is set, netshaper set comes back with an error. This way,
we can test the net-shaper rollback.

base-commit: 612848d37e68b858e15815175f1c5e609e09d719

 drivers/net/netdevsim/netdev.c    | 54 +++++++++++++++++++++++++++++--
 drivers/net/netdevsim/netdevsim.h |  4 +++
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index 0372a9bd63bb..fce044a455be 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -608,18 +608,48 @@ static int nsim_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
 	return 0;
 }
 
+static struct netdevsim *nsim_shaper_get(struct net_shaper_binding *binding)
+{
+	if (binding->type != NET_SHAPER_BINDING_TYPE_NETDEV)
+		return NULL;
+
+	return netdev_priv(binding->netdev);
+}
+
+static int nsim_shaper_inject_failure(bool fail, struct netlink_ext_ack *extack)
+{
+	if (!fail)
+		return 0;
+
+	NL_SET_ERR_MSG_MOD(extack, "User setup the operation to fail for testing purposes");
+
+	return -EINVAL;
+}
+
 static int nsim_shaper_set(struct net_shaper_binding *binding,
 			   const struct net_shaper *shaper,
 			   struct netlink_ext_ack *extack)
 {
-	return 0;
+	struct netdevsim *ns;
+
+	ns = nsim_shaper_get(binding);
+	if (!ns)
+		return 0;
+
+	return nsim_shaper_inject_failure(ns->fail_shaper_set, extack);
 }
 
 static int nsim_shaper_del(struct net_shaper_binding *binding,
 			   const struct net_shaper_handle *handle,
 			   struct netlink_ext_ack *extack)
 {
-	return 0;
+	struct netdevsim *ns;
+
+	ns = nsim_shaper_get(binding);
+	if (!ns)
+		return 0;
+
+	return nsim_shaper_inject_failure(ns->fail_shaper_del, extack);
 }
 
 static int nsim_shaper_group(struct net_shaper_binding *binding,
@@ -628,7 +658,13 @@ static int nsim_shaper_group(struct net_shaper_binding *binding,
 			     const struct net_shaper *root,
 			     struct netlink_ext_ack *extack)
 {
-	return 0;
+	struct netdevsim *ns;
+
+	ns = nsim_shaper_get(binding);
+	if (!ns)
+		return 0;
+
+	return nsim_shaper_inject_failure(ns->fail_shaper_group, extack);
 }
 
 static void nsim_shaper_cap(struct net_shaper_binding *binding,
@@ -1193,6 +1229,15 @@ struct netdevsim *nsim_create(struct nsim_dev *nsim_dev,
 					 &nsim_qreset_fops);
 	ns->vlan_dfs = debugfs_create_file("vlan", 0400, nsim_dev_port->ddir,
 					   ns, &nsim_vlan_fops);
+	if (nsim_dev_port_is_pf(nsim_dev_port)) {
+		debugfs_create_bool("fail_shaper_set", 0600, nsim_dev_port->ddir,
+				    &ns->fail_shaper_set);
+		debugfs_create_bool("fail_shaper_del", 0600, nsim_dev_port->ddir,
+				    &ns->fail_shaper_del);
+		debugfs_create_bool("fail_shaper_group", 0600,
+				    nsim_dev_port->ddir,
+				    &ns->fail_shaper_group);
+	}
 	return ns;
 
 err_free_netdev:
@@ -1207,6 +1252,9 @@ void nsim_destroy(struct netdevsim *ns)
 	struct netdevsim *peer;
 	u16 vid;
 
+	debugfs_lookup_and_remove("fail_shaper_set", ns->nsim_dev_port->ddir);
+	debugfs_lookup_and_remove("fail_shaper_del", ns->nsim_dev_port->ddir);
+	debugfs_lookup_and_remove("fail_shaper_group", ns->nsim_dev_port->ddir);
 	debugfs_remove(ns->vlan_dfs);
 	debugfs_remove(ns->qr_dfs);
 	debugfs_remove(ns->pp_dfs);
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 2aa7ea924396..937d56998332 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -163,6 +163,10 @@ struct netdevsim {
 
 	struct notifier_block nb;
 	struct netdev_net_notifier nn;
+
+	bool fail_shaper_set;
+	bool fail_shaper_del;
+	bool fail_shaper_group;
 };
 
 struct netdevsim *nsim_create(struct nsim_dev *nsim_dev,
-- 
2.25.1
Technical Details
Message-ID: <20261201022735.3588142-1-chenguang.zhao@linux.dev>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374631-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374631-linux-kernel-netdev=dewy.ru
From: chenguang.zhao@linux.dev (Chenguang Zhao)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next] netdevsim: add debugfs knobs to fail net-shaper ops
Date: Tue,  1 Dec 2026 10:27:35 +0800
Organization: Usenet Network
Message-ID: <20261201022735.3588142-1-chenguang.zhao@linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1591641"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:bpBHTLFZo99b+E/TbRGicmTLdDE= sha256:LdSjvOl+Ol575owmfFiZpMqlYazdv8ADMtAdtcQLyiU=
	sha1:C1csv0pouttCOEwpUALfLvpnUI4= sha256:uv1gh/5HK3I02rqzQogb2kgEicFS3a3OkSGemi6S2hA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3B3971171F9; Tue,  1 Dec 2026 05:28:32 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 5VfhdrskSJJB;
	Tue,  1 Dec 2026 05:28:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374631-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0B9FD117165; Tue,  1 Dec 2026 05:28:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 125D32030D; Tue,  1 Dec 2026 02:28:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796092089;
	b=WIUc6gWSP7Wr9Z/wcMDodaGa6Tp6LZG3gcmc+nYhq7NVMe/Ki/0vqYlnFGMqZF7Y6dAP
	 zFduxnG4MmOCbjjqK7JQ+0JAPT0ouaTjlxy0gBfs7xyz3ItyffhVp9Sna2/dKvYvC4p0A
	 wtukLUT7OIjyNkfaqDaOpsBI/PaminPxBjKb7DhcM+pLdAMgJ68doB9PiBdwJ9wDjf8Tm
	 8GGR5rW8/kSmDij+YkuhaBcJntxvips36QJEVI9jSn4CnyqBVC7JFY4XZ0JcZZe1cDTmP
	 FU+xjfobR6BsuicIDx3osmOFfEu7a3F330jxMpsh3JkGmcgFY5/KBQj1T+h6+KinVDw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796092089;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:
	 Subject:Date:Message-Id:X-Mailer:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=4xQqec2HXVAbh0k4x/KtFfpxVcWIEOHgsIbmWr5rB34=;
	b=uNwh0ONJwaLJablhq/ruWmIe1sPJlRwaFwo0IMtHcDMHQBbWEGv7JiNYJe3sVUz8beOT
	 0mSxI94MNkuFJO1VPwDpBVY9NdtjTsQJvbXJud1hFSDSLkEQ5rDU2Lh0yMoXTt9D5cKHf
	 ZSFlO6IhC+7kBb3n2m3GShXypPhNktpZ8GTTZ43tlNHs5FpA7XaMpEJUeQiQSPdfgeQp1
	 EWqUpKD/uf5skGPT3tM6xR6N36jxHZy/OL2cmWFVIpm307iELcmVL0A6WLIRXjziUe1j1
	 u4jkNZwaSTyMs6oa1mSTQWPMnslzTB9U/bDzcVTFrglLnFdtIhVOQnN1X/wM728toqw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MM40FPvG;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id DAC7D606A327;
	Tue,  1 Dec 2026 02:28:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MM40FPvG
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.83
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796092089;
	b=O8y0dHUOIjFp2alysZsTNftYkSV2+nPshn6Gia+kENhoySXJaPwjxz7QhEixjb+Qhxoy
	 vMZfEvRS91STy21zi3wIDfHikYCoH49jeLgQrxBqMo+ovXfe9m5+zWS5yjPFttxoTRNfa
	 1Ui2l9V8A4dew3NecQEDlJrWbHlEcuTli65eYr9G2afFAxbeQCsbBpvb+jLk97iyYVJ3s
	 YVuFIzQ4RCZqtsiXijgLxsj6m7UbFncKwipMpx/bG5aqmp0WYZcMO7th5nG4ociSjDDqB
	 wL7+MyCBAt1267bSNjRTEis5kkdTWns7iIDAncgl4QmYoqfp5p7LsFHTsYG5x3u6U1g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796092089;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-Id:
	 X-Mailer:MIME-Version:Content-Transfer-Encoding;
	bh=4xQqec2HXVAbh0k4x/KtFfpxVcWIEOHgsIbmWr5rB34=;
	b=EDD6GkXSzpcaQ+NEJLS33qedw3OpUD9Ar8tlMHesE7IMOJMgFA7tcJX7pg/pm7ji8SKJ
	 JwnES0zoE/UHTh9UiSaa6/oQAkcIwF3mx0j3BS122S0xZGPC8nat727WYo0sJTjoZyw2m
	 zQIDuEJPQdfuHbc9gPu5gFB4G/hspzXkz/xXXlkB0eRXRejvqcAz6wRH/mlR2jikBh0Y4
	 fQgohYVaQY9raqPFLNozHlSc1ibsEHmlYpxPoIWp5PXv8sSOOdMBPuWNj6Z5uS45wQALn
	 P9ZOYg0wsITU/pjqsFD0//ZBextQ8+GzgX71wg+VCIX38FPmhRxKcP+i6iWAEsV3hoA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=MM40FPvG;
	arc=none smtp.remote-ip=95.215.58.83
X-Received: from mta1.migadu.com (out-83.mta1.migadu.com [95.215.58.83])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B5FA606A336
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 02:28:06 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B5FA606A336
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=Hnb1DYpnHc4FXUr9P0d1XcqHWtgVnhCz6ZQN5gxTXrY=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1796092085; v=1; x=1796696885;
 b=MM40FPvGr9+kl3Cr+ubpEZd66iWxWWzuOOzgNOmHBkwsg/+1L5kEDxr7mvkftzn1Gh7OSGhI
 wCSYDWbwISHe20Biq05J6MzL6olulZ/Fnq84OKRSJ7ymzSuYc403MvA1iEsrzMieXuMIeBisQjZ
 ok5lZIwEwniV9Yy6Fnu0nqoA=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 43ef542e9d7dd098;
	Tue, 01 Dec 2026 02:28:05 +0000
X-Mizu-Trace-ID: 43ef542e9d7dd098
X-Migadu-Flow: FLOW_OUT
X-Cc: netdev@vger.kernel.org,
	Chenguang Zhao <zhaochenguang@kylinos.cn>
X-Mailer: git-send-email 2.25.1
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list