When SME is enabled in the first kernel, it needs to allocate decrypted
pages for kdump, because when it boots to the kdump kernel, these pages
won't be accessed encrypted at the initial stage, in order to boot the
kdump kernel in the same manner as originally booted.

Signed-off-by: Lianbo Jiang <liji...@redhat.com>
Reviewed-by: Tom Lendacky <thomas.lenda...@amd.com>
---
Changes since v7:
1. Modify comment in the code.(Suggested by Borislav)
2. Improve patch log.(Suggested by Borislav)

 kernel/kexec_core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 23a83a4da38a..6353daaee7f1 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -471,6 +471,18 @@ static struct page 
*kimage_alloc_crash_control_pages(struct kimage *image,
                }
        }
 
+       if (pages) {
+               /*
+                * For kdump, it needs to ensure that these pages are
+                * decrypted if SME is enabled.
+                * By the way, it is unnecessary to call the arch_
+                * kexec_pre_free_pages(), because these pages are
+                * reserved memory and once the crash kernel is done,
+                * it will always remain in these memory until reboot
+                * or unloading.
+                */
+               arch_kexec_post_alloc_pages(page_address(pages), 1 << order, 0);
+       }
        return pages;
 }
 
@@ -867,6 +879,7 @@ static int kimage_load_crash_segment(struct kimage *image,
                        result  = -ENOMEM;
                        goto out;
                }
+               arch_kexec_post_alloc_pages(page_address(page), 1, 0);
                ptr = kmap(page);
                ptr += maddr & ~PAGE_MASK;
                mchunk = min_t(size_t, mbytes,
@@ -884,6 +897,7 @@ static int kimage_load_crash_segment(struct kimage *image,
                        result = copy_from_user(ptr, buf, uchunk);
                kexec_flush_icache_page(page);
                kunmap(page);
+               arch_kexec_pre_free_pages(page_address(page), 1);
                if (result) {
                        result = -EFAULT;
                        goto out;
-- 
2.17.1


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

Reply via email to