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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230720121829.566974-12-jiri@resnulli.us>
Date: Thu, 20 Jul 2023 14:18:29 +0200
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: kuba@...nel.org,
	pabeni@...hat.com,
	davem@...emloft.net,
	edumazet@...gle.com,
	moshe@...dia.com,
	saeedm@...dia.com,
	idosch@...dia.com,
	petrm@...dia.com
Subject: [patch net-next v2 11/11] devlink: extend health reporter dump selector by port index

From: Jiri Pirko <jiri@...dia.com>

Introduce a possibility for devlink object to expose attributes it
supports for selection of dumped objects.

Use this by health reporter to indicate it supports port index based
selection of dump objects. Implement this selection mechanism in
devlink_nl_cmd_health_reporter_get_dump_one()

Example:
$ devlink health
pci/0000:08:00.0:
  reporter fw
    state healthy error 0 recover 0 auto_dump true
  reporter fw_fatal
    state healthy error 0 recover 0 grace_period 60000 auto_recover true auto_dump true
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.0/32768:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.0/32769:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.0/32770:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.1:
  reporter fw
    state healthy error 0 recover 0 auto_dump true
  reporter fw_fatal
    state healthy error 0 recover 0 grace_period 60000 auto_recover true auto_dump true
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.1/98304:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.1/98305:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.1/98306:
  reporter vnic
    state healthy error 0 recover 0

$ devlink health show pci/0000:08:00.0
pci/0000:08:00.0:
  reporter fw
    state healthy error 0 recover 0 auto_dump true
  reporter fw_fatal
    state healthy error 0 recover 0 grace_period 60000 auto_recover true auto_dump true
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.0/32768:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.0/32769:
  reporter vnic
    state healthy error 0 recover 0
pci/0000:08:00.0/32770:
  reporter vnic
    state healthy error 0 recover 0

$ devlink health show pci/0000:08:00.0/32768
pci/0000:08:00.0/32768:
  reporter vnic
    state healthy error 0 recover 0

The last command is possible because of this patch.

Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
 net/devlink/devl_internal.h |  2 ++
 net/devlink/health.c        | 21 +++++++++++++++++++--
 net/devlink/netlink.c       |  8 ++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 168d36dbc6f7..510b66806341 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -115,6 +115,8 @@ struct devlink_nl_dump_state {
 struct devlink_cmd {
 	int (*dump_one)(struct sk_buff *msg, struct devlink *devlink,
 			struct netlink_callback *cb);
+	const u16 *dump_selector_attrs;
+	unsigned int dump_selector_attrs_count;
 };
 
 extern const struct genl_small_ops devlink_nl_ops[40];
diff --git a/net/devlink/health.c b/net/devlink/health.c
index 194340a8bb86..74d322ee5b83 100644
--- a/net/devlink/health.c
+++ b/net/devlink/health.c
@@ -390,12 +390,21 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
 					    struct netlink_callback *cb)
 {
 	struct devlink_nl_dump_state *state = devlink_dump_state(cb);
+	struct nlattr **selector = state->selector;
 	struct devlink_health_reporter *reporter;
+	unsigned long port_index_end = ULONG_MAX;
+	unsigned long port_index_start = 0;
 	struct devlink_port *port;
 	unsigned long port_index;
 	int idx = 0;
 	int err;
 
+	if (selector && selector[DEVLINK_ATTR_PORT_INDEX]) {
+		port_index_start = nla_get_u32(selector[DEVLINK_ATTR_PORT_INDEX]);
+		port_index_end = port_index_start;
+		goto per_port_dump;
+	}
+
 	list_for_each_entry(reporter, &devlink->reporter_list, list) {
 		if (idx < state->idx) {
 			idx++;
@@ -412,7 +421,9 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
 		}
 		idx++;
 	}
-	xa_for_each(&devlink->ports, port_index, port) {
+per_port_dump:
+	xa_for_each_range(&devlink->ports, port_index, port,
+			  port_index_start, port_index_end) {
 		list_for_each_entry(reporter, &port->reporter_list, list) {
 			if (idx < state->idx) {
 				idx++;
@@ -434,8 +445,14 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
 	return 0;
 }
 
+static const u16 devl_cmd_health_reporter_dump_selector_attrs[] = {
+	DEVLINK_ATTR_PORT_INDEX,
+};
+
 const struct devlink_cmd devl_cmd_health_reporter_get = {
-	.dump_one		= devlink_nl_cmd_health_reporter_get_dump_one,
+	.dump_one			= devlink_nl_cmd_health_reporter_get_dump_one,
+	.dump_selector_attrs		= devl_cmd_health_reporter_dump_selector_attrs,
+	.dump_selector_attrs_count	= ARRAY_SIZE(devl_cmd_health_reporter_dump_selector_attrs),
 };
 
 int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index c2083398bd73..bd60d229cfbe 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -265,8 +265,16 @@ static void devlink_nl_policy_cpy(struct nla_policy *policy, unsigned int attr)
 static void devlink_nl_dump_selector_policy_init(const struct devlink_cmd *cmd,
 						 struct nla_policy *policy)
 {
+	int i;
+
 	devlink_nl_policy_cpy(policy, DEVLINK_ATTR_BUS_NAME);
 	devlink_nl_policy_cpy(policy, DEVLINK_ATTR_DEV_NAME);
+
+	for (i = 0; i < cmd->dump_selector_attrs_count; i++) {
+		unsigned int attr = cmd->dump_selector_attrs[i];
+
+		memcpy(&policy[attr], &devlink_nl_policy[attr], sizeof(*policy));
+	}
 }
 
 static int devlink_nl_start(struct netlink_callback *cb)
-- 
2.41.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ