Skip to content

Commit c8e1da0

Browse files
Eran Ben Elishadavem330
authored andcommitted
devlink: Add health report functionality
Upon error discover, every driver can report it to the devlink health mechanism via devlink_health_report function, using the appropriate reporter registered to it. Driver can pass error specific context which will be delivered to it as part of the dump / recovery callbacks. Once an error is reported, devlink health will do 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 stored at the reporter instance (as long as there is no other dump which is already stored) * Auto recovery attempt is being done. Depends on: - Auto Recovery configuration - Grace period vs. Time since last recover Signed-off-by: Eran Ben Elisha <eranbe@mellanox.com> Reviewed-by: Moshe Shemesh <moshe@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a0bdcc5 commit c8e1da0

3 files changed

Lines changed: 193 additions & 0 deletions

File tree

‎include/net/devlink.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
704704

705705
void *
706706
devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
707+
int devlink_health_report(struct devlink_health_reporter *reporter,
708+
const char *msg, void *priv_ctx);
707709

708710
#else
709711

@@ -1173,6 +1175,13 @@ devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
11731175
{
11741176
return NULL;
11751177
}
1178+
1179+
static inline int
1180+
devlink_health_report(struct devlink_health_reporter *reporter,
1181+
const char *msg, void *priv_ctx)
1182+
{
1183+
return 0;
1184+
}
11761185
#endif
11771186

11781187
#if IS_REACHABLE(CONFIG_NET_DEVLINK)

‎include/trace/events/devlink.h‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,71 @@ TRACE_EVENT(devlink_hwerr,
7575
__get_str(driver_name), __entry->err, __get_str(msg))
7676
);
7777

78+
/*
79+
* Tracepoint for devlink health message:
80+
*/
81+
TRACE_EVENT(devlink_health_report,
82+
TP_PROTO(const struct devlink *devlink, const char *reporter_name,
83+
const char *msg),
84+
85+
TP_ARGS(devlink, reporter_name, msg),
86+
87+
TP_STRUCT__entry(
88+
__string(bus_name, devlink->dev->bus->name)
89+
__string(dev_name, dev_name(devlink->dev))
90+
__string(driver_name, devlink->dev->driver->name)
91+
__string(reporter_name, msg)
92+
__string(msg, msg)
93+
),
94+
95+
TP_fast_assign(
96+
__assign_str(bus_name, devlink->dev->bus->name);
97+
__assign_str(dev_name, dev_name(devlink->dev));
98+
__assign_str(driver_name, devlink->dev->driver->name);
99+
__assign_str(reporter_name, reporter_name);
100+
__assign_str(msg, msg);
101+
),
102+
103+
TP_printk("bus_name=%s dev_name=%s driver_name=%s reporter_name=%s: %s",
104+
__get_str(bus_name), __get_str(dev_name),
105+
__get_str(driver_name), __get_str(reporter_name),
106+
__get_str(msg))
107+
);
108+
109+
/*
110+
* Tracepoint for devlink health recover aborted message:
111+
*/
112+
TRACE_EVENT(devlink_health_recover_aborted,
113+
TP_PROTO(const struct devlink *devlink, const char *reporter_name,
114+
bool health_state, u64 time_since_last_recover),
115+
116+
TP_ARGS(devlink, reporter_name, health_state, time_since_last_recover),
117+
118+
TP_STRUCT__entry(
119+
__string(bus_name, devlink->dev->bus->name)
120+
__string(dev_name, dev_name(devlink->dev))
121+
__string(driver_name, devlink->dev->driver->name)
122+
__string(reporter_name, reporter_name)
123+
__field(bool, health_state)
124+
__field(u64, time_since_last_recover)
125+
),
126+
127+
TP_fast_assign(
128+
__assign_str(bus_name, devlink->dev->bus->name);
129+
__assign_str(dev_name, dev_name(devlink->dev));
130+
__assign_str(driver_name, devlink->dev->driver->name);
131+
__assign_str(reporter_name, reporter_name);
132+
__entry->health_state = health_state;
133+
__entry->time_since_last_recover = time_since_last_recover;
134+
),
135+
136+
TP_printk("bus_name=%s dev_name=%s driver_name=%s reporter_name=%s: health_state=%d time_since_last_recover=%llu recover aborted",
137+
__get_str(bus_name), __get_str(dev_name),
138+
__get_str(driver_name), __get_str(reporter_name),
139+
__entry->health_state,
140+
__entry->time_since_last_recover)
141+
);
142+
78143
#endif /* _TRACE_DEVLINK_H */
79144

80145
/* This part must be outside protection */

‎net/core/devlink.c‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,9 +4367,20 @@ struct devlink_health_reporter {
43674367
void *priv;
43684368
const struct devlink_health_reporter_ops *ops;
43694369
struct devlink *devlink;
4370+
struct devlink_fmsg *dump_fmsg;
4371+
struct mutex dump_lock; /* lock parallel read/write from dump buffers */
43704372
u64 graceful_period;
43714373
bool auto_recover;
43724374
u8 health_state;
4375+
u64 dump_ts;
4376+
u64 error_count;
4377+
u64 recovery_count;
4378+
u64 last_recovery_ts;
4379+
};
4380+
4381+
enum devlink_health_reporter_state {
4382+
DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
4383+
DEVLINK_HEALTH_REPORTER_STATE_ERROR,
43734384
};
43744385

43754386
void *
@@ -4431,6 +4442,7 @@ devlink_health_reporter_create(struct devlink *devlink,
44314442
reporter->devlink = devlink;
44324443
reporter->graceful_period = graceful_period;
44334444
reporter->auto_recover = auto_recover;
4445+
mutex_init(&reporter->dump_lock);
44344446
list_add_tail(&reporter->list, &devlink->reporter_list);
44354447
unlock:
44364448
mutex_unlock(&devlink->lock);
@@ -4449,10 +4461,117 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter)
44494461
mutex_lock(&reporter->devlink->lock);
44504462
list_del(&reporter->list);
44514463
mutex_unlock(&reporter->devlink->lock);
4464+
if (reporter->dump_fmsg)
4465+
devlink_fmsg_free(reporter->dump_fmsg);
44524466
kfree(reporter);
44534467
}
44544468
EXPORT_SYMBOL_GPL(devlink_health_reporter_destroy);
44554469

4470+
static int
4471+
devlink_health_reporter_recover(struct devlink_health_reporter *reporter,
4472+
void *priv_ctx)
4473+
{
4474+
int err;
4475+
4476+
if (!reporter->ops->recover)
4477+
return -EOPNOTSUPP;
4478+
4479+
err = reporter->ops->recover(reporter, priv_ctx);
4480+
if (err)
4481+
return err;
4482+
4483+
reporter->recovery_count++;
4484+
reporter->health_state = DEVLINK_HEALTH_REPORTER_STATE_HEALTHY;
4485+
reporter->last_recovery_ts = jiffies;
4486+
4487+
return 0;
4488+
}
4489+
4490+
static void
4491+
devlink_health_dump_clear(struct devlink_health_reporter *reporter)
4492+
{
4493+
if (!reporter->dump_fmsg)
4494+
return;
4495+
devlink_fmsg_free(reporter->dump_fmsg);
4496+
reporter->dump_fmsg = NULL;
4497+
}
4498+
4499+
static int devlink_health_do_dump(struct devlink_health_reporter *reporter,
4500+
void *priv_ctx)
4501+
{
4502+
int err;
4503+
4504+
if (!reporter->ops->dump)
4505+
return 0;
4506+
4507+
if (reporter->dump_fmsg)
4508+
return 0;
4509+
4510+
reporter->dump_fmsg = devlink_fmsg_alloc();
4511+
if (!reporter->dump_fmsg) {
4512+
err = -ENOMEM;
4513+
return err;
4514+
}
4515+
4516+
err = devlink_fmsg_obj_nest_start(reporter->dump_fmsg);
4517+
if (err)
4518+
goto dump_err;
4519+
4520+
err = reporter->ops->dump(reporter, reporter->dump_fmsg,
4521+
priv_ctx);
4522+
if (err)
4523+
goto dump_err;
4524+
4525+
err = devlink_fmsg_obj_nest_end(reporter->dump_fmsg);
4526+
if (err)
4527+
goto dump_err;
4528+
4529+
reporter->dump_ts = jiffies;
4530+
4531+
return 0;
4532+
4533+
dump_err:
4534+
devlink_health_dump_clear(reporter);
4535+
return err;
4536+
}
4537+
4538+
int devlink_health_report(struct devlink_health_reporter *reporter,
4539+
const char *msg, void *priv_ctx)
4540+
{
4541+
struct devlink *devlink = reporter->devlink;
4542+
4543+
/* write a log message of the current error */
4544+
WARN_ON(!msg);
4545+
trace_devlink_health_report(devlink, reporter->ops->name, msg);
4546+
reporter->error_count++;
4547+
4548+
/* abort if the previous error wasn't recovered */
4549+
if (reporter->auto_recover &&
4550+
(reporter->health_state != DEVLINK_HEALTH_REPORTER_STATE_HEALTHY ||
4551+
jiffies - reporter->last_recovery_ts <
4552+
msecs_to_jiffies(reporter->graceful_period))) {
4553+
trace_devlink_health_recover_aborted(devlink,
4554+
reporter->ops->name,
4555+
reporter->health_state,
4556+
jiffies -
4557+
reporter->last_recovery_ts);
4558+
return -ECANCELED;
4559+
}
4560+
4561+
reporter->health_state = DEVLINK_HEALTH_REPORTER_STATE_ERROR;
4562+
4563+
mutex_lock(&reporter->dump_lock);
4564+
/* store current dump of current error, for later analysis */
4565+
devlink_health_do_dump(reporter, priv_ctx);
4566+
mutex_unlock(&reporter->dump_lock);
4567+
4568+
if (reporter->auto_recover)
4569+
return devlink_health_reporter_recover(reporter, priv_ctx);
4570+
4571+
return 0;
4572+
}
4573+
EXPORT_SYMBOL_GPL(devlink_health_report);
4574+
44564575
static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
44574576
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
44584577
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },

0 commit comments

Comments
 (0)