From: Palmer Dabbelt <palmer@sifive.com>
To: linux-riscv@lists.infradead.org,
Paul Walmsley <paul.walmsley@sifive.com>,
marco@decred.org, me@carlosedp.com, joel@sing.id.au
Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt <palmer@sifive.com>
Subject: [PATCH v2] RISC-V: Break load reservations during switch_to
Date: Fri, 7 Jun 2019 15:22:22 -0700 [thread overview]
Message-ID: <20190607222222.15300-1-palmer@sifive.com> (raw)
The comment describes why in detail. This was found because QEMU never
gives up load reservations, the issue is unlikely to manifest on real
hardware.
Thanks to Carlos Eduardo for finding the bug!
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
---
Changes since v1 <20190605231735.26581-1-palmer@sifive.com>:
* REG_SC is now defined as a helper macro, for any code that wants to SC
a register-sized value.
* The explicit #ifdef to check that TASK_THREAD_RA_RA is 0 has been
removed. Instead we rely on the assembler to catch non-zero SC
offsets. I've tested this does actually work.
arch/riscv/include/asm/asm.h | 1 +
arch/riscv/kernel/entry.S | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/arch/riscv/include/asm/asm.h b/arch/riscv/include/asm/asm.h
index 5ad4cb622bed..946b671f996c 100644
--- a/arch/riscv/include/asm/asm.h
+++ b/arch/riscv/include/asm/asm.h
@@ -30,6 +30,7 @@
#define REG_L __REG_SEL(ld, lw)
#define REG_S __REG_SEL(sd, sw)
+#define REG_SC __REG_SEL(sc.w, sc.d)
#define SZREG __REG_SEL(8, 4)
#define LGREG __REG_SEL(3, 2)
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 1c1ecc238cfa..af685782af17 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -330,6 +330,17 @@ ENTRY(__switch_to)
add a3, a0, a4
add a4, a1, a4
REG_S ra, TASK_THREAD_RA_RA(a3)
+ /*
+ * The Linux ABI allows programs to depend on load reservations being
+ * broken on context switches, but the ISA doesn't require that the
+ * hardware ever breaks a load reservation. The only way to break a
+ * load reservation is with a store conditional, so we emit one here.
+ * Since nothing ever takes a load reservation on TASK_THREAD_RA_RA we
+ * know this will always fail, but just to be on the safe side this
+ * writes the same value that was unconditionally written by the
+ * previous instruction.
+ */
+ REG_SC x0, ra, TASK_THREAD_RA_RA(a3)
REG_S sp, TASK_THREAD_SP_RA(a3)
REG_S s0, TASK_THREAD_S0_RA(a3)
REG_S s1, TASK_THREAD_S1_RA(a3)
--
2.21.0
next reply other threads:[~2019-06-07 22:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-07 22:22 Palmer Dabbelt [this message]
2019-06-08 8:19 ` Christoph Hellwig
2019-06-16 17:54 ` Joel Sing
2019-06-17 3:09 ` Palmer Dabbelt
2019-06-19 7:36 ` Mark Rutland
2019-06-21 1:50 ` Palmer Dabbelt
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=20190607222222.15300-1-palmer@sifive.com \
--to=palmer@sifive.com \
--cc=joel@sing.id.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=marco@decred.org \
--cc=me@carlosedp.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
all inboxes | Powered by JetHome®