Re: [PATCH v6 1/6] OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature.
Ashish Kalra
Hello Tom,
On Mon, Aug 09, 2021 at 08:41:27AM -0500, Tom Lendacky wrote: On 8/2/21 7:31 AM, Ashish Kalra wrote:Yes KVM only programs CPUID function 0x40000000, as do other hypervisors+I still really don't understand the need for the CPUID loop. KVM only ever like Hyper-V. Also mentioned that leaf 0x40000000 is the Hypervisor CPUID leaf range and vendor ID signature in MSFT Hypervisor Interface document. But looking at linux kernel code for the same functionality : static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves) { uint32_t base, eax, signature[3]; for (base = 0x40000000; base < 0x40010000; base += 0x100) { cpuid(base, &eax, &signature[0], &signature[1], &signature[2]); if (!memcmp(sig, signature, 12) ... ... And the Xen detection code in OVMF: for (mXenLeaf = 0x40000000; mXenLeaf < 0x40010000; mXenLeaf += 0x100) { AsmCpuid (mXenLeaf, NULL, (UINT32 *) &Signature[0], (UINT32 *) &Signature[4], (UINT32 *) &Signature[8]); if (!AsciiStrCmp ((CHAR8 *) Signature, "XenVMMXenVMM")) { return TRUE; The above functions are doing a loop-test. The kernel patch also mentions about the loop-test : https://lore.kernel.org/kvm/51FF1E26.6010707@redhat.com/t/ This patch introduce hypervisor_cpuid_base() which loop test the hypervisor existence function until the signature match and check the number of leaves if required. This could be used by Xen/KVM guest to detect the existence of hypervisor. The above patches/functions don't have any additonal documentation for why are they doing the loop-test ? I don't want to miss any functionality, hence i am reusing the same loop-test code. Thanks, Ashish + AsmCpuid (
|
|