Skip to contentSkip to conversation

devlink: cleanups and move devlink health functionality to separate file

PATCH Applied Moshe Shemesh 3 participants 14 messages Feb 14, 2023 – Feb 16, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover devlink: cleanups and move devlink health functionality to separate file

This patchset moves devlink health callbacks, helpers and related code from leftover.c to new file health.c. About 1.3K LoC are moved by this patchset, covering all devlink health functionality.

In addition this patchset includes a couple of small cleanups in devlink health code and documentation update.

---
v1->v2:
- Fix kdoc indentation and make reporter create/destroy kdoc more clear
- Add note on the two cleanup patches that the bug is harmless
- Drop patch 4 ("devlink: health: Don't try to add trace with NULL msg")
- Add patch "devlink: Fix TP_STRUCT_entry in trace of devlink health report"

Moshe Shemesh (10):
devlink: Split out health reporter create code
devlink: health: Fix nla_nest_end in error flow
devlink: Move devlink health get and set code to health file
devlink: Move devlink health report and recover to health file
devlink: Move devlink fmsg and health diagnose to health file
devlink: Move devlink health dump to health file
devlink: Move devlink health test to health file
devlink: Move health common function to health file
devlink: Update devlink health documentation
devlink: Fix TP_STRUCT_entry in trace of devlink health report

 .../networking/devlink/devlink-health.rst     |   23 +-
 include/trace/events/devlink.h                |    2 +-
 net/devlink/Makefile                          |    2 +-
 net/devlink/devl_internal.h                   |   16 +
 net/devlink/health.c                          | 1333 +++++++++++++++++
 net/devlink/leftover.c                        | 1330 +---------------
 6 files changed, 1374 insertions(+), 1332 deletions(-)
 create mode 100644 net/devlink/health.c
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 1/10 devlink: Split out health reporter create code

Move devlink health reporter create/destroy and related dev code to new file health.c. This file shall include all callbacks and functionality that are related to devlink health.

In addition, fix kdoc indentation and make reporter create/destroy kdoc more clear. No functional change in this patch.

---
 net/devlink/Makefile        |   2 +-
 net/devlink/devl_internal.h |  28 +++++
 net/devlink/health.c        | 196 +++++++++++++++++++++++++++++++++
 net/devlink/leftover.c      | 209 +-----------------------------------
 4 files changed, 226 insertions(+), 209 deletions(-)
 create mode 100644 net/devlink/health.c
net/devlink/Makefile +1 -1
index daad4521c61e..ef91a76646a3 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 
-obj-y := leftover.o core.o netlink.o dev.o
+obj-y := leftover.o core.o netlink.o dev.o health.o
net/devlink/devl_internal.h +28 -0
index 2f4820e40d27..49fe9e2dae34 100644
@@ -198,6 +198,34 @@ int devlink_resources_validate(struct devlink *devlink,
 			       struct devlink_resource *resource,
 			       struct genl_info *info);
 
+/* Health */
+struct devlink_health_reporter {
+	struct list_head list;
+	void *priv;
+	const struct devlink_health_reporter_ops *ops;
+	struct devlink *devlink;
+	struct devlink_port *devlink_port;
+	struct devlink_fmsg *dump_fmsg;
+	struct mutex dump_lock; /* lock parallel read/write from dump buffers */
+	u64 graceful_period;
+	bool auto_recover;
+	bool auto_dump;
+	u8 health_state;
+	u64 dump_ts;
+	u64 dump_real_ts;
+	u64 error_count;
+	u64 recovery_count;
+	u64 last_recovery_ts;
+};
+
+struct devlink_health_reporter *
+devlink_health_reporter_find_by_name(struct devlink *devlink,
+				     const char *reporter_name);
+struct devlink_health_reporter *
+devlink_port_health_reporter_find_by_name(struct devlink_port *devlink_port,
+					  const char *reporter_name);
+void devlink_fmsg_free(struct devlink_fmsg *fmsg);
+
 /* Line cards */
 struct devlink_linecard;
 
net/devlink/health.c new file +196 -0

196 lines not on this page · raw message

net/devlink/leftover.c +1 -208

221 lines not on this page · raw message

Signature · 1 line
2.27.0
maintainer Reviewed-by on v2 1/10
#2 lore raw

Re: [PATCH net-next v2 01/10] devlink: Split out health reporter create code

Quoted 8 lines · Tue, Feb 14, 2023 at 05:37:57PM CET, [email protected] wrote:

Move devlink health reporter create/destroy and related dev code to new file health.c. This file shall include all callbacks and functionality that are related to devlink health.

In addition, fix kdoc indentation and make reporter create/destroy kdoc more clear. No functional change in this patch.

#3 lore raw

PATCH v2 2/10 devlink: health: Fix nla_nest_end in error flow

In reply to Moshe Shemesh

devlink_nl_health_reporter_fill() error flow calls nla_nest_end(). Fix it to call nla_nest_cancel() instead.

Note the bug is harmless as genlmsg_cancel() cancel the entire message, so no fixes tag added.

---
 net/devlink/leftover.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/devlink/leftover.c +1 -1
index cfd1b90a0fc1..90f95f06de28 100644
@@ -6028,7 +6028,7 @@ devlink_nl_health_reporter_fill(struct sk_buff *msg,
 	return 0;
 
 reporter_nest_cancel:
-	nla_nest_end(msg, reporter_attr);
+	nla_nest_cancel(msg, reporter_attr);
 genlmsg_cancel:
 	genlmsg_cancel(msg, hdr);
 	return -EMSGSIZE;
Signature · 1 line
2.27.0
#4 lore raw

PATCH v2 3/10 devlink: Move devlink health get and set code to health file

In reply to Moshe Shemesh

Move devlink health get and set callbacks and related code from leftover.c to health.c. No functional change in this patch.

---
 net/devlink/devl_internal.h |  18 +++
 net/devlink/health.c        | 214 +++++++++++++++++++++++++++++++++++
 net/devlink/leftover.c      | 219 +-----------------------------------
 3 files changed, 234 insertions(+), 217 deletions(-)
net/devlink/devl_internal.h +18 -0
index 49fe9e2dae34..085f80b5feb8 100644
@@ -176,6 +176,8 @@ int devlink_port_netdevice_event(struct notifier_block *nb,
 
 struct devlink_port *
 devlink_port_get_from_info(struct devlink *devlink, struct genl_info *info);
+struct devlink_port *devlink_port_get_from_attrs(struct devlink *devlink,
+						 struct nlattr **attrs);
 
 /* Reload */
 bool devlink_reload_actions_valid(const struct devlink_ops *ops);
@@ -224,6 +226,18 @@ devlink_health_reporter_find_by_name(struct devlink *devlink,
 struct devlink_health_reporter *
 devlink_port_health_reporter_find_by_name(struct devlink_port *devlink_port,
 					  const char *reporter_name);
+struct devlink_health_reporter *
+devlink_health_reporter_get_from_attrs(struct devlink *devlink,
+				       struct nlattr **attrs);
+struct devlink_health_reporter *
+devlink_health_reporter_get_from_info(struct devlink *devlink,
+				      struct genl_info *info);
+int
+devlink_nl_health_reporter_fill(struct sk_buff *msg,
+				struct devlink_health_reporter *reporter,
+				enum devlink_command cmd, u32 portid,
+				u32 seq, int flags);
+
 void devlink_fmsg_free(struct devlink_fmsg *fmsg);
 
 /* Line cards */
@@ -249,3 +263,7 @@ int devlink_nl_cmd_info_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_flash_update(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb, struct genl_info *info);
 int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info);
+int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
+					    struct genl_info *info);
+int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
+					    struct genl_info *info);
net/devlink/health.c +214 -0

217 lines not on this page · raw message

net/devlink/leftover.c +2 -217

243 lines not on this page · raw message

Signature · 1 line
2.27.0
#5 lore raw

PATCH v2 4/10 devlink: Move devlink health report and recover to health file

In reply to Moshe Shemesh

Move devlink health report helper and recover callback and related code from leftover.c to health.c. No functional change in this patch.

---
 net/devlink/devl_internal.h |   5 ++
 net/devlink/health.c        | 136 ++++++++++++++++++++++++++++++++++
 net/devlink/leftover.c      | 141 +-----------------------------------
 3 files changed, 144 insertions(+), 138 deletions(-)
net/devlink/devl_internal.h +5 -0
index 085f80b5feb8..d1a901cb5900 100644
@@ -237,6 +237,9 @@ devlink_nl_health_reporter_fill(struct sk_buff *msg,
 				struct devlink_health_reporter *reporter,
 				enum devlink_command cmd, u32 portid,
 				u32 seq, int flags);
+int devlink_health_do_dump(struct devlink_health_reporter *reporter,
+			   void *priv_ctx,
+			   struct netlink_ext_ack *extack);
 
 void devlink_fmsg_free(struct devlink_fmsg *fmsg);
 
@@ -267,3 +270,5 @@ int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
 					    struct genl_info *info);
 int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
 					    struct genl_info *info);
+int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
+						struct genl_info *info);
net/devlink/health.c +136 -0

145 lines not on this page · raw message

net/devlink/leftover.c +3 -138

165 lines not on this page · raw message

Signature · 1 line
2.27.0
#6 lore raw

PATCH v2 5/10 devlink: Move devlink fmsg and health diagnose to health file

In reply to Moshe Shemesh

Devlink fmsg (formatted message) is used by devlink health diagnose, dump and drivers which support these devlink health callbacks. Therefore, move devlink fmsg helpers and related code to file health.c. Move devlink health diagnose to file health.c. No functional change in this patch.

---
 net/devlink/devl_internal.h |   6 +
 net/devlink/health.c        | 630 ++++++++++++++++++++++++++++++++++++
 net/devlink/leftover.c      | 630 ------------------------------------
 3 files changed, 636 insertions(+), 630 deletions(-)
net/devlink/devl_internal.h +6 -0
index d1a901cb5900..a4b96f8a0ab4 100644
@@ -240,7 +240,11 @@ devlink_nl_health_reporter_fill(struct sk_buff *msg,
 int devlink_health_do_dump(struct devlink_health_reporter *reporter,
 			   void *priv_ctx,
 			   struct netlink_ext_ack *extack);
+int devlink_fmsg_dumpit(struct devlink_fmsg *fmsg, struct sk_buff *skb,
+			struct netlink_callback *cb,
+			enum devlink_command cmd);
 
+struct devlink_fmsg *devlink_fmsg_alloc(void);
 void devlink_fmsg_free(struct devlink_fmsg *fmsg);
 
 /* Line cards */
@@ -272,3 +276,5 @@ int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
 					    struct genl_info *info);
 int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
 						struct genl_info *info);
+int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
+						 struct genl_info *info);
net/devlink/health.c +630 -0

639 lines not on this page · raw message

net/devlink/leftover.c +0 -630

642 lines not on this page · raw message

Signature · 1 line
2.27.0
#7 lore raw

PATCH v2 6/10 devlink: Move devlink health dump to health file

In reply to Moshe Shemesh

Move devlink health report dump callbacks and related code from leftover.c to health.c. No functional change in this patch.

---
 net/devlink/devl_internal.h |   4 ++
 net/devlink/health.c        | 122 +++++++++++++++++++++++++++++++++++
 net/devlink/leftover.c      | 123 ------------------------------------
 3 files changed, 126 insertions(+), 123 deletions(-)
net/devlink/devl_internal.h +4 -0
index a4b96f8a0ab4..ae7229742d66 100644
@@ -278,3 +278,7 @@ int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,
 						struct genl_info *info);
 int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb,
 						 struct genl_info *info);
+int devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb,
+						   struct netlink_callback *cb);
+int devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
+						   struct genl_info *info);
net/devlink/health.c +122 -0

137 lines not on this page · raw message

net/devlink/leftover.c +0 -123

129 lines not on this page · raw message

Signature · 1 line
2.27.0
#8 lore raw

PATCH v2 7/10 devlink: Move devlink health test to health file

In reply to Moshe Shemesh

Move devlink health report test callback from leftover.c to health.c. No functional change in this patch.

---
 net/devlink/devl_internal.h |  2 ++
 net/devlink/health.c        | 16 ++++++++++++++++
 net/devlink/leftover.c      | 16 ----------------
 3 files changed, 18 insertions(+), 16 deletions(-)
net/devlink/devl_internal.h +2 -0
index ae7229742d66..211f7ea38d6a 100644
@@ -282,3 +282,5 @@ int devlink_nl_cmd_health_reporter_dump_get_dumpit(struct sk_buff *skb,
 						   struct netlink_callback *cb);
 int devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
 						   struct genl_info *info);
+int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb,
+					     struct genl_info *info);
net/devlink/health.c +16 -0
index 6991b9405f4f..38ad890bb947 100644
@@ -1296,3 +1296,19 @@ int devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb,
 	mutex_unlock(&reporter->dump_lock);
 	return 0;
 }
+
+int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb,
+					     struct genl_info *info)
+{
+	struct devlink *devlink = info->user_ptr[0];
+	struct devlink_health_reporter *reporter;
+
+	reporter = devlink_health_reporter_get_from_info(devlink, info);
+	if (!reporter)
+		return -EINVAL;
+
+	if (!reporter->ops->test)
+		return -EOPNOTSUPP;
+
+	return reporter->ops->test(reporter, info->extack);
+}
net/devlink/leftover.c +0 -16
index 55be664d14ad..dffca2f9bfa7 100644
@@ -5372,22 +5372,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	return err;
 }
 
-static int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb,
-						    struct genl_info *info)
-{
-	struct devlink *devlink = info->user_ptr[0];
-	struct devlink_health_reporter *reporter;
-
-	reporter = devlink_health_reporter_get_from_info(devlink, info);
-	if (!reporter)
-		return -EINVAL;
-
-	if (!reporter->ops->test)
-		return -EOPNOTSUPP;
-
-	return reporter->ops->test(reporter, info->extack);
-}
-
 struct devlink_stats {
 	u64_stats_t rx_bytes;
 	u64_stats_t rx_packets;
Signature · 1 line
2.27.0
#9 lore raw

PATCH v2 8/10 devlink: Move health common function to health file

In reply to Moshe Shemesh

Now that all devlink health callbacks and related code are in file health.c move common health functions and devlink_health_reporter struct to be local in health.c file.

---
 net/devlink/devl_internal.h | 47 -------------------------------------
 net/devlink/health.c        | 45 +++++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 60 deletions(-)
net/devlink/devl_internal.h +0 -47
index 211f7ea38d6a..e133f423294a 100644
@@ -200,53 +200,6 @@ int devlink_resources_validate(struct devlink *devlink,
 			       struct devlink_resource *resource,
 			       struct genl_info *info);
 
-/* Health */
-struct devlink_health_reporter {
-	struct list_head list;
-	void *priv;
-	const struct devlink_health_reporter_ops *ops;
-	struct devlink *devlink;
-	struct devlink_port *devlink_port;
-	struct devlink_fmsg *dump_fmsg;
-	struct mutex dump_lock; /* lock parallel read/write from dump buffers */
-	u64 graceful_period;
-	bool auto_recover;
-	bool auto_dump;
-	u8 health_state;
-	u64 dump_ts;
-	u64 dump_real_ts;
-	u64 error_count;
-	u64 recovery_count;
-	u64 last_recovery_ts;
-};
-
-struct devlink_health_reporter *
-devlink_health_reporter_find_by_name(struct devlink *devlink,
-				     const char *reporter_name);
-struct devlink_health_reporter *
-devlink_port_health_reporter_find_by_name(struct devlink_port *devlink_port,
-					  const char *reporter_name);
-struct devlink_health_reporter *
-devlink_health_reporter_get_from_attrs(struct devlink *devlink,
-				       struct nlattr **attrs);
-struct devlink_health_reporter *
-devlink_health_reporter_get_from_info(struct devlink *devlink,
-				      struct genl_info *info);
-int
-devlink_nl_health_reporter_fill(struct sk_buff *msg,
-				struct devlink_health_reporter *reporter,
-				enum devlink_command cmd, u32 portid,
-				u32 seq, int flags);
-int devlink_health_do_dump(struct devlink_health_reporter *reporter,
-			   void *priv_ctx,
-			   struct netlink_ext_ack *extack);
-int devlink_fmsg_dumpit(struct devlink_fmsg *fmsg, struct sk_buff *skb,
-			struct netlink_callback *cb,
-			enum devlink_command cmd);
-
-struct devlink_fmsg *devlink_fmsg_alloc(void);
-void devlink_fmsg_free(struct devlink_fmsg *fmsg);
-
 /* Line cards */
 struct devlink_linecard;
 
net/devlink/health.c +32 -13

105 lines not on this page · raw message

Signature · 1 line
2.27.0
#10 lore raw

PATCH v2 9/10 devlink: Update devlink health documentation

In reply to Moshe Shemesh

Update devlink-health.rst file:
- Add devlink formatted message (fmsg) API documentation.
- Add auto-dump as a condition to do dump once error reported.
- Expand OOB to clarify this acronym.

---
 .../networking/devlink/devlink-health.rst     | 23 +++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
Documentation/networking/devlink/devlink-health.rst +21 -2
index e37f77734b5b..e0b8cfed610a 100644
@@ -33,7 +33,7 @@ Device driver can provide specific callbacks for each "health reporter", e.g.:
   * Recovery procedures
   * Diagnostics procedures
   * Object dump procedures
-  * OOB initial parameters
+  * Out Of Box initial parameters
 
 Different parts of the driver can register different types of health reporters
 with different handlers.
@@ -46,12 +46,31 @@ Once an error is reported, devlink health will perform the following actions:
   * A log is being send to the kernel trace events buffer
   * Health status and statistics are being updated for the reporter instance
   * Object dump is being taken and saved at the reporter instance (as long as
-    there is no other dump which is already stored)
+    auto-dump is set and there is no other dump which is already stored)
   * Auto recovery attempt is being done. Depends on:
 
     - Auto-recovery configuration
     - Grace period vs. time passed since last recover
 
+Devlink formatted message
+=========================
+
+To handle devlink health diagnose and health dump requests, devlink creates a
+formatted message structure ``devlink_fmsg`` and send it to the driver's callback
+to fill the data in using the devlink fmsg API.
+
+Devlink fmsg is a mechanism to pass descriptors between drivers and devlink, in
+json-like format. The API allows the driver to add nested attributes such as
+object, object pair and value array, in addition to attributes such as name and
+value.
+
+Driver should use this API to fill the fmsg context in a format which will be
+translated by the devlink to the netlink message later. When it needs to send
+the data using SKBs to the netlink layer, it fragments the data between
+different SKBs. In order to do this fragmentation, it uses virtual nests
+attributes, to avoid actual nesting use which cannot be divided between
+different SKBs.
+
 User Interface
 ==============
 
Signature · 1 line
2.27.0
#11 lore raw

PATCH v2 10/10 devlink: Fix TP_STRUCT_entry in trace of devlink health report

In reply to Moshe Shemesh

Fix a bug in trace point definition for devlink health report, as TP_STRUCT_entry of reporter_name should get reporter_name and not msg.

Note no fixes tag as this is a harmless bug as both reporter_name and msg are strings and TP_fast_assign for this entry is correct.

---
 include/trace/events/devlink.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/devlink.h +1 -1
index 24969184c534..77ff7cfc6049 100644
@@ -88,7 +88,7 @@ TRACE_EVENT(devlink_health_report,
 		__string(bus_name, devlink_to_dev(devlink)->bus->name)
 		__string(dev_name, dev_name(devlink_to_dev(devlink)))
 		__string(driver_name, devlink_to_dev(devlink)->driver->name)
-		__string(reporter_name, msg)
+		__string(reporter_name, reporter_name)
 		__string(msg, msg)
 	),
 
Signature · 1 line
2.27.0
maintainer Reviewed-by on v2 10/10
#12 lore raw

Re: [PATCH net-next v2 10/10] devlink: Fix TP_STRUCT_entry in trace of devlink health report

Quoted 7 lines · Tue, Feb 14, 2023 at 05:38:06PM CET, [email protected] wrote:

Fix a bug in trace point definition for devlink health report, as TP_STRUCT_entry of reporter_name should get reporter_name and not msg.

Note no fixes tag as this is a harmless bug as both reporter_name and msg are strings and TP_fast_assign for this entry is correct.

#13 lore raw
In reply to Moshe Shemesh
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 14 Feb 2023 18:37:56 +0200 you wrote:

This patchset moves devlink health callbacks, helpers and related code from leftover.c to new file health.c. About 1.3K LoC are moved by this patchset, covering all devlink health functionality.

In addition this patchset includes a couple of small cleanups in devlink health code and documentation update.

[...]

Here is the summary with links:
- [net-next,v2,01/10] devlink: Split out health reporter create code

    https://git.kernel.org/netdev/net-next/c/b4740e3a8137
  - [net-next,v2,02/10] devlink: health: Fix nla_nest_end in error flow
    https://git.kernel.org/netdev/net-next/c/bfd4e6a5dbbc
  - [net-next,v2,03/10] devlink: Move devlink health get and set code to health file
    https://git.kernel.org/netdev/net-next/c/db6b5f3ec400
  - [net-next,v2,04/10] devlink: Move devlink health report and recover to health file
    https://git.kernel.org/netdev/net-next/c/55b9b2496852
  - [net-next,v2,05/10] devlink: Move devlink fmsg and health diagnose to health file
    https://git.kernel.org/netdev/net-next/c/a929df7fd9c6
  - [net-next,v2,06/10] devlink: Move devlink health dump to health file
    https://git.kernel.org/netdev/net-next/c/7004c6c45761
  - [net-next,v2,07/10] devlink: Move devlink health test to health file
    https://git.kernel.org/netdev/net-next/c/c9311ee13f0e
  - [net-next,v2,08/10] devlink: Move health common function to health file
    https://git.kernel.org/netdev/net-next/c/12af29e7790a
  - [net-next,v2,09/10] devlink: Update devlink health documentation
    https://git.kernel.org/netdev/net-next/c/c745cfb27ae3
  - [net-next,v2,10/10] devlink: Fix TP_STRUCT_entry in trace of devlink health report
    https://git.kernel.org/netdev/net-next/c/d0ab772c1f15

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html