From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796389358; b=wJpi2fIkINLlt4TKESvoZ3P6k7ck4ymsWMtaNg3UyaxHCzEPR2S+FK4OrVKzVO6lxG2n Y/RtHr/xif9Kjxtlu+LQW+e2mg7NkKYh1e4xGTKxeX0KAQjBoF66yJRsIzBsWOp5MYS0G h++GaeKSkzDdvYRbH2oN08s8cWmSJ4iFvtlyS0L2LyvL4Xgnm4NC7wEz2UrqlhVIBWVeu AL13nrcqwo1D1ZwuIwK2ni7Iy84XQqihYNDUOOrZJN8y4FznYdETUqPNPXkvwX0lNdMSg EH3AkWlhERCFw/iPPCEg4281PIQQlOa1PymY+K0KpYbWHi6cQTA0s/aJJcD71Ox+yPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389358; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=k5r4cCuz5NxQpikfx2XvlZUqZg3HXnQZJz02U077lbs=; b=hgxODgehspoWZmS6gI5Mlk0GoQ6u14Ucrb5EUUZ4+i6ASRs6R4wvkfPszIA1y83hgYrY pMSb76AEYz3YmoGwbbmMYLG8i+cxhaEZTbSi+OCx9Pemgn8UnBvWIy4rPImdICqVdwZx4 PjdvENYjoco+7VTxl6KOtyK+TbIUKhWJDR+uIwMkYBnvzK+YAFhVC7aax8yobx2zS/SR4 ppLa5cXBaStYU7GicpwkZi8SKxqWe9IWjd0YOn0bZ72QLq0oOXqk56G5l1We37OLwoFcj sQGjFvJi5PWQ+hAnhc4OHgLj/W7tUe+1NUhcWmq9cqsA7KFeMITI2bFatVJU1T5uYxA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="hT/zkXGQ"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AA49606A336; Fri, 4 Dec 2026 13:02:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hT/zkXGQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80A371F00A06; Fri, 4 Dec 2026 13:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389357; bh=k5r4cCuz5NxQpikfx2XvlZUqZg3HXnQZJz02U077lbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hT/zkXGQlqLs0my66ih/FaEr5efG2fr91aQfGmVGrMgAJPNd6S8+FnVikzFjtkeDp qnsvWzEHD6CxI1Gsgl9AWW9mEGvO/uS8/kjgWgZBihgu+O1AHVDEfa3KUSn2+Dahzf 2znoNomEjhv0ljEQA59S2Vl2E5s83ll2HxAwtJws= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Amit Machhiwal , "Ritesh Harjani (IBM)" , Madhavan Srinivasan Subject: [PATCH 6.1 0961/1059] KVM: PPC: Book3S HV: Disable preemption around host-side HPT lock users Date: Fri, 4 Dec 2026 19:08:12 +0900 Message-ID: <20261204100708.909878188@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amit Machhiwal commit 4e6e66ecf62185828f731914000a6b0baff355db upstream. 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 Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kvm/book3s_64_mmu_hv.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c @@ -46,6 +46,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 */ @@ -307,6 +310,22 @@ static long kvmppc_virtmode_do_h_enter(s } +/* + * 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) { @@ -812,9 +831,11 @@ static void kvm_unmap_rmapp(struct kvm * 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; } @@ -828,6 +849,7 @@ static void kvm_unmap_rmapp(struct kvm * 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; @@ -836,6 +858,7 @@ static void kvm_unmap_rmapp(struct kvm * kvmppc_unmap_hpte(kvm, i, memslot, rmapp, gfn); unlock_rmap(rmapp); __unlock_hpte(hptep, be64_to_cpu(hptep[0])); + preempt_enable(); } } @@ -892,6 +915,7 @@ static bool kvm_age_rmapp(struct kvm *kv rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn]; retry: + preempt_disable(); lock_rmap(rmapp); if (*rmapp & KVMPPC_RMAP_REFERENCED) { *rmapp &= ~KVMPPC_RMAP_REFERENCED; @@ -899,6 +923,7 @@ static bool kvm_age_rmapp(struct kvm *kv } if (!(*rmapp & KVMPPC_RMAP_PRESENT)) { unlock_rmap(rmapp); + preempt_enable(); return ret; } @@ -914,6 +939,7 @@ static bool kvm_age_rmapp(struct kvm *kv 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; @@ -933,6 +959,7 @@ static bool kvm_age_rmapp(struct kvm *kv } while ((i = j) != head); unlock_rmap(rmapp); + preempt_enable(); return ret; } @@ -1233,6 +1260,7 @@ static unsigned long resize_hpt_rehash_h 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(); @@ -1360,6 +1388,7 @@ static unsigned long resize_hpt_rehash_h out: unlock_hpte(hptep, vpte); + preempt_enable(); return ret; } @@ -1882,7 +1911,7 @@ static ssize_t kvm_htab_write(struct fil 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); @@ -1912,7 +1941,7 @@ static ssize_t kvm_htab_write(struct fil 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; }