From nobody Thu Jan 8 12:42:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1767109846; cv=none; d=zohomail.com; s=zohoarc; b=cZCfnnQUX9kRLEcfg41YKwA6VnvMfsqNjWkit/QSWTGvzf9z2t/+qPygXd0fu915OvP1Ncop/DOztYeYSF8DDgY+5boXi7Hv+UOrPmG1iWXZm/C8IGsB60xF2bfVlXcrs61lfDs8HTGKZof5/dV2K1wOMjheBsi/EVo8LNWYoak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767109846; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=n7gKOOgmmYdSIY6PAwcf6NmkP9o7a38tNEad4djOSS4=; b=Zv2yKZNnsQ6+3c/zs0lCAtX5dtD/okiUn1/LfDgGlAxwJCULJy5PJocqu6twoANBCTaEl7h7lI8aP4StADHsLg08m0KKI3jeJtYcwaDg5LLTW/Sk1v0rPRwuZvrxF7/FAbPu1XzSckUdiEzj2N0i57vOzjD4VL2RiC2TY+b/e3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1767109846205326.02315660313513; Tue, 30 Dec 2025 07:50:46 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1194337.1512742 (Exim 4.92) (envelope-from ) id 1vabzR-0001so-Eg; Tue, 30 Dec 2025 15:50:29 +0000 Received: by outflank-mailman (output) from mailman id 1194337.1512742; Tue, 30 Dec 2025 15:50:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vabzR-0001sh-BT; Tue, 30 Dec 2025 15:50:29 +0000 Received: by outflank-mailman (input) for mailman id 1194337; Tue, 30 Dec 2025 15:50:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vabzP-0001sb-Ve for xen-devel@lists.xenproject.org; Tue, 30 Dec 2025 15:50:27 +0000 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [2a00:1450:4864:20::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 413ec65a-e597-11f0-9ccf-f158ae23cfc8; Tue, 30 Dec 2025 16:50:24 +0100 (CET) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b7cf4a975d2so1543505366b.2 for ; Tue, 30 Dec 2025 07:50:24 -0800 (PST) Received: from fedora (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b8037de0de1sm3695413366b.40.2025.12.30.07.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Dec 2025 07:50:23 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 413ec65a-e597-11f0-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767109824; x=1767714624; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n7gKOOgmmYdSIY6PAwcf6NmkP9o7a38tNEad4djOSS4=; b=GuPoCqmdaXAqg6SP70pxDTdlBBFZuBjWHhrMSNu+65vi6xQ8T7xpLCCQcTTX55FLxN 8GVifEpUQlTwGOWl2DegyPr4kaRtOQySmG6szUUbhMYx2KvGE1GuNETdNZ602vdWy19s h2s03d3q8HZDmc7hNllRsLZ0GB5vM7Y0pc13h/qnAsvVhFnVGqMedArr6ce+SSIrw8gC paKOVtpgss1EELN++Odg3fHSi3yAsleezp2v4LSj0elZ8MZidQQRCiWHRTVOuCm84dbr qJDPht4z8WnlGs29RP0mMqVmGZ8lgxj4FcPEHVM4K/pxvGOcE9dYNrmfiLKU11qPy2Oc gYJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767109824; x=1767714624; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=n7gKOOgmmYdSIY6PAwcf6NmkP9o7a38tNEad4djOSS4=; b=KcJyahAMXT2ZNqdMWU8cebqJeyLQEbxNLuN3CTLx+uv3RZXnCOWRHf/JxGROoeBNtu NG2JkEQVYMgbFKLkh0pgSzEe+0zxG1R57IJE268KTXwsNA9kTR4Fb++ynQ1m0aR8lzuu aHM3OxECZmq792LbkEQyauuFW6gDTnSAUx1nNnwjL9kH6PoMRUysdpHin41ggSrKi6W3 S5u7YS0JYQUYqsCXf0wtPKmA7i7D3Cf0ffkmJ8WW3yTe++2n9bo86g7dN2bMoq6tSBMx R0aJutZPXL7bDZW+4eh9E9LNZhVAD2k5mBr22f5DuBuYKu39OkcNUT4jJxcVWVSAxIhW 1DaQ== X-Gm-Message-State: AOJu0YxLf8jlHVlGVKzBQ3th5aTeAUo3nlYpWmwrjgnxM4OQXuWq3x06 Q8LfZgzSxSg1uYE32VAO7hm6ziIyl3WgghCCk7HwsFerGToNBqW48V+/6Y9ljQ== X-Gm-Gg: AY/fxX7M48MgqJA2CMx2liS2QbWA4L5+JH+l2C9WRDVWIxUppLGuvA/4oQON3Vc789Q B/V8Dds6njqqJoo424WWe/AkEd9lvETJQ1Pn94B0+J35mVt4vUbYJwKm56+fDsAIEz3aU+6iU9p Fj6DPrOfWUk/zO1RPJuq/NPg52X5Vf8mo+z6mc+M7p9/MdFWMFFH/fJBFFGJaTRz00D714PQF3G Jub++hPAZyRItK05ELCNpRKaGFGztvhxnPRz4/+c4bSTYe+hyfeoz7W+wLBm3IIYMJUbyhDz2lo MM1pZL6OhX7+/Odh+ZiY+8iZJYTKsP1kaMgs2Lh0D0bMYqUdMEDkh0/EVkVF2V+HncmjbZUVmVe 0gR1WDy/uwK1kbyzHZ1ms2lJOUw83d6RpsJ7bRY8hDCLNNi0OS5AhQtYTUeh+GMI48aPkx+oqnW CYI2hTxLIoIFEeRord5ozHyVKkvnhZYzL7RwAamnAZ226SorlDD7MGVQ== X-Google-Smtp-Source: AGHT+IHmPTleLF1vmAUMJ+0zoGqS1Qu6n/ZbaQyy5oVKptd2FFupdkOFy0+GoFZJ837xlHaFP7jySA== X-Received: by 2002:a17:906:4fd0:b0:b70:b700:df98 with SMTP id a640c23a62f3a-b8036ebbe4amr3376642066b.5.1767109823599; Tue, 30 Dec 2025 07:50:23 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v4 1/1] xen/riscv: add RISC-V virtual SBI base extension support for guests Date: Tue, 30 Dec 2025 16:50:11 +0100 Message-ID: X-Mailer: git-send-email 2.52.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1767109848174158500 Content-Type: text/plain; charset="utf-8" Add support of virtual SBI base extension calls for RISC-V guests, delegati= ng hardware-specific queries to the underlying SBI and handling version and firmware ID queries directly. The changes include: 1. Define new SBI base extension function IDs (SBI_EXT_BASE_GET_MVENDORID, SBI_EXT_BASE_GET_MARCHID, SBI_EXT_BASE_GET_MIMPID). 2. Introduce XEN_SBI_VER_MAJOR, XEN_SBI_VER_MINOR for imeplenataion of SBI_EXT_BASE_GET_SPEC_VERSION. 4. Introduce SBI_XEN_IMPID to implement SBI_EXT_BASE_GET_IMP_ID. 5. Implement handling of SBI base extension functions, including version, firmware ID, and machine-specific queries. Signed-off-by: Oleksii Kurochko Acked-by: Jan Beulich --- Changes in v4: - Move definition of XEN_SBI_VER_{MAJOR, MINOR} to base-extension.c. - Correct string format for FID: s/#%#lx/#%lu. - Print first EID then FID (as vsbi/core.c code does). --- Changes in v3: - s/XEN_SBI_IMPID/SBI_XEN_IMPID - Add ASSERT(eid =3D=3D SBI_EXT_BASE) in vsbi_base_ecall_handler(). - Fix code style for switch/case. - Use current instead of `vcpu` argument as it was dropped from vsbi_base_ecall_handler() prototype. - Add comments for define-s XEN_SBI_VER_{MAJOR, MINOR} and SBI_XEN_IMPID. --- Changes in v2: - s/vsbi-base-extension.*/base-extension.* - Introduce VCPU_SBI_IMPID, XEN_SBI_VER_MINOR and XEN_SBI_VER_MAJOR. - Return VCPU_SBI_IMPID in the case of SBI_EXT_BASE_GET_IMP_ID. - Return Xen version in the case of SBI_EXT_BASE_GET_IMP_VERSION. - Use domain_crash() instead of panic() for default case. - For SBI_EXT_BASE_GET_{MVENDORID,MARCHID,MIMPID} abd SBI_EXT_BASE_PROBE_E= XT add handling of a domain is h/w or not. --- xen/arch/riscv/include/asm/sbi.h | 6 ++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/base-extension.c | 82 ++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 xen/arch/riscv/vsbi/base-extension.c diff --git a/xen/arch/riscv/include/asm/sbi.h b/xen/arch/riscv/include/asm/= sbi.h index 751bae6d6654..79f7ff5c5501 100644 --- a/xen/arch/riscv/include/asm/sbi.h +++ b/xen/arch/riscv/include/asm/sbi.h @@ -14,6 +14,9 @@ =20 #include =20 +/* SBI-defined implementation ID */ +#define SBI_XEN_IMPID 7 + #define SBI_EXT_0_1_SET_TIMER 0x0 #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 #define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 @@ -32,6 +35,9 @@ #define SBI_EXT_BASE_GET_IMP_ID 0x1 #define SBI_EXT_BASE_GET_IMP_VERSION 0x2 #define SBI_EXT_BASE_PROBE_EXT 0x3 +#define SBI_EXT_BASE_GET_MVENDORID 0x4 +#define SBI_EXT_BASE_GET_MARCHID 0x5 +#define SBI_EXT_BASE_GET_MIMPID 0x6 =20 /* SBI function IDs for RFENCE extension */ #define SBI_EXT_RFENCE_REMOTE_FENCE_I 0x0 diff --git a/xen/arch/riscv/vsbi/Makefile b/xen/arch/riscv/vsbi/Makefile index bc5755cb13d6..8ce470f787c5 100644 --- a/xen/arch/riscv/vsbi/Makefile +++ b/xen/arch/riscv/vsbi/Makefile @@ -1,2 +1,3 @@ +obj-y +=3D base-extension.o obj-y +=3D core.o obj-y +=3D legacy-extension.o diff --git a/xen/arch/riscv/vsbi/base-extension.c b/xen/arch/riscv/vsbi/bas= e-extension.c new file mode 100644 index 000000000000..41a95ae188dd --- /dev/null +++ b/xen/arch/riscv/vsbi/base-extension.c @@ -0,0 +1,82 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +#include +#include +#include + +/* Xen-controlled SBI version reported to guests */ +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2 + +static int vsbi_base_ecall_handler(unsigned long eid, unsigned long fid, + struct cpu_user_regs *regs) +{ + int ret =3D 0; + struct sbiret sbi_ret; + + ASSERT(eid =3D=3D SBI_EXT_BASE); + + switch ( fid ) + { + case SBI_EXT_BASE_GET_SPEC_VERSION: + regs->a1 =3D MASK_INSR(XEN_SBI_VER_MAJOR, SBI_SPEC_VERSION_MAJOR_M= ASK) | + XEN_SBI_VER_MINOR; + break; + + case SBI_EXT_BASE_GET_IMP_ID: + regs->a1 =3D SBI_XEN_IMPID; + break; + + case SBI_EXT_BASE_GET_IMP_VERSION: + regs->a1 =3D (xen_major_version() << 16) | xen_minor_version(); + break; + + case SBI_EXT_BASE_GET_MVENDORID: + case SBI_EXT_BASE_GET_MARCHID: + case SBI_EXT_BASE_GET_MIMPID: + if ( is_hardware_domain(current->domain) ) + { + sbi_ret =3D sbi_ecall(SBI_EXT_BASE, fid, 0, 0, 0, 0, 0, 0); + ret =3D sbi_ret.error; + regs->a1 =3D sbi_ret.value; + } + else + /* + * vSBI should present a consistent, virtualized view to guest= s. + * In particular, DomU-visible data must remain stable across + * migration and must not expose hardware-specific details. + * + * These register(s) must be readable in any implementation, + * but a value of 0 can be returned to indicate the field + * is not implemented. + */ + regs->a1 =3D 0; + + break; + + case SBI_EXT_BASE_PROBE_EXT: + regs->a1 =3D vsbi_find_extension(regs->a0) ? 1 : 0; + break; + + default: + /* + * TODO: domain_crash() is acceptable here while things are still = under + * development. + * It shouldn't stay like this in the end though: guests should not + * be punished like this for something Xen hasn't implemented. + */ + domain_crash(current->domain, + "%s: Unsupported ecall: EID: #%#lx FID: #%lu\n", + __func__, eid, fid); + break; + } + + return ret; +} + +VSBI_EXT(base, SBI_EXT_BASE, SBI_EXT_BASE, vsbi_base_ecall_handler) --=20 2.52.0