From: "Ashish Kalra" <ashish.kalra@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>
Cc: devel@edk2.groups.io, dovmurik@linux.vnet.ibm.com,
brijesh.singh@amd.com, tobin@ibm.com, jejb@linux.ibm.com,
jordan.l.justen@intel.com, ard.biesheuvel@arm.com,
erdemaktas@google.com, jiewen.yao@intel.com, min.m.xu@intel.com
Subject: Re: [PATCH v6 1/6] OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature.
Date: Mon, 9 Aug 2021 14:37:14 +0000 [thread overview]
Message-ID: <20210809143714.GA7990@ashkalra_ubuntu_server> (raw)
In-Reply-To: <172fa9d6-6edb-41b1-c827-03b04d964469@amd.com>
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:
> > +
> > + Signature[12] = '\0';
> > + for (mKvmLeaf = 0x40000000; mKvmLeaf < 0x40010000; mKvmLeaf += 0x100) {
>
> I still really don't understand the need for the CPUID loop. KVM only ever
> programs CPUID function 0x40000000, right?
>
Yes KVM only programs CPUID function 0x40000000, as do other hypervisors
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 (
> > + mKvmLeaf,
> > + NULL,
> > + (UINT32 *) &Signature[0],
> > + (UINT32 *) &Signature[4],
> > + (UINT32 *) &Signature[8]);
> > +
> > + if (AsciiStrCmp (Signature, "KVMKVMKVM") == 0) {
> > + DEBUG ((
> > + DEBUG_INFO,
> > + "%a: KVM Detected, signature = %a\n",
> > + __FUNCTION__,
> > + Signature
> > + ));
> > +
> > + RegEax = mKvmLeaf + 1;
> > + RegEcx = 0;
> > + AsmCpuid (mKvmLeaf + 1, &RegEax, &RegEbx, &RegEcx, &RegEdx);
> > + if ((RegEax & KVM_FEATURE_MIGRATION_CONTROL) != 0) {
> > + DEBUG ((
> > + DEBUG_INFO,
> > + "%a: SEV Live Migration feature supported\n",
> > + __FUNCTION__
> > + ));
> > +
> > + return TRUE;
> > + }
> > + }
> > + }
> > +
> > + return FALSE;
> > +}
next prev parent reply other threads:[~2021-08-09 14:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1627906232.git.ashish.kalra@amd.com>
2021-08-02 12:31 ` [PATCH v6 1/6] OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature Ashish Kalra
2021-08-09 13:41 ` Lendacky, Thomas
2021-08-09 14:37 ` Ashish Kalra [this message]
2021-08-10 6:05 ` [edk2-devel] " Gerd Hoffmann
2021-08-10 13:04 ` Lendacky, Thomas
2021-08-02 12:31 ` [PATCH v6 2/6] OvmfPkg/BaseMemEncryptLib: Hypercall API for page encryption state change Ashish Kalra
2021-08-09 14:19 ` Lendacky, Thomas
2021-08-02 12:32 ` [PATCH v6 3/6] OvmfPkg/BaseMemEncryptLib: Invoke page encryption state change hypercall Ashish Kalra
2021-08-02 12:32 ` [PATCH v6 4/6] OvmfPkg/VmgExitLib: Encryption state change hypercall support in VC handler Ashish Kalra
2021-08-02 12:33 ` [PATCH v6 5/6] OvmfPkg/PlatformPei: Mark SEC GHCB page as unencrypted via hypercall Ashish Kalra
2021-08-02 12:33 ` [PATCH v6 6/6] OvmfPkg/AmdSevDxe: Add support for SEV live migration Ashish Kalra
2021-08-09 14:29 ` Lendacky, Thomas
2021-08-10 11:13 ` Ashish Kalra
2021-08-10 13:06 ` Lendacky, Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210809143714.GA7990@ashkalra_ubuntu_server \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox