From nobody Fri Jun 12 18:34:01 2026 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 6EC063914E2; Wed, 13 May 2026 10:08:37 +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=1778666921; cv=none; b=ovpEa67rnFN2wTyW6D6jfRLofnXkGLyKiCq0+sxopmNpr4JSpZDy+wSRslNozOUJRyAAlJoMNFmpJu165zstT6jtgdhCq6DSBo+kfSoP5rxcrZd0CzeDPdLDuMWhBcHLoalmyLBO3qyT+XUmhadu+7sq56XrqR8+O9/3s5BNvyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666921; c=relaxed/simple; bh=U7tF20pssz6me+fheOnlK6BHi1qvp3Lu2OPMgCaxh0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ut6jzPdjDWJSPohYaUmfXSwAyXcE4M+77w9R4CF/sK3WyyMEmfrZgsJ0e/12jBgslIotq6ULIOt7XzR9n5oGrOAbSMKmATWctH7U4/Q544yq64eht+H/PNVzqiPYLn9jIS/Pxu/6X0aF2FcYbkGV7NNIUeMXjOLSp/jMBDjBMWM= 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=Y4zNzKab; 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="Y4zNzKab" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64D2WbKl3185718; Wed, 13 May 2026 10:08:27 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=fHOsSxshys3nROBe3 I3bMAVl02Qok1BmG9nH1qsqhQc=; b=Y4zNzKabRJC0EPjW4LjDjFeYyYUilmwJz /TuEx+h8W0HsIr91DliPJcRzKJ5Dxgj4RaowoqccL1IRx1wO1rCBeqLiDQ7RjEOg l4zjlW7pVgDbpw/8AQ637QYkiBNq3BAXBzotQKFKytHPLGKY7a52YhTpHFHK2MAu gbpBKJZEsbeSbMANV2UC5/rS2sPGDgie2tyJgcGfu9yR4T36ZfF5kvyHIeJVTvGK ENLo6gaa8kH+8pn0UFuw0eewaA9aY9gepBAvmLndEYDUeUFYV5WaraBQ5NbL9DKc U54+B4gf9ZzNUJtaYVOqmZe4EiB8pv7nH7nqUIoqXYRT71NctndPA== 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 4e3nv5f65d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:27 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64D9sQ5H017710; Wed, 13 May 2026 10:08:26 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgq7ta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:26 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64DA8MiY23331106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2026 10:08:22 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 559AA2006C; Wed, 13 May 2026 10:08:22 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FC222004E; Wed, 13 May 2026 10:08:20 +0000 (GMT) Received: from mac.bl1-in.ibm.com (unknown [9.123.0.51]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 May 2026 10:08:20 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Amit Machhiwal , Vaibhav Jain , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode Date: Wed, 13 May 2026 15:37:50 +0530 Message-ID: <20260513100755.83215-2-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513100755.83215-1-amachhiw@linux.ibm.com> References: <20260513100755.83215-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=cPHQdFeN c=1 sm=1 tr=0 ts=6a044d9b cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=9nGdcix9NZkGgJ1vRr8A:9 X-Proofpoint-ORIG-GUID: UOi0TGmF9l-2LvZA5Sn0gQfMb8zVuClu X-Proofpoint-GUID: WE_86_NKnGijjWFHy_BtKp0_fF5mPlzq X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEzMDEwNSBTYWx0ZWRfXyya9usxCm8iP sagDQDo12e/XYQuntprat5e03gr4jSf1gb6vk6TPpnnUi1b6dfFMuEOTiRYMEs9sP1Cnyjp5Gdv 2rjB9E76KJODVK4Ax9YyYgtzNkqj/EOtn7FEe5yka8cb60yDs9y7SVhDTSyWhTPvjo92pOIXXZN qLg2VoTLJZgMSetLxFTj/nUZyisJV7wyp6XZTt3/wmjsqC5IQQp94zPb/JmtN88Lp6s6vWPEYan KDk+VzK4w4L4VZyFVtK5H9/+8bHZVLX5DrZt8BKskHWZDwo8D+nqQIxnyJUOzDIc6w3RQhu8wJh gRgJ+IIy2aSjXf9Zz4jTdrWaorkiocVd7dXA/CkT0sPfY6S26nuZw3ka588S8KSlID6mwAOO2df BHYvTnWmYk0/HZBl8X2rw5WC9n64vTIKJGCzrwwzuJxnnCBsWIz/M1LpDHDHfUAJhP5/fgquHlI a4qVQEzeRTMH43F/8hw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 spamscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605130105 Content-Type: text/plain; charset="utf-8" On IBM POWER systems, newer processor generations can operate in compatibility modes corresponding to earlier generations. This becomes relevant for nested virtualization, where nested KVM guests may need to run with a specific processor compatibility level. Currently, when running a nested KVM guest (L2) inside a Power11 pSeries logical partition (L1) booted in Power10 compatibility mode, the guest fails to boot while setting 'arch_compat'. This happens because the CPU class is derived from the hardware PVR (via mfspr()), which reflects the physical processor generation (Power11), rather than the effective compatibility mode (Power10). As a result, userspace may request a Power11 arch_compat for the L2 guest. However, the L1 partition, running in Power10 compatibility, has only negotiated support up to Power10 with the Power Hypervisor (L0). When H_SET_STATE is invoked with a Power11 Logical PVR, the hypervisor rejects the request, leading to a late guest boot failure: KVM-NESTEDv2: couldn't set guest wide elements [..KVM reg dump..] This situation should be detected earlier. Rejecting unsupported 'arch_compat' values in 'kvmppc_set_arch_compat()' avoids issuing an invalid H_SET_STATE hcall and provides a clearer failure mode. Add a check to reject Power11 'arch_compat' requests when the host is running in Power10 compatibility mode, returning -EINVAL early instead of deferring the failure to the hypervisor. Signed-off-by: Amit Machhiwal Tested-by: Anushree Mathur --- arch/powerpc/kvm/book3s_hv.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 61dbeea317f3..249d1f2e4e2c 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -446,7 +446,19 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcp= u, u32 arch_compat) guest_pcr_bit =3D PCR_ARCH_300; break; case PVR_ARCH_31: + guest_pcr_bit =3D PCR_ARCH_31; + break; case PVR_ARCH_31_P11: + /* + * Need to check this for ISA 3.1, as Power10 and + * Power11 share the same PCR. For any subsequent ISA + * versions, this will be taken care of by the guest vs + * host PCR comparison below. + */ + if ((PVR_ARCH_31 & cur_cpu_spec->pvr_mask) =3D=3D + cur_cpu_spec->pvr_value) { + return -EINVAL; + } guest_pcr_bit =3D PCR_ARCH_31; break; default: --=20 2.50.1 (Apple Git-155) From nobody Fri Jun 12 18:34:01 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 66A49390CBA; Wed, 13 May 2026 10:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666947; cv=none; b=JaIWkz4pxn80Qbv2PqSXYnjNqxGjKRlZ7SbzxYE8BI02hxgYbBnqZh/D9PXOu+6u9hRqWtm3b6VlSVnhZI7xNkHEnrxyjifWn+jCqTyFh+vI17VQZU8KGWrDVOOxcrvlJXNRhOOFmjDp5zbGN01ONqSIJU5LHm9dL1EmrH6FxcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666947; c=relaxed/simple; bh=KIHGD5xHsOZvvaNsOY7jnrcXPzbrpLY3rtnJq07nWT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TCnqHpM60dTwT/doTuWr8HbGXA4F2DTOHNg3BznDeRGvPT/x8Zr8BElh4x1lnOSeyR9QuOjoRfnrB/TYP/c2u9KSlBjdlwI1ucrToNYH6g51k+PrX5WNQIQxi48aBTO9r80mba5O8eIlINy8wlIQKgFfTwm1DDc1ysaXIC/pTlY= 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=Jaiefri1; arc=none smtp.client-ip=148.163.158.5 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="Jaiefri1" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64D20gKY2761190; Wed, 13 May 2026 10:08:37 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=/Ue2spGrn56X4TfU8 hYc54q9HRRp5buBXeXnKQKtLZY=; b=Jaiefri1dF3CzN92AMaIMz+UEJaqCbRLm SBM3vNhUBPVfQVI50lt/+4nIODa9YKlApptnW4Cu381vqmnP7LbdmeLW2fNrFg0b S4M6s3ynbgIOEjsBdmbKNJZx7Np4BJQc03wen5wYdah/rkyNyags2vtSKfhLwRAK jVbMWyfX83w/k/U+vQp1rVYegnnqBwKBqya9IBeYijMCIxOV6H1n2HvGes9/3DaN 0GBhVLeziJbiKh4gA69V65mnZ/khbppafqINBscgZ2o9t4eUWBEZ2qqG5CVWtfVu Vvo2Y6QKU7fOyjIRLzM6Q6Hz8qGcHx5OlUV36I+Dv/SAdUQC7S4Sw== 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 4e3nv6pupr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:36 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64D9sQ5J017710; Wed, 13 May 2026 10:08:35 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgq7tm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:35 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64DA8Vt945547818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2026 10:08:32 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA1702004F; Wed, 13 May 2026 10:08:31 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E01EE20065; Wed, 13 May 2026 10:08:29 +0000 (GMT) Received: from mac.bl1-in.ibm.com (unknown [9.123.0.51]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 May 2026 10:08:29 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Amit Machhiwal , Vaibhav Jain , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Date: Wed, 13 May 2026 15:37:51 +0530 Message-ID: <20260513100755.83215-3-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513100755.83215-1-amachhiw@linux.ibm.com> References: <20260513100755.83215-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-ORIG-GUID: FzB0T6nTlJjdFQqILFNtle6O10i1NPfd X-Proofpoint-GUID: ksypFeiv_aU8udWo87-lkGi2QUEoqOXK X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEzMDEwNSBTYWx0ZWRfX4l5KJ8UJ/Rg1 HK8mZAuyeLQQpEG52jhVErEXjWypQS2iAVCGLbQiRwlK2rhs5aCiuzJytn1jJYlvB4FWMjz6JuL etVC0qZFEDJfgNjdXNG4eG/rptdLWXL1O7o0WQjR6DwybaCxqlsDpptc78485HlRHyEt9IbMblb jA2ftjnPSaXd0Hbgukx+BKWwudhD8GsEnL9AMXkJFud4va601U6T9JW/B5oGi6Awk3gf/owdQsz mOGwl95TFQPuJY60OyllN62AgMB7jEcQcmsEbNZHOSuOYe9XOQyNM3HnI+GCMF0irLER8TF2/lO /F803oC84fi91jZBooCXMv5OYMympg0nKeCLpy9e/tQl3y5z4t3XWP5NRzMzNOf4NzLHKfLd78a Kqhd/1c+7eZ5+4VCpJ0PJibVnJi5Is1ojurTOlSuj51suJK7v8FqSlMMbCvMO54uMiJEc8O66/B sRh9dftSVMRmoCkl8vg== X-Authority-Analysis: v=2.4 cv=P8UKQCAu c=1 sm=1 tr=0 ts=6a044da4 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=D7P34WnVX5hk26v0a_EA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 phishscore=0 bulkscore=0 clxscore=1015 malwarescore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605130105 Content-Type: text/plain; charset="utf-8" Introduce a new capability and ioctl to expose CPU compatibility modes supported by the host processor for nested guests. On IBM POWER systems, newer processor generations (N) can operate in compatibility modes corresponding to earlier generations, like (N-1) and (N-2). This is particularly relevant for nested virtualization, where nested KVM guests may need to run with a specific processor compatibility level. Introduce KVM_CAP_PPC_COMPAT_CAPS capability and the corresponding KVM_PPC_GET_COMPAT_CAPS vm ioctl. The ioctl returns a bitmap describing the compatibility modes supported by the host in respective bit numbers, allowing userspace (e.g., QEMU) to select an appropriate compatibility level when configuring nested KVM guests. The ioctl handling is added in kvm_arch_vm_ioctl() and retrieves host CPU compatibility capabilities via a PowerPC-specific backend implementation when available. If the capability is not supported, the ioctl returns success with no capabilities set, allowing userspace to fall back gracefully. Signed-off-by: Amit Machhiwal Tested-by: Anushree Mathur --- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 6 ++++++ arch/powerpc/kvm/powerpc.c | 21 +++++++++++++++++++++ include/uapi/linux/kvm.h | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/= kvm_ppc.h index 0953f2daa466..cadfb839e836 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -319,6 +319,7 @@ struct kvmppc_ops { bool (*hash_v3_possible)(void); int (*create_vm_debugfs)(struct kvm *kvm); int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu, struct dentry *debugfs_= dentry); + int (*get_compat_cpu_ver)(struct kvm_ppc_compat_caps *host_caps); }; =20 extern struct kvmppc_ops *kvmppc_hv_ops; diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uap= i/asm/kvm.h index 077c5437f521..081d6c7f7f70 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -437,6 +437,12 @@ struct kvm_ppc_cpu_char { __u64 behaviour_mask; /* valid bits in behaviour */ }; =20 +/* For KVM_PPC_GET_COMPAT_CAPS */ +struct kvm_ppc_compat_caps { + __u64 flags; /* Reserved for future use */ + __u64 compat_capabilities; /* Capabilities supported by the host */ +}; + /* * Values for character and character_mask. * These are identical to the values used by H_GET_CPU_CHARACTERISTICS. diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 00302399fc37..91a0228942e1 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -697,6 +697,13 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long= ext) } } break; +#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE) + case KVM_CAP_PPC_COMPAT_CAPS: + r =3D 0; + if (kvmhv_on_pseries()) + r =3D 1; + break; +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ default: r =3D 0; break; @@ -2463,6 +2470,20 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned in= t ioctl, unsigned long arg) r =3D kvm->arch.kvm_ops->svm_off(kvm); break; } + case KVM_PPC_GET_COMPAT_CAPS: { + struct kvm_ppc_compat_caps host_caps; + + r =3D 0; + memset(&host_caps, 0, sizeof(host_caps)); + if (!kvm->arch.kvm_ops->get_compat_cpu_ver) + goto out; + + r =3D kvm->arch.kvm_ops->get_compat_cpu_ver(&host_caps); + if (!r && copy_to_user(argp, &host_caps, + sizeof(host_caps))) + r =3D -EFAULT; + break; + } default: { struct kvm *kvm =3D filp->private_data; r =3D kvm->arch.kvm_ops->arch_vm_ioctl(filp, ioctl, arg); diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6c8afa2047bf..1788a0068662 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -996,6 +996,7 @@ struct kvm_enable_cap { #define KVM_CAP_S390_USER_OPEREXEC 246 #define KVM_CAP_S390_KEYOP 247 #define KVM_CAP_S390_VSIE_ESAMODE 248 +#define KVM_CAP_PPC_COMPAT_CAPS 249 =20 struct kvm_irq_routing_irqchip { __u32 irqchip; @@ -1349,6 +1350,9 @@ struct kvm_s390_keyop { #define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr) #define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr) =20 +/* Available with KVM_CAP_PPC_COMPAT_CAPS */ +#define KVM_PPC_GET_COMPAT_CAPS _IOR(KVMIO, 0xe4, struct kvm_ppc_compat_c= aps) + /* * ioctls for vcpu fds */ --=20 2.50.1 (Apple Git-155) From nobody Fri Jun 12 18:34:01 2026 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 50A9E3921E4; Wed, 13 May 2026 10:08:57 +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=1778666944; cv=none; b=ZLh52Ycvb6vF9r/1CTvXx7e4xxAOhHHFFmafSxSXTkevPTnat1KU0ZH8eCFwy96+yQ0SuOdpwdVzG9gcn031esiYYjfG2FO1ogDnSEVkFSHvzO/38F/4utfkemBUvSDGcWT1e0gjkzG9DbjQ1ccO9vN5V7CkUvwqGOGGcHFIFOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666944; c=relaxed/simple; bh=IZ2d0mynhllzNrhh3ZrLEKJCb36UcO98QBhwzj23ZeI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQXtcITXyhMk1stwVPErq3arBGnYJ0zR/KJsoPPrVHbHZErii1DLBUgATpzODq/LVF1S2Rogk8dXuj3vLXpEqMlVSd7JwcMeP87qocA+kQr3Jrl5LnRUDbud2jVYVH/XZ1R7KoCsqTzRSW/yQu6SiKzFWSZMfgcjU54JbP5v1f0= 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=bFQVzXzy; 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="bFQVzXzy" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64CH0Dc03678855; Wed, 13 May 2026 10:08:46 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=joVrI7uY5yjtKuPEN WybqFccqiCoZbuRt2VIrtKJ/Ss=; b=bFQVzXzyyJR46ABBkN3lhMFmNB3QFIKZ4 nkx5nU9vBsvoLfBu1gdLtWDY6Drz1FKRP1LPo7WC0+F/lQoST3RO4OI5nzieaKIS wUXkCgfluqn4Dtd6hxkB+PEEeSkt4zAGdZUtyLhrALfXwUOtxmm1niLHCtDj4VEY 7C9uP1+VpiHUaU36199ndl4nooFXDTH0p7EBhBUrrgWNx/wKUvXGuSLLZ/2hyGtV VKcBrbOtaA8993aNkr+3NYOAGONdoUizvpmxiYqgt2/tpePUa0ocmyJw4I2uRS/s Fi/yWqFrWwMtkVE8hLKF6U0Bjt9ncP+IvVJJesPJbgvIezKWXFgdg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e3nvdy5st-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:45 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64D9dXBw005872; Wed, 13 May 2026 10:08:44 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgf8mc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:44 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64DA8ewp52035936 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2026 10:08:41 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9EDD2005A; Wed, 13 May 2026 10:08:40 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1FCA52004E; Wed, 13 May 2026 10:08:39 +0000 (GMT) Received: from mac.bl1-in.ibm.com (unknown [9.123.0.51]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 May 2026 10:08:38 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Amit Machhiwal , Vaibhav Jain , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/5] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM Date: Wed, 13 May 2026 15:37:52 +0530 Message-ID: <20260513100755.83215-4-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513100755.83215-1-amachhiw@linux.ibm.com> References: <20260513100755.83215-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=Y/XIdBeN c=1 sm=1 tr=0 ts=6a044dad cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=lI54la875Hh5wgzWY30A:9 X-Proofpoint-GUID: whn5_bf2zPMcRbtsCAA92mu5E2BrUYqm X-Proofpoint-ORIG-GUID: 7Wtuqf8pNosA2WC1Dosc5UVEH8u9k6tW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEzMDEwNSBTYWx0ZWRfX1VjU35OYLQhd GTxU7natxTqLK8I0aI4HS3A254rCB3KQPAAjgOx9fICZkQewFHAcgE8p9ak/vRI1/AA1dXOBGio ymvYG5ffWrfYmWmwybN1PW1M2W5Mkr4bLNVjqRL9BOwtjE0/PSCIyj0Vk1hV1ShNrMLfe3NiE10 udRJKOp6mCWher1ybFHkxYfNQLJz5lGq+qV7hWMHWzBkJOubFCv2k3Ir6/92rI9p8RGEBUSMgqT rT0E8IezGGv3Y6wTIJhLB+t3/Oo1sJm7X1AL4MANv4Q5d5Qb2XBK72eM9p3bnbxmPvTW4by9cNC n2kf0+m9WsWhjPwBHnTZCp6YMbh9VdV/vSEvfmGcm8uQCGYqn4KvFTiVR55ddmFMixOk2j9xEyy d1k2hYrrllan28lCmKzu1yqm3afIF3b6JxIkOpdSRZS0eXQEEAyh+xT4C5uERD0Hd9ByC7l0Mwz pIRSDtpTr90lmlaXRlA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605130105 Content-Type: text/plain; charset="utf-8" On POWER systems, the host CPU may run in a compatibility mode (e.g., a Power11 processor operating in Power10 compatibility mode). In such cases, the effective CPU level exposed to guests differs from the physical processor generation. When running nested KVM guests, QEMU derives the host CPU type using mfpvr(), which reflects the physical processor version. This can result in a mismatch between the CPU model selected by QEMU and the compatibility mode enforced by the host, leading to guest boot failures. For example, booting a nested guest on a Power11 LPAR configured in Power10 compatibility mode fails with: KVM-NESTEDv2: couldn't set guest wide elements [..KVM reg dump..] This occurs because QEMU selects a CPU model corresponding to the physical processor (via mfpvr()), while the host operates in a lower compatibility mode. As a result, KVM rejects the requested compatibility level during guest initialization. Add support for retrieving host CPU compatibility capabilities for nested guests on PowerVM (PAPR nested API v2). The hypervisor provides the effective compatibility levels via the H_GUEST_GET_CAPABILITIES hcall, which reflects the processor modes negotiated between the Power hypervisor (L0) and the host partition (L1). On pseries systems, obtain the capability bitmap using plpar_guest_get_capabilities() and return it via struct kvm_ppc_compat_caps. This information is then exposed to userspace through the KVM_PPC_GET_COMPAT_CAPS ioctl. Hook the implementation into the Book3S HV kvmppc_ops so that it can be invoked by the generic KVM ioctl handling code. Signed-off-by: Amit Machhiwal Tested-by: Anushree Mathur --- arch/powerpc/kvm/book3s_hv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 249d1f2e4e2c..38de7040e2b7 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -6522,6 +6522,21 @@ static bool kvmppc_hash_v3_possible(void) return true; } =20 + +static int kvmppc_get_compat_cpu_caps(struct kvm_ppc_compat_caps *host_cap= s) +{ + unsigned long capabilities =3D 0; + long rc =3D -EINVAL; + + if (kvmhv_on_pseries()) { + if (kvmhv_is_nestedv2()) + rc =3D plpar_guest_get_capabilities(0, &capabilities); + host_caps->compat_capabilities =3D capabilities; + } + + return rc; +} + static struct kvmppc_ops kvm_ops_hv =3D { .get_sregs =3D kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs =3D kvm_arch_vcpu_ioctl_set_sregs_hv, @@ -6564,6 +6579,7 @@ static struct kvmppc_ops kvm_ops_hv =3D { .hash_v3_possible =3D kvmppc_hash_v3_possible, .create_vcpu_debugfs =3D kvmppc_arch_create_vcpu_debugfs_hv, .create_vm_debugfs =3D kvmppc_arch_create_vm_debugfs_hv, + .get_compat_cpu_ver =3D kvmppc_get_compat_cpu_caps, }; =20 static int kvm_init_subcore_bitmap(void) --=20 2.50.1 (Apple Git-155) From nobody Fri Jun 12 18:34:01 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 312FD3914E1; Wed, 13 May 2026 10:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666948; cv=none; b=Ry+sxxwDGCBUMLJO0AiV23kT1Gx+9hTH3BKqKhHTS1iTTKsXCaYCVuMbtpT0yQtyJvhM31TbqLO5tW6iqCEeiZ4426TKmM/uUzxOCJblQow48dpR5DNeYWLFnMGNFynJfaQZdMVm18cWdJKUjwfOTotuw/hchjxSygmWO0Mhais= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666948; c=relaxed/simple; bh=hoiPVbgXJJKMMufq/BBPcVTOGtHTK78y6E97QfH2KN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YU+0xKecyo12vwV5DG0pnPBAZKJ4yL8fQp7axnad0gGuryWbrvWLx97lcSZ3HvhLyGAbq5oeVlzW1QC2mGnBeK1a44eXzvI6JssG1knwA+lx35Adhqg0fkwV/w/okN035n35OBA+g89hnny+18ZvS/RWhO1IYgOTY9fQoRNfiro= 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=oYJ0vw8J; arc=none smtp.client-ip=148.163.158.5 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="oYJ0vw8J" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64D20Di93179810; Wed, 13 May 2026 10:08:50 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=/9IiKZksxGmIbh6Xg yZTZodERudGux8RFDGSWVKLUgU=; b=oYJ0vw8JQ4HjwwLG9PgAmGD6BrmSzUd5l MVYLZDdXs7A69ApBr4HEbh4v2Q4sNgIuQ7Lic7mai3iQhrYm+ZTjWPEOMEvssyog JgCwHv4Nuc3vZMlRBQFoJ342DQdggIyA6bbIzUfQq+izhokI1vpW0QjCMa61Wb55 6G9JCm34rs8pwVoSE3ebLfco2QGQtkxbgcdPyS9vD2SdraOHj5vz3s2/nctEH8Hq gFUbG8sQP0iEbzcSSji0xq2h/X/QBEgliAnVO0g1smYaI/mmHoBeI5dpbP+33X6j HH6ZpI46eGJ5gI0Cye9AusF/mqUDKuD0IjaoKi71M2eyPmWEl5jxA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e3nv6pua8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:49 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64D9sJXo019682; Wed, 13 May 2026 10:08:48 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgf9cn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:08:48 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64DA8jvI57016806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2026 10:08:45 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5CB332005A; Wed, 13 May 2026 10:08:45 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 962162004F; Wed, 13 May 2026 10:08:43 +0000 (GMT) Received: from mac.bl1-in.ibm.com (unknown [9.123.0.51]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 May 2026 10:08:43 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Amit Machhiwal , Vaibhav Jain , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/5] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV Date: Wed, 13 May 2026 15:37:53 +0530 Message-ID: <20260513100755.83215-5-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513100755.83215-1-amachhiw@linux.ibm.com> References: <20260513100755.83215-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=Us1T8ewB c=1 sm=1 tr=0 ts=6a044db2 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=LbGGMz8L2r-vpTRwWUsA:9 X-Proofpoint-GUID: t3sGPUW_HZjUI3MMceRlHMbGlDVN1Zh1 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEzMDEwNSBTYWx0ZWRfXz+3LoU3hVEmU MY/OzrmhZzmTRdOFw01JP0i1HVu+PxC4wqgjk4iRqwMVKhlac3Qj3B5bsipxRVyfYp5lx9E2tCo tjp8pxhevLR+8SlbPIN3V0pJfrcD3MzrlQjIMvQJRUHjPUzeR54LVB2lu75MW8Vv2iOBP+tkL1m XK92Y2rfkRCtTKEMnNTMq8Q1jtduHNwwGAIL7ZRRnzZjgpZxcRtW90Uz6yRfoKCiry+p3qHU0MW PKM7l7+qLf/xA4XA1fJtIyUvY+RHl4WBByBKuIxl1KWrwt8IdTxj1EXtl9w+yzsnJmII2hd/u9e fjfwcYUd80Bghf4u/OzKp4w7gQLGe/0NCX3dYdr6UGNFsf4XQmdkjslUFVRd9woP6kP96jtxZAw bM6ZXUw3pBuc6ViOXfYRzB7lhK94vvqcuh0FLbELKowcbOZ07t30xYKHBZMbBNzTVWhOiGCe//o uhM/SgLN6VcMz2lKK2w== X-Proofpoint-ORIG-GUID: ZnjYOATTMb7OJJTQWTKWaU6X_W-Vy740 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 spamscore=0 malwarescore=0 clxscore=1015 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605130105 Content-Type: text/plain; charset="utf-8" Currently, when booting a compatibility-mode KVM guest (L1) on a PowerNV hypervisor (L0), the guest runs with the expected processor compatibility level. However, when booting a nested KVM guest (L2) inside the L1, QEMU derives the CPU model from the raw host PVR and attempts to run the nested guest at that level, instead of honoring the compatibility mode of the L1. Extend host CPU compatibility capability reporting to support nested virtualization on PowerNV systems (PAPR nested API v1). For nested API v2 (PowerVM), compatibility capabilities are obtained from the hypervisor via the H_GUEST_GET_CAPABILITIES hcall. This information is not available on PowerNV systems. For nested API v1, derive the compatibility capabilities from the L1 guest by reading the "cpu-version" property from the device tree, which reflects the effective (logical) processor compatibility level. Map this value to the corresponding compatibility capability bitmap. Introduce a helper to translate CPU version values into compatibility capability bits and integrate it into kvmppc_get_compat_cpu_caps(). This allows userspace to query host CPU compatibility modes on both PowerVM and PowerNV platforms via the KVM_PPC_GET_COMPAT_CAPS ioctl. Signed-off-by: Amit Machhiwal Tested-by: Anushree Mathur --- arch/powerpc/kvm/book3s_hv.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 38de7040e2b7..18774c49af85 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -6522,15 +6522,50 @@ static bool kvmppc_hash_v3_possible(void) return true; } =20 +static int kvmppc_map_compat_capabilities(const __be32 cpu_version, + unsigned long *capabilities) +{ + switch (cpu_version) { + case PVR_ARCH_31_P11: + *capabilities |=3D H_GUEST_CAP_POWER11; + break; + case PVR_ARCH_31: + *capabilities |=3D H_GUEST_CAP_POWER10; + break; + case PVR_ARCH_300: + *capabilities |=3D H_GUEST_CAP_POWER9; + break; + default: + return -EINVAL; + } + + return 0; +} =20 static int kvmppc_get_compat_cpu_caps(struct kvm_ppc_compat_caps *host_cap= s) { + struct device_node *np; unsigned long capabilities =3D 0; + const __be32 *prop =3D NULL; long rc =3D -EINVAL; + u32 cpu_version; =20 if (kvmhv_on_pseries()) { - if (kvmhv_is_nestedv2()) + if (kvmhv_is_nestedv2()) { rc =3D plpar_guest_get_capabilities(0, &capabilities); + } else { + for_each_node_by_type(np, "cpu") { + prop =3D of_get_property(np, "cpu-version", NULL); + if (prop) { + cpu_version =3D be32_to_cpup(prop); + break; + } + } + if (!prop) + return -EINVAL; + rc =3D kvmppc_map_compat_capabilities(cpu_version, + &capabilities); + } host_caps->compat_capabilities =3D capabilities; } =20 --=20 2.50.1 (Apple Git-155) From nobody Fri Jun 12 18:34:01 2026 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 6BDFA3A5E7C; Wed, 13 May 2026 10:09:11 +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=1778666958; cv=none; b=GaPw71SqJuGPRnUx4NYIZ2HJQSyAxL5oQURejarkzYaUG3kUqtw3kLu6GZC0iK8iZ2wOpi5+aFuZdXxMDEv9EH+WihPdUP7b7qHpcCSlfnLftZiOnlM2pSMpzi47iqsql3iBFeKcOGnzExoCud38jWqTIxbdRfEdhRVIGZikinw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778666958; c=relaxed/simple; bh=T16Yiq7DU4hyzsZOEvkFRwg0lhBj02EOhCphYusLKl4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uu3xY77ZpKAXvDW+6VcwojTTEBGlajDV52vV/IFk9JayF9GCYFS/pQmGFPMgN6GABGS3chfkEBeVjRK8ueunqmXNYkuRLC8DnIcKusq2JXz7xj4RlWfh7CcGszBkPMdHBIjqaz5KAKkP/ywrSdjJFm4D+h42OlHMzJ+uDnZafIQ= 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=iV9KPDGq; 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="iV9KPDGq" 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 64D3KUiG2608088; Wed, 13 May 2026 10:09:04 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=eYTK6cAUBtTFuzy/O 8wptvb61XPJ8NVqXjyj9UPi/yA=; b=iV9KPDGqX7ZDOs+6UhqLxbe2bktFBhjL2 G0O2vitUvsQlp03PXW0POXOzCIVZnFCLMh3EsNyBR9uIcag9NvOvLtktmJeS+WL2 Y6bMP/gggl5R8RLGoK3WDBAzrFRY09jpnKTTqxZo3g2YMED0yGvmg5MRoLntbXUT gmxH+HQAkLgBAqkNQWvmCvcz76/60B8MHUZd0ayCgq6b3hHrNbWwTCCFd+gkFcTH 9WsGgSeUcDKBvH7/TAzoZQ0OHyFiUPHdgSg4I6v70a/1/KY8KZaQ08KCdt5cpReu hFeBYreIgUaDm0QPj5OOpdGZ+hSSBgv8RPgu4YJOrBFPYBDQVrcbA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e3nv5751y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:09:03 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64D9dU8V024778; Wed, 13 May 2026 10:09:02 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgq8wx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 10:09:02 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64DA8w3v61276538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2026 10:08:58 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A3FDB20063; Wed, 13 May 2026 10:08:58 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B80FC20065; Wed, 13 May 2026 10:08:56 +0000 (GMT) Received: from mac.bl1-in.ibm.com (unknown [9.123.0.51]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 May 2026 10:08:56 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Amit Machhiwal , Vaibhav Jain , Paolo Bonzini , Jonathan Corbet , Shuah Khan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v2 5/5] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl Date: Wed, 13 May 2026 15:37:54 +0530 Message-ID: <20260513100755.83215-6-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513100755.83215-1-amachhiw@linux.ibm.com> References: <20260513100755.83215-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEzMDEwNSBTYWx0ZWRfX/TNKQD8ZsDEq xnf+us/AasQaZDvdyetolHyfkMKPryjrhC9INEb9alHAsRdYW6FzzQM+rWooowm9ofLyWurNlCa CHhjVRfSG4jMOwl6HmjjIyinEaGBnmUyIxvdgebYCOefNx9O77dvKC1pdDY95o9OeZzrBsZ5uEX aDjGbx/Cjm+l7EuSIUM6kgXqVkNQ4wKJ7OA2D6NefbQmxm+Pl8m9tlDPa+XrKkzZ9b62awUqVJp EpF6UpaKh3mCtaXQEdTnYEa8j56jEeQvW73u4lPRK7cQN4+MXjJdqYEBh2LLfs8CLiXXED2P7Wy RTbd+tRqBPkO3v7n/sy+1kTRO48J9FuKPU84yyr5z+/M5TiwI/drQLLyxoouNTis91qQRcCFRqy Z1GGIAYewrT98zZUmc0T7ymsJ1YG0De4FRey+7fnvSOwmD4HmivHb0mz+kYpKRCVf478lBU6ekG FNVtV6uxmFXqCE+CFjw== X-Proofpoint-ORIG-GUID: GHcvUbvyi9sBzj_5vVZaIPGnRCxtENJ- X-Authority-Analysis: v=2.4 cv=Jc6Ma0KV c=1 sm=1 tr=0 ts=6a044dbf cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=FhmJ5nnsb20HCo8Rnz4A:9 X-Proofpoint-GUID: GHcvUbvyi9sBzj_5vVZaIPGnRCxtENJ- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 clxscore=1015 phishscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605130105 Content-Type: text/plain; charset="utf-8" Add documentation for the KVM_PPC_GET_COMPAT_CAPS ioctl to the KVM API documentation. The ioctl exposes host processor compatibility modes supported for nested KVM guests on PowerPC systems. Signed-off-by: Amit Machhiwal Tested-by: Anushree Mathur --- Documentation/virt/kvm/api.rst | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 52bbbb553ce1..1b533f674a09 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6555,6 +6555,41 @@ KVM_S390_KEYOP_SSKE =20 .. _kvm_run: =20 +4.145 KVM_PPC_GET_COMPAT_CAPS +----------------------------- +:Capability: KVM_CAP_PPC_COMPAT_CAPS +:Architectures: powerpc +:Type: vm ioctl +:Parameters: struct kvm_ppc_compat_caps (out) +:Returns: + 0 on successful completion, + -EFAULT if ``struct kvm_ppc_compat_caps`` cannot be written + +IBM POWER system server-based processors provide a compatibility mode feat= ure +where an Nth generation processor can operate in modes consistent with ear= lier +generations such as (N-1) and (N-2). + +This ioctl provides userspace with information about the CPU compatibility= modes +supported by the current host processor for booting the nested KVM guests = on +PowerNV (KVM nested APIv1) and PowerVM (KVM nested APIv2) platforms. + +:: + + struct kvm_ppc_compat_caps { + __u64 flags; /* Reserved for future use */ + __u64 compat_capabilities; /* Capabilities supported by the host */ + }; + +The ``compat_capabilities`` bit field describes the processor compatibility +modes supported by the host. For example, the following bits indicate supp= ort +for specific processor modes. + +:: + +H_GUEST_CAP_POWER9 (bit 1): KVM guests can run in Power9 processor mode +H_GUEST_CAP_POWER10 (bit 2): KVM guests can run in Power10 processor mode +H_GUEST_CAP_POWER11 (bit 3): KVM guests can run in Power11 processor mode + 5. The kvm_run structure =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.50.1 (Apple Git-155)