linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions
@ 2012-11-09  6:18 Michael Neuling
  2012-11-09  6:18 ` [PATCH 01/14] powerpc: Fix name denorm hypervisor symbol Michael Neuling
                   ` (15 more replies)
  0 siblings, 16 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:18 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

This set of patches adds support for taking exceptions with the MMU on which is
supported by POWER8.

A new set of exception vectors is added at 0xc000_0000_0000_4xxx.  When the HW
takes us here, MSR IR/DR will be set already and we no longer need a costly
RFID to turn the MMU back on again.

The original 0x0 based exception vectors remain for when the HW can't leave the
MMU on.  Examples of this are when we can't trust the current the MMU mappings,
like when we are changing from guest to hypervisor (HV 0 -> 1) or when the MMU
was off already.  In these cases the HW will take us to the original 0x0 based
exception vectors with the MMU off as before.

The core of these patches were originally written by Matt Evans.  

Ian Munsie (5):
  powerpc: Add set_mode hcall
  powerpc: Add wrappers to enable/disable relocation on exceptions
  powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate
    function
  powerpc: Enable relocation on during exceptions at boot
  powerpc: Disable relocation on exceptions when kexecing

Michael Neuling (9):
  powerpc: Add POWER8 architected mode to cputable
  powerpc: Whitespace changes in exception64s.S
  powerpc: Remove unessessary 0x3000 location enforcement
  powerpc: Make load_hander handle upto 64k offset
  powerpc: Turn syscall handler into macros
  powerpc: Add new macros needed for relocation on exceptions
  powerpc: Add relocation on exception vector handlers
  powerpc: Move initial mfspr LPCR out of __init_LPCR
  powerpc: Setup relocation on exceptions for bare metal systems

 arch/powerpc/include/asm/exception-64s.h        |   97 ++++++-
 arch/powerpc/include/asm/firmware.h             |    4 +-
 arch/powerpc/include/asm/hvcall.h               |   23 +-
 arch/powerpc/include/asm/reg.h                  |    2 +
 arch/powerpc/kernel/cpu_setup_power.S           |    8 +-
 arch/powerpc/kernel/cputable.c                  |   15 ++
 arch/powerpc/kernel/exceptions-64s.S            |  306 +++++++++++++++++++----
 arch/powerpc/kernel/head_64.S                   |    3 +-
 arch/powerpc/kernel/setup_64.c                  |    5 +
 arch/powerpc/platforms/pseries/firmware.c       |    1 +
 arch/powerpc/platforms/pseries/plpar_wrappers.h |   36 +++
 arch/powerpc/platforms/pseries/setup.c          |   71 ++++++
 drivers/infiniband/hw/ehca/hcp_if.c             |   20 --
 drivers/net/ethernet/ibm/ehea/ehea_phyp.h       |   20 --
 14 files changed, 516 insertions(+), 95 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 01/14] powerpc: Fix name denorm hypervisor symbol
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
@ 2012-11-09  6:18 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 02/14] powerpc: Whitespace changes in exception64s.S Michael Neuling
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:18 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/kernel/exceptions-64s.S |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 10b658a..5663018 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -276,7 +276,7 @@ vsx_unavailable_pSeries_1:
 	KVM_HANDLER_PR_SKIP(PACA_EXGEN, EXC_STD, 0x1300)
 
 	. = 0x1500
-	.global denorm_Hypervisor
+	.global denorm_exception_hv
 denorm_exception_hv:
 	HMT_MEDIUM
 	mtspr	SPRN_SPRG_HSCRATCH0,r13
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 02/14] powerpc: Whitespace changes in exception64s.S
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
  2012-11-09  6:18 ` [PATCH 01/14] powerpc: Fix name denorm hypervisor symbol Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 03/14] powerpc: Remove unessessary 0x3000 location enforcement Michael Neuling
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

Remove redundancy spaces and make tab usage consistent.

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/kernel/exceptions-64s.S |   30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 5663018..29cf7b1 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -613,8 +613,8 @@ machine_check_common:
 	STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
 	STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
 	STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
-        STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
-        STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
+	STD_EXCEPTION_COMMON(0xe40, emulation_assist, .program_check_exception)
+	STD_EXCEPTION_COMMON(0xe60, hmi_exception, .unknown_exception)
 	STD_EXCEPTION_COMMON_ASYNC(0xf00, performance_monitor, .performance_monitor_exception)
 	STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
 	STD_EXCEPTION_COMMON(0x1502, denorm, .unknown_exception)
@@ -714,21 +714,21 @@ data_access_common:
 	ld	r3,PACA_EXGEN+EX_DAR(r13)
 	lwz	r4,PACA_EXGEN+EX_DSISR(r13)
 	li	r5,0x300
-	b	.do_hash_page	 	/* Try to handle as hpte fault */
+	b	.do_hash_page		/* Try to handle as hpte fault */
 
 	.align  7
-        .globl  h_data_storage_common
+	.globl  h_data_storage_common
 h_data_storage_common:
-        mfspr   r10,SPRN_HDAR
-        std     r10,PACA_EXGEN+EX_DAR(r13)
-        mfspr   r10,SPRN_HDSISR
-        stw     r10,PACA_EXGEN+EX_DSISR(r13)
-        EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
-        bl      .save_nvgprs
+	mfspr   r10,SPRN_HDAR
+	std     r10,PACA_EXGEN+EX_DAR(r13)
+	mfspr   r10,SPRN_HDSISR
+	stw     r10,PACA_EXGEN+EX_DSISR(r13)
+	EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
+	bl      .save_nvgprs
 	DISABLE_INTS
-        addi    r3,r1,STACK_FRAME_OVERHEAD
-        bl      .unknown_exception
-        b       .ret_from_except
+	addi    r3,r1,STACK_FRAME_OVERHEAD
+	bl      .unknown_exception
+	b       .ret_from_except
 
 	.align	7
 	.globl instruction_access_common
@@ -741,7 +741,7 @@ instruction_access_common:
 	li	r5,0x400
 	b	.do_hash_page		/* Try to handle as hpte fault */
 
-        STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
+	STD_EXCEPTION_COMMON(0xe20, h_instr_storage, .unknown_exception)
 
 /*
  * Here is the common SLB miss user that is used when going to virtual
@@ -1164,7 +1164,7 @@ fwnmi_data_area:
 	/* pseries and powernv need to keep the whole page from
 	 * 0x7000 to 0x8000 free for use by the firmware
 	 */
-        . = 0x8000
+	. = 0x8000
 #endif /* defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) */
 
 /* Space for CPU0's segment table */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 03/14] powerpc: Remove unessessary 0x3000 location enforcement
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
  2012-11-09  6:18 ` [PATCH 01/14] powerpc: Fix name denorm hypervisor symbol Michael Neuling
  2012-11-09  6:19 ` [PATCH 02/14] powerpc: Whitespace changes in exception64s.S Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 04/14] powerpc: Make load_hander handle upto 64k offset Michael Neuling
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

This removes the large gap between 0x1800 and 0x3000.

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/kernel/exceptions-64s.S |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 29cf7b1..de02964 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -311,12 +311,14 @@ denorm_exception_hv:
 #ifdef CONFIG_CBE_RAS
 	STD_EXCEPTION_HV(0x1800, 0x1802, cbe_thermal)
 	KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1802)
+#else
+	. = 0x1800
 #endif /* CONFIG_CBE_RAS */
 
-	. = 0x3000
 
 /*** Out of line interrupts support ***/
 
+	.align	7
 	/* moved from 0x200 */
 machine_check_pSeries:
 	.globl machine_check_fwnmi
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 04/14] powerpc: Make load_hander handle upto 64k offset
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (2 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 03/14] powerpc: Remove unessessary 0x3000 location enforcement Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 05/14] powerpc: Turn syscall handler into macros Michael Neuling
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

If we change load_hander() to use an ori instead of addi, we can load handlers
upto 64k away provided we are still 64k aligned.
---
 arch/powerpc/include/asm/exception-64s.h |    3 ++-
 arch/powerpc/kernel/exceptions-64s.S     |    4 ++--
 arch/powerpc/kernel/setup_64.c           |    5 +++++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index a43c147..9258daa 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -55,7 +55,8 @@
  * word.
  */
 #define LOAD_HANDLER(reg, label)					\
-	addi	reg,reg,(label)-_stext;	/* virt addr of handler ... */
+	/* Handlers must be within 64K of kbase, which must be 64k aligned */ \
+	ori	reg,reg,(label)-_stext;	/* virt addr of handler ... */
 
 /* Exception register prefixes */
 #define EXC_HV	H
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index de02964..0969b7f 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -585,8 +585,8 @@ __end_interrupts:
  * Code from here down to __end_handlers is invoked from the
  * exception prologs above.  Because the prologs assemble the
  * addresses of these handlers using the LOAD_HANDLER macro,
- * which uses an addi instruction, these handlers must be in
- * the first 32k of the kernel image.
+ * which uses an ori instruction, these handlers must be in
+ * the first 64k of the kernel image.
  */
 
 /*** Common interrupt handlers ***/
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index efb6a41..6da881b 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -601,6 +601,11 @@ void __init setup_arch(char **cmdline_p)
 
 	kvm_linear_init();
 
+	/* Interrupt code needs to be 64K-aligned */
+	if ((unsigned long)_stext & 0xffff)
+		panic("Kernelbase not 64K-aligned (0x%lx)!\n",
+		      (unsigned long)_stext);
+
 	ppc64_boot_msg(0x15, "Setup Done");
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 05/14] powerpc: Turn syscall handler into macros
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (3 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 04/14] powerpc: Make load_hander handle upto 64k offset Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 06/14] powerpc: Add new macros needed for relocation on exceptions Michael Neuling
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

This turns the syscall handler into macros as we are going to want to reuse
them again later.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/kernel/exceptions-64s.S |   63 +++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 0969b7f..85b3c7e 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -25,6 +25,43 @@
  * 0x7000 - 0x7fff : FWNMI data area
  * 0x8000 -        : Early init and support code
  */
+	/* Syscall routine is used twice, in reloc-off and reloc-on paths */
+#define SYSCALL_PSERIES_1 					\
+BEGIN_FTR_SECTION						\
+	cmpdi	r0,0x1ebe ; 					\
+	beq-	1f ;						\
+END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)				\
+	mr	r9,r13 ;					\
+	GET_PACA(r13) ;						\
+	mfspr	r11,SPRN_SRR0 ;					\
+0:
+
+#define SYSCALL_PSERIES_2_RFID 					\
+	mfspr	r12,SPRN_SRR1 ;					\
+	ld	r10,PACAKBASE(r13) ; 				\
+	LOAD_HANDLER(r10, system_call_entry) ; 			\
+	mtspr	SPRN_SRR0,r10 ; 				\
+	ld	r10,PACAKMSR(r13) ;				\
+	mtspr	SPRN_SRR1,r10 ; 				\
+	rfid ; 							\
+	b	. ;	/* prevent speculative execution */
+
+#define SYSCALL_PSERIES_3					\
+	/* Fast LE/BE switch system call */			\
+1:	mfspr	r12,SPRN_SRR1 ;					\
+	xori	r12,r12,MSR_LE ;				\
+	mtspr	SPRN_SRR1,r12 ;					\
+	rfid ;		/* return to userspace */		\
+	b	. ;						\
+2:	mfspr	r12,SPRN_SRR1 ;					\
+	andi.	r12,r12,MSR_PR ;				\
+	bne	0b ;						\
+	mtspr	SPRN_SRR0,r3 ;					\
+	mtspr	SPRN_SRR1,r4 ;					\
+	mtspr	SPRN_SDR1,r5 ;					\
+	rfid ;							\
+	b	. ;	/* prevent speculative execution */
+
 
 /*
  * This is the start of the interrupt handlers for pSeries
@@ -207,31 +244,11 @@ system_call_pSeries:
 	KVMTEST(0xc00)
 	GET_SCRATCH0(r13)
 #endif
-BEGIN_FTR_SECTION
-	cmpdi	r0,0x1ebe
-	beq-	1f
-END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
-	mr	r9,r13
-	GET_PACA(r13)
-	mfspr	r11,SPRN_SRR0
-	mfspr	r12,SPRN_SRR1
-	ld	r10,PACAKBASE(r13)
-	LOAD_HANDLER(r10, system_call_entry)
-	mtspr	SPRN_SRR0,r10
-	ld	r10,PACAKMSR(r13)
-	mtspr	SPRN_SRR1,r10
-	rfid
-	b	.	/* prevent speculative execution */
-
+	SYSCALL_PSERIES_1
+	SYSCALL_PSERIES_2_RFID
+	SYSCALL_PSERIES_3
 	KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
 
-/* Fast LE/BE switch system call */
-1:	mfspr	r12,SPRN_SRR1
-	xori	r12,r12,MSR_LE
-	mtspr	SPRN_SRR1,r12
-	rfid		/* return to userspace */
-	b	.
-
 	STD_EXCEPTION_PSERIES(0xd00, 0xd00, single_step)
 	KVM_HANDLER_PR(PACA_EXGEN, EXC_STD, 0xd00)
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 06/14] powerpc: Add new macros needed for relocation on exceptions
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (4 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 05/14] powerpc: Turn syscall handler into macros Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 07/14] powerpc: Add relocation on exception vector handlers Michael Neuling
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

POWER8/v2.07 allows exceptions to be taken with the MMU still on.

A new set of exception vectors is added at 0xc000_0000_0000_4xxx.  When the HW
takes us here, MSR IR/DR will be set already and we no longer need a costly
RFID to turn the MMU back on again.

The original 0x0 based exception vectors remain for when the HW can't leave the
MMU on.  Examples of this are when we can't trust the current the MMU mappings,
like when we are changing from guest to hypervisor (HV 0 -> 1) or when the MMU
was off already.  In these cases the HW will take us to the original 0x0 based
exception vectors with the MMU off as before.

The below macros are copies of the macros used at the 0x0 offset but modified
to handle the MMU being on.  In these macros we use the link register to jump
to the secondary handlers rather than using RFID (RFID was also use to turn on
the MMU).

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/exception-64s.h |   90 ++++++++++++++++++++++++++++++
 arch/powerpc/kernel/exceptions-64s.S     |   25 +++++++++
 2 files changed, 115 insertions(+)

diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 9258daa..10787d3 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -48,6 +48,35 @@
 #define EX_LR		72
 #define EX_CFAR		80
 
+#ifdef CONFIG_RELOCATABLE
+#define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)			\
+	ld	r12,PACAKBASE(r13);	/* get high part of &label */	\
+	mfspr	r11,SPRN_##h##SRR0;	/* save SRR0 */			\
+	LOAD_HANDLER(r12,label);					\
+	mtlr	r12;							\
+	mfspr	r12,SPRN_##h##SRR1;	/* and SRR1 */			\
+	li	r10,MSR_RI;						\
+	mtmsrd 	r10,1;			/* Set RI (EE=0) */		\
+	blr;
+#else
+/* If not relocatable, we can jump directly -- and save messing with LR */
+#define EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)			\
+	mfspr	r11,SPRN_##h##SRR0;	/* save SRR0 */			\
+	mfspr	r12,SPRN_##h##SRR1;	/* and SRR1 */			\
+	li	r10,MSR_RI;						\
+	mtmsrd 	r10,1;			/* Set RI (EE=0) */		\
+	b	label;
+#endif
+
+/*
+ * As EXCEPTION_PROLOG_PSERIES(), except we've already got relocation on
+ * so no need to rfid.  Save lr in case we're CONFIG_RELOCATABLE, in which
+ * case EXCEPTION_RELON_PROLOG_PSERIES_1 will be using lr.
+ */
+#define EXCEPTION_RELON_PROLOG_PSERIES(area, label, h, extra, vec)	\
+	EXCEPTION_PROLOG_1(area, extra, vec);				\
+	EXCEPTION_RELON_PROLOG_PSERIES_1(label, h)
+
 /*
  * We're short on space and time in the exception prolog, so we can't
  * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
@@ -62,6 +91,22 @@
 #define EXC_HV	H
 #define EXC_STD
 
+#if defined(CONFIG_RELOCATABLE)
+/*
+ * If we support interrupts with relocation on AND we're a relocatable
+ * kernel, we need to use LR to get to the 2nd level handler.  So, save/restore
+ * it when required.
+ */
+#define SAVE_LR(reg, area)	mflr	reg ; 	std	reg,area+EX_LR(r13)
+#define GET_LR(reg, area) 			ld	reg,area+EX_LR(r13)
+#define RESTORE_LR(reg, area)	ld	reg,area+EX_LR(r13) ; mtlr reg
+#else
+/* ...else LR is unused and in register. */
+#define SAVE_LR(reg, area)
+#define GET_LR(reg, area) 	mflr	reg
+#define RESTORE_LR(reg, area)
+#endif
+
 #define __EXCEPTION_PROLOG_1(area, extra, vec)				\
 	GET_PACA(r13);							\
 	std	r9,area+EX_R9(r13);	/* save r9 - r12 */		\
@@ -233,6 +278,26 @@ label##_hv:						\
 	EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common,	\
 				 EXC_HV, KVMTEST, vec)
 
+#define STD_RELON_EXCEPTION_PSERIES(loc, vec, label)	\
+	. = loc;					\
+	.globl label##_relon_pSeries;			\
+label##_relon_pSeries:					\
+	HMT_MEDIUM;					\
+	/* No guest interrupts come through here */	\
+	SET_SCRATCH0(r13);		/* save r13 */	\
+	EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
+				       EXC_STD, KVMTEST_PR, vec)
+
+#define STD_RELON_EXCEPTION_HV(loc, vec, label)		\
+	. = loc;					\
+	.globl label##_relon_hv;			\
+label##_relon_hv:					\
+	HMT_MEDIUM;					\
+	/* No guest interrupts come through here */	\
+	SET_SCRATCH0(r13);	/* save r13 */		\
+	EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label##_common, \
+				       EXC_HV, KVMTEST, vec)
+
 /* This associate vector numbers with bits in paca->irq_happened */
 #define SOFTEN_VALUE_0x500	PACA_IRQ_EE
 #define SOFTEN_VALUE_0x502	PACA_IRQ_EE
@@ -258,6 +323,9 @@ label##_hv:						\
 	KVMTEST(vec);							\
 	_SOFTEN_TEST(EXC_STD, vec)
 
+#define SOFTEN_NOTEST_PR(vec)		_SOFTEN_TEST(EXC_STD, vec)
+#define SOFTEN_NOTEST_HV(vec)		_SOFTEN_TEST(EXC_HV, vec)
+
 #define __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)		\
 	HMT_MEDIUM;							\
 	SET_SCRATCH0(r13);    /* save r13 */				\
@@ -280,6 +348,28 @@ label##_hv:								\
 	_MASKABLE_EXCEPTION_PSERIES(vec, label,				\
 				    EXC_HV, SOFTEN_TEST_HV)
 
+#define __MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)	\
+	HMT_MEDIUM;							\
+	SET_SCRATCH0(r13);    /* save r13 */				\
+	__EXCEPTION_PROLOG_1(PACA_EXGEN, extra, vec);		\
+	EXCEPTION_RELON_PROLOG_PSERIES_1(label##_common, h);
+#define _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)	\
+	__MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, h, extra)
+
+#define MASKABLE_RELON_EXCEPTION_PSERIES(loc, vec, label)		\
+	. = loc;							\
+	.globl label##_relon_pSeries;					\
+label##_relon_pSeries:							\
+	_MASKABLE_RELON_EXCEPTION_PSERIES(vec, label,			\
+					  EXC_STD, SOFTEN_NOTEST_PR)
+
+#define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label)			\
+	. = loc;							\
+	.globl label##_relon_hv;					\
+label##_relon_hv:							\
+	_MASKABLE_RELON_EXCEPTION_PSERIES(vec, label,			\
+					  EXC_HV, SOFTEN_NOTEST_HV)
+
 /*
  * Our exception common code can be passed various "additions"
  * to specify the behaviour of interrupts, whether to kick the
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 85b3c7e..4dc1a04 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -62,6 +62,31 @@ END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)				\
 	rfid ;							\
 	b	. ;	/* prevent speculative execution */
 
+#if defined(CONFIG_RELOCATABLE)
+	/*
+	 * We can't branch directly; in the direct case we use LR
+	 * and system_call_entry restores LR.  (We thus need to move
+	 * LR to r10 in the RFID case too.)
+	 */
+#define SYSCALL_PSERIES_2_DIRECT				\
+	mflr	r10 ;						\
+	ld	r12,PACAKBASE(r13) ; 				\
+	LOAD_HANDLER(r12, system_call_entry_direct) ;		\
+	mtlr	r12 ;						\
+	mfspr	r12,SPRN_SRR1 ;					\
+	/* Re-use of r13... No spare regs to do this */	\
+	li	r13,MSR_RI ;					\
+	mtmsrd 	r13,1 ;						\
+	GET_PACA(r13) ;	/* get r13 back */			\
+	blr ;
+#else
+	/* We can branch directly */
+#define SYSCALL_PSERIES_2_DIRECT				\
+	mfspr	r12,SPRN_SRR1 ;					\
+	li	r10,MSR_RI ;					\
+	mtmsrd 	r10,1 ;			/* Set RI (EE=0) */	\
+	b	system_call_entry_direct ;
+#endif
 
 /*
  * This is the start of the interrupt handlers for pSeries
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 07/14] powerpc: Add relocation on exception vector handlers
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (5 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 06/14] powerpc: Add new macros needed for relocation on exceptions Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 08/14] powerpc: Move initial mfspr LPCR out of __init_LPCR Michael Neuling
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

POWER8/v2.07 allows exceptions to be taken with the MMU still on.

A new set of exception vectors is added at 0xc000_0000_0000_4xxx.  When the HW
takes us here, MSR IR/DR will be set already and we no longer need a costly
RFID to turn the MMU back on again.

The original 0x0 based exception vectors remain for when the HW can't leave the
MMU on.  Examples of this are when we can't trust the current the MMU mappings,
like when we are changing from guest to hypervisor (HV 0 -> 1) or when the MMU
was off already.  In these cases the HW will take us to the original 0x0 based
exception vectors with the MMU off as before.

This uses the new macros added previously too implement these new execption
vectors at 0xc000_0000_0000_4xxx.  We exit these exception vectors using
mflr/blr (rather than mtspr SSR0/RFID), since we don't need the costly MMU
switch anymore.

This moves the __end_interrupts marker down past these new 0x4000 vectors since
they will need to be copied down to 0x0 when the kernel is not at 0x0.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/exception-64s.h |    4 +-
 arch/powerpc/kernel/exceptions-64s.S     |  180 ++++++++++++++++++++++++++++--
 arch/powerpc/kernel/head_64.S            |    3 +-
 3 files changed, 177 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 10787d3..ad708dd 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -115,6 +115,7 @@
 	mfspr	r10,SPRN_CFAR;						\
 	std	r10,area+EX_CFAR(r13);					\
 	END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);		\
+	SAVE_LR(r10, area);						\
 	mfcr	r9;							\
 	extra(vec);							\
 	std	r11,area+EX_R11(r13);					\
@@ -215,6 +216,7 @@ do_kvm_##n:								\
 	sth	r1,PACA_TRAP_SAVE(r13);					   \
 	std	r3,area+EX_R3(r13);					   \
 	addi	r3,r13,area;		/* r3 -> where regs are saved*/	   \
+	RESTORE_LR(r1, area);						   \
 	b	bad_stack;						   \
 3:	std	r9,_CCR(r1);		/* save CR in stackframe	*/ \
 	std	r11,_NIP(r1);		/* save SRR0 in stackframe	*/ \
@@ -240,8 +242,8 @@ do_kvm_##n:								\
 	ld	r10,area+EX_CFAR(r13);					   \
 	std	r10,ORIG_GPR3(r1);					   \
 	END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66);		   \
+	GET_LR(r9,area);		/* Get LR, later save to stack	*/ \
 	ld	r2,PACATOC(r13);	/* get kernel TOC into r2	*/ \
-	mflr	r9;			/* save LR in stackframe	*/ \
 	std	r9,_LINK(r1);						   \
 	mfctr	r10;			/* save CTR in stackframe	*/ \
 	std	r10,_CTR(r1);						   \
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 4dc1a04..fb95747 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -19,11 +19,13 @@
 /*
  * We layout physical memory as follows:
  * 0x0000 - 0x00ff : Secondary processor spin code
- * 0x0100 - 0x2fff : pSeries Interrupt prologs
- * 0x3000 - 0x5fff : interrupt support common interrupt prologs
- * 0x6000 - 0x6fff : Initial (CPU0) segment table
+ * 0x0100 - 0x17ff : pSeries Interrupt prologs
+ * 0x1800 - 0x4000 : interrupt support common interrupt prologs
+ * 0x4000 - 0x5fff : pSeries interrupts with IR=1,DR=1
+ * 0x6000 - 0x6fff : more interrupt support including for IR=1,DR=1
  * 0x7000 - 0x7fff : FWNMI data area
- * 0x8000 -        : Early init and support code
+ * 0x8000 - 0x8fff : Initial (CPU0) segment table
+ * 0x9000 -        : Early init and support code
  */
 	/* Syscall routine is used twice, in reloc-off and reloc-on paths */
 #define SYSCALL_PSERIES_1 					\
@@ -619,10 +621,6 @@ slb_miss_user_pseries:
 	b	.				/* prevent spec. execution */
 #endif /* __DISABLED__ */
 
-	.align	7
-	.globl	__end_interrupts
-__end_interrupts:
-
 /*
  * Code from here down to __end_handlers is invoked from the
  * exception prologs above.  Because the prologs assemble the
@@ -673,7 +671,158 @@ machine_check_common:
 	STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
 #endif /* CONFIG_CBE_RAS */
 
+	/*
+	 * Relocation-on interrupts: A subset of the interrupts can be delivered
+	 * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
+	 * it.  Addresses are the same as the original interrupt addresses, but
+	 * offset by 0xc000000000004000.
+	 * It's impossible to receive interrupts below 0x300 via this mechanism.
+	 * KVM: None of these traps are from the guest ; anything that escalated
+	 * to HV=1 from HV=0 is delivered via real mode handlers.
+	 */
+
+	/*
+	 * This uses the standard macro, since the original 0x300 vector
+	 * only has extra guff for STAB-based processors -- which never
+	 * come here.
+	 */
+	STD_RELON_EXCEPTION_PSERIES(0x4300, 0x300, data_access)
+	. = 0x4380
+	.globl data_access_slb_relon_pSeries
+data_access_slb_relon_pSeries:
+	HMT_MEDIUM
+	SET_SCRATCH0(r13)
+	EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
+	std	r3,PACA_EXSLB+EX_R3(r13)
+	mfspr	r3,SPRN_DAR
+	mfspr	r12,SPRN_SRR1
+#ifndef CONFIG_RELOCATABLE
+	b	.slb_miss_realmode
+#else
+	/*
+	 * We can't just use a direct branch to .slb_miss_realmode
+	 * because the distance from here to there depends on where
+	 * the kernel ends up being put.
+	 */
+	mfctr	r11
+	ld	r10,PACAKBASE(r13)
+	LOAD_HANDLER(r10, .slb_miss_realmode)
+	mtctr	r10
+	bctr
+#endif
+
+	STD_RELON_EXCEPTION_PSERIES(0x4400, 0x400, instruction_access)
+	. = 0x4480
+	.globl instruction_access_slb_relon_pSeries
+instruction_access_slb_relon_pSeries:
+	HMT_MEDIUM
+	SET_SCRATCH0(r13)
+	EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
+	std	r3,PACA_EXSLB+EX_R3(r13)
+	mfspr	r3,SPRN_SRR0		/* SRR0 is faulting address */
+	mfspr	r12,SPRN_SRR1
+#ifndef CONFIG_RELOCATABLE
+	b	.slb_miss_realmode
+#else
+	mfctr	r11
+	ld	r10,PACAKBASE(r13)
+	LOAD_HANDLER(r10, .slb_miss_realmode)
+	mtctr	r10
+	bctr
+#endif
+
+	. = 0x4500
+	.globl hardware_interrupt_relon_pSeries;
+	.globl hardware_interrupt_relon_hv;
+hardware_interrupt_relon_pSeries:
+hardware_interrupt_relon_hv:
+	BEGIN_FTR_SECTION
+		_MASKABLE_RELON_EXCEPTION_PSERIES(0x502, hardware_interrupt, EXC_HV, SOFTEN_TEST_HV)
+	FTR_SECTION_ELSE
+		_MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt, EXC_STD, SOFTEN_TEST_PR)
+	ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_206)
+	STD_RELON_EXCEPTION_PSERIES(0x4600, 0x600, alignment)
+	STD_RELON_EXCEPTION_PSERIES(0x4700, 0x700, program_check)
+	STD_RELON_EXCEPTION_PSERIES(0x4800, 0x800, fp_unavailable)
+	MASKABLE_RELON_EXCEPTION_PSERIES(0x4900, 0x900, decrementer)
+	STD_RELON_EXCEPTION_PSERIES(0x4980, 0x980, hdecrementer)
+	STD_RELON_EXCEPTION_PSERIES(0x4b00, 0xb00, trap_0b)
+
+	. = 0x4c00
+	.globl system_call_relon_pSeries
+system_call_relon_pSeries:
+	HMT_MEDIUM
+	SYSCALL_PSERIES_1
+	SYSCALL_PSERIES_2_DIRECT
+	SYSCALL_PSERIES_3
+
+	STD_RELON_EXCEPTION_PSERIES(0x4d00, 0xd00, single_step)
+
+	. = 0x4e00
+	b	h_data_storage_relon_hv
+
+	. = 0x4e20
+	b	h_instr_storage_relon_hv
+
+	. = 0x4e40
+	b	emulation_assist_relon_hv
+
+	. = 0x4e50
+	b	hmi_exception_relon_hv
+
+	. = 0x4e60
+	b	hmi_exception_relon_hv
+
+	/* For when we support the doorbell interrupt:
+	STD_RELON_EXCEPTION_HYPERVISOR(0x4e80, 0xe80, doorbell_hyper)
+	*/
+
+performance_monitor_relon_pSeries_1:
+	. = 0x4f00
+	b	performance_monitor_relon_pSeries
+
+altivec_unavailable_relon_pSeries_1:
+	. = 0x4f20
+	b	altivec_unavailable_relon_pSeries
+
+vsx_unavailable_relon_pSeries_1:
+	. = 0x4f40
+	b	vsx_unavailable_relon_pSeries
+
+#ifdef CONFIG_CBE_RAS
+	STD_RELON_EXCEPTION_HV(0x5200, 0x1202, cbe_system_error)
+#endif /* CONFIG_CBE_RAS */
+	STD_RELON_EXCEPTION_PSERIES(0x5300, 0x1300, instruction_breakpoint)
+#ifdef CONFIG_PPC_DENORMALISATION
+	. = 0x5500
+	b	denorm_exception_hv
+#endif
+#ifdef CONFIG_CBE_RAS
+	STD_RELON_EXCEPTION_HV(0x5600, 0x1602, cbe_maintenance)
+#else
+#ifdef CONFIG_HVC_SCOM
+	STD_RELON_EXCEPTION_HV(0x5600, 0x1600, maintence_interrupt)
+	KVM_HANDLER_SKIP(PACA_EXGEN, EXC_HV, 0x1600)
+#endif /* CONFIG_HVC_SCOM */
+#endif /* CONFIG_CBE_RAS */
+	STD_RELON_EXCEPTION_PSERIES(0x5700, 0x1700, altivec_assist)
+#ifdef CONFIG_CBE_RAS
+	STD_RELON_EXCEPTION_HV(0x5800, 0x1802, cbe_thermal)
+#endif /* CONFIG_CBE_RAS */
+
+	/* Other future vectors */
+	.align	7
+	.globl	__end_interrupts
+__end_interrupts:
+
 	.align	7
+system_call_entry_direct:
+#if defined(CONFIG_RELOCATABLE)
+	/* The first level prologue may have used LR to get here, saving
+	 * orig in r10.  To save hacking/ifdeffing common code, restore here.
+	 */
+	mtlr	r10
+#endif
 system_call_entry:
 	b	system_call_common
 
@@ -1196,6 +1345,21 @@ _GLOBAL(do_stab_bolted)
 	rfid
 	b	.	/* prevent speculative execution */
 
+
+	/* Equivalents to the above handlers for relocation-on interrupt vectors */
+	STD_RELON_EXCEPTION_HV(., 0xe00, h_data_storage)
+	KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe00)
+	STD_RELON_EXCEPTION_HV(., 0xe20, h_instr_storage)
+	KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe20)
+	STD_RELON_EXCEPTION_HV(., 0xe40, emulation_assist)
+	KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe40)
+	STD_RELON_EXCEPTION_HV(., 0xe60, hmi_exception)
+	KVM_HANDLER(PACA_EXGEN, EXC_HV, 0xe60)
+
+	STD_RELON_EXCEPTION_PSERIES(., 0xf00, performance_monitor)
+	STD_RELON_EXCEPTION_PSERIES(., 0xf20, altivec_unavailable)
+	STD_RELON_EXCEPTION_PSERIES(., 0xf40, vsx_unavailable)
+
 #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
 /*
  * Data area reserved for FWNMI option.
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index 58bddee..d5a4efe 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -432,7 +432,8 @@ _STATIC(__after_prom_start)
 	cmplwi	cr0,r7,1
 	bne	3f
 
-	li	r5,__end_interrupts - _stext	/* just copy interrupts */
+	/* just copy interrupts */
+	LOAD_REG_IMMEDIATE(r5, __end_interrupts - _stext)
 	b	5f
 3:
 #endif
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 08/14] powerpc: Move initial mfspr LPCR out of __init_LPCR
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (6 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 07/14] powerpc: Add relocation on exception vector handlers Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems Michael Neuling
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

We want to change what's initially set in the LPCR, so start by taking the move
from LPCR out of the function and into the caller.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/kernel/cpu_setup_power.S |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/cpu_setup_power.S b/arch/powerpc/kernel/cpu_setup_power.S
index a92101d..52dd033 100644
--- a/arch/powerpc/kernel/cpu_setup_power.S
+++ b/arch/powerpc/kernel/cpu_setup_power.S
@@ -27,6 +27,7 @@ _GLOBAL(__setup_cpu_power7)
 	beqlr
 	li	r0,0
 	mtspr	SPRN_LPID,r0
+	mfspr	r3,SPRN_LPCR
 	bl	__init_LPCR
 	bl	__init_TLB
 	mtlr	r11
@@ -39,6 +40,7 @@ _GLOBAL(__restore_cpu_power7)
 	beqlr
 	li	r0,0
 	mtspr	SPRN_LPID,r0
+	mfspr	r3,SPRN_LPCR
 	bl	__init_LPCR
 	bl	__init_TLB
 	mtlr	r11
@@ -51,6 +53,7 @@ _GLOBAL(__setup_cpu_power8)
 	beqlr
 	li	r0,0
 	mtspr	SPRN_LPID,r0
+	mfspr	r3,SPRN_LPCR
 	bl	__init_LPCR
 	bl	__init_TLB
 	mtlr	r11
@@ -63,6 +66,7 @@ _GLOBAL(__restore_cpu_power8)
 	beqlr
 	li	r0,0
 	mtspr	SPRN_LPID,r0
+	mfspr   r3,SPRN_LPCR
 	bl	__init_LPCR
 	bl	__init_TLB
 	mtlr	r11
@@ -81,6 +85,7 @@ __init_hvmode_206:
 
 __init_LPCR:
 	/* Setup a sane LPCR:
+	 *   Called with initial LPCR in R3
 	 *
 	 *   LPES = 0b01 (HSRR0/1 used for 0x500)
 	 *   PECE = 0b111
@@ -91,7 +96,6 @@ __init_LPCR:
 	 *
 	 * Other bits untouched for now
 	 */
-	mfspr	r3,SPRN_LPCR
 	li	r5,1
 	rldimi	r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
 	ori	r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (7 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 08/14] powerpc: Move initial mfspr LPCR out of __init_LPCR Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-12  1:32   ` Segher Boessenkool
  2012-11-09  6:19 ` [PATCH 10/14] powerpc: Add set_mode hcall Michael Neuling
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

This turns on MMU on execptions via AIL field in the LPCR.

Signed-off-by: Matt Evans <matt@ozlabs.org>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/reg.h        |    2 ++
 arch/powerpc/kernel/cpu_setup_power.S |    2 ++
 2 files changed, 4 insertions(+)

diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
index 7b44a6e..886ab8e 100644
--- a/arch/powerpc/include/asm/reg.h
+++ b/arch/powerpc/include/asm/reg.h
@@ -249,6 +249,8 @@
 #define   LPCR_RMLS    0x1C000000      /* impl dependent rmo limit sel */
 #define	  LPCR_RMLS_SH	(63-37)
 #define   LPCR_ILE     0x02000000      /* !HV irqs set MSR:LE */
+#define   LPCR_AIL_0	0x00000000	/* MMU off IRQ location 0x0 */
+#define   LPCR_AIL_3	0x01800000	/* MMU on IRQ location 0xc00...4xxx */
 #define   LPCR_PECE	0x00007000	/* powersave exit cause enable */
 #define     LPCR_PECE0	0x00004000	/* ext. exceptions can cause exit */
 #define     LPCR_PECE1	0x00002000	/* decrementer can cause exit */
diff --git a/arch/powerpc/kernel/cpu_setup_power.S b/arch/powerpc/kernel/cpu_setup_power.S
index 52dd033..57cf140 100644
--- a/arch/powerpc/kernel/cpu_setup_power.S
+++ b/arch/powerpc/kernel/cpu_setup_power.S
@@ -54,6 +54,7 @@ _GLOBAL(__setup_cpu_power8)
 	li	r0,0
 	mtspr	SPRN_LPID,r0
 	mfspr	r3,SPRN_LPCR
+	oris	r3, r3, LPCR_AIL_3@h
 	bl	__init_LPCR
 	bl	__init_TLB
 	mtlr	r11
@@ -67,6 +68,7 @@ _GLOBAL(__restore_cpu_power8)
 	li	r0,0
 	mtspr	SPRN_LPID,r0
 	mfspr   r3,SPRN_LPCR
+	oris	r3, r3, LPCR_AIL_3@h
 	bl	__init_LPCR
 	bl	__init_TLB
 	mtlr	r11
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 10/14] powerpc: Add set_mode hcall
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (8 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 10/12] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

From: Ian Munsie <imunsie@au1.ibm.com>

This new hcall in POWER8 is used to set various resource mode registers.
eg. it can set address translation mode on interrupt (note: partition wide
scope)

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/firmware.h             |    4 +++-
 arch/powerpc/include/asm/hvcall.h               |    3 ++-
 arch/powerpc/platforms/pseries/firmware.c       |    1 +
 arch/powerpc/platforms/pseries/plpar_wrappers.h |    6 ++++++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/firmware.h b/arch/powerpc/include/asm/firmware.h
index ad0b751..973cc3b 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -49,6 +49,7 @@
 #define FW_FEATURE_XCMO		ASM_CONST(0x0000000008000000)
 #define FW_FEATURE_OPAL		ASM_CONST(0x0000000010000000)
 #define FW_FEATURE_OPALv2	ASM_CONST(0x0000000020000000)
+#define FW_FEATURE_SET_MODE	ASM_CONST(0x0000000040000000)
 
 #ifndef __ASSEMBLY__
 
@@ -62,7 +63,8 @@ enum {
 		FW_FEATURE_VIO | FW_FEATURE_RDMA | FW_FEATURE_LLAN |
 		FW_FEATURE_BULK_REMOVE | FW_FEATURE_XDABR |
 		FW_FEATURE_MULTITCE | FW_FEATURE_SPLPAR | FW_FEATURE_LPAR |
-		FW_FEATURE_CMO | FW_FEATURE_VPHN | FW_FEATURE_XCMO,
+		FW_FEATURE_CMO | FW_FEATURE_VPHN | FW_FEATURE_XCMO |
+		FW_FEATURE_SET_MODE,
 	FW_FEATURE_PSERIES_ALWAYS = 0,
 	FW_FEATURE_POWERNV_POSSIBLE = FW_FEATURE_OPAL | FW_FEATURE_OPALv2,
 	FW_FEATURE_POWERNV_ALWAYS = 0,
diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
index 7a86706..a3d26d8 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -267,7 +267,8 @@
 #define H_RANDOM		0x300
 #define H_COP			0x304
 #define H_GET_MPP_X		0x314
-#define MAX_HCALL_OPCODE	H_GET_MPP_X
+#define H_SET_MODE		0x31C
+#define MAX_HCALL_OPCODE	H_SET_MODE
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/powerpc/platforms/pseries/firmware.c b/arch/powerpc/platforms/pseries/firmware.c
index 0b0eff0..7b56118 100644
--- a/arch/powerpc/platforms/pseries/firmware.c
+++ b/arch/powerpc/platforms/pseries/firmware.c
@@ -56,6 +56,7 @@ firmware_features_table[FIRMWARE_MAX_FEATURES] = {
 	{FW_FEATURE_MULTITCE,		"hcall-multi-tce"},
 	{FW_FEATURE_SPLPAR,		"hcall-splpar"},
 	{FW_FEATURE_VPHN,		"hcall-vphn"},
+	{FW_FEATURE_SET_MODE,		"hcall-set-mode"},
 };
 
 /* Build up the firmware features bitmask using the contents of
diff --git a/arch/powerpc/platforms/pseries/plpar_wrappers.h b/arch/powerpc/platforms/pseries/plpar_wrappers.h
index 13e8cc4..44ad214 100644
--- a/arch/powerpc/platforms/pseries/plpar_wrappers.h
+++ b/arch/powerpc/platforms/pseries/plpar_wrappers.h
@@ -273,4 +273,10 @@ static inline long plpar_put_term_char(unsigned long termno, unsigned long len,
 			lbuf[1]);
 }
 
+/* Set various resource mode parameters */
+static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
+		unsigned long value1, unsigned long value2)
+{
+	return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
+}
 #endif /* _PSERIES_PLPAR_WRAPPERS_H */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 10/12] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (9 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 10/14] powerpc: Add set_mode hcall Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 11/14] powerpc: Add wrappers to enable/disable relocation on exceptions Michael Neuling
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

From: Ian Munsie <imunsie@au1.ibm.com>

I am going to use this in the next patch, better to have this code in
one place rather than three.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/hvcall.h         |   20 ++++++++++++++++++++
 drivers/infiniband/hw/ehca/hcp_if.c       |   20 --------------------
 drivers/net/ethernet/ibm/ehea/ehea_phyp.h |   20 --------------------
 3 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
index a3d26d8..0975e5c 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -356,6 +356,26 @@ struct hvcall_mpp_x_data {
 
 int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data);
 
+static inline unsigned int get_longbusy_msecs(int longbusy_rc)
+{
+	switch (longbusy_rc) {
+	case H_LONG_BUSY_ORDER_1_MSEC:
+		return 1;
+	case H_LONG_BUSY_ORDER_10_MSEC:
+		return 10;
+	case H_LONG_BUSY_ORDER_100_MSEC:
+		return 100;
+	case H_LONG_BUSY_ORDER_1_SEC:
+		return 1000;
+	case H_LONG_BUSY_ORDER_10_SEC:
+		return 10000;
+	case H_LONG_BUSY_ORDER_100_SEC:
+		return 100000;
+	default:
+		return 1;
+	}
+}
+
 #ifdef CONFIG_PPC_PSERIES
 extern int CMO_PrPSP;
 extern int CMO_SecPSP;
diff --git a/drivers/infiniband/hw/ehca/hcp_if.c b/drivers/infiniband/hw/ehca/hcp_if.c
index 2d41d04..89517ff 100644
--- a/drivers/infiniband/hw/ehca/hcp_if.c
+++ b/drivers/infiniband/hw/ehca/hcp_if.c
@@ -90,26 +90,6 @@
 
 static DEFINE_SPINLOCK(hcall_lock);
 
-static u32 get_longbusy_msecs(int longbusy_rc)
-{
-	switch (longbusy_rc) {
-	case H_LONG_BUSY_ORDER_1_MSEC:
-		return 1;
-	case H_LONG_BUSY_ORDER_10_MSEC:
-		return 10;
-	case H_LONG_BUSY_ORDER_100_MSEC:
-		return 100;
-	case H_LONG_BUSY_ORDER_1_SEC:
-		return 1000;
-	case H_LONG_BUSY_ORDER_10_SEC:
-		return 10000;
-	case H_LONG_BUSY_ORDER_100_SEC:
-		return 100000;
-	default:
-		return 1;
-	}
-}
-
 static long ehca_plpar_hcall_norets(unsigned long opcode,
 				    unsigned long arg1,
 				    unsigned long arg2,
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
index 8364815..99b6c2a 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
+++ b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
@@ -39,26 +39,6 @@
  * hcp_*  - structures, variables and functions releated to Hypervisor Calls
  */
 
-static inline u32 get_longbusy_msecs(int long_busy_ret_code)
-{
-	switch (long_busy_ret_code) {
-	case H_LONG_BUSY_ORDER_1_MSEC:
-		return 1;
-	case H_LONG_BUSY_ORDER_10_MSEC:
-		return 10;
-	case H_LONG_BUSY_ORDER_100_MSEC:
-		return 100;
-	case H_LONG_BUSY_ORDER_1_SEC:
-		return 1000;
-	case H_LONG_BUSY_ORDER_10_SEC:
-		return 10000;
-	case H_LONG_BUSY_ORDER_100_SEC:
-		return 100000;
-	default:
-		return 1;
-	}
-}
-
 /* Number of pages which can be registered at once by H_REGISTER_HEA_RPAGES */
 #define EHEA_MAX_RPAGE 512
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 11/14] powerpc: Add wrappers to enable/disable relocation on exceptions
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (10 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 10/12] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

From: Ian Munsie <imunsie@au1.ibm.com>

These wrappers hide the parameters that have to be passed to H_SET_MODE
to enable/disable relocation on during exceptions.

As noted in the comments, since these have partition wide scope, they
may take some time to complete and must be periodically retried until
H_SUCCESS is returned.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/platforms/pseries/plpar_wrappers.h |   25 +++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/plpar_wrappers.h b/arch/powerpc/platforms/pseries/plpar_wrappers.h
index 44ad214..e6cc34a 100644
--- a/arch/powerpc/platforms/pseries/plpar_wrappers.h
+++ b/arch/powerpc/platforms/pseries/plpar_wrappers.h
@@ -279,4 +279,29 @@ static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
 {
 	return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
 }
+
+/*
+ * Enable relocation on exceptions on this partition
+ *
+ * Note: this call has a partition wide scope and can take a while to complete.
+ * If it returns H_LONG_BUSY_* it should be retried periodically until it
+ * returns H_SUCCESS.
+ */
+static inline long enable_reloc_on_exceptions(void)
+{
+	/* mflags = 3: Exceptions at 0xC000000000004000 */
+	return plpar_set_mode(3, 3, 0, 0);
+}
+
+/*
+ * Disable relocation on exceptions on this partition
+ *
+ * Note: this call has a partition wide scope and can take a while to complete.
+ * If it returns H_LONG_BUSY_* it should be retried periodically until it
+ * returns H_SUCCESS.
+ */
+static inline long disable_reloc_on_exceptions(void) {
+	return plpar_set_mode(0, 3, 0, 0);
+}
+
 #endif /* _PSERIES_PLPAR_WRAPPERS_H */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (11 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 11/14] powerpc: Add wrappers to enable/disable relocation on exceptions Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  9:26   ` Stephen Rothwell
  2012-11-09  6:19 ` [PATCH 13/14] powerpc: Enable relocation on during exceptions at boot Michael Neuling
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

From: Ian Munsie <imunsie@au1.ibm.com>

I am going to use this in the next patch, better to have this code in
one place rather than three.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/include/asm/hvcall.h         |   20 ++++++++++++++++++++
 drivers/infiniband/hw/ehca/hcp_if.c       |   20 --------------------
 drivers/net/ethernet/ibm/ehea/ehea_phyp.h |   20 --------------------
 3 files changed, 20 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
index a3d26d8..0975e5c 100644
--- a/arch/powerpc/include/asm/hvcall.h
+++ b/arch/powerpc/include/asm/hvcall.h
@@ -356,6 +356,26 @@ struct hvcall_mpp_x_data {
 
 int h_get_mpp_x(struct hvcall_mpp_x_data *mpp_x_data);
 
+static inline unsigned int get_longbusy_msecs(int longbusy_rc)
+{
+	switch (longbusy_rc) {
+	case H_LONG_BUSY_ORDER_1_MSEC:
+		return 1;
+	case H_LONG_BUSY_ORDER_10_MSEC:
+		return 10;
+	case H_LONG_BUSY_ORDER_100_MSEC:
+		return 100;
+	case H_LONG_BUSY_ORDER_1_SEC:
+		return 1000;
+	case H_LONG_BUSY_ORDER_10_SEC:
+		return 10000;
+	case H_LONG_BUSY_ORDER_100_SEC:
+		return 100000;
+	default:
+		return 1;
+	}
+}
+
 #ifdef CONFIG_PPC_PSERIES
 extern int CMO_PrPSP;
 extern int CMO_SecPSP;
diff --git a/drivers/infiniband/hw/ehca/hcp_if.c b/drivers/infiniband/hw/ehca/hcp_if.c
index 2d41d04..89517ff 100644
--- a/drivers/infiniband/hw/ehca/hcp_if.c
+++ b/drivers/infiniband/hw/ehca/hcp_if.c
@@ -90,26 +90,6 @@
 
 static DEFINE_SPINLOCK(hcall_lock);
 
-static u32 get_longbusy_msecs(int longbusy_rc)
-{
-	switch (longbusy_rc) {
-	case H_LONG_BUSY_ORDER_1_MSEC:
-		return 1;
-	case H_LONG_BUSY_ORDER_10_MSEC:
-		return 10;
-	case H_LONG_BUSY_ORDER_100_MSEC:
-		return 100;
-	case H_LONG_BUSY_ORDER_1_SEC:
-		return 1000;
-	case H_LONG_BUSY_ORDER_10_SEC:
-		return 10000;
-	case H_LONG_BUSY_ORDER_100_SEC:
-		return 100000;
-	default:
-		return 1;
-	}
-}
-
 static long ehca_plpar_hcall_norets(unsigned long opcode,
 				    unsigned long arg1,
 				    unsigned long arg2,
diff --git a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
index 8364815..99b6c2a 100644
--- a/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
+++ b/drivers/net/ethernet/ibm/ehea/ehea_phyp.h
@@ -39,26 +39,6 @@
  * hcp_*  - structures, variables and functions releated to Hypervisor Calls
  */
 
-static inline u32 get_longbusy_msecs(int long_busy_ret_code)
-{
-	switch (long_busy_ret_code) {
-	case H_LONG_BUSY_ORDER_1_MSEC:
-		return 1;
-	case H_LONG_BUSY_ORDER_10_MSEC:
-		return 10;
-	case H_LONG_BUSY_ORDER_100_MSEC:
-		return 100;
-	case H_LONG_BUSY_ORDER_1_SEC:
-		return 1000;
-	case H_LONG_BUSY_ORDER_10_SEC:
-		return 10000;
-	case H_LONG_BUSY_ORDER_100_SEC:
-		return 100000;
-	default:
-		return 1;
-	}
-}
-
 /* Number of pages which can be registered at once by H_REGISTER_HEA_RPAGES */
 #define EHEA_MAX_RPAGE 512
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 13/14] powerpc: Enable relocation on during exceptions at boot
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (12 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  6:19 ` [PATCH 14/14] powerpc: Disable relocation on exceptions when kexecing Michael Neuling
  2012-11-09  8:58 ` [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Gabriel Paubert
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

From: Ian Munsie <imunsie@au1.ibm.com>

We currently do this synchronously at boot from setup_arch. On a large
system this could hypothetically take a little while to complete, so
currently we will give up if we are asked to wait for more than a second
in total.

If we actually start hitting that timeout in practice we can always move
this code into a kernel thread to take care of it in the background.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
---
 arch/powerpc/platforms/pseries/setup.c |   38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index e3cb7ae..4c4adc0 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -367,6 +367,36 @@ static void pSeries_idle(void)
 	}
 }
 
+/*
+ * Enable relocation on during exceptions. This has partition wide scope and
+ * may take a while to complete, if it takes longer than one second we will
+ * just give up rather than wasting any more time on this - if that turns out
+ * to ever be a problem in practice we can move this into a kernel thread to
+ * finish off the process later in boot.
+ */
+static int __init pSeries_enable_reloc_on_exc(void)
+{
+	long rc;
+	unsigned int delay, total_delay = 0;
+
+	while (1) {
+		rc = enable_reloc_on_exceptions();
+		if (!H_IS_LONG_BUSY(rc))
+			return rc;
+
+		delay = get_longbusy_msecs(rc);
+		total_delay += delay;
+		if (total_delay > 1000) {
+			pr_warn("Warning: Giving up waiting to enable "
+				"relocation on exceptions (%u msec)!\n",
+				total_delay);
+			return rc;
+		}
+
+		mdelay(delay);
+	}
+}
+
 static void __init pSeries_setup_arch(void)
 {
 	panic_timeout = 10;
@@ -402,6 +432,14 @@ static void __init pSeries_setup_arch(void)
 		ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
 	else
 		ppc_md.enable_pmcs = power4_enable_pmcs;
+
+	if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+		long rc;
+		if ((rc = pSeries_enable_reloc_on_exc()) != H_SUCCESS) {
+			pr_warn("Unable to enable relocation on exceptions: "
+				"%ld\n", rc);
+		}
+	}
 }
 
 static int __init pSeries_init_panel(void)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 14/14] powerpc: Disable relocation on exceptions when kexecing
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (13 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 13/14] powerpc: Enable relocation on during exceptions at boot Michael Neuling
@ 2012-11-09  6:19 ` Michael Neuling
  2012-11-09  8:58 ` [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Gabriel Paubert
  15 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  6:19 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Michael Neuling, linuxppc-dev, Ian Munsie, Matt Evans

From: Ian Munsie <imunsie@au1.ibm.com>

Since we don't know if they new kernel we are kexecing into has been
built to support relocation on exceptions, we disable them before we
kexec.

We do NOT disable them if we are execing a kdump kernel, because we
want to change as little state as possible and it is likely that we are
execing ourselves and will be able to handle them anyway.

Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
---
 arch/powerpc/platforms/pseries/setup.c |   33 ++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 4c4adc0..47d2a7e 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -40,6 +40,7 @@
 #include <linux/seq_file.h>
 #include <linux/root_dev.h>
 #include <linux/cpuidle.h>
+#include <linux/kexec.h>
 
 #include <asm/mmu.h>
 #include <asm/processor.h>
@@ -397,6 +398,35 @@ static int __init pSeries_enable_reloc_on_exc(void)
 	}
 }
 
+#ifdef CONFIG_KEXEC
+static long pSeries_disable_reloc_on_exc(void)
+{
+	long rc;
+
+	while (1) {
+		rc = disable_reloc_on_exceptions();
+		if (!H_IS_LONG_BUSY(rc))
+			return rc;
+		mdelay(get_longbusy_msecs(rc));
+	}
+}
+
+static void pSeries_machine_kexec(struct kimage *image)
+{
+	long rc;
+
+	if (firmware_has_feature(FW_FEATURE_SET_MODE) &&
+	    (image->type != KEXEC_TYPE_CRASH)) {
+		rc = pSeries_disable_reloc_on_exc();
+		if (rc != H_SUCCESS)
+			pr_warning("Warning: Failed to disable relocation on "
+				   "exceptions: %ld\n", rc);
+	}
+
+	default_machine_kexec(image);
+}
+#endif
+
 static void __init pSeries_setup_arch(void)
 {
 	panic_timeout = 10;
@@ -697,4 +727,7 @@ define_machine(pseries) {
 	.progress		= rtas_progress,
 	.system_reset_exception = pSeries_system_reset_exception,
 	.machine_check_exception = pSeries_machine_check_exception,
+#ifdef CONFIG_KEXEC
+	.machine_kexec          = pSeries_machine_kexec,
+#endif
 };
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions
  2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
                   ` (14 preceding siblings ...)
  2012-11-09  6:19 ` [PATCH 14/14] powerpc: Disable relocation on exceptions when kexecing Michael Neuling
@ 2012-11-09  8:58 ` Gabriel Paubert
  2012-11-09  9:51   ` Michael Neuling
  15 siblings, 1 reply; 22+ messages in thread
From: Gabriel Paubert @ 2012-11-09  8:58 UTC (permalink / raw)
  To: Michael Neuling; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

On Fri, Nov 09, 2012 at 05:18:58PM +1100, Michael Neuling wrote:
> This set of patches adds support for taking exceptions with the MMU on which is
> supported by POWER8.
> 
> A new set of exception vectors is added at 0xc000_0000_0000_4xxx.  When the HW
> takes us here, MSR IR/DR will be set already and we no longer need a costly
> RFID to turn the MMU back on again.
> 
> The original 0x0 based exception vectors remain for when the HW can't leave the
> MMU on.  Examples of this are when we can't trust the current the MMU mappings,
                                                                ^^^
Extra "the" (here and in a couple of patches). 

Can't do much more since I don't have any hardware past G5, but the series
looks nice and avoiding transient excursions to real mode is a good thing.

	Gabriel


> like when we are changing from guest to hypervisor (HV 0 -> 1) or when the MMU
> was off already.  In these cases the HW will take us to the original 0x0 based
> exception vectors with the MMU off as before.
> 
> The core of these patches were originally written by Matt Evans.  
> 
> Ian Munsie (5):
>   powerpc: Add set_mode hcall
>   powerpc: Add wrappers to enable/disable relocation on exceptions
>   powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate
>     function
>   powerpc: Enable relocation on during exceptions at boot
>   powerpc: Disable relocation on exceptions when kexecing
> 
> Michael Neuling (9):
>   powerpc: Add POWER8 architected mode to cputable
>   powerpc: Whitespace changes in exception64s.S
>   powerpc: Remove unessessary 0x3000 location enforcement
>   powerpc: Make load_hander handle upto 64k offset
>   powerpc: Turn syscall handler into macros
>   powerpc: Add new macros needed for relocation on exceptions
>   powerpc: Add relocation on exception vector handlers
>   powerpc: Move initial mfspr LPCR out of __init_LPCR
>   powerpc: Setup relocation on exceptions for bare metal systems
> 
>  arch/powerpc/include/asm/exception-64s.h        |   97 ++++++-
>  arch/powerpc/include/asm/firmware.h             |    4 +-
>  arch/powerpc/include/asm/hvcall.h               |   23 +-
>  arch/powerpc/include/asm/reg.h                  |    2 +
>  arch/powerpc/kernel/cpu_setup_power.S           |    8 +-
>  arch/powerpc/kernel/cputable.c                  |   15 ++
>  arch/powerpc/kernel/exceptions-64s.S            |  306 +++++++++++++++++++----
>  arch/powerpc/kernel/head_64.S                   |    3 +-
>  arch/powerpc/kernel/setup_64.c                  |    5 +
>  arch/powerpc/platforms/pseries/firmware.c       |    1 +
>  arch/powerpc/platforms/pseries/plpar_wrappers.h |   36 +++
>  arch/powerpc/platforms/pseries/setup.c          |   71 ++++++
>  drivers/infiniband/hw/ehca/hcp_if.c             |   20 --
>  drivers/net/ethernet/ibm/ehea/ehea_phyp.h       |   20 --
>  14 files changed, 516 insertions(+), 95 deletions(-)
> 
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function
  2012-11-09  6:19 ` [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
@ 2012-11-09  9:26   ` Stephen Rothwell
  2012-11-09  9:49     ` Michael Neuling
  0 siblings, 1 reply; 22+ messages in thread
From: Stephen Rothwell @ 2012-11-09  9:26 UTC (permalink / raw)
  To: Michael Neuling; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

[-- Attachment #1: Type: text/plain, Size: 788 bytes --]

Hi Mikey,

On Fri,  9 Nov 2012 17:19:11 +1100 Michael Neuling <mikey@neuling.org> wrote:
>
> From: Ian Munsie <imunsie@au1.ibm.com>
> 
> I am going to use this in the next patch, better to have this code in
> one place rather than three.
> 
> Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> ---
>  arch/powerpc/include/asm/hvcall.h         |   20 ++++++++++++++++++++
>  drivers/infiniband/hw/ehca/hcp_if.c       |   20 --------------------
>  drivers/net/ethernet/ibm/ehea/ehea_phyp.h |   20 --------------------
>  3 files changed, 20 insertions(+), 40 deletions(-)

This is identical to patch 10/14 ...

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function
  2012-11-09  9:26   ` Stephen Rothwell
@ 2012-11-09  9:49     ` Michael Neuling
  0 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  9:49 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> Hi Mikey,
> 
> On Fri,  9 Nov 2012 17:19:11 +1100 Michael Neuling <mikey@neuling.org> wrote:
> >
> > From: Ian Munsie <imunsie@au1.ibm.com>
> > 
> > I am going to use this in the next patch, better to have this code in
> > one place rather than three.
> > 
> > Signed-off-by: Ian Munsie <imunsie@au1.ibm.com>
> > Signed-off-by: Michael Neuling <mikey@neuling.org>
> > ---
> >  arch/powerpc/include/asm/hvcall.h         |   20 ++++++++++++++++++++
> >  drivers/infiniband/hw/ehca/hcp_if.c       |   20 --------------------
> >  drivers/net/ethernet/ibm/ehea/ehea_phyp.h |   20 --------------------
> >  3 files changed, 20 insertions(+), 40 deletions(-)
> 
> This is identical to patch 10/14 ...

Actually, it's the same as 10/12.  Looks like i didn't clear out my send
directory correctly.

10/14 is correct.

Thanks,
Mikey

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions
  2012-11-09  8:58 ` [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Gabriel Paubert
@ 2012-11-09  9:51   ` Michael Neuling
  0 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-09  9:51 UTC (permalink / raw)
  To: Gabriel Paubert; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

> > This set of patches adds support for taking exceptions with the MMU on which is
> > supported by POWER8.
> > 
> > A new set of exception vectors is added at 0xc000_0000_0000_4xxx.  When the HW
> > takes us here, MSR IR/DR will be set already and we no longer need a costly
> > RFID to turn the MMU back on again.
> > 
> > The original 0x0 based exception vectors remain for when the HW can't leave the
> > MMU on.  Examples of this are when we can't trust the current the MMU mappings,
>                                                                 ^^^
> Extra "the" (here and in a couple of patches). 

Thanks, I'll fix.

> Can't do much more since I don't have any hardware past G5, but the
> series looks nice and avoiding transient excursions to real mode is a
> good thing.

Thanks.

Mikey

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems
  2012-11-09  6:19 ` [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems Michael Neuling
@ 2012-11-12  1:32   ` Segher Boessenkool
  2012-11-12  2:08     ` Michael Neuling
  0 siblings, 1 reply; 22+ messages in thread
From: Segher Boessenkool @ 2012-11-12  1:32 UTC (permalink / raw)
  To: Michael Neuling; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

> --- a/arch/powerpc/include/asm/reg.h
> +++ b/arch/powerpc/include/asm/reg.h
> @@ -249,6 +249,8 @@
>  #define   LPCR_RMLS    0x1C000000      /* impl dependent rmo limit  
> sel */
>  #define	  LPCR_RMLS_SH	(63-37)
>  #define   LPCR_ILE     0x02000000      /* !HV irqs set MSR:LE */
> +#define   LPCR_AIL_0	0x00000000	/* MMU off IRQ location 0x0 */
> +#define   LPCR_AIL_3	0x01800000	/* MMU on IRQ location  
> 0xc00...4xxx */

s/IRQ location/exception offset/ ?

> --- a/arch/powerpc/kernel/cpu_setup_power.S
> +++ b/arch/powerpc/kernel/cpu_setup_power.S
> @@ -54,6 +54,7 @@ _GLOBAL(__setup_cpu_power8)
>  	li	r0,0
>  	mtspr	SPRN_LPID,r0
>  	mfspr	r3,SPRN_LPCR
> +	oris	r3, r3, LPCR_AIL_3@h

Is the AIL field only two bits?  If not, you probably want to clear
the other bits.

This series looks really nice btw :-)


Segher

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems
  2012-11-12  1:32   ` Segher Boessenkool
@ 2012-11-12  2:08     ` Michael Neuling
  0 siblings, 0 replies; 22+ messages in thread
From: Michael Neuling @ 2012-11-12  2:08 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Ian Munsie, Matt Evans

Segher Boessenkool <segher@kernel.crashing.org> wrote:

> > --- a/arch/powerpc/include/asm/reg.h
> > +++ b/arch/powerpc/include/asm/reg.h
> > @@ -249,6 +249,8 @@
> >  #define   LPCR_RMLS    0x1C000000      /* impl dependent rmo limit sel */
> >  #define	  LPCR_RMLS_SH	(63-37)
> >  #define   LPCR_ILE     0x02000000      /* !HV irqs set MSR:LE */
> > +#define   LPCR_AIL_0	0x00000000	/* MMU off IRQ location 0x0 */
> > +#define   LPCR_AIL_3	0x01800000	/* MMU on IRQ location 0xc00...4xxx */
> 
> s/IRQ location/exception offset/ ?

Sure, updated.

> 
> > --- a/arch/powerpc/kernel/cpu_setup_power.S
> > +++ b/arch/powerpc/kernel/cpu_setup_power.S
> > @@ -54,6 +54,7 @@ _GLOBAL(__setup_cpu_power8)
> >  	li	r0,0
> >  	mtspr	SPRN_LPID,r0
> >  	mfspr	r3,SPRN_LPCR
> > +	oris	r3, r3, LPCR_AIL_3@h
> 
> Is the AIL field only two bits?  If not, you probably want to clear
> the other bits.

Yes it only 2 bits.

> This series looks really nice btw :-)

Cheers,
Mikey

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2012-11-12  2:08 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-09  6:18 [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Michael Neuling
2012-11-09  6:18 ` [PATCH 01/14] powerpc: Fix name denorm hypervisor symbol Michael Neuling
2012-11-09  6:19 ` [PATCH 02/14] powerpc: Whitespace changes in exception64s.S Michael Neuling
2012-11-09  6:19 ` [PATCH 03/14] powerpc: Remove unessessary 0x3000 location enforcement Michael Neuling
2012-11-09  6:19 ` [PATCH 04/14] powerpc: Make load_hander handle upto 64k offset Michael Neuling
2012-11-09  6:19 ` [PATCH 05/14] powerpc: Turn syscall handler into macros Michael Neuling
2012-11-09  6:19 ` [PATCH 06/14] powerpc: Add new macros needed for relocation on exceptions Michael Neuling
2012-11-09  6:19 ` [PATCH 07/14] powerpc: Add relocation on exception vector handlers Michael Neuling
2012-11-09  6:19 ` [PATCH 08/14] powerpc: Move initial mfspr LPCR out of __init_LPCR Michael Neuling
2012-11-09  6:19 ` [PATCH 09/14] powerpc: Setup relocation on exceptions for bare metal systems Michael Neuling
2012-11-12  1:32   ` Segher Boessenkool
2012-11-12  2:08     ` Michael Neuling
2012-11-09  6:19 ` [PATCH 10/14] powerpc: Add set_mode hcall Michael Neuling
2012-11-09  6:19 ` [PATCH 10/12] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
2012-11-09  6:19 ` [PATCH 11/14] powerpc: Add wrappers to enable/disable relocation on exceptions Michael Neuling
2012-11-09  6:19 ` [PATCH 12/14] powerpc: Move get_longbusy_msecs into hvcall.h and remove duplicate function Michael Neuling
2012-11-09  9:26   ` Stephen Rothwell
2012-11-09  9:49     ` Michael Neuling
2012-11-09  6:19 ` [PATCH 13/14] powerpc: Enable relocation on during exceptions at boot Michael Neuling
2012-11-09  6:19 ` [PATCH 14/14] powerpc: Disable relocation on exceptions when kexecing Michael Neuling
2012-11-09  8:58 ` [PATCH 00/14] powerpc: Add support for POWER8 relocation on exceptions Gabriel Paubert
2012-11-09  9:51   ` Michael Neuling

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).