From f294ebd827e7a2b831b1eef4aaf437f07b2c235e Mon Sep 17 00:00:00 2001 From: Jiale Yao Date: Thu, 29 Oct 2026 13:29:48 +0800 Subject: [PATCH 01/13] powerpc/eeh: NUL-terminate force recovery input eeh_force_recover_write() can fill its entire stack buffer from userspace and then pass the unterminated data to strncmp() and sscanf(). This can make the string helpers read beyond the buffer. Reserve the last byte and initialize the buffer so every accepted input is NUL-terminated. Propagate copy errors before parsing as well. Fixes: 954bd99435b8 ("powerpc/eeh: Add eeh_force_recover to debugfs") Cc: stable@vger.kernel.org Signed-off-by: Jiale Yao Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261029052948.2525048-1-yaojiale02@163.com --- arch/powerpc/kernel/eeh.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c index bb836f02101c..2d7898ef6b8c 100644 --- a/arch/powerpc/kernel/eeh.c +++ b/arch/powerpc/kernel/eeh.c @@ -1728,10 +1728,12 @@ static ssize_t eeh_force_recover_write(struct file *filp, struct pci_controller *hose; uint32_t phbid, pe_no; struct eeh_pe *pe; - char buf[20]; + char buf[20] = {}; int ret; - ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count); + ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf, count); + if (ret < 0) + return ret; if (!ret) return -EFAULT; From 4e6e66ecf62185828f731914000a6b0baff355db Mon Sep 17 00:00:00 2001 From: Amit Machhiwal Date: Thu, 15 Oct 2026 00:22:15 +0530 Subject: [PATCH 02/13] KVM: PPC: Book3S HV: Disable preemption around host-side HPT lock users A previous change ("KVM: PPC: Book3S HV: Add preempt_disable() around virtual-mode HPTE bit-lock users") at [1] added preempt_disable() around guest vCPU HPT hcalls and page fault handlers executed in virtual mode. This ensures vCPU threads cannot be preempted while holding HPTE_V_HVLOCK or the reverse-map lock. However, several host-side virtual-mode paths in book3s_64_mmu_hv.c also acquire HPTE_V_HVLOCK and lock_rmap() in process context with preemption enabled. Specifically, kvm_unmap_rmapp() and kvm_age_rmapp() take both locks during MMU notifier callbacks and memslot flushes, while resize_hpt_rehash_hpte() acquires HPTE_V_HVLOCK during HPT resizing. If a host thread is preempted while holding either bit-lock, any guest vCPU thread scheduled on the same CPU spinning for the same lock with preemption disabled will never yield, resulting in a permanent CPU hang. Fix this by disabling preemption across these host-side critical sections. For kvm_unmap_rmapp() and kvm_age_rmapp(), place preempt_disable() before lock_rmap() so that both the rmap chain lock and the subsequent HPTE_V_HVLOCK bit-lock are held under a single non-preemptible window. To preserve the ABBA lock ordering between the two locks, re-enable preemption after dropping the rmap lock on any retry or early-exit path before spinning on cpu_relax(), allowing the lock holder to be scheduled. For kvm_htab_write(), the HPT migration restore path, replace the direct calls to kvmppc_do_h_remove() with kvmppc_virtmode_do_h_remove(), a thin wrapper that brackets kvmppc_do_h_remove() with preempt_disable() and preempt_enable(), mirroring the existing kvmppc_virtmode_do_h_enter() helper. For resize_hpt_rehash_hpte(), place preempt_disable() before the try_lock_hpte() spin loop and preempt_enable() after unlock_hpte() at the function exit. [1] https://git.kernel.org/powerpc/c/abbbe5ff83e7c9ed3a4d61b73011f1df7bf87907 Fixes: 6165d5dd99db ("KVM: PPC: Book3S HV: add virtual mode handlers for HPT hcalls and page faults") Cc: stable@vger.kernel.org # v5.14+ Signed-off-by: Amit Machhiwal Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261014185215.71832-1-amachhiw@linux.ibm.com --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c index 00b8a3f855f4..97740173974c 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -47,6 +47,9 @@ static long kvmppc_virtmode_do_h_enter(struct kvm *kvm, unsigned long flags, long pte_index, unsigned long pteh, unsigned long ptel, unsigned long *pte_idx_ret); +static void kvmppc_virtmode_do_h_remove(struct kvm *kvm, unsigned long flags, + unsigned long pte_index, unsigned long avpn, + unsigned long *hpret); struct kvm_resize_hpt { /* These fields read-only after init */ @@ -308,6 +311,22 @@ static long kvmppc_virtmode_do_h_enter(struct kvm *kvm, unsigned long flags, } +/* + * Virtual-mode H_REMOVE. kvmppc_do_h_remove() is also called from real mode, + * where preempt_disable() is not usable, so the guard stays here. The function + * spins on HPTE_V_HVLOCK and then lock_rmap() (via remove_revmap_chain()); + * preemption must be disabled across both bit-locks so that spinning callers + * holding preempt_disable() can make forward progress. + */ +static void kvmppc_virtmode_do_h_remove(struct kvm *kvm, unsigned long flags, + unsigned long pte_index, unsigned long avpn, + unsigned long *hpret) +{ + preempt_disable(); + kvmppc_do_h_remove(kvm, flags, pte_index, avpn, hpret); + preempt_enable(); +} + static struct kvmppc_slb *kvmppc_mmu_book3s_hv_find_slbe(struct kvm_vcpu *vcpu, gva_t eaddr) { @@ -810,9 +829,11 @@ static void kvm_unmap_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn]; for (;;) { + preempt_disable(); lock_rmap(rmapp); if (!(*rmapp & KVMPPC_RMAP_PRESENT)) { unlock_rmap(rmapp); + preempt_enable(); break; } @@ -826,6 +847,7 @@ static void kvm_unmap_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, if (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) { /* unlock rmap before spinning on the HPTE lock */ unlock_rmap(rmapp); + preempt_enable(); while (be64_to_cpu(hptep[0]) & HPTE_V_HVLOCK) cpu_relax(); continue; @@ -834,6 +856,7 @@ static void kvm_unmap_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, kvmppc_unmap_hpte(kvm, i, memslot, rmapp, gfn); unlock_rmap(rmapp); __unlock_hpte(hptep, be64_to_cpu(hptep[0])); + preempt_enable(); } } @@ -890,6 +913,7 @@ static bool kvm_age_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn]; retry: + preempt_disable(); lock_rmap(rmapp); if (*rmapp & KVMPPC_RMAP_REFERENCED) { *rmapp &= ~KVMPPC_RMAP_REFERENCED; @@ -897,6 +921,7 @@ static bool kvm_age_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, } if (!(*rmapp & KVMPPC_RMAP_PRESENT)) { unlock_rmap(rmapp); + preempt_enable(); return ret; } @@ -912,6 +937,7 @@ static bool kvm_age_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, if (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) { /* unlock rmap before spinning on the HPTE lock */ unlock_rmap(rmapp); + preempt_enable(); while (be64_to_cpu(hptep[0]) & HPTE_V_HVLOCK) cpu_relax(); goto retry; @@ -931,6 +957,7 @@ static bool kvm_age_rmapp(struct kvm *kvm, struct kvm_memory_slot *memslot, } while ((i = j) != head); unlock_rmap(rmapp); + preempt_enable(); return ret; } @@ -1219,6 +1246,7 @@ static unsigned long resize_hpt_rehash_hpte(struct kvm_resize_hpt *resize, if (!(vpte & HPTE_V_VALID) && !(vpte & HPTE_V_ABSENT)) return 0; /* nothing to do */ + preempt_disable(); while (!try_lock_hpte(hptep, HPTE_V_HVLOCK)) cpu_relax(); @@ -1346,6 +1374,7 @@ static unsigned long resize_hpt_rehash_hpte(struct kvm_resize_hpt *resize, out: unlock_hpte(hptep, vpte); + preempt_enable(); return ret; } @@ -1868,7 +1897,7 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf, nb += HPTE_SIZE; if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT)) - kvmppc_do_h_remove(kvm, 0, i, 0, tmp); + kvmppc_virtmode_do_h_remove(kvm, 0, i, 0, tmp); err = -EIO; ret = kvmppc_virtmode_do_h_enter(kvm, H_EXACT, i, v, r, tmp); @@ -1897,7 +1926,7 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf, for (j = 0; j < hdr.n_invalid; ++j) { if (be64_to_cpu(hptp[0]) & (HPTE_V_VALID | HPTE_V_ABSENT)) - kvmppc_do_h_remove(kvm, 0, i, 0, tmp); + kvmppc_virtmode_do_h_remove(kvm, 0, i, 0, tmp); ++i; hptp += 2; } From d8c6ab0aeeca7cc2adfcf0ce1f796c6a86314ec0 Mon Sep 17 00:00:00 2001 From: Gautam Menghani Date: Mon, 12 Oct 2026 13:59:17 +0530 Subject: [PATCH 03/13] KVM: PPC: Book3S HV: Ensure that calls to idr_alloc are synchronized Calls to idr_alloc() in __prealloc_nested() are not currently synchronized. According to the documentation [1], the caller should provide their own locking to prevent concurrent modifications to the idr to prevent bugs. __prealloc_nested() calls idr_alloc() with GFP_KERNEL which can sleep and mmu_lock is a spinlock. So idr_alloc() cannot be moved under mmu_lock. In such cases the idr Documentation says: If you need to take a lock while allocating a new ID from the IDR, you may need to pass a restrictive set of GFP flags, which can lead to the IDR being unable to allocate memory. To work around this, you can call idr_preload() before taking the lock, and then idr_preload_end() after the allocation. Hence preload the idr memory with idr_preload() before taking mmu_lock, which allows us to use idr_alloc(..., GFP_NOWAIT) under the spinlock. This also allows to kill __prealloc_nested() and __add_nested(), as they are not needed anymore with idr_preload(). [1]: lib/idr.c Fixes: c0f00a18e2a8 ("KVM: PPC: Book3S HV Nested: Change nested guest lookup to use idr") Cc: stable@vger.kernel.org # 5.19+ Co-developed-by: Ritesh Harjani (IBM) Signed-off-by: Ritesh Harjani (IBM) Signed-off-by: Gautam Menghani Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261012082922.218799-2-gautam@linux.ibm.com --- arch/powerpc/kvm/book3s_hv_nested.c | 34 +++++++++-------------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c index a6ff42d7666c..e893fdd24f0a 100644 --- a/arch/powerpc/kvm/book3s_hv_nested.c +++ b/arch/powerpc/kvm/book3s_hv_nested.c @@ -702,20 +702,6 @@ static struct kvm_nested_guest *__find_nested(struct kvm *kvm, int lpid) return idr_find(&kvm->arch.kvm_nested_guest_idr, lpid); } -static bool __prealloc_nested(struct kvm *kvm, int lpid) -{ - if (idr_alloc(&kvm->arch.kvm_nested_guest_idr, - NULL, lpid, lpid + 1, GFP_KERNEL) != lpid) - return false; - return true; -} - -static void __add_nested(struct kvm *kvm, int lpid, struct kvm_nested_guest *gp) -{ - if (idr_replace(&kvm->arch.kvm_nested_guest_idr, gp, lpid)) - WARN_ON(1); -} - static void __remove_nested(struct kvm *kvm, int lpid) { idr_remove(&kvm->arch.kvm_nested_guest_idr, lpid); @@ -862,21 +848,21 @@ struct kvm_nested_guest *kvmhv_get_nested(struct kvm *kvm, int l1_lpid, if (!newgp) return NULL; - if (!__prealloc_nested(kvm, l1_lpid)) { - kvmhv_release_nested(newgp); - return NULL; - } - + idr_preload(GFP_KERNEL); spin_lock(&kvm->mmu_lock); gp = __find_nested(kvm, l1_lpid); if (!gp) { - __add_nested(kvm, l1_lpid, newgp); - ++newgp->refcnt; - gp = newgp; - newgp = NULL; + if (idr_alloc(&kvm->arch.kvm_nested_guest_idr, newgp, + l1_lpid, l1_lpid + 1, GFP_NOWAIT) >= 0) { + ++newgp->refcnt; + gp = newgp; + newgp = NULL; + } } - ++gp->refcnt; + if (gp) + ++gp->refcnt; spin_unlock(&kvm->mmu_lock); + idr_preload_end(); if (newgp) kvmhv_release_nested(newgp); From b9d9a8741752c5b42c65b1c8dffba867889b74e5 Mon Sep 17 00:00:00 2001 From: Gautam Menghani Date: Mon, 12 Oct 2026 13:59:18 +0530 Subject: [PATCH 04/13] KVM: PPC: Book3S HV: XICS: Update irq_type for cleanup to work In kvmppc_xive_connect_vcpu(), if any failures are encountered, the control flow jumps to the 'bail' label where kvmppc_xive_cleanup_vcpu() is called. This cleanup function exits prematurely since vcpu->arch.irq_type is set to KVMPPC_IRQ_DEFAULT at this point. This ends up resulting in wasted memory. Fix this by setting irq_type to KVMPPC_IRQ_XICS before vcpu configuration starts. This makes XICS initialization symmetrical to XIVE initialization done in kvmppc_xive_native_connect_vcpu(). Fixes: 5af50993850a ("KVM: PPC: Book3S HV: Native usage of the XIVE interrupt controller") Cc: stable@vger.kernel.org # 4.12+ Signed-off-by: Gautam Menghani Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261012082922.218799-3-gautam@linux.ibm.com --- arch/powerpc/kvm/book3s_xive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c index d348365df72d..72c89e820e2f 100644 --- a/arch/powerpc/kvm/book3s_xive.c +++ b/arch/powerpc/kvm/book3s_xive.c @@ -1939,6 +1939,7 @@ int kvmppc_xive_connect_vcpu(struct kvm_device *dev, xc->vp_id = vp_id; xc->mfrr = 0xff; xc->valid = true; + vcpu->arch.irq_type = KVMPPC_IRQ_XICS; r = xive_native_get_vp_info(xc->vp_id, &xc->vp_cam, &xc->vp_chip_id); if (r) @@ -2027,7 +2028,6 @@ bail: return r; } - vcpu->arch.irq_type = KVMPPC_IRQ_XICS; return 0; } From 7279692d70f3e399b3dd2d07ffa365e9f533761f Mon Sep 17 00:00:00 2001 From: Gautam Menghani Date: Mon, 12 Oct 2026 13:59:19 +0530 Subject: [PATCH 05/13] KVM: PPC: Book3S HV: XICS: Avoid NULL ptr deref in kvmppc_xive_cleanup_vcpu() In kvmppc_xive_connect_vcpu() if there is a failure before xc->vp_ipi_data is setup, it can result in a NULL pointer dereference in kvmppc_xive_cleanup_vcpu() when accessing the MMIO page in xive_vm_esb_load(). Fix this by adding a check before masking the VP IPI before accessing the MMIO pages. Fixes: 5af50993850a ("KVM: PPC: Book3S HV: Native usage of the XIVE interrupt controller") Cc: stable@vger.kernel.org # 4.12+ Signed-off-by: Gautam Menghani Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261012082922.218799-4-gautam@linux.ibm.com --- arch/powerpc/kvm/book3s_xive.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_xive.c b/arch/powerpc/kvm/book3s_xive.c index 72c89e820e2f..9d2039ee37b2 100644 --- a/arch/powerpc/kvm/book3s_xive.c +++ b/arch/powerpc/kvm/book3s_xive.c @@ -1820,7 +1820,8 @@ void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu) kvmppc_xive_disable_vcpu_interrupts(vcpu); /* Mask the VP IPI */ - xive_vm_esb_load(&xc->vp_ipi_data, XIVE_ESB_SET_PQ_01); + if (xc->vp_ipi_data.eoi_mmio) + xive_vm_esb_load(&xc->vp_ipi_data, XIVE_ESB_SET_PQ_01); /* Free escalations */ for (i = 0; i < KVMPPC_XIVE_Q_COUNT; i++) { From b04be22bf6ea06b92bff7850328a8057b8d964ae Mon Sep 17 00:00:00 2001 From: Gautam Menghani Date: Mon, 12 Oct 2026 13:59:20 +0530 Subject: [PATCH 06/13] KVM: PPC: Book3S HV: Take SRCU read lock around kvmppc_h_page_init() call Since there is no srcu read lock around kvmppc_h_page_init(), a "suspicious rcu_dereference_check() usage" can be triggered by running host linux with CONFIG_PROVE_RCU=y and the following code in the guest: plpar_hcall_norets(H_PAGE_INIT, H_ZERO_PAGE, phys_addr, 0); ============================= WARNING: suspicious RCU usage 7.0.0-dirty #227 Not tainted ----------------------------- ./include/linux/kvm_host.h:1074 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 1 lock held by qemu-system-ppc/2093: #0: c000000354197ab0 (&vcpu->mutex){+.+.}-{3:3}, at: kvm_vcpu_ioctl+0x10c/0xaf0 stack backtrace: CPU: 30 UID: 0 PID: 2093 Comm: qemu-system-ppc Not tainted 7.0.0-dirty #227 PREEMPT(full) Hardware name: IBM,9080-HEX POWER10 (architected) 0x800200 0xf000006 of:IBM,FW1060.60 (NH1060_158) hv:phyp pSeries Call Trace: [c00000033e1bf430] [c000000001b3dbd4] dump_stack_lvl+0xc8/0x130 (unreliable) [c00000033e1bf470] [c0000000003da964] lockdep_rcu_suspicious+0x1f4/0x290 [c00000033e1bf520] [c000000000231424] gfn_to_memslot+0x1b4/0x1c0 [c00000033e1bf560] [c00000000023637c] kvm_clear_guest+0x9c/0x110 [c00000033e1bf5c0] [c0000000002714a4] kvmppc_h_page_init+0x160/0x1a0 [c00000033e1bf610] [c00000000026c040] kvmppc_pseries_do_hcall+0x1930/0x1940 [c00000033e1bf6d0] [c00000000026fb18] kvmppc_vcpu_run_hv+0x268/0x800 [c00000033e1bf7a0] [c000000000246b30] kvmppc_vcpu_run+0x30/0x50 [c00000033e1bf7c0] [c000000000241ed4] kvm_arch_vcpu_ioctl_run+0x364/0x530 [c00000033e1bf860] [c00000000022b870] kvm_vcpu_ioctl+0x1b0/0xaf0 [c00000033e1bfa50] [c0000000009b4514] sys_ioctl+0x144/0x190 [c00000033e1bfab0] [c000000000034330] system_call_exception+0x170/0x370 [c00000033e1bfe50] [c00000000000d05c] system_call_vectored_common+0x15c/0x2ec Fix this by taking a srcu read lock around kvmppc_h_page_init(). Fixes: 2d34d1c3bbfd ("KVM: PPC: Book3S HV: Implement virtual mode H_PAGE_INIT handler") Cc: stable@vger.kernel.org # 5.2+ Signed-off-by: Gautam Menghani Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261012082922.218799-5-gautam@linux.ibm.com --- arch/powerpc/kvm/book3s_hv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 22283d46e8fe..7c4aa12bf606 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1388,9 +1388,11 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) ret = kvmhv_copy_tofrom_guest_nested(vcpu); break; case H_PAGE_INIT: + idx = srcu_read_lock(&kvm->srcu); ret = kvmppc_h_page_init(vcpu, kvmppc_get_gpr(vcpu, 4), kvmppc_get_gpr(vcpu, 5), kvmppc_get_gpr(vcpu, 6)); + srcu_read_unlock(&kvm->srcu, idx); break; case H_SVM_PAGE_IN: ret = H_UNSUPPORTED; From 9751c361cb234f000261879b1b5015bf08f6a428 Mon Sep 17 00:00:00 2001 From: Gautam Menghani Date: Mon, 2 Nov 2026 14:46:59 +0530 Subject: [PATCH 07/13] KVM: PPC: Book3S HV: Avoid spurious interrupts caused by LPCR_MER bit A huge number of spurious interrupts can be seen immediately after a KVM on PowerNV guest boots up in XIVE mode. $ cat /proc/interrupts | grep SPU SPU: 223705 192439 273526 147623 Spurious interrupts This bug was introduced by commit ecd10702baae5 ("KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE"). The root cause is that once LPCR_MER bit is set, it is supposed to be reset by software. But when a vCPU starts running with LPCR_MER set, the vCPU does not exit back to the host until the decrementer expires or there is an hcall, etc. This is because KVM on PowerNV guests have support for native XIVE, so they are not dependent on host for interrupt emulation. Due to this behaviour, a huge number of spurious interrupts are seen since LPCR_MER continues to be set and LPCR_MER cannot be reset until the vCPU exits to the host. Fix this behaviour by not using the LPCR_MER bit whenever native XIVE is available (currently in case of KVM on PowerNV only), as the XIVE hardware can present interrupts to the KVM guest vCPU directly. So the LPCR_MER functionality is not required. This reduces the number of spurious interrupts drastically. Fixes: ecd10702baae5 ("KVM: PPC: Book3S HV: Handle pending exceptions on guest entry with MSR_EE") Cc: stable@vger.kernel.org # 6.8+ Reported-by: Timothy Pearson Closes: https://lore.kernel.org/linuxppc-dev/582904882.11159.1786719390349.JavaMail.zimbra@raptorengineeringinc.com Signed-off-by: Gautam Menghani Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261102091700.253381-1-gautam@linux.ibm.com --- arch/powerpc/kvm/book3s_hv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 7c4aa12bf606..bafe9546087b 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -4986,7 +4986,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, if (!kvmhv_on_pseries() && (__kvmppc_get_msr_hv(vcpu) & MSR_EE)) kvmppc_inject_interrupt_hv(vcpu, BOOK3S_INTERRUPT_EXTERNAL, 0); - else + else if (!kvmppc_xive_enabled(vcpu)) lpcr |= LPCR_MER; } else { /* From 0a7ad2e55ff0de8c13dbe25aa87cecb0243b245e Mon Sep 17 00:00:00 2001 From: Christian Zigotzky A-EON Open Source Date: Sat, 24 Oct 2026 09:55:19 +0200 Subject: [PATCH 08/13] powerpc/pasemi: Defer Nemo IRQ initialization Since pas_pci_init() is now called later during boot, the i8259 initialization in pas_init_IRQ() happens too early and accesses registers that are not yet mapped, preventing the board from booting. Move the Nemo-specific i8259 initialization to pas_add_bridge(), after the ISA bridge has been discovered. Suggested-by: Darren Stevens Tested-by: Christian Zigotzky Signed-off-by: Christian Zigotzky A-EON Open Source Fixes: c144bc719234 ("powerpc/pasemi: Move PHB discovery") Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261024075519.18877-1-chzigotzky@xenosoft.de --- arch/powerpc/platforms/pasemi/pasemi.h | 6 ++++++ arch/powerpc/platforms/pasemi/pci.c | 5 +++++ arch/powerpc/platforms/pasemi/setup.c | 12 ++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/platforms/pasemi/pasemi.h b/arch/powerpc/platforms/pasemi/pasemi.h index 6f6743b8e48d..01bcfa258625 100644 --- a/arch/powerpc/platforms/pasemi/pasemi.h +++ b/arch/powerpc/platforms/pasemi/pasemi.h @@ -7,6 +7,12 @@ extern void pas_pci_init(void); struct pci_dev; extern void pas_pci_dma_dev_setup(struct pci_dev *dev); +#ifdef CONFIG_PPC_PASEMI_NEMO +void __init nemo_init_IRQ(void); +#else +static inline void __init nemo_init_IRQ(void) { } +#endif + void __iomem *__init pasemi_pci_getcfgaddr(struct pci_dev *dev, int offset); extern void __init pasemi_map_registers(void); diff --git a/arch/powerpc/platforms/pasemi/pci.c b/arch/powerpc/platforms/pasemi/pci.c index 2df955274652..fb53782da7ec 100644 --- a/arch/powerpc/platforms/pasemi/pci.c +++ b/arch/powerpc/platforms/pasemi/pci.c @@ -265,6 +265,11 @@ static int __init pas_add_bridge(struct device_node *dev) */ isa_bridge_find_early(hose); + /* + * ISA bridge is now active, add the i8259 cascade (if needed) + */ + nemo_init_IRQ(); + return 0; } diff --git a/arch/powerpc/platforms/pasemi/setup.c b/arch/powerpc/platforms/pasemi/setup.c index 45792ecd5dfd..7a961f2a228f 100644 --- a/arch/powerpc/platforms/pasemi/setup.c +++ b/arch/powerpc/platforms/pasemi/setup.c @@ -216,10 +216,12 @@ static void sb600_8259_cascade(struct irq_desc *desc) chip->irq_eoi(&desc->irq_data); } -static void __init nemo_init_IRQ(struct mpic *mpic) +void __init nemo_init_IRQ(void) { struct device_node *np; int gpio_virq; + struct mpic *mpic; + /* Connect the SB600's legacy i8259 controller */ np = of_find_node_by_path("/pxp@0,e0000000"); i8259_init(np, 0); @@ -230,14 +232,10 @@ static void __init nemo_init_IRQ(struct mpic *mpic) irq_set_chained_handler(gpio_virq, sb600_8259_cascade); mpic_unmask_irq(irq_get_irq_data(gpio_virq)); + mpic = irq_get_chip_data(gpio_virq); irq_set_default_domain(mpic->irqhost); } -#else - -static inline void nemo_init_IRQ(struct mpic *mpic) -{ -} #endif static __init void pas_init_IRQ(void) @@ -300,8 +298,6 @@ static __init void pas_init_IRQ(void) mpic_unmask_irq(irq_get_irq_data(nmi_virq)); } - nemo_init_IRQ(mpic); - of_node_put(mpic_node); of_node_put(root); } From 126b47221b7b98d83c118781ce724c0515d86d9c Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Mon, 9 Nov 2026 13:00:12 -0500 Subject: [PATCH 09/13] powerpc/smp: Handle of_property_count_u32_elems() error in parse_thread_groups() After commit 0af298e62e5c ("treewide: refresh kmalloc_obj() conversions"), there is a warning on boot for several PowerPC configurations in QEMU: WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0x174/0x1b0, CPU#0: swapper/0/1 Modules linked in: CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.4.0-rc1-00262-g0af298e62e5c #1 PREEMPT(lazy) NIP [c0000000006074e4] ___kmalloc_large_node+0x174/0x1b0 LR [c00000000060782c] __kmalloc_large_node_noprof+0x3c/0x150 Call Trace: ... [c00000000369fb60] [c000000000614ff0] __kmalloc_noprof+0x490/0x690 [c00000000369fbe0] [c000000000051308] _kzalloc_noprof.constprop.0+0x1c/0x74 [c00000000369fc00] [c00000000200b450] init_thread_group_cache_map+0xc0/0x2c4 ... In this case, of_property_count_u32_elems() returns -EINVAL because there is no "ibm,thread-groups" property. When kcalloc() was used to allocate thread_group_array, the multiplication overflow check in _kmalloc_array_noprof() caught that a really large allocation was requested (as -EINVAL was converted to size_t) and returned NULL. kzalloc_objs() has no such check, so the large allocation check in __kmalloc_large_noprof() triggers the visible warning above. Check if of_property_count_u32_elems() has returned an error and bail out if so, clearing up the warning. Fixes: 790a1662d3a2 ("powerpc/smp: Parse ibm,thread-groups with multiple properties") Signed-off-by: Nathan Chancellor Reviewed-by: Ritesh Harjani (IBM) Reviewed-by: Shrikanth Hegde Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261109-powerpc-smp-handle-count-err-v1-1-e777fde7f71a@kernel.org --- arch/powerpc/kernel/smp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index 7a25eaa59e62..58824f5f4c80 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -824,6 +824,8 @@ static int parse_thread_groups(struct device_node *dn, int i = 0; count = of_property_count_u32_elems(dn, "ibm,thread-groups"); + if (count < 0) + return count; thread_group_array = kzalloc_objs(u32, count); if (!thread_group_array) return -ENOMEM; From 6648db997a0b8223fefbee3b4d5391c0d90d0422 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Tue, 3 Nov 2026 18:23:07 -0500 Subject: [PATCH 10/13] selftests/powerpc: override EMIT_TESTS instead of the emit_tests rule The powerpc Makefiles include lib.mk and then define their own emit_tests rule, so every selftests build that includes powerpc warns, on any architecture: Makefile:60: warning: overriding recipe for target 'emit_tests' ../lib.mk:183: warning: ignoring old recipe for target 'emit_tests' lib.mk used to keep the recipe in an EMIT_TESTS variable that Makefiles could override, as they still do with RUN_TESTS, INSTALL_RULE and CLEAN. Commit d4e59a536f50 ("selftests: Use runner.sh for emit targets") dropped the variable, and commit 58b33e78a317 ("selftests/powerpc: Fix emit_tests to work with run_kselftest.sh") then replaced the powerpc EMIT_TESTS definitions with rules. Bring EMIT_TESTS back in lib.mk and override it in the powerpc Makefiles again. Mark the lib.mk recipe with '+', so that the powerpc sub-makes still get the jobserver, as they did when $(MAKE) was in the rule itself. The emitted test lists don't change. Fixes: 58b33e78a317 ("selftests/powerpc: Fix emit_tests to work with run_kselftest.sh") Signed-off-by: Sasha Levin Acked-by: Michael Ellerman Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261103232307.1924618-3-sashal@kernel.org --- tools/testing/selftests/lib.mk | 6 +++++- tools/testing/selftests/powerpc/Makefile | 3 ++- tools/testing/selftests/powerpc/pmu/Makefile | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 881f13ee2c8a..506cb26510e4 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -179,11 +179,15 @@ else $(error Error: set INSTALL_PATH to use install) endif -emit_tests: +define EMIT_TESTS for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo "$(COLLECTION):$$BASENAME_TEST"; \ done +endef + +emit_tests: + +$(EMIT_TESTS) # define if isn't already. It is undefined in make O= case. ifeq ($(RM),) diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile index b175e94e1901..aeab9366d09b 100644 --- a/tools/testing/selftests/powerpc/Makefile +++ b/tools/testing/selftests/powerpc/Makefile @@ -56,11 +56,12 @@ override define INSTALL_RULE done; endef -emit_tests: +override define EMIT_TESTS +@for TARGET in $(SUB_DIRS); do \ BUILD_TARGET=$(OUTPUT)/$$TARGET; \ $(MAKE) OUTPUT=$$BUILD_TARGET COLLECTION=$(COLLECTION)/$$TARGET -s -C $$TARGET $@;\ done; +endef override define CLEAN +@for TARGET in $(SUB_DIRS); do \ diff --git a/tools/testing/selftests/powerpc/pmu/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile index 7e9dbf3d0d09..3aca10223f0f 100644 --- a/tools/testing/selftests/powerpc/pmu/Makefile +++ b/tools/testing/selftests/powerpc/pmu/Makefile @@ -37,7 +37,7 @@ override define RUN_TESTS done; endef -emit_tests: +override define EMIT_TESTS for TEST in $(TEST_GEN_PROGS); do \ BASENAME_TEST=`basename $$TEST`; \ echo "$(COLLECTION):$$BASENAME_TEST"; \ @@ -46,6 +46,7 @@ emit_tests: BUILD_TARGET=$(OUTPUT)/$$TARGET; \ $(MAKE) OUTPUT=$$BUILD_TARGET COLLECTION=$(COLLECTION)/$$TARGET -s -C $$TARGET emit_tests; \ done; +endef DEFAULT_INSTALL_RULE := $(INSTALL_RULE) override define INSTALL_RULE From d513ec3c907b067d4a32b14ec6f73c3e041cb136 Mon Sep 17 00:00:00 2001 From: "Luiz Capitulino (Red Hat)" Date: Tue, 3 Nov 2026 22:40:18 -0500 Subject: [PATCH 11/13] powerpc/watchdog: disable watchdog when watchdog_thresh=0 On powerpc, trying to disable the hardlockup detector with: # echo 0 > /proc/sys/kernel/watchdog_thresh causes an immediate and endless hardlockup detection, eventually leading to an unusable system (splat example below). This happens because watchdog_calc_timeouts() sets wd_timer_period_ms, wd_panic_timeout_tb and wd_smp_panic_timeout_tb to zero, but start_watchdog() still starts the timer (with expiry=0) in this code path: proc_watchdog_thresh() proc_watchdog_update() __lockup_detector_reconfigure() watchdog_hardlockup_start() start_watchdog_on_cpu() start_watchdog() hrtimer_start() /* wd_timer_period_ms=0 */ However, according to Documentation/admin-guide/sysctl/kernel.rst, setting watchdog_thresh=0 should disable both the soft and hard lockup detectors. This condition is already checked in __lockup_detector_reconfigure() for the soft lockup detector and the arch-independent hardlockup detector, what's missing is powerpc performing the same check in start_watchdog(). [ 278.110085] watchdog: CPU 0 detected hard LOCKUP on other CPUs 1 [ 278.110086] watchdog: CPU 1 became unstuck TB:33050716089564575 [ 278.110097] CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Kdump: loaded Tainted: G E 7.4.0-rc1 #1 PREEMPT(full) [ 278.110103] watchdog: CPU 0 TB:33050716089564185, last SMP heartbeat TB:33050716089563885 (0ms ago) [ 278.110109] Tainted: [E]=UNSIGNED_MODULE [ 278.110126] Hardware name: IBM,8375-42A POWER9 (architected) 0x4e0202 0xf000005 of:IBM,FW940.00 (VL940_027) hv:phyp pSeries [ 278.110136] NIP: c0000000001bd518 LR: c0000000014dedf8 CTR: 0000000000000000 [ 278.110145] REGS: c000000004b17a80 TRAP: 0900 Tainted: G E (7.4.0-rc1) [ 278.110155] MSR: 800000000280b033 CR: 22000224 XER: 20040004 [ 278.110189] CFAR: 0000000000000000 IRQMASK: 0 GPR00: 0000000000000000 c000000004b17d20 c000000001c38100 0000000000000000 GPR04: 000000000000ffff 0000000000000000 0000000000000000 0000000000000000 GPR08: 0000000000000000 0000000000000080 0000000000000080 ffffffffffffffff GPR12: 0000000000000000 c000000017fff300 0000000000000000 000000002ef3d820 GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000001 GPR24: 0000000000000001 00000040c0a6075e 0000000000000000 0000000000000001 GPR28: c0000001fdb5b140 0000000000000001 c000000002291968 c000000002291970 [ 278.110306] NIP [c0000000001bd518] plpar_hcall_norets_notrace+0x18/0x2c [ 278.110319] LR [c0000000014dedf8] check_and_cede_processor+0x48/0x60 [ 278.110333] Call Trace: [ 278.110338] [c000000004b17d20] [c000000004b17dd0] 0xc000000004b17dd0 (unreliable) [ 278.110354] [c000000004b17d80] [c0000000014df020] shared_cede_loop+0x70/0x170 [ 278.110367] [c000000004b17dc0] [c0000000014de460] cpuidle_enter_state+0x2f0/0x748 [ 278.110381] [c000000004b17e70] [c000000000fe43b8] cpuidle_enter+0x48/0x70 [ 278.110397] [c000000004b17eb0] [c0000000002cdcf8] call_cpuidle+0x48/0x90 [ 278.110409] [c000000004b17ed0] [c0000000002d6300] cpuidle_idle_call+0x160/0x2d0 [ 278.110422] [c000000004b17f20] [c0000000002d6578] do_idle+0x108/0x1f0 [ 278.110434] [c000000004b17f60] [c0000000002d6938] cpu_startup_entry+0x48/0x50 [ 278.110446] [c000000004b17f90] [c0000000000615c0] start_secondary+0x290/0x2a0 [ 278.110459] [c000000004b17fe0] [c00000000000e258] start_secondary_prolog+0x10/0x14 Fixes: 2104180a5369 ("powerpc/64s: implement arch-specific hardlockup watchdog") Cc: stable@vger.kernel.org Signed-off-by: Luiz Capitulino (Red Hat) Reviewed-by: Michael Ellerman Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261104034018.2676750-1-luiz.capitulino@linux.dev --- arch/powerpc/kernel/watchdog.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/kernel/watchdog.c b/arch/powerpc/kernel/watchdog.c index 582ee3fd71c1..44f178e07531 100644 --- a/arch/powerpc/kernel/watchdog.c +++ b/arch/powerpc/kernel/watchdog.c @@ -487,6 +487,9 @@ static void start_watchdog(void *arg) if (!(watchdog_enabled & WATCHDOG_HARDLOCKUP_ENABLED)) return; + if (!watchdog_thresh) + return; + if (!cpumask_test_cpu(cpu, &watchdog_cpumask)) return; From dc6eb6f08be536223e8289c7a8b1f515b1355721 Mon Sep 17 00:00:00 2001 From: Bradley Morgan Date: Wed, 23 Sep 2026 17:56:31 +0000 Subject: [PATCH 12/13] powerpc32/modules: Reserve a PLT entry for ftrace_regs_caller Commit 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") made count_relocs() undercount the PLT entries the loader consumes: module_finalize_ftrace() now creates two trampolines (mod->arch.tramp for ftrace_caller() and mod->arch.tramp_regs for ftrace_regs_caller()), while count_relocs() reserves only one entry for ftrace. So the core .plt ends up one ppc_plt_entry (16 bytes) short. The walk in do_plt_call() scans for a free slot with "while (entry->jump[0])" and has no bound check, so once the last reserved slot is used up, the walk steps past the end of the section and patch_instruction() writes the 4-instruction trampoline into whatever module memory follows the .plt. Count the second entry, mirroring what module_64.c does for the same pair of stubs. Signed-off-by: Bradley Morgan Fixes: 7dfbfb87c243 ("powerpc/ftrace: Activate HAVE_DYNAMIC_FTRACE_WITH_REGS on PPC32") Reviewed-by: Christophe Leroy (CS GROUP) Cc: stable@vger.kernel.org Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20260923175631.235276-1-brads@mainlining.org --- arch/powerpc/kernel/module_32.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c index f930e3395a7f..61152deffc55 100644 --- a/arch/powerpc/kernel/module_32.c +++ b/arch/powerpc/kernel/module_32.c @@ -41,6 +41,9 @@ static unsigned int count_relocs(const Elf32_Rela *rela, unsigned int num) #ifdef CONFIG_DYNAMIC_FTRACE _count_relocs++; /* add one for ftrace_caller */ +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + _count_relocs++; /* add one for ftrace_regs_caller */ +#endif #endif return _count_relocs; } From 9500416c8aa7c271b85be6a0d5856da62b60223a Mon Sep 17 00:00:00 2001 From: Mohammad Shahid Date: Mon, 2 Nov 2026 20:07:19 +0530 Subject: [PATCH 13/13] powerpc/perf/vpa-dtl: use GFP_ATOMIC for DTL buffer allocation The DTL buffer is allocated while holding dtl_global_lock, which is spinlock. GFP_KERNEL allow direct memory reclaim and may sleep. Combining GFP_KERNEL with GFP_ATOMIC does not remove the direct reclaim. Use GFP_ATOMIC alone to ensure the allocation does not sleep while the spinlock is held. The issue is reported by script coccinelle call_kern.cocci. Signed-off-by: Mohammad Shahid Fixes: 4708fba19ade ("powerpc/vpa_dtl: Add interface to expose vpa dtl counters via perf") Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20261102143719.165508-1-mdshahid03@gmail.com --- arch/powerpc/perf/vpa-dtl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/perf/vpa-dtl.c b/arch/powerpc/perf/vpa-dtl.c index 3e3d65b6c796..3d34417e6aae 100644 --- a/arch/powerpc/perf/vpa-dtl.c +++ b/arch/powerpc/perf/vpa-dtl.c @@ -338,7 +338,7 @@ static int vpa_dtl_mem_alloc(int cpu) if (!dtl_cache) return -ENOMEM; - buf = kmem_cache_alloc_node(dtl_cache, GFP_KERNEL | GFP_ATOMIC, cpu_to_node(cpu)); + buf = kmem_cache_alloc_node(dtl_cache, GFP_ATOMIC, cpu_to_node(cpu)); if (!buf) { pr_warn("buffer allocation failed for cpu %d\n", cpu); return -ENOMEM;