x86/sev: Fix making shared pages private during kdump
Subsystems (4)
PATCH v5 1/1 x86/sev: Fix making shared pages private during kdump
From: Ashish Kalra <[email protected]>
When the shared pages are being made private during kdump preparation there are additional checks to handle shared GHCB pages.
These additional checks include handling the case of GHCB page being contained within a huge page.
The check for handling the case of GHCB contained within a huge page incorrectly skips a page just below the GHCB page from being transitioned back to private during kdump preparation.
This skipped page causes a 0x404 #VC exception when it is accessed later while dumping guest memory during vmcore generation via kdump.
Correct the range to be checked for GHCB contained in a huge page. Also ensure that the skipped huge page containing the GHCB page is transitioned back to private by applying the correct address mask later when changing GHCBs to private at end of kdump preparation.
--- arch/x86/coco/sev/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/coco/sev/core.c +7 -4
@@ -1019,7 +1019,8 @@ static void unshare_all_memory(void) data =per_cpu (runtime_data, cpu); ghcb = (unsigned long )&data->ghcb_page; -if (addr <= ghcb && ghcb <= addr + size) { +/* Handle the case of a huge page containing the GHCB page */ +if (addr <= ghcb && ghcb < addr + size) { skipped_addr = true;break ; }
@@ -1131,8 +1132,8 @@ static void shutdown_all_aps(void)void snp_kexec_finish (void ) {struct sev_es_runtime_data *data; +unsigned long size, addr;unsigned int level, cpu; -unsigned long size;struct ghcb *ghcb;pte_t *pte;
@@ -1160,8 +1161,10 @@ void snp_kexec_finish(void) ghcb = &data->ghcb_page; pte =lookup_address ((unsigned long )ghcb, &level); size =page_level_size (level); -set_pte_enc (pte, level, (void *)ghcb); -snp_set_memory_private ((unsigned long )ghcb, (size /PAGE_SIZE )); +/* Handle the case of a huge page containing the GHCB page */ + addr = (unsigned long )ghcb &page_level_mask (level); +set_pte_enc (pte, level, (void *)addr); +snp_set_memory_private (addr, (size /PAGE_SIZE )); } }
Signature · 1 line
2.34.1
Borislav Petkov
maintainerQuoted 20 lines · Ashish Kalra
From: Ashish Kalra <[email protected]>
When the shared pages are being made private during kdump preparation there are additional checks to handle shared GHCB pages.
These additional checks include handling the case of GHCB page being contained within a huge page.
The check for handling the case of GHCB contained within a huge page incorrectly skips a page just below the GHCB page from being transitioned back to private during kdump preparation.
This skipped page causes a
0x404#VC exception when it is accessed later while dumping guest memory during vmcore generation via kdump.Correct the range to be checked for GHCB contained in a huge page. Also ensure that the skipped huge page containing the GHCB page is transitioned back to private by applying the correct address mask later when changing GHCBs to private at end of kdump preparation.
Quoted 6 lines
Fixes 3074152e56c9 ("x86/sev: Convert shared memory back to private on kexec")Signed-off-by Ashish Kalra <[email protected]>--- arch/x86/coco/sev/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Ok, I've pushed both patches here:
https://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git/log/?h=tip-x86-urgent-sev
Please have those who are affected by the issues test and report back.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteAithal, Srikanth
Tested-byQuoted 28 lines · Borislav Petkov
Quoted 20 lines · Ashish Kalra
From: Ashish Kalra <[email protected]>
When the shared pages are being made private during kdump preparation there are additional checks to handle shared GHCB pages.
These additional checks include handling the case of GHCB page being contained within a huge page.
The check for handling the case of GHCB contained within a huge page incorrectly skips a page just below the GHCB page from being transitioned back to private during kdump preparation.
This skipped page causes a
0x404#VC exception when it is accessed later while dumping guest memory during vmcore generation via kdump.Correct the range to be checked for GHCB contained in a huge page. Also ensure that the skipped huge page containing the GHCB page is transitioned back to private by applying the correct address mask later when changing GHCBs to private at end of kdump preparation.
Quoted 6 lines
Fixes 3074152e56c9 ("x86/sev: Convert shared memory back to private on kexec")Signed-off-by Ashish Kalra <[email protected]>--- arch/x86/coco/sev/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 8 lines
Ok, I've pushed both patches here:
https://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git/log/?h=tip-x86-urgent-sev
Please have those who are affected by the issues test and report back.
Thx.
I tested the failure scenario with the patch hosted in the referenced Git tree [1]. The patch resolves the issue.
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git/log/?h=tip-x86-urgent-sev
Quoted 15 lines · Ashish Kalra
From: Ashish Kalra <[email protected]>
When the shared pages are being made private during kdump preparation there are additional checks to handle shared GHCB pages.
These additional checks include handling the case of GHCB page being contained within a huge page.
The check for handling the case of GHCB contained within a huge page incorrectly skips a page just below the GHCB page from being transitioned back to private during kdump preparation.
This skipped page causes a
0x404#VC exception when it is accessed later while dumping guest memory during vmcore generation via kdump.
Quoted 8 lines
Correct the range to be checked for GHCB contained in a huge page. Also ensure that the skipped huge page containing the GHCB page is transitioned back to private by applying the correct address mask later when changing GHCBs to private at end of kdump preparation.
Fixes 3074152e56c9 ("x86/sev: Convert shared memory back to private on kexec")Signed-off-by Ashish Kalra <[email protected]>
Quoted 41 lines
--- arch/x86/coco/sev/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)arch/x86/coco/sev/core.c +7
-4@@ -1019,7 +1019,8 @@ static void unshare_all_memory(void) data =per_cpu (runtime_data, cpu); ghcb = (unsigned long )&data->ghcb_page; -if (addr <= ghcb && ghcb <= addr + size) { +/* Handle the case of a huge page containing the GHCB page */ +if (addr <= ghcb && ghcb < addr + size) { skipped_addr = true;break ; }@@ -1131,8 +1132,8 @@ static void shutdown_all_aps(void)void snp_kexec_finish (void ) {struct sev_es_runtime_data *data; +unsigned long size, addr;unsigned int level, cpu; -unsigned long size;struct ghcb *ghcb;pte_t *pte;@@ -1160,8 +1161,10 @@ void snp_kexec_finish(void) ghcb = &data->ghcb_page; pte =lookup_address ((unsigned long )ghcb, &level); size =page_level_size (level); -set_pte_enc (pte, level, (void *)ghcb); -snp_set_memory_private ((unsigned long )ghcb, (size /PAGE_SIZE )); +/* Handle the case of a huge page containing the GHCB page */ + addr = (unsigned long )ghcb &page_level_mask (level); +set_pte_enc (pte, level, (void *)addr); +snp_set_memory_private (addr, (size /PAGE_SIZE )); } }
[tip: x86/urgent] x86/sev: Make sure pages are not skipped during kdump
In reply to Ashish KalraThe following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 82b7f88f2316c5442708daeb0b5ec5aa54c8ff7f Gitweb: https://git.kernel.org/tip/82b7f88f2316c5442708daeb0b5ec5aa54c8ff7f Author: Ashish Kalra <[email protected]> AuthorDate: Tue, 06 May 2025 18:35:29 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 13 May 2025 19:47:48 +02:00
x86/sev: Make sure pages are not skipped during kdump
When shared pages are being converted to private during kdump, additional checks are performed. They include handling the case of a GHCB page being contained within a huge page.
Currently, this check incorrectly skips a page just below the GHCB page from being transitioned back to private during kdump preparation.
This skipped page causes a 0x404 #VC exception when it is accessed later while dumping guest memory for vmcore generation.
Correct the range to be checked for GHCB contained in a huge page. Also, ensure that the skipped huge page containing the GHCB page is transitioned back to private by applying the correct address mask later when changing GHCBs to private at end of kdump preparation.
[ bp: Massage commit message. ]
--- arch/x86/coco/sev/core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/coco/sev/core.c +7 -4
@@ -1101,7 +1101,8 @@ static void unshare_all_memory(void) data =per_cpu (runtime_data, cpu); ghcb = (unsigned long )&data->ghcb_page; -if (addr <= ghcb && ghcb <= addr + size) { +/* Handle the case of a huge page containing the GHCB page */ +if (addr <= ghcb && ghcb < addr + size) { skipped_addr = true;break ; }
@@ -1213,8 +1214,8 @@ static void shutdown_all_aps(void)void snp_kexec_finish (void ) {struct sev_es_runtime_data *data; +unsigned long size, addr;unsigned int level, cpu; -unsigned long size;struct ghcb *ghcb;pte_t *pte;
@@ -1242,8 +1243,10 @@ void snp_kexec_finish(void) ghcb = &data->ghcb_page; pte =lookup_address ((unsigned long )ghcb, &level); size =page_level_size (level); -set_pte_enc (pte, level, (void *)ghcb); -snp_set_memory_private ((unsigned long )ghcb, (size /PAGE_SIZE )); +/* Handle the case of a huge page containing the GHCB page */ + addr = (unsigned long )ghcb &page_level_mask (level); +set_pte_enc (pte, level, (void *)addr); +snp_set_memory_private (addr, (size /PAGE_SIZE )); } }