Re: [PATCH v7 09/31] OvmfPkg/SecMain: register GHCB gpa for the SEV-SNP guest

Brijesh Singh

On 9/15/21 12:08 PM, Erdem Aktas wrote:
On Mon, Sep 13, 2021 at 9:20 PM Brijesh Singh <brijesh.singh@...> wrote:
+SevSnpGhcbRegister (
+ UINTN Address
+ )
+ GuestFrameNumber = Address >> EFI_PAGE_SHIFT;
+ //
+ // Save the current MSR Value
+ //
+ CurrentMsr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
We are backing the current MSR value but when was it initialized
before ? Also is not this function supposed to set the Address as the
GHCB address? If it is, do we care about the old value?
Good point, there is no reason to read and restore the old GHCB, I will remove it in next version. The function does not set this as a GHCB address, it send request to hypervisor saying that it would like to use this address. If hypervisor is not okay with the address then it may recommend something else. We don't support working with the hypervisor preferred address. Setting the GHCB address code is common between Snp and Es but checking with hypervisor whether its okay to use is new in the GHCBv2 and is SNP specific.

+ // Restore the MSR
+ //
+ AsmWriteMsr64 (MSR_SEV_ES_GHCB, CurrentMsr.GhcbPhysicalAddress);
Why are we restoring the old value? I may have misunderstood but I
thought this function will set Address as the new GHCB address?

Join to automatically receive all group messages.