From: Andrew Jones <ajones@ventanamicro.com>
To: linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org
Cc: paul.walmsley@sifive.com, palmer@dabbelt.com,
aou@eecs.berkeley.edu, conor.dooley@microchip.com,
anup@brainfault.org, atishp@atishpatra.org,
christoph.muellner@vrull.eu, heiko@sntech.de,
charlie@rivosinc.com, David.Laight@ACULAB.COM
Subject: [PATCH 2/5] riscv: Prefer wrs.nto over wrs.sto
Date: Fri, 15 Mar 2024 14:40:12 +0100 [thread overview]
Message-ID: <20240315134009.580167-9-ajones@ventanamicro.com> (raw)
In-Reply-To: <20240315134009.580167-7-ajones@ventanamicro.com>
When running as a guest we'd like to trap to the host while waiting
in order to give the hypervisor a chance to schedule the lock holding
VCPU. Unlike wrs.sto, wrs.nto may be configured to raise an exception
when its duration expires, so use it instead. Protect ourselves from
unhandled exceptions with _ASM_EXTABLE in case the higher privileged
level configures wrs.nto to raise exceptions, but then doesn't handle
them.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
arch/riscv/include/asm/barrier.h | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/include/asm/barrier.h b/arch/riscv/include/asm/barrier.h
index 93b3f572d643..441b9eb4b0ef 100644
--- a/arch/riscv/include/asm/barrier.h
+++ b/arch/riscv/include/asm/barrier.h
@@ -13,6 +13,7 @@
#ifndef __ASSEMBLY__
#include <linux/compiler.h>
#include <asm/alternative-macros.h>
+#include <asm/asm-extable.h>
#include <asm/hwcap.h>
#include <asm/rwonce.h>
@@ -22,10 +23,14 @@
#define ZAWRS_WRS_NTO ".long 0x00d00073"
#define ZAWRS_WRS_STO ".long 0x01d00073"
+#define __ALT_WRS_NTO \
+ ALTERNATIVE("nop\n", ZAWRS_WRS_NTO "\n", \
+ 0, RISCV_ISA_EXT_ZAWRS, CONFIG_RISCV_ISA_ZAWRS)
#define ALT_WRS_NTO() \
- __asm__ __volatile__ (ALTERNATIVE( \
- "nop\n", ZAWRS_WRS_NTO "\n", \
- 0, RISCV_ISA_EXT_ZAWRS, CONFIG_RISCV_ISA_ZAWRS))
+ __asm__ __volatile__ ( \
+ "1: " __ALT_WRS_NTO "\n" \
+ "2:\n" \
+ _ASM_EXTABLE(1b, 2b))
#define ALT_WRS_STO() \
__asm__ __volatile__ (ALTERNATIVE( \
"nop\n", ZAWRS_WRS_STO "\n", \
@@ -130,7 +135,7 @@ do { \
VAL = __smp_load_reserved_relaxed(__PTR); \
if (cond_expr) \
break; \
- ALT_WRS_STO(); \
+ ALT_WRS_NTO(); \
} \
} \
(typeof(*ptr))VAL; \
@@ -147,7 +152,7 @@ do { \
VAL = __smp_load_reserved_acquire(__PTR); \
if (cond_expr) \
break; \
- ALT_WRS_STO(); \
+ ALT_WRS_NTO(); \
} \
} \
(typeof(*ptr))VAL; \
--
2.44.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2024-03-15 13:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 13:40 [PATCH 0/5] riscv: Apply Zawrs when available Andrew Jones
2024-03-15 13:40 ` [PATCH 1/5] riscv: Add Zawrs support for spinlocks Andrew Jones
2024-03-16 11:36 ` Andrea Parri
2024-03-16 17:17 ` Andrew Jones
2024-03-15 13:40 ` Andrew Jones [this message]
2024-03-15 13:40 ` [PATCH 3/5] riscv: hwprobe: export Zawrs ISA extension Andrew Jones
2024-03-15 13:40 ` [PATCH 4/5] KVM: riscv: Support guest wrs.nto Andrew Jones
2024-03-15 13:40 ` [PATCH 5/5] KVM: riscv: selftests: Add Zawrs extension to get-reg-list test Andrew Jones
2024-03-18 15:31 ` [PATCH 0/5] riscv: Apply Zawrs when available Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240315134009.580167-9-ajones@ventanamicro.com \
--to=ajones@ventanamicro.com \
--cc=David.Laight@ACULAB.COM \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atishp@atishpatra.org \
--cc=charlie@rivosinc.com \
--cc=christoph.muellner@vrull.eu \
--cc=conor.dooley@microchip.com \
--cc=heiko@sntech.de \
--cc=kvm-riscv@lists.infradead.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox