Re: [PATCH v2] pstore: Don't use semaphores in always-atomic-context code
From: Kees Cook
Date: Wed Feb 23 2022 - 02:50:01 EST
On February 18, 2022 10:19:50 AM PST, Jann Horn <jannh@xxxxxxxxxx> wrote:
>pstore_dump() is *always* invoked in atomic context (nowadays in an RCU
>read-side critical section, before that under a spinlock).
>It doesn't make sense to try to use semaphores here.
Ah, very nice. Thanks for the analysis!
>[...]
>-static bool pstore_cannot_wait(enum kmsg_dump_reason reason)
>+bool pstore_cannot_block_path(enum kmsg_dump_reason reason)
Why the rename, extern, and EXPORT? This appears to still only have the same single caller?
> [...]
>- pr_err("dump skipped in %s path: may corrupt error record\n",
>- in_nmi() ? "NMI" : why);
>- return;
>- }
>- if (down_interruptible(&psinfo->buf_lock)) {
>- pr_err("could not grab semaphore?!\n");
>+ if (pstore_cannot_block_path(reason)) {
>+ if (!spin_trylock_irqsave(&psinfo->buf_lock, flags)) {
>+ pr_err("dump skipped in %s path because of concurrent dump\n"
>+ , in_nmi() ? "NMI" : why);
The pr_err had the comma following the format string moved, and the note about corruption removed. Is that no longer accurate?
Otherwise looks good; thank you!
--
Kees Cook