From: Christian Ludwig <christian_ludwig@genua.de>
To: <pve-devel@lists.proxmox.com>
Subject: [PATCH qemu-server 2/7] sev: Detect SEV-
Date: Thu, 24 Sep 2026 16:14:04 +0200 [thread overview]
Message-ID: <64d1760116eab24690f674738cc6ef63a9213710.1790236014.git@genua.de> (raw)
In-Reply-To: <chipid.1790235905.git@genua.de>
[-- Attachment #1: Type: text/plain, Size: 2638 bytes --]
CPUID only announces what the silicon is capable of. SEV, SEV-ES and SNP
can all still be disabled by firmware/platform config. If KVM signals
support, Qemu is able launch VMs with that feature.
Signed-off-by: Christian Ludwig <christian_ludwig@genua.de>
---
.../query-machine-capabilities.c | 42 ++++++++++++++++---
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/src/query-machine-capabilities/query-machine-capabilities.c b/src/query-machine-capabilities/query-machine-capabilities.c
index 0a9ab805..b7e06286 100644
--- a/src/query-machine-capabilities/query-machine-capabilities.c
+++ b/src/query-machine-capabilities/query-machine-capabilities.c
@@ -120,9 +120,44 @@ int read_msr(uint32_t msr_index, uint64_t *value) {
return 0;
}
+
void query_cpu_capabilities_sev(cpu_caps_amd_sev_t *res) {
#ifdef __x86_64__
uint32_t eax, ebx, ecx, edx;
+ struct {
+ const char *path;
+ bool *result;
+ } s[] = {
+ { "/sys/module/kvm_amd/parameters/sev", &res->sev_support },
+ { "/sys/module/kvm_amd/parameters/sev_es", &res->sev_es_support },
+ { "/sys/module/kvm_amd/parameters/sev_snp", &res->sev_snp_support },
+ };
+
+ for (size_t i = 0; i < sizeof(s) / sizeof(s[0]); i++) {
+ char c;
+ FILE *fp = fopen(s[i].path, "r");
+ if (fp == NULL)
+ continue;
+ if (fscanf(fp, " %c", &c) != 1) {
+ fclose(fp);
+ continue;
+ }
+ fclose(fp);
+
+ switch (c) {
+ case '1':
+ case 'y':
+ case 'Y':
+ *s[i].result = true;
+ break;
+ default:
+ *s[i].result = false;
+ break;
+ }
+ }
+
+ if (!res->sev_support && !res->sev_es_support && !res->sev_snp_support)
+ return;
// query Encrypted Memory Capabilities, see:
// https://en.wikipedia.org/wiki/CPUID#EAX=8000001Fh:_Encrypted_Memory_Capabilities
@@ -132,12 +167,9 @@ void query_cpu_capabilities_sev(cpu_caps_amd_sev_t *res) {
: "0"(query_function)
);
- res->sev_support = (eax & (1<<1)) != 0;
- res->sev_es_support = (eax & (1<<3)) != 0;
- res->sev_snp_support = (eax & (1<<4)) != 0;
-
res->cbitpos = ebx & 0x3f;
res->reduced_phys_bits = (ebx >> 6) & 0x3f;
+
#else
memset(res, 0, sizeof(*res));
#endif
@@ -206,7 +238,7 @@ int main() {
#ifdef __x86_64__
if (strncmp(vendor, "AuthenticAMD", 12) == 0) {
- cpu_caps_amd_sev_t caps_sev;
+ cpu_caps_amd_sev_t caps_sev = { 0 };
query_cpu_capabilities_sev(&caps_sev);
ret = fprintf(file,
--
2.34.1
next prev parent reply other threads:[~2026-09-24 14:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 14:14 [PATCH 0/7] SEV: Expose chip ID and reported TCB versions Christian Ludwig
2026-09-24 14:14 ` [PATCH pve-common 1/7] procfs: read CPU model and stepping from cpuinfo Christian Ludwig
2026-09-24 14:14 ` Christian Ludwig [this message]
2026-09-24 14:14 ` [PATCH qemu-server 3/7] sev: Expose chip ID and reported TCB versions Christian Ludwig
2026-09-24 14:14 ` [PATCH qemu-server 4/7] api: add endpoint for SEV attestation data Christian Ludwig
2026-09-24 14:14 ` [PATCH pve-manager 5/7] api: register SEV capabilities endpoint Christian Ludwig
2026-09-24 14:14 ` [PATCH pve-docs 6/7] qm: Describe ASIDs for SEV Christian Ludwig
2026-09-24 14:14 ` [PATCH pve-docs 7/7] sev: Describe VCEK retieval Christian Ludwig
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=64d1760116eab24690f674738cc6ef63a9213710.1790236014.git@genua.de \
--to=christian_ludwig@genua.de \
--cc=pve-devel@lists.proxmox.com \
/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