Skip to content

Commit 77f63b4

Browse files
committed
Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
Pull powerpc fixes from Ben Herrenschmidt: "This includes small series from Michael Neuling to fix a couple of nasty remaining problems with the new Power8 support, also targeted at stable 3.10, without which some new userspace accessible registers aren't properly context switched, and in some case, can be clobbered by the user of transactional memory. Along with that, a few slightly more minor things, such as a missing Kconfig option to enable handling of denorm exceptions when not running under a hypervisor (or userspace will randomly crash when hitting denorms with the vector unit), some nasty bugs in the new pstore oops code, and other simple bug fixes worth having in now. Note: I picked up the two powerpc KVM fixes as Alex Graf asked me to handle KVM bits while he is on vacation. However I'll let him decide whether they should go to -stable or not when he is back" * 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc: powerpc/tm: Fix context switching TAR, PPR and DSCR SPRs powerpc: Save the TAR register earlier powerpc: Fix context switch DSCR on POWER8 powerpc: Rework setting up H/FSCR bit definitions powerpc: Fix hypervisor facility unavaliable vector number powerpc/kvm/book3s_pr: Return appropriate error when allocation fails powerpc/kvm: Add signed type cast for comparation powerpc/eeh: Add missing procfs entry for PowerNV powerpc/pseries: Add backward compatibilty to read old kernel oops-log powerpc/pseries: Fix buffer overflow when reading from pstore powerpc: On POWERNV enable PPC_DENORMALISATION by default
2 parents 30b229b + 28e61cc commit 77f63b4

File tree

14 files changed

+170
-99
lines changed

14 files changed

+170
-99
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ config SCHED_SMT
566566
config PPC_DENORMALISATION
567567
bool "PowerPC denormalisation exception handling"
568568
depends on PPC_BOOK3S_64
569-
default "n"
569+
default "y" if PPC_POWERNV
570570
---help---
571571
Add support for handling denormalisation of single precision
572572
values. Useful for bare metal only. If unsure say Y here.

arch/powerpc/include/asm/processor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ struct thread_struct {
247247
unsigned long tm_orig_msr; /* Thread's MSR on ctx switch */
248248
struct pt_regs ckpt_regs; /* Checkpointed registers */
249249

250+
unsigned long tm_tar;
251+
unsigned long tm_ppr;
252+
unsigned long tm_dscr;
253+
250254
/*
251255
* Transactional FP and VSX 0-31 register set.
252256
* NOTE: the sense of these is the opposite of the integer ckpt_regs!

arch/powerpc/include/asm/reg.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,28 @@
254254
#define SPRN_HRMOR 0x139 /* Real mode offset register */
255255
#define SPRN_HSRR0 0x13A /* Hypervisor Save/Restore 0 */
256256
#define SPRN_HSRR1 0x13B /* Hypervisor Save/Restore 1 */
257+
/* HFSCR and FSCR bit numbers are the same */
258+
#define FSCR_TAR_LG 8 /* Enable Target Address Register */
259+
#define FSCR_EBB_LG 7 /* Enable Event Based Branching */
260+
#define FSCR_TM_LG 5 /* Enable Transactional Memory */
261+
#define FSCR_PM_LG 4 /* Enable prob/priv access to PMU SPRs */
262+
#define FSCR_BHRB_LG 3 /* Enable Branch History Rolling Buffer*/
263+
#define FSCR_DSCR_LG 2 /* Enable Data Stream Control Register */
264+
#define FSCR_VECVSX_LG 1 /* Enable VMX/VSX */
265+
#define FSCR_FP_LG 0 /* Enable Floating Point */
257266
#define SPRN_FSCR 0x099 /* Facility Status & Control Register */
258-
#define FSCR_TAR (1 << (63-55)) /* Enable Target Address Register */
259-
#define FSCR_EBB (1 << (63-56)) /* Enable Event Based Branching */
260-
#define FSCR_DSCR (1 << (63-61)) /* Enable Data Stream Control Register */
267+
#define FSCR_TAR __MASK(FSCR_TAR_LG)
268+
#define FSCR_EBB __MASK(FSCR_EBB_LG)
269+
#define FSCR_DSCR __MASK(FSCR_DSCR_LG)
261270
#define SPRN_HFSCR 0xbe /* HV=1 Facility Status & Control Register */
262-
#define HFSCR_TAR (1 << (63-55)) /* Enable Target Address Register */
263-
#define HFSCR_EBB (1 << (63-56)) /* Enable Event Based Branching */
264-
#define HFSCR_TM (1 << (63-58)) /* Enable Transactional Memory */
265-
#define HFSCR_PM (1 << (63-60)) /* Enable prob/priv access to PMU SPRs */
266-
#define HFSCR_BHRB (1 << (63-59)) /* Enable Branch History Rolling Buffer*/
267-
#define HFSCR_DSCR (1 << (63-61)) /* Enable Data Stream Control Register */
268-
#define HFSCR_VECVSX (1 << (63-62)) /* Enable VMX/VSX */
269-
#define HFSCR_FP (1 << (63-63)) /* Enable Floating Point */
271+
#define HFSCR_TAR __MASK(FSCR_TAR_LG)
272+
#define HFSCR_EBB __MASK(FSCR_EBB_LG)
273+
#define HFSCR_TM __MASK(FSCR_TM_LG)
274+
#define HFSCR_PM __MASK(FSCR_PM_LG)
275+
#define HFSCR_BHRB __MASK(FSCR_BHRB_LG)
276+
#define HFSCR_DSCR __MASK(FSCR_DSCR_LG)
277+
#define HFSCR_VECVSX __MASK(FSCR_VECVSX_LG)
278+
#define HFSCR_FP __MASK(FSCR_FP_LG)
270279
#define SPRN_TAR 0x32f /* Target Address Register */
271280
#define SPRN_LPCR 0x13E /* LPAR Control Register */
272281
#define LPCR_VPM0 (1ul << (63-0))

arch/powerpc/include/asm/switch_to.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ extern struct task_struct *__switch_to(struct task_struct *,
1515
struct thread_struct;
1616
extern struct task_struct *_switch(struct thread_struct *prev,
1717
struct thread_struct *next);
18+
#ifdef CONFIG_PPC_BOOK3S_64
19+
static inline void save_tar(struct thread_struct *prev)
20+
{
21+
if (cpu_has_feature(CPU_FTR_ARCH_207S))
22+
prev->tar = mfspr(SPRN_TAR);
23+
}
24+
#else
25+
static inline void save_tar(struct thread_struct *prev) {}
26+
#endif
1827

1928
extern void giveup_fpu(struct task_struct *);
2029
extern void load_up_fpu(void);

arch/powerpc/kernel/asm-offsets.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ int main(void)
138138
DEFINE(THREAD_TM_TFHAR, offsetof(struct thread_struct, tm_tfhar));
139139
DEFINE(THREAD_TM_TEXASR, offsetof(struct thread_struct, tm_texasr));
140140
DEFINE(THREAD_TM_TFIAR, offsetof(struct thread_struct, tm_tfiar));
141+
DEFINE(THREAD_TM_TAR, offsetof(struct thread_struct, tm_tar));
142+
DEFINE(THREAD_TM_PPR, offsetof(struct thread_struct, tm_ppr));
143+
DEFINE(THREAD_TM_DSCR, offsetof(struct thread_struct, tm_dscr));
141144
DEFINE(PT_CKPT_REGS, offsetof(struct thread_struct, ckpt_regs));
142145
DEFINE(THREAD_TRANSACT_VR0, offsetof(struct thread_struct,
143146
transact_vr[0]));

arch/powerpc/kernel/eeh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static const struct file_operations proc_eeh_operations = {
10611061

10621062
static int __init eeh_init_proc(void)
10631063
{
1064-
if (machine_is(pseries))
1064+
if (machine_is(pseries) || machine_is(powernv))
10651065
proc_create("powerpc/eeh", 0, NULL, &proc_eeh_operations);
10661066
return 0;
10671067
}

arch/powerpc/kernel/entry_64.S

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_DSCR)
449449

450450
#ifdef CONFIG_PPC_BOOK3S_64
451451
BEGIN_FTR_SECTION
452-
/*
453-
* Back up the TAR across context switches. Note that the TAR is not
454-
* available for use in the kernel. (To provide this, the TAR should
455-
* be backed up/restored on exception entry/exit instead, and be in
456-
* pt_regs. FIXME, this should be in pt_regs anyway (for debug).)
457-
*/
458-
mfspr r0,SPRN_TAR
459-
std r0,THREAD_TAR(r3)
460-
461452
/* Event based branch registers */
462453
mfspr r0, SPRN_BESCR
463454
std r0, THREAD_BESCR(r3)
@@ -584,9 +575,34 @@ BEGIN_FTR_SECTION
584575
ld r7,DSCR_DEFAULT@toc(2)
585576
ld r0,THREAD_DSCR(r4)
586577
cmpwi r6,0
578+
li r8, FSCR_DSCR
587579
bne 1f
588580
ld r0,0(r7)
589-
1: cmpd r0,r25
581+
b 3f
582+
1:
583+
BEGIN_FTR_SECTION_NESTED(70)
584+
mfspr r6, SPRN_FSCR
585+
or r6, r6, r8
586+
mtspr SPRN_FSCR, r6
587+
BEGIN_FTR_SECTION_NESTED(69)
588+
mfspr r6, SPRN_HFSCR
589+
or r6, r6, r8
590+
mtspr SPRN_HFSCR, r6
591+
END_FTR_SECTION_NESTED(CPU_FTR_HVMODE, CPU_FTR_HVMODE, 69)
592+
b 4f
593+
END_FTR_SECTION_NESTED(CPU_FTR_ARCH_207S, CPU_FTR_ARCH_207S, 70)
594+
3:
595+
BEGIN_FTR_SECTION_NESTED(70)
596+
mfspr r6, SPRN_FSCR
597+
andc r6, r6, r8
598+
mtspr SPRN_FSCR, r6
599+
BEGIN_FTR_SECTION_NESTED(69)
600+
mfspr r6, SPRN_HFSCR
601+
andc r6, r6, r8
602+
mtspr SPRN_HFSCR, r6
603+
END_FTR_SECTION_NESTED(CPU_FTR_HVMODE, CPU_FTR_HVMODE, 69)
604+
END_FTR_SECTION_NESTED(CPU_FTR_ARCH_207S, CPU_FTR_ARCH_207S, 70)
605+
4: cmpd r0,r25
590606
beq 2f
591607
mtspr SPRN_DSCR,r0
592608
2:

arch/powerpc/kernel/exceptions-64s.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ hv_facility_unavailable_relon_trampoline:
848848
. = 0x4f80
849849
SET_SCRATCH0(r13)
850850
EXCEPTION_PROLOG_0(PACA_EXGEN)
851-
b facility_unavailable_relon_hv
851+
b hv_facility_unavailable_relon_hv
852852

853853
STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
854854
#ifdef CONFIG_PPC_DENORMALISATION
@@ -1175,6 +1175,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX)
11751175
b .ret_from_except
11761176

11771177
STD_EXCEPTION_COMMON(0xf60, facility_unavailable, .facility_unavailable_exception)
1178+
STD_EXCEPTION_COMMON(0xf80, hv_facility_unavailable, .facility_unavailable_exception)
11781179

11791180
.align 7
11801181
.globl __end_handlers
@@ -1188,7 +1189,7 @@ __end_handlers:
11881189
STD_RELON_EXCEPTION_PSERIES_OOL(0xf20, altivec_unavailable)
11891190
STD_RELON_EXCEPTION_PSERIES_OOL(0xf40, vsx_unavailable)
11901191
STD_RELON_EXCEPTION_PSERIES_OOL(0xf60, facility_unavailable)
1191-
STD_RELON_EXCEPTION_HV_OOL(0xf80, facility_unavailable)
1192+
STD_RELON_EXCEPTION_HV_OOL(0xf80, hv_facility_unavailable)
11921193

11931194
#if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
11941195
/*

arch/powerpc/kernel/process.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ struct task_struct *__switch_to(struct task_struct *prev,
600600
struct ppc64_tlb_batch *batch;
601601
#endif
602602

603+
/* Back up the TAR across context switches.
604+
* Note that the TAR is not available for use in the kernel. (To
605+
* provide this, the TAR should be backed up/restored on exception
606+
* entry/exit instead, and be in pt_regs. FIXME, this should be in
607+
* pt_regs anyway (for debug).)
608+
* Save the TAR here before we do treclaim/trecheckpoint as these
609+
* will change the TAR.
610+
*/
611+
save_tar(&prev->thread);
612+
603613
__switch_to_tm(prev);
604614

605615
#ifdef CONFIG_SMP

arch/powerpc/kernel/tm.S

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ dont_backup_fp:
233233
std r5, _CCR(r7)
234234
std r6, _XER(r7)
235235

236+
237+
/* ******************** TAR, PPR, DSCR ********** */
238+
mfspr r3, SPRN_TAR
239+
mfspr r4, SPRN_PPR
240+
mfspr r5, SPRN_DSCR
241+
242+
std r3, THREAD_TM_TAR(r12)
243+
std r4, THREAD_TM_PPR(r12)
244+
std r5, THREAD_TM_DSCR(r12)
245+
236246
/* MSR and flags: We don't change CRs, and we don't need to alter
237247
* MSR.
238248
*/
@@ -347,6 +357,16 @@ dont_restore_fp:
347357
mtmsr r6 /* FP/Vec off again! */
348358

349359
restore_gprs:
360+
361+
/* ******************** TAR, PPR, DSCR ********** */
362+
ld r4, THREAD_TM_TAR(r3)
363+
ld r5, THREAD_TM_PPR(r3)
364+
ld r6, THREAD_TM_DSCR(r3)
365+
366+
mtspr SPRN_TAR, r4
367+
mtspr SPRN_PPR, r5
368+
mtspr SPRN_DSCR, r6
369+
350370
/* ******************** CR,LR,CCR,MSR ********** */
351371
ld r3, _CTR(r7)
352372
ld r4, _LINK(r7)

arch/powerpc/kernel/traps.c

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
#include <asm/machdep.h>
4545
#include <asm/rtas.h>
4646
#include <asm/pmc.h>
47-
#ifdef CONFIG_PPC32
4847
#include <asm/reg.h>
49-
#endif
5048
#ifdef CONFIG_PMAC_BACKLIGHT
5149
#include <asm/backlight.h>
5250
#endif
@@ -1296,43 +1294,54 @@ void vsx_unavailable_exception(struct pt_regs *regs)
12961294
die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT);
12971295
}
12981296

1297+
#ifdef CONFIG_PPC64
12991298
void facility_unavailable_exception(struct pt_regs *regs)
13001299
{
13011300
static char *facility_strings[] = {
1302-
"FPU",
1303-
"VMX/VSX",
1304-
"DSCR",
1305-
"PMU SPRs",
1306-
"BHRB",
1307-
"TM",
1308-
"AT",
1309-
"EBB",
1310-
"TAR",
1301+
[FSCR_FP_LG] = "FPU",
1302+
[FSCR_VECVSX_LG] = "VMX/VSX",
1303+
[FSCR_DSCR_LG] = "DSCR",
1304+
[FSCR_PM_LG] = "PMU SPRs",
1305+
[FSCR_BHRB_LG] = "BHRB",
1306+
[FSCR_TM_LG] = "TM",
1307+
[FSCR_EBB_LG] = "EBB",
1308+
[FSCR_TAR_LG] = "TAR",
13111309
};
1312-
char *facility, *prefix;
1310+
char *facility = "unknown";
13131311
u64 value;
1312+
u8 status;
1313+
bool hv;
13141314

1315-
if (regs->trap == 0xf60) {
1316-
value = mfspr(SPRN_FSCR);
1317-
prefix = "";
1318-
} else {
1315+
hv = (regs->trap == 0xf80);
1316+
if (hv)
13191317
value = mfspr(SPRN_HFSCR);
1320-
prefix = "Hypervisor ";
1318+
else
1319+
value = mfspr(SPRN_FSCR);
1320+
1321+
status = value >> 56;
1322+
if (status == FSCR_DSCR_LG) {
1323+
/* User is acessing the DSCR. Set the inherit bit and allow
1324+
* the user to set it directly in future by setting via the
1325+
* H/FSCR DSCR bit.
1326+
*/
1327+
current->thread.dscr_inherit = 1;
1328+
if (hv)
1329+
mtspr(SPRN_HFSCR, value | HFSCR_DSCR);
1330+
else
1331+
mtspr(SPRN_FSCR, value | FSCR_DSCR);
1332+
return;
13211333
}
13221334

1323-
value = value >> 56;
1335+
if ((status < ARRAY_SIZE(facility_strings)) &&
1336+
facility_strings[status])
1337+
facility = facility_strings[status];
13241338

13251339
/* We restore the interrupt state now */
13261340
if (!arch_irq_disabled_regs(regs))
13271341
local_irq_enable();
13281342

1329-
if (value < ARRAY_SIZE(facility_strings))
1330-
facility = facility_strings[value];
1331-
else
1332-
facility = "unknown";
1333-
13341343
pr_err("%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n",
1335-
prefix, facility, regs->nip, regs->msr);
1344+
hv ? "Hypervisor " : "", facility, regs->nip, regs->msr);
13361345

13371346
if (user_mode(regs)) {
13381347
_exception(SIGILL, regs, ILL_ILLOPC, regs->nip);
@@ -1341,6 +1350,7 @@ void facility_unavailable_exception(struct pt_regs *regs)
13411350

13421351
die("Unexpected facility unavailable exception", regs, SIGABRT);
13431352
}
1353+
#endif
13441354

13451355
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
13461356

arch/powerpc/kvm/book3s_hv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu)
18091809
rma_size <<= PAGE_SHIFT;
18101810
rmls = lpcr_rmls(rma_size);
18111811
err = -EINVAL;
1812-
if (rmls < 0) {
1812+
if ((long)rmls < 0) {
18131813
pr_err("KVM: Can't use RMA of 0x%lx bytes\n", rma_size);
18141814
goto out_srcu;
18151815
}
@@ -1874,7 +1874,7 @@ int kvmppc_core_init_vm(struct kvm *kvm)
18741874
/* Allocate the guest's logical partition ID */
18751875

18761876
lpid = kvmppc_alloc_lpid();
1877-
if (lpid < 0)
1877+
if ((long)lpid < 0)
18781878
return -ENOMEM;
18791879
kvm->arch.lpid = lpid;
18801880

arch/powerpc/kvm/book3s_pr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,12 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
10471047
if (err)
10481048
goto free_shadow_vcpu;
10491049

1050+
err = -ENOMEM;
10501051
p = __get_free_page(GFP_KERNEL|__GFP_ZERO);
1051-
/* the real shared page fills the last 4k of our page */
1052-
vcpu->arch.shared = (void*)(p + PAGE_SIZE - 4096);
10531052
if (!p)
10541053
goto uninit_vcpu;
1054+
/* the real shared page fills the last 4k of our page */
1055+
vcpu->arch.shared = (void *)(p + PAGE_SIZE - 4096);
10551056

10561057
#ifdef CONFIG_PPC_BOOK3S_64
10571058
/* default to book3s_64 (970fx) */

0 commit comments

Comments
 (0)