Commit fd2d7a4a authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'pstore-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull pstore updates from Kees Cook:

 - Don't use semaphores in always-atomic-context code (Jann Horn)

 - Add "ECC:" prefix to ECC messages (Vincent Whitchurch)

* tag 'pstore-v5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  pstore: Don't use semaphores in always-atomic-context code
  pstore: Add prefix to ECC messages
parents b7a801f3 8126b1c7
...@@ -266,7 +266,7 @@ static int efi_pstore_write(struct pstore_record *record) ...@@ -266,7 +266,7 @@ static int efi_pstore_write(struct pstore_record *record)
efi_name[i] = name[i]; efi_name[i] = name[i];
ret = efivar_entry_set_safe(efi_name, vendor, PSTORE_EFI_ATTRIBUTES, ret = efivar_entry_set_safe(efi_name, vendor, PSTORE_EFI_ATTRIBUTES,
preemptible(), record->size, record->psi->buf); false, record->size, record->psi->buf);
if (record->reason == KMSG_DUMP_OOPS && try_module_get(THIS_MODULE)) if (record->reason == KMSG_DUMP_OOPS && try_module_get(THIS_MODULE))
if (!schedule_work(&efivar_work)) if (!schedule_work(&efivar_work))
......
...@@ -143,21 +143,22 @@ static void pstore_timer_kick(void) ...@@ -143,21 +143,22 @@ static void pstore_timer_kick(void)
mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms)); mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
} }
/* static bool pstore_cannot_block_path(enum kmsg_dump_reason reason)
* Should pstore_dump() wait for a concurrent pstore_dump()? If
* not, the current pstore_dump() will report a failure to dump
* and return.
*/
static bool pstore_cannot_wait(enum kmsg_dump_reason reason)
{ {
/* In NMI path, pstore shouldn't block regardless of reason. */ /*
* In case of NMI path, pstore shouldn't be blocked
* regardless of reason.
*/
if (in_nmi()) if (in_nmi())
return true; return true;
switch (reason) { switch (reason) {
/* In panic case, other cpus are stopped by smp_send_stop(). */ /* In panic case, other cpus are stopped by smp_send_stop(). */
case KMSG_DUMP_PANIC: case KMSG_DUMP_PANIC:
/* Emergency restart shouldn't be blocked. */ /*
* Emergency restart shouldn't be blocked by spinning on
* pstore_info::buf_lock.
*/
case KMSG_DUMP_EMERG: case KMSG_DUMP_EMERG:
return true; return true;
default: default:
...@@ -389,21 +390,19 @@ static void pstore_dump(struct kmsg_dumper *dumper, ...@@ -389,21 +390,19 @@ static void pstore_dump(struct kmsg_dumper *dumper,
unsigned long total = 0; unsigned long total = 0;
const char *why; const char *why;
unsigned int part = 1; unsigned int part = 1;
unsigned long flags = 0;
int ret; int ret;
why = kmsg_dump_reason_str(reason); why = kmsg_dump_reason_str(reason);
if (down_trylock(&psinfo->buf_lock)) { if (pstore_cannot_block_path(reason)) {
/* Failed to acquire lock: give up if we cannot wait. */ if (!spin_trylock_irqsave(&psinfo->buf_lock, flags)) {
if (pstore_cannot_wait(reason)) { pr_err("dump skipped in %s path because of concurrent dump\n",
pr_err("dump skipped in %s path: may corrupt error record\n",
in_nmi() ? "NMI" : why); in_nmi() ? "NMI" : why);
return; return;
} }
if (down_interruptible(&psinfo->buf_lock)) { } else {
pr_err("could not grab semaphore?!\n"); spin_lock_irqsave(&psinfo->buf_lock, flags);
return;
}
} }
kmsg_dump_rewind(&iter); kmsg_dump_rewind(&iter);
...@@ -467,8 +466,7 @@ static void pstore_dump(struct kmsg_dumper *dumper, ...@@ -467,8 +466,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
total += record.size; total += record.size;
part++; part++;
} }
spin_unlock_irqrestore(&psinfo->buf_lock, flags);
up(&psinfo->buf_lock);
} }
static struct kmsg_dumper pstore_dumper = { static struct kmsg_dumper pstore_dumper = {
...@@ -594,7 +592,7 @@ int pstore_register(struct pstore_info *psi) ...@@ -594,7 +592,7 @@ int pstore_register(struct pstore_info *psi)
psi->write_user = pstore_write_user_compat; psi->write_user = pstore_write_user_compat;
psinfo = psi; psinfo = psi;
mutex_init(&psinfo->read_mutex); mutex_init(&psinfo->read_mutex);
sema_init(&psinfo->buf_lock, 1); spin_lock_init(&psinfo->buf_lock);
if (psi->flags & PSTORE_FLAGS_DMESG) if (psi->flags & PSTORE_FLAGS_DMESG)
allocate_buf_for_compression(); allocate_buf_for_compression();
......
...@@ -263,10 +263,10 @@ ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, ...@@ -263,10 +263,10 @@ ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,
if (prz->corrected_bytes || prz->bad_blocks) if (prz->corrected_bytes || prz->bad_blocks)
ret = snprintf(str, len, "" ret = snprintf(str, len, ""
"\n%d Corrected bytes, %d unrecoverable blocks\n", "\nECC: %d Corrected bytes, %d unrecoverable blocks\n",
prz->corrected_bytes, prz->bad_blocks); prz->corrected_bytes, prz->bad_blocks);
else else
ret = snprintf(str, len, "\nNo errors detected\n"); ret = snprintf(str, len, "\nECC: No errors detected\n");
return ret; return ret;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/kmsg_dump.h> #include <linux/kmsg_dump.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/semaphore.h> #include <linux/spinlock.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -87,7 +87,7 @@ struct pstore_record { ...@@ -87,7 +87,7 @@ struct pstore_record {
* @owner: module which is responsible for this backend driver * @owner: module which is responsible for this backend driver
* @name: name of the backend driver * @name: name of the backend driver
* *
* @buf_lock: semaphore to serialize access to @buf * @buf_lock: spinlock to serialize access to @buf
* @buf: preallocated crash dump buffer * @buf: preallocated crash dump buffer
* @bufsize: size of @buf available for crash dump bytes (must match * @bufsize: size of @buf available for crash dump bytes (must match
* smallest number of bytes available for writing to a * smallest number of bytes available for writing to a
...@@ -178,7 +178,7 @@ struct pstore_info { ...@@ -178,7 +178,7 @@ struct pstore_info {
struct module *owner; struct module *owner;
const char *name; const char *name;
struct semaphore buf_lock; spinlock_t buf_lock;
char *buf; char *buf;
size_t bufsize; size_t bufsize;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment