[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 2/4] xen/riscv: add csr_read_safe() helper
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
- Date: Wed, 8 Apr 2026 11:38:31 +0200
- Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:In-Reply-To:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID"
- Cc: Romain Caritey <Romain.Caritey@xxxxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Wed, 08 Apr 2026 09:38:50 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 4/2/26 8:30 AM, Jan Beulich wrote:
On 31.03.2026 21:04, Oleksii Kurochko wrote:
@@ -78,6 +80,38 @@
: "memory" ); \
})
+static always_inline bool csr_read_safe(unsigned long csr,
+ unsigned long *val)
+{
+#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
+ asm_inline goto (
+ "1: csrr %[val], %[csr]\n"
+ ASM_EXTABLE(1b, %l[fault])
+ : [val] "=&r" (*val)
Why the & when there's only a single insn?
Agree, the & isn't needed here.
+ : [csr] "i" (csr)
+ :
+ : fault );
+
+ return true;
+
+ fault:
+ return false;
+#else
+ bool allowed = false;
+
+ asm_inline volatile (
+ "1: csrr %[val], %[csr]\n"
+ " li %[allowed], 1\n"
+ "2:\n"
+ ASM_EXTABLE(1b, 2b)
+ : [val] "=&r" (*val), [allowed] "+r" (allowed)
+ : [csr] "i" (csr)
+ : );
Why the excess colon?
Missed to proper cleanup. It could be also dropped.
With these adjusted (again happy to do so while committing, so long
as you agree):
I would be happy with that.
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
Thanks!
~ Oleksii
|