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 6AB99E9B249 for ; Tue, 24 Feb 2026 10:42:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1239775.1541185 (Exim 4.92) (envelope-from ) id 1vups3-0002Nr-FY; Tue, 24 Feb 2026 10:42:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1239775.1541185; Tue, 24 Feb 2026 10:42:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vups3-0002Nk-Bf; Tue, 24 Feb 2026 10:42:27 +0000 Received: by outflank-mailman (input) for mailman id 1239775; Tue, 24 Feb 2026 10:42:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vups2-0002NZ-UX for xen-devel@lists.xenproject.org; Tue, 24 Feb 2026 10:42:26 +0000 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [2a00:1450:4864:20::336]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 821fdca2-116d-11f1-b164-2bf370ae4941; Tue, 24 Feb 2026 11:42:25 +0100 (CET) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso39941625e9.1 for ; Tue, 24 Feb 2026 02:42:26 -0800 (PST) Received: from [192.168.1.6] (user-109-243-67-101.play-internet.pl. [109.243.67.101]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483a31bc068sm315306205e9.4.2026.02.24.02.42.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Feb 2026 02:42: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: 821fdca2-116d-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771929745; x=1772534545; darn=lists.xenproject.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WaFq5XH2JILj6dEwhuKq5ki6UOjiTkyCI8uYrK6FTZk=; b=X++mYcPha4Hxseebp9o4tpIFhNNh3MlrTja5hRtCRcT2/os5ZdwFa9nPvQmA/HeU8Z oaZrGtgq62ZhDT9zA58EchdWXRBTPXgcZC1xNRt1P0N4bOf0bu2+S/KM30AvgawB8CyA 3MpVUKUqvumUF8im7fLcn7JZbkS7EAbEzOQ7BGvf4Yj6GGJ0mwT68tKfvZgD6LTK8gYD fm/NUdp3Rq6Q7UDnKUo4JiUq7+9kuT7l/9+oeYf/3f4/V0AvfdDig1X3dvTneUapgXU2 Ba9lLsmAY8flQyVAY63B1XC+55waawpFWPMVpKfoAQZ2DjuqIm1Nsq7zbsLCOA673M3Z /Zdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771929745; x=1772534545; h=content-transfer-encoding:in-reply-to: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=WaFq5XH2JILj6dEwhuKq5ki6UOjiTkyCI8uYrK6FTZk=; b=Z1QWN1ixCmlkm3cSHv1uOqUT771BBb+wq89qWTyXxt3pMCcgyoBPGrKgThOyq/xKZ0 DroG/OVKWYnyN4+7EM/z+s7yz88DL+LY/H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471:700:f281 with SMTP id 5b1f17b1804b1-483a95e5b24mr189281825e9.25.1771929745076; Tue, 24 Feb 2026 02:42:25 -0800 (PST) Message-ID: <5e4362ed-c310-442b-a742-ca7c3d1c47dc@gmail.com> Date: Tue, 24 Feb 2026 11:42:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 01/14] xen/riscv: detect and store supported hypervisor CSR bits at boot To: Jan Beulich Cc: Romain Caritey , Alistair Francis , 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: <4f36d83e58bfba807660ebc1fc48e71ae056805a.1771590794.git.oleksii.kurochko@gmail.com> <541a6c57-406c-49e5-8b8b-019e30bf0d89@suse.com> Content-Language: en-US From: Oleksii Kurochko In-Reply-To: <541a6c57-406c-49e5-8b8b-019e30bf0d89@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/24/26 11:16 AM, Jan Beulich wrote: > On 24.02.2026 10:44, Oleksii Kurochko wrote: >> On 2/24/26 9:07 AM, Jan Beulich wrote: >>> On 20.02.2026 17:18, Oleksii Kurochko wrote: >>>> --- a/xen/arch/riscv/domain.c >>>> +++ b/xen/arch/riscv/domain.c >>>> @@ -2,9 +2,39 @@ >>>> >>>> #include >>>> #include >>>> +#include >>>> #include >>>> #include >>>> >>>> +#include >>>> +#include >>>> + >>>> +struct csr_masks { >>>> + register_t hedeleg; >>>> + register_t henvcfg; >>>> + register_t hideleg; >>>> + register_t hstateen0; >>>> +}; >>>> + >>>> +static struct csr_masks __ro_after_init csr_masks; >>>> + >>>> +void __init init_csr_masks(void) >>>> +{ >>>> +#define INIT_CSR_MASK(csr, field) do { \ >>>> + register_t old; \ >>>> + old = csr_read(CSR_##csr); \ >>> Can't this be the initializer of the variable? Can't ... >> I agree that this is change is okay to be done but I am not sure about ... >> >>>> + csr_set(CSR_##csr, ULONG_MAX); \ >>> ... csr_swap() be used here, too? >> ... as after re-reading spec again I am not sure that we can do in this way >> at all. >> >> Initially I used csr_set() instead of csr_swap() or csr_write() as csr_set() to >> take into account a writability of the bit, so it won't touch a bit if it >> is r/o. > To me the spec isn't quite clear enough in this regard. > >> But it seems like this approach won't work with**WLRL or WPRI fields as these >> fields aren't r/o, > In the CSRs presently dealt with, are there any WLRL fields at all? (I don't > think WPRI fields represent much of an issue for the purpose here.) Agree, currently used CSRs in this function don't have WLRL feilds, but I suppose we want to have the similar treatment (read WLRL fields and reuse what was read) for WLRL fields as these fields expect only valid value and so all 1s for this fields can be wrong to use. > >> but they only support specific value and for example: >> >> - Implementations are permitted but not required to raise an >> illegal-instruction exception if an instruction attempts to write a >> non-supported value to a WLRL field. >> - For these reserved fields, software is required to preserve the existing >> values when writing to other fields in the same register. Overwriting them >> with 1s could be considered non-compliant behavior. >> >> So it seems like we can't just do csr_swap() with all 1s and it is needed >> to pass a mask to INIT_CSR_MASK() which will tell which bits should be >> ignored and don't touched. >> For example, HENVCFG and HSTATEEN0 has WPRI fields. >> >> reserved_bits_mask = 0x1FFFFFFCFFFFFF00; >> tmp = csr_read(HENVCFG); >> tmp=(~reserved_bits_mask) |(tmp&reserved_bits_mask); csr_set(HENVCFG, tmp); > What I find further concerning is that HSTATEEN0 also may have read-only-1 > fields. You don't currently cope with that, I think. Because of this: A bit in an hstateen CSR cannot be read-only one unless the same bit is read-only one in the matching mstateen CSR. ? I expect that it will be covered by csr_set() which will touch only writable bits and ignore read-only. So doesn't matter if a bit is read only 1 or 0 it still shouldn't be in the final mask. ~ Oleksii