Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0A606D59D99 for ; Mon, 15 Dec 2025 08:21:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1186659.1508084 (Exim 4.92) (envelope-from ) id 1vV3oj-0005gd-Tp; Mon, 15 Dec 2025 08:20:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1186659.1508084; Mon, 15 Dec 2025 08:20: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 1vV3oj-0005gW-Qm; Mon, 15 Dec 2025 08:20:29 +0000 Received: by outflank-mailman (input) for mailman id 1186659; Mon, 15 Dec 2025 08:20:29 +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 1vV3oj-0005gQ-3N for xen-devel@lists.xenproject.org; Mon, 15 Dec 2025 08:20:29 +0000 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [2a00:1450:4864:20::32a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e87a2398-d98e-11f0-9cce-f158ae23cfc8; Mon, 15 Dec 2025 09:20:25 +0100 (CET) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4777771ed1aso23563935e9.2 for ; Mon, 15 Dec 2025 00:20:25 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f4f4150sm173924275e9.11.2025.12.15.00.20.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Dec 2025 00:20:24 -0800 (PST) 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: e87a2398-d98e-11f0-9cce-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765786825; x=1766391625; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=/YFLV4pXe8bVfA8YZOHvsyj2Qk1hXDlSxSc6Pp20XXE=; b=GB1mKjISO7liKO/LrUIvcwct4Pm+ZzNhRWfstjRSw2wtu8JTr1c2yRQUZprc9rzd0J SzDVSXcwMZGw9ZvEYU4509mAfDAScmPhvQWE+N7JBUSas7ntOGFy7NRr/AtF+2p4HWdA 9gapziJ6X9CSI7n/+ZW5SpeDGNP4XkFfzAFa4SteC/7rOLODCDW0M8yKGkpIl9qG0KEn H4fwnnE8HxHQD9u3DmY6BDUFxxCh4geN99JLGSbCP4kZCppg0WTNguwoCsP6OPajv7aD 03raVGyon2E4LlsVk+csbeySvVqkuiXTJESYjfeu9uo9cMntjb2TGgFQq+0PgxV8FTsA zR+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765786825; x=1766391625; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/YFLV4pXe8bVfA8YZOHvsyj2Qk1hXDlSxSc6Pp20XXE=; b=u9PX57RFulp+9p2a7fjDuxvW5rukA5Z4mhyj9ChxGu7zsbhHgxjQLzIwwj35azxMLh KV1pXdoLWB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hgkWI4sdTPj+9tnZuwqtwO1lXKRFKdFUBAhGxcvAcyo58BBgpsKTQ9N5ppQatTJdzA== X-Received: by 2002:a05:600c:1d2a:b0:477:9a28:b09a with SMTP id 5b1f17b1804b1-47a8f7039c3mr104435225e9.0.1765786825162; Mon, 15 Dec 2025 00:20:25 -0800 (PST) Message-ID: <3cf7d382-3a05-401b-8483-41aa436079c5@suse.com> Date: Mon, 15 Dec 2025 09:20:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 3/3] xen/riscv: add RISC-V virtual SBI base extension support for guests To: Oleksii Kurochko Cc: Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Stefano Stabellini , xen-devel@lists.xenproject.org References: <275721bc-07c2-4f69-93c2-e6d3022fee4f@suse.com> <5154e129-675b-4027-b97f-257559c7ea50@gmail.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiu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ea50@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 12.12.2025 16:25, Oleksii Kurochko wrote: > On 12/8/25 4:15 PM, Jan Beulich wrote: >> On 01.12.2025 11:24, Oleksii Kurochko wrote: >>> --- /dev/null >>> +++ b/xen/arch/riscv/vsbi/vsbi-base-extension.c >>> @@ -0,0 +1,52 @@ >>> + >>> +/* SPDX-License-Identifier: GPL-2.0-only */ >>> + >>> +#include >>> +#include >>> + >>> +#include >>> +#include >>> +#include >>> + >>> +extern unsigned long __ro_after_init sbi_spec_version; >>> +extern long __ro_after_init sbi_fw_id; >>> +extern long __ro_after_init sbi_fw_version; >>> + >>> +static int vsbi_base_ecall_handler(struct vcpu *vcpu, unsigned long eid, >>> + unsigned long fid, >>> + struct cpu_user_regs *regs) >>> +{ >>> + int ret = 0; >>> + struct sbiret sbi_ret; >>> + >>> + switch ( fid ) { >>> + case SBI_EXT_BASE_GET_SPEC_VERSION: >>> + regs->a1 = sbi_spec_version; >> Wouldn't this need to be the minimum of what firmware supports and what Xen >> supports / knows about? (Assuming backward compatibility among the spec >> versions of course.) > > The base extension is mandatory (according to the spec), and based on some Linux > commits from contributors to the OpenSBI spec, it is also intended to allow > backward compatibility and probing of future extensions (although I was not able > to find this explicitly stated in the spec). > > However, none of this guarantees that everything else is backward compatible. > For example, the entire v0.1 SBI has been moved to the legacy extension, which > is now an optional extension. This is technically a backwards-incompatible > change because the legacy extension is optional, and v0.1 of the SBI does not > allow probing. > > Regarding what should be written to|regs->a1|, I think you are right: it should > be the minimum of what the firmware provides and what Xen supports. Otherwise, > if|sbi_spec_version| is set to 2.0 and we return 2.0 to the guest, the guest might > try to probe the DBGN (which Xen does not currently support) extension and use > it instead of the legacy extension for the early console. > > >>> + break; >>> + case SBI_EXT_BASE_GET_IMP_ID: >>> + regs->a1 = sbi_fw_id; >>> + break; >>> + case SBI_EXT_BASE_GET_IMP_VERSION: >>> + regs->a1 = sbi_fw_version; >> Same concern here, but see also below. > > For SBI_EXT_BASE_GET_IMP_ID, I think we want to return XEN id which is according > to OpenSBI spec is 7. > > Something similar for SBI_EXT_BASE_GET_IMP_VERSION, maybe we want to return Xen > version code (XEN_FULLVERSION). > >> >>> + break; >>> + case SBI_EXT_BASE_GET_MVENDORID: >>> + case SBI_EXT_BASE_GET_MARCHID: >>> + case SBI_EXT_BASE_GET_MIMPID: >>> + sbi_ret = sbi_ecall(SBI_EXT_BASE, fid, 0, 0, 0, 0, 0, 0); >> This may be okay to do for the hardware domain, but hardly for DomU-s. > > I don’t see an issue with returning the vendor, microarchitecture, and > processor ID. This is essentially what other hypervisors do. > > What would be better to return? Returning 0 could be an option, and according > to the RISC-V spec: > This register must be readable in any implementation, but a value of 0 can > be returned to indicate the field is not implemented. > > So returning 0 would simply indicate that the field is not provided for case > of DomUs, and provide it for hardware domain. > > Would it be better? > >> >> Same concern for SBI_EXT_BASE_GET_IMP_ID. >> >>> + ret = sbi_ret.error; >>> + regs->a1 = sbi_ret.value; >>> + break; >>> + case SBI_EXT_BASE_PROBE_EXT: >>> + regs->a1 = vsbi_find_extension(regs->a0) ? 1 : 0; >> At least for hwdom doesn't this also need combining virtual and >> underlying physical lookup, if for some extensions you may pass the >> requests down to the physical one (as done above)? > > I think I understand your intention, but I am not 100% sure that we need to > perform a physical lookup. There may be implementation-specific cases where > a call is emulated by the hypervisor instead of being passthroughed to > OpenSBI. > In other words, it could be the case that an extension is fully emulated > without requiring support for the corresponding physical extension. I don't have sufficient RISC-V knowledge to further comment on this. My main concern is that we have to present (a) a consistent picture to both hwdom and DomU-s while (b) presenting a properly virtualized view to DomU-s (i.e. abstracting away hardware implementation details). In particular for DomU-s you will already now need to think of what happens if a guest is migrated: Data returned from vSBI probably shouldn't change across migration, or else you may confuse the guest. Jan