From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 9286C1FF164
	for <inbox@lore.proxmox.com>; Fri, 22 Nov 2024 10:23:52 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id B7AEBE0DF;
	Fri, 22 Nov 2024 10:23:59 +0100 (CET)
To: pve-devel@lists.proxmox.com
Date: Fri, 22 Nov 2024 18:22:51 +0900
MIME-Version: 1.0
Message-ID: <mailman.561.1732267439.391.pve-devel@lists.proxmox.com>
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Post: <mailto:pve-devel@lists.proxmox.com>
From: Jing Luo via pve-devel <pve-devel@lists.proxmox.com>
Precedence: list
Cc: Jing Luo <jing@jing.rocks>
X-Mailman-Version: 2.1.29
X-BeenThere: pve-devel@lists.proxmox.com
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
Subject: [pve-devel] [PATCH qemu-server] query-machine-capabilities: make it
 work on non-x86 arch
Content-Type: multipart/mixed; boundary="===============7351842918767868194=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============7351842918767868194==
Content-Type: message/rfc822
Content-Disposition: inline

Return-Path: <jing@jing.rocks>
X-Original-To: pve-devel@lists.proxmox.com
Delivered-To: pve-devel@lists.proxmox.com
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by lists.proxmox.com (Postfix) with ESMTPS id 69E1BC8675
	for <pve-devel@lists.proxmox.com>; Fri, 22 Nov 2024 10:23:58 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 4A460E0C7
	for <pve-devel@lists.proxmox.com>; Fri, 22 Nov 2024 10:23:58 +0100 (CET)
Received: from mail-gw3.jing.rocks (mail-gw3.jing.rocks [219.117.250.209])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by firstgate.proxmox.com (Proxmox) with ESMTPS
	for <pve-devel@lists.proxmox.com>; Fri, 22 Nov 2024 10:23:55 +0100 (CET)
Received: from mail-gw3.jing.rocks (localhost [127.0.0.1])
	by mail-gw3.jing.rocks (Proxmox) with ESMTP id 365B91C36E
	for <pve-devel@lists.proxmox.com>; Fri, 22 Nov 2024 18:23:51 +0900 (JST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jing.rocks; h=cc
	:cc:content-transfer-encoding:date:from:from:message-id
	:mime-version:reply-to:subject:subject:to:to; s=mail-gw; bh=ybX3
	sKBmbXrKq6mdQQ4vyPD3emfF72KDf3S3niQ+tZs=; b=E8UUAgNtjVxXD9WA7HC/
	RfXza+awY3texj3E/J55KWnO5scYS0Ff6315qkAf6hrnQqLrpqH3bdPyGGqjwsWh
	Upp/Cv6f6zKNbs3maK3d/s04NY7cnqO8hZx8vPgp+WLxWAtO1nNOerBG9X2GbBsE
	586vResB6YHtzdUd3zzSBD4sPhteV256SCqQ+ngyoqONCErLHTM9Be0b534G96pm
	eVNCNRr975bZnK41dHKSpoHvCcWOk/Z+29ko3r/RR0zdF7HsRwxS8vW2dYhxahNK
	s684ddqdFRwvjaZYXtw6yg1Gia4JorIWLEeWn01StM0+m6Ln48zNcI1lpkb66F6p
	yw==
Received: from mail.jing.rocks (mail.jing.rocks [IPv6:240b:10:f00:1b00::222])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mail-gw3.jing.rocks (Proxmox) with ESMTPS id 50CB11C36B
	for <pve-devel@lists.proxmox.com>; Fri, 22 Nov 2024 18:23:49 +0900 (JST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=jing.rocks;
	s=default; t=1732267429;
	bh=b97fOqg2Bu8OhyHyr/hTP29vRXBBRDeFyY2OPNJil0I=;
	h=From:To:Cc:Subject:Date:From;
	b=iW38R+03scVB0t/gZr/a3Bemj03LlcEN9aEyrBTaP5Pbxivc7VfR5cFYruBARXBpu
	 pklJbyfJU/INTrVbz3Rz55Ycmu4TLeNJPCBGae+rcX8kACQC1n5WaR0OdkcI8BjdR9
	 ZHg0WkOSOIYBtLnlCek5+hGTLNOZAHtB/SNC+DRGSjXIYUbXSUXjjrvyzbV9v9PAin
	 Nza9KsWbo6QvODQJ/dklSQI1fCv6Mppxw2oeYbpW+4xcudNTWNqrX+mG0n8f5ptone
	 zwHZnpkFU3nOdTOOJp2NrmvcBlyUPz1cbsuBOKaPiQBXrm0KO6jfPiUDcWaoedbmFD
	 mBHHgckCdExFQ==
Received: from X570AM.jing.rocks (unknown [IPv6:240b:10:f00:1b00::7e82])
	(Authenticated sender: jing@jing.rocks)
	by mail.jing.rocks (Postfix) with ESMTPSA id 43C9E3B807;
	Fri, 22 Nov 2024 18:23:49 +0900 (JST)
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>
X-Mailer: git-send-email 2.47.0
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
	AWL                    -0.002 Adjusted score from AWL reputation of From: address
	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_PASS               -0.1 DMARC pass policy
	KAM_INFOUSMEBIZ          0.75 Prevalent use of .info|.us|.me|.me.uk|.biz|xyz|id|rocks|life domains in spam/malware
	KAM_OTHER_BAD_TLD        0.75 Other untrustworthy TLDs
	RCVD_IN_VALIDITY_CERTIFIED_BLOCKED  0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked.  See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information.
	RCVD_IN_VALIDITY_RPBL_BLOCKED  0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked.  See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information.
	RCVD_IN_VALIDITY_SAFE_BLOCKED  0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked.  See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information.
	SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
	SPF_PASS               -0.001 SPF: sender matches SPF record

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




--===============7351842918767868194==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============7351842918767868194==--