Support kdump for AMD secure memory encryption(SME)
Subsystems (8)
v7 cover Support kdump for AMD secure memory encryption(SME)
When SME is enabled on AMD machine, we also need to support kdump. Because the memory is encrypted in the first kernel, we will remap the old memory to the kdump kernel for dumping data, and SME is also enabled in the kdump kernel, otherwise the old memory can not be decrypted.
For the kdump, it is necessary to distinguish whether the memory is encrypted. Furthermore, we should also know which part of the memory is encrypted or decrypted. We will appropriately remap the memory according to the specific situation in order to tell cpu how to access the memory.
As we know, a page of memory that is marked as encrypted, which will be automatically decrypted when read from DRAM, and will also be automatically encrypted when written to DRAM. If the old memory is encrypted, we have to remap the old memory with the memory encryption mask, which will automatically decrypt the old memory when we read those data.
For kdump(SME), there are two cases that doesn't support:
----------------------------------------------
| first-kernel | second-kernel | kdump support | | (mem_encrypt=on|off) | (yes|no) | |--------------+---------------+---------------| | on | on | yes | | off | off | yes | | on | off | no | | off | on | no | |______________|_______________|_______________|
1. SME is enabled in the first kernel, but SME is disabled in kdump kernel In this case, because the old memory is encrypted, we can't decrypt the old memory.
2. SME is disabled in the first kernel, but SME is enabled in kdump kernel It is unnecessary to support in this case, because the old memory is unencrypted, the old memory can be dumped as usual, we don't need to enable SME in kdump kernel. Another, If we must support the scenario, it will increase the complexity of the code, we will have to consider how to pass the SME flag from the first kernel to the kdump kernel, in order to let the kdump kernel know that whether the old memory is encrypted.
There are two methods to pass the SME flag to the kdump kernel. The first method is to modify the assembly code, which includes some common code and the path is too long. The second method is to use kexec tool, which could require the SME flag to be exported in the first kernel by "proc" or "sysfs", kexec tools will read the SME flag from "proc" or "sysfs" when we use kexec tools to load image, subsequently the SME flag will be saved in boot_params, we can properly remap the old memory according to the previously saved SME flag. But it is too expensive to do this.
This patches are only for SME kdump, the patches don't support SEV kdump.
Test tools:
makedumpfile[v1.6.3]: https://github.com/LianboJ/makedumpfile
commit e1de103eca8f (A draft for kdump vmcore about AMD SME)
Note: This patch can only dump vmcore in the case of SME enabled.
crash-7.2.3: https://github.com/crash-utility/crash.git
commit 001f77a05585 (Fix for Linux 4.19-rc1 and later kernels that contain
kernel commit7290d58095712a89f845e1bca05334796dd49ed2)
kexec-tools-2.0.17: git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
commit b9de21ef51a7 (kexec: fix for "Unhandled rela relocation: R_X86_64_PLT32" error)
Note:
Before you load the kernel and initramfs for kdump, this patch(http://lists.infradead.org/pipermail/kexec/2018-September/021460.html) must be merged to kexec-tools, and then the kdump kernel will work well. Because there
is a patch which is removed based on v6(x86/ioremap: strengthen the logic in early_memremap_pgprot_adjust()
to adjust encryption mask).
Test environment:
HP ProLiant DL385Gen10 AMD EPYC 7251
8-Core Processor
32768 MB memory
600 GB disk space
Linux 4.19-rc2:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
commit 57361846b52bc686112da6ca5368d11210796804
Reference:
AMD64 Architecture Programmer's Manual
https://support.amd.com/TechDocs/24593.pdf
Changes since v6:
1. There is a patch which is removed based on v6.
(x86/ioremap: strengthen the logic in early_memremap_pgprot_adjust() to adjust encryption mask) Dave Young suggests that this patch can be removed and fix the kexec-tools.
Reference: http://lists.infradead.org/pipermail/kexec/2018-September/021460.html)
2. Update the patch log.
Some known issues:
1. about SME
Upstream kernel will hang on HP machine(DL385Gen10 AMD EPYC 7251) when we execute the kexec command as follow:
# kexec -l /boot/vmlinuz-4.19.0-rc2+ --initrd=/boot/initramfs-4.19.0-rc2+.img --command-line="root=/dev/mapper/rhel_hp--dl385g10--03-root ro mem_encrypt=on rd.lvm.lv=rhel_hp-dl385g10-03/root rd.lvm.lv=rhel_hp-dl385g10-03/swap console=ttyS0,115200n81 LANG=en_US.UTF-8 earlyprintk=serial debug nokaslr" # kexec -e (or reboot)
But this issue can not be reproduced on speedway machine, and this issue is irrelevant to my posted patches.
The kernel log:
[ 1248.932239] kexec_core: Starting new kernel
early console in extract_kernelinput_data: 0x000000087e91c3b4input_len: 0x000000000067fcbd
output: 0x000000087d400000output_len: 0x0000000001b6fa90kernel_total_size: 0x0000000001a9d000trampoline_32bit: 0x0000000000099000
Decompressing Linux...
Parsing ELF... [---Here the system will hang]
Lianbo Jiang (4):
x86/ioremap: add a function ioremap_encrypted() to remap kdump old
memory
kexec: allocate unencrypted control pages for kdump in case SME is
enabled
amd_iommu: remap the device table of IOMMU with the memory encryption
mask for kdump
kdump/vmcore: support encrypted old memory with SME enabled
arch/x86/include/asm/io.h | 3 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/crash_dump_encrypt.c | 53 ++++++++++++++++++++++++++++ arch/x86/mm/ioremap.c | 25 ++++++++----- drivers/iommu/amd_iommu_init.c | 14 ++++++-- fs/proc/vmcore.c | 21 +++++++---- include/linux/crash_dump.h | 12 +++++++ kernel/kexec_core.c | 12 +++++++ 8 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 arch/x86/kernel/crash_dump_encrypt.c
Signature · 1 line
2.17.1
PATCH v7 1/4 x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
--- arch/x86/include/asm/io.h | 3 +++ arch/x86/mm/ioremap.c | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)
arch/x86/include/asm/io.h +3 -0
@@ -192,6 +192,9 @@ extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);#define ioremap_cache ioremap_cacheextern void __iomem *ioremap_prot (resource_size_t offset,unsigned long size,unsigned long prot_val);#define ioremap_prot ioremap_prot +extern void __iomem *ioremap_encrypted (resource_size_t phys_addr, +unsigned long size); +#define ioremap_encrypted ioremap_encrypted/** * ioremap - map bus memory into CPU space
arch/x86/mm/ioremap.c +17 -8
@@ -24,6 +24,7 @@#include <asm/pgalloc.h> #include <asm/pat.h> #include <asm/setup.h> +#include <linux/crash_dump.h> #include "physaddr.h"
@@ -131,7 +132,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,* caller shouldn't need to know that small detail. */ static void __iomem *__ioremap_caller (resource_size_t phys_addr, -unsigned long size,enum page_cache_mode pcm,void *caller) +unsigned long size,enum page_cache_mode pcm, +void *caller,bool encrypted) {unsigned long offset, vaddr;resource_size_t last_addr;
@@ -199,7 +201,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,* resulting mapping. */ prot =PAGE_KERNEL_IO ; -if (sev_active () && mem_flags.desc_other) +if ((sev_active () && mem_flags.desc_other) || encrypted) prot =pgprot_encrypted (prot);switch (pcm) {
@@ -291,7 +293,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC_MINUS;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_nocache);
@@ -324,7 +326,7 @@ void __iomem *ioremap_uc(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL_GPL (ioremap_uc);
@@ -341,7 +343,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);void __iomem *ioremap_wc (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WC, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wc);
@@ -358,14 +360,21 @@ EXPORT_SYMBOL(ioremap_wc);void __iomem *ioremap_wt (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WT, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wt); +void __iomem *ioremap_encrypted (resource_size_t phys_addr,unsigned long size) +{ +return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, +__builtin_return_address (0 ), true); +} +EXPORT_SYMBOL (ioremap_encrypted); +void __iomem *ioremap_cache (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_cache);
@@ -374,7 +383,7 @@ void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, {return __ioremap_caller (phys_addr, size,pgprot2cachemode (__pgprot (prot_val)), -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_prot);
Signature · 1 line
2.17.1
Re: [PATCH 1/4 v7] x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
Hi Lianbo,
Quoted 3 lines · Lianbo Jiang
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
This patch series looks good to me. One thing is in your v5 post, Boris reviewed and complained about the git log, we worked together to make an document to explain, wondering why you don't rearrange it into log of this patch. Other than this, all looks fine.
Quoted 115 lines
Signed-off-by Lianbo Jiang <[email protected]>--- arch/x86/include/asm/io.h | 3 +++ arch/x86/mm/ioremap.c | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)arch/x86/include/asm/io.h +3
-0@@ -192,6 +192,9 @@ extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);#define ioremap_cache ioremap_cacheextern void __iomem *ioremap_prot (resource_size_t offset,unsigned long size,unsigned long prot_val);#define ioremap_prot ioremap_prot +extern void __iomem *ioremap_encrypted (resource_size_t phys_addr, +unsigned long size); +#define ioremap_encrypted ioremap_encrypted/** * ioremap - map bus memory into CPU space arch/x86/mm/ioremap.c +17
-8@@ -24,6 +24,7 @@#include <asm/pgalloc.h> #include <asm/pat.h> #include <asm/setup.h> +#include <linux/crash_dump.h> #include "physaddr.h" @@ -131,7 +132,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,* caller shouldn't need to know that small detail. */ static void __iomem *__ioremap_caller (resource_size_t phys_addr, -unsigned long size,enum page_cache_mode pcm,void *caller) +unsigned long size,enum page_cache_mode pcm, +void *caller,bool encrypted) {unsigned long offset, vaddr;resource_size_t last_addr;@@ -199,7 +201,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,* resulting mapping. */ prot =PAGE_KERNEL_IO ; -if (sev_active () && mem_flags.desc_other) +if ((sev_active () && mem_flags.desc_other) || encrypted) prot =pgprot_encrypted (prot);switch (pcm) {@@ -291,7 +293,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC_MINUS;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_nocache);@@ -324,7 +326,7 @@ void __iomem *ioremap_uc(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL_GPL (ioremap_uc);@@ -341,7 +343,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);void __iomem *ioremap_wc (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WC, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wc);@@ -358,14 +360,21 @@ EXPORT_SYMBOL(ioremap_wc);void __iomem *ioremap_wt (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WT, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wt); +void __iomem *ioremap_encrypted (resource_size_t phys_addr,unsigned long size) +{ +return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, +__builtin_return_address (0 ), true); +} +EXPORT_SYMBOL (ioremap_encrypted); +void __iomem *ioremap_cache (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_cache);@@ -374,7 +383,7 @@ void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, {return __ioremap_caller (phys_addr, size,pgprot2cachemode (__pgprot (prot_val)), -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_prot);Signature · 1 line
2.17.1
Re: [PATCH 1/4 v7] x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
Quoted 7 lines · Baoquan He
Hi Lianbo,
Quoted 3 lines · Lianbo Jiang
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
Quoted 7 lines
This patch series looks good to me. One thing is in your v5 post, Boris reviewed and complained about the git log, we worked together to make an document to explain, wondering why you don't rearrange it into log of this patch. Other than this, all looks fine.
Thank you, Baoquan.
Previously i had considered whether i should put these explaining into patch log, because these contents are a little more, i might just put the description of Solution A into this patch log and post this patch again.
Lianbo
Quoted 113 lines
Quoted 113 lines
Signed-off-by Lianbo Jiang <[email protected]>--- arch/x86/include/asm/io.h | 3 +++ arch/x86/mm/ioremap.c | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)arch/x86/include/asm/io.h +3
-0@@ -192,6 +192,9 @@ extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);#define ioremap_cache ioremap_cacheextern void __iomem *ioremap_prot (resource_size_t offset,unsigned long size,unsigned long prot_val);#define ioremap_prot ioremap_prot +extern void __iomem *ioremap_encrypted (resource_size_t phys_addr, +unsigned long size); +#define ioremap_encrypted ioremap_encrypted/** * ioremap - map bus memory into CPU space arch/x86/mm/ioremap.c +17
-8@@ -24,6 +24,7 @@#include <asm/pgalloc.h> #include <asm/pat.h> #include <asm/setup.h> +#include <linux/crash_dump.h> #include "physaddr.h" @@ -131,7 +132,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,* caller shouldn't need to know that small detail. */ static void __iomem *__ioremap_caller (resource_size_t phys_addr, -unsigned long size,enum page_cache_mode pcm,void *caller) +unsigned long size,enum page_cache_mode pcm, +void *caller,bool encrypted) {unsigned long offset, vaddr;resource_size_t last_addr;@@ -199,7 +201,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,* resulting mapping. */ prot =PAGE_KERNEL_IO ; -if (sev_active () && mem_flags.desc_other) +if ((sev_active () && mem_flags.desc_other) || encrypted) prot =pgprot_encrypted (prot);switch (pcm) {@@ -291,7 +293,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC_MINUS;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_nocache);@@ -324,7 +326,7 @@ void __iomem *ioremap_uc(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL_GPL (ioremap_uc);@@ -341,7 +343,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);void __iomem *ioremap_wc (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WC, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wc);@@ -358,14 +360,21 @@ EXPORT_SYMBOL(ioremap_wc);void __iomem *ioremap_wt (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WT, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wt); +void __iomem *ioremap_encrypted (resource_size_t phys_addr,unsigned long size) +{ +return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, +__builtin_return_address (0 ), true); +} +EXPORT_SYMBOL (ioremap_encrypted); +void __iomem *ioremap_cache (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_cache);@@ -374,7 +383,7 @@ void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, {return __ioremap_caller (phys_addr, size,pgprot2cachemode (__pgprot (prot_val)), -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_prot);
Quoted 9 lines
Quoted 3 lines
Signature · 1 line
2.17.1_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/4 v7] x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
Also cc maintainer and other reviewer. Thanks.
Quoted 150 lines · lijiang
Quoted 7 lines · Baoquan He
Hi Lianbo,
Quoted 3 lines · Lianbo Jiang
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
Quoted 7 lines
This patch series looks good to me. One thing is in your v5 post, Boris reviewed and complained about the git log, we worked together to make an document to explain, wondering why you don't rearrange it into log of this patch. Other than this, all looks fine.
Thank you, Baoquan.
Previously i had considered whether i should put these explaining into patch log, because these contents are a little more, i might just put the description of Solution A into this patch log and post this patch again.
Lianbo
Quoted 113 lines
Quoted 113 lines
Signed-off-by Lianbo Jiang <[email protected]>--- arch/x86/include/asm/io.h | 3 +++ arch/x86/mm/ioremap.c | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)arch/x86/include/asm/io.h +3
-0@@ -192,6 +192,9 @@ extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);#define ioremap_cache ioremap_cacheextern void __iomem *ioremap_prot (resource_size_t offset,unsigned long size,unsigned long prot_val);#define ioremap_prot ioremap_prot +extern void __iomem *ioremap_encrypted (resource_size_t phys_addr, +unsigned long size); +#define ioremap_encrypted ioremap_encrypted/** * ioremap - map bus memory into CPU space arch/x86/mm/ioremap.c +17
-8@@ -24,6 +24,7 @@#include <asm/pgalloc.h> #include <asm/pat.h> #include <asm/setup.h> +#include <linux/crash_dump.h> #include "physaddr.h" @@ -131,7 +132,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,* caller shouldn't need to know that small detail. */ static void __iomem *__ioremap_caller (resource_size_t phys_addr, -unsigned long size,enum page_cache_mode pcm,void *caller) +unsigned long size,enum page_cache_mode pcm, +void *caller,bool encrypted) {unsigned long offset, vaddr;resource_size_t last_addr;@@ -199,7 +201,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,* resulting mapping. */ prot =PAGE_KERNEL_IO ; -if (sev_active () && mem_flags.desc_other) +if ((sev_active () && mem_flags.desc_other) || encrypted) prot =pgprot_encrypted (prot);switch (pcm) {@@ -291,7 +293,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC_MINUS;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_nocache);@@ -324,7 +326,7 @@ void __iomem *ioremap_uc(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL_GPL (ioremap_uc);@@ -341,7 +343,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);void __iomem *ioremap_wc (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WC, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wc);@@ -358,14 +360,21 @@ EXPORT_SYMBOL(ioremap_wc);void __iomem *ioremap_wt (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WT, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wt); +void __iomem *ioremap_encrypted (resource_size_t phys_addr,unsigned long size) +{ +return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, +__builtin_return_address (0 ), true); +} +EXPORT_SYMBOL (ioremap_encrypted); +void __iomem *ioremap_cache (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_cache);@@ -374,7 +383,7 @@ void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, {return __ioremap_caller (phys_addr, size,pgprot2cachemode (__pgprot (prot_val)), -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_prot);Quoted 9 lines
Quoted 3 lines
Signature · 1 line
2.17.1_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/4 v8] x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
Here we only talk about the case that SME is active in the first kernel, and only care it's active too in kdump kernel. there are four cases we need considered.
a. dump vmcore
It is encrypted in the first kernel, and needs be read out in kdump kernel.
b. crash notes
When dumping vmcore, the people usually need to read the useful information from notes, and the notes is also encrypted.
c. iommu device table
It is allocated by kernel, need fill its pointer into mmio of amd iommu. It's encrypted in the first kernel, need read the old content to analyze and get useful information.
d. mmio of amd iommu
Register reported by amd firmware, it's not RAM, we don't encrypt in both the first kernel and kdump kernel.
To achieve the goal, the solution is:
1. add a new bool parameter "encrypted" to __ioremap_caller() It is a low level function, and check the newly added parameter, if it's true and in kdump kernel, will remap the memory with sme mask.
2. add a new function ioremap_encrypted() to explicitly passed in a "true" value for "encrypted".
For above a, b, c, we will call ioremap_encrypted();
3. adjust all existed ioremap wrapper functions, passed in "false" for encrypted to make them an before.
ioremap_encrypted()\ ioremap_cache() | ioremap_prot() | ioremap_wt() |->__ioremap_caller() ioremap_wc() | ioremap_uc() | ioremap_nocache() /
---
Changes since v7:
1. Only modify patch log(suggested by Baoquan He)
arch/x86/include/asm/io.h | 3 +++ arch/x86/mm/ioremap.c | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-)
arch/x86/include/asm/io.h +3 -0
@@ -192,6 +192,9 @@ extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);#define ioremap_cache ioremap_cacheextern void __iomem *ioremap_prot (resource_size_t offset,unsigned long size,unsigned long prot_val);#define ioremap_prot ioremap_prot +extern void __iomem *ioremap_encrypted (resource_size_t phys_addr, +unsigned long size); +#define ioremap_encrypted ioremap_encrypted/** * ioremap - map bus memory into CPU space
arch/x86/mm/ioremap.c +17 -8
@@ -24,6 +24,7 @@#include <asm/pgalloc.h> #include <asm/pat.h> #include <asm/setup.h> +#include <linux/crash_dump.h> #include "physaddr.h"
@@ -131,7 +132,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,* caller shouldn't need to know that small detail. */ static void __iomem *__ioremap_caller (resource_size_t phys_addr, -unsigned long size,enum page_cache_mode pcm,void *caller) +unsigned long size,enum page_cache_mode pcm, +void *caller,bool encrypted) {unsigned long offset, vaddr;resource_size_t last_addr;
@@ -199,7 +201,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,* resulting mapping. */ prot =PAGE_KERNEL_IO ; -if (sev_active () && mem_flags.desc_other) +if ((sev_active () && mem_flags.desc_other) || encrypted) prot =pgprot_encrypted (prot);switch (pcm) {
@@ -291,7 +293,7 @@ void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC_MINUS;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_nocache);
@@ -324,7 +326,7 @@ void __iomem *ioremap_uc(resource_size_t phys_addr, unsigned long size)enum page_cache_mode pcm = _PAGE_CACHE_MODE_UC;return __ioremap_caller (phys_addr, size, pcm, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL_GPL (ioremap_uc);
@@ -341,7 +343,7 @@ EXPORT_SYMBOL_GPL(ioremap_uc);void __iomem *ioremap_wc (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WC, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wc);
@@ -358,14 +360,21 @@ EXPORT_SYMBOL(ioremap_wc);void __iomem *ioremap_wt (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WT, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_wt); +void __iomem *ioremap_encrypted (resource_size_t phys_addr,unsigned long size) +{ +return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, +__builtin_return_address (0 ), true); +} +EXPORT_SYMBOL (ioremap_encrypted); +void __iomem *ioremap_cache (resource_size_t phys_addr,unsigned long size) {return __ioremap_caller (phys_addr, size, _PAGE_CACHE_MODE_WB, -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_cache);
@@ -374,7 +383,7 @@ void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size, {return __ioremap_caller (phys_addr, size,pgprot2cachemode (__pgprot (prot_val)), -__builtin_return_address (0 )); +__builtin_return_address (0 ), false); }EXPORT_SYMBOL (ioremap_prot);
Signature · 1 line
2.17.1
Re: [PATCH 1/4 v8] x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
Hi Lianbo,
Quoted 37 lines · lijiang
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
Here we only talk about the case that SME is active in the first kernel, and only care it's active too in kdump kernel. there are four cases we need considered.
a. dump vmcore
It is encrypted in the first kernel, and needs be read out in kdump kernel.b. crash notes
When dumping vmcore, the people usually need to read the useful information from notes, and the notes is also encrypted.c. iommu device table
It is allocated by kernel, need fill its pointer into mmio of amd iommu. It's encrypted in the first kernel, need read the old content to analyze and get useful information.d. mmio of amd iommu
Register reported by amd firmware, it's not RAM, we don't encrypt in both the first kernel and kdump kernel.To achieve the goal, the solution is:
1. add a new bool parameter "encrypted" to__ioremap_caller()It is a low level function, and check the newly added parameter, if it's true and in kdump kernel, will remap the memory with sme mask.2. add a new function
ioremap_encrypted()to explicitly passed in a "true" value for "encrypted".
For above a, b, c, we will callioremap_encrypted();3. adjust all existed ioremap wrapper functions, passed in "false" for encrypted to make them an before.
Quoted 7 lines
ioremap_encrypted()\ ioremap_cache() | ioremap_prot() | ioremap_wt() |->__ioremap_caller() ioremap_wc() | ioremap_uc() | ioremap_nocache() /
Thanks, I think it's better. Since no code change, just patch log improvement, maybe you can repost a series and carry both Tom and Joerg's ACK.
Re: [PATCH 1/4 v8] x86/ioremap: add a function ioremap_encrypted() to remap kdump old memory
Quoted 48 lines · Baoquan He
Hi Lianbo,
Quoted 37 lines · lijiang
When SME is enabled on AMD machine, the memory is encrypted in the first kernel. In this case, SME also needs to be enabled in kdump kernel, and we have to remap the old memory with the memory encryption mask.
Here we only talk about the case that SME is active in the first kernel, and only care it's active too in kdump kernel. there are four cases we need considered.
a. dump vmcore
It is encrypted in the first kernel, and needs be read out in kdump kernel.b. crash notes
When dumping vmcore, the people usually need to read the useful information from notes, and the notes is also encrypted.c. iommu device table
It is allocated by kernel, need fill its pointer into mmio of amd iommu. It's encrypted in the first kernel, need read the old content to analyze and get useful information.d. mmio of amd iommu
Register reported by amd firmware, it's not RAM, we don't encrypt in both the first kernel and kdump kernel.To achieve the goal, the solution is:
1. add a new bool parameter "encrypted" to__ioremap_caller()It is a low level function, and check the newly added parameter, if it's true and in kdump kernel, will remap the memory with sme mask.2. add a new function
ioremap_encrypted()to explicitly passed in a "true" value for "encrypted".
For above a, b, c, we will callioremap_encrypted();3. adjust all existed ioremap wrapper functions, passed in "false" for encrypted to make them an before.
Quoted 7 lines
ioremap_encrypted()\ ioremap_cache() | ioremap_prot() | ioremap_wt() |->__ioremap_caller() ioremap_wc() | ioremap_uc() | ioremap_nocache() /
Quoted 4 lines
Thanks, I think it's better. Since no code change, just patch log improvement, maybe you can repost a series and carry both Tom and Joerg's ACK.
Thank you, Baoquan.
I will resend a series, and add Tom's Reviewed-by for all patches, also add Joerg's Acked-by for patch 3/4.
Thanks.
Lianbo
PATCH v7 2/4 kexec: allocate unencrypted control pages for kdump in case SME is enabled
In reply to Lianbo JiangWhen SME is enabled in the first kernel, we will allocate unencrypted pages for kdump in order to be able to boot the kdump kernel like kexec.
--- kernel/kexec_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
kernel/kexec_core.c +12 -0
@@ -471,6 +471,16 @@ static struct page *kimage_alloc_crash_control_pages(struct kimage *image, } } +if (pages) { +/* +* For kdump, we need to ensure that these pages are +* unencrypted pages if SME is enabled. +* By the way, it is unnecessary to call the arch_ +* kexec_pre_free_pages(), which will make the code +* become more simple. +*/ +arch_kexec_post_alloc_pages (page_address (pages),1 << order,0 ); + }return pages; }
@@ -867,6 +877,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 +895,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;
Signature · 1 line
2.17.1
PATCH v7 3/4 amd_iommu: remap the device table of IOMMU with the memory encryption mask for kdump
In reply to Lianbo JiangIn kdump kernel, it will copy the device table of IOMMU from the old device table, which is encrypted when SME is enabled in the first kernel. So we have to remap the old device table with the memory encryption mask.
--- drivers/iommu/amd_iommu_init.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/iommu/amd_iommu_init.c +12 -2
@@ -902,12 +902,22 @@ static bool copy_device_table(void) } } - old_devtb_phys = entry &PAGE_MASK ; +/* +* When SME is enabled in the first kernel, the entry includes the +* memory encryption mask(sme_me_mask), we must remove the memory +* encryption mask to obtain the true physical address in kdump kernel. +*/ + old_devtb_phys =__sme_clr (entry) &PAGE_MASK ; +if (old_devtb_phys >=0x100000000ULL ) {pr_err ("The address of old device table is above 4G, not trustworthy!\n" );return false; } - old_devtb =memremap (old_devtb_phys, dev_table_size,MEMREMAP_WB ); + old_devtb = (sme_active () &&is_kdump_kernel ()) + ? (__force void *)ioremap_encrypted (old_devtb_phys, + dev_table_size) + :memremap (old_devtb_phys, dev_table_size,MEMREMAP_WB ); +if (!old_devtb)return false;
Signature · 1 line
2.17.1
Re: [PATCH 3/4 v7] amd_iommu: remap the device table of IOMMU with the memory encryption mask for kdump
Quoted 5 lines · Lianbo Jiang
In kdump kernel, it will copy the device table of IOMMU from the old device table, which is encrypted when SME is enabled in the first kernel. So we have to remap the old device table with the memory encryption mask.
Signed-off-by Lianbo Jiang <[email protected]>
Please change the subject to:
iommu/amd: Remap the device table of IOMMU with the memory encryption mask for kdump
With that you can add my:
Re: [PATCH 3/4 v7] amd_iommu: remap the device table of IOMMU with the memory encryption mask for kdump
Quoted 7 lines · Joerg Roedel
Quoted 5 lines · Lianbo Jiang
In kdump kernel, it will copy the device table of IOMMU from the old device table, which is encrypted when SME is enabled in the first kernel. So we have to remap the old device table with the memory encryption mask.
Signed-off-by Lianbo Jiang <[email protected]>
Quoted 8 lines
Please change the subject to:
iommu/amd: Remap the device table of IOMMU with the memory encryption mask for kdump
With that you can add my:
Acked-by Joerg Roedel <[email protected]>
Thank you, Joerg.
Sorry for my late reply. I will change the subject and resend this patch.
Thanks.
Lianbo
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
PATCH v7 4/4 kdump/vmcore: support encrypted old memory with SME enabled
In reply to Lianbo JiangIn kdump kernel, we need to dump the old memory into vmcore file,if SME is enabled in the first kernel, we have to remap the old memory with the memory encryption mask, which will be automatically decrypted when we read from DRAM.
For SME kdump, there are two cases that doesn't support:
----------------------------------------------
| first-kernel | second-kernel | kdump support | | (mem_encrypt=on|off) | (yes|no) | |--------------+---------------+---------------| | on | on | yes | | off | off | yes | | on | off | no | | off | on | no | |______________|_______________|_______________|
1. SME is enabled in the first kernel, but SME is disabled in kdump kernel In this case, because the old memory is encrypted, we can't decrypt the old memory.
2. SME is disabled in the first kernel, but SME is enabled in kdump kernel On the one hand, the old memory is unencrypted, the old memory can be dumped as usual, we don't need to enable SME in kdump kernel; On the other hand, it will increase the complexity of the code, we will have to consider how to pass the SME flag from the first kernel to the kdump kernel, it is really too expensive to do this.
This patches are only for SME kdump, the patches don't support SEV kdump.
--- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/crash_dump_encrypt.c | 53 ++++++++++++++++++++++++++++ fs/proc/vmcore.c | 21 +++++++---- include/linux/crash_dump.h | 12 +++++++ 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 arch/x86/kernel/crash_dump_encrypt.c
arch/x86/kernel/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_KEXEC_CORE) += machine_kexec_$(BITS).o obj-$(CONFIG_KEXEC_CORE) += relocate_kernel_$(BITS).o crash.o obj-$(CONFIG_KEXEC_FILE) += kexec-bzimage64.o obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o +obj-$(CONFIG_AMD_MEM_ENCRYPT) += crash_dump_encrypt.o obj-y += kprobes/ obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_DOUBLEFAULT) += doublefault.o
arch/x86/kernel/crash_dump_encrypt.c new file +53 -0
53 lines not on this page · raw message
fs/proc/vmcore.c +15 -6
@@ -25,6 +25,9 @@#include <linux/pagemap.h> #include <linux/uaccess.h> #include <asm/io.h> +#include <linux/io.h> +#include <linux/mem_encrypt.h> +#include <asm/pgtable.h> #include "internal.h" /* List representing chunks of contiguous memory areas and their offsets in
@@ -98,7 +101,8 @@ static int pfn_is_ram(unsigned long pfn)/* Reads a page from the oldmem device from given offset. */ static ssize_t read_from_oldmem (char *buf,size_t count, -u64 *ppos,int userbuf) +u64 *ppos,int userbuf, +bool encrypted) {unsigned long pfn, offset;size_t nr_bytes;
@@ -120,8 +124,11 @@ static ssize_t read_from_oldmem(char *buf, size_t count,if (pfn_is_ram (pfn) ==0 )memset (buf,0 , nr_bytes);else { - tmp =copy_oldmem_page (pfn, buf, nr_bytes, - offset, userbuf); + tmp = encrypted ?copy_oldmem_page_encrypted (pfn, + buf, nr_bytes, offset, userbuf) + :copy_oldmem_page (pfn, buf, nr_bytes, + offset, userbuf); +if (tmp <0 )return tmp; }
@@ -155,7 +162,7 @@ void __weak elfcorehdr_free(unsigned long long addr)*/ ssize_t __weak elfcorehdr_read (char *buf,size_t count,u64 *ppos) { -return read_from_oldmem (buf, count, ppos,0 ); +return read_from_oldmem (buf, count, ppos,0 , false); }/*
@@ -163,7 +170,7 @@ ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos)*/ ssize_t __weak elfcorehdr_read_notes (char *buf,size_t count,u64 *ppos) { -return read_from_oldmem (buf, count, ppos,0 ); +return read_from_oldmem (buf, count, ppos,0 ,sme_active ()); }/*
@@ -173,6 +180,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot) { + prot =pgprot_encrypted (prot);return remap_pfn_range (vma, from, pfn, size, prot); }
@@ -351,7 +359,8 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, m->offset + m->size - *fpos, buflen); start = m->paddr + *fpos - m->offset; - tmp =read_from_oldmem (buffer, tsz, &start, userbuf); + tmp =read_from_oldmem (buffer, tsz, &start, userbuf, +sme_active ());if (tmp <0 )return tmp; buflen -= tsz;
include/linux/crash_dump.h +12 -0
@@ -26,6 +26,18 @@ extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,extern ssize_t copy_oldmem_page (unsigned long ,char *,size_t ,unsigned long ,int ); +#ifdef CONFIG_AMD_MEM_ENCRYPT +extern ssize_t copy_oldmem_page_encrypted (unsigned long pfn,char *buf, +size_t csize,unsigned long offset, +int userbuf); +#else +static inline +ssize_t copy_oldmem_page_encrypted (unsigned long pfn,char *buf,size_t csize, +unsigned long offset,int userbuf) +{ +return 0 ; +} +#endif void vmcore_cleanup (void );/* Architecture code defines this if there are other possible ELF
Signature · 1 line
2.17.1
Quoted 49 lines · Lianbo Jiang
When SME is enabled on AMD machine, we also need to support kdump. Because the memory is encrypted in the first kernel, we will remap the old memory to the kdump kernel for dumping data, and SME is also enabled in the kdump kernel, otherwise the old memory can not be decrypted.
For the kdump, it is necessary to distinguish whether the memory is encrypted. Furthermore, we should also know which part of the memory is encrypted or decrypted. We will appropriately remap the memory according to the specific situation in order to tell cpu how to access the memory.
As we know, a page of memory that is marked as encrypted, which will be automatically decrypted when read from DRAM, and will also be automatically encrypted when written to DRAM. If the old memory is encrypted, we have to remap the old memory with the memory encryption mask, which will automatically decrypt the old memory when we read those data.
For kdump(SME), there are two cases that doesn't support:
----------------------------------------------
| first-kernel | second-kernel | kdump support | | (mem_encrypt=on|off) | (yes|no) | |--------------+---------------+---------------| | on | on | yes | | off | off | yes | | on | off | no | | off | on | no | |______________|_______________|_______________|1. SME is enabled in the first kernel, but SME is disabled in kdump kernel In this case, because the old memory is encrypted, we can't decrypt the old memory.
2. SME is disabled in the first kernel, but SME is enabled in kdump kernel It is unnecessary to support in this case, because the old memory is unencrypted, the old memory can be dumped as usual, we don't need to enable SME in kdump kernel. Another, If we must support the scenario, it will increase the complexity of the code, we will have to consider how to pass the SME flag from the first kernel to the kdump kernel, in order to let the kdump kernel know that whether the old memory is encrypted.
There are two methods to pass the SME flag to the kdump kernel. The first method is to modify the assembly code, which includes some common code and the path is too long. The second method is to use kexec tool, which could require the SME flag to be exported in the first kernel by "proc" or "sysfs", kexec tools will read the SME flag from "proc" or "sysfs" when we use kexec tools to load image, subsequently the SME flag will be saved in
boot_params, we can properly remap the old memory according to the previously saved SME flag. But it is too expensive to do this.
Quoted 1 line
This patches are only for SME kdump, the patches don't support SEV kdump.
Just curious, are you planning to add SEV kdump support after this?
Also, a question below...
Quoted 60 lines
Test tools:
makedumpfile[v1.6.3]: https://github.com/LianboJ/makedumpfile
commite1de103eca8f(A draft for kdump vmcore about AMD SME)
Note: This patch can only dump vmcore in the case of SME enabled.crash-7.2.3: https://github.com/crash-utility/crash.git
commit001f77a05585(Fix for Linux 4.19-rc1 and later kernels that containkernel commit7290d58095712a89f845e1bca05334796dd49ed2)kexec-tools-2.0.17:
git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
commitb9de21ef51a7(kexec: fix for "Unhandled rela relocation:R_X86_64_PLT32" error)
Note:
Before you load the kernel and initramfs for kdump, this patch(http://lists.infradead.org/pipermail/kexec/2018-September/021460.html) must be merged to kexec-tools, and then the kdump kernel will work well. Because there
is a patch which is removed based on v6(x86/ioremap: strengthen the logic inearly_memremap_pgprot_adjust()
to adjust encryption mask).Test environment:
HP ProLiant DL385Gen10 AMD EPYC 7251
8-Core Processor
32768 MB memory
600 GB disk spaceLinux 4.19-rc2:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
commit57361846b52bc686112da6ca5368d11210796804Reference:
AMD64 Architecture Programmer's Manual
https://support.amd.com/TechDocs/24593.pdfChanges since v6:
1. There is a patch which is removed based on v6.
(x86/ioremap: strengthen the logic inearly_memremap_pgprot_adjust()to adjust encryption mask) Dave Young suggests that this patch can be removed and fix the kexec-tools.
Reference: http://lists.infradead.org/pipermail/kexec/2018-September/021460.html)
2. Update the patch log.Some known issues:
1. about SME
Upstream kernel will hang on HP machine(DL385Gen10 AMD EPYC 7251) when we execute the kexec command as follow:# kexec -l /boot/vmlinuz-4.19.0-rc2+ --initrd=/boot/initramfs-4.19.0-rc2+.img --command-line="root=/dev/mapper/rhel_hp--dl385g10--03-root ro mem_encrypt=on rd.lvm.lv=rhel_hp-dl385g10-03/root rd.lvm.lv=rhel_hp-dl385g10-03/swap console=ttyS0,115200n81 LANG=en_US.UTF-8 earlyprintk=serial debug nokaslr" # kexec -e (or reboot)But this issue can not be reproduced on speedway machine, and this issue is irrelevant to my posted patches.
The kernel log:
[ 1248.932239] kexec_core: Starting new kernelearly console in
extract_kernelinput_data:0x000000087e91c3b4input_len:0x000000000067fcbd
output:0x000000087d400000output_len:0x0000000001b6fa90kernel_total_size:0x0000000001a9d000trampoline_32bit:0x0000000000099000
Quoted 2 lines
Decompressing Linux...
Parsing ELF... [---Here the system will hang]
Do you know the reason for the hang? It looks like it is hanging in parse_elf(). Can you add some debug to parse_elf() to see if the value of ehdr.e_phnum is valid (maybe it is not a valid value and so the loop takes forever)?
Thanks,
Tom
Quoted 22 lines
Lianbo Jiang (4):
x86/ioremap: add a functionioremap_encrypted()to remap kdump old
memory
kexec: allocate unencrypted control pages for kdump in case SME is
enabled
amd_iommu: remap the device table of IOMMU with the memory encryption
mask for kdump
kdump/vmcore: support encrypted old memory with SME enabledarch/x86/include/asm/io.h | 3 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/crash_dump_encrypt.c | 53 ++++++++++++++++++++++++++++ arch/x86/mm/ioremap.c | 25 ++++++++----- drivers/iommu/amd_iommu_init.c | 14 ++++++-- fs/proc/vmcore.c | 21 +++++++---- include/linux/crash_dump.h | 12 +++++++ kernel/kexec_core.c | 12 +++++++ 8 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 arch/x86/kernel/crash_dump_encrypt.c
Quoted 50 lines · Thomas
Quoted 49 lines · Lianbo Jiang
When SME is enabled on AMD machine, we also need to support kdump. Because the memory is encrypted in the first kernel, we will remap the old memory to the kdump kernel for dumping data, and SME is also enabled in the kdump kernel, otherwise the old memory can not be decrypted.
For the kdump, it is necessary to distinguish whether the memory is encrypted. Furthermore, we should also know which part of the memory is encrypted or decrypted. We will appropriately remap the memory according to the specific situation in order to tell cpu how to access the memory.
As we know, a page of memory that is marked as encrypted, which will be automatically decrypted when read from DRAM, and will also be automatically encrypted when written to DRAM. If the old memory is encrypted, we have to remap the old memory with the memory encryption mask, which will automatically decrypt the old memory when we read those data.
For kdump(SME), there are two cases that doesn't support:
----------------------------------------------
| first-kernel | second-kernel | kdump support | | (mem_encrypt=on|off) | (yes|no) | |--------------+---------------+---------------| | on | on | yes | | off | off | yes | | on | off | no | | off | on | no | |______________|_______________|_______________|1. SME is enabled in the first kernel, but SME is disabled in kdump kernel In this case, because the old memory is encrypted, we can't decrypt the old memory.
2. SME is disabled in the first kernel, but SME is enabled in kdump kernel It is unnecessary to support in this case, because the old memory is unencrypted, the old memory can be dumped as usual, we don't need to enable SME in kdump kernel. Another, If we must support the scenario, it will increase the complexity of the code, we will have to consider how to pass the SME flag from the first kernel to the kdump kernel, in order to let the kdump kernel know that whether the old memory is encrypted.
There are two methods to pass the SME flag to the kdump kernel. The first method is to modify the assembly code, which includes some common code and the path is too long. The second method is to use kexec tool, which could require the SME flag to be exported in the first kernel by "proc" or "sysfs", kexec tools will read the SME flag from "proc" or "sysfs" when we use kexec tools to load image, subsequently the SME flag will be saved in
boot_params, we can properly remap the old memory according to the previously saved SME flag. But it is too expensive to do this.
Quoted 4 lines
Quoted 1 line
This patches are only for SME kdump, the patches don't support SEV kdump.
Reviewed-by Tom Lendacky <[email protected]>
Thank you, Tom. I'm very glad that you would like to review my patches, and also gave me some advice to improve these patches.
Quoted 2 lines
Just curious, are you planning to add SEV kdump support after this?
Yes, we are planning to add SEV kdump support after this.
And i also welcome that you would like to review my SEV kdump patch again.
Quoted 62 lines
Also, a question below...
Quoted 60 lines
Test tools:
makedumpfile[v1.6.3]: https://github.com/LianboJ/makedumpfile
commite1de103eca8f(A draft for kdump vmcore about AMD SME)
Note: This patch can only dump vmcore in the case of SME enabled.crash-7.2.3: https://github.com/crash-utility/crash.git
commit001f77a05585(Fix for Linux 4.19-rc1 and later kernels that containkernel commit7290d58095712a89f845e1bca05334796dd49ed2)kexec-tools-2.0.17:
git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
commitb9de21ef51a7(kexec: fix for "Unhandled rela relocation:R_X86_64_PLT32" error)
Note:
Before you load the kernel and initramfs for kdump, this patch(http://lists.infradead.org/pipermail/kexec/2018-September/021460.html) must be merged to kexec-tools, and then the kdump kernel will work well. Because there
is a patch which is removed based on v6(x86/ioremap: strengthen the logic inearly_memremap_pgprot_adjust()
to adjust encryption mask).Test environment:
HP ProLiant DL385Gen10 AMD EPYC 7251
8-Core Processor
32768 MB memory
600 GB disk spaceLinux 4.19-rc2:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
commit57361846b52bc686112da6ca5368d11210796804Reference:
AMD64 Architecture Programmer's Manual
https://support.amd.com/TechDocs/24593.pdfChanges since v6:
1. There is a patch which is removed based on v6.
(x86/ioremap: strengthen the logic inearly_memremap_pgprot_adjust()to adjust encryption mask) Dave Young suggests that this patch can be removed and fix the kexec-tools.
Reference: http://lists.infradead.org/pipermail/kexec/2018-September/021460.html)
2. Update the patch log.Some known issues:
1. about SME
Upstream kernel will hang on HP machine(DL385Gen10 AMD EPYC 7251) when we execute the kexec command as follow:# kexec -l /boot/vmlinuz-4.19.0-rc2+ --initrd=/boot/initramfs-4.19.0-rc2+.img --command-line="root=/dev/mapper/rhel_hp--dl385g10--03-root ro mem_encrypt=on rd.lvm.lv=rhel_hp-dl385g10-03/root rd.lvm.lv=rhel_hp-dl385g10-03/swap console=ttyS0,115200n81 LANG=en_US.UTF-8 earlyprintk=serial debug nokaslr" # kexec -e (or reboot)But this issue can not be reproduced on speedway machine, and this issue is irrelevant to my posted patches.
The kernel log:
[ 1248.932239] kexec_core: Starting new kernelearly console in
extract_kernelinput_data:0x000000087e91c3b4input_len:0x000000000067fcbd
output:0x000000087d400000output_len:0x0000000001b6fa90kernel_total_size:0x0000000001a9d000trampoline_32bit:0x0000000000099000
Quoted 8 lines
Quoted 2 lines
Decompressing Linux...
Parsing ELF... [---Here the system will hang]Do you know the reason for the hang? It looks like it is hanging in
parse_elf(). Can you add some debug toparse_elf()to see if the value of ehdr.e_phnum is valid (maybe it is not a valid value and so the loop takes forever)?
Previously, i had loaned a speedway machine, however i could not reproduce this issue on this machine. But on the 'HP ProLiant DL385Gen10' machine, this issue was always reproduced.(btw: the code is the same.)
I'm not sure whether this issue is relate to hardware. I had printed these values, and i remembered that the value of ehdr.e_phum was valid.
Because this issue is only reproduced on DL385Gen10 machine, i decreased the priority of dealing with this issue.
If you also care about this issue, i can create a new email thread to trace this issue. What do you think about this?
Thanks
Lianbo
Quoted 25 lines
Thanks,
TomQuoted 11 lines
Lianbo Jiang (4):
x86/ioremap: add a functionioremap_encrypted()to remap kdump old
memory
kexec: allocate unencrypted control pages for kdump in case SME is
enabled
amd_iommu: remap the device table of IOMMU with the memory encryption
mask for kdump
kdump/vmcore: support encrypted old memory with SME enabledQuoted 11 lines
arch/x86/include/asm/io.h | 3 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/crash_dump_encrypt.c | 53 ++++++++++++++++++++++++++++ arch/x86/mm/ioremap.c | 25 ++++++++----- drivers/iommu/amd_iommu_init.c | 14 ++++++-- fs/proc/vmcore.c | 21 +++++++---- include/linux/crash_dump.h | 12 +++++++ kernel/kexec_core.c | 12 +++++++ 8 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 arch/x86/kernel/crash_dump_encrypt.c
Quoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Also cc maintainer and other reviewer. Thanks.
Quoted 188 lines · lijiang
Quoted 50 lines · Thomas
Quoted 49 lines · Lianbo Jiang
When SME is enabled on AMD machine, we also need to support kdump. Because the memory is encrypted in the first kernel, we will remap the old memory to the kdump kernel for dumping data, and SME is also enabled in the kdump kernel, otherwise the old memory can not be decrypted.
For the kdump, it is necessary to distinguish whether the memory is encrypted. Furthermore, we should also know which part of the memory is encrypted or decrypted. We will appropriately remap the memory according to the specific situation in order to tell cpu how to access the memory.
As we know, a page of memory that is marked as encrypted, which will be automatically decrypted when read from DRAM, and will also be automatically encrypted when written to DRAM. If the old memory is encrypted, we have to remap the old memory with the memory encryption mask, which will automatically decrypt the old memory when we read those data.
For kdump(SME), there are two cases that doesn't support:
----------------------------------------------
| first-kernel | second-kernel | kdump support | | (mem_encrypt=on|off) | (yes|no) | |--------------+---------------+---------------| | on | on | yes | | off | off | yes | | on | off | no | | off | on | no | |______________|_______________|_______________|1. SME is enabled in the first kernel, but SME is disabled in kdump kernel In this case, because the old memory is encrypted, we can't decrypt the old memory.
2. SME is disabled in the first kernel, but SME is enabled in kdump kernel It is unnecessary to support in this case, because the old memory is unencrypted, the old memory can be dumped as usual, we don't need to enable SME in kdump kernel. Another, If we must support the scenario, it will increase the complexity of the code, we will have to consider how to pass the SME flag from the first kernel to the kdump kernel, in order to let the kdump kernel know that whether the old memory is encrypted.
There are two methods to pass the SME flag to the kdump kernel. The first method is to modify the assembly code, which includes some common code and the path is too long. The second method is to use kexec tool, which could require the SME flag to be exported in the first kernel by "proc" or "sysfs", kexec tools will read the SME flag from "proc" or "sysfs" when we use kexec tools to load image, subsequently the SME flag will be saved in
boot_params, we can properly remap the old memory according to the previously saved SME flag. But it is too expensive to do this.Quoted 4 lines
Quoted 1 line
This patches are only for SME kdump, the patches don't support SEV kdump.
Reviewed-by Tom Lendacky <[email protected]>Thank you, Tom. I'm very glad that you would like to review my patches, and also gave me some advice to improve these patches.
Quoted 2 lines
Just curious, are you planning to add SEV kdump support after this?
Yes, we are planning to add SEV kdump support after this.
And i also welcome that you would like to review my SEV kdump patch again.Quoted 62 lines
Also, a question below...
Quoted 60 lines
Test tools:
makedumpfile[v1.6.3]: https://github.com/LianboJ/makedumpfile
commite1de103eca8f(A draft for kdump vmcore about AMD SME)
Note: This patch can only dump vmcore in the case of SME enabled.crash-7.2.3: https://github.com/crash-utility/crash.git
commit001f77a05585(Fix for Linux 4.19-rc1 and later kernels that containkernel commit7290d58095712a89f845e1bca05334796dd49ed2)kexec-tools-2.0.17:
git://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git
commitb9de21ef51a7(kexec: fix for "Unhandled rela relocation:R_X86_64_PLT32" error)
Note:
Before you load the kernel and initramfs for kdump, this patch(http://lists.infradead.org/pipermail/kexec/2018-September/021460.html) must be merged to kexec-tools, and then the kdump kernel will work well. Because there
is a patch which is removed based on v6(x86/ioremap: strengthen the logic inearly_memremap_pgprot_adjust()
to adjust encryption mask).Test environment:
HP ProLiant DL385Gen10 AMD EPYC 7251
8-Core Processor
32768 MB memory
600 GB disk spaceLinux 4.19-rc2:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
commit57361846b52bc686112da6ca5368d11210796804Reference:
AMD64 Architecture Programmer's Manual
https://support.amd.com/TechDocs/24593.pdfChanges since v6:
1. There is a patch which is removed based on v6.
(x86/ioremap: strengthen the logic inearly_memremap_pgprot_adjust()to adjust encryption mask) Dave Young suggests that this patch can be removed and fix the kexec-tools.
Reference: http://lists.infradead.org/pipermail/kexec/2018-September/021460.html)
2. Update the patch log.Some known issues:
1. about SME
Upstream kernel will hang on HP machine(DL385Gen10 AMD EPYC 7251) when we execute the kexec command as follow:# kexec -l /boot/vmlinuz-4.19.0-rc2+ --initrd=/boot/initramfs-4.19.0-rc2+.img --command-line="root=/dev/mapper/rhel_hp--dl385g10--03-root ro mem_encrypt=on rd.lvm.lv=rhel_hp-dl385g10-03/root rd.lvm.lv=rhel_hp-dl385g10-03/swap console=ttyS0,115200n81 LANG=en_US.UTF-8 earlyprintk=serial debug nokaslr" # kexec -e (or reboot)But this issue can not be reproduced on speedway machine, and this issue is irrelevant to my posted patches.
The kernel log:
[ 1248.932239] kexec_core: Starting new kernelearly console in
extract_kernelinput_data:0x000000087e91c3b4input_len:0x000000000067fcbd
output:0x000000087d400000output_len:0x0000000001b6fa90kernel_total_size:0x0000000001a9d000trampoline_32bit:0x0000000000099000Quoted 8 lines
Quoted 2 lines
Decompressing Linux...
Parsing ELF... [---Here the system will hang]Do you know the reason for the hang? It looks like it is hanging in
parse_elf(). Can you add some debug toparse_elf()to see if the value of ehdr.e_phnum is valid (maybe it is not a valid value and so the loop takes forever)?Previously, i had loaned a speedway machine, however i could not reproduce this issue on this machine. But on the 'HP ProLiant DL385Gen10' machine, this issue was always reproduced.(btw: the code is the same.)
I'm not sure whether this issue is relate to hardware. I had printed these values, and i remembered that the value of ehdr.e_phum was valid.
Because this issue is only reproduced on DL385Gen10 machine, i decreased the priority of dealing with this issue.
If you also care about this issue, i can create a new email thread to trace this issue. What do you think about this?
Thanks
LianboQuoted 25 lines
Thanks,
TomQuoted 11 lines
Lianbo Jiang (4):
x86/ioremap: add a functionioremap_encrypted()to remap kdump old
memory
kexec: allocate unencrypted control pages for kdump in case SME is
enabled
amd_iommu: remap the device table of IOMMU with the memory encryption
mask for kdump
kdump/vmcore: support encrypted old memory with SME enabledQuoted 11 lines
arch/x86/include/asm/io.h | 3 ++ arch/x86/kernel/Makefile | 1 + arch/x86/kernel/crash_dump_encrypt.c | 53 ++++++++++++++++++++++++++++ arch/x86/mm/ioremap.c | 25 ++++++++----- drivers/iommu/amd_iommu_init.c | 14 ++++++-- fs/proc/vmcore.c | 21 +++++++---- include/linux/crash_dump.h | 12 +++++++ kernel/kexec_core.c | 12 +++++++ 8 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 arch/x86/kernel/crash_dump_encrypt.cQuoted 5 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec