From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 546F21FF16F for ; Tue, 16 Sep 2025 11:14:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 10817E626; Tue, 16 Sep 2025 11:13:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1758009453; x=1758614253; d=canarybit.eu; s=rsa1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=LreTnDL/puGr2BL5VBvX6SLdv2e68OPI1ZkzyEiuczA=; b=fW7uej+eTgY/cM8TqNDt6SKQEqm4i2DSl8qINot4vJ3Hwem9nAz8oHzCNimZQt7ZuWlPg0UnLg3bj MuN+A2BBTpfoQ1UMhEDQTCsPb5UJrR15E5UPzqgyMjYRE96y5aR2DxjSjsorquWvsYHHvk+/DU4hRA hRPFaheVn3mwQTWIVMZ122hWL0ohMkEe613Zns9Pw9EG3xzwQY4AQPMlzLp2+3ehwDAjNbVAsxSDAK rh0PBb0isisH/uHwO+4+HOBniEgehuwB8nt5Ul9WTMKkAueDgVLr6eHqzJsu5wfDqw+XjAGecSAto8 1v5Zq3JQM741e+nQU8ww2wrFXhL1Yaw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1758009453; x=1758614253; d=canarybit.eu; s=ed1; h=content-transfer-encoding:mime-version:references:in-reply-to:message-id:date: subject:cc:to:from:from; bh=LreTnDL/puGr2BL5VBvX6SLdv2e68OPI1ZkzyEiuczA=; b=HdOLn5xnxk6XsZn0BSvZu2rbbp64RkidZ8mUtPRPWOdQkDVgVCXVW+6smTnZPBw6LnUa32Om66dKC 5bdvIcyAw== X-HalOne-ID: cbeb6f47-92d2-11f0-842d-494313b7f784 From: Anton Iacobaeus To: pve-devel@lists.proxmox.com Date: Tue, 16 Sep 2025 09:52:52 +0200 Message-ID: <20250916075406.33084-10-anton.iacobaeus@canarybit.eu> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250916075406.33084-2-anton.iacobaeus@canarybit.eu> References: <20250916075406.33084-2-anton.iacobaeus@canarybit.eu> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_MISSING 0.1 Missing DMARC policy RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_PASS -0.001 SPF: HELO matches SPF record SPF_NONE 0.001 SPF: sender does not publish an SPF Record X-Mailman-Approved-At: Tue, 16 Sep 2025 11:13:12 +0200 Subject: [pve-devel] [PATCH qemu-server 2/3] Add check for TDX support X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Cc: Anton Iacobaeus , Philipp Giersfeld Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" From: Philipp Giersfeld Check whether TDX is enabled on this machine. Instead of using CPUID like AMD SEV, Intel TDX enablement can be verified by reading an MSR (https://cc-enabling.trustedservices.intel.com/intel-tdx-enabling-guide/05/host_os_setup/). Signed-off-by: Philipp Giersfeld Signed-off-by: Anton Iacobaeus --- .../query-machine-capabilities.c | 56 ++++++++++++++++++- src/usr/modules-load.conf | 1 + 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/query-machine-capabilities/query-machine-capabilities.c b/src/query-machine-capabilities/query-machine-capabilities.c index 0c522afc..913d15c5 100644 --- a/src/query-machine-capabilities/query-machine-capabilities.c +++ b/src/query-machine-capabilities/query-machine-capabilities.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #define eprintf(...) fprintf(stderr, __VA_ARGS__) @@ -15,11 +18,49 @@ typedef struct { bool sev_support; bool sev_es_support; bool sev_snp_support; + bool tdx_support; uint8_t cbitpos; uint8_t reduced_phys_bits; } cpu_caps_t; +int read_msr(uint32_t msr_index, unsigned int *value) { + int64_t data; + char* msr_file_name = "/dev/cpu/0/msr"; + int fd; + + fd = open(msr_file_name, O_RDONLY); + if (fd < 0) { + if (errno == ENXIO) { + fprintf(stderr, "rdmsr: No CPU 0\n"); + exit(2); + } else if (errno == EIO) { + fprintf(stderr, "rdmsr: CPU oesn't support MSRs\n"); + exit(3); + } else { + perror("rdmsr: open"); + exit(127); + } + } + + if (pread(fd, &data, sizeof data, msr_index) != sizeof data) { + if (errno == EIO) { + fprintf(stderr, "rdmsr: CPU cannot read MSR 0x%08x\n", msr_index); + exit(4); + } else { + perror("rdmsr: pread"); + exit(127); + } + } + + + *value = data; + + close(fd); + return 0; +} + + void query_cpu_capabilities(cpu_caps_t *res) { uint32_t eax, ebx, ecx, edx; @@ -37,6 +78,15 @@ void query_cpu_capabilities(cpu_caps_t *res) { res->cbitpos = ebx & 0x3f; res->reduced_phys_bits = (ebx >> 6) & 0x3f; + + unsigned int value; + + if (read_msr(0x1401, &value) == 0) { + fprintf(stderr, "to read MSR: %08x \n", value); + res->tdx_support = (value & (1<<11)); + } else { + fprintf(stderr, "Failed to read MSR\n"); + } } int prepare_output_directory() { @@ -82,13 +132,17 @@ int main() { " \"sev-support\": %s," " \"sev-support-es\": %s," " \"sev-support-snp\": %s" + " }," + " \"intel-tdx\": {" + " \"tdx-support\": %s" " }" " }\n", caps.cbitpos, caps.reduced_phys_bits, caps.sev_support ? "true" : "false", caps.sev_es_support ? "true" : "false", - caps.sev_snp_support ? "true" : "false" + caps.sev_snp_support ? "true" : "false", + caps.tdx_support ? "true" : "false" ); if (ret < 0) { eprintf("Error writing to file '" OUTPUT_PATH "': %s\n", strerror(errno)); diff --git a/src/usr/modules-load.conf b/src/usr/modules-load.conf index aee7d42a..f45d256b 100644 --- a/src/usr/modules-load.conf +++ b/src/usr/modules-load.conf @@ -1 +1,2 @@ vhost_net +msr -- 2.43.0 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel