diff mbox series

[net-next,v2,11/11] devlink: extend health reporter dump selector by port index

Message ID 20230720121829.566974-12-jiri@resnulli.us (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series devlink: introduce dump selector attr and use it for per-instance dumps | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1344 this patch: 1344
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1367 this patch: 1367
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns WARNING: line length of 87 exceeds 80 columns WARNING: line length of 99 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiri Pirko July 20, 2023, 12:18 p.m. UTC
From: Jiri Pirko <jiri@nvidia.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@nvidia.com>
---
 net/devlink/devl_internal.h |  2 ++
 net/devlink/health.c        | 21 +++++++++++++++++++--
 net/devlink/netlink.c       |  8 ++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski July 25, 2023, 6:48 p.m. UTC | #1
On Thu, 20 Jul 2023 14:18:29 +0200 Jiri Pirko wrote:
> 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()

This patch is not very clean. IMHO implementing the filters by skipping
is not going to scale to reasonably complex filters. Isn't it better to
add a .filter callback which will look at the about-to-be-dumped object
and return true/false on whether it should be dumped?
Jiri Pirko July 31, 2023, 12:52 p.m. UTC | #2
Tue, Jul 25, 2023 at 08:48:03PM CEST, kuba@kernel.org wrote:
>On Thu, 20 Jul 2023 14:18:29 +0200 Jiri Pirko wrote:
>> 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()
>
>This patch is not very clean. IMHO implementing the filters by skipping
>is not going to scale to reasonably complex filters. Isn't it better to

I'm not sure what do you mean by skipping? There is not skipping. In
case PORT_INDEX is passed in the selector, only that specific port is
processed. No scale issues I see. Am I missing something?


>add a .filter callback which will look at the about-to-be-dumped object
>and return true/false on whether it should be dumped?

No, that would not scale. Passing the selector attrs to the dump
callback it better, as the dump callback according to the attrs can
reach only what is needed, knowing the internals. But perhaps I don't
understand correctly your suggestion.
Jakub Kicinski July 31, 2023, 5:06 p.m. UTC | #3
On Mon, 31 Jul 2023 14:52:44 +0200 Jiri Pirko wrote:
> >This patch is not very clean. IMHO implementing the filters by skipping
> >is not going to scale to reasonably complex filters. Isn't it better to  
> 
> I'm not sure what do you mean by skipping? There is not skipping. In
> case PORT_INDEX is passed in the selector, only that specific port is
> processed. No scale issues I see. Am I missing something?
> 
> 
> >add a .filter callback which will look at the about-to-be-dumped object
> >and return true/false on whether it should be dumped?  
> 
> No, that would not scale. Passing the selector attrs to the dump
> callback it better, as the dump callback according to the attrs can
> reach only what is needed, knowing the internals. But perhaps I don't
> understand correctly your suggestion.

for_each_obj() {
	if (obj_dump_filtered(obj, dump_info))  // < run filter
		continue;                       // < skip object

	dump_one(obj)
}
Jiri Pirko Aug. 1, 2023, 6:49 a.m. UTC | #4
Mon, Jul 31, 2023 at 07:06:32PM CEST, kuba@kernel.org wrote:
>On Mon, 31 Jul 2023 14:52:44 +0200 Jiri Pirko wrote:
>> >This patch is not very clean. IMHO implementing the filters by skipping
>> >is not going to scale to reasonably complex filters. Isn't it better to  
>> 
>> I'm not sure what do you mean by skipping? There is not skipping. In
>> case PORT_INDEX is passed in the selector, only that specific port is
>> processed. No scale issues I see. Am I missing something?
>> 
>> 
>> >add a .filter callback which will look at the about-to-be-dumped object
>> >and return true/false on whether it should be dumped?  
>> 
>> No, that would not scale. Passing the selector attrs to the dump
>> callback it better, as the dump callback according to the attrs can
>> reach only what is needed, knowing the internals. But perhaps I don't
>> understand correctly your suggestion.
>
>for_each_obj() {
>	if (obj_dump_filtered(obj, dump_info))  // < run filter
>		continue;                       // < skip object
>
>	dump_one(obj)

I don't see how this would help. For example, passing PORT_INDEX, I know
exactly what object to reach, according to this PORT_INDEX. Why to
iterate over all of them and try the filter? Does not make sense to me.

Maybe we are each understanding this feature differently. This is about
passing keys which index the objects. It is always devlink handle,
sometimes port index and I see another example in shared buffer index.
That's about it. Basically user passes partial tuple of indexes.
Example:
devlink port show
the key is: bus_name/dev_name/port_index
user passes bus_name/dev_name, this is the selector, a partial key.

The sophisticated filtering is not a focus of this patchset. User can do
it putting bpf filter on the netlink socket.
Jakub Kicinski Aug. 1, 2023, 3:56 p.m. UTC | #5
On Tue, 1 Aug 2023 08:49:45 +0200 Jiri Pirko wrote:
> >for_each_obj() {
> >	if (obj_dump_filtered(obj, dump_info))  // < run filter
> >		continue;                       // < skip object
> >
> >	dump_one(obj)  
> 
> I don't see how this would help. For example, passing PORT_INDEX, I know
> exactly what object to reach, according to this PORT_INDEX. Why to
> iterate over all of them and try the filter? Does not make sense to me.
> 
> Maybe we are each understanding this feature differently. This is about
> passing keys which index the objects. It is always devlink handle,
> sometimes port index and I see another example in shared buffer index.
> That's about it. Basically user passes partial tuple of indexes.
> Example:
> devlink port show
> the key is: bus_name/dev_name/port_index
> user passes bus_name/dev_name, this is the selector, a partial key.
> 
> The sophisticated filtering is not a focus of this patchset. User can do
> it putting bpf filter on the netlink socket.

Okay, I was trying to be helpful, I don't want to argue for
a particular implementation. IMO what's posted is too ugly
to be merged, please restructure it.
Jiri Pirko Aug. 2, 2023, 7:04 a.m. UTC | #6
Tue, Aug 01, 2023 at 05:56:44PM CEST, kuba@kernel.org wrote:
>On Tue, 1 Aug 2023 08:49:45 +0200 Jiri Pirko wrote:
>> >for_each_obj() {
>> >	if (obj_dump_filtered(obj, dump_info))  // < run filter
>> >		continue;                       // < skip object
>> >
>> >	dump_one(obj)  
>> 
>> I don't see how this would help. For example, passing PORT_INDEX, I know
>> exactly what object to reach, according to this PORT_INDEX. Why to
>> iterate over all of them and try the filter? Does not make sense to me.
>> 
>> Maybe we are each understanding this feature differently. This is about
>> passing keys which index the objects. It is always devlink handle,
>> sometimes port index and I see another example in shared buffer index.
>> That's about it. Basically user passes partial tuple of indexes.
>> Example:
>> devlink port show
>> the key is: bus_name/dev_name/port_index
>> user passes bus_name/dev_name, this is the selector, a partial key.
>> 
>> The sophisticated filtering is not a focus of this patchset. User can do
>> it putting bpf filter on the netlink socket.
>
>Okay, I was trying to be helpful, I don't want to argue for
>a particular implementation. IMO what's posted is too ugly
>to be merged, please restructure it.

Ugly in which sense? What exactly needs to be restructured?
diff mbox series

Patch

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)