From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: "Cédric Le Goater" <clg@kaod.org>, "Nicholas Piggin" <npiggin@gmail.com>
Subject: [RFC PATCH 2/3] powerpc/64s: Emulate scv syscalls if facility unavailable and PR KVM is possible
Date: Tue, 18 Jan 2022 00:24:22 +1000 [thread overview]
Message-ID: <20220117142423.3038570-2-npiggin@gmail.com> (raw)
In-Reply-To: <20220117142423.3038570-1-npiggin@gmail.com>
The SCV facility will be disabled at runtime in the host by PR KVM by
the next change, emulate it in the facility unavailable handler.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/traps.c | 45 +++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 11741703d26e..6e4eaa6bf58d 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -58,6 +58,7 @@
#include <asm/ppc-opcode.h>
#include <asm/rio.h>
#include <asm/fadump.h>
+#include <asm/sstep.h>
#include <asm/switch_to.h>
#include <asm/tm.h>
#include <asm/debug.h>
@@ -1778,6 +1779,49 @@ DEFINE_INTERRUPT_HANDLER(facility_unavailable_exception)
return;
}
+ if (status == FSCR_SCV_LG) {
+ u32 lev;
+ ppc_inst_t instr;
+
+ /* If we didn't advertise the feature to userspace, SIGILL */
+ if (!(cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_SCV))
+ goto out_msg;
+
+ /*
+ * PR KVM disables the FSCR[SCV] facility even if the rest of
+ * the kernel and userspace thought SCV was enabled. THis
+ * causes scv instructions executed by both the host and the
+ * guest to come here, in their respective kernels.
+ *
+ * If radix is enabled then PR KVM can not be in use and can
+ * not be our hypervisor, so treat this as a normal illegal
+ * instruction. If we are hash guest or host, we might need
+ * to emulate a legitimate scv interrupt here.
+ */
+ if (radix_enabled())
+ goto out_msg;
+
+ /*
+ * User is making SCV call with SCV disabled. Emulate it.
+ */
+ if (get_user_instr(instr, (void __user *)regs->nip)) {
+ pr_err("Failed to fetch the user instruction\n");
+ return;
+ }
+
+ instword = ppc_inst_val(instr);
+ if (WARN_ON_ONCE((instword & 0xfffff01f) != 0x44000001))
+ goto out;
+
+ lev = (instword >> 5) & 0x7f;
+ if (lev == 0) {
+ if (emulate_step(regs, instr) > 0)
+ return;
+ else
+ pr_err_ratelimited("Failed to emulate SCV\n");
+ }
+ }
+
if (status == FSCR_TM_LG) {
/*
* If we're here then the hardware is TM aware because it
@@ -1799,6 +1843,7 @@ DEFINE_INTERRUPT_HANDLER(facility_unavailable_exception)
return;
}
+out_msg:
pr_err_ratelimited("%sFacility '%s' unavailable (%d), exception at 0x%lx, MSR=%lx\n",
hv ? "Hypervisor " : "", facility, status, regs->nip, regs->msr);
--
2.23.0
next prev parent reply other threads:[~2022-01-17 14:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 14:24 [RFC PATCH 1/3] powerpc/64s: Fix system call emulation Nicholas Piggin
2022-01-17 14:24 ` Nicholas Piggin [this message]
2022-01-17 14:24 ` [RFC PATCH 3/3] KVM: PPC: Book3S PR: Disable SCV when running AIL is disabled Nicholas Piggin
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=20220117142423.3038570-2-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=clg@kaod.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/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;
as well as URLs for NNTP newsgroup(s).