Skip to contentSkip to conversation

powerpc: Add more PPC bit conversion macros

PATCH In review Benjamin Herrenschmidt 3 participants 14 messages Apr 5, 2017 – Apr 12, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/10 powerpc: Add more PPC bit conversion macros

Add 32 and 8 bit variants

---
 arch/powerpc/include/asm/bitops.h | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/powerpc/include/asm/bitops.h +8 -0
index bc5fdfd..33a24fd 100644
@@ -55,6 +55,14 @@
 #define PPC_BITEXTRACT(bits, ppc_bit, dst_bit)			\
 	((((bits) >> PPC_BITLSHIFT(ppc_bit)) & 1) << (dst_bit))
 
+#define PPC_BITLSHIFT32(be)	(32 - 1 - (be))
+#define PPC_BIT32(bit)		(1UL << PPC_BITLSHIFT32(bit))
+#define PPC_BITMASK32(bs, be)	((PPC_BIT32(bs) - PPC_BIT32(be))|PPC_BIT32(bs))
+
+#define PPC_BITLSHIFT8(be)	(8 - 1 - (be))
+#define PPC_BIT8(bit)		(1UL << PPC_BITLSHIFT8(bit))
+#define PPC_BITMASK8(bs, be)	((PPC_BIT8(bs) - PPC_BIT8(be))|PPC_BIT8(bs))
+
 #include <asm/barrier.h>
 
 /* Macro for generating the ***_bits() functions */
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 2/10 powerpc: Add optional smp_ops->prepare_cpu SMP callback

Some platforms (will) need to perform allocations before bringing a new CPU online. Doing it from smp_ops->setup_cpu is the wrong thing to do:

- It has no useful failure path (too late)
- Calling any allocator will enable interrupts prematurely causing problems with large decrementer among others

Instead, add a new callback that is called from __cpu_up (so from the context trying to online the new CPU) at a point where we can safely allocate and handle failures.

This will be used by XIVE support.

---
 arch/powerpc/include/asm/smp.h |  1 +
 arch/powerpc/kernel/smp.c      | 10 ++++++++++
 2 files changed, 11 insertions(+)
arch/powerpc/include/asm/smp.h +1 -0
index 32db16d..2f8e36f 100644
@@ -44,6 +44,7 @@ struct smp_ops_t {
 #endif
 	void  (*probe)(void);
 	int   (*kick_cpu)(int nr);
+	int   (*prepare_cpu)(int nr);
 	void  (*setup_cpu)(int nr);
 	void  (*bringup_done)(void);
 	void  (*take_timebase)(void);
arch/powerpc/kernel/smp.c +10 -0
index 46f89e6..b12f5f0 100644
@@ -521,6 +521,16 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
 
 	cpu_idle_thread_init(cpu, tidle);
 
+	/*
+	 * The platform might need to allocate resources prior to bringing
+	 * up the CPU
+	 */
+	if (smp_ops->prepare_cpu) {
+		rc = smp_ops->prepare_cpu(cpu);
+		if (rc)
+			return rc;
+	}
+
 	/* Make sure callin-map entry is 0 (can be leftover a CPU
 	 * hotplug
 	 */
Signature · 1 line
2.9.3
#7 lore raw

PATCH v2 6/10 powerpc/kvm: Make kvmppc_xics_create_icp static

In reply to Benjamin Herrenschmidt

It's only used within the same file it's defined

---
 arch/powerpc/include/asm/kvm_ppc.h | 4 ----
 arch/powerpc/kvm/book3s_xics.c     | 2 +-
 2 files changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +0 -4
index dd11c4c..bfef1ae 100644
@@ -478,7 +478,6 @@ extern void kvmppc_free_host_rm_ops(void);
 extern void kvmppc_free_pimap(struct kvm *kvm);
 extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall);
 extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu);
-extern int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server);
 extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args);
 extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
 extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
@@ -507,9 +506,6 @@ static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall)
 static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
 	{ return 0; }
 static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { }
-static inline int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu,
-					 unsigned long server)
-	{ return -EINVAL; }
 static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm,
 					struct kvm_irq_level *args)
 	{ return -ENOTTY; }
arch/powerpc/kvm/book3s_xics.c +1 -1
index e48803e..ef4fd52 100644
@@ -1084,7 +1084,7 @@ static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,
 	return xics->ics[icsid];
 }
 
-int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_num)
+static int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server_num)
 {
 	struct kvmppc_icp *icp;
 
Signature · 1 line
2.9.3
#10 lore raw

PATCH v2 9/10 powerpc: Fixup LPCR:PECE and HEIC setting on POWER9

In reply to Benjamin Herrenschmidt

We need to set LPES in order for normal external interrupts (0x500) to be directed to the guest while running in guest state.

We also need HEIC set to prevent them to be sent to the host while in host state.

With XIVE the host never gets one of these and wouldn't know how to handle it. All host external interrupts come in via the new hypervisor virtualization interrupts vector.

---
 arch/powerpc/include/asm/reg.h        |  1 +
 arch/powerpc/kernel/cpu_setup_power.S | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/reg.h +1 -0
index fc879fd..d0b332b 100644
@@ -365,6 +365,7 @@
 #define   LPCR_MER_SH		11
 #define	  LPCR_GTSE		ASM_CONST(0x0000000000000400)  	/* Guest Translation Shootdown Enable */
 #define   LPCR_TC		ASM_CONST(0x0000000000000200)	/* Translation control */
+#define   LPCR_HEIC		ASM_CONST(0x0000000000000010)   /* Hypervisor External Interrupt Control */
 #define   LPCR_LPES		0x0000000c
 #define   LPCR_LPES0		ASM_CONST(0x0000000000000008)      /* LPAR Env selector 0 */
 #define   LPCR_LPES1		ASM_CONST(0x0000000000000004)      /* LPAR Env selector 1 */
arch/powerpc/kernel/cpu_setup_power.S +10 -5
index 7fe8c79..7013ae3 100644
@@ -29,6 +29,7 @@ _GLOBAL(__setup_cpu_power7)
 	li	r0,0
 	mtspr	SPRN_LPID,r0
 	mfspr	r3,SPRN_LPCR
+	li	r4,(LPCR_LPES1 >> LPCR_LPES_SH)
 	bl	__init_LPCR
 	bl	__init_tlb_power7
 	mtlr	r11
@@ -42,6 +43,7 @@ _GLOBAL(__restore_cpu_power7)
 	li	r0,0
 	mtspr	SPRN_LPID,r0
 	mfspr	r3,SPRN_LPCR
+	li	r4,(LPCR_LPES1 >> LPCR_LPES_SH)
 	bl	__init_LPCR
 	bl	__init_tlb_power7
 	mtlr	r11
@@ -59,6 +61,7 @@ _GLOBAL(__setup_cpu_power8)
 	mtspr	SPRN_LPID,r0
 	mfspr	r3,SPRN_LPCR
 	ori	r3, r3, LPCR_PECEDH
+	li	r4,0 /* LPES = 0 */
 	bl	__init_LPCR
 	bl	__init_HFSCR
 	bl	__init_tlb_power8
@@ -80,6 +83,7 @@ _GLOBAL(__restore_cpu_power8)
 	mtspr	SPRN_LPID,r0
 	mfspr   r3,SPRN_LPCR
 	ori	r3, r3, LPCR_PECEDH
+	li	r4,0 /* LPES = 0 */
 	bl	__init_LPCR
 	bl	__init_HFSCR
 	bl	__init_tlb_power8
@@ -99,10 +103,11 @@ _GLOBAL(__setup_cpu_power9)
 	mtspr	SPRN_PSSCR,r0
 	mtspr	SPRN_LPID,r0
 	mfspr	r3,SPRN_LPCR
-	LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE)
+	LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE  | LPCR_HEIC)
 	or	r3, r3, r4
 	LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
 	andc	r3, r3, r4
+	li	r4,(LPCR_LPES0 >> LPCR_LPES_SH)
 	bl	__init_LPCR
 	bl	__init_HFSCR
 	bl	__init_tlb_power9
@@ -122,10 +127,11 @@ _GLOBAL(__restore_cpu_power9)
 	mtspr	SPRN_PSSCR,r0
 	mtspr	SPRN_LPID,r0
 	mfspr   r3,SPRN_LPCR
-	LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE)
+	LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)
 	or	r3, r3, r4
 	LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
 	andc	r3, r3, r4
+	li	r4,(LPCR_LPES0 >> LPCR_LPES_SH)
 	bl	__init_LPCR
 	bl	__init_HFSCR
 	bl	__init_tlb_power9
@@ -146,7 +152,7 @@ __init_hvmode_206:
 
 __init_LPCR:
 	/* Setup a sane LPCR:
-	 *   Called with initial LPCR in R3
+	 *   Called with initial LPCR in R3 and desired LPES 2-bit value in R4
 	 *
 	 *   LPES = 0b01 (HSRR0/1 used for 0x500)
 	 *   PECE = 0b111
@@ -157,8 +163,7 @@ __init_LPCR:
 	 *
 	 * Other bits untouched for now
 	 */
-	li	r5,1
-	rldimi	r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
+	rldimi	r3,r4, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
 	ori	r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
 	li	r5,4
 	rldimi	r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
Signature · 1 line
2.9.3
#6 lore raw

PATCH v2 5/10 powerpc/kvm: Massage order of #include

In reply to Benjamin Herrenschmidt

We traditionally have linux/ before asm/

---
 arch/powerpc/kvm/book3s.c    |  8 ++++----
 arch/powerpc/kvm/book3s_hv.c | 18 +++++++++---------
 2 files changed, 13 insertions(+), 13 deletions(-)
arch/powerpc/kvm/book3s.c +4 -4
index b6b5c18..aedacef 100644
@@ -20,6 +20,10 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/miscdevice.h>
+#include <linux/gfp.h>
+#include <linux/sched.h>
+#include <linux/vmalloc.h>
+#include <linux/highmem.h>
 
 #include <asm/reg.h>
 #include <asm/cputable.h>
@@ -31,10 +35,6 @@
 #include <asm/kvm_book3s.h>
 #include <asm/mmu_context.h>
 #include <asm/page.h>
-#include <linux/gfp.h>
-#include <linux/sched.h>
-#include <linux/vmalloc.h>
-#include <linux/highmem.h>
 
 #include "book3s.h"
 #include "trace.h"
arch/powerpc/kvm/book3s_hv.c +9 -9
index 1ec86d9..fadb75a 100644
@@ -35,6 +35,15 @@
 #include <linux/srcu.h>
 #include <linux/miscdevice.h>
 #include <linux/debugfs.h>
+#include <linux/gfp.h>
+#include <linux/vmalloc.h>
+#include <linux/highmem.h>
+#include <linux/hugetlb.h>
+#include <linux/kvm_irqfd.h>
+#include <linux/irqbypass.h>
+#include <linux/module.h>
+#include <linux/compiler.h>
+#include <linux/of.h>
 
 #include <asm/reg.h>
 #include <asm/cputable.h>
@@ -58,15 +67,6 @@
 #include <asm/mmu.h>
 #include <asm/opal.h>
 #include <asm/xics.h>
-#include <linux/gfp.h>
-#include <linux/vmalloc.h>
-#include <linux/highmem.h>
-#include <linux/hugetlb.h>
-#include <linux/kvm_irqfd.h>
-#include <linux/irqbypass.h>
-#include <linux/module.h>
-#include <linux/compiler.h>
-#include <linux/of.h>
 
 #include "book3s.h"
 
Signature · 1 line
2.9.3
#9 lore raw

PATCH v2 8/10 powerpc: Consolidate variants of real-mode MMIOs

In reply to Benjamin Herrenschmidt

We have all sort of variants of MMIO accessors for the real mode instructions. This creates a clean set of accessors based on Linux normal naming conventions, replacing all occurrences of the old ones in the tree.

I have purposefully removed the "out/in" variants in favor of only including __raw variants. Any code using these is already pretty much hand tuned to operate in a very specific environment. I've fixed up the 2 users (only one of them actually needed a barrier in the first place).

---
 arch/powerpc/include/asm/io.h             | 98 ++++++++++++++++---------------
 arch/powerpc/include/asm/kvm_book3s_asm.h |  2 +-
 arch/powerpc/include/asm/kvm_ppc.h        |  2 +-
 arch/powerpc/kvm/book3s_hv_builtin.c      | 21 +++----
 arch/powerpc/kvm/book3s_hv_rm_xics.c      |  4 +-
 arch/powerpc/platforms/powernv/rng.c      |  2 +-
 arch/powerpc/sysdev/xics/icp-native.c     |  8 +--
 7 files changed, 68 insertions(+), 69 deletions(-)
arch/powerpc/include/asm/io.h +51 -47
index 5ed2924..45c136a 100644
@@ -192,24 +192,8 @@ DEF_MMIO_OUT_D(out_le32, 32, stw);
 
 #endif /* __BIG_ENDIAN */
 
-/*
- * Cache inhibitied accessors for use in real mode, you don't want to use these
- * unless you know what you're doing.
- *
- * NB. These use the cpu byte ordering.
- */
-DEF_MMIO_OUT_X(out_rm8,   8, stbcix);
-DEF_MMIO_OUT_X(out_rm16, 16, sthcix);
-DEF_MMIO_OUT_X(out_rm32, 32, stwcix);
-DEF_MMIO_IN_X(in_rm8,   8, lbzcix);
-DEF_MMIO_IN_X(in_rm16, 16, lhzcix);
-DEF_MMIO_IN_X(in_rm32, 32, lwzcix);
-
 #ifdef __powerpc64__
 
-DEF_MMIO_OUT_X(out_rm64, 64, stdcix);
-DEF_MMIO_IN_X(in_rm64, 64, ldcix);
-
 #ifdef __BIG_ENDIAN__
 DEF_MMIO_OUT_D(out_be64, 64, std);
 DEF_MMIO_IN_D(in_be64, 64, ld);
@@ -242,35 +226,6 @@ static inline void out_be64(volatile u64 __iomem *addr, u64 val)
 #endif
 #endif /* __powerpc64__ */
 
-
-/*
- * Simple Cache inhibited accessors
- * Unlike the DEF_MMIO_* macros, these don't include any h/w memory
- * barriers, callers need to manage memory barriers on their own.
- * These can only be used in hypervisor real mode.
- */
-
-static inline u32 _lwzcix(unsigned long addr)
-{
-	u32 ret;
-
-	__asm__ __volatile__("lwzcix %0,0, %1"
-			     : "=r" (ret) : "r" (addr) : "memory");
-	return ret;
-}
-
-static inline void _stbcix(u64 addr, u8 val)
-{
-	__asm__ __volatile__("stbcix %0,0,%1"
-		: : "r" (val), "r" (addr) : "memory");
-}
-
-static inline void _stwcix(u64 addr, u32 val)
-{
-	__asm__ __volatile__("stwcix %0,0,%1"
-		: : "r" (val), "r" (addr) : "memory");
-}
-
 /*
  * Low level IO stream instructions are defined out of line for now
  */
@@ -417,15 +372,64 @@ static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
 }
 
 /*
- * Real mode version of the above. stdcix is only supposed to be used
- * in hypervisor real mode as per the architecture spec.
+ * Real mode versions of the above. Those instructions are only supposed
+ * to be used in hypervisor real mode as per the architecture spec.
  */
+static inline void __raw_rm_writeb(u8 val, volatile void __iomem *paddr)
+{
+	__asm__ __volatile__("stbcix %0,0,%1"
+		: : "r" (val), "r" (paddr) : "memory");
+}
+
+static inline void __raw_rm_writew(u16 val, volatile void __iomem *paddr)
+{
+	__asm__ __volatile__("sthcix %0,0,%1"
+		: : "r" (val), "r" (paddr) : "memory");
+}
+
+static inline void __raw_rm_writel(u32 val, volatile void __iomem *paddr)
+{
+	__asm__ __volatile__("stwcix %0,0,%1"
+		: : "r" (val), "r" (paddr) : "memory");
+}
+
 static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
 {
 	__asm__ __volatile__("stdcix %0,0,%1"
 		: : "r" (val), "r" (paddr) : "memory");
 }
 
+static inline u8 __raw_rm_readb(volatile void __iomem *paddr)
+{
+	u8 ret;
+	__asm__ __volatile__("lbzcix %0,0, %1"
+			     : "=r" (ret) : "r" (paddr) : "memory");
+	return ret;
+}
+
+static inline u16 __raw_rm_readw(volatile void __iomem *paddr)
+{
+	u16 ret;
+	__asm__ __volatile__("lhzcix %0,0, %1"
+			     : "=r" (ret) : "r" (paddr) : "memory");
+	return ret;
+}
+
+static inline u32 __raw_rm_readl(volatile void __iomem *paddr)
+{
+	u32 ret;
+	__asm__ __volatile__("lwzcix %0,0, %1"
+			     : "=r" (ret) : "r" (paddr) : "memory");
+	return ret;
+}
+
+static inline u64 __raw_rm_readq(volatile void __iomem *paddr)
+{
+	u64 ret;
+	__asm__ __volatile__("ldcix %0,0, %1"
+			     : "=r" (ret) : "r" (paddr) : "memory");
+	return ret;
+}
 #endif /* __powerpc64__ */
 
 /*
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -1
index d318d43..0593d94 100644
@@ -110,7 +110,7 @@ struct kvmppc_host_state {
 	u8 ptid;
 	struct kvm_vcpu *kvm_vcpu;
 	struct kvmppc_vcore *kvm_vcore;
-	unsigned long xics_phys;
+	void __iomem *xics_phys;
 	u32 saved_xirr;
 	u64 dabr;
 	u64 host_mmcr[7];	/* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */
arch/powerpc/include/asm/kvm_ppc.h +1 -1
index 0c41865..c387799 100644
@@ -409,7 +409,7 @@ struct openpic;
 extern void kvm_cma_reserve(void) __init;
 static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
 {
-	paca[cpu].kvm_hstate.xics_phys = addr;
+	paca[cpu].kvm_hstate.xics_phys = (void __iomem *)addr;
 }
 
 static inline u32 kvmppc_get_xics_latch(void)
arch/powerpc/kvm/book3s_hv_builtin.c +8 -13
index ae55603..a752e29 100644
@@ -194,12 +194,6 @@ long kvmppc_h_random(struct kvm_vcpu *vcpu)
 	return H_HARDWARE;
 }
 
-static inline void rm_writeb(unsigned long paddr, u8 val)
-{
-	__asm__ __volatile__("stbcix %0,0,%1"
-		: : "r" (val), "r" (paddr) : "memory");
-}
-
 /*
  * Send an interrupt or message to another CPU.
  * The caller needs to include any barrier needed to order writes
@@ -207,7 +201,7 @@ static inline void rm_writeb(unsigned long paddr, u8 val)
  */
 void kvmhv_rm_send_ipi(int cpu)
 {
-	unsigned long xics_phys;
+	void __iomem *xics_phys;
 	unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
 
 	/* On POWER9 we can use msgsnd for any destination cpu. */
@@ -232,7 +226,7 @@ void kvmhv_rm_send_ipi(int cpu)
 	/* Else poke the target with an IPI */
 	xics_phys = paca[cpu].kvm_hstate.xics_phys;
 	if (xics_phys)
-		rm_writeb(xics_phys + XICS_MFRR, IPI_PRIORITY);
+		__raw_rm_writeb(IPI_PRIORITY, xics_phys + XICS_MFRR);
 	else
 		opal_int_set_mfrr(get_hard_smp_processor_id(cpu), IPI_PRIORITY);
 }
@@ -405,7 +399,7 @@ long kvmppc_read_intr(void)
 
 static long kvmppc_read_one_intr(bool *again)
 {
-	unsigned long xics_phys;
+	void __iomem *xics_phys;
 	u32 h_xirr;
 	__be32 xirr;
 	u32 xisr;
@@ -423,7 +417,7 @@ static long kvmppc_read_one_intr(bool *again)
 	if (!xics_phys)
 		rc = opal_int_get_xirr(&xirr, false);
 	else
-		xirr = _lwzcix(xics_phys + XICS_XIRR);
+		xirr = __raw_rm_readl(xics_phys + XICS_XIRR);
 	if (rc < 0)
 		return 1;
 
@@ -453,8 +447,8 @@ static long kvmppc_read_one_intr(bool *again)
 	if (xisr == XICS_IPI) {
 		rc = 0;
 		if (xics_phys) {
-			_stbcix(xics_phys + XICS_MFRR, 0xff);
-			_stwcix(xics_phys + XICS_XIRR, xirr);
+			__raw_rm_writeb(0xff, xics_phys + XICS_MFRR);
+			__raw_rm_writel(xirr, xics_phys + XICS_XIRR);
 		} else {
 			opal_int_set_mfrr(hard_smp_processor_id(), 0xff);
 			rc = opal_int_eoi(h_xirr);
@@ -479,7 +473,8 @@ static long kvmppc_read_one_intr(bool *again)
 			 * we need to resend that IPI, bummer
 			 */
 			if (xics_phys)
-				_stbcix(xics_phys + XICS_MFRR, IPI_PRIORITY);
+				__raw_rm_writeb(IPI_PRIORITY,
+						xics_phys + XICS_MFRR);
 			else
 				opal_int_set_mfrr(hard_smp_processor_id(),
 						  IPI_PRIORITY);
arch/powerpc/kvm/book3s_hv_rm_xics.c +2 -2
index e78542d..3a1a463 100644
@@ -766,7 +766,7 @@ unsigned long eoi_rc;
 
 static void icp_eoi(struct irq_chip *c, u32 hwirq, __be32 xirr, bool *again)
 {
-	unsigned long xics_phys;
+	void __iomem *xics_phys;
 	int64_t rc;
 
 	rc = pnv_opal_pci_msi_eoi(c, hwirq);
@@ -779,7 +779,7 @@ static void icp_eoi(struct irq_chip *c, u32 hwirq, __be32 xirr, bool *again)
 	/* EOI it */
 	xics_phys = local_paca->kvm_hstate.xics_phys;
 	if (xics_phys) {
-		_stwcix(xics_phys + XICS_XIRR, xirr);
+		__raw_rm_writel(xirr, xics_phys + XICS_XIRR);
 	} else {
 		rc = opal_int_eoi(be32_to_cpu(xirr));
 		*again = rc > 0;
arch/powerpc/platforms/powernv/rng.c +1 -1
index 5dcbdea..1a9d843 100644
@@ -62,7 +62,7 @@ int powernv_get_random_real_mode(unsigned long *v)
 
 	rng = raw_cpu_read(powernv_rng);
 
-	*v = rng_whiten(rng, in_rm64(rng->regs_real));
+	*v = rng_whiten(rng, __raw_rm_readq(rng->regs_real));
 
 	return 1;
 }
arch/powerpc/sysdev/xics/icp-native.c +4 -4
index 8a6a043..f0f3f47 100644
@@ -168,15 +168,15 @@ void icp_native_cause_ipi_rm(int cpu)
 	 * Need the physical address of the XICS to be
 	 * previously saved in kvm_hstate in the paca.
 	 */
-	unsigned long xics_phys;
+	void __iomem *xics_phys;
 
 	/*
 	 * Just like the cause_ipi functions, it is required to
-	 * include a full barrier (out8 includes a sync) before
-	 * causing the IPI.
+	 * include a full barrier before causing the IPI.
 	 */
 	xics_phys = paca[cpu].kvm_hstate.xics_phys;
-	out_rm8((u8 *)(xics_phys + XICS_MFRR), IPI_PRIORITY);
+	mb();
+	__raw_rm_writeb(IPI_PRIORITY, xics_phys + XICS_MFRR);
 }
 #endif
 
Signature · 1 line
2.9.3
#8 lore raw

PATCH v2 7/10 powerpc/kvm: Remove obsolete kvm_vm_ioctl_xics_irq declaration

In reply to Benjamin Herrenschmidt

The function doesn't exist anymore

---
 arch/powerpc/include/asm/kvm_ppc.h | 4 ----
 1 file changed, 4 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +0 -4
index bfef1ae..0c41865 100644
@@ -478,7 +478,6 @@ extern void kvmppc_free_host_rm_ops(void);
 extern void kvmppc_free_pimap(struct kvm *kvm);
 extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall);
 extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu);
-extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args);
 extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
 extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
 extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
@@ -506,9 +505,6 @@ static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall)
 static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
 	{ return 0; }
 static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { }
-static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm,
-					struct kvm_irq_level *args)
-	{ return -ENOTTY; }
 static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd)
 	{ return 0; }
 #endif
Signature · 1 line
2.9.3
#2 lore raw

PATCH v2 3/10 powerpc/smp: Remove migrate_irq() custom implementation

In reply to Benjamin Herrenschmidt

Some powerpc platforms use this to move IRQs away from a CPU being unplugged. This function has several bugs such as not taking the right locks or failing to NULL check pointers.

There's a new generic function doing exactly the same thing without all the bugs, so let's use it instead.

---
 arch/powerpc/Kconfig           |  1 +
 arch/powerpc/include/asm/smp.h |  1 -
 arch/powerpc/kernel/irq.c      | 40 ----------------------------------------
 arch/powerpc/kernel/smp.c      |  9 ++++++++-
 4 files changed, 9 insertions(+), 42 deletions(-)
arch/powerpc/Kconfig +1 -0
index 97a8bc8..29fb0e6 100644
@@ -431,6 +431,7 @@ config HOTPLUG_CPU
 	bool "Support for enabling/disabling CPUs"
 	depends on SMP && (PPC_PSERIES || \
 	PPC_PMAC || PPC_POWERNV || FSL_SOC_BOOKE)
+	select GENERIC_IRQ_MIGRATION
 	---help---
 	  Say Y here to be able to disable and re-enable individual
 	  CPUs at runtime on SMP machines.
arch/powerpc/include/asm/smp.h +0 -1
index 2f8e36f..63fa780 100644
@@ -62,7 +62,6 @@ extern void smp_generic_take_timebase(void);
 DECLARE_PER_CPU(unsigned int, cpu_pvr);
 
 #ifdef CONFIG_HOTPLUG_CPU
-extern void migrate_irqs(void);
 int generic_cpu_disable(void);
 void generic_cpu_die(unsigned int cpu);
 void generic_set_cpu_dead(unsigned int cpu);
arch/powerpc/kernel/irq.c +0 -40
index a018f5c..8ee7b44 100644
@@ -442,46 +442,6 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
 	return sum;
 }
 
-#ifdef CONFIG_HOTPLUG_CPU
-void migrate_irqs(void)
-{
-	struct irq_desc *desc;
-	unsigned int irq;
-	static int warned;
-	cpumask_var_t mask;
-	const struct cpumask *map = cpu_online_mask;
-
-	alloc_cpumask_var(&mask, GFP_KERNEL);
-
-	for_each_irq_desc(irq, desc) {
-		struct irq_data *data;
-		struct irq_chip *chip;
-
-		data = irq_desc_get_irq_data(desc);
-		if (irqd_is_per_cpu(data))
-			continue;
-
-		chip = irq_data_get_irq_chip(data);
-
-		cpumask_and(mask, irq_data_get_affinity_mask(data), map);
-		if (cpumask_any(mask) >= nr_cpu_ids) {
-			pr_warn("Breaking affinity for irq %i\n", irq);
-			cpumask_copy(mask, map);
-		}
-		if (chip->irq_set_affinity)
-			chip->irq_set_affinity(data, mask, true);
-		else if (desc->action && !(warned++))
-			pr_err("Cannot set affinity for irq %i\n", irq);
-	}
-
-	free_cpumask_var(mask);
-
-	local_irq_enable();
-	mdelay(1);
-	local_irq_disable();
-}
-#endif
-
 static inline void check_stack_overflow(void)
 {
 #ifdef CONFIG_DEBUG_STACKOVERFLOW
arch/powerpc/kernel/smp.c +8 -1
index b12f5f0..6e61cdb 100644
@@ -439,7 +439,14 @@ int generic_cpu_disable(void)
 #ifdef CONFIG_PPC64
 	vdso_data->processorCount--;
 #endif
-	migrate_irqs();
+	/* Update affinity of all IRQs previously aimed at this CPU */
+	irq_migrate_all_off_this_cpu();
+
+	/* Give the CPU time to drain in-flight ones */
+	local_irq_enable();
+	mdelay(1);
+	local_irq_disable();
+
 	return 0;
 }
 
Signature · 1 line
2.9.3
#11 lore raw

PATCH v2 10/10 powerpc/kvm: Native usage of the XIVE interrupt controller

In reply to Benjamin Herrenschmidt

This patch makes KVM capable of using the XIVE interrupt controller to provide the standard PAPR "XICS" style hypercalls. It is necessary for proper operations when the host uses XIVE natively.

This has been lightly tested on an actual system, including PCI pass-through with a TG3 device.

--
v2. Address review comments

# Conflicts:
# arch/powerpc/sysdev/xive/common.c
# arch/powerpc/sysdev/xive/native.c

# Conflicts:
# arch/powerpc/sysdev/xive/common.c

---
 arch/powerpc/include/asm/kvm_book3s_asm.h |    2 +
 arch/powerpc/include/asm/kvm_host.h       |   28 +-
 arch/powerpc/include/asm/kvm_ppc.h        |   48 +
 arch/powerpc/include/asm/xive.h           |    9 +-
 arch/powerpc/kernel/asm-offsets.c         |   10 +
 arch/powerpc/kvm/Makefile                 |    4 +-
 arch/powerpc/kvm/book3s.c                 |   73 +-
 arch/powerpc/kvm/book3s_hv.c              |   50 +-
 arch/powerpc/kvm/book3s_hv_builtin.c      |  101 ++
 arch/powerpc/kvm/book3s_hv_rm_xics.c      |   10 +-
 arch/powerpc/kvm/book3s_hv_rm_xive.c      |   47 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S   |   62 +-
 arch/powerpc/kvm/book3s_rtas.c            |   21 +-
 arch/powerpc/kvm/book3s_xics.c            |   35 +-
 arch/powerpc/kvm/book3s_xics.h            |    5 +
 arch/powerpc/kvm/book3s_xive.c            | 1898 +++++++++++++++++++++++++++++
 arch/powerpc/kvm/book3s_xive.h            |  251 ++++
 arch/powerpc/kvm/book3s_xive_template.c   |  498 ++++++++
 arch/powerpc/kvm/irq.h                    |    1 +
 arch/powerpc/kvm/powerpc.c                |   17 +-
 arch/powerpc/platforms/powernv/opal.c     |    1 +
 arch/powerpc/sysdev/xive/common.c         |  142 ++-
 arch/powerpc/sysdev/xive/native.c         |   85 +-
 include/linux/kvm_host.h                  |    1 -
 virt/kvm/kvm_main.c                       |    4 -
 25 files changed, 3313 insertions(+), 90 deletions(-)
 create mode 100644 arch/powerpc/kvm/book3s_hv_rm_xive.c
 create mode 100644 arch/powerpc/kvm/book3s_xive.c
 create mode 100644 arch/powerpc/kvm/book3s_xive.h
 create mode 100644 arch/powerpc/kvm/book3s_xive_template.c
arch/powerpc/include/asm/kvm_book3s_asm.h +2 -0
index 0593d94..b148496 100644
@@ -111,6 +111,8 @@ struct kvmppc_host_state {
 	struct kvm_vcpu *kvm_vcpu;
 	struct kvmppc_vcore *kvm_vcore;
 	void __iomem *xics_phys;
+	void __iomem *xive_tima_phys;
+	void __iomem *xive_tima_virt;
 	u32 saved_xirr;
 	u64 dabr;
 	u64 host_mmcr[7];	/* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */
arch/powerpc/include/asm/kvm_host.h +27 -1
index 7bba8f4..5a8ab4a 100644
@@ -205,6 +205,12 @@ struct kvmppc_spapr_tce_table {
 /* XICS components, defined in book3s_xics.c */
 struct kvmppc_xics;
 struct kvmppc_icp;
+extern struct kvm_device_ops kvm_xics_ops;
+
+/* XIVE components, defined in book3s_xive.c */
+struct kvmppc_xive;
+struct kvmppc_xive_vcpu;
+extern struct kvm_device_ops kvm_xive_ops;
 
 struct kvmppc_passthru_irqmap;
 
@@ -293,6 +299,7 @@ struct kvm_arch {
 #endif
 #ifdef CONFIG_KVM_XICS
 	struct kvmppc_xics *xics;
+	struct kvmppc_xive *xive;
 	struct kvmppc_passthru_irqmap *pimap;
 #endif
 	struct kvmppc_ops *kvm_ops;
@@ -421,7 +428,7 @@ struct kvmppc_passthru_irqmap {
 
 #define KVMPPC_IRQ_DEFAULT	0
 #define KVMPPC_IRQ_MPIC		1
-#define KVMPPC_IRQ_XICS		2
+#define KVMPPC_IRQ_XICS		2 /* Includes a XIVE option */
 
 #define MMIO_HPTE_CACHE_SIZE	4
 
@@ -443,6 +450,21 @@ struct mmio_hpte_cache {
 
 struct openpic;
 
+/* W0 and W1 of a XIVE thread management context */
+union xive_tma_w01 {
+	struct {
+		u8	nsr;
+		u8	cppr;
+		u8	ipb;
+		u8	lsmfb;
+		u8	ack;
+		u8	inc;
+		u8	age;
+		u8	pipr;
+	};
+	__be64 w01;
+};
+
 struct kvm_vcpu_arch {
 	ulong host_stack;
 	u32 host_pid;
@@ -688,6 +710,10 @@ struct kvm_vcpu_arch {
 	struct openpic *mpic;	/* KVM_IRQ_MPIC */
 #ifdef CONFIG_KVM_XICS
 	struct kvmppc_icp *icp; /* XICS presentation controller */
+	struct kvmppc_xive_vcpu *xive_vcpu; /* XIVE virtual CPU data */
+	__be32 xive_cam_word;    /* Cooked W2 in proper endian with valid bit */
+	u32 xive_pushed;	 /* Is the VP pushed on the physical CPU ? */
+	union xive_tma_w01 xive_saved_state; /* W0..1 of XIVE thread state */
 #endif
 
 #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
arch/powerpc/include/asm/kvm_ppc.h +48 -0

84 lines not on this page · raw message

arch/powerpc/include/asm/xive.h +4 -5
index 53755e1..b2b6537 100644
@@ -99,7 +99,6 @@ struct xive_q {
 #define XIVE_ESB_SET_PQ_01	0xd00
 #define XIVE_ESB_SET_PQ_10	0xe00
 #define XIVE_ESB_SET_PQ_11	0xf00
-#define XIVE_ESB_MASK		XIVE_ESB_SET_PQ_01
 
 #define XIVE_ESB_VAL_P		0x2
 #define XIVE_ESB_VAL_Q		0x1
@@ -136,11 +135,11 @@ extern int xive_native_configure_queue(u32 vp_id, struct xive_q *q, u8 prio,
 				       __be32 *qpage, u32 order, bool can_escalate);
 extern void xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio);
 
-extern bool __xive_irq_trigger(struct xive_irq_data *xd);
-extern bool __xive_irq_retrigger(struct xive_irq_data *xd);
-extern void xive_do_source_eoi(u32 hw_irq, struct xive_irq_data *xd);
-
+extern void xive_native_sync_source(u32 hw_irq);
 extern bool is_xive_irq(struct irq_chip *chip);
+extern int xive_native_enable_vp(u32 vp_id);
+extern int xive_native_disable_vp(u32 vp_id);
+extern int xive_native_get_vp_info(u32 vp_id, u32 *out_cam_id, u32 *out_chip_id);
 
 #else
 
arch/powerpc/kernel/asm-offsets.c +10 -0
index 4367e7d..18221878 100644
@@ -630,6 +630,8 @@ int main(void)
 	HSTATE_FIELD(HSTATE_KVM_VCPU, kvm_vcpu);
 	HSTATE_FIELD(HSTATE_KVM_VCORE, kvm_vcore);
 	HSTATE_FIELD(HSTATE_XICS_PHYS, xics_phys);
+	HSTATE_FIELD(HSTATE_XIVE_TIMA_PHYS, xive_tima_phys);
+	HSTATE_FIELD(HSTATE_XIVE_TIMA_VIRT, xive_tima_virt);
 	HSTATE_FIELD(HSTATE_SAVED_XIRR, saved_xirr);
 	HSTATE_FIELD(HSTATE_HOST_IPI, host_ipi);
 	HSTATE_FIELD(HSTATE_PTID, ptid);
@@ -715,6 +717,14 @@ int main(void)
 	OFFSET(VCPU_HOST_MAS6, kvm_vcpu, arch.host_mas6);
 #endif
 
+#ifdef CONFIG_KVM_XICS
+	DEFINE(VCPU_XIVE_SAVED_STATE, offsetof(struct kvm_vcpu,
+					       arch.xive_saved_state));
+	DEFINE(VCPU_XIVE_CAM_WORD, offsetof(struct kvm_vcpu,
+					    arch.xive_cam_word));
+	DEFINE(VCPU_XIVE_PUSHED, offsetof(struct kvm_vcpu, arch.xive_pushed));
+#endif
+
 #ifdef CONFIG_KVM_EXIT_TIMING
 	OFFSET(VCPU_TIMING_EXIT_TBU, kvm_vcpu, arch.timing_exit.tv32.tbu);
 	OFFSET(VCPU_TIMING_EXIT_TBL, kvm_vcpu, arch.timing_exit.tv32.tbl);
arch/powerpc/kvm/Makefile +2 -2
index b87ccde..ef89c8c 100644
@@ -74,7 +74,7 @@ kvm-hv-y += \
 	book3s_64_mmu_radix.o
 
 kvm-book3s_64-builtin-xics-objs-$(CONFIG_KVM_XICS) := \
-	book3s_hv_rm_xics.o
+	book3s_hv_rm_xics.o book3s_hv_rm_xive.o
 
 ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
 kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \
@@ -87,7 +87,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \
 endif
 
 kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \
-	book3s_xics.o
+	book3s_xics.o book3s_xive.o
 
 kvm-book3s_64-module-objs := \
 	$(common-objs-y) \
arch/powerpc/kvm/book3s.c +67 -6

114 lines not on this page · raw message

arch/powerpc/kvm/book3s_hv.c +38 -12

122 lines not on this page · raw message

arch/powerpc/kvm/book3s_hv_builtin.c +101 -0

122 lines not on this page · raw message

arch/powerpc/kvm/book3s_hv_rm_xics.c +5 -5
index 3a1a463..f806880 100644
@@ -485,7 +485,7 @@ static void icp_rm_down_cppr(struct kvmppc_xics *xics, struct kvmppc_icp *icp,
 }
 
 
-unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu)
+unsigned long xics_rm_h_xirr(struct kvm_vcpu *vcpu)
 {
 	union kvmppc_icp_state old_state, new_state;
 	struct kvmppc_xics *xics = vcpu->kvm->arch.xics;
@@ -523,8 +523,8 @@ unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu)
 	return check_too_hard(xics, icp);
 }
 
-int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
-		    unsigned long mfrr)
+int xics_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
+		  unsigned long mfrr)
 {
 	union kvmppc_icp_state old_state, new_state;
 	struct kvmppc_xics *xics = vcpu->kvm->arch.xics;
@@ -610,7 +610,7 @@ int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
 	return check_too_hard(xics, this_icp);
 }
 
-int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr)
+int xics_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr)
 {
 	union kvmppc_icp_state old_state, new_state;
 	struct kvmppc_xics *xics = vcpu->kvm->arch.xics;
@@ -730,7 +730,7 @@ static int ics_rm_eoi(struct kvm_vcpu *vcpu, u32 irq)
 	return check_too_hard(xics, icp);
 }
 
-int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr)
+int xics_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr)
 {
 	struct kvmppc_xics *xics = vcpu->kvm->arch.xics;
 	struct kvmppc_icp *icp = vcpu->arch.icp;
arch/powerpc/kvm/book3s_hv_rm_xive.c new file +47 -0

47 lines not on this page · raw message

arch/powerpc/kvm/book3s_hv_rmhandlers.S +60 -2

92 lines not on this page · raw message

arch/powerpc/kvm/book3s_rtas.c +17 -4
index 20528701..2d3b2b1 100644
@@ -16,6 +16,7 @@
 #include <asm/kvm_ppc.h>
 #include <asm/hvcall.h>
 #include <asm/rtas.h>
+#include <asm/xive.h>
 
 #ifdef CONFIG_KVM_XICS
 static void kvm_rtas_set_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
@@ -32,7 +33,10 @@ static void kvm_rtas_set_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
 	server = be32_to_cpu(args->args[1]);
 	priority = be32_to_cpu(args->args[2]);
 
-	rc = kvmppc_xics_set_xive(vcpu->kvm, irq, server, priority);
+	if (xive_enabled())
+		rc = kvmppc_xive_set_xive(vcpu->kvm, irq, server, priority);
+	else
+		rc = kvmppc_xics_set_xive(vcpu->kvm, irq, server, priority);
 	if (rc)
 		rc = -3;
 out:
@@ -52,7 +56,10 @@ static void kvm_rtas_get_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
 	irq = be32_to_cpu(args->args[0]);
 
 	server = priority = 0;
-	rc = kvmppc_xics_get_xive(vcpu->kvm, irq, &server, &priority);
+	if (xive_enabled())
+		rc = kvmppc_xive_get_xive(vcpu->kvm, irq, &server, &priority);
+	else
+		rc = kvmppc_xics_get_xive(vcpu->kvm, irq, &server, &priority);
 	if (rc) {
 		rc = -3;
 		goto out;
@@ -76,7 +83,10 @@ static void kvm_rtas_int_off(struct kvm_vcpu *vcpu, struct rtas_args *args)
 
 	irq = be32_to_cpu(args->args[0]);
 
-	rc = kvmppc_xics_int_off(vcpu->kvm, irq);
+	if (xive_enabled())
+		rc = kvmppc_xive_int_off(vcpu->kvm, irq);
+	else
+		rc = kvmppc_xics_int_off(vcpu->kvm, irq);
 	if (rc)
 		rc = -3;
 out:
@@ -95,7 +105,10 @@ static void kvm_rtas_int_on(struct kvm_vcpu *vcpu, struct rtas_args *args)
 
 	irq = be32_to_cpu(args->args[0]);
 
-	rc = kvmppc_xics_int_on(vcpu->kvm, irq);
+	if (xive_enabled())
+		rc = kvmppc_xive_int_on(vcpu->kvm, irq);
+	else
+		rc = kvmppc_xics_int_on(vcpu->kvm, irq);
 	if (rc)
 		rc = -3;
 out:
arch/powerpc/kvm/book3s_xics.c +2 -33
index ef4fd52..e6829c4 100644
@@ -1307,8 +1307,8 @@ static int xics_set_source(struct kvmppc_xics *xics, long irq, u64 addr)
 	return 0;
 }
 
-int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
-		bool line_status)
+int kvmppc_xics_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
+			bool line_status)
 {
 	struct kvmppc_xics *xics = kvm->arch.xics;
 
@@ -1317,14 +1317,6 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level,
 	return ics_deliver_irq(xics, irq, level);
 }
 
-int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *irq_entry,
-			      struct kvm *kvm, int irq_source_id,
-			      int level, bool line_status)
-{
-	return kvm_set_irq(kvm, irq_source_id, irq_entry->gsi,
-			   level, line_status);
-}
-
 static int xics_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
 {
 	struct kvmppc_xics *xics = dev->private;
@@ -1458,29 +1450,6 @@ void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu)
 	vcpu->arch.irq_type = KVMPPC_IRQ_DEFAULT;
 }
 
-static int xics_set_irq(struct kvm_kernel_irq_routing_entry *e,
-			struct kvm *kvm, int irq_source_id, int level,
-			bool line_status)
-{
-	return kvm_set_irq(kvm, irq_source_id, e->gsi, level, line_status);
-}
-
-int kvm_irq_map_gsi(struct kvm *kvm,
-		    struct kvm_kernel_irq_routing_entry *entries, int gsi)
-{
-	entries->gsi = gsi;
-	entries->type = KVM_IRQ_ROUTING_IRQCHIP;
-	entries->set = xics_set_irq;
-	entries->irqchip.irqchip = 0;
-	entries->irqchip.pin = gsi;
-	return 1;
-}
-
-int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin)
-{
-	return pin;
-}
-
 void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long irq,
 			    unsigned long host_irq)
 {
arch/powerpc/kvm/book3s_xics.h +5 -0
index ec5474c..5016676 100644
@@ -144,5 +144,10 @@ static inline struct kvmppc_ics *kvmppc_xics_find_ics(struct kvmppc_xics *xics,
 	return ics;
 }
 
+extern unsigned long xics_rm_h_xirr(struct kvm_vcpu *vcpu);
+extern int xics_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
+			 unsigned long mfrr);
+extern int xics_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr);
+extern int xics_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr);
 
 #endif /* _KVM_PPC_BOOK3S_XICS_H */
arch/powerpc/kvm/book3s_xive.c new file +1898 -0

1,898 lines not on this page · raw message

arch/powerpc/kvm/book3s_xive.h new file +251 -0

247 lines not on this page · raw message

arch/powerpc/kvm/book3s_xive_template.c new file +498 -0

498 lines not on this page · raw message

arch/powerpc/kvm/irq.h +1 -0
index 5a9a10b..3f1be85 100644

Lines of this file are not shown. View the raw message.

arch/powerpc/kvm/powerpc.c +13 -4
index 95c91a9..de79bd72 100644

Lines of this file are not shown. View the raw message.

arch/powerpc/platforms/powernv/opal.c +1 -0
index e0f856b..d71cd77 100644

Lines of this file are not shown. View the raw message.

arch/powerpc/sysdev/xive/common.c +136 -6

142 lines not on this page · raw message

arch/powerpc/sysdev/xive/native.c +80 -5

85 lines not on this page · raw message

include/linux/kvm_host.h +0 -1
index d025074..ea501ed 100644

Lines of this file are not shown. View the raw message.

virt/kvm/kvm_main.c +0 -4
index 88257b3..914459c 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.9.3

Part of the diff is not shown here. View the raw message.

#3 lore raw

PATCH v2 4/10 powerpc/xive: Native exploitation of the XIVE interrupt controller

In reply to Benjamin Herrenschmidt

The XIVE interrupt controller is the new interrupt controller found in POWER9. It supports advanced virtualization capabilities among other things.

Currently we use a set of firmware calls that simulate the old "XICS" interrupt controller but this is fairly inefficient.

This adds the framework for using XIVE along with a native backend which OPAL for configuration. Later, a backend allowing the use in a KVM or PowerVM guest will also be provided.

This disables some fast path for interrupts in KVM when XIVE is enabled as these rely on the firmware emulation code which is no longer available when the XIVE is used natively by Linux.

A latter patch will make KVM also directly exploit the XIVE, thus recovering the lost performance (and more).

--

v2: - Add comments, rename a few things, move some around, based
on review comments
- Fix mask/unmask to avoid potential queue overflows by storing the P bit away and restoring it.
- Replace various BUG_ON's with WARN_ON's

---
 arch/powerpc/include/asm/xive-regs.h     |   96 +++
 arch/powerpc/include/asm/xive.h          |  164 ++++
 arch/powerpc/include/asm/xmon.h          |    2 +
 arch/powerpc/kvm/book3s_hv_builtin.c     |    8 +
 arch/powerpc/platforms/powernv/Kconfig   |    2 +
 arch/powerpc/platforms/powernv/setup.c   |   15 +-
 arch/powerpc/platforms/powernv/smp.c     |   39 +-
 arch/powerpc/sysdev/Kconfig              |    1 +
 arch/powerpc/sysdev/Makefile             |    1 +
 arch/powerpc/sysdev/xive/Kconfig         |    7 +
 arch/powerpc/sysdev/xive/Makefile        |    4 +
 arch/powerpc/sysdev/xive/common.c        | 1276 ++++++++++++++++++++++++++++++
 arch/powerpc/sysdev/xive/native.c        |  643 +++++++++++++++
 arch/powerpc/sysdev/xive/xive-internal.h |   61 ++
 arch/powerpc/xmon/xmon.c                 |   93 ++-
 15 files changed, 2400 insertions(+), 12 deletions(-)
 create mode 100644 arch/powerpc/include/asm/xive-regs.h
 create mode 100644 arch/powerpc/include/asm/xive.h
 create mode 100644 arch/powerpc/sysdev/xive/Kconfig
 create mode 100644 arch/powerpc/sysdev/xive/Makefile
 create mode 100644 arch/powerpc/sysdev/xive/common.c
 create mode 100644 arch/powerpc/sysdev/xive/native.c
 create mode 100644 arch/powerpc/sysdev/xive/xive-internal.h
arch/powerpc/include/asm/xive-regs.h new file +96 -0
new file mode 100644
index 0000000..3dbaf41
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016,2017 IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+#ifndef __XIVE_REGS_H__
+#define __XIVE_REGS_H__
+
+/*
+ * Thread Management (aka "TM") registers
+ */
+
+/* TM register offsets */
+#define TM_QW0_USER		0x000 /* All rings */
+#define TM_QW1_OS		0x010 /* Ring 0..2 */
+#define TM_QW2_HV_POOL		0x020 /* Ring 0..1 */
+#define TM_QW3_HV_PHYS		0x030 /* Ring 0..1 */
+
+/* Byte offsets inside a QW             QW0 QW1 QW2 QW3 */
+#define TM_NSR			0x0  /*  +   +   -   +  */
+#define TM_CPPR			0x1  /*  -   +   -   +  */
+#define TM_IPB			0x2  /*  -   +   +   +  */
+#define TM_LSMFB		0x3  /*  -   +   +   +  */
+#define TM_ACK_CNT		0x4  /*  -   +   -   -  */
+#define TM_INC			0x5  /*  -   +   -   +  */
+#define TM_AGE			0x6  /*  -   +   -   +  */
+#define TM_PIPR			0x7  /*  -   +   -   +  */
+
+#define TM_WORD0		0x0
+#define TM_WORD1		0x4
+
+/* QW word 2 contains the valid bit at the top and other fields
+ * depending on the QW
+ */
+#define TM_WORD2		0x8
+#define   TM_QW0W2_VU		PPC_BIT32(0)
+#define   TM_QW0W2_LOGIC_SERV	PPC_BITMASK32(1,31) // XX 2,31 ?
+#define   TM_QW1W2_VO		PPC_BIT32(0)
+#define   TM_QW1W2_OS_CAM	PPC_BITMASK32(8,31)
+#define   TM_QW2W2_VP		PPC_BIT32(0)
+#define   TM_QW2W2_POOL_CAM	PPC_BITMASK32(8,31)
+#define   TM_QW3W2_VT		PPC_BIT32(0)
+#define   TM_QW3W2_LP		PPC_BIT32(6)
+#define   TM_QW3W2_LE		PPC_BIT32(7)
+#define   TM_QW3W2_T		PPC_BIT32(31)
+
+/* In addition to normal loads to "peek" and writes (only when invalid)
+ * using 4 and 8 bytes accesses, the above registers support these
+ * "special" byte operations:
+ *
+ *   - Byte load from QW0[NSR] - User level NSR (EBB)
+ *   - Byte store to QW0[NSR] - User level NSR (EBB)
+ *   - Byte load/store to QW1[CPPR] and QW3[CPPR] - CPPR access
+ *   - Byte load from QW3[TM_WORD2] - Read VT||00000||LP||LE on thrd 0
+ *                                    otherwise VT||0000000
+ *   - Byte store to QW3[TM_WORD2] - Set VT bit (and LP/LE if present)
+ *
+ * Then we have all these "special" CI ops at these offset that trigger
+ * all sorts of side effects:
+ */
+#define TM_SPC_ACK_EBB		0x800	/* Load8 ack EBB to reg*/
+#define TM_SPC_ACK_OS_REG	0x810	/* Load16 ack OS irq to reg */
+#define TM_SPC_PUSH_USR_CTX	0x808	/* Store32 Push/Validate user context */
+#define TM_SPC_PULL_USR_CTX	0x808	/* Load32 Pull/Invalidate user context */
+#define TM_SPC_SET_OS_PENDING	0x812	/* Store8 Set OS irq pending bit */
+#define TM_SPC_PULL_OS_CTX	0x818	/* Load32/Load64 Pull/Invalidate OS context to reg */
+#define TM_SPC_PULL_POOL_CTX	0x828	/* Load32/Load64 Pull/Invalidate Pool context to reg*/
+#define TM_SPC_ACK_HV_REG	0x830	/* Load16 ack HV irq to reg */
+#define TM_SPC_PULL_USR_CTX_OL	0xc08	/* Store8 Pull/Inval usr ctx to odd line */
+#define TM_SPC_ACK_OS_EL	0xc10	/* Store8 ack OS irq to even line */
+#define TM_SPC_ACK_HV_POOL_EL	0xc20	/* Store8 ack HV evt pool to even line */
+#define TM_SPC_ACK_HV_EL	0xc30	/* Store8 ack HV irq to even line */
+/* XXX more... */
+
+/* NSR fields for the various QW ack types */
+#define TM_QW0_NSR_EB		PPC_BIT8(0)
+#define TM_QW1_NSR_EO		PPC_BIT8(0)
+#define TM_QW3_NSR_HE		PPC_BITMASK8(0,1)
+#define  TM_QW3_NSR_HE_NONE	0
+#define  TM_QW3_NSR_HE_POOL	1
+#define  TM_QW3_NSR_HE_PHYS	2
+#define  TM_QW3_NSR_HE_LSI	3
+#define TM_QW3_NSR_I		PPC_BIT8(2)
+#define TM_QW3_NSR_GRP_LVL	PPC_BIT8(3,7)
+
+/* Utilities to manipulate these (originaly from OPAL) */
+#define MASK_TO_LSH(m)		(__builtin_ffsl(m) - 1)
+#define GETFIELD(m, v)		(((v) & (m)) >> MASK_TO_LSH(m))
+#define SETFIELD(m, v, val)				\
+	(((v) & ~(m)) |	((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m)))
+
+
+#endif /* __XIVE_H__ */
arch/powerpc/include/asm/xive.h new file +164 -0

164 lines not on this page · raw message

arch/powerpc/include/asm/xmon.h +2 -0
index 5eb8e59..eb42a0c 100644
@@ -29,5 +29,7 @@ static inline void xmon_register_spus(struct list_head *list) { };
 extern int cpus_are_in_xmon(void);
 #endif
 
+extern void xmon_printf(const char *format, ...);
+
 #endif /* __KERNEL __ */
 #endif /* __ASM_POWERPC_XMON_H */
arch/powerpc/kvm/book3s_hv_builtin.c +8 -0
index 4d6c64b..ae55603 100644
@@ -23,6 +23,7 @@
 #include <asm/kvm_book3s.h>
 #include <asm/archrandom.h>
 #include <asm/xics.h>
+#include <asm/xive.h>
 #include <asm/dbell.h>
 #include <asm/cputhreads.h>
 #include <asm/io.h>
@@ -224,6 +225,10 @@ void kvmhv_rm_send_ipi(int cpu)
 		return;
 	}
 
+	/* We should never reach this */
+	if (WARN_ON_ONCE(xive_enabled()))
+	    return;
+
 	/* Else poke the target with an IPI */
 	xics_phys = paca[cpu].kvm_hstate.xics_phys;
 	if (xics_phys)
@@ -386,6 +391,9 @@ long kvmppc_read_intr(void)
 	long rc;
 	bool again;
 
+	if (xive_enabled())
+		return 1;
+
 	do {
 		again = false;
 		rc = kvmppc_read_one_intr(&again);
arch/powerpc/platforms/powernv/Kconfig +2 -0
index 3a07e4d..81ee2ed 100644
@@ -4,6 +4,8 @@ config PPC_POWERNV
 	select PPC_NATIVE
 	select PPC_XICS
 	select PPC_ICP_NATIVE
+	select PPC_XIVE
+	select PPC_XIVE_NATIVE
 	select PPC_P7_NAP
 	select PCI
 	select PCI_MSI
arch/powerpc/platforms/powernv/setup.c +12 -3
index d50c7d9..adceac9 100644
@@ -32,6 +32,7 @@
 #include <asm/machdep.h>
 #include <asm/firmware.h>
 #include <asm/xics.h>
+#include <asm/xive.h>
 #include <asm/opal.h>
 #include <asm/kexec.h>
 #include <asm/smp.h>
@@ -76,7 +77,9 @@ static void __init pnv_init(void)
 
 static void __init pnv_init_IRQ(void)
 {
-	xics_init();
+	/* Try using a XIVE if available, otherwise use a XICS */
+	if (!xive_native_init())
+		xics_init();
 
 	WARN_ON(!ppc_md.get_irq);
 }
@@ -218,10 +221,12 @@ static void pnv_kexec_wait_secondaries_down(void)
 
 static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
 {
-	xics_kexec_teardown_cpu(secondary);
+	if (xive_enabled())
+		xive_kexec_teardown_cpu(secondary);
+	else
+		xics_kexec_teardown_cpu(secondary);
 
 	/* On OPAL, we return all CPUs to firmware */
-
 	if (!firmware_has_feature(FW_FEATURE_OPAL))
 		return;
 
@@ -237,6 +242,10 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)
 		/* Primary waits for the secondaries to have reached OPAL */
 		pnv_kexec_wait_secondaries_down();
 
+		/* Switch XIVE back to emulation mode */
+		if (xive_enabled())
+			xive_shutdown();
+
 		/*
 		 * We might be running as little-endian - now that interrupts
 		 * are disabled, reset the HILE bit to big-endian so we don't
arch/powerpc/platforms/powernv/smp.c +32 -7
index 8b67e1e..f571955 100644
@@ -29,6 +29,7 @@
 #include <asm/vdso_datapage.h>
 #include <asm/cputhreads.h>
 #include <asm/xics.h>
+#include <asm/xive.h>
 #include <asm/opal.h>
 #include <asm/runlatch.h>
 #include <asm/code-patching.h>
@@ -47,7 +48,9 @@
 
 static void pnv_smp_setup_cpu(int cpu)
 {
-	if (cpu != boot_cpuid)
+	if (xive_enabled())
+		xive_smp_setup_cpu();
+	else if (cpu != boot_cpuid)
 		xics_setup_cpu();
 
 #ifdef CONFIG_PPC_DOORBELL
@@ -132,7 +135,10 @@ static int pnv_smp_cpu_disable(void)
 	vdso_data->processorCount--;
 	if (cpu == boot_cpuid)
 		boot_cpuid = cpumask_any(cpu_online_mask);
-	xics_migrate_irqs_away();
+	if (xive_enabled())
+		xive_smp_disable_cpu();
+	else
+		xics_migrate_irqs_away();
 	return 0;
 }
 
@@ -213,9 +219,12 @@ static void pnv_smp_cpu_kill_self(void)
 		if (((srr1 & wmask) == SRR1_WAKEEE) ||
 		    ((srr1 & wmask) == SRR1_WAKEHVI) ||
 		    (local_paca->irq_happened & PACA_IRQ_EE)) {
-			if (cpu_has_feature(CPU_FTR_ARCH_300))
-				icp_opal_flush_interrupt();
-			else
+			if (cpu_has_feature(CPU_FTR_ARCH_300)) {
+				if (xive_enabled())
+					xive_flush_interrupt();
+				else
+					icp_opal_flush_interrupt();
+			} else
 				icp_native_flush_interrupt();
 		} else if ((srr1 & wmask) == SRR1_WAKEHDBELL) {
 			unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
@@ -252,10 +261,26 @@ static int pnv_cpu_bootable(unsigned int nr)
 	return smp_generic_cpu_bootable(nr);
 }
 
+static int pnv_smp_prepare_cpu(int cpu)
+{
+	if (xive_enabled())
+		return xive_smp_prepare_cpu(cpu);
+	return 0;
+}
+
+static void __init pnv_smp_probe(void)
+{
+	if (xive_enabled())
+		xive_smp_probe();
+	else
+		xics_smp_probe();
+}
+
 static struct smp_ops_t pnv_smp_ops = {
 	.message_pass	= smp_muxed_ipi_message_pass,
-	.cause_ipi	= NULL,	/* Filled at runtime by xics_smp_probe() */
-	.probe		= xics_smp_probe,
+	.cause_ipi	= NULL, /* Filled at runtime by xi{cs,ve}_smp_probe() */
+	.probe		= pnv_smp_probe,
+	.prepare_cpu	= pnv_smp_prepare_cpu,
 	.kick_cpu	= pnv_smp_kick_cpu,
 	.setup_cpu	= pnv_smp_setup_cpu,
 	.cpu_bootable	= pnv_cpu_bootable,
arch/powerpc/sysdev/Kconfig +1 -0
index 52dc165..caf882e 100644
@@ -28,6 +28,7 @@ config PPC_MSI_BITMAP
 	default y if PPC_POWERNV
 
 source "arch/powerpc/sysdev/xics/Kconfig"
+source "arch/powerpc/sysdev/xive/Kconfig"
 
 config PPC_SCOM
 	bool
arch/powerpc/sysdev/Makefile +1 -0
index a254824..c0ae11d 100644
@@ -71,5 +71,6 @@ obj-$(CONFIG_PPC_EARLY_DEBUG_MEMCONS)	+= udbg_memcons.o
 subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror
 
 obj-$(CONFIG_PPC_XICS)		+= xics/
+obj-$(CONFIG_PPC_XIVE)		+= xive/
 
 obj-$(CONFIG_GE_FPGA)		+= ge/
arch/powerpc/sysdev/xive/Kconfig new file +7 -0
new file mode 100644
index 0000000..c8816c8
@@ -0,0 +1,7 @@
+config PPC_XIVE
+       def_bool n
+       select PPC_SMP_MUXED_IPI
+       select HARDIRQS_SW_RESEND
+
+config PPC_XIVE_NATIVE
+       def_bool n
arch/powerpc/sysdev/xive/Makefile new file +4 -0
new file mode 100644
index 0000000..3fab303
@@ -0,0 +1,4 @@
+subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror
+
+obj-y				+= common.o
+obj-$(CONFIG_PPC_XIVE_NATIVE)	+= native.o
arch/powerpc/sysdev/xive/common.c new file +1276 -0

1,276 lines not on this page · raw message

arch/powerpc/sysdev/xive/native.c new file +643 -0

643 lines not on this page · raw message

arch/powerpc/sysdev/xive/xive-internal.h new file +61 -0

61 lines not on this page · raw message

arch/powerpc/xmon/xmon.c +91 -2

117 lines not on this page · raw message

Signature · 1 line
2.9.3
#4 lore raw

Re: [PATCH v2 04/10] powerpc/xive: Native exploitation of the XIVE interrupt controller

reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Benjamin,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.11-rc5 next-20170405]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Benjamin-Herrenschmidt/powerpc-Add-more-PPC-bit-conversion-macros/20170406-041935
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc

All errors (new ones prefixed by >>):

arch/powerpc/sysdev/xive/native.c: In function 'xive_native_populate_irq_data':

>> arch/powerpc/sysdev/xive/native.c:55:7: error: implicit declaration of function 'opal_xive_get_irq_info' [-Werror=implicit-function-declaration]
     rc = opal_xive_get_irq_info(hw_irq, &flags, &eoi_page, &trig_page,
          ^~~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:64:19: error: 'OPAL_XIVE_IRQ_STORE_EOI' undeclared (first use in this function)
     if (opal_flags & OPAL_XIVE_IRQ_STORE_EOI)
                      ^~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c:64:19: note: each undeclared identifier is reported only once for each function it appears in
>> arch/powerpc/sysdev/xive/native.c:66:19: error: 'OPAL_XIVE_IRQ_LSI' undeclared (first use in this function)
     if (opal_flags & OPAL_XIVE_IRQ_LSI)
                      ^~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:68:19: error: 'OPAL_XIVE_IRQ_SHIFT_BUG' undeclared (first use in this function)
     if (opal_flags & OPAL_XIVE_IRQ_SHIFT_BUG)
                      ^~~~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:70:19: error: 'OPAL_XIVE_IRQ_MASK_VIA_FW' undeclared (first use in this function)
     if (opal_flags & OPAL_XIVE_IRQ_MASK_VIA_FW)
                      ^~~~~~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:72:19: error: 'OPAL_XIVE_IRQ_EOI_VIA_FW' undeclared (first use in this function)
     if (opal_flags & OPAL_XIVE_IRQ_EOI_VIA_FW)
                      ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_configure_irq':
>> arch/powerpc/sysdev/xive/native.c:105:8: error: implicit declaration of function 'opal_xive_set_irq_config' [-Werror=implicit-function-declaration]
      rc = opal_xive_set_irq_config(hw_irq, target, prio, sw_irq);
           ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_configure_queue':
>> arch/powerpc/sysdev/xive/native.c:135:7: error: implicit declaration of function 'opal_xive_get_queue_info' [-Werror=implicit-function-declaration]
     rc = opal_xive_get_queue_info(vp_id, prio, NULL, NULL,
          ^~~~~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:148:10: error: 'OPAL_XIVE_EQ_ALWAYS_NOTIFY' undeclared (first use in this function)
     flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY | OPAL_XIVE_EQ_ENABLED;
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:148:39: error: 'OPAL_XIVE_EQ_ENABLED' undeclared (first use in this function)
     flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY | OPAL_XIVE_EQ_ENABLED;
                                          ^~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:153:12: error: 'OPAL_XIVE_EQ_ESCALATE' undeclared (first use in this function)
      flags |= OPAL_XIVE_EQ_ESCALATE;
               ^~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:158:8: error: implicit declaration of function 'opal_xive_set_queue_info' [-Werror=implicit-function-declaration]
      rc = opal_xive_set_queue_info(vp_id, prio, qpage_phys, order, flags);
           ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_get_ipi':
>> arch/powerpc/sysdev/xive/native.c:254:9: error: implicit declaration of function 'opal_xive_allocate_irq' [-Werror=implicit-function-declaration]
      irq = opal_xive_allocate_irq(chip_id);
            ^~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_alloc_irq':
>> arch/powerpc/sysdev/xive/native.c:275:31: error: 'OPAL_XIVE_ANY_CHIP' undeclared (first use in this function)
      rc = opal_xive_allocate_irq(OPAL_XIVE_ANY_CHIP);
                                  ^~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_free_irq':
>> arch/powerpc/sysdev/xive/native.c:288:12: error: implicit declaration of function 'opal_xive_free_irq' [-Werror=implicit-function-declaration]
      s64 rc = opal_xive_free_irq(irq);
               ^~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_shutdown':
>> arch/powerpc/sysdev/xive/native.c:317:2: error: implicit declaration of function 'opal_xive_reset' [-Werror=implicit-function-declaration]
     opal_xive_reset(OPAL_XIVE_MODE_EMU);
     ^~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:317:18: error: 'OPAL_XIVE_MODE_EMU' undeclared (first use in this function)
     opal_xive_reset(OPAL_XIVE_MODE_EMU);
                     ^~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_setup_cpu':
>> arch/powerpc/sysdev/xive/native.c:392:8: error: implicit declaration of function 'opal_xive_set_vp_info' [-Werror=implicit-function-declaration]
      rc = opal_xive_set_vp_info(vp, OPAL_XIVE_VP_ENABLED, 0);
           ^~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:392:34: error: 'OPAL_XIVE_VP_ENABLED' undeclared (first use in this function)
      rc = opal_xive_set_vp_info(vp, OPAL_XIVE_VP_ENABLED, 0);
                                     ^~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/sysdev/xive/native.c:403:7: error: implicit declaration of function 'opal_xive_get_vp_info' [-Werror=implicit-function-declaration]
     rc = opal_xive_get_vp_info(vp, NULL, &vp_cam_be, NULL, NULL);
          ^~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function 'xive_native_sync_source':
--
   arch/powerpc/xmon/xmon.c: In function 'dump_one_xive':
>> arch/powerpc/xmon/xmon.c:2352:2: error: implicit declaration of function 'opal_xive_dump' [-Werror=implicit-function-declaration]
     opal_xive_dump(XIVE_DUMP_TM_HYP, hwid);
     ^~~~~~~~~~~~~~
>> arch/powerpc/xmon/xmon.c:2352:17: error: 'XIVE_DUMP_TM_HYP' undeclared (first use in this function)
     opal_xive_dump(XIVE_DUMP_TM_HYP, hwid);
                    ^~~~~~~~~~~~~~~~
   arch/powerpc/xmon/xmon.c:2352:17: note: each undeclared identifier is reported only once for each function it appears in
>> arch/powerpc/xmon/xmon.c:2353:17: error: 'XIVE_DUMP_TM_POOL' undeclared (first use in this function)
     opal_xive_dump(XIVE_DUMP_TM_POOL, hwid);
                    ^~~~~~~~~~~~~~~~~
>> arch/powerpc/xmon/xmon.c:2354:17: error: 'XIVE_DUMP_TM_OS' undeclared (first use in this function)
     opal_xive_dump(XIVE_DUMP_TM_OS, hwid);
                    ^~~~~~~~~~~~~~~
>> arch/powerpc/xmon/xmon.c:2355:17: error: 'XIVE_DUMP_TM_USER' undeclared (first use in this function)
     opal_xive_dump(XIVE_DUMP_TM_USER, hwid);
                    ^~~~~~~~~~~~~~~~~
>> arch/powerpc/xmon/xmon.c:2356:17: error: 'XIVE_DUMP_VP' undeclared (first use in this function)
     opal_xive_dump(XIVE_DUMP_VP, hwid);
                    ^~~~~~~~~~~~
>> arch/powerpc/xmon/xmon.c:2357:17: error: 'XIVE_DUMP_EMU_STATE' undeclared (first use in this function)
     opal_xive_dump(XIVE_DUMP_EMU_STATE, hwid);
                    ^~~~~~~~~~~~~~~~~~~
   arch/powerpc/xmon/xmon.c: In function 'dump_one_xive_irq':
>> arch/powerpc/xmon/xmon.c:2393:7: error: implicit declaration of function 'opal_xive_get_irq_config' [-Werror=implicit-function-declaration]
     rc = opal_xive_get_irq_config(num, &vp, &prio, &lirq);
          ^~~~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors

vim +/opal_xive_get_irq_info +55 arch/powerpc/sysdev/xive/native.c

    49		__be32 esb_shift, src_chip;
    50		u64 opal_flags;
    51		s64 rc;
    52	
    53		memset(data, 0, sizeof(*data));
    54	
  > 55		rc = opal_xive_get_irq_info(hw_irq, &flags, &eoi_page, &trig_page,
    56					    &esb_shift, &src_chip);
    57		if (rc) {
    58			pr_err("XIVE: opal_xive_get_irq_info(0x%x) returned %lld\n",
    59			       hw_irq, rc);
    60			return -EINVAL;
    61		}
    62	
    63		opal_flags = be64_to_cpu(flags);
  > 64		if (opal_flags & OPAL_XIVE_IRQ_STORE_EOI)
    65			data->flags |= XIVE_IRQ_FLAG_STORE_EOI;
  > 66		if (opal_flags & OPAL_XIVE_IRQ_LSI)
    67			data->flags |= XIVE_IRQ_FLAG_LSI;
  > 68		if (opal_flags & OPAL_XIVE_IRQ_SHIFT_BUG)
    69			data->flags |= XIVE_IRQ_FLAG_SHIFT_BUG;
  > 70		if (opal_flags & OPAL_XIVE_IRQ_MASK_VIA_FW)
    71			data->flags |= XIVE_IRQ_FLAG_MASK_FW;
  > 72		if (opal_flags & OPAL_XIVE_IRQ_EOI_VIA_FW)
    73			data->flags |= XIVE_IRQ_FLAG_EOI_FW;
    74		data->eoi_page = be64_to_cpu(eoi_page);
    75		data->trig_page = be64_to_cpu(trig_page);
    76		data->esb_shift = be32_to_cpu(esb_shift);
    77		data->src_chip = be32_to_cpu(src_chip);
    78	
    79		data->eoi_mmio = ioremap(data->eoi_page, 1u << data->esb_shift);
    80		if (!data->eoi_mmio) {
    81			pr_err("XIVE: Failed to map EOI page for irq 0x%x\n", hw_irq);
    82			return -ENOMEM;
    83		}
    84	
    85		if (!data->trig_page)
    86			return 0;
    87		if (data->trig_page == data->eoi_page) {
    88			data->trig_mmio = data->eoi_mmio;
    89			return 0;
    90		}
    91	
    92		data->trig_mmio = ioremap(data->trig_page, 1u << data->esb_shift);
    93		if (!data->trig_mmio) {
    94			pr_err("XIVE: Failed to map trigger page for irq 0x%x\n", hw_irq);
    95			return -ENOMEM;
    96		}
    97		return 0;
    98	}
    99	
   100	int xive_native_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq)
   101	{
   102		s64 rc;
   103	
   104		for (;;) {
 > 105			rc = opal_xive_set_irq_config(hw_irq, target, prio, sw_irq);
   106			if (rc != OPAL_BUSY)
   107				break;
   108			msleep(1);
   109		}
   110		return rc == 0 ? 0 : -ENXIO;
   111	}
   112	
   113	/* This can be called multiple time to change a queue configuration */
   114	int xive_native_configure_queue(u32 vp_id, struct xive_q *q, u8 prio,
   115					__be32 *qpage, u32 order, bool can_escalate)
   116	{
   117		s64 rc = 0;
   118		__be64 qeoi_page_be;
   119		__be32 esc_irq_be;
   120		u64 flags, qpage_phys;
   121	
   122		/* If there's an actual queue page, clean it */
   123		if (order) {
   124			if (WARN_ON(!qpage))
   125				return -EINVAL;
   126			qpage_phys = __pa(qpage);
   127		} else
   128			qpage_phys = 0;
   129	
   130		/* Initialize the rest of the fields */
   131		q->msk = order ? ((1u << (order - 2)) - 1) : 0;
   132		q->idx = 0;
   133		q->toggle = 0;
   134	
 > 135		rc = opal_xive_get_queue_info(vp_id, prio, NULL, NULL,
   136					      &qeoi_page_be,
   137					      &esc_irq_be,
   138					      NULL);
   139		if (rc) {
   140			pr_err("XIVE: Error %lld getting queue info prio %d\n",
   141			       rc, prio);
   142			rc = -EIO;
   143			goto fail;
   144		}
   145		q->eoi_phys = be64_to_cpu(qeoi_page_be);
   146	
   147		/* Default flags */
 > 148		flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY | OPAL_XIVE_EQ_ENABLED;
   149	
   150		/* Escalation needed ? */
   151		if (can_escalate) {
   152			q->esc_irq = be32_to_cpu(esc_irq_be);
 > 153			flags |= OPAL_XIVE_EQ_ESCALATE;
   154		}
   155	
   156		/* Configure and enable the queue in HW */
   157		for (;;) {
 > 158			rc = opal_xive_set_queue_info(vp_id, prio, qpage_phys, order, flags);
   159			if (rc != OPAL_BUSY)
   160				break;
   161			msleep(1);
   162		}
   163		if (rc) {
   164			pr_err("XIVE: Error %lld setting queue for prio %d\n",
   165			       rc, prio);
   166			rc = -EIO;
   167		} else {
   168			/*
   169			 * KVM code requires all of the above to be visible before
   170			 * q->qpage is set due to how it manages IPI EOIs
   171			 */
   172			wmb();
   173			q->qpage = qpage;
   174		}
   175	 fail:
   176		return rc;
   177	}
   178	
   179	static void __xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio)
   180	{
   181		s64 rc;
   182	
   183		/* Disable the queue in HW */
   184		for (;;) {
   185			rc = opal_xive_set_queue_info(vp_id, prio, 0, 0, 0);
   186				break;
   187			msleep(1);
   188		}
   189		if (rc)
   190			pr_err("XIVE: Error %lld disabling queue for prio %d\n",
   191			       rc, prio);
   192	}
   193	
   194	void xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio)
   195	{
   196		__xive_native_disable_queue(vp_id, q, prio);
   197	}
   198	
   199	static int xive_native_setup_queue(unsigned int cpu, struct xive_cpu *xc, u8 prio)
   200	{
   201		struct xive_q *q = &xc->queue[prio];
   202		unsigned int alloc_order;
   203		struct page *pages;
   204		__be32 *qpage;
   205	
   206		alloc_order = (xive_queue_shift > PAGE_SHIFT) ?
   207			(xive_queue_shift - PAGE_SHIFT) : 0;
   208		pages = alloc_pages_node(cpu_to_node(cpu), GFP_KERNEL, alloc_order);
   209		if (!pages)
   210			return -ENOMEM;
   211		qpage = (__be32 *)page_address(pages);
   212		memset(qpage, 0, 1 << xive_queue_shift);
   213		return xive_native_configure_queue(get_hard_smp_processor_id(cpu),
   214						   q, prio, qpage, xive_queue_shift, false);
   215	}
   216	
   217	static void xive_native_cleanup_queue(unsigned int cpu, struct xive_cpu *xc, u8 prio)
   218	{
   219		struct xive_q *q = &xc->queue[prio];
   220		unsigned int alloc_order;
   221	
   222		/*
   223		 * We use the variant with no iounmap as this is called on exec
   224		 * from an IPI and iounmap isn't safe
   225		 */
   226		__xive_native_disable_queue(get_hard_smp_processor_id(cpu), q, prio);
   227		alloc_order = (xive_queue_shift > PAGE_SHIFT) ?
   228			(xive_queue_shift - PAGE_SHIFT) : 0;
   229		free_pages((unsigned long)q->qpage, alloc_order);
   230		q->qpage = NULL;
   231	}
   232	
   233	static bool xive_native_match(struct device_node *node)
   234	{
   235		return of_device_is_compatible(node, "ibm,opal-xive-vc");
   236	}
   237	
   238	#ifdef CONFIG_SMP
   239	static int xive_native_get_ipi(unsigned int cpu, struct xive_cpu *xc)
   240	{
   241		struct device_node *np;
   242		unsigned int chip_id;
   243		s64 irq;
   244	
   245		/* Find the chip ID */
   246		np = of_get_cpu_node(cpu, NULL);
   247		if (np) {
   248			if (of_property_read_u32(np, "ibm,chip-id", &chip_id) < 0)
   249				chip_id = 0;
   250		}
   251	
   252		/* Allocate an IPI and populate info about it */
   253		for (;;) {
 > 254			irq = opal_xive_allocate_irq(chip_id);

255 if (irq == OPAL_BUSY) {
256 msleep(1);
257 continue;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw

Re: [PATCH v2 04/10] powerpc/xive: Native exploitation of the XIVE interrupt controller

Quoted 6 lines · kbuild test robot

Hi Benjamin,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.11-rc5 next-20170405]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

Ooops, I was 1 patch off in my git send-email, forgetting the opal-api.h updates. I'm sending the pre-req patch separately.

Cheers,
Ben.

Quoted 450 lines

url:    https://github.com/0day-ci/linux/commits/Benjamin-
Herrenschmidt/powerpc-Add-more-PPC-bit-conversion-macros/20170406- 041935
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
.git next
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705 reproduce:
        wget https://raw.githubusercontent.com/01org/lkp-tests/master
/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross

        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   arch/powerpc/sysdev/xive/native.c: In function
'xive_native_populate_irq_data':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:55:7: error: implicit declaration of function 'opal_xive_get_irq_info' [- Werror=implicit-function-declaration]

     rc = opal_xive_get_irq_info(hw_irq, &flags, &eoi_page, &trig_page,
          ^~~~~~~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:64:19: error:
'OPAL_XIVE_IRQ_STORE_EOI' undeclared (first use in this function)

     if (opal_flags & OPAL_XIVE_IRQ_STORE_EOI) ^~~~~~~~~~~~~~~~~~~~~~~ arch/powerpc/sysdev/xive/native.c:64:19: note: each undeclared identifier is reported only once for each function it appears in

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:66:19: error:
'OPAL_XIVE_IRQ_LSI' undeclared (first use in this function)

     if (opal_flags & OPAL_XIVE_IRQ_LSI)
                      ^~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:68:19: error:
'OPAL_XIVE_IRQ_SHIFT_BUG' undeclared (first use in this function)

     if (opal_flags & OPAL_XIVE_IRQ_SHIFT_BUG)
                      ^~~~~~~~~~~~~~~~~~~~~~~

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:70:19: error:
'OPAL_XIVE_IRQ_MASK_VIA_FW' undeclared (first use in this function)

     if (opal_flags & OPAL_XIVE_IRQ_MASK_VIA_FW)
                      ^~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:72:19: error:
'OPAL_XIVE_IRQ_EOI_VIA_FW' undeclared (first use in this function)

     if (opal_flags & OPAL_XIVE_IRQ_EOI_VIA_FW)
                      ^~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function
'xive_native_configure_irq':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:105:8: error: implicit declaration of function 'opal_xive_set_irq_config' [- Werror=implicit-function-declaration]

      rc = opal_xive_set_irq_config(hw_irq, target, prio, sw_irq); ^~~~~~~~~~~~~~~~~~~~~~~~ arch/powerpc/sysdev/xive/native.c: In function 'xive_native_configure_queue':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:135:7: error: implicit declaration of function 'opal_xive_get_queue_info' [- Werror=implicit-function-declaration]

     rc = opal_xive_get_queue_info(vp_id, prio, NULL, NULL, ^~~~~~~~~~~~~~~~~~~~~~~~

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:148:10: error:
'OPAL_XIVE_EQ_ALWAYS_NOTIFY' undeclared (first use in this function)

     flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY | OPAL_XIVE_EQ_ENABLED; ^~~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:148:39: error:
'OPAL_XIVE_EQ_ENABLED' undeclared (first use in this function)

     flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY | OPAL_XIVE_EQ_ENABLED; ^~~~~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:153:12: error:
'OPAL_XIVE_EQ_ESCALATE' undeclared (first use in this function)

      flags |= OPAL_XIVE_EQ_ESCALATE;
               ^~~~~~~~~~~~~~~~~~~~~

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:158:8: error: implicit declaration of function 'opal_xive_set_queue_info' [- Werror=implicit-function-declaration]

      rc = opal_xive_set_queue_info(vp_id, prio, qpage_phys, order, flags);
           ^~~~~~~~~~~~~~~~~~~~~~~~ arch/powerpc/sysdev/xive/native.c: In function 'xive_native_get_ipi':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:254:9: error: implicit declaration of function 'opal_xive_allocate_irq' [- Werror=implicit-function-declaration]

      irq = opal_xive_allocate_irq(chip_id);
            ^~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function
'xive_native_alloc_irq':

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:275:31: error:
'OPAL_XIVE_ANY_CHIP' undeclared (first use in this function)

      rc = opal_xive_allocate_irq(OPAL_XIVE_ANY_CHIP); ^~~~~~~~~~~~~~~~~~ arch/powerpc/sysdev/xive/native.c: In function 'xive_native_free_irq':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:288:12: error: implicit declaration of function 'opal_xive_free_irq' [-Werror=implicit- function-declaration]

      s64 rc = opal_xive_free_irq(irq);
               ^~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function
'xive_native_shutdown':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:317:2: error: implicit declaration of function 'opal_xive_reset' [-Werror=implicit- function-declaration]

     opal_xive_reset(OPAL_XIVE_MODE_EMU);
     ^~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:317:18: error:
'OPAL_XIVE_MODE_EMU' undeclared (first use in this function)

     opal_xive_reset(OPAL_XIVE_MODE_EMU);
                     ^~~~~~~~~~~~~~~~~~
   arch/powerpc/sysdev/xive/native.c: In function
'xive_native_setup_cpu':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:392:8: error: implicit declaration of function 'opal_xive_set_vp_info' [- Werror=implicit-function-declaration]

      rc = opal_xive_set_vp_info(vp, OPAL_XIVE_VP_ENABLED, 0); ^~~~~~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/sysdev/xive/native.c:392:34: error:
'OPAL_XIVE_VP_ENABLED' undeclared (first use in this function)

      rc = opal_xive_set_vp_info(vp, OPAL_XIVE_VP_ENABLED, 0); ^~~~~~~~~~~~~~~~~~~~

Quoted 3 lines
Quoted 3 lines

arch/powerpc/sysdev/xive/native.c:403:7: error: implicit declaration of function 'opal_xive_get_vp_info' [- Werror=implicit-function-declaration]

     rc = opal_xive_get_vp_info(vp, NULL, &vp_cam_be, NULL, NULL); ^~~~~~~~~~~~~~~~~~~~~ arch/powerpc/sysdev/xive/native.c: In function 'xive_native_sync_source':
--
   arch/powerpc/xmon/xmon.c: In function 'dump_one_xive':

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2352:2: error: implicit declaration of function 'opal_xive_dump' [-Werror=implicit-function-declaration]

     opal_xive_dump(XIVE_DUMP_TM_HYP, hwid);
     ^~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2352:17: error: 'XIVE_DUMP_TM_HYP' undeclared (first use in this function)

     opal_xive_dump(XIVE_DUMP_TM_HYP, hwid); ^~~~~~~~~~~~~~~~ arch/powerpc/xmon/xmon.c:2352:17: note: each undeclared identifier is reported only once for each function it appears in

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2353:17: error: 'XIVE_DUMP_TM_POOL' undeclared (first use in this function)

     opal_xive_dump(XIVE_DUMP_TM_POOL, hwid);
                    ^~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2354:17: error: 'XIVE_DUMP_TM_OS' undeclared (first use in this function)

     opal_xive_dump(XIVE_DUMP_TM_OS, hwid);
                    ^~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2355:17: error: 'XIVE_DUMP_TM_USER' undeclared (first use in this function)

     opal_xive_dump(XIVE_DUMP_TM_USER, hwid);
                    ^~~~~~~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2356:17: error: 'XIVE_DUMP_VP' undeclared (first use in this function)

     opal_xive_dump(XIVE_DUMP_VP, hwid);
                    ^~~~~~~~~~~~

Quoted 2 lines
Quoted 2 lines

arch/powerpc/xmon/xmon.c:2357:17: error: 'XIVE_DUMP_EMU_STATE' undeclared (first use in this function)

     opal_xive_dump(XIVE_DUMP_EMU_STATE, hwid); ^~~~~~~~~~~~~~~~~~~ arch/powerpc/xmon/xmon.c: In function 'dump_one_xive_irq':

Quoted 3 lines
Quoted 3 lines

arch/powerpc/xmon/xmon.c:2393:7: error: implicit declaration of function 'opal_xive_get_irq_config' [-Werror=implicit-function- declaration]

     rc = opal_xive_get_irq_config(num, &vp, &prio, &lirq); ^~~~~~~~~~~~~~~~~~~~~~~~
   cc1: all warnings being treated as errors

vim +/opal_xive_get_irq_info +55 arch/powerpc/sysdev/xive/native.c

    49 __be32 esb_shift, src_chip;
    50 u64 opal_flags;
    51 s64 rc;
    52
    53 memset(data, 0, sizeof(*data));
    54
  > 55 rc = opal_xive_get_irq_info(hw_irq, &flags,
&eoi_page, &trig_page,
    56     &esb_shift,
&src_chip);
    57 if (rc) {
    58 pr_err("XIVE:
opal_xive_get_irq_info(0x%x) returned %lld\n",
    59        hw_irq, rc);
    60 return -EINVAL;
    61 }
    62
    63 opal_flags = be64_to_cpu(flags);
  > 64 if (opal_flags & OPAL_XIVE_IRQ_STORE_EOI)
    65 data->flags |= XIVE_IRQ_FLAG_STORE_EOI;
  > 66 if (opal_flags & OPAL_XIVE_IRQ_LSI)
    67 data->flags |= XIVE_IRQ_FLAG_LSI;
  > 68 if (opal_flags & OPAL_XIVE_IRQ_SHIFT_BUG)
    69 data->flags |= XIVE_IRQ_FLAG_SHIFT_BUG;
  > 70 if (opal_flags & OPAL_XIVE_IRQ_MASK_VIA_FW)
    71 data->flags |= XIVE_IRQ_FLAG_MASK_FW;
  > 72 if (opal_flags & OPAL_XIVE_IRQ_EOI_VIA_FW)
    73 data->flags |= XIVE_IRQ_FLAG_EOI_FW;
    74 data->eoi_page = be64_to_cpu(eoi_page);
    75 data->trig_page = be64_to_cpu(trig_page);
    76 data->esb_shift = be32_to_cpu(esb_shift);
    77 data->src_chip = be32_to_cpu(src_chip);
    78
    79 data->eoi_mmio = ioremap(data->eoi_page, 1u <<
data->esb_shift);
    80 if (!data->eoi_mmio) {
    81 pr_err("XIVE: Failed to map EOI page
for irq 0x%x\n", hw_irq);
    82 return -ENOMEM;
    83 }
    84
    85 if (!data->trig_page)
    86 return 0;
    87 if (data->trig_page == data->eoi_page) {
    88 data->trig_mmio = data->eoi_mmio;
    89 return 0;
    90 }
    91
    92 data->trig_mmio = ioremap(data->trig_page, 1u
<< data->esb_shift);
    93 if (!data->trig_mmio) {
    94 pr_err("XIVE: Failed to map trigger
page for irq 0x%x\n", hw_irq);
    95 return -ENOMEM;
    96 }
    97 return 0;
    98 }
    99
   100 int xive_native_configure_irq(u32 hw_irq, u32 target,
u8 prio, u32 sw_irq)
   101 {
   102 s64 rc;
   103
   104 for (;;) {
 > 105 rc = opal_xive_set_irq_config(hw_irq,
target, prio, sw_irq);
   106 if (rc != OPAL_BUSY)
   107 break;
   108 msleep(1);
   109 }
   110 return rc == 0 ? 0 : -ENXIO;
   111 }
   112
   113 /* This can be called multiple time to change a queue
configuration */
   114 int xive_native_configure_queue(u32 vp_id, struct
xive_q *q, u8 prio,
   115 __be32 *qpage, u32
order, bool can_escalate)
   116 {
   117 s64 rc = 0;
   118 __be64 qeoi_page_be;
   119 __be32 esc_irq_be;
   120 u64 flags, qpage_phys;
   121
   122 /* If there's an actual queue page, clean it */
   123 if (order) {
   124 if (WARN_ON(!qpage))
   125 return -EINVAL;
   126 qpage_phys = __pa(qpage);
   127 } else
   128 qpage_phys = 0;
   129
   130 /* Initialize the rest of the fields */
   131 q->msk = order ? ((1u << (order - 2)) - 1) : 0;
   132 q->idx = 0;
   133 q->toggle = 0;
   134
 > 135 rc = opal_xive_get_queue_info(vp_id, prio,
NULL, NULL,
   136       &qeoi_page_be,
   137       &esc_irq_be,
   138       NULL);
   139 if (rc) {
   140 pr_err("XIVE: Error %lld getting queue
info prio %d\n",
   141        rc, prio);
   142 rc = -EIO;
   143 goto fail;
   144 }
   145 q->eoi_phys = be64_to_cpu(qeoi_page_be);
   146
   147 /* Default flags */
 > 148 flags = OPAL_XIVE_EQ_ALWAYS_NOTIFY |
OPAL_XIVE_EQ_ENABLED;
   149
   150 /* Escalation needed ? */
   151 if (can_escalate) {
   152 q->esc_irq = be32_to_cpu(esc_irq_be);
 > 153 flags |= OPAL_XIVE_EQ_ESCALATE;
   154 }
   155
   156 /* Configure and enable the queue in HW */
   157 for (;;) {
 > 158 rc = opal_xive_set_queue_info(vp_id,
prio, qpage_phys, order, flags);
   159 if (rc != OPAL_BUSY)
   160 break;
   161 msleep(1);
   162 }
   163 if (rc) {
   164 pr_err("XIVE: Error %lld setting queue
for prio %d\n",
   165        rc, prio);
   166 rc = -EIO;
   167 } else {
   168 /*
   169  * KVM code requires all of the above
to be visible before
   170  * q->qpage is set due to how it
manages IPI EOIs
   171  */
   172 wmb();
   173 q->qpage = qpage;
   174 }
   175  fail:
   176 return rc;
   177 }
   178
   179 static void __xive_native_disable_queue(u32 vp_id,
struct xive_q *q, u8 prio)
   180 {
   181 s64 rc;
   182
   183 /* Disable the queue in HW */
   184 for (;;) {
   185 rc = opal_xive_set_queue_info(vp_id,
prio, 0, 0, 0);
   186 break;
   187 msleep(1);
   188 }
   189 if (rc)
   190 pr_err("XIVE: Error %lld disabling
queue for prio %d\n",
   191        rc, prio);
   192 }
   193
   194 void xive_native_disable_queue(u32 vp_id, struct xive_q
*q, u8 prio)
   195 {
   196 __xive_native_disable_queue(vp_id, q, prio);
   197 }
   198
   199 static int xive_native_setup_queue(unsigned int cpu,
struct xive_cpu *xc, u8 prio)
   200 {
   201 struct xive_q *q = &xc->queue[prio];
   202 unsigned int alloc_order;
   203 struct page *pages;
   204 __be32 *qpage;
   205
   206 alloc_order = (xive_queue_shift > PAGE_SHIFT) ?
   207 (xive_queue_shift - PAGE_SHIFT) : 0;
   208 pages = alloc_pages_node(cpu_to_node(cpu),
GFP_KERNEL, alloc_order);
   209 if (!pages)
   210 return -ENOMEM;
   211 qpage = (__be32 *)page_address(pages);
   212 memset(qpage, 0, 1 << xive_queue_shift);
   213 return
xive_native_configure_queue(get_hard_smp_processor_id(cpu),
   214    q, prio,
qpage, xive_queue_shift, false);
   215 }
   216
   217 static void xive_native_cleanup_queue(unsigned int cpu,
struct xive_cpu *xc, u8 prio)
   218 {
   219 struct xive_q *q = &xc->queue[prio];
   220 unsigned int alloc_order;
   221
   222 /*
   223  * We use the variant with no iounmap as this
is called on exec
   224  * from an IPI and iounmap isn't safe
   225  */
   226 __xive_native_disable_queue(get_hard_smp_proces
sor_id(cpu), q, prio);
   227 alloc_order = (xive_queue_shift > PAGE_SHIFT) ?
   228 (xive_queue_shift - PAGE_SHIFT) : 0;
   229 free_pages((unsigned long)q->qpage,
alloc_order);
   230 q->qpage = NULL;
   231 }
   232
   233 static bool xive_native_match(struct device_node *node)
   234 {
   235 return of_device_is_compatible(node, "ibm,opal-
xive-vc");
   236 }
   237
   238 #ifdef CONFIG_SMP
   239 static int xive_native_get_ipi(unsigned int cpu, struct
xive_cpu *xc)
   240 {
   241 struct device_node *np;
   242 unsigned int chip_id;
   243 s64 irq;
   244
   245 /* Find the chip ID */
   246 np = of_get_cpu_node(cpu, NULL);
   247 if (np) {
   248 if (of_property_read_u32(np, "ibm,chip-
id", &chip_id) < 0)
   249 chip_id = 0;
   250 }
   251
   252 /* Allocate an IPI and populate info about it
*/
   253 for (;;) {
 > 254 irq = opal_xive_allocate_irq(chip_id);
   255 if (irq == OPAL_BUSY) {
   256 msleep(1);
   257 continue;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel
Corporation

#12 lore raw

Re: [PATCH v2 10/10] powerpc/kvm: Native usage of the XIVE interrupt controller

In reply to Benjamin Herrenschmidt
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Benjamin,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.11-rc5 next-20170405]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Benjamin-Herrenschmidt/powerpc-Add-more-PPC-bit-conversion-macros/20170406-041935
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc

All errors (new ones prefixed by >>):

arch/powerpc/kvm/book3s_xive.c: In function 'xive_lock_and_mask':

>> arch/powerpc/kvm/book3s_xive.c:340:18: error: 'OPAL_XIVE_IRQ_MASK_VIA_FW' undeclared (first use in this function)
     if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
   arch/powerpc/kvm/book3s_xive.c:340:18: note: each undeclared identifier is reported only once for each function it appears in
   arch/powerpc/kvm/book3s_xive.c: In function 'xive_finish_unmask':
   arch/powerpc/kvm/book3s_xive.c:396:18: error: 'OPAL_XIVE_IRQ_MASK_VIA_FW' undeclared (first use in this function)
     if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
                     ^~~~~~~~~~~~~~~~~~~~~~~~~
>> arch/powerpc/kvm/book3s_xive.c:404:21: error: 'OPAL_XIVE_IRQ_LSI' undeclared (first use in this function)
      if (!(xd->flags & OPAL_XIVE_IRQ_LSI))
                        ^~~~~~~~~~~~~~~~~

vim +/OPAL_XIVE_IRQ_MASK_VIA_FW +340 arch/powerpc/kvm/book3s_xive.c

334 * lazy masking instead.
335 *
336 * For now, we work around this in unmask by forcing
337 * an interrupt whenever we unmask a non-LSI via FW
338 * (if ever).
339 */

 > 340		if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
   341			xive_native_configure_irq(hw_num,
   342						  xive->vp_base + state->act_server,
   343						  MASKED, state->number);
   344			/* set old_p so we can track if an H_EOI was done */
   345			state->old_p = true;
   346			state->old_q = false;
   347		} else {
   348			/* Set PQ to 10, return old P and old Q and remember them */
   349			val = xive_vm_esb_load(xd, XIVE_ESB_SET_PQ_10);
   350			state->old_p = !!(val & 2);
   351			state->old_q = !!(val & 1);
   352	
   353			/*
   354			 * Synchronize hardware to sensure the queues are updated
   355			 * when masking
   356			 */
   357			xive_native_sync_source(hw_num);
   358		}
   359	
   360		return old_prio;
   361	}
   362	
   363	static void xive_lock_for_unmask(struct kvmppc_xive_src_block *sb,
   364					 struct kvmppc_xive_irq_state *state)
   365	{
   366		/*
   367		 * Take the lock try again if racing with H_EOI
   368		 */
   369		for (;;) {
   370			arch_spin_lock(&sb->lock);
   371			if (!state->in_eoi)
   372				break;
   373			arch_spin_unlock(&sb->lock);
   374		}
   375	}
   376	
   377	static void xive_finish_unmask(struct kvmppc_xive *xive,
   378				       struct kvmppc_xive_src_block *sb,
   379				       struct kvmppc_xive_irq_state *state,
   380				       u8 prio)
   381	{
   382		struct xive_irq_data *xd;
   383		u32 hw_num;
   384	
   385		/* If we aren't changing a thing, move on */
   386		if (state->guest_priority != MASKED)
   387			goto bail;
   388	
   389		/* Get the right irq */
   390		kvmppc_xive_select_irq(state, &hw_num, &xd);
   391	
   392		/*
   393		 * See command in xive_lock_and_mask() concerning masking
   394		 * via firmware.
   395		 */
   396		if (xd->flags & OPAL_XIVE_IRQ_MASK_VIA_FW) {
   397			xive_native_configure_irq(hw_num,
   398						  xive->vp_base + state->act_server,
   399						  state->act_priority, state->number);
   400			/* If an EOI is needed, do it here */
   401			if (!state->old_p)
   402				xive_vm_source_eoi(hw_num, xd);
   403			/* If this is not an LSI, force a trigger */
 > 404			if (!(xd->flags & OPAL_XIVE_IRQ_LSI))

405 xive_irq_trigger(xd);
406 goto bail;
407 }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation