public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server] query-machine-capabilities: make it work on non-x86 arch
@ 2024-11-22  9:22 Jing Luo via pve-devel
  2024-11-22  9:43 ` Lukas Wagner
  0 siblings, 1 reply; 2+ messages in thread
From: Jing Luo via pve-devel @ 2024-11-22  9:22 UTC (permalink / raw)
  To: pve-devel; +Cc: Jing Luo

[-- Attachment #1: Type: message/rfc822, Size: 6924 bytes --]

From: Jing Luo <jing@jing.rocks>
To: pve-devel@lists.proxmox.com
Cc: Jing Luo <jing@jing.rocks>
Subject: [PATCH qemu-server] query-machine-capabilities: make it work on non-x86 arch
Date: Fri, 22 Nov 2024 18:22:51 +0900
Message-ID: <20241122092345.1411799-1-jing@jing.rocks>

This little program has inline assembly code that won't work on non-x86
arch:

query-machine-capabilities.c: In function 'query_cpu_capabilities':
query-machine-capabilities.c:29:5: error: impossible constraint in 'asm'
   29 |     asm volatile("cpuid"
      |     ^~~

So let's define a marco if we find ourselves not on x86, and skip the actual
querying, just write false to things since non-x86 cpu definitely won't
support AMD SEV.

Signed-off-by: Jing Luo <jing@jing.rocks>
---
 query-machine-capabilities/Makefile                     | 5 +++++
 query-machine-capabilities/query-machine-capabilities.c | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/query-machine-capabilities/Makefile b/query-machine-capabilities/Makefile
index 5db2bf97..cd55369c 100644
--- a/query-machine-capabilities/Makefile
+++ b/query-machine-capabilities/Makefile
@@ -6,6 +6,11 @@ SERVICEDIR=/lib/systemd/system
 CC ?= gcc
 CFLAGS += -O2 -fanalyzer -Werror -Wall -Wextra -Wpedantic -Wtype-limits -Wl,-z,relro -std=gnu11
 
+DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
+ifneq ($(DEB_HOST_ARCH),amd64)
+	CFLAGS += -DNOT_X86
+endif
+
 query-machine-capabilities: query-machine-capabilities.c
 	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
 
diff --git a/query-machine-capabilities/query-machine-capabilities.c b/query-machine-capabilities/query-machine-capabilities.c
index 0c522afc..53a6badb 100644
--- a/query-machine-capabilities/query-machine-capabilities.c
+++ b/query-machine-capabilities/query-machine-capabilities.c
@@ -21,6 +21,7 @@ typedef struct {
 } cpu_caps_t;
 
 void query_cpu_capabilities(cpu_caps_t *res) {
+#ifndef NOT_X86
     uint32_t eax, ebx, ecx, edx;
 
     // query Encrypted Memory Capabilities, see:
@@ -37,6 +38,14 @@ void query_cpu_capabilities(cpu_caps_t *res) {
 
     res->cbitpos = ebx & 0x3f;
     res->reduced_phys_bits = (ebx >> 6) & 0x3f;
+#else
+    res->sev_support = false;
+    res->sev_es_support = false;
+    res->sev_snp_support = false;
+
+    res->cbitpos = 0;
+    res->reduced_phys_bits = 0;
+#endif
 }
 
 int prepare_output_directory() {
-- 
2.47.0




[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] query-machine-capabilities: make it work on non-x86 arch
  2024-11-22  9:22 [pve-devel] [PATCH qemu-server] query-machine-capabilities: make it work on non-x86 arch Jing Luo via pve-devel
@ 2024-11-22  9:43 ` Lukas Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Lukas Wagner @ 2024-11-22  9:43 UTC (permalink / raw)
  To: Proxmox VE development discussion; +Cc: Jing Luo

Hello,

instead of modifying the CFLAGS variable in the makefile, you could make use of
one of GCC's built-in defines [1] to check for the machine's architecture.
For instance, you could do a `#if __x86_64__` or `#if __amd64__`.

[1] https://blog.kowalczyk.info/article/j/guide-to-predefined-macros-in-c-compilers-gcc-clang-msvc-etc..html

-- 
- Lukas


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-11-22  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-22  9:22 [pve-devel] [PATCH qemu-server] query-machine-capabilities: make it work on non-x86 arch Jing Luo via pve-devel
2024-11-22  9:43 ` Lukas Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal