[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1682554137-13938-14-git-send-email-anthony.yznaga@oracle.com>
Date: Wed, 26 Apr 2023 17:08:49 -0700
From: Anthony Yznaga <anthony.yznaga@...cle.com>
To: linux-mm@...ck.org, linux-kernel@...r.kernel.org
Cc: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, x86@...nel.org,
hpa@...or.com, dave.hansen@...ux.intel.com, luto@...nel.org,
peterz@...radead.org, rppt@...nel.org, akpm@...ux-foundation.org,
ebiederm@...ssion.com, keescook@...omium.org, graf@...zon.com,
jason.zeng@...el.com, lei.l.li@...el.com,
steven.sistare@...cle.com, fam.zheng@...edance.com,
mgalaxy@...mai.com, kexec@...ts.infradead.org
Subject: [RFC v3 13/21] PKRAM: prevent inadvertent use of a stale superblock
When pages have been saved to be preserved by the current boot, set
a magic number on the super block to be validated by the next kernel.
Signed-off-by: Anthony Yznaga <anthony.yznaga@...cle.com>
---
mm/pkram.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mm/pkram.c b/mm/pkram.c
index c63b27bb711b..befdffc76940 100644
--- a/mm/pkram.c
+++ b/mm/pkram.c
@@ -22,6 +22,7 @@
#include "internal.h"
+#define PKRAM_MAGIC 0x706B726D
/*
* Represents a reference to a data page saved to PKRAM.
@@ -110,6 +111,8 @@ struct pkram_region_list {
* The structure occupies a memory page.
*/
struct pkram_super_block {
+ __u32 magic;
+
__u64 node_pfn; /* first element of the node list */
__u64 region_list_pfn;
__u64 nr_regions;
@@ -179,6 +182,11 @@ void __init pkram_reserve(void)
err = PTR_ERR(pkram_sb);
goto out;
}
+ if (pkram_sb->magic != PKRAM_MAGIC) {
+ pr_err("PKRAM: invalid super block\n");
+ err = -EINVAL;
+ goto out;
+ }
/* An empty pkram_sb is not an error */
if (!pkram_sb->node_pfn) {
pkram_sb = NULL;
@@ -1012,6 +1020,7 @@ static void __pkram_reboot(void)
*/
memset(pkram_sb, 0, PAGE_SIZE);
if (!err && node_pfn) {
+ pkram_sb->magic = PKRAM_MAGIC;
pkram_sb->node_pfn = node_pfn;
pkram_sb->region_list_pfn = rl_pfn;
pkram_sb->nr_regions = nr_regions;
--
1.9.4
Powered by blists - more mailing lists