diff mbox series

[kvm-unit-tests,RFC,3/3] x86 AMD SEV-ES: Setup a new page table and install level 1 PTEs

Message ID 20240325213623.747590-3-papaluri@amd.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests,RFC,1/3] x86 EFI: Bypass call to fdt_check_header() | expand

Commit Message

Paluri, PavanKumar March 25, 2024, 9:36 p.m. UTC
KUT's UEFI tests don't currently have support for page allocation.
SEV-ES/SNP tests will need this later, so the support for page
allocation is provided via setup_vm().

SEV-ES/SNP guest uses GHCB page to communicate with the host. Such a
page should remain unencrypted (its c-bit should be unset). Therefore,
call setup_ghcb_pte() in the path of setup_vm() to make sure c-bit of
GHCB's pte is unset.

Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
---
 lib/x86/vm.c  | 6 ++++++
 x86/amd_sev.c | 7 +++++++
 2 files changed, 13 insertions(+)

Comments

Tom Lendacky March 26, 2024, 2:01 p.m. UTC | #1
On 3/25/24 16:36, Pavan Kumar Paluri wrote:
> KUT's UEFI tests don't currently have support for page allocation.
> SEV-ES/SNP tests will need this later, so the support for page
> allocation is provided via setup_vm().
> 
> SEV-ES/SNP guest uses GHCB page to communicate with the host. Such a
> page should remain unencrypted (its c-bit should be unset). Therefore,
> call setup_ghcb_pte() in the path of setup_vm() to make sure c-bit of
> GHCB's pte is unset.

This looks like it should be 2 separate patches. One for supporting page 
allocation and one for setting the GHCB page attributes.

Thanks,
Tom

> 
> Signed-off-by: Pavan Kumar Paluri <papaluri@amd.com>
> ---
>   lib/x86/vm.c  | 6 ++++++
>   x86/amd_sev.c | 7 +++++++
>   2 files changed, 13 insertions(+)
> 
> diff --git a/lib/x86/vm.c b/lib/x86/vm.c
> index 90f73fbb2dfd..ce2063aee75d 100644
> --- a/lib/x86/vm.c
> +++ b/lib/x86/vm.c
> @@ -3,6 +3,7 @@
>   #include "vmalloc.h"
>   #include "alloc_page.h"
>   #include "smp.h"
> +#include "amd_sev.h"
>   
>   static pteval_t pte_opt_mask;
>   
> @@ -197,6 +198,11 @@ void *setup_mmu(phys_addr_t end_of_memory, void *opt_mask)
>       init_alloc_vpage((void*)(3ul << 30));
>   #endif
>   
> +#ifdef CONFIG_EFI
> +	if (amd_sev_es_enabled())
> +		setup_ghcb_pte(cr3);
> +#endif
> +
>       write_cr3(virt_to_phys(cr3));
>   #ifndef __x86_64__
>       write_cr4(X86_CR4_PSE);
> diff --git a/x86/amd_sev.c b/x86/amd_sev.c
> index 7757d4f85b7a..03636e581dfe 100644
> --- a/x86/amd_sev.c
> +++ b/x86/amd_sev.c
> @@ -14,6 +14,8 @@
>   #include "x86/processor.h"
>   #include "x86/amd_sev.h"
>   #include "msr.h"
> +#include "x86/vm.h"
> +#include "alloc_page.h"
>   
>   #define EXIT_SUCCESS 0
>   #define EXIT_FAILURE 1
> @@ -89,9 +91,14 @@ static void test_stringio(void)
>   int main(void)
>   {
>   	int rtn;
> +	unsigned long *vaddr;
>   	rtn = test_sev_activation();
>   	report(rtn == EXIT_SUCCESS, "SEV activation test.");
>   	test_sev_es_activation();
>   	test_stringio();
> +	setup_vm();
> +	vaddr = alloc_page();
> +	if (!vaddr)
> +		assert_msg(vaddr, "Page allocation Failure");
>   	return report_summary();
>   }
Paluri, PavanKumar March 26, 2024, 3:35 p.m. UTC | #2
On 3/26/2024 9:01 AM, Tom Lendacky wrote:
> On 3/25/24 16:36, Pavan Kumar Paluri wrote:
>> KUT's UEFI tests don't currently have support for page allocation.
>> SEV-ES/SNP tests will need this later, so the support for page
>> allocation is provided via setup_vm().
>>
>> SEV-ES/SNP guest uses GHCB page to communicate with the host. Such a
>> page should remain unencrypted (its c-bit should be unset). Therefore,
>> call setup_ghcb_pte() in the path of setup_vm() to make sure c-bit of
>> GHCB's pte is unset.
> 
> This looks like it should be 2 separate patches. One for supporting page
> allocation and one for setting the GHCB page attributes.
> 

Sure, I will separate this into 2 patches, the GHCB page attribute patch
followed by the page allocation support.

Thanks,
Pavan
> Thanks,
> Tom
>
diff mbox series

Patch

diff --git a/lib/x86/vm.c b/lib/x86/vm.c
index 90f73fbb2dfd..ce2063aee75d 100644
--- a/lib/x86/vm.c
+++ b/lib/x86/vm.c
@@ -3,6 +3,7 @@ 
 #include "vmalloc.h"
 #include "alloc_page.h"
 #include "smp.h"
+#include "amd_sev.h"
 
 static pteval_t pte_opt_mask;
 
@@ -197,6 +198,11 @@  void *setup_mmu(phys_addr_t end_of_memory, void *opt_mask)
     init_alloc_vpage((void*)(3ul << 30));
 #endif
 
+#ifdef CONFIG_EFI
+	if (amd_sev_es_enabled())
+		setup_ghcb_pte(cr3);
+#endif
+
     write_cr3(virt_to_phys(cr3));
 #ifndef __x86_64__
     write_cr4(X86_CR4_PSE);
diff --git a/x86/amd_sev.c b/x86/amd_sev.c
index 7757d4f85b7a..03636e581dfe 100644
--- a/x86/amd_sev.c
+++ b/x86/amd_sev.c
@@ -14,6 +14,8 @@ 
 #include "x86/processor.h"
 #include "x86/amd_sev.h"
 #include "msr.h"
+#include "x86/vm.h"
+#include "alloc_page.h"
 
 #define EXIT_SUCCESS 0
 #define EXIT_FAILURE 1
@@ -89,9 +91,14 @@  static void test_stringio(void)
 int main(void)
 {
 	int rtn;
+	unsigned long *vaddr;
 	rtn = test_sev_activation();
 	report(rtn == EXIT_SUCCESS, "SEV activation test.");
 	test_sev_es_activation();
 	test_stringio();
+	setup_vm();
+	vaddr = alloc_page();
+	if (!vaddr)
+		assert_msg(vaddr, "Page allocation Failure");
 	return report_summary();
 }