The SEV GHCB specification defines two methods for a guest to register
its GHCB page with the hypervisor: an MSR-based protocol and a GPA-based
protocol. The hypervisor (KVM) distinguishes between them by inspecting
the value written to the MSR_AMD64_SEV_ES_GHCB MSR. If the value has its
lower 12 bits as zero, it is treated as a page-aligned Guest Physical
Address (GPA). Otherwise, it is interpreted as a command for the
MSR-based protocol.
The selftest's ghcb_entry struct is not explicitly page-aligned. When
the test guest attemptd to register the GHCB by writing its unaligned
GPA to the MSR, KVM would incorrectly interpret the request as a
malformed MSR-based command instead of a GPA registration. This caused
GHCB initialization to fail.
Fix this by aligning the ghcb_entry struct definition to PAGE_SIZE.
This forces the structure to be page-aligned, ensuring its GPA has
zero in the lower 12 bits and allowing KVM to correctly recognize
it as a GPA registration request.
Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
---
tools/testing/selftests/kvm/lib/x86/sev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kvm/lib/x86/sev.c b/tools/testing/selftests/kvm/lib/x86/sev.c
index 3090a6518066..edefba7f49ce 100644
--- a/tools/testing/selftests/kvm/lib/x86/sev.c
+++ b/tools/testing/selftests/kvm/lib/x86/sev.c
@@ -22,7 +22,7 @@ struct ghcb_entry {
/* Host virtual address of this struct. */
struct ghcb_entry *hva;
-};
+} __aligned(PAGE_SIZE);
struct ghcb_header {
struct ghcb_entry ghcbs[KVM_MAX_VCPUS];
--
2.34.1