Skip to contentSkip to conversation

powerpc: Enable ILE on pSeries without H_MODE_SET

PATCH New Alexander Graf 1 participant 5 messages Dec 23, 2013 PowerPC

lore
Share & tools
lore
#0 lore raw

cover powerpc: Enable ILE on pSeries without H_MODE_SET

Howdy,

There are a few machines out there that would be pretty ppc64le capable if only it wasn't for the hypervisor that's running on them.

The problem is that we need to run in ILE (interrupts delivered in little endian) mode to run our normal interrupt vectors. The hypercall to enable this mode is not available on PowerVM.

However, we can try to be smart here. Instead of configuring the hypervisor to run interrupts in little endian mode, we can just bring ourselves back to little endian on every interrupt.

We do this by patching every interrupt handler with a "branch" instruction at the beginning which jumps into a tiny helper that turns on MSR.LE and resumes the interrupt handler.

This is not the most smart thing to do performance wise, but it does have a really nice side effect: We do not impact hypervisors that do support H_SET_MODE. This is important, as we want to be as fast as possible on machines that are supposed to run Little Endian guests.

As a tiny side effect we also clobber CFAR in every interrupt, rendering the whole thing pretty useless. So we don't get nice and shiny perf and debugging helps. Oh well.

Given that the alternatives to all of this would either be

a) Not run at all or
b) Incur performance penalties for "good" systems or
c) Add significant maintenance burden on us

I'm quite convinced this is the way we want to go.

Enjoy,

Alex

Alexander Graf (4):
powerpc: Add global exports for all interrupt vectors
powerpc: Add relocation code for fixups
powerpc: Add hack to make ppc64le work on hosts without ILE
powerpc: Don't return to BE mode when we are already there

 arch/powerpc/include/asm/cputable.h    |   2 +
 arch/powerpc/kernel/Makefile           |   3 +
 arch/powerpc/kernel/exceptions-64s.S   |   5 ++
 arch/powerpc/kernel/fake_ile.S         | 101 +++++++++++++++++++++++++++++++++
 arch/powerpc/kernel/vmlinux.lds.S      |  14 +++++
 arch/powerpc/lib/feature-fixups.c      |  22 +++++++
 arch/powerpc/platforms/pseries/setup.c |  61 +++++++++++++++++++-
 7 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/kernel/fake_ile.S
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 1/4 powerpc: Add global exports for all interrupt vectors

We need to access every interrupt vector we can find soon, so let's make them all visible through names to outside code.

---
 arch/powerpc/kernel/exceptions-64s.S | 5 +++++
 1 file changed, 5 insertions(+)
arch/powerpc/kernel/exceptions-64s.S +5 -0
index 9f905e4..fcd039f 100644
@@ -148,6 +148,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 				 NOTEST, 0x100)
 
 	. = 0x200
+	.globl machine_check_pSeries_1
 machine_check_pSeries_1:
 	/* This is moved out of line as it can be patched by FW, but
 	 * some code path might still want to branch into the original
@@ -328,24 +329,28 @@ hv_doorbell_trampoline:
 	 * trickery is thus necessary
 	 */
 	. = 0xf00
+	.global performance_monitor_pseries_trampoline
 performance_monitor_pseries_trampoline:
 	SET_SCRATCH0(r13)
 	EXCEPTION_PROLOG_0(PACA_EXGEN)
 	b	performance_monitor_pSeries
 
 	. = 0xf20
+	.global altivec_unavailable_pseries_trampoline
 altivec_unavailable_pseries_trampoline:
 	SET_SCRATCH0(r13)
 	EXCEPTION_PROLOG_0(PACA_EXGEN)
 	b	altivec_unavailable_pSeries
 
 	. = 0xf40
+	.global vsx_unavailable_pseries_trampoline
 vsx_unavailable_pseries_trampoline:
 	SET_SCRATCH0(r13)
 	EXCEPTION_PROLOG_0(PACA_EXGEN)
 	b	vsx_unavailable_pSeries
 
 	. = 0xf60
+	.global facility_unavailable_trampoline
 facility_unavailable_trampoline:
 	SET_SCRATCH0(r13)
 	EXCEPTION_PROLOG_0(PACA_EXGEN)
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/4 powerpc: Add relocation code for fixups

In reply to Alexander Graf

We need to patch an instruction that is covered by the fixup framework. If we don't do anything about it we end up getting our own patched instruction unpatched by nops by the fixups.

So add an export to the fixup code that allows us to tell it that an instruction moved location in memory. This works because we move the instruction into a different location, but still execute it.

---
 arch/powerpc/include/asm/cputable.h |  2 ++
 arch/powerpc/lib/feature-fixups.c   | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)
arch/powerpc/include/asm/cputable.h +2 -0
index 0d4939b..c981f99 100644
@@ -99,6 +99,8 @@ extern unsigned int __start___ftr_fixup, __stop___ftr_fixup;
 extern struct cpu_spec *identify_cpu(unsigned long offset, unsigned int pvr);
 extern void do_feature_fixups(unsigned long value, void *fixup_start,
 			      void *fixup_end);
+extern void relocate_fixup_entry(void *fixup_start, void *fixup_end,
+				 void *old_addr, void *new_addr);
 
 extern const char *powerpc_base_platform;
 
arch/powerpc/lib/feature-fixups.c +22 -0
index 7a8a748..33996a4 100644
@@ -151,6 +151,28 @@ void do_final_fixups(void)
 #endif
 }
 
+/*
+ * This changes the internal fixup location of a code block from
+ * old_addr to new_addr.
+ */
+void relocate_fixup_entry(void *fixup_start, void *fixup_end,
+			  void *old_addr, void *new_addr)
+{
+	struct fixup_entry *fcur, *fend;
+
+	fcur = fixup_start;
+	fend = fixup_end;
+
+	for (; fcur < fend; fcur++) {
+		long diff = (long)new_addr -
+			    (long)calc_addr(fcur, fcur->start_off);
+		if (calc_addr(fcur, fcur->start_off) == old_addr) {
+			fcur->start_off += diff;
+			fcur->end_off += diff;
+		}
+	}
+}
+
 #ifdef CONFIG_FTR_FIXUP_SELFTEST
 
 #define check(x)	\
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/4 powerpc: Add hack to make ppc64le work on hosts without ILE

In reply to Alexander Graf

Some hypervisors don't implement the H_SET_MODE hypercall that we need to set the ILE bit in LPCR which allows us to execute interrupts in little endian mode.

However otherwise we would be able to run on those hypervisors just fine.

So let's be creative. This patch creates a few small helpers that work without register clobbering that execute in big endian mode.

Every interrupt gets patched with a branch instruction as the first instruction which jumps into their respective helper. That helper enables MSR.LE and returns back to the original interrupt.

That way we can keep our interrupt handlers in little endian code while the hypervisor is unaware that we need them to be in little endian.

---
 arch/powerpc/kernel/Makefile           |   3 +
 arch/powerpc/kernel/fake_ile.S         | 101 +++++++++++++++++++++++++++++++++
 arch/powerpc/kernel/vmlinux.lds.S      |  14 +++++
 arch/powerpc/platforms/pseries/setup.c |  50 ++++++++++++++++
 4 files changed, 168 insertions(+)
 create mode 100644 arch/powerpc/kernel/fake_ile.S
arch/powerpc/kernel/Makefile +3 -0
index 445cb6e..31842e6 100644
@@ -131,6 +131,9 @@ endif
 
 obj-$(CONFIG_EPAPR_PARAVIRT)	+= epapr_paravirt.o epapr_hcalls.o
 obj-$(CONFIG_KVM_GUEST)		+= kvm.o kvm_emul.o
+ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
+obj-$(CONFIG_PPC_BOOK3S_64)	+= fake_ile.o
+endif
 
 # Disable GCOV in odd or sensitive code
 GCOV_PROFILE_prom_init.o := n
arch/powerpc/kernel/fake_ile.S new file +101 -0

101 lines not on this page · raw message

arch/powerpc/kernel/vmlinux.lds.S +14 -0
index f096e72..7fdb7c9 100644
@@ -147,6 +147,20 @@ SECTIONS
 		*(__fw_ftr_fixup)
 		__stop___fw_ftr_fixup = .;
 	}
+
+	. = ALIGN(8);
+	__fake_ile : AT(ADDR(__fake_ile) - LOAD_OFFSET) {
+		__start___fake_ile = .;
+		*(__fake_ile)
+		__stop___fake_ile = .;
+	}
+
+	. = ALIGN(8);
+	__be_patch : AT(ADDR(__be_patch) - LOAD_OFFSET) {
+		__start___be_patch = .;
+		*(__be_patch)
+		__stop___be_patch = .;
+	}
 #endif
 	.init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
 		INIT_RAM_FS
arch/powerpc/platforms/pseries/setup.c +50 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/4 powerpc: Don't return to BE mode when we are already there

In reply to Alexander Graf

Our Little Endian kernels can now live in a world where they are running with Big Endian interrupts enabled. That is great for kexec, because now we don't have to switch back to Big Endian mode.

Indicate this in the code. Only try to go into Big Endian mode when we're not already there yet.

---
 arch/powerpc/platforms/pseries/setup.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/platforms/pseries/setup.c +10 -1
index fb5d98c..7db1cf1 100644
@@ -446,10 +446,15 @@ static void pSeries_machine_kexec(struct kimage *image)
 #endif
 
 #ifdef __LITTLE_ENDIAN__
+static bool ile_enabled;
+
 long pseries_big_endian_exceptions(void)
 {
 	long rc;
 
+	if (!ile_enabled)
+		return H_SUCCESS;
+
 	while (1) {
 		rc = enable_big_endian_exceptions();
 		if (!H_IS_LONG_BUSY(rc))
@@ -498,8 +503,12 @@ static long pseries_little_endian_exceptions(void)
 
 	while (1) {
 		rc = enable_little_endian_exceptions();
-		if (!H_IS_LONG_BUSY(rc))
+
+		if (!H_IS_LONG_BUSY(rc)) {
+			ile_enabled = true;
 			return rc;
+		}
+
 		mdelay(get_longbusy_msecs(rc));
 	}
 }
Signature · 1 line
1.8.1.4