linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next v2] pstore/ram: Fix pstore lost information
@ 2025-09-01 15:30 chenguanxi11234
  0 siblings, 0 replies; only message in thread
From: chenguanxi11234 @ 2025-09-01 15:30 UTC (permalink / raw)
  To: kees
  Cc: tony.luck, gpiccoli, linux-hardening, linux-kernel, haonan.chen,
	xiaocheng.yan

From: Chen Haonan <haonan.chen@zyt.com>

Background
==========
persistent_ram_zap() is used to prevent the corresponding file from 
still appearing after an unlink operation in the next boot, but 
this is unnecessary for console, pmsg, and ftrace. Worse yet, it 
causes the system to only show logs generated after the deletion 
operation the next time it reboots, following the removal of the 
corresponding file under /sys/fs/pstore.

Solution
==========
Before executing persistent_ram_zap(), check the file type and 
perform this operation only for dmesg logs. 

Result View
==========
Before patch:

root@ubuntu:/sys/fs/pstore# echo test1 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# rm pmsg-ramoops-0 
root@ubuntu:/sys/fs/pstore# echo test2 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# reboot
...
root@ubuntu:/sys/fs/pstore# cat pmsg-ramoops-0 
test2

After patch:

root@ubuntu:/sys/fs/pstore# echo test1 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# rm pmsg-ramoops-0 
root@ubuntu:/sys/fs/pstore# echo test2 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# reboot
...
root@ubuntu:/sys/fs/pstore# cat pmsg-ramoops-0
test1
test2

Signed-off-by: Chen Haonan <haonan.chen@zyt.com>
---
 fs/pstore/ram.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index bc68b4de5287..48e4abd5dcad 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -436,7 +436,8 @@ static int ramoops_pstore_erase(struct pstore_record *record)
 	}
 
 	persistent_ram_free_old(prz);
-	persistent_ram_zap(prz);
+	if (record->type == PSTORE_TYPE_DMESG)
+		persistent_ram_zap(prz);
 
 	return 0;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-09-01 15:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01 15:30 [PATCH linux-next v2] pstore/ram: Fix pstore lost information chenguanxi11234

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).