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 2E50DF54AC0 for ; Tue, 24 Mar 2026 14:17:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1260873.1554039 (Exim 4.92) (envelope-from ) id 1w52ZI-0003JS-SW; Tue, 24 Mar 2026 14:17:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1260873.1554039; Tue, 24 Mar 2026 14:17:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w52ZI-0003JL-Oz; Tue, 24 Mar 2026 14:17:16 +0000 Received: by outflank-mailman (input) for mailman id 1260873; Tue, 24 Mar 2026 14:17:15 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w52ZH-0003JA-Mx for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 14:17:15 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w52ZG-00DNqk-P9 for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 15:17:14 +0100 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c29ce7-5cb7-0a2a0a5109dd-0a2a4508cce0-16 for ; Tue, 24 Mar 2026 15:17:14 +0100 Received: from [209.85.128.46] (helo=mail-wm1-f46.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c29cea-1950-0a2a45080019-d155802eac30-3 for ; Tue, 24 Mar 2026 15:17:14 +0100 Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-486fb439299so44917585e9.0 for ; Tue, 24 Mar 2026 07:17:14 -0700 (PDT) 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-4870f81db8esm23115115e9.8.2026.03.24.07.17.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Mar 2026 07:17:13 -0700 (PDT) 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" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1774361834; x=1774966634; 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=jjk36FmCoVluiy2HZwxxB/+cIqhyJA+nOWcfdolVM2A=; b=ck9sis2/2DMCSYHHNaqG1OAMy1Xl7IpylVQ1mOuACbGOW2003rQz60qhn1aYQoezg/ yrJhtADPsktFQu0cNEjrG47F+M9oKkucNbc2Rim8/vs38nsfWFOk62antG0haJbNL/fm glcA4dGVpLzbD61t3HuHSiPLXXLzCxmXWO1FK/74njRe7nwJwvy6cwH21vnobY1Nqa3u aI4VBrI71gdML51eVeAubYZDqhQRs51//KyTHlwCj/FSRVbLHfF34qgPHhUfUCeMZrIC Uu7F4ZFDfrIfjiSunggzvJwQxpoRwOiULvS7jTh9iNFO7hWu/3+qxfq2PU2p7i6Xd50c N3Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774361834; x=1774966634; 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=jjk36FmCoVluiy2HZwxxB/+cIqhyJA+nOWcfdolVM2A=; b=MQPLl60JW5D8iengklGBBiwYYoTxKo0+ku3EpI6sSGbtTbi+aP/KtzGYTWy4OoYAyK +DvFvbGn9E1PVRWLPMxOShld5LVh98ZMUnJxKlhCM37WUl9P+erwN6nhb9tKBRqm5kob H9vgvvYC6wzEqLfbrkE8gFEMcyYf1/wnEOYpke2+FRFmSBGQGjyjUfCiTNj4kQPyYVJC 8s4VvavZ9J9orQ36OnQTqL79Zw+sp4hwebjY1wvuYDbSFnoNPE1A8TTlYMlFICHlMFpA CVder4JXneRJd9WFe3TPHLzxXYy3og0hYdhaXA1nSh86eSYttioQdPLWkvbcSUQI2+0d yc+g== X-Forwarded-Encrypted: i=1; AJvYcCXX4HH4s0UrY0BJ8MgADQ2Z0Zqk2NhKGlHwFybZJJskeu3Km5hWGHcHJoQrYl9vTaK8o9bDKKjvDRc=@lists.xenproject.org X-Gm-Message-State: AOJu0Yxnnmj8KocZan+Sy3VHgjhdzisn8RwpsIYZL3c0264SccEsZqXF laSCm2IWIOoWULiuMa1ZRnAb5pFvJWRfCZGPWhpnAN0JRIundRDAwqMMG75D9X4ndw== X-Gm-Gg: ATEYQzwxbY44yrOOAUFVHsJKeNiv4wqC5StBWzqwumY40BWN+dUh7Ro1i5faDN2PgIn 7aDW+ZdpdGoFIGNCFRIkA5idbhdezbQ+ax6Dj7VjfFD4UJudqouNCH1ezu2kqORcXqja2H2V8PO gdo6mm1EHYtTj0FQVBEhVzINV/QJHc2U52cSYWyf6Y3VKdxp0smCH8B6Q+V7N6AAVVJ5Qivy5E2 wNvz0OWsnJc6FYpOrY+HpkXzxM8OtwIthFuRQCFil7TXjTNklJONvY5kVhUJ9+DMmbAllMM5QzH iDbea2aqZGgAqlyFivbzzoZ6eSl/yb1DrXshWOOqLKW/6dsM4NruW8w2nyaUjnlDvURSFMvYxVN 2Xr/cnDp+ZuRkzpHiEb3Rwu1dql3KKg2WPqR1eZQYj9P/FAcw3ky3pn3hwyycpuyF0tXua2+eC0 lgzAArubsocqu5tZsklmqlcHvvKcDpazJYTWW/jeOXsA+vMLD8L3R3TwDpU3BkuXeoowIdpdUvH JtLFmZdjSEc5xE= X-Received: by 2002:a05:600c:c48f:b0:485:b6dd:5066 with SMTP id 5b1f17b1804b1-486febb6014mr232959745e9.7.1774361833899; Tue, 24 Mar 2026 07:17:13 -0700 (PDT) Message-ID: Date: Tue, 24 Mar 2026 15:17:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 2/4] xen/riscv: add csr_allowed_read() helper To: Oleksii Kurochko 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: <2ea34e564533accb33ccee66b4a8c7a750733ae0.1773419622.git.oleksii.kurochko@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 M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E75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <2ea34e564533accb33ccee66b4a8c7a750733ae0.1773419622.git.oleksii.kurochko@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-purgate-ID: tlsNG-c1860d/1774361834-E8882726-26241A44/0/0 X-purgate-type: clean X-purgate-size: 3033 On 13.03.2026 17:44, Oleksii Kurochko wrote: > Accessing some CSRs may trap when the corresponding extension is not > implemented or enabled. Introduce csr_allowed_read() which attempts to > read a CSR and relies on the exception table mechanism to safely recover > if the access faults. > > This helper allows Xen to probe CSR availability without taking a fatal > trap and will be used for feature detection during early boot as we > can't always rely on what is in riscv,isa string in DTS. > > While touching the header, reorder the include directives to follow the > usual Xen style. > > Signed-off-by: Oleksii Kurochko > --- > xen/arch/riscv/include/asm/csr.h | 34 +++++++++++++++++++++++++++++++- > 1 file changed, 33 insertions(+), 1 deletion(-) > > diff --git a/xen/arch/riscv/include/asm/csr.h b/xen/arch/riscv/include/asm/csr.h > index 01876f828981..b9bee3d25d21 100644 > --- a/xen/arch/riscv/include/asm/csr.h > +++ b/xen/arch/riscv/include/asm/csr.h > @@ -6,8 +6,10 @@ > #ifndef ASM__RISCV__CSR_H > #define ASM__RISCV__CSR_H > > -#include > #include > + > +#include > +#include > #include > > #ifndef __ASSEMBLER__ > @@ -78,6 +80,36 @@ > : "memory" ); \ > }) > > +static always_inline bool csr_allowed_read(unsigned long csr, > + unsigned long *val) > +{ > + bool error = false; Wrong polarity or wrong name? You set this ... > + /* > + * Use "+" as a constraint instead of "=" to ensure the compiler passes the > + * initial value into the asm volatile block. Otherwise, if the instruction > + * (at label 1) faults, the variable 'error' may contain an undefined value > + * instead of 0. > + * If reading of CSR register was failed, we don't care about val, so "=" > + * constraint could be used in asm volatile block to not force always init. > + * val argument before being passed to csr_allowed_read() functions. > + * > + * This avoids the need for an additional instruction inside the asm block > + * to explicitly initialize 'error' to 0 before executing the potentially > + * faulting instruction. > + */ > + asm volatile ( > + "1: csrr %[val], %[csr]\n" > + " li %[err], 1\n" ... to true in the success case. Please can all of the commentary be dropped? You're re-stating what the compiler doc has, and (imo) such doesn't belong here. If you want to comment on anything, then the (again imo) less obvious need to use always_inline. > + "2:\n" > + ASM_EXTABLE(1b, 2b) > + : [val] "=&r" (*val), [err] "+&r" (error) You don't clobber [err] early, so & isn't needed here. > + : [csr] "i" (csr) > + : "memory" ); The memory clobber, if you think you really need it, wants to come with a comment. Jan