Update the logic to classify the persistent memory pool in the kexec e820 table as "kernel reserved" when its corresponding e820 region type is "System RAM". Restore the pool when its type is "kernel reserved". This ensures the persistence of the memory pool across kexec operations. Signed-off-by: Stanislav Kinsburskii <skinsburskii@xxxxxxxxxxxxxxxxxxx> --- mm/pmpool.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/mm/pmpool.c b/mm/pmpool.c index c74f09b99283..1e3a2dffc5d3 100644 --- a/mm/pmpool.c +++ b/mm/pmpool.c @@ -11,11 +11,14 @@ #include <linux/mm.h> #include <linux/pmpool.h> +#include <asm/e820/api.h> + #include "cma.h" struct pmpool { struct resource resource; struct cma *cma; + bool exists; }; static struct pmpool *default_pmpool; @@ -50,6 +53,18 @@ static void pmpool_cma_accomodate_bitmap(struct cma *cma) pr_info("CMA bitmap moved to %#llx\n", virt_to_phys(cma->bitmap)); } +static void pmpool_cma_restore_bitmap(struct cma *cma) +{ + u64 base; + + base = PFN_PHYS(cma->base_pfn); + + bitmap_free(cma->bitmap); + cma->bitmap = phys_to_virt(base); + + pr_info("CMA bitmap restored to %#llx\n", base); +} + static int __init default_pmpool_fixup(void) { if (!default_pmpool) @@ -58,7 +73,11 @@ static int __init default_pmpool_fixup(void) if (insert_resource(&iomem_resource, &default_pmpool->resource)) pr_err("failed to insert resource\n"); - pmpool_cma_accomodate_bitmap(default_pmpool->cma); + if (default_pmpool->exists) + pmpool_cma_restore_bitmap(default_pmpool->cma); + else + pmpool_cma_accomodate_bitmap(default_pmpool->cma); + return 0; } postcore_initcall(default_pmpool_fixup); @@ -73,7 +92,7 @@ static int __init parse_pmpool_opt(char *str) } }; phys_addr_t base, size, end; - int err; + int err, e820_type; /* Format is pmpool=<base>,<size> */ base = memparse(str, &str); @@ -92,10 +111,33 @@ static int __init parse_pmpool_opt(char *str) return 0; } + e820_type = e820__get_entry_type(base, end); + switch (e820_type) { + case E820_TYPE_RAM: + e820__range_update_kexec(base, size, E820_TYPE_RAM, + E820_TYPE_RESERVED_KERN); + e820__update_table_kexec(); + break; + case E820_TYPE_RESERVED_KERN: + /* + * TODO: there are several assumptions here: + * 1. That the kernel reserved region represents pmpool, + * 2. That the region had the same base and size and + * 3. That the region was properly initialized. + * All these assumptions aren't valid in general case and this + * should be addressed. + */ + pmpool.exists = true; + break; + default: + pr_err("unsupported e820 type: %d\n", e820_type); + goto free_memblock; + } + err = cma_init_reserved_mem(base, size, 0, "pmpool", &pmpool.cma); if (err) { pr_err("failed to initialize CMA: %d\n", err); - goto free_memblock; + goto remove_e820_kexec_range; } pmpool.resource.start = base; @@ -108,6 +150,8 @@ static int __init parse_pmpool_opt(char *str) return 0; +remove_e820_kexec_range: + e820__range_remove_kexec(base, size, E820_TYPE_RESERVED_KERN, 1); free_memblock: memblock_phys_free(base, size); return 0; _______________________________________________ kexec mailing list kexec@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/kexec