From nobody Tue Sep 29 10:32:13 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 63DDC366DD3; Sat, 8 Aug 2026 16:12:30 +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=1786205552; cv=none; b=Yhx3js6fG/xjS+zQkKnYHsng0cDOcqYrAIQZvs9cukzXOkoUr1L3I7PqWsQIqAp+j8R5QlhtOa44XiA6CFHftu3j/3E2BifRxOnMyXYinMqtdeLjY1XEtcEaH6bOJoRX9t8K8pZrflo3FGOzLL/IflssQMAOn+W9y5FUau3vXPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786205552; c=relaxed/simple; bh=P+G16lv4L049orokO3HBQt4MBZAT91AFln91KbRBvbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RMxVGFKAyiwp+slzDO+nU9PSuKaX+XTMknXHGnab4YolwdZ7UUdWgl7RM3/286HiHtnvxI0Pz8XkCySIClVDn9USZ8PDjIELFCB2rnihCjH5qoOhzhYIHLIaUjo724Z7rjtBfSntbEfRcltTuyI1AqeEs7aUBlb7KM+dpRIUQaw= 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=BM3hQbnX; 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="BM3hQbnX" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 678E2A6S259720; Sat, 8 Aug 2026 16:12:14 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=56mbsJmtqmy/6GZvl 8Gn67gvMFzrx22mXIbhqmxFqOw=; b=BM3hQbnXqsvPH8ZEq2QGx20tHTAQ00M3M 4mVyV4ynWuXvKDXvCpGtMISd3fDIR6HjEmTlpRSRxjNyGkXJQft74px/GX5EYasu MN4zqKOpnuT1fDxEemsbhL8qEOXs6mmHfzMgVM7PHssbsULNcLHGsVXJl2SowOQ1 qbtgx315ZgfwC9tbKXw4DkCGdsRPfOh/SLFWLxWzX9sY0MievAcXbXXhN0iPwrGV UH1xPR336n9LKjlyPXP3wQJS6SqYvEbXCfmfB6kcqsmyIsRxZAmEA4tPH46QupEL OZEHP4SQPz3XQhgwST25m6UHfoht0P/8a2TFZbBKEPLLUxht7hc5w== 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 4fwvkchh44-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:13 +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 678GBG1d015185; Sat, 8 Aug 2026 16:12:13 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fsvmhuvuq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:13 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 678GC8Rl28115390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Aug 2026 16:12:09 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D43B220043; Sat, 8 Aug 2026 16:12:08 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 07C9D20040; Sat, 8 Aug 2026 16:12:05 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.213.63]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Sat, 8 Aug 2026 16:12:04 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Vaibhav Jain , Amit Machhiwal , Anushree Mathur , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Jonathan Corbet , Shuah Khan , Ritesh Harjani , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Harsh Prateek Bora , Gautam Menghani Subject: [PATCH v9 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Date: Sat, 8 Aug 2026 21:41:45 +0530 Message-ID: <20260808161148.66673-2-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260808161148.66673-1-amachhiw@linux.ibm.com> References: <20260808161148.66673-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-GUID: O1o0nyjWLggnEO-jipgUopbzYHUQ_01W X-Authority-Analysis: v=2.4 cv=J86aKgnS c=1 sm=1 tr=0 ts=6a77555e cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=ETYFO_97Qo2pusGNp_0A:9 X-Proofpoint-ORIG-GUID: HA7DU7A_yCku5bpWKxzQGhUfyhTJTFBy X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX2MzLawupy+Dz ZWugiyjBiokFqSEFpyH6HSCbOBn6JVKpDUuGgB3yZj8ZWEAqM+wWLg6YJhy7lk0nm3XGFQq4x9f CYce2wZapkCJxOFyHz44LPJs7BIgoW8S+GhJl04jBDqIt0aE68hZStqBQWAnIcnLoGPX0SaOuqE K+8Xolv9enrOD9ys5hvJMYD3FBLgpY076qwEhXBufXlTIMwl8nW5yt34+qb9SCooCduIfFlakxb BSA48jI+7akQfnZBmHLgLjyxCyrwZ1LGga/LQeIArCPbCaCdkXbODkPffo7nZiEAao0dSRckxfF JX7mU+CxVtgLL2uy4ljCu5BCqlkKpEKayC3RynA1Wwt6Zs2Kn3xtiow52apgm+OJ1NV4CXYxlIw m6II52hVJ272OX9AgMxw81ZAgJIelULk+sW8D0whaEq9xY1hPkWKvOLFAHygbopPlRBXYV/1n8x Lc6M7BrO7VHHkJMrAHg== X-Proofpoint-Spam-Info: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX+x2kg/OZLWId DGm0U8/7Ejv6NSXWOusB8uh7sDrwbIqgErtr2Mnzh0zNgEv4uarp3eOzVAQlw3cFZRLCGg8akNR 0TheWkuhhbDVNlepLgJiziNtGNc+biU= 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-08-08_05,2026-08-07_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608080137 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. The struct kvm_ppc_compat_caps places the 'size' field first so it can be read alone via get_user() before copy_struct_from_user() is called, avoiding pointer arithmetic to locate the size field. The ioctl is defined using _IO so the ioctl number remains stable even if the struct grows in future versions. It uses copy_struct_from_user() and copy_struct_to_user() to provide forward- and backward-compatible extensibility: older userspace passing a smaller struct to a newer kernel gets zero-padded trailing fields. Newer userspace passing a larger struct to an older kernel (usize > ksize) succeeds if trailing bytes are zero (the kernel reports back min(usize, ksize) as the filled size); if trailing bytes are non-zero, the kernel writes back ksize into host_caps.size and returns -E2BIG so userspace can retry with the correct size. KVM_PPC_COMPAT_CAPS_SIZE_VER0 is defined as a frozen integer constant (24) marking the size of the initial struct version, used as the minimum floor for size field validation, similar to other versioned struct interfaces in the kernel. The 'flags' field is reserved for future use. The kernel rejects any call where flags is non-zero with -EINVAL, preventing garbage values from being baked into ABI permanently. The ioctl returns appropriate error codes: E2BIG if usize exceeds PAGE_SIZE, or if new userspace provides a larger struct with non-zero trailing bytes (with ksize written back into host_caps.size for the retry); EINVAL for an invalid size or non-zero reserved fields; EFAULT for failed copy operations; and ENOTTY if the backend doesn't implement get_compat_caps. Suggested-by: Vaibhav Jain Tested-by: Gautam Menghani Reviewed-by: Gautam Menghani Tested-by: Anushree Mathur Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Amit Machhiwal --- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 8 +++ arch/powerpc/kvm/powerpc.c | 78 +++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 3 ++ 4 files changed, 90 insertions(+) diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/= kvm_ppc.h index 0953f2daa466..169ea6a7fbad 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_caps)(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..19e53d5ae540 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -437,6 +437,14 @@ 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 size; /* Size of this structure */ + __u64 flags; /* Reserved for future use */ + __u64 compat_capabilities; /* Capabilities supported by the host */ +}; +#define KVM_PPC_COMPAT_CAPS_SIZE_VER0 24 /* sizeof first published struct = */ + /* * 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 b6b83fe3233f..14a661a88d4e 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -703,6 +703,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 (hv_enabled && kvmhv_on_pseries()) + r =3D 1; + break; +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ default: r =3D 0; break; @@ -2469,6 +2476,77 @@ 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 =3D {}; + u64 usize; + + /* + * Read the size field first to drive copy_struct_from_user. + * size must be the first field of the struct. + */ + r =3D -EFAULT; + if (get_user(usize, (__u64 __user *)argp)) + goto out; + + r =3D -E2BIG; + if (unlikely(usize > PAGE_SIZE)) + goto out; + + /* + * Enforce a minimum: reject buffers smaller than the initial + * struct version (VER0). This allows old userspace compiled + * against the original struct to still work on a newer kernel + * that has grown the struct with appended fields. + */ + r =3D -EINVAL; + if (usize < KVM_PPC_COMPAT_CAPS_SIZE_VER0) + goto out; + + /* + * copy_struct_from_user() handles forward/backward compat: + * usize =3D=3D ksize: verbatim copy + * usize < ksize: zero-pad trailing (old userspace, new kernel) + * usize > ksize: succeed iff trailing bytes are zero, else -E2BIG + */ + r =3D copy_struct_from_user(&host_caps, sizeof(host_caps), + argp, usize); + if (r) { + /* + * New userspace with a larger struct called an older + * kernel. Write back ksize in host_caps.size so + * userspace knows which older struct to retry with, + * then fail with -E2BIG. + */ + if (r =3D=3D -E2BIG) + if (put_user((__u64)sizeof(host_caps), + (__u64 __user *)argp)) + r =3D -EFAULT; + goto out; + } + + /* Reserved fields must be zero */ + r =3D -EINVAL; + if (host_caps.flags) + goto out; + + r =3D -ENOTTY; + if (!kvm->arch.kvm_ops->get_compat_caps) + goto out; + + r =3D kvm->arch.kvm_ops->get_compat_caps(&host_caps); + if (r) + goto out; + + /* + * Report the number of bytes actually populated by the kernel, + * not usize: if new userspace passed a larger struct with zero + * trailing bytes, we only filled sizeof(host_caps) bytes. + */ + host_caps.size =3D min_t(u64, usize, sizeof(host_caps)); + r =3D copy_struct_to_user(argp, usize, &host_caps, + sizeof(host_caps), NULL); + 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 419011097fa8..70e36e6a0ad4 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -997,6 +997,7 @@ struct kvm_enable_cap { #define KVM_CAP_S390_KEYOP 247 #define KVM_CAP_S390_VSIE_ESAMODE 248 #define KVM_CAP_S390_HPAGE_2G 249 +#define KVM_CAP_PPC_COMPAT_CAPS 250 =20 struct kvm_irq_routing_irqchip { __u32 irqchip; @@ -1341,6 +1342,8 @@ struct kvm_s390_keyop { /* Available with KVM_CAP_COUNTER_OFFSET */ #define KVM_ARM_SET_COUNTER_OFFSET _IOW(KVMIO, 0xb5, struct kvm_arm_count= er_offset) #define KVM_ARM_GET_REG_WRITABLE_MASKS _IOR(KVMIO, 0xb6, struct reg_mask_= range) +/* Available with KVM_CAP_PPC_COMPAT_CAPS */ +#define KVM_PPC_GET_COMPAT_CAPS _IO(KVMIO, 0xb8) =20 /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) --=20 2.50.1 (Apple Git-155) From nobody Tue Sep 29 10:32:13 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 11AE836EA98; Sat, 8 Aug 2026 16:12:31 +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=1786205553; cv=none; b=cCxUfpdAwDwFwheI45h6zbn8yz3Zc9Ci/bt/oiuwtnFMwgKoX4kVawrsWYnG76TJ86CuvujmLkg/RcziAJ7vzVueMaOMIqDVkLDpbELBfZUBla0E26WewbmqYzbWUizJiosKze+YM4uXbAqjpj1Ou4wgo7EsQTZP5x2NBTPU0lw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786205553; c=relaxed/simple; bh=8SJaesSmEMz50q645V+iXmIoBbDesixH+uHDXS6TbAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rgkvsy2IFMFcLU5ZWEKy74MebIuA6rhVusGmlV92t6FNHf4kO111Mm25xM0GZHsPOKDpF5MVxpbM1Y7znP9jNk1urPESiF54NNkANvXOZ4Sj4DxnyyA0okeHe7q5xMi92/nyE2qqY6YQpAjSRdSovfdbAIGKfD3uww5k91HaHVc= 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=i7UCs4im; 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="i7UCs4im" 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 678E1eqB334427; Sat, 8 Aug 2026 16:12:19 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=6ZsR7bxa41ZnjXxzT z2yS40d1f72fEwF8oWdyBI1bAo=; b=i7UCs4imApD4By60cNw8OYTsiV6v6xj0N 0t7o0rPHv3mxRAi2iXese4LrAdiVfr3UBjnDNUMKD0Z6jiP21WbAcazj2ce9RA8s Gbn2GwtO/Bqi6qKR8w9YiIBVslg5AIBceN8vvdJCXpcXw5PyHC02GUnOR8KWaBC0 lArE32Gu5J6mRZIT6hU4KygCv5eMWSgrN0v4xTDBZlTQmIku/XR6KrocEU96TPrg r+8iidyrvIxL7ayoOiXrK4J4ZySbYp4g6Z86sKJU8l/64EY68qg1NxNdUN8j2QuO QwM9bd5G2VRTdz7Lm7VQvB/0KOXF2AQAGFtKc86rH/V8fRpxJlUcg== 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 4fwvq91m60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:18 +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 678GBJak022001; Sat, 8 Aug 2026 16:12:17 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fsu4r42ym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:17 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 678GCECC43909592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Aug 2026 16:12:14 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24F7520043; Sat, 8 Aug 2026 16:12:14 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F0C420040; Sat, 8 Aug 2026 16:12:10 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.213.63]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Sat, 8 Aug 2026 16:12:10 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Vaibhav Jain , Amit Machhiwal , Anushree Mathur , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Jonathan Corbet , Shuah Khan , Ritesh Harjani , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Harsh Prateek Bora , Gautam Menghani Subject: [PATCH v9 2/4] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM Date: Sat, 8 Aug 2026 21:41:46 +0530 Message-ID: <20260808161148.66673-3-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260808161148.66673-1-amachhiw@linux.ibm.com> References: <20260808161148.66673-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-GUID: Bl7tPeHvJ5mPBsJ8tz6viKykQAgXxsa6 X-Authority-Analysis: v=2.4 cv=PbDPQChd c=1 sm=1 tr=0 ts=6a775563 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=igDgF-0WGXUSGxExIdQA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX7WXOyl+r1Xlp tEN13WBSOsJ3SftwlpB14N5n6k+5SVebKUJW60SNFfvfxJPYNk47HdvCohoX5x/zeVVYeQqyzMt E4Dw8upxHLpAZBzVXWFlo3Ht5vI0WPjGTDRmY65JYTsmh30ryxT4f1OxtJnO49oFVkKk6LhWOFW zqoyygaB4uaSJA63oHy7cXTYs7mOQrWMuYUHSyz4DdJUaXwmTsnRSLipNv6+h66LEbE6veUrEEb SoKLxAhV0XsWFTufuYHvZrYA7zHq/2wpsjN3P2m7+hxVrUxXUZR3NlZH/+74dUGDNJDbHKWWfMi IjvPrIdCNZ7ipkIoRp4/8QaYwYpK+6c9SA9FK0WxRphNabyaEBnpFA+YImSxVnRJKubUI5IeBwq WpDH+TdrhQr5gJ56goSRa3vIOVL1gsIQB9WXRjyFBXUGsD+inmC+KdZ7Pm+6YnyXss0ZGBCVTH/ FG6t54Yd3QTF2Ho1Wbw== X-Proofpoint-ORIG-GUID: mEj7vIWAfnB371Nf2wRsM-91qjisbKSl X-Proofpoint-Spam-Info: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX3R3TqObuef2F 4TLObyk/9pZ0d+plsEbU8W1MrikNhTTpChGmpwS9H4tYqGPT69Db8NUfGFdFBuHQK1UqjFSr8Rn ENsvLcq1P+o2tfQOUZd/gcHh6nP4rso= 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-08-08_05,2026-08-07_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1015 priorityscore=1501 suspectscore=0 phishscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608080137 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. On pseries nestedv2 systems, add support for retrieving host CPU compatibility capabilities for nested guests on PowerVM. The capability bitmap reflects the processor modes negotiated between the Power hypervisor (L0) and the host partition (L1) via the H_GUEST_GET_CAPABILITIES hcall, but is retrieved from the cached nested_capabilities value populated during module initialization, avoiding repeated hypervisor calls. A WARN_ON_ONCE() flags the unexpected case where nested_capabilities is zero on a nestedv2 system. The implementation defines KVM-specific capability constants (KVM_PPC_COMPAT_CAP_POWER9/10/11), masks unsupported bits, and exposes the result 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. Suggested-by: Vaibhav Jain Tested-by: Gautam Menghani Reviewed-by: Gautam Menghani Tested-by: Anushree Mathur Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Amit Machhiwal --- arch/powerpc/include/uapi/asm/kvm.h | 10 ++++++++++ arch/powerpc/kvm/book3s_hv.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uap= i/asm/kvm.h index 19e53d5ae540..913a64b901a3 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -445,6 +445,16 @@ struct kvm_ppc_compat_caps { }; #define KVM_PPC_COMPAT_CAPS_SIZE_VER0 24 /* sizeof first published struct = */ =20 +/* + * Capability bits for compat_capabilities field in kvm_ppc_compat_caps. + * These bits indicate which processor compatibility modes are supported. + */ +#define KVM_PPC_COMPAT_CAP_POWER9 (1ULL << 62) +#define KVM_PPC_COMPAT_CAP_POWER10 (1ULL << 61) +#define KVM_PPC_COMPAT_CAP_POWER11 (1ULL << 60) +#define KVM_PPC_COMPAT_BITMASK (KVM_PPC_COMPAT_CAP_POWER9 | \ + KVM_PPC_COMPAT_CAP_POWER10 | \ + KVM_PPC_COMPAT_CAP_POWER11) /* * Values for character and character_mask. * These are identical to the values used by H_GET_CPU_CHARACTERISTICS. diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index f9380ef65750..152cd08a5b38 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -6523,6 +6523,25 @@ static bool kvmppc_hash_v3_possible(void) return true; } =20 + +static int kvmppc_get_compat_caps(struct kvm_ppc_compat_caps *host_caps) +{ + unsigned long capabilities =3D 0; + long rc =3D -EINVAL; + + if (kvmhv_on_pseries()) { + if (kvmhv_is_nestedv2()) { + WARN_ON_ONCE(!nested_capabilities); + capabilities =3D nested_capabilities; + rc =3D 0; + } + } + + host_caps->compat_capabilities =3D capabilities & KVM_PPC_COMPAT_BITMASK; + + 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, @@ -6565,6 +6584,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_caps =3D kvmppc_get_compat_caps, }; =20 static int kvm_init_subcore_bitmap(void) --=20 2.50.1 (Apple Git-155) From nobody Tue Sep 29 10:32:13 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 D31CA1FE44A; Sat, 8 Aug 2026 16:12:40 +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=1786205562; cv=none; b=BTQldfkjGAA3MBrngfqByVOnk234GXeZ5ZYQAZ6YgM5/4M/mlaxXejEP/xuB6Fc/jJGdga2ipVxDZlitcixSxh68MkYyC6Lrz655jzduNJBU8iIHf9ruacOIxiOUsPnUPhzmVR+KfaMbhl/ejUEEL3DcG/Y7QO0QWggWGCp5KA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786205562; c=relaxed/simple; bh=5h/s+AAYgQlPhirHpaBQESgx7qCL8kqNs1uxioqPv9o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AG9z4lRF8XflpkHsWNtHP8izgkTGOdBLz2uGG4qgVZ9JgQPgdgxkmNXbsFaNAN+5mXtXa3Po9lv23Bl4DPrVnYbznwVSR84uVO3KMwLoDYECw4/jYVfTE4sWXtiKJkYnfTSBdTv5YixFDug1XPCjSdzTJFWZIL0vcflFZGvYiQM= 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=NYZ5UZ7L; 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="NYZ5UZ7L" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 678E1gVl259165; Sat, 8 Aug 2026 16:12:24 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=JK/HgCIRS7bWKsUL0 /9kFYeCHCkOOqKTR3vxOapEigE=; b=NYZ5UZ7L1of4H+Pvn490jDmtA5T3NnEFX xrqrlFbmTi3P0LMCs8IAUPI7bktx/3mTD+p9MRj0YMbldGIVeuDiXUffg7UkCPsy XsHvk2GluLvlYkLRiPKLipxZj9f/B4NuBTdnFhbFT6cKPyQGgCZB0coZKcG0w6wJ iarmkObkRIYBfpgjwIfRX87Wvgv5Ezx/9LebHOJs8HbcPh21Kxg5MXkbfhnxY2rU J3OE9Ws7k+Q1qBdDBbp7TtRC1xlvYZgYE5RJCW4o7OETJ9RvAS9OpoV399p7OQkX LP3NrUDgvN+p3YnDyK68RoLEoU0BDU93XIM8QIr7Tk6SBtKPrKJbw== 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 4fwvkchh4e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:24 +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 678GBJam022001; Sat, 8 Aug 2026 16:12:23 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fsu4r42yv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:23 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 678GCJvg16253370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Aug 2026 16:12:19 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5DDDC20043; Sat, 8 Aug 2026 16:12:19 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADF5020040; Sat, 8 Aug 2026 16:12:15 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.213.63]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Sat, 8 Aug 2026 16:12:15 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Vaibhav Jain , Amit Machhiwal , Anushree Mathur , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Jonathan Corbet , Shuah Khan , Ritesh Harjani , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Harsh Prateek Bora , Gautam Menghani Subject: [PATCH v9 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV Date: Sat, 8 Aug 2026 21:41:47 +0530 Message-ID: <20260808161148.66673-4-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260808161148.66673-1-amachhiw@linux.ibm.com> References: <20260808161148.66673-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-GUID: j_XrE5XMtz4JE_WllbMeEDU6Ps1XoviZ X-Authority-Analysis: v=2.4 cv=J86aKgnS c=1 sm=1 tr=0 ts=6a775568 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=jUdWb-NNBahwQYUnPB4A:9 X-Proofpoint-ORIG-GUID: KQ4qhbchK1-rAF86Q0UmdrMVGzQTJ0P- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX9fCXkeSQ53Z+ Hd4CF0Cj9AzZSDMwshNqSpy/d5xw46wt0Pfq7FfKbYscLOgFU9arqJTV0rTP6IZJRjVgMlUyoiK 4Ax1bmvocZjtU2YQ0dSxRA697XQvJhfN6GkdWmIkDNz56QQvTdD2Aqf5++EtRZbpyGC/pusD66m GPsldyxhpQ/XImO05Q+I5IclH0oGk5ZvqXzymO3hSYv2hvqgREpQiInVmQwg2XAA7hw/SuE6W+K t4rG69mqYjMv7MmNEQTD13n/asZS66M2yb9e+G3XAO8Hlg9mkkdCnZkecIT+A39IXrxtKnIhqHE a6XFi2B898AHZDt8jFD+05Z2xjR19iKFYbqgLPr1EWUROkn/CkNXupWjDf1inYOmGLXmNN1RbGb 0huitwLG7uYhTomIl8v39j+aZracH/qQAqCck5xjE3cj6ccDmp8gY7ogvF94jrNuAA9/WDoefvJ 2to7p9jdS0B4Cnvcgtw== X-Proofpoint-Spam-Info: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX6pyyLdP28/kx SAOQ14VRyzRS4TEeI9os/snb4+Vdp4JGsxqx141I8/O5Aoi3cqSuLkwjg2kXTtAJxvdTh66CU/r Ti+hsBBmQSI26iJs29maZmYgn+Ji0Dg= 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-08-08_05,2026-08-07_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608080137 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 served from the cached nested_capabilities value (populated at module init via kvmhv_nested_init() using 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 using KVM-specific constants. The mapping is cumulative: a system running at a given compatibility level is assumed to also support older generations down the supported chain. Note that unlike KVM on PowerVM (nested API v2), KVM on PowerNV currently does not strictly enforce older generation compatibility modes for nested guests - the reported capabilities reflect what the host CPU can present, not what the hypervisor independently validates. Introduce a helper kvmppc_map_compat_capabilities() to translate CPU version values into KVM_PPC_COMPAT_CAP bits using a fallthrough switch, and integrate it into kvmppc_get_compat_caps(). The implementation applies masking to ensure only supported processor modes are exposed. This allows userspace to query host CPU compatibility modes on both KVM on PowerVM and on PowerNV platforms via the KVM_PPC_GET_COMPAT_CAPS ioctl. Suggested-by: Vaibhav Jain Tested-by: Gautam Menghani Reviewed-by: Gautam Menghani Tested-by: Anushree Mathur Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Amit Machhiwal --- arch/powerpc/kvm/book3s_hv.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 152cd08a5b38..4d0307f55e06 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -6523,20 +6523,56 @@ static bool kvmppc_hash_v3_possible(void) return true; } =20 +static int kvmppc_map_compat_capabilities(u32 cpu_version, + unsigned long *capabilities) +{ + switch (cpu_version) { + case PVR_ARCH_31_P11: + *capabilities |=3D KVM_PPC_COMPAT_CAP_POWER11; + fallthrough; + case PVR_ARCH_31: + *capabilities |=3D KVM_PPC_COMPAT_CAP_POWER10; + fallthrough; + case PVR_ARCH_300: + *capabilities |=3D KVM_PPC_COMPAT_CAP_POWER9; + break; + default: + return -EINVAL; + } + + return 0; +} =20 static int kvmppc_get_compat_caps(struct kvm_ppc_compat_caps *host_caps) { + struct device_node *np; unsigned long capabilities =3D 0; long rc =3D -EINVAL; + u32 cpu_version =3D 0; =20 if (kvmhv_on_pseries()) { if (kvmhv_is_nestedv2()) { WARN_ON_ONCE(!nested_capabilities); capabilities =3D nested_capabilities; rc =3D 0; + } else { + for_each_node_by_type(np, "cpu") { + if (!of_property_read_u32(np, "cpu-version", + &cpu_version)) { + of_node_put(np); + break; + } + } + if (!cpu_version) + return -EINVAL; + rc =3D kvmppc_map_compat_capabilities(cpu_version, + &capabilities); } } =20 + if (rc < 0) + return rc; + host_caps->compat_capabilities =3D capabilities & KVM_PPC_COMPAT_BITMASK; =20 return rc; --=20 2.50.1 (Apple Git-155) From nobody Tue Sep 29 10:32:13 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 DB0F036F900; Sat, 8 Aug 2026 16:12:43 +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=1786205565; cv=none; b=mRxgf7Lk5vJjrWbSBj2SBkvBkFToC7KfT+doyGVGUpJ41W9PgZdXBDEtYXH3OuRO+cIP4jQcxexZu3VIeGLtdBluuT2qUl7FQNx2T6G1ORTsVEDtzkAz4dcr5mbt8v5/GSeL4P96dpUpJnkXAnrWE0u/ihFNWUseMl0aUbB7B2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786205565; c=relaxed/simple; bh=1HeJlmpeRxKjQq+ge7hyKyQsZjOmD0gdM28GYEb2JbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ef5CvDbNblsc13YBxf9c30x+YtR1P1o+8fv17342ko9fpgZ/MoE8QFXwiX9N8Bc3ulCC9BIuItmM9+7G7Dn42Q0xQsOMDzkMVYeqbxu3gP3ORTuowSUT/8gjF2DSDNkZg5VAGcpji1bpm7TMl4MmF623+Fi4+fGdRB6d+Rf7R14= 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=E49/3/Yr; 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="E49/3/Yr" 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 678E1rHO2693437; Sat, 8 Aug 2026 16:12:31 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=gj4ui9kz41zX9V9VU JmxHpEXrLvfRCtOc/o4abThskE=; b=E49/3/Yr8NkjeBjs7Iw7siefdhK6Rbkba rxusIUbX8EjeJxs4z1vaFolY2YKDp6LMIEixWJCV18FGY0GogD9DFOeDjHh7AZX5 wL4qUW4IbHPg8kWn6Q3EewyeJBoArjL9t4lOH/e8Gf+BBxAk1rPEHRkKtufWE812 qfGi4euet6Pd349AfUHbhKY2f2CDWPaXT9tEMBg7BVJGdJ2a4JPu8JJsf8j/09Ja 072qEjvEhs+Y5DheI0ICdkVZTagnNgeKwyW9udB9Gb9WZq7VSFtWgv3uZUBjnMFy vRRqjfcxRIEyz9ChJL9kOgjqkvDQFZhlGiOoe15EDNZ3igyWN9d4Q== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4fwvjyhmkq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:30 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 678GBHKb003347; Sat, 8 Aug 2026 16:12:29 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fsugwm1wq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 16:12:29 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 678GCP4L32571692 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Aug 2026 16:12:25 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8AFA520043; Sat, 8 Aug 2026 16:12:25 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D199620040; Sat, 8 Aug 2026 16:12:21 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.213.63]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Sat, 8 Aug 2026 16:12:21 +0000 (GMT) From: Amit Machhiwal To: linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan Cc: Vaibhav Jain , Amit Machhiwal , Anushree Mathur , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Jonathan Corbet , Shuah Khan , Ritesh Harjani , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Harsh Prateek Bora , Gautam Menghani Subject: [PATCH v9 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl Date: Sat, 8 Aug 2026 21:41:48 +0530 Message-ID: <20260808161148.66673-5-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260808161148.66673-1-amachhiw@linux.ibm.com> References: <20260808161148.66673-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-Spam-Details-Enc: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfXzzjJ0qtsCbNd +9OzBcp7gBYdoo8TKQb2OXv+2m70vGbJidu18biu3MM/Y9fs3OU0E3gGwLeX74Wtwhb7vc0F0ky KH6VbRziyeuKB8NSQ9KgyZLbQjFjOQrw8GauiG2cq9bOWmt9AIqvOKVDQizBx1fBtlpUoGiepdC j0YsCDUfFBsZrEZMJkY8+5doUKQ0kGrrGHwCE1HELYn5LL+eHV37rjfXktMdklRIqHIJmKjKJ7r KXEB1D36fCdRIXpCkOsF+4aWpxyj21/hSQAl7Lm2H/9XkDkQGi8kFrujoRZGYsSAgOJbnyiUTWP f0bGLBSh4T6vOfF4Qh2cyFt5LWS66SWulFyGk8c14qtghiYIru+hY9QuxtvjQDTCyIXWYk67f4n WEdRPuTbulgJl+PB6hMLQQ8SE0AewH4dCCntIKT+1Qb4YUQh8y6QyAPLBe34JD+W6x9KYDUU3Ka 9+tx3kytJqUMg7zrdTw== X-Proofpoint-Spam-Info: AW1haW4tMjYwODA4MDEzNyBTYWx0ZWRfX5aaLY79UMRiI 8MiEHywuvTWT7774//X7Kfrg8bXVutzb5dzEuXF470ptwaz9QPLeFW65T6Us+ajSsVGRWqMSZt6 WVhg79n2y46M2707oP3VCAtMaJ36SNw= X-Authority-Analysis: v=2.4 cv=RqD16imK c=1 sm=1 tr=0 ts=6a77556f cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=hQeoMbdVOOR6M4iuoH8A:9 X-Proofpoint-GUID: nCJEZoLmeAcTg7JuNgY6yQYjvdRt3rYh X-Proofpoint-ORIG-GUID: u028xhPpvvCdjVTo0ORtRjWovfm7cRba 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-08-08_05,2026-08-07_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 bulkscore=0 malwarescore=0 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608080137 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. The documentation covers error code descriptions including E2BIG for forward compatibility, KVM_PPC_COMPAT_CAPS_SIZE_VER0 as the minimum size floor, the rationale for rejecting non-zero reserved fields to prevent ABI ambiguity, bit numbering clarification for IBM MSB-0 convention, and KVM-specific capability bit constants. Tested-by: Gautam Menghani Reviewed-by: Gautam Menghani Tested-by: Anushree Mathur Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Amit Machhiwal --- Changes in this version: - Simplify versioning paragraph: drop the three-case explanation of copy_struct_{from,to}_user() behaviour; keep a single sentence referencing the functions [Ritesh] Documentation/virt/kvm/api.rst | 77 ++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index e3003a241d5b..3660d7478fb9 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6566,6 +6566,83 @@ KVM_S390_KEYOP_SSKE Sets the storage key for the guest address ``guest_addr`` to the key specified in ``key``, returning the previous value in ``key``. =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 (in/out) +:Returns: 0 on success, negative value on failure + +Errors include: + + =3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + EFAULT if ``struct kvm_ppc_compat_caps`` cannot be read from or + written to userspace + EINVAL if the ``size`` field is smaller than + ``KVM_PPC_COMPAT_CAPS_SIZE_VER0``, if the ``flags`` field + is non-zero, or if the backend fails to retrieve or map + CPU compatibility capabilities + E2BIG if ``size`` exceeds ``PAGE_SIZE`` (pathological input guard), + or if ``size`` is larger than the kernel's struct size and + the unknown trailing bytes are non-zero (new userspace on + old kernel with non-default fields set); in the latter case + the kernel writes back its own struct size into the ``size`` + field so userspace can retry with the correct size + ENOTTY if the backend does not implement the ``get_compat_caps`` + operation (e.g., on non-HV KVM implementations where the + required KVM operations are not available) + =3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +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 +KVM on PowerNV (nested API v1) and KVM on PowerVM (nested API v2) platform= s. + +:: + + struct kvm_ppc_compat_caps { + __u64 size; /* Size of this structure */ + __u64 flags; /* Reserved for future use, must be 0 */ + __u64 compat_capabilities; /* Capabilities supported by the host */ + }; + +Before calling this ioctl, userspace must set the ``size`` field to +``sizeof(struct kvm_ppc_compat_caps)`` and zero the ``flags`` field. +The kernel rejects non-zero ``flags`` with ``-EINVAL`` to prevent +uninitialized stack values from being silently accepted, keeping the +field available for future use without ABI ambiguity. + +The ioctl uses ``copy_struct_from_user()`` and ``copy_struct_to_user()`` +to support extensible versioning. + +``KVM_PPC_COMPAT_CAPS_SIZE_VER0`` (24) is a frozen constant marking the +size of the initial struct version. + +The ``compat_capabilities`` bit field describes the processor compatibility +modes supported by the host. The following bits indicate support for speci= fic +processor modes (using IBM's MSB-0 convention where bit 0 is the most +significant bit): + +- ``KVM_PPC_COMPAT_CAP_POWER9`` (bit 1) -- KVM guests can run in Power9 p= rocessor mode +- ``KVM_PPC_COMPAT_CAP_POWER10`` (bit 2) -- KVM guests can run in Power10 = processor mode +- ``KVM_PPC_COMPAT_CAP_POWER11`` (bit 3) -- KVM guests can run in Power11 = processor mode + +.. note:: + + The bit numbering above uses IBM's MSB-0 convention (bit 0 is the most + significant bit). In the actual implementation, these are defined as: + + - ``KVM_PPC_COMPAT_CAP_POWER9`` =3D ``(1ULL << 62)`` + - ``KVM_PPC_COMPAT_CAP_POWER10`` =3D ``(1ULL << 61)`` + - ``KVM_PPC_COMPAT_CAP_POWER11`` =3D ``(1ULL << 60)`` + + Userspace should use the defined constants from ```` rather + than hardcoding bit positions. + .. _kvm_run: =20 5. The kvm_run structure --=20 2.50.1 (Apple Git-155)