diff mbox series

[RFC,v3,17/21] kexec: PKRAM: avoid clobbering already preserved pages

Message ID 1682554137-13938-18-git-send-email-anthony.yznaga@oracle.com (mailing list archive)
State New
Headers show
Series Preserved-over-Kexec RAM | expand

Commit Message

Anthony Yznaga April 27, 2023, 12:08 a.m. UTC
Ensure destination ranges of the kexec segments do not overlap
with any kernel pages marked to be preserved across kexec.

For kexec_load, return EADDRNOTAVAIL if overlap is detected.

For kexec_file_load, skip ranges containing preserved pages when
seaching for available ranges to use.

Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
---
 kernel/kexec_core.c | 3 +++
 kernel/kexec_file.c | 5 +++++
 2 files changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 3d578c6fefee..e0d52f70cb48 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -40,6 +40,7 @@ 
 #include <linux/hugetlb.h>
 #include <linux/objtool.h>
 #include <linux/kmsg_dump.h>
+#include <linux/pkram.h>
 
 #include <asm/page.h>
 #include <asm/sections.h>
@@ -178,6 +179,8 @@  int sanity_check_segment_list(struct kimage *image)
 			return -EADDRNOTAVAIL;
 		if (mend >= KEXEC_DESTINATION_MEMORY_LIMIT)
 			return -EADDRNOTAVAIL;
+		if (pkram_has_preserved_pages(mstart, mend))
+			return -EADDRNOTAVAIL;
 	}
 
 	/* Verify our destination addresses do not overlap.
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index ca2aa2d61955..8bca01060d32 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -490,6 +490,11 @@  static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end,
 			continue;
 		}
 
+		if (pkram_has_preserved_pages(temp_start, temp_end + 1)) {
+			temp_start = temp_start - PAGE_SIZE;
+			continue;
+		}
+
 		/* We found a suitable memory range */
 		break;
 	} while (1);