@@ -13,6 +13,7 @@
#include "libcflat.h"
#include "x86/processor.h"
#include "x86/amd_sev.h"
+#include "msr.h"
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
@@ -55,10 +56,42 @@ static int test_sev_activation(void)
return EXIT_SUCCESS;
}
+#ifdef CONFIG_AMD_SEV_ES
+static int test_sev_es_activation(void)
+{
+ if (!(rdmsr(MSR_SEV_STATUS) & SEV_ES_ENABLED_MASK)) {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+static int test_sev_es_msr(void)
+{
+ /* With SEV-ES, rdmsr/wrmsr trigger #VC exception. If #VC is handled
+ * correctly, rdmsr/wrmsr should work like without SEV-ES and not crash
+ * the guest VM.
+ */
+ u64 val = 0x1234;
+ wrmsr(MSR_TSC_AUX, val);
+ if(val != rdmsr(MSR_TSC_AUX)) {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+#endif /* CONFIG_AMD_SEV_ES */
+
int main(void)
{
int rtn;
rtn = test_sev_activation();
report(rtn == EXIT_SUCCESS, "SEV activation test.");
+#ifdef CONFIG_AMD_SEV_ES
+ rtn = test_sev_es_activation();
+ report(rtn == EXIT_SUCCESS, "SEV-ES activation test.");
+ rtn = test_sev_es_msr();
+ report(rtn == EXIT_SUCCESS, "SEV-ES MSR test.");
+#endif /* CONFIG_AMD_SEV_ES */
return report_summary();
}
SEV-ES introduces #VC handler for guest/host communications, e.g., accessing MSR, executing CPUID. This commit provides test cases to check if SEV-ES is enabled and if rdmsr/wrmsr are handled correctly in SEV-ES. Signed-off-by: Zixuan Wang <zixuanwang@google.com> --- x86/amd_sev.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)