Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pstore: replace spinlock_t by raw_spinlock_t

pstore_dump() is called when both preemption and local IRQ are disabled,
and a spinlock is obtained, which is problematic for the RT kernel because
in this configuration, spinlocks are sleep locks.

Replace the spinlock_t with raw_spinlock_t to avoid sleeping in atomic context.

Signed-off-by: Wen Yang <wen.yang@linux.dev>
Cc: Kees Cook <kees@kernel.org>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Guilherme G. Piccoli <gpiccoli@igalia.com>
Cc: linux-hardening@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Link: https://lore.kernel.org/r/20240819145945.61274-1-wen.yang@linux.dev
Signed-off-by: Kees Cook <kees@kernel.org>

authored by

Wen Yang and committed by
Kees Cook
1bf8012f a7050ca7

+5 -5
+4 -4
fs/pstore/platform.c
··· 288 288 why = kmsg_dump_reason_str(reason); 289 289 290 290 if (pstore_cannot_block_path(reason)) { 291 - if (!spin_trylock_irqsave(&psinfo->buf_lock, flags)) { 291 + if (!raw_spin_trylock_irqsave(&psinfo->buf_lock, flags)) { 292 292 pr_err("dump skipped in %s path because of concurrent dump\n", 293 293 in_nmi() ? "NMI" : why); 294 294 return; 295 295 } 296 296 } else { 297 - spin_lock_irqsave(&psinfo->buf_lock, flags); 297 + raw_spin_lock_irqsave(&psinfo->buf_lock, flags); 298 298 } 299 299 300 300 kmsg_dump_rewind(&iter); ··· 364 364 total += record.size; 365 365 part++; 366 366 } 367 - spin_unlock_irqrestore(&psinfo->buf_lock, flags); 367 + raw_spin_unlock_irqrestore(&psinfo->buf_lock, flags); 368 368 369 369 if (saved_ret) { 370 370 pr_err_once("backend (%s) writing error (%d)\n", psinfo->name, ··· 503 503 psi->write_user = pstore_write_user_compat; 504 504 psinfo = psi; 505 505 mutex_init(&psinfo->read_mutex); 506 - spin_lock_init(&psinfo->buf_lock); 506 + raw_spin_lock_init(&psinfo->buf_lock); 507 507 508 508 if (psi->flags & PSTORE_FLAGS_DMESG) 509 509 allocate_buf_for_compression();
+1 -1
include/linux/pstore.h
··· 182 182 struct module *owner; 183 183 const char *name; 184 184 185 - spinlock_t buf_lock; 185 + raw_spinlock_t buf_lock; 186 186 char *buf; 187 187 size_t bufsize; 188 188