Messages in this thread Patch in this message | | | From | Łukasz Bartosik <> | Subject | [PATCH v4 11/39] dyndbg: don't close trace instance when in use | Date | Sun, 11 Feb 2024 00:49:41 +0100 |
| |
Don't allow trace instance to be closed when it is still being used by at least one callsite.
Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org> --- lib/dynamic_debug.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index d0d1057911e8..6668f265f2c3 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -81,6 +81,7 @@ struct flag_settings { struct dd_private_tracebuf { const char *name; struct trace_array *arr; + int use_cnt; }; /* @@ -279,6 +280,7 @@ static int handle_trace_open_cmd(const char *arg) goto end; } + buf->use_cnt = 0; set_bit(idx, trc_tbl.bmap); v3pr_info("opened trace instance idx=%d, name=%s\n", idx, arg); end: @@ -301,6 +303,14 @@ static int handle_trace_close_cmd(const char *arg) buf = &trc_tbl.buf[idx]; + WARN_ON(buf->use_cnt < 0); + if (buf->use_cnt) { + pr_err("trace instance is being used name=%s, use_cnt=%d\n", + buf->name, buf->use_cnt); + ret = -EBUSY; + goto end; + } + trace_array_put(buf->arr); /* * don't destroy trace instance but let user do it manually @@ -321,6 +331,22 @@ static int handle_trace_close_cmd(const char *arg) return ret; } +static +void update_tr_dst(const struct _ddebug *desc, const struct dd_ctrl *nctrl) +{ + int odst = get_trace_dst(desc); + int ndst = nctrl->trace_dst; + + if (odst == ndst) + return; + + if (odst) + trc_tbl.buf[odst].use_cnt--; + + if (ndst) + trc_tbl.buf[ndst].use_cnt++; +} + static int ddebug_parse_cmd(char *words[], int nwords) { if (nwords != 1) @@ -447,6 +473,7 @@ static int ddebug_change(const struct ddebug_query *query, dt->mod_name, dp->function, ddebug_describe_flags(get_flags(dp), &fbuf), ddebug_describe_flags(nctrl.flags, &nbuf)); + update_tr_dst(dp, &nctrl); set_ctrl(dp, &nctrl); } } @@ -1628,6 +1655,14 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module) static void ddebug_table_free(struct ddebug_table *dt) { + int dst, i; + + for (i = 0; i < dt->num_ddebugs; i++) { + dst = get_trace_dst(&dt->ddebugs[i]); + if (dst) + trc_tbl.buf[dst].use_cnt--; + } + list_del_init(&dt->link); kfree(dt); } -- 2.43.0.687.g38aa6559b0-goog
| |