From nobody Thu Dec 18 07:59:51 2025 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; 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=1765990502; cv=none; d=zohomail.com; s=zohoarc; b=OtVM1eCjniujTIjJxCQ0Ll69f6vou4x4BTBrs3hiZviFevnRGwRz+aDz0274WqjJjUSv4ewslhjyc8+pPe0pXLGtblHDt+Rt02qAGA8sn2wVvBUZic5MFOqaOVGXEbqD4DbHCbZYeB/FbotL8Y9A7ie8/kA+hbtXjYJUFdgX41k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765990502; 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=kQk7ZnANczFPXo4k/D8bh9dPiQ3Gd6pMKZAsRVMfKwc=; b=mxkhM/67LpsAwzlfniD1UKAfAKz3yXGAPo/tPMfAAD9SOafFQSzXceXPzTXu1rkwRpbejiLJY2meGPr7idAWj95T2taaymWLELU+KfpbfxbgLG1+e6tvcW5DDZa4VzJc+IJuX/9MnvJQ+WKPTcFjcgIoidcHNkVQnJF3uvUhB9Q= 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 1765990502609271.8380881106058; Wed, 17 Dec 2025 08:55:02 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1188963.1509960 (Exim 4.92) (envelope-from ) id 1vVunJ-0003DI-LY; Wed, 17 Dec 2025 16:54:33 +0000 Received: by outflank-mailman (output) from mailman id 1188963.1509960; Wed, 17 Dec 2025 16:54:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vVunJ-0003D9-IR; Wed, 17 Dec 2025 16:54:33 +0000 Received: by outflank-mailman (input) for mailman id 1188963; Wed, 17 Dec 2025 16:54:32 +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 1vVunI-0003An-FR for xen-devel@lists.xenproject.org; Wed, 17 Dec 2025 16:54:32 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0ddc1f4d-db69-11f0-9cce-f158ae23cfc8; Wed, 17 Dec 2025 17:54:30 +0100 (CET) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b79af62d36bso146021766b.3 for ; Wed, 17 Dec 2025 08:54:30 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b7cfa5d1e89sm2015077966b.69.2025.12.17.08.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 08:54:28 -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: 0ddc1f4d-db69-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765990469; x=1766595269; 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=kQk7ZnANczFPXo4k/D8bh9dPiQ3Gd6pMKZAsRVMfKwc=; b=KWi0IFtrRUFVtG6KjKkjy9sWzjALC6noIilmwWAMMB7G4WrGJtp5I8lV9acjB7PrA5 HiAew+JI12s5CO8TbDyPQe7+bREz9FnrIil8qQrR0M+t0t+zK9Y7MK070HIUPu6uRCb1 RtBSrLcdqphbM+2I96+gYY0T/REEFDxCeKJdgNi+sKccVMMYjTZrpJAqvW6eskExYsvi e75+gtJjhU9drmSGsrsmifGI36Ga/tJJZg57E8g55hvk6ZKBw6i8QDVufH48JgjyD16q Df2qzZiza2zNL/P044v5hdy+k0bnESvC7N9oyc1+w+U19oYlqJBTytldpKZsc/+gJzkp XdCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765990469; x=1766595269; 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=kQk7ZnANczFPXo4k/D8bh9dPiQ3Gd6pMKZAsRVMfKwc=; b=IBcjbpm8Snj01oQwbbhiRTjqCUoJSmO/5YSXM6leipuYxFQsraDdn/q8yn1ni5CaDq BDT1oEZaBfxyAGSVIF+fD0MkQQqrqQcv4knadiDNjqTqX7kfPYc48honRi1vMmobwjlf 68NQCQ6m3deYFxxAKLY4D6i0dYyVdhXbyzWKjfj2yQAeFV+Y8DFSvh+qrJKMPkh8ycZN fad9AQ3Bj1EkwitQcWcCCPLRkXtJYigjndDRNda7u1x/cNNd13/RJBUMXnUzzhrnrBfO Amm+V9S0MoGUgoyB66EpHNwtMAPy29JGLsnsd2DjQoxpOCo5aP3aKTtMHNPxlhFmaDsq Gqww== X-Gm-Message-State: AOJu0Yxpp2sYIBT9up63zBfOlq9VzSQOZv8DejF2f7abMkSeYOabGmmz o0KIczPiM2ftn9R9mVL46djpWWbvKJhE5AmhRJN6HolKoshSosjJb1OrGz1zcg== X-Gm-Gg: AY/fxX60BguPoJNBnkwCmZ8PkibBqzPvxvRyLQ/cfsxQDukLDQttBCrDHym15uLcXRT L05M6myNfl/tZFdy/G584d2nVcTX3JK7ftr+ghjanVV3pGrnawh7DX3fSv4fsGVdDawqk0q78ig 9RCOXyxSS+GjKX3AYcSUraCiFreovCBx+HA+8sOWgg7FpvqJU1qOviOm0GY8nUpO0JysieusF0p ABsgOnS/Y/9pbOiABMawdIEmX9Tmgh+tjS+pKROyajUAImppjwZTAlPHLRj6cMucaCAdzebPc7J 3CuyeAlcpwwjDd/D2iTygtGrMQNnd3Y9jOyHdNDMxxDQ/us8aEO4cbFHFfsgsEZYUVeB9sZIIee /85Tu/kUOZf7KE2u3omnGBrGmXdaL79Lt4Ja7W7JCysI0qF9TIy3MN8K6OtR4dJyDKqhUA53T+G MWT8jnr/07vQ477i8rgAVY9W75bzfxsMnE9koNf6OuBl5V5guRGET6Mw4= X-Google-Smtp-Source: AGHT+IHqilvwj5t8yrsGPSAYmL11A43Cp28OZZNp5iLgT32cQWncDyFE/6JLXBfxQEHwTLlQVsgdAw== X-Received: by 2002:a17:907:2d8d:b0:b76:23b0:7d89 with SMTP id a640c23a62f3a-b7d236265abmr1903765666b.14.1765990468825; Wed, 17 Dec 2025 08:54:28 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 1/3] xen/riscv: introduce vSBI extension framework Date: Wed, 17 Dec 2025 17:54:18 +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: 1765990504784158500 Content-Type: text/plain; charset="utf-8" This commit introduces support for handling virtual SBI extensions in Xen. The changes include: - Added new vsbi/core.c and vsbi.h files to implement virtual SBI extension handling. - Modified traps.c to handle CAUSE_VIRTUAL_SUPERVISOR_ECALL by calling vsbi_handle_ecall() when the trap originates from VS-mode. - Updated xen.lds.S to include a new .vsbi.exts section for virtual SBI extension data. - Updated Makefile to include the new vsbi/ directory in the build. - Add hstatus register to struct cpu_user_regs as it is needed for a check that CAUSE_VIRTUAL_SUPERVISOR_ECALL happens from VS-mode. Also, add storing/restoring of hstatus register in handle_trap(). - Introduce vsbi_find_extension() to check if vsbi extension is supported by Xen. For now it is called only inside vsbi/core.c, but in future it is going to be called from other files. - Introduce check_vsbi_ext_ranges() to check if there EIDs ranges overlapping between extensions. The implementation allows for registration and handling of SBI extensions via a new vsbi_ext structure and ".vsbi.exts" section, enabling extensible virtual SBI support for RISC-V guests. Note: All EIDs are printed in the format #%#lx and all FIDs in #%#lu, as the SBI spec uses these formats. Printing them this way makes it easier to search for them in the SBI spec. Signed-off-by: Oleksii Kurochko --- Changes in v2: - s/struct regs/struct cpu_user_regs. - s/handle/handler. - Drop extid_ prefix inside VSBI_EXT_START(). - use BUG_ON() instead of panic to be sure that=20 CAUSE_VIRTUAL_SUPERVISOR_ECALL comes from VS-mode. - s/ext_id/eid for vsbi_find_extension(). - Add the comment above VSBI_EXT_START about [start,end] range. - Drop check "&& ext->handler" in vsbi_handle_ecall() as it isn't be so that handler() isn't provided. - s/vsbi.c/core.c - s/vsbi_ext/ext for local variable inside vsbi_find_extension(). - Update the commit message: add a note about FID and EID printing formats, add some information about vsbo_find_extension() function, and add info about check_vsbi_ext_ranges(). - Introduce check_vsbi_ext_ranges() to be sure that there is no overlapping in EIDs range(s). - Add storing/restoring of hstatus register in handle_trap()[entry.S]. --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/entry.S | 6 +++ xen/arch/riscv/include/asm/processor.h | 1 + xen/arch/riscv/include/asm/vsbi.h | 32 +++++++++++++++ xen/arch/riscv/riscv64/asm-offsets.c | 1 + xen/arch/riscv/setup.c | 3 ++ xen/arch/riscv/traps.c | 8 ++++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/core.c | 56 ++++++++++++++++++++++++++ xen/arch/riscv/xen.lds.S | 7 ++++ 10 files changed, 116 insertions(+) create mode 100644 xen/arch/riscv/include/asm/vsbi.h create mode 100644 xen/arch/riscv/vsbi/Makefile create mode 100644 xen/arch/riscv/vsbi/core.c diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index 9dde693db4..87c1148b00 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -20,6 +20,7 @@ obj-y +=3D time.o obj-y +=3D traps.o obj-y +=3D vmid.o obj-y +=3D vm_event.o +obj-y +=3D vsbi/ =20 $(TARGET): $(TARGET)-syms $(OBJCOPY) -O binary -S $< $@ diff --git a/xen/arch/riscv/entry.S b/xen/arch/riscv/entry.S index 4db818ba8d..202a35fb03 100644 --- a/xen/arch/riscv/entry.S +++ b/xen/arch/riscv/entry.S @@ -48,11 +48,17 @@ save_to_stack: csrr t0, CSR_SSTATUS REG_S t0, CPU_USER_REGS_SSTATUS(sp) =20 + csrr t0, CSR_HSTATUS + REG_S t0, CPU_USER_REGS_HSTATUS(sp) + mv a0, sp call do_trap =20 restore_registers: /* Restore stack_cpu_regs */ + REG_L t0, CPU_USER_REGS_HSTATUS(sp) + csrw CSR_HSTATUS, t0 + REG_L t0, CPU_USER_REGS_SEPC(sp) csrw CSR_SEPC, t0 REG_L t0, CPU_USER_REGS_SSTATUS(sp) diff --git a/xen/arch/riscv/include/asm/processor.h b/xen/arch/riscv/includ= e/asm/processor.h index 2502045642..6b89df4a2d 100644 --- a/xen/arch/riscv/include/asm/processor.h +++ b/xen/arch/riscv/include/asm/processor.h @@ -49,6 +49,7 @@ struct cpu_user_regs unsigned long t6; unsigned long sepc; unsigned long sstatus; + unsigned long hstatus; /* pointer to previous stack_cpu_regs */ unsigned long pregs; }; diff --git a/xen/arch/riscv/include/asm/vsbi.h b/xen/arch/riscv/include/asm= /vsbi.h new file mode 100644 index 0000000000..47a38dce02 --- /dev/null +++ b/xen/arch/riscv/include/asm/vsbi.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef ASM_RISCV_VSBI_H +#define ASM_RISCV_VSBI_H + +struct cpu_user_regs; +struct vcpu; + +struct vsbi_ext { + const char *name; + unsigned long eid_start; + unsigned long eid_end; + int (*handler)(struct vcpu *vcpu, unsigned long eid, + unsigned long fid, struct cpu_user_regs *regs); +}; + +/* Ranges (start and end) are inclusive within an extension */ +#define VSBI_EXT(ext, start, end, handle) \ +static const struct vsbi_ext vsbi_ext_##ext __used \ +__section(".vsbi.exts") =3D { \ + .name =3D #ext, \ + .eid_start =3D start, \ + .eid_end =3D end, \ + .handler =3D handle, \ +}; + +void vsbi_handle_ecall(struct vcpu *vcpu, struct cpu_user_regs *regs); +const struct vsbi_ext *vsbi_find_extension(unsigned long eid); + +void check_vsbi_ext_ranges(void); + +#endif diff --git a/xen/arch/riscv/riscv64/asm-offsets.c b/xen/arch/riscv/riscv64/= asm-offsets.c index 3b5daf3b36..472cced4f8 100644 --- a/xen/arch/riscv/riscv64/asm-offsets.c +++ b/xen/arch/riscv/riscv64/asm-offsets.c @@ -49,6 +49,7 @@ void asm_offsets(void) OFFSET(CPU_USER_REGS_T6, struct cpu_user_regs, t6); OFFSET(CPU_USER_REGS_SEPC, struct cpu_user_regs, sepc); OFFSET(CPU_USER_REGS_SSTATUS, struct cpu_user_regs, sstatus); + OFFSET(CPU_USER_REGS_HSTATUS, struct cpu_user_regs, hstatus); OFFSET(CPU_USER_REGS_PREGS, struct cpu_user_regs, pregs); BLANK(); DEFINE(PCPU_INFO_SIZE, sizeof(struct pcpu_info)); diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 8f46f1a1de..9b4835960d 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -26,6 +26,7 @@ #include #include #include +#include =20 /* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE] @@ -110,6 +111,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, =20 end_boot_allocator(); =20 + check_vsbi_ext_ranges(); + /* * The memory subsystem has been initialized, we can now switch from * early_boot -> boot. diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index f061004d83..5c3d1988d7 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 /* * Initialize the trap handling. @@ -114,6 +115,13 @@ void do_trap(struct cpu_user_regs *cpu_regs) =20 switch ( cause ) { + case CAUSE_VIRTUAL_SUPERVISOR_ECALL: + /* CAUSE_VIRTUAL_SUPERVISOR_ECALL should come from VS-mode */ + BUG_ON(!(cpu_regs->hstatus & HSTATUS_SPV)); + + vsbi_handle_ecall(current, cpu_regs); + break; + case CAUSE_ILLEGAL_INSTRUCTION: if ( do_bug_frame(cpu_regs, pc) >=3D 0 ) { diff --git a/xen/arch/riscv/vsbi/Makefile b/xen/arch/riscv/vsbi/Makefile new file mode 100644 index 0000000000..820eb10ac2 --- /dev/null +++ b/xen/arch/riscv/vsbi/Makefile @@ -0,0 +1 @@ +obj-y +=3D core.o diff --git a/xen/arch/riscv/vsbi/core.c b/xen/arch/riscv/vsbi/core.c new file mode 100644 index 0000000000..5ac4fee379 --- /dev/null +++ b/xen/arch/riscv/vsbi/core.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +#include +#include +#include + +extern const struct vsbi_ext _svsbi_exts[], _evsbi_exts[]; + +void __init check_vsbi_ext_ranges(void) +{ + for ( const struct vsbi_ext *a =3D _svsbi_exts; a !=3D _evsbi_exts; a+= + ) + for ( const struct vsbi_ext *b =3D a + 1; b !=3D _evsbi_exts; b++ ) + if ( !(a->eid_end < b->eid_start || b->eid_end < a->eid_start)= ) + panic("EID range overlap detected: " + "%s:[#%#lx..#%#lx] vs %s:[#%#lx..#%#lx]\n", + a->name, a->eid_start, a->eid_end, + b->name, b->eid_start, b->eid_end); +} + +const struct vsbi_ext *vsbi_find_extension(unsigned long eid) +{ + const struct vsbi_ext *ext; + + for ( ext =3D _svsbi_exts; ext !=3D _evsbi_exts; ext++ ) + if ( (eid >=3D ext->eid_start) && (eid <=3D ext->eid_end) ) + return ext; + + return NULL; +} + +void vsbi_handle_ecall(struct vcpu *vcpu, struct cpu_user_regs *regs) +{ + const unsigned long eid =3D regs->a7; + const unsigned long fid =3D regs->a6; + const struct vsbi_ext *ext =3D vsbi_find_extension(eid); + int ret; + + if ( ext ) + ret =3D ext->handler(vcpu, eid, fid, regs); + else + { + printk("Unsupported Guest SBI EID #%#lx, FID #%lu\n", eid, regs->a= 1); + ret =3D SBI_ERR_NOT_SUPPORTED; + } + + /* + * The ecall instruction is not part of the RISC-V C extension (compre= ssed + * instructions), so it is always 4 bytes long. Therefore, it is safe = to + * use a fixed length of 4 bytes instead of reading guest memory to + * determine the instruction length. + */ + regs->sepc +=3D 4; + regs->a0 =3D ret; +} diff --git a/xen/arch/riscv/xen.lds.S b/xen/arch/riscv/xen.lds.S index 45d2e053d0..331a7d63d3 100644 --- a/xen/arch/riscv/xen.lds.S +++ b/xen/arch/riscv/xen.lds.S @@ -61,6 +61,13 @@ SECTIONS __note_gnu_build_id_end =3D .; } :note :text #endif + + . =3D ALIGN(POINTER_ALIGN); + DECL_SECTION(.vsbi.exts) { + _svsbi_exts =3D .; + *(.vsbi.exts) + _evsbi_exts =3D .; + } :text _erodata =3D .; /* End of read-only data */ =20 . =3D ALIGN(PAGE_SIZE); --=20 2.52.0 From nobody Thu Dec 18 07:59:51 2025 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; 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=1765990489; cv=none; d=zohomail.com; s=zohoarc; b=S7o/qgXUtSGVc385DEYJDdNiXYp1YBnp/p5uzYpG44lVNm986AQFToUTkEUiIMvjCBgpirQXFKT46/3RVsV8lOzKycuu1MPfpq3mR67dOKXpN7hBVvQL/aUWk4tXmFYTeUO1BkmtHtJK44ms5y2iorVPvAZ6aCUGoxszeqFSsj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765990489; 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=Xk8VLGfP89HNwQj29hZGIP9LR5h0D6fyBDqrK9XH7AU=; b=bsMXjLZtNZVxRrOOSMhE0UTpxp9LmgB0G0LNScVMUZWgjdwTMR6FuSu7gxDzKnYA5Kc5EXzevp5dNUw8SWFQ+YgxiwO4RslhOqFy7ueky4ZIXHDDfFyFjwln5LkwhANl6Xbisc1YGWe0030/ibz6FDRpkABLB8aq9SwXdVzQO5c= 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 1765990489716112.29070430206605; Wed, 17 Dec 2025 08:54:49 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1188964.1509970 (Exim 4.92) (envelope-from ) id 1vVunL-0003Qz-1S; Wed, 17 Dec 2025 16:54:35 +0000 Received: by outflank-mailman (output) from mailman id 1188964.1509970; Wed, 17 Dec 2025 16:54:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vVunK-0003Qs-U0; Wed, 17 Dec 2025 16:54:34 +0000 Received: by outflank-mailman (input) for mailman id 1188964; Wed, 17 Dec 2025 16:54:33 +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 1vVunJ-0003An-3A for xen-devel@lists.xenproject.org; Wed, 17 Dec 2025 16:54:33 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0e3aa4cc-db69-11f0-9cce-f158ae23cfc8; Wed, 17 Dec 2025 17:54:30 +0100 (CET) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-649820b4b3aso4427797a12.3 for ; Wed, 17 Dec 2025 08:54:30 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b7cfa5d1e89sm2015077966b.69.2025.12.17.08.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 08:54:29 -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: 0e3aa4cc-db69-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765990470; x=1766595270; 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=Xk8VLGfP89HNwQj29hZGIP9LR5h0D6fyBDqrK9XH7AU=; b=nqeXuKJc5XiRRMXRIuSwfH6pDZnvgwy3bJWCn/Jgisazc9SWBYiaKmxBzuQAUrM+U5 vOl/LfTZLPvywLmEDihU1peIxZgTqbTfZeKcR8l0tGeg1drbyH8W9rezyt7Uql+GYmmK UtYvR/SUGCp0YwfDAxTHQiwK56l6CfvAEACrsDS6YVRUw7vcMKxXnbC7iUFNyA//6PPO 7GwKelkH8rx8oide/KBCTELO2icz7Ept60DVm/euSaq9WMn1xl8uXrtcw4guhRpd1QGg vg4iAE3ZSGBLg8P5+AfeflfJ0GMulCBb9C1j0K/npFnT++yWKb75dViEH4Iyn46KrDFh 6VNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765990470; x=1766595270; 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=Xk8VLGfP89HNwQj29hZGIP9LR5h0D6fyBDqrK9XH7AU=; b=CM6VZzHxC7MbnNb1agOwZUIT4x8cOHgJ/PAy50DFbh2NpD+hMT/yCSITkBTJFI1lFd iEpG9WHmvfTDipXVHniJ8luVFkJ7GKlufjp7qOFkvEnLVAjOctsPZjmZ2whU5bVxh5Qn Fyo21EFNn14iwznUIIQ4yCPOdImWOR1YnnZ58uuODtIzZecL9fpFN7kuXjviSW+H+k99 5ta1YcvIGPlcmWxdxaZdQQCtY93QfJ24zHXq/DMgLpq9V4L6Hh5v0s0p6QVLBX9hvLrk yQdXw2WVTWcVrztznhgKeJymNs+Wvn6rZ9NWF87UkLv1pssLewnSK/zgRezHbZFwyZey 6/Hw== X-Gm-Message-State: AOJu0Yy9WdgaWtZNLUr9hLxFGwBE3JT5Z4A/xPBwOSgqyr8rYXCChAJS oWTTbm18auy1d5M8S3MY1DiDnqoAkXv02AnlHouZ1dwKqeEAHqPcnzv0SXQFSg== X-Gm-Gg: AY/fxX5HNwywoQ/tdiwWys8Zdr4EJMEKl9G8bRnecp+lbvOUArGMMeYn91eHKHVDGui KkFcHIUzgpI9+so8zhLlRywOLMNzaGeeZ4MsMr3Jj/0utg5v9cgyWCXyJBaEBZfULNtI7m3SjCn ICFR2cGaZDj9ODcP+3YROqq2xm/u+WVGiZt9njcw0QhDMni/0vmOZAqtszEOvdJvyv/3P1esXnE 4EMqSpqVMj9yWyUwNn3IFBdVm/fKUWtnZojf7oAejruCMfE/rTccvxxhK0d2zxRV6EvJGjvpi3s MF1XfNWPWoz7SPPgZ0qGgc9lVCCExVu22D7xR6Xt8NCD7OQc2b3DaIU1UXtfBbKgGtxf4G+g8J8 9wB8HVHYUjyJAcZPk/m5EtbfPlVhCfRANfwYOssa+PAYeH5FwF1og0JGG3/U85GqY7ecZsSf9ZJ Nd56+KYXgQ8Ov18rhyOlMy+m6QvBQB03kARwidV+gmLFgldrezFGqyh5o= X-Google-Smtp-Source: AGHT+IEMdu2XSHa6enoreBym9vX+fgimxJ1D+uQFmMT9LBHk2c/NxVbfJe3zJelR1wqkCmuusah+pw== X-Received: by 2002:a17:907:68a2:b0:b80:448:37f1 with SMTP id a640c23a62f3a-b800448e482mr297467166b.10.1765990469724; Wed, 17 Dec 2025 08:54:29 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 2/3] xen/riscv: add RISC-V legacy SBI extension support for guests Date: Wed, 17 Dec 2025 17:54:19 +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: 1765990491121154100 Content-Type: text/plain; charset="utf-8" This commit adds support for legacy SBI extensions (version 0.1) in Xen for guest domains. The changes include: 1. Define all legacy SBI extension IDs (0x0 to 0x8) for better clarity and completeness. 2. Implement handling of legacy SBI extensions, starting with support for SBI_EXT_0_1_CONSOLE_{PUT,GET}CHAR. The implementation uses the existing virtual SBI framework to handle legacy SBI ecalls, ensuring compatibility with older SBI specifications in RISC-V guests. Signed-off-by: Oleksii Kurochko --- Changes in v2: - s/vsbi-legacy-extension.*/legacy-extension.* - Correct padding for SBI_EXT_0_1_* macros. - Set ret =3D SBI_ERR_NOT_SUPPORTED; in the case of vsbi_legacy_ecall_hand= ler() instead of regs->a0 =3D ... as regs->a0 will be overwritten in vsbi_handle_ecall(). - Use domain_crash() instead of panic() in vsbi_legacy_ecall_handler() and add TODO. - Use newly introduced VSBI_EXT macros instead of VSBI_EXT_{START,END}. - Introduce vsbi_print_line() and use it instead of plain printk() in the handler of SBI_EXT_0_1_CONSOLE_PUTCHAR. --- xen/arch/riscv/include/asm/sbi.h | 11 ++++- xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/legacy-extension.c | 65 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 xen/arch/riscv/vsbi/legacy-extension.c diff --git a/xen/arch/riscv/include/asm/sbi.h b/xen/arch/riscv/include/asm/= sbi.h index ade24a572d..751bae6d66 100644 --- a/xen/arch/riscv/include/asm/sbi.h +++ b/xen/arch/riscv/include/asm/sbi.h @@ -14,8 +14,15 @@ =20 #include =20 -#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 -#define SBI_EXT_0_1_SHUTDOWN 0x8 +#define SBI_EXT_0_1_SET_TIMER 0x0 +#define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 +#define SBI_EXT_0_1_CONSOLE_GETCHAR 0x2 +#define SBI_EXT_0_1_CLEAR_IPI 0x3 +#define SBI_EXT_0_1_SEND_IPI 0x4 +#define SBI_EXT_0_1_REMOTE_FENCE_I 0x5 +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA 0x6 +#define SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID 0x7 +#define SBI_EXT_0_1_SHUTDOWN 0x8 =20 #define SBI_EXT_BASE 0x10 #define SBI_EXT_RFENCE 0x52464E43 diff --git a/xen/arch/riscv/vsbi/Makefile b/xen/arch/riscv/vsbi/Makefile index 820eb10ac2..bc5755cb13 100644 --- a/xen/arch/riscv/vsbi/Makefile +++ b/xen/arch/riscv/vsbi/Makefile @@ -1 +1,2 @@ obj-y +=3D core.o +obj-y +=3D legacy-extension.o diff --git a/xen/arch/riscv/vsbi/legacy-extension.c b/xen/arch/riscv/vsbi/l= egacy-extension.c new file mode 100644 index 0000000000..75280de3bc --- /dev/null +++ b/xen/arch/riscv/vsbi/legacy-extension.c @@ -0,0 +1,65 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +#include +#include + +static void vsbi_print_line(char c) +{ + struct domain *cd =3D current->domain; + struct domain_console *cons =3D cd->console; + + if ( !is_console_printable(c) ) + return; + + spin_lock(&cons->lock); + ASSERT(cons->idx < ARRAY_SIZE(cons->buf)); + if ( c !=3D '\n' ) + cons->buf[cons->idx++] =3D c; + if ( (cons->idx =3D=3D (ARRAY_SIZE(cons->buf) - 1)) || (c =3D=3D '\n')= ) + { + cons->buf[cons->idx] =3D '\0'; + guest_printk(cd, XENLOG_G_DEBUG "%s\n", cons->buf); + cons->idx =3D 0; + } + spin_unlock(&cons->lock); +} + +static int vsbi_legacy_ecall_handler(struct vcpu *vcpu, unsigned long eid, + unsigned long fid, + struct cpu_user_regs *regs) +{ + int ret =3D 0; + + switch ( eid ) + { + case SBI_EXT_0_1_CONSOLE_PUTCHAR: + vsbi_print_line((char)regs->a0); + break; + + case SBI_EXT_0_1_CONSOLE_GETCHAR: + ret =3D SBI_ERR_NOT_SUPPORTED; + 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(vcpu->domain, + "%s: Unsupported ecall: FID: #%lx, EID: #%lx\n", + __func__, fid, eid); + break; + } + + return ret; +} + +VSBI_EXT(legacy, SBI_EXT_0_1_SET_TIMER, SBI_EXT_0_1_SHUTDOWN, + vsbi_legacy_ecall_handler); --=20 2.52.0 From nobody Thu Dec 18 07:59:51 2025 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; 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=1765990507; cv=none; d=zohomail.com; s=zohoarc; b=XLzQ41/9DoAourRP2KdP/h6uzjtNz7kT3UcZ9PNmLXxHYb+O5xHB83aEk+FQ3pJFvqusPUiMvRe+eDWsQ0XPg8kOppoVwZDu8n9z6a4NrsaInvySb2Fett+r6op7M98LgaL8cBhdWXpxPmKehi+0h+xMZVGO0Qb6eM69kAiMH34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765990507; 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=HProhutWVGlAtxwETbSQ5hkPTg+rlxBFKSeiQ584ZZ8=; b=H4o+dgcQCvmBNdeov8Sj+nmxJwzQircxNsIBYibAfhWyNbK5Y/aKmv5KOjd2GU03maMpbQdrph1xUyDZqZuf72S+vMhpva5CkmHqOaBUZ3NjfY0XfZ+gbmgL5u3401nRF1oWl4P/1XdhhWIssD1hzEZIkA1sBY21HfDkJ62AbM0= 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 1765990507283735.3452887840689; Wed, 17 Dec 2025 08:55:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1188965.1509980 (Exim 4.92) (envelope-from ) id 1vVunM-0003fj-9D; Wed, 17 Dec 2025 16:54:36 +0000 Received: by outflank-mailman (output) from mailman id 1188965.1509980; Wed, 17 Dec 2025 16:54:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vVunM-0003fW-5L; Wed, 17 Dec 2025 16:54:36 +0000 Received: by outflank-mailman (input) for mailman id 1188965; Wed, 17 Dec 2025 16:54:34 +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 1vVunK-0003An-3U for xen-devel@lists.xenproject.org; Wed, 17 Dec 2025 16:54:34 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0ee1d115-db69-11f0-9cce-f158ae23cfc8; Wed, 17 Dec 2025 17:54:31 +0100 (CET) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b7355f6ef12so1166558066b.3 for ; Wed, 17 Dec 2025 08:54:31 -0800 (PST) Received: from fedora (user-109-243-71-38.play-internet.pl. [109.243.71.38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b7cfa5d1e89sm2015077966b.69.2025.12.17.08.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 08:54:30 -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: 0ee1d115-db69-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765990471; x=1766595271; 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=HProhutWVGlAtxwETbSQ5hkPTg+rlxBFKSeiQ584ZZ8=; b=Xwl5f+mQLtMQeO7NucwY7GzQkPHCKK1dEuvgD3r9fOD+3PCyE0dMaxoZouvgnAZMsI yKkpDY5W6zZNGz0zXDIPqbxBgjaFshIkh4vN/Pohs3nKK8+/f+M7Nd7RX3saHlwj5Sbs ln9OBt5vezar28AjM9UJ3qQmS4XMdAr7rO9G4MHnrM7gkPSlEmYl4d9tfIk1gCc/MimE WSPXxINToNKpVkpTTr0phYosAh9LQ8gxuJEfH7mGd4mzMmQjW6gh0SjgchZHXxXAtTMr ukFfDIPvaZJiqaCSElp1QrYcZXa+CXdhIv25uTHfKeJPRSqWCMN0CRkRcS2xkQvLltkX IGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765990471; x=1766595271; 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=HProhutWVGlAtxwETbSQ5hkPTg+rlxBFKSeiQ584ZZ8=; b=wnaapf1vaM95z1hLPuJO0eiLFn1p2eHnHNELlAu9XcO/jAwKxfGQlykp5TI+MzFAbL CvDWn0RrRMADbldqgNezSqvxVl09ozuXrzn5scc/EML934sXxDnQtBsrJ19Q+NhlChff AJ1pWpfjIH2oVQWadn0/4Rfx2OkZ5woNQkzlhIQNkwJB0BOWfhaw82oUZWHlcChuaKq4 B57kWos7hsbO7hPpHSRkN67mBzl17xA+TQMEPPgBgvL8s3E2D2CvE/hpigZH291zoWxN 60NTux71F77wi0FioQAM+IV1WCFS2afBG3o1emZ/aZTNlJpv//CPKsLFLnArmsnJyTfR +O7w== X-Gm-Message-State: AOJu0YxJV8lgBwwlhqSObLwiqupQtlaXxSUbChpOrlNYbxIRFAub6HT/ wne/iEwXWJ8HGSB2aKqqwB+YFHHqIB1HFa38zVhUYQikrO9jZRK8ffa7hlsY/g== X-Gm-Gg: AY/fxX5NbVTEv3IPjlNA2twCIrihNH+C76H0uiqylJnAO0mWEMySX6d9zBZT8DdrCeB syQ5uW70lUPyu5QHFt4UtHJX7cZmQ52/bmevLpUO5yxLRoaoijjkHapXl2Z9tsZwk3yeNzr3csp nd0xyq7Kpdf50HZ3w2yfmKdMKi6mdwBufA8MuOK52UzyMkE2nwzpRwj1YmYExUxx1Mbe6nMOYBP iYgTeKGq1RZakVmBiM36u1ODM08xZdE1JY8jmzD8dBPT6h4MsiMNsTrc5Gt1ZLQfVbVuNPzXDjL ERAscgESzvEElDC0GpIcRow3STU9VjE9iDIPGxG/MmuGE4WIbF1ux7RSW0lOMMDABTs+HM4rNGO ndxb7cykD4mDD3ab+9e/clsrbZRmi8d+4jASB3WRtQOL+6aX/eL/Otl50EilKXacPhCgq2eft1y qb9iJzgJKD9Ac4mLG9V56tEVURYef8h/nNv8JB2AcV7ie76TFXoKTUoxk= X-Google-Smtp-Source: AGHT+IG1H3GtPgFSOJHR9vgrIn0wXF1xLUG3R3t5vkJcnFXHHJV3MrSFklOcRbKrp1y1mVpyVM3LIA== X-Received: by 2002:a17:907:7f23:b0:b72:588:2976 with SMTP id a640c23a62f3a-b7d23d1390bmr1805073066b.60.1765990470626; Wed, 17 Dec 2025 08:54:30 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH v2 3/3] xen/riscv: add RISC-V virtual SBI base extension support for guests Date: Wed, 17 Dec 2025 17:54:20 +0100 Message-ID: <2e42e8ee51badcfa2cb16e3db71fdecaac445bca.1765888425.git.oleksii.kurochko@gmail.com> 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: 1765990509337154100 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 VCPU_SBI_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 --- 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 | 7 +++ xen/arch/riscv/vsbi/Makefile | 1 + xen/arch/riscv/vsbi/base-extension.c | 71 ++++++++++++++++++++++++++++ 3 files changed, 79 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 751bae6d66..eb710950cc 100644 --- a/xen/arch/riscv/include/asm/sbi.h +++ b/xen/arch/riscv/include/asm/sbi.h @@ -14,6 +14,10 @@ =20 #include =20 +#define XEN_SBI_VER_MAJOR 0 +#define XEN_SBI_VER_MINOR 2 +#define XEN_SBI_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 +36,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 bc5755cb13..8ce470f787 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 0000000000..567429c715 --- /dev/null +++ b/xen/arch/riscv/vsbi/base-extension.c @@ -0,0 +1,71 @@ + +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +#include +#include +#include + +static int vsbi_base_ecall_handler(struct vcpu *vcpu, unsigned long eid, + unsigned long fid, + struct cpu_user_regs *regs) +{ + int ret =3D 0; + struct sbiret sbi_ret; + + 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 XEN_SBI_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(vcpu->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(vcpu->domain, + "%s: Unsupported ecall: FID: #%lx, EID: #%lx\n", + __func__, fid, eid); + break; + } + + return ret; +} + +VSBI_EXT(base, SBI_EXT_BASE, SBI_EXT_BASE, vsbi_base_ecall_handler) --=20 2.52.0