lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220620152647.2498927-4-dchumak@nvidia.com>
Date:   Mon, 20 Jun 2022 18:26:45 +0300
From:   Dima Chumak <dchumak@...dia.com>
To:     Jakub Kicinski <kuba@...nel.org>
CC:     Jiri Pirko <jiri@...dia.com>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Paolo Abeni <pabeni@...hat.com>, <netdev@...r.kernel.org>,
        Dima Chumak <dchumak@...dia.com>
Subject: [PATCH net-next 3/5] netdevsim: Support devlink rate limit_type police

Implement devlink_ops that enable setting devlink_rate attributes for
the new DEVLINK_RATE_LIMIT_TYPE_POLICE type of rate objects via devlink
API.

The new rate values of VF ports and rate nodes are exposed to netdevsim
debugfs.

Signed-off-by: Dima Chumak <dchumak@...dia.com>
---
 drivers/net/netdevsim/dev.c       | 211 ++++++++++++++++++++++++++++--
 drivers/net/netdevsim/netdevsim.h |  11 +-
 2 files changed, 207 insertions(+), 15 deletions(-)

diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 57a3ac893792..9ac78ab09a58 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -406,10 +406,24 @@ static int nsim_dev_port_debugfs_init(struct nsim_dev *nsim_dev,
 	if (nsim_dev_port_is_vf(nsim_dev_port)) {
 		unsigned int vf_id = nsim_dev_port_index_to_vf_index(port_index);
 
-		debugfs_create_u16("tx_share", 0400, nsim_dev_port->ddir,
+		debugfs_create_u64("tx_share", 0400, nsim_dev_port->ddir,
 				   &nsim_dev->vfconfigs[vf_id].min_tx_rate);
-		debugfs_create_u16("tx_max", 0400, nsim_dev_port->ddir,
+		debugfs_create_u64("tx_max", 0400, nsim_dev_port->ddir,
 				   &nsim_dev->vfconfigs[vf_id].max_tx_rate);
+		debugfs_create_u64("tx_burst", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].tx_burst);
+		debugfs_create_u64("rx_max", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].rx_max);
+		debugfs_create_u64("rx_burst", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].rx_burst);
+		debugfs_create_u64("tx_pkts", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].tx_pkts);
+		debugfs_create_u64("tx_pkts_burst", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].tx_pkts_burst);
+		debugfs_create_u64("rx_pkts", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].rx_pkts);
+		debugfs_create_u64("rx_pkts_burst", 0400, nsim_dev_port->ddir,
+				   &nsim_dev->vfconfigs[vf_id].rx_pkts_burst);
 		nsim_dev_port->rate_parent = debugfs_create_file("rate_parent",
 								 0400,
 								 nsim_dev_port->ddir,
@@ -1192,20 +1206,106 @@ static int nsim_leaf_tx_max_set(struct devlink_rate *devlink_rate, void *priv,
 	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
 	int err;
 
-	err = nsim_rate_bytes_to_units("tx_max", &tx_max, extack);
-	if (err)
-		return err;
+	if (devlink_rate->limit_type == DEVLINK_RATE_LIMIT_TYPE_SHAPING) {
+		err = nsim_rate_bytes_to_units("tx_max", &tx_max, extack);
+		if (err)
+			return err;
+	}
 
 	nsim_dev->vfconfigs[vf_id].max_tx_rate = tx_max;
 	return 0;
 }
 
+static int nsim_leaf_tx_burst_set(struct devlink_rate *rate_leaf, void *priv,
+				  u64 tx_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].tx_burst = tx_burst;
+	return 0;
+}
+
+static int nsim_leaf_rx_max_set(struct devlink_rate *rate_leaf, void *priv,
+				u64 rx_max, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].rx_max = rx_max;
+	return 0;
+}
+
+static int nsim_leaf_rx_burst_set(struct devlink_rate *rate_leaf, void *priv,
+				  u64 rx_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].rx_burst = rx_burst;
+	return 0;
+}
+
+static int nsim_leaf_tx_pkts_set(struct devlink_rate *rate_leaf, void *priv,
+				 u64 tx_pkts, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].tx_pkts = tx_pkts;
+	return 0;
+}
+
+static int nsim_leaf_tx_pkts_burst_set(struct devlink_rate *rate_leaf, void *priv,
+				       u64 tx_pkts_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].tx_pkts_burst = tx_pkts_burst;
+	return 0;
+}
+
+static int nsim_leaf_rx_pkts_set(struct devlink_rate *rate_leaf, void *priv,
+				 u64 rx_pkts, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].rx_pkts = rx_pkts;
+	return 0;
+}
+
+static int nsim_leaf_rx_pkts_burst_set(struct devlink_rate *rate_leaf, void *priv,
+				       u64 rx_pkts_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_dev_port *nsim_dev_port = priv;
+	struct nsim_dev *nsim_dev = nsim_dev_port->ns->nsim_dev;
+	int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index);
+
+	nsim_dev->vfconfigs[vf_id].rx_pkts_burst = rx_pkts_burst;
+	return 0;
+}
+
 struct nsim_rate_node {
 	struct dentry *ddir;
 	struct dentry *rate_parent;
 	char *parent_name;
-	u16 tx_share;
-	u16 tx_max;
+	u64 tx_share;
+	u64 tx_max;
+	u64 tx_burst;
+	u64 rx_max;
+	u64 rx_burst;
+	u64 tx_pkts;
+	u64 tx_pkts_burst;
+	u64 rx_pkts;
+	u64 rx_pkts_burst;
 };
 
 static int nsim_node_tx_share_set(struct devlink_rate *devlink_rate, void *priv,
@@ -1228,14 +1328,79 @@ static int nsim_node_tx_max_set(struct devlink_rate *devlink_rate, void *priv,
 	struct nsim_rate_node *nsim_node = priv;
 	int err;
 
-	err = nsim_rate_bytes_to_units("tx_max", &tx_max, extack);
-	if (err)
-		return err;
+	if (devlink_rate->limit_type == DEVLINK_RATE_LIMIT_TYPE_SHAPING) {
+		err = nsim_rate_bytes_to_units("tx_max", &tx_max, extack);
+		if (err)
+			return err;
+	}
 
 	nsim_node->tx_max = tx_max;
 	return 0;
 }
 
+static int nsim_node_tx_burst_set(struct devlink_rate *rate_node, void *priv,
+				  u64 tx_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->tx_burst = tx_burst;
+	return 0;
+}
+
+static int nsim_node_rx_max_set(struct devlink_rate *rate_node, void *priv,
+				u64 rx_max, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->rx_max = rx_max;
+	return 0;
+}
+
+static int nsim_node_rx_burst_set(struct devlink_rate *rate_node, void *priv,
+				  u64 rx_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->rx_burst = rx_burst;
+	return 0;
+}
+
+static int nsim_node_tx_pkts_set(struct devlink_rate *rate_node, void *priv,
+				 u64 tx_pkts, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->tx_pkts = tx_pkts;
+	return 0;
+}
+
+static int nsim_node_tx_pkts_burst_set(struct devlink_rate *rate_node, void *priv,
+				       u64 tx_pkts_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->tx_pkts_burst = tx_pkts_burst;
+	return 0;
+}
+
+static int nsim_node_rx_pkts_set(struct devlink_rate *rate_node, void *priv,
+				 u64 rx_pkts, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->rx_pkts = rx_pkts;
+	return 0;
+}
+
+static int nsim_node_rx_pkts_burst_set(struct devlink_rate *rate_node, void *priv,
+				       u64 rx_pkts_burst, struct netlink_ext_ack *extack)
+{
+	struct nsim_rate_node *nsim_node = priv;
+
+	nsim_node->rx_pkts_burst = rx_pkts_burst;
+	return 0;
+}
+
 static int nsim_rate_node_new(struct devlink_rate *node, void **priv,
 			      struct netlink_ext_ack *extack)
 {
@@ -1253,13 +1418,19 @@ static int nsim_rate_node_new(struct devlink_rate *node, void **priv,
 
 	nsim_node->ddir = debugfs_create_dir(node->name, nsim_dev->nodes_ddir);
 
-	debugfs_create_u16("tx_share", 0400, nsim_node->ddir, &nsim_node->tx_share);
-	debugfs_create_u16("tx_max", 0400, nsim_node->ddir, &nsim_node->tx_max);
+	debugfs_create_u64("tx_share", 0400, nsim_node->ddir, &nsim_node->tx_share);
+	debugfs_create_u64("tx_max", 0400, nsim_node->ddir, &nsim_node->tx_max);
+	debugfs_create_u64("tx_burst", 0400, nsim_node->ddir, &nsim_node->tx_burst);
+	debugfs_create_u64("rx_max", 0400, nsim_node->ddir, &nsim_node->rx_max);
+	debugfs_create_u64("rx_burst", 0400, nsim_node->ddir, &nsim_node->rx_burst);
+	debugfs_create_u64("tx_pkts", 0400, nsim_node->ddir, &nsim_node->tx_pkts);
+	debugfs_create_u64("tx_pkts_burst", 0400, nsim_node->ddir, &nsim_node->tx_pkts_burst);
+	debugfs_create_u64("rx_pkts", 0400, nsim_node->ddir, &nsim_node->rx_pkts);
+	debugfs_create_u64("rx_pkts_burst", 0400, nsim_node->ddir, &nsim_node->rx_pkts_burst);
 	nsim_node->rate_parent = debugfs_create_file("rate_parent", 0400,
 						     nsim_node->ddir,
 						     &nsim_node->parent_name,
 						     &nsim_dev_rate_parent_fops);
-
 	*priv = nsim_node;
 	return 0;
 }
@@ -1337,8 +1508,22 @@ static const struct devlink_ops nsim_dev_devlink_ops = {
 	.trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get,
 	.rate_leaf_tx_share_set = nsim_leaf_tx_share_set,
 	.rate_leaf_tx_max_set = nsim_leaf_tx_max_set,
+	.rate_leaf_tx_burst_set = nsim_leaf_tx_burst_set,
+	.rate_leaf_rx_max_set = nsim_leaf_rx_max_set,
+	.rate_leaf_rx_burst_set = nsim_leaf_rx_burst_set,
+	.rate_leaf_tx_pkts_set = nsim_leaf_tx_pkts_set,
+	.rate_leaf_tx_pkts_burst_set = nsim_leaf_tx_pkts_burst_set,
+	.rate_leaf_rx_pkts_set = nsim_leaf_rx_pkts_set,
+	.rate_leaf_rx_pkts_burst_set = nsim_leaf_rx_pkts_burst_set,
 	.rate_node_tx_share_set = nsim_node_tx_share_set,
 	.rate_node_tx_max_set = nsim_node_tx_max_set,
+	.rate_node_tx_burst_set = nsim_node_tx_burst_set,
+	.rate_node_rx_max_set = nsim_node_rx_max_set,
+	.rate_node_rx_burst_set = nsim_node_rx_burst_set,
+	.rate_node_tx_pkts_set = nsim_node_tx_pkts_set,
+	.rate_node_tx_pkts_burst_set = nsim_node_tx_pkts_burst_set,
+	.rate_node_rx_pkts_set = nsim_node_rx_pkts_set,
+	.rate_node_rx_pkts_burst_set = nsim_node_rx_pkts_burst_set,
 	.rate_node_new = nsim_rate_node_new,
 	.rate_node_del = nsim_rate_node_del,
 	.rate_leaf_parent_set = nsim_rate_leaf_parent_set,
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 0b122872b2c9..2040b95e5f93 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -241,8 +241,15 @@ struct nsim_dev_port {
 
 struct nsim_vf_config {
 	int link_state;
-	u16 min_tx_rate;
-	u16 max_tx_rate;
+	u64 min_tx_rate;
+	u64 max_tx_rate;
+	u64 tx_burst;
+	u64 rx_max;
+	u64 rx_burst;
+	u64 tx_pkts;
+	u64 tx_pkts_burst;
+	u64 rx_pkts;
+	u64 rx_pkts_burst;
 	u16 vlan;
 	__be16 vlan_proto;
 	u16 qos;
-- 
2.36.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ