Skip to content

Commit

Permalink
pstore: Do not leave timer disabled for next backend
Browse files Browse the repository at this point in the history
The pstore.update_ms value was being disabled during pstore_unregister(),
which would cause any prior value to go unnoticed on the next
pstore_register(). Instead, just let del_timer() stop the timer, which
was always sufficient. This additionally refactors the timer reset code
and allows the timer to be enabled if the module parameter is changed
away from the default.

Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed May 30, 2020
1 parent 27e5041 commit 78c83c8
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions fs/pstore/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int pstore_update_ms = -1;
module_param_named(update_ms, pstore_update_ms, int, 0600);
MODULE_PARM_DESC(update_ms, "milliseconds before pstore updates its content "
"(default is -1, which means runtime updates are disabled; "
"enabling this option is not safe, it may lead to further "
"enabling this option may not be safe; it may lead to further "
"corruption on Oopses)");

/* Names should be in the same order as the enum pstore_type_id */
Expand Down Expand Up @@ -150,6 +150,14 @@ static const char *get_reason_str(enum kmsg_dump_reason reason)
}
}

static void pstore_timer_kick(void)
{
if (pstore_update_ms < 0)
return;

mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
}

/*
* Should pstore_dump() wait for a concurrent pstore_dump()? If
* not, the current pstore_dump() will report a failure to dump
Expand Down Expand Up @@ -460,8 +468,10 @@ static void pstore_dump(struct kmsg_dumper *dumper,
}

ret = psinfo->write(&record);
if (ret == 0 && reason == KMSG_DUMP_OOPS)
if (ret == 0 && reason == KMSG_DUMP_OOPS) {
pstore_new_entry = 1;
pstore_timer_kick();
}

total += record.size;
part++;
Expand Down Expand Up @@ -604,11 +614,7 @@ int pstore_register(struct pstore_info *psi)
pstore_register_pmsg();

/* Start watching for new records, if desired. */
if (pstore_update_ms >= 0) {
pstore_timer.expires = jiffies +
msecs_to_jiffies(pstore_update_ms);
add_timer(&pstore_timer);
}
pstore_timer_kick();

/*
* Update the module parameter backend, so it is visible
Expand Down Expand Up @@ -637,11 +643,7 @@ void pstore_unregister(struct pstore_info *psi)
return;
}

/* Stop timer and make sure all work has finished. */
pstore_update_ms = -1;
del_timer_sync(&pstore_timer);
flush_work(&pstore_work);

/* Unregister all callbacks. */
if (psi->flags & PSTORE_FLAGS_PMSG)
pstore_unregister_pmsg();
if (psi->flags & PSTORE_FLAGS_FTRACE)
Expand All @@ -651,6 +653,10 @@ void pstore_unregister(struct pstore_info *psi)
if (psi->flags & PSTORE_FLAGS_DMESG)
pstore_unregister_kmsg();

/* Stop timer and make sure all work has finished. */
del_timer_sync(&pstore_timer);
flush_work(&pstore_work);

free_buf_for_compression();

psinfo = NULL;
Expand Down Expand Up @@ -792,9 +798,7 @@ static void pstore_timefunc(struct timer_list *unused)
schedule_work(&pstore_work);
}

if (pstore_update_ms >= 0)
mod_timer(&pstore_timer,
jiffies + msecs_to_jiffies(pstore_update_ms));
pstore_timer_kick();
}

static void __init pstore_choose_compression(void)
Expand Down

0 comments on commit 78c83c8

Please sign in to comment.