Merge the topic branch we share with kvm-ppc, this brings in two xive commits, one from Paul to rework HMI handling, and a minor cleanup to drop an unused flag.
···1010#define _ASM_POWERPC_XIVE_REGS_H11111212/*1313+ * "magic" Event State Buffer (ESB) MMIO offsets.1414+ *1515+ * Each interrupt source has a 2-bit state machine called ESB1616+ * which can be controlled by MMIO. It's made of 2 bits, P and1717+ * Q. P indicates that an interrupt is pending (has been sent1818+ * to a queue and is waiting for an EOI). Q indicates that the1919+ * interrupt has been triggered while pending.2020+ *2121+ * This acts as a coalescing mechanism in order to guarantee2222+ * that a given interrupt only occurs at most once in a queue.2323+ *2424+ * When doing an EOI, the Q bit will indicate if the interrupt2525+ * needs to be re-triggered.2626+ *2727+ * The following offsets into the ESB MMIO allow to read or2828+ * manipulate the PQ bits. They must be used with an 8-bytes2929+ * load instruction. They all return the previous state of the3030+ * interrupt (atomically).3131+ *3232+ * Additionally, some ESB pages support doing an EOI via a3333+ * store at 0 and some ESBs support doing a trigger via a3434+ * separate trigger page.3535+ */3636+#define XIVE_ESB_STORE_EOI 0x400 /* Store */3737+#define XIVE_ESB_LOAD_EOI 0x000 /* Load */3838+#define XIVE_ESB_GET 0x800 /* Load */3939+#define XIVE_ESB_SET_PQ_00 0xc00 /* Load */4040+#define XIVE_ESB_SET_PQ_01 0xd00 /* Load */4141+#define XIVE_ESB_SET_PQ_10 0xe00 /* Load */4242+#define XIVE_ESB_SET_PQ_11 0xf00 /* Load */4343+4444+#define XIVE_ESB_VAL_P 0x24545+#define XIVE_ESB_VAL_Q 0x14646+4747+/*1348 * Thread Management (aka "TM") registers1449 */1550
+3-35
arch/powerpc/include/asm/xive.h
···5858#define XIVE_IRQ_FLAG_EOI_FW 0x105959#define XIVE_IRQ_FLAG_H_INT_ESB 0x2060606161+/* Special flag set by KVM for excalation interrupts */6262+#define XIVE_IRQ_NO_EOI 0x806363+6164#define XIVE_INVALID_CHIP_ID -162656366/* A queue tracking structure in a CPU */···7471 atomic_t count;7572 atomic_t pending_count;7673};7777-7878-/*7979- * "magic" Event State Buffer (ESB) MMIO offsets.8080- *8181- * Each interrupt source has a 2-bit state machine called ESB8282- * which can be controlled by MMIO. It's made of 2 bits, P and8383- * Q. P indicates that an interrupt is pending (has been sent8484- * to a queue and is waiting for an EOI). Q indicates that the8585- * interrupt has been triggered while pending.8686- *8787- * This acts as a coalescing mechanism in order to guarantee8888- * that a given interrupt only occurs at most once in a queue.8989- *9090- * When doing an EOI, the Q bit will indicate if the interrupt9191- * needs to be re-triggered.9292- *9393- * The following offsets into the ESB MMIO allow to read or9494- * manipulate the PQ bits. They must be used with an 8-bytes9595- * load instruction. They all return the previous state of the9696- * interrupt (atomically).9797- *9898- * Additionally, some ESB pages support doing an EOI via a9999- * store at 0 and some ESBs support doing a trigger via a100100- * separate trigger page.101101- */102102-#define XIVE_ESB_STORE_EOI 0x400 /* Store */103103-#define XIVE_ESB_LOAD_EOI 0x000 /* Load */104104-#define XIVE_ESB_GET 0x800 /* Load */105105-#define XIVE_ESB_SET_PQ_00 0xc00 /* Load */106106-#define XIVE_ESB_SET_PQ_01 0xd00 /* Load */107107-#define XIVE_ESB_SET_PQ_10 0xe00 /* Load */108108-#define XIVE_ESB_SET_PQ_11 0xf00 /* Load */109109-110110-#define XIVE_ESB_VAL_P 0x2111111-#define XIVE_ESB_VAL_Q 0x11127411375/* Global enable flags for the XIVE support */11476extern bool __xive_enabled;
+114-28
arch/powerpc/kernel/mce.c
···495495 return handled;496496}497497498498-long hmi_exception_realmode(struct pt_regs *regs)498498+/* Possible meanings for HMER_DEBUG_TRIG bit being set on POWER9 */499499+static enum {500500+ DTRIG_UNKNOWN,501501+ DTRIG_VECTOR_CI, /* need to emulate vector CI load instr */502502+ DTRIG_SUSPEND_ESCAPE, /* need to escape from TM suspend mode */503503+} hmer_debug_trig_function;504504+505505+static int init_debug_trig_function(void)499506{507507+ int pvr;508508+ struct device_node *cpun;509509+ struct property *prop = NULL;510510+ const char *str;511511+512512+ /* First look in the device tree */513513+ preempt_disable();514514+ cpun = of_get_cpu_node(smp_processor_id(), NULL);515515+ if (cpun) {516516+ of_property_for_each_string(cpun, "ibm,hmi-special-triggers",517517+ prop, str) {518518+ if (strcmp(str, "bit17-vector-ci-load") == 0)519519+ hmer_debug_trig_function = DTRIG_VECTOR_CI;520520+ else if (strcmp(str, "bit17-tm-suspend-escape") == 0)521521+ hmer_debug_trig_function = DTRIG_SUSPEND_ESCAPE;522522+ }523523+ of_node_put(cpun);524524+ }525525+ preempt_enable();526526+527527+ /* If we found the property, don't look at PVR */528528+ if (prop)529529+ goto out;530530+531531+ pvr = mfspr(SPRN_PVR);532532+ /* Check for POWER9 Nimbus (scale-out) */533533+ if ((PVR_VER(pvr) == PVR_POWER9) && (pvr & 0xe000) == 0) {534534+ /* DD2.2 and later */535535+ if ((pvr & 0xfff) >= 0x202)536536+ hmer_debug_trig_function = DTRIG_SUSPEND_ESCAPE;537537+ /* DD2.0 and DD2.1 - used for vector CI load emulation */538538+ else if ((pvr & 0xfff) >= 0x200)539539+ hmer_debug_trig_function = DTRIG_VECTOR_CI;540540+ }541541+542542+ out:543543+ switch (hmer_debug_trig_function) {544544+ case DTRIG_VECTOR_CI:545545+ pr_debug("HMI debug trigger used for vector CI load\n");546546+ break;547547+ case DTRIG_SUSPEND_ESCAPE:548548+ pr_debug("HMI debug trigger used for TM suspend escape\n");549549+ break;550550+ default:551551+ break;552552+ }553553+ return 0;554554+}555555+__initcall(init_debug_trig_function);556556+557557+/*558558+ * Handle HMIs that occur as a result of a debug trigger.559559+ * Return values:560560+ * -1 means this is not a HMI cause that we know about561561+ * 0 means no further handling is required562562+ * 1 means further handling is required563563+ */564564+long hmi_handle_debugtrig(struct pt_regs *regs)565565+{566566+ unsigned long hmer = mfspr(SPRN_HMER);567567+ long ret = 0;568568+569569+ /* HMER_DEBUG_TRIG bit is used for various workarounds on P9 */570570+ if (!((hmer & HMER_DEBUG_TRIG)571571+ && hmer_debug_trig_function != DTRIG_UNKNOWN))572572+ return -1;573573+574574+ hmer &= ~HMER_DEBUG_TRIG;575575+ /* HMER is a write-AND register */576576+ mtspr(SPRN_HMER, ~HMER_DEBUG_TRIG);577577+578578+ switch (hmer_debug_trig_function) {579579+ case DTRIG_VECTOR_CI:580580+ /*581581+ * Now to avoid problems with soft-disable we582582+ * only do the emulation if we are coming from583583+ * host user space584584+ */585585+ if (regs && user_mode(regs))586586+ ret = local_paca->hmi_p9_special_emu = 1;587587+588588+ break;589589+590590+ default:591591+ break;592592+ }593593+594594+ /*595595+ * See if any other HMI causes remain to be handled596596+ */597597+ if (hmer & mfspr(SPRN_HMEER))598598+ return -1;599599+600600+ return ret;601601+}602602+603603+/*604604+ * Return values:605605+ */606606+long hmi_exception_realmode(struct pt_regs *regs)607607+{ 608608+ int ret;609609+500610 __this_cpu_inc(irq_stat.hmi_exceptions);501611502502-#ifdef CONFIG_PPC_BOOK3S_64503503- /* Workaround for P9 vector CI loads (see p9_hmi_special_emu) */504504- if (pvr_version_is(PVR_POWER9)) {505505- unsigned long hmer = mfspr(SPRN_HMER);506506-507507- /* Do we have the debug bit set */508508- if (hmer & PPC_BIT(17)) {509509- hmer &= ~PPC_BIT(17);510510- mtspr(SPRN_HMER, hmer);511511-512512- /*513513- * Now to avoid problems with soft-disable we514514- * only do the emulation if we are coming from515515- * user space516516- */517517- if (user_mode(regs))518518- local_paca->hmi_p9_special_emu = 1;519519-520520- /*521521- * Don't bother going to OPAL if that's the522522- * only relevant bit.523523- */524524- if (!(hmer & mfspr(SPRN_HMEER)))525525- return local_paca->hmi_p9_special_emu;526526- }527527- }528528-#endif /* CONFIG_PPC_BOOK3S_64 */612612+ ret = hmi_handle_debugtrig(regs);613613+ if (ret >= 0)614614+ return ret;529615530616 wait_for_subcore_guest_exit();531617
+5-3
arch/powerpc/kvm/book3s_hv_ras.c
···266266 * secondary threads to proceed.267267 * - All secondary threads will eventually call opal hmi handler on268268 * their exit path.269269+ *270270+ * Returns 1 if the timebase offset should be applied, 0 if not.269271 */270272271273long kvmppc_realmode_hmi_handler(void)272274{273273- int ptid = local_paca->kvm_hstate.ptid;274275 bool resync_req;275276276276- /* This is only called on primary thread. */277277- BUG_ON(ptid != 0);278277 __this_cpu_inc(irq_stat.hmi_exceptions);278278+279279+ if (hmi_handle_debugtrig(NULL) >= 0)280280+ return 1;279281280282 /*281283 * By now primary thread has already completed guest->host
+4-5
arch/powerpc/kvm/book3s_hv_rm_mmu.c
···4242}43434444/* Return 1 if we need to do a global tlbie, 0 if we can use tlbiel */4545-static int global_invalidates(struct kvm *kvm, unsigned long flags)4545+static int global_invalidates(struct kvm *kvm)4646{4747 int global;4848 int cpu;···522522 if (v & HPTE_V_VALID) {523523 hpte[0] &= ~cpu_to_be64(HPTE_V_VALID);524524 rb = compute_tlbie_rb(v, pte_r, pte_index);525525- do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags), true);525525+ do_tlbies(kvm, &rb, 1, global_invalidates(kvm), true);526526 /*527527 * The reference (R) and change (C) bits in a HPT528528 * entry can be set by hardware at any time up until···572572573573 if (kvm_is_radix(kvm))574574 return H_FUNCTION;575575- global = global_invalidates(kvm, 0);575575+ global = global_invalidates(kvm);576576 for (i = 0; i < 4 && ret == H_SUCCESS; ) {577577 n = 0;578578 for (; i < 4; ++i) {···732732 rb = compute_tlbie_rb(v, r, pte_index);733733 hpte[0] = cpu_to_be64((pte_v & ~HPTE_V_VALID) |734734 HPTE_V_ABSENT);735735- do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags),736736- true);735735+ do_tlbies(kvm, &rb, 1, global_invalidates(kvm), true);737736 /* Don't lose R/C bit updates done by hardware */738737 r |= be64_to_cpu(hpte[1]) & (HPTE_R_R | HPTE_R_C);739738 hpte[1] = cpu_to_be64(r);
+5-4
arch/powerpc/kvm/book3s_hv_rmhandlers.S
···19091909 bne 27f19101910 bl kvmppc_realmode_hmi_handler19111911 nop19121912+ cmpdi r3, 019121913 li r12, BOOK3S_INTERRUPT_HMI19131914 /*19141914- * At this point kvmppc_realmode_hmi_handler would have resync-ed19151915- * the TB. Hence it is not required to subtract guest timebase19161916- * offset from timebase. So, skip it.19151915+ * At this point kvmppc_realmode_hmi_handler may have resync-ed19161916+ * the TB, and if it has, we must not subtract the guest timebase19171917+ * offset from the timebase. So, skip it.19171918 *19181919 * Also, do not call kvmppc_subcore_exit_guest() because it has19191920 * been invoked as part of kvmppc_realmode_hmi_handler().19201921 */19211921- b 30f19221922+ beq 30f192219231923192427:19241925 /* Subtract timebase offset from timebase */
+2-1
arch/powerpc/sysdev/xive/common.c
···367367 * EOI the source if it hasn't been disabled and hasn't368368 * been passed-through to a KVM guest369369 */370370- if (!irqd_irq_disabled(d) && !irqd_is_forwarded_to_vcpu(d))370370+ if (!irqd_irq_disabled(d) && !irqd_is_forwarded_to_vcpu(d) &&371371+ !(xd->flags & XIVE_IRQ_NO_EOI))371372 xive_do_source_eoi(irqd_to_hwirq(d), xd);372373373374 /*