From: "Jörg Thalheim" <joerg@thalheim.io>
To: qemu-devel@nongnu.org
Cc: okelmann@in.tum.de
Subject: [PATCH] hw/i386: fix phys-bits on cpus with AMD SEV/SMD
Date: Wed, 21 Jul 2021 11:35:34 +0000 [thread overview]
Message-ID: <0b3132692ee53e98082b4dd12e41b4a3@thalheim.io> (raw)
On AMD machines with SEV/SMD the physical address space needs
to be reduced by a number of bits. Linux does this correctly
and shows this information in /proc/cpuinfo. CPUID set by qemu
however reports too big physical addresses i.e. 48 bit instead of 43.
This patch has been tested on both Intel and AMD.
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
---
target/i386/host-cpu.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c
index 4ea9e354ea..0fb98ca566 100644
--- a/target/i386/host-cpu.c
+++ b/target/i386/host-cpu.c
@@ -13,22 +13,39 @@
#include "qapi/error.h"
#include "sysemu/sysemu.h"
+static uint32_t sme_sev_bits(void) {
+ uint32_t eax, ebx;
+ // get AMD Encrypted Memory Capabilities information according to AMD doc 24594—Rev. 3.32
+ host_cpuid(0x8000001f, 0, &eax, &ebx, NULL, NULL);
+ // bits:
+ // 0:1 SME
+ // 1:2 SEV
+ // ...
+ if (eax & 1 || eax & 2) {
+ // bits:
+ // 11:6 PhysAddrReduction
+ return (ebx >> 6) & 0x3f;
+ } else {
+ return 0;
+ }
+}
+
/* Note: Only safe for use on x86(-64) hosts */
static uint32_t host_cpu_phys_bits(void)
{
- uint32_t eax;
+ uint32_t eax, ebx;
uint32_t host_phys_bits;
host_cpuid(0x80000000, 0, &eax, NULL, NULL, NULL);
if (eax >= 0x80000008) {
- host_cpuid(0x80000008, 0, &eax, NULL, NULL, NULL);
+ host_cpuid(0x80000008, 0, &eax, &ebx, NULL, NULL);
/*
* Note: According to AMD doc 25481 rev 2.34 they have a field
* at 23:16 that can specify a maximum physical address bits for
* the guest that can override this value; but I've not seen
* anything with that set.
*/
- host_phys_bits = eax & 0xff;
+ host_phys_bits = (eax & 0xff) - sme_sev_bits();
} else {
/*
* It's an odd 64 bit machine that doesn't have the leaf for
--
2.32.0
next reply other threads:[~2021-07-21 13:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 11:35 Jörg Thalheim [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-12-13 16:59 [PATCH] hw/i386: fix phys-bits on cpus with AMD SEV/SMD Jörg Thalheim
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-all 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=0b3132692ee53e98082b4dd12e41b4a3@thalheim.io \
--to=joerg@thalheim.io \
--cc=okelmann@in.tum.de \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.