From: Chenguang Zhao <chenguang.zhao@linux.dev>
To: kuba@kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net,
edumazet@kernel.org, pabeni@redhat.com
Cc: netdev@vger.kernel.org, Chenguang Zhao <zhaochenguang@kylinos.cn>
Subject: [PATCH net-next] netdevsim: add debugfs knobs to fail net-shaper ops
Date: Tue, 1 Dec 2026 10:27:35 +0800 [thread overview]
Message-ID: <20261201022735.3588142-1-chenguang.zhao@linux.dev> (raw)
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
reply other threads:[~2026-12-01 2:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201022735.3588142-1-chenguang.zhao@linux.dev \
--to=chenguang.zhao@linux.dev \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=zhaochenguang@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox