@@ -70,11 +70,13 @@ extern unsigned long pkram_reserved_pages;
void pkram_reserve(void);
void pkram_free_pgt(void);
void pkram_ban_region(unsigned long start, unsigned long end);
+int pkram_has_preserved_pages(unsigned long start, unsigned long end);
#else
#define pkram_reserved_pages 0UL
static inline void pkram_reserve(void) { }
static inline void pkram_free_pgt(void) { }
static inline void pkram_ban_region(unsigned long start, unsigned long end) { }
+static inline int pkram_has_preserved_pages(unsigned long start, unsigned long end) { return 0; }
#endif
#endif /* _LINUX_PKRAM_H */
@@ -1499,3 +1499,28 @@ phys_addr_t __init_memblock pkram_memblock_find_in_range(phys_addr_t start,
return st.retval;
}
+
+static int pkram_has_preserved_pages_cb(struct pkram_pg_state *st, unsigned long base, unsigned long size)
+{
+ st->retval = 1;
+ return 1;
+}
+
+/*
+ * Check whether the memory range [start, end) contains preserved pages.
+ */
+int pkram_has_preserved_pages(unsigned long start, unsigned long end)
+{
+ struct pkram_pg_state st = {
+ .range_cb = pkram_has_preserved_pages_cb,
+ .min_addr = start,
+ .max_addr = end,
+ };
+
+ if (!pkram_pgd)
+ return 0;
+
+ pkram_walk_pgt_rev(&st, pkram_pgd);
+
+ return st.retval;
+}
When a kernel is loaded for kexec the address ranges where the kexec segments will be copied to may conflict with pages already set to be preserved. Provide a way to determine if preserved pages exist in a specified range. Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> --- include/linux/pkram.h | 2 ++ mm/pkram.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+)