Commit 2517617e authored by Michael Neuling's avatar Michael Neuling Committed by Benjamin Herrenschmidt

powerpc: Fix context switch DSCR on POWER8

POWER8 allows the DSCR to be accessed directly from userspace via a new SPR
number 0x3 (Rather than 0x11.  DSCR SPR number 0x11 is still used on POWER8 but
like POWER7, is only accessible in HV and OS modes).  Currently, we allow this
by setting H/FSCR DSCR bit on boot.

Unfortunately this doesn't work, as the kernel needs to see the DSCR change so
that it knows to no longer restore the system wide version of DSCR on context
switch (ie. to set thread.dscr_inherit).

This clears the H/FSCR DSCR bit initially.  If a process then accesses the DSCR
(via SPR 0x3), it'll trap into the kernel where we set thread.dscr_inherit in
facility_unavailable_exception().

We also change _switch() so that we set or clear the H/FSCR DSCR bit based on
the thread.dscr_inherit.
Signed-off-by: default avatarMichael Neuling <mikey@neuling.org>
Cc: <stable@vger.kernel.org> [v3.10]
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 74e400ce
...@@ -584,9 +584,34 @@ BEGIN_FTR_SECTION ...@@ -584,9 +584,34 @@ BEGIN_FTR_SECTION
ld r7,DSCR_DEFAULT@toc(2) ld r7,DSCR_DEFAULT@toc(2)
ld r0,THREAD_DSCR(r4) ld r0,THREAD_DSCR(r4)
cmpwi r6,0 cmpwi r6,0
li r8, FSCR_DSCR
bne 1f bne 1f
ld r0,0(r7) ld r0,0(r7)
1: cmpd r0,r25 b 3f
1:
BEGIN_FTR_SECTION_NESTED(70)
mfspr r6, SPRN_FSCR
or r6, r6, r8
mtspr SPRN_FSCR, r6
BEGIN_FTR_SECTION_NESTED(69)
mfspr r6, SPRN_HFSCR
or r6, r6, r8
mtspr SPRN_HFSCR, r6
END_FTR_SECTION_NESTED(CPU_FTR_HVMODE, CPU_FTR_HVMODE, 69)
b 4f
END_FTR_SECTION_NESTED(CPU_FTR_ARCH_207S, CPU_FTR_ARCH_207S, 70)
3:
BEGIN_FTR_SECTION_NESTED(70)
mfspr r6, SPRN_FSCR
andc r6, r6, r8
mtspr SPRN_FSCR, r6
BEGIN_FTR_SECTION_NESTED(69)
mfspr r6, SPRN_HFSCR
andc r6, r6, r8
mtspr SPRN_HFSCR, r6
END_FTR_SECTION_NESTED(CPU_FTR_HVMODE, CPU_FTR_HVMODE, 69)
END_FTR_SECTION_NESTED(CPU_FTR_ARCH_207S, CPU_FTR_ARCH_207S, 70)
4: cmpd r0,r25
beq 2f beq 2f
mtspr SPRN_DSCR,r0 mtspr SPRN_DSCR,r0
2: 2:
......
...@@ -44,9 +44,7 @@ ...@@ -44,9 +44,7 @@
#include <asm/machdep.h> #include <asm/machdep.h>
#include <asm/rtas.h> #include <asm/rtas.h>
#include <asm/pmc.h> #include <asm/pmc.h>
#ifdef CONFIG_PPC32
#include <asm/reg.h> #include <asm/reg.h>
#endif
#ifdef CONFIG_PMAC_BACKLIGHT #ifdef CONFIG_PMAC_BACKLIGHT
#include <asm/backlight.h> #include <asm/backlight.h>
#endif #endif
...@@ -1296,43 +1294,54 @@ void vsx_unavailable_exception(struct pt_regs *regs) ...@@ -1296,43 +1294,54 @@ void vsx_unavailable_exception(struct pt_regs *regs)
die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
} }
#ifdef CONFIG_PPC64
void facility_unavailable_exception(struct pt_regs *regs) void facility_unavailable_exception(struct pt_regs *regs)
{ {
static char *facility_strings[] = { static char *facility_strings[] = {
"FPU", [FSCR_FP_LG] = "FPU",
"VMX/VSX", [FSCR_VECVSX_LG] = "VMX/VSX",
"DSCR", [FSCR_DSCR_LG] = "DSCR",
"PMU SPRs", [FSCR_PM_LG] = "PMU SPRs",
"BHRB", [FSCR_BHRB_LG] = "BHRB",
"TM", [FSCR_TM_LG] = "TM",
"AT", [FSCR_EBB_LG] = "EBB",
"EBB", [FSCR_TAR_LG] = "TAR",
"TAR",
}; };
char *facility, *prefix; char *facility = "unknown";
u64 value; u64 value;
u8 status;
bool hv;
if (regs->trap == 0xf60) { hv = (regs->trap == 0xf80);
value = mfspr(SPRN_FSCR); if (hv)
prefix = "";
} else {
value = mfspr(SPRN_HFSCR); value = mfspr(SPRN_HFSCR);
prefix = "Hypervisor "; else
value = mfspr(SPRN_FSCR);
status = value >> 56;
if (status == FSCR_DSCR_LG) {
/* User is acessing the DSCR. Set the inherit bit and allow
* the user to set it directly in future by setting via the
* H/FSCR DSCR bit.
*/
current->thread.dscr_inherit = 1;
if (hv)
mtspr(SPRN_HFSCR, value | HFSCR_DSCR);
else
mtspr(SPRN_FSCR, value | FSCR_DSCR);
return;
} }
value = value >> 56; if ((status < ARRAY_SIZE(facility_strings)) &&
facility_strings[status])
facility = facility_strings[status];
/* We restore the interrupt state now */ /* We restore the interrupt state now */
if (!arch_irq_disabled_regs(regs)) if (!arch_irq_disabled_regs(regs))
local_irq_enable(); local_irq_enable();
if (value < ARRAY_SIZE(facility_strings))
facility = facility_strings[value];
else
facility = "unknown";
pr_err("%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n", pr_err("%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n",
prefix, facility, regs->nip, regs->msr); hv ? "Hypervisor " : "", facility, regs->nip, regs->msr);
if (user_mode(regs)) { if (user_mode(regs)) {
_exception(SIGILL, regs, ILL_ILLOPC, regs->nip); _exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
...@@ -1341,6 +1350,7 @@ void facility_unavailable_exception(struct pt_regs *regs) ...@@ -1341,6 +1350,7 @@ void facility_unavailable_exception(struct pt_regs *regs)
die("Unexpected facility unavailable exception", regs, SIGABRT); die("Unexpected facility unavailable exception", regs, SIGABRT);
} }
#endif
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment