From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 092EE4AB3CF; Mon, 28 Sep 2026 11:37:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790595463; cv=none; b=INW8OJaUtqsiaWkIuIJ2EEg7OuT9EBHe6XNDIOhH3TQUIEbMmQsi9hs9kOSTGRYUhiKUR0Aee8N68bQMzGEHu+xd/GTsu2f4U5C89G78o4kfo9/o66aklnS8tox+hIr+AFs8jfU/uRM1MQKsdNg72ehG6DhVIcwRW0E0EdWDwaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790595463; c=relaxed/simple; bh=GvP7G2PSnXIoSImaFHhXEd072q2Cp+mwExuu4yGceO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VrC75AFDmFze0zOPk2c/GLaGDSl/CZTaa8zcjJMb2Epli+1Y228hQjVXGTzZiDRtxd79w2QkuW/E7Pd/Yo8oYSwkCkcAJmXOhAFGsObVjs+HlvHYXrNBMFhJ1GJAHysIY9AoA2QdoDkTQaAfRAXVysWwErOtkbTwzDzrQmLtb3M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=ZoJ4Y775; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="ZoJ4Y775" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68SBZUkI3374979; Mon, 28 Sep 2026 11:37:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=daJyeZajojOGLh8il E00SNT0arUWx6DSIzy/uQ+v/6g=; b=ZoJ4Y775I1AzaLdlHvvdUSVpkq0wFkEkl 5Pw5FeXLz2ZVkAoJvQY5EF657Pn+xAXVssgxUsj+bvzfNkmGqN+WlA1OZ0XVb02X SG7Uzg7oIiZ21VmuvHjjwbEO4uM5ahcpVgEFtr9sBIeODXCpwB5JxcNzGgtts5xN +3ckPApDkhIqLp6R8qbey+Gumrjmq6N63tAS6i9jwcMdRbB1ItRXft4RLL+OUKcn 8N8VL8ihMZOOxf0YWQRttgAolNPYS6L2lwnP+FA73UHfDITn+AMbtsswNRQQZOSP 70FyRbd4CT5nkhSz0kjdxPGv1LqC+IZscZQQbfcIb3YqIOx+XNsFQ== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gx5qr0yyn-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 28 Sep 2026 11:37:28 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68SBHrj3076671; Mon, 28 Sep 2026 11:37:28 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gxsvhcxw0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Sep 2026 11:37:27 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68SBbODG43712826 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Sep 2026 11:37:24 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA84E2004B; Mon, 28 Sep 2026 11:37:23 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA45320040; Mon, 28 Sep 2026 11:37:19 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.213.32]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 28 Sep 2026 11:37:19 +0000 (GMT) From: Amit Machhiwal To: Madhavan Srinivasan , linuxppc-dev@lists.ozlabs.org Cc: Amit Machhiwal , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , "Ritesh Harjani (IBM)" , Shrikanth Hegde , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Gautam Menghani , Harsh Prateek Bora , R Nageswara Sastry , Alexander Graf , linux-hardening@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/3] KVM: PPC: Book3S HV: Add preempt_disable() around virtual-mode HPTE bit-lock users Date: Mon, 28 Sep 2026 17:07:02 +0530 Message-ID: <20260928113704.48912-2-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260928113704.48912-1-amachhiw@linux.ibm.com> References: <20260928113704.48912-1-amachhiw@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTI4MDA0NiBTYWx0ZWRfX1OGsw7KVqYB1 HcCtJUn974+6W+URq4QLMgiGGc/ISA1n4XiulJFiJ7nLZy4efUlScTIVgvgwHYP14ohZSD19xPo JdBzb6ibdxnK+zp/I5BRwREoa0Sqt50ht2LImKOHcqNhfnEEB0w+/NW1NmsazKCXsI9XnUXHSRl XVBRmslcx6uuYBYuuajmqkY66gVwdcp7D0OHqb4ibA/5sVbZ+268BUesP/Lf1ewrlNTvdRUMzO0 zu7BxTCY9eyik4HHOEbDcr+akzjTiWlmWVlQj16YGisJf6FJxiAHDnlKcM8OaAlpCfeZv+G2vFk 3EoMdxbPlF36ChtRyoza+FuDs2NlMmhxCec1Voqjy6HWs4dGTDB4Ps3pdfNOcUXMY96SGzXDUI3 rn66FV6u5AiEDywl5y8FSHgOzvnbe9NRAGlm/SETHJzW0P+ylW4p1lXd8Y69FtDZnKdUuOyu4UI 3QPGV3QHpFiIUOSgj7w== X-Authority-Analysis: v=2.4 cv=SPbXx+vH c=1 sm=1 tr=0 ts=6aba5179 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=u-HXxruZ6MoSruA0XqgA:9 X-Proofpoint-ORIG-GUID: ADm22fkfSgfbafxC0YLIktbEV8yuzGX9 X-Proofpoint-Spam-Info: AW1haW4tMjYwOTI4MDA0NiBTYWx0ZWRfX1f41Hil1LDQ0 kAMDlQihwx/foy/HA5eYmCqbZEwbtpcOHz91ZUiDe3ESYLwjOTqkg1shelDIP0dSjeLJw5zSw1y ispUE7ejwcU1QJW7OPevxnlf2wj+OeM= X-Proofpoint-GUID: LnBMfUHgCHDaSucEpd61V4zdVmXLftoD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-28_03,2026-09-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 bulkscore=0 impostorscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609280046 kvmppc_hv_find_lock_hpte() requires virtual-mode callers to run with preemption disabled, because it can return with HPTE_V_HVLOCK still held until the caller later unlocks the HPTE. Existing virtual-mode callers in book3s_64_mmu_hv.c already follow that rule. Two virtual-mode call paths do not: 1. kvmppc_handle_exit_hv() calls kvmppc_hpte_hv_fault() for hash-mode data-side and instruction-side faults after guest exit, with preemption already enabled. kvmppc_hpte_hv_fault() calls kvmppc_hv_find_lock_hpte() directly. 2. kvmppc_pseries_do_hcall() executes virtual-mode handlers for HPT hcalls via kvmppc_pseries_do_hpt_hcall() with preemption enabled. The handlers for H_ENTER, H_REMOVE, H_READ, H_CLEAR_MOD, H_CLEAR_REF, H_PROTECT, and H_BULK_REMOVE spin on try_lock_hpte() or lock_rmap(), and H_ENTER also reaches kvmppc_do_h_enter(), which uses arch_spin_lock() on kvm->mmu_lock. That raw lock choice is intentional because kvmppc_do_h_enter() is also used by real-mode callers, so the correct fix is to establish the proper preemption context at the virtual-mode caller boundary. If a vCPU thread is preempted while holding HPTE_V_HVLOCK, any other thread on the same CPU trying to acquire the same bit-lock can spin indefinitely. The same applies to lock_rmap() users and to the H_ENTER path while holding the raw mmu_lock. Fix this by adding preempt_disable()/preempt_enable() pairs around the two kvmppc_hpte_hv_fault() call sites in kvmppc_handle_exit_hv(), and around the kvmppc_pseries_do_hpt_hcall() invocation in kvmppc_pseries_do_hcall(). Targeting only the HPT hcall helper avoids wrapping non-HPT hcalls (such as H_RTAS, H_CONFER, H_REGISTER_VPA) that perform page faults, blocking memory allocations, or context switches. 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 --- arch/powerpc/kvm/book3s_hv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index aa51968e206a..52f72f30baf0 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1212,9 +1212,11 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu) case H_CLEAR_REF: case H_PROTECT: case H_BULK_REMOVE: + preempt_disable(); idx = srcu_read_lock(&kvm->srcu); ret = kvmppc_pseries_do_hpt_hcall(vcpu, req); srcu_read_unlock(&kvm->srcu, idx); + preempt_enable(); if (ret == H_TOO_HARD) return RESUME_HOST; break; @@ -1834,8 +1836,10 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu, else vsid = vcpu->arch.fault_gpa; + preempt_disable(); err = kvmppc_hpte_hv_fault(vcpu, vcpu->arch.fault_dar, vsid, vcpu->arch.fault_dsisr, true); + preempt_enable(); if (err == 0) { r = RESUME_GUEST; } else if (err == -1 || err == -2) { @@ -1881,8 +1885,10 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu, else vsid = vcpu->arch.fault_gpa; + preempt_disable(); err = kvmppc_hpte_hv_fault(vcpu, vcpu->arch.fault_dar, vsid, vcpu->arch.fault_dsisr, false); + preempt_enable(); if (err == 0) { r = RESUME_GUEST; } else if (err == -1) { -- 2.54.0 (Apple Git-157)