From nobody Fri Oct 2 01:07:28 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 7F8E536DA04; Thu, 6 Aug 2026 17:07:20 +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=1786036042; cv=none; b=W799TdizL87UmtbUKHuFfYDnDV4IprbpKDXminZPrzFKJNkNhqkAyztTSMSYerXDEdMk419ry57WkN0h/RnMcIUSvmLylmMCRf3cp+jaCQ43/V3jBRF8dljDdXeAqnk3DsClfx3JelZmdS56tGQUcV66vsq1jIFc76otELC5kf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786036042; c=relaxed/simple; bh=sGw/4+Se6//bBk39ScVJ//Pyli6DxqVRzoJdSG5NQ50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sh7of14o6ZVYxXKjI2cKeqQmBzwobUZSCIbeDCUyfp+K7BeU65ZekWsxKCPoFJzOqyQubFnUZixnEls2/qTJ9F7Q2c+6gEWTI2VsEQceaaL8Ftvufy4JYs2bXZNMLAqkyx6Xq3eiUIxlN0hmqdV0XJo4MAgDPk2B8Dqmi8z6gSw= 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=FrgXaUd+; 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="FrgXaUd+" 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 676Eo06U2966159; Thu, 6 Aug 2026 17:07:07 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=XF0yfXZadJRhpb/eQ /yc//gnd8Qnt7yOLj2Rb/LJK5Q=; b=FrgXaUd+HVvOdXXBLbHgcio4NjdExVp67 iRpyllY0MNctZ5cl/q+oo17GJr/mu/Jw0TWLtGWBLNjNHRLh06tV9/5nNclDihXY ldk8jBbTl41bbG8551aPdJ/xFyjKRArzdDXHNpYRCO+Lr4V6ovqIPkkYtXmSvo1D fB3EeVJtuSY+ckf5A+KLkKDVRNvLb+F6rNSjpOg6/3rZGqE/w3xtOo7qBa1KVJCL uRc0VM3JukD+QGJ6EotpxIblWTFE+s48s+9e50PupzII5KHWh/7LgpFYJOibwY9z z9TK35Hk3YeOXHY0wS/BqX1z+NXUaehEJCvJ+D6Tcd1HZTB9pRwHA== 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 4fs8h59gpw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:06 +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 676GuNIK004041; Thu, 6 Aug 2026 17:07:05 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fswtyuw55-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:05 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 676H716Q32047494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Aug 2026 17:07:01 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B721520043; Thu, 6 Aug 2026 17:07:01 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5FED20040; Thu, 6 Aug 2026 17:06:57 +0000 (GMT) Received: from localhost.localdomain (unknown [9.39.29.233]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Aug 2026 17:06:57 +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, Gautam Menghani Subject: [PATCH v7 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Date: Thu, 6 Aug 2026 22:36:42 +0530 Message-ID: <20260806170645.11892-2-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260806170645.11892-1-amachhiw@linux.ibm.com> References: <20260806170645.11892-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-Info: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfX1i8d98aaaXYk lOnqE+CT7NWzJWlYS9ulEc3fE+N1uEhjAmz8DwJDX+lWwrdtV+kwo9y1VCRBybc5VvHg/hYEAR0 V/Vy3SC9e8jf9NbjHfqla+rnHkbsCrg= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfXw5CDzGHTj1Kk OVIubkRZ9h72hyFgoGyPxXZx/ubTPcrl40ga32AKxmcmzFi1MlBFH7ybuQnIXzzp+p7fkjOzYiV k02/kv6BDJkqryExZLKxRVMzke6hkuz64QJZkGOKrFRbaDBCQhkSbZn3wU1p777YDw9P90jbdlw moZgHmsDLkHWrH0ex8vdXotT1T2mFVwJyzpn6+cgGe0j+SKjnExr1EoyCQKEIePAoInMCpHjkIP FnwHJCAQa8JEHnx8tQjk2V7kdokw5dX43CYnPSE/TWHLNhO25PIlkkdUw9JG3weyE65SyowCCoW 9n4rd+RTIYAIK77sQNq6QRm1oetXZO/kB4POmH7pBLzn2B/xZckjHmuD3t8Msrx0J5omopuGSTs jvxKQQ5c0qRsDXL5CL4pdIn4SNHyJh1fXWkd0jAB6pcipLpdOfv3VPMqcavQh4Bfvj4O812dCZq ouOsVxDl1kIN8iNUrrg== X-Authority-Analysis: v=2.4 cv=SI1ykuvH c=1 sm=1 tr=0 ts=6a74bf3b cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=rQyBRTFaFC3FL7QHXY8A:9 X-Proofpoint-ORIG-GUID: xw4h6RMYoy5kFufRhgRZvgjVBJV1WePw X-Proofpoint-GUID: ysCEd5QDaFYDo4jTNYcOiNiQ16EPj3ac 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-06_01,2026-08-05_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608060131 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, while newer userspace passing a larger struct to an older kernel (usize > ksize) gets sizeof(struct kvm_ppc_compat_caps) written back to host_caps.size so it can retry with the older kernel-supported size, after which the kernel returns -E2BIG. 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: EINVAL for an invalid size or non-zero reserved fields, E2BIG if new userspace provides a larger struct than the kernel knows about (with ksize written back into host_caps.size for the retry), 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 Signed-off-by: Amit Machhiwal --- Changes in this version: - KVM_CAP_PPC_COMPAT_CAPS: add hv_enabled guard to align the capability check with ioctl availability; a PR KVM VM on pseries now correctly returns 0 for the capability [Sashiko] arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/include/uapi/asm/kvm.h | 8 ++++ arch/powerpc/kvm/powerpc.c | 71 +++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 3 ++ 4 files changed, 83 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..e64b3cfadd3a 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,70 @@ 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; + + /* + * 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; + + /* + * 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 (usize > sizeof(host_caps)) { + host_caps.size =3D sizeof(host_caps); + r =3D -EFAULT; + if (put_user(host_caps.size, (__u64 __user *)argp)) + goto out; + r =3D -E2BIG; + 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) + */ + r =3D copy_struct_from_user(&host_caps, sizeof(host_caps), + argp, usize); + if (r) + 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; + + host_caps.size =3D 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 Fri Oct 2 01:07:28 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 E86AB481235; Thu, 6 Aug 2026 17:07:24 +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=1786036046; cv=none; b=G3+G3vRNNSFlDwuuVvEVq7cVKS3St3jdDbzHqCQlVm550TCcOGxT3KmsTM4PLJ6cH3NrLqRz8039VIz7gTmrdJ45lIPR0oMs4+g6JsXzzfVHuWLHv06WLR2qeEbziA/wMU48O2h8t3J9CKEkW6Y6dqxO4C5jWwtsX5blazi+ITY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786036046; c=relaxed/simple; bh=lfBZOX1VQKYCZHgXLZTOBLmjIuOzKe9t684VOkMklJE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YbuwZuAYp/vfBhAsB1pVGzQ546z66/v50SVbaFrPz2gULm/VR8znl/SbmUnAo4pcb5mwewwg8XUyuzNXD9LkO2I02XUW+8PAZrD0/P4GtRjB63qeE8qyGBiLB+s1o28la/ZmBy/YqMo/BjmcpfuVcMSujzpvJYKktojmbqy+Wvw= 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=RsAkDLBG; 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="RsAkDLBG" 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 676EnWSB2964719; Thu, 6 Aug 2026 17:07:13 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=3UZH/zqW2AVZf/DrJ +f2oTkR6dbVp6LIpNDQn2wmwM8=; b=RsAkDLBGWm8k/5yLJSmD+WACV0OQmS2zn ytg+NPgUAd2wgKWWo5y2IopSAfylMSnAmCdwzZFT3pvO6YYyutWKSZ2RXjFOPmtY Z5HuCnZzpgFX/uoBJFesLG0lbgANW+6iuYZy94LrakFj7qFf4wEGgBF89SirwHhr X01NTpyTIECtyN8NeEcnohl5ezxEUnmjAelJNuIkqulTf5/xqPuphcAInuX4we9+ LjziOzx947job6HvRVLakoVwrKWDBLJKdl2SnXWjFBhp4xXWlihE5tYNM6RVFIk1 ZPDiZdFWIHNDB7H/7KR5EDXoW0GXAQjkWBvyNWe+HlVMuJKjCBgFg== 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 4fs8h59gqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:12 +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 676GuYHK008520; Thu, 6 Aug 2026 17:07:11 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fsugwc798-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:10 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 676H779D48562524 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Aug 2026 17:07:07 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5F2920043; Thu, 6 Aug 2026 17:07:06 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C83920040; Thu, 6 Aug 2026 17:07:03 +0000 (GMT) Received: from localhost.localdomain (unknown [9.39.29.233]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Aug 2026 17:07:03 +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, Gautam Menghani Subject: [PATCH v7 2/4] KVM: PPC: Book3S HV: Implement compat CPU capability retrieval for KVM on PowerVM Date: Thu, 6 Aug 2026 22:36:43 +0530 Message-ID: <20260806170645.11892-3-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260806170645.11892-1-amachhiw@linux.ibm.com> References: <20260806170645.11892-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-Info: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfX199dhqw5TvmU sa8YlkNKPYHBziDNLTY5vM9GjIuKtyAnQyyFX5I6TbF7TbLgIIH0jjHsDhpGUR6D8qtzV/Q+cSi uiCq7DLua5epV61fNpZk6wwvFsgIgcc= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfX17ugA259lhzH W6dp8CukQzZu96oD/fBnAsKwQGVla6vXgY88jU6Prg4Q8PtWM+Rzfvm6KdgUawKYujFVbCjUYeV DVF05Lm8FyLocmwUEvVp9QMnWxI2xDdEC+GcoVRGF42IRZ4LYSQguIFeT44biPbbbvxoArTTfvR cDUy81mB5mQJodRMBrZxCEbHdBBo7BDPOq1eo6eatf5jQQitAmsHnPhOSh5xAwl3xMVrsvXqDtS iNS1fwZGrlcIz6KWYC18rlfOKDBYM3PDx9dZvMUTzbAPtHqowea39elcyy9cXQcsVJAhv+0J1rM k7FsFC974tutmW4yMSZdxVrXF2b3mIODUMxAgEDI0OX25aT+sPoffam2rT4akFN3aC5U9Nh+E2r 65YFwYHxNxR7+AIc96B6U+5ItKyZ94Ssc+uoMAvWxYXLhDiqtR6i/xKMErxDuxAz+k5lsweNR9U VmIz3zpBaa4lI6TOcsw== X-Authority-Analysis: v=2.4 cv=SI1ykuvH c=1 sm=1 tr=0 ts=6a74bf40 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=igDgF-0WGXUSGxExIdQA:9 X-Proofpoint-ORIG-GUID: UXq2YvKsH4VdYDIYSVhRaq6thgwSKCfE X-Proofpoint-GUID: R4wJaup2cdv5Xo0vkjdf7UqZDVUqH_4k 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-06_01,2026-08-05_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608060131 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 Signed-off-by: Amit Machhiwal Reviewed-by: Ritesh Harjani (IBM) --- 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 Fri Oct 2 01:07:28 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 78C39486656; Thu, 6 Aug 2026 17:07:32 +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=1786036053; cv=none; b=uPbcmVLg4AAdeIuLVkZZdGrx2wF85iOtBt8WW0EPBQTP3hddP62QJMu31FGRqPmsa5rthiFLd+19f4QKAXFTYtHPP0wICOYoP++gdhDZwVvIwW0G+xP1w02X6nNjVMKBwO+TsWRYZrbrDTATW/VZOzTV1t+z22pUIMb0aC25MSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786036053; c=relaxed/simple; bh=h5gGSAJqwt9dfOnoJKv5CZ1c5uD/ojyDb/nuDlHko6s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rr2G+DuECVR/As6n6puR0JC9GnnhweBYq34JWVvfg7IYhXT00VsTLMCYBKteYnBFq+0RyDMdTII3hSOpNYVAl6SdHhavnuwVpR7SJTJCjkYh+uK5aXT5OeUyrIVIAoWgHIF8LnwmwIS4pbkyzeGuuubvRUxQwFx7wtemFO+i6TA= 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=Gkc6Zz1u; 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="Gkc6Zz1u" 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 676EnKvo2964512; Thu, 6 Aug 2026 17:07:18 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=yMuovlYNoPVAGbCdU wJL8fEbqTXkZMqSQabPEyNkVFo=; b=Gkc6Zz1ukzBR/YXdeVmaogUkQ6wazJUlK rChF1fdOhLwd5eaw6hVt45GTojrCJdRi4DCbtxStEfnR6AoHf5N5rNNBxXNvtAcT J5mz2tDOwtF9kKmAyrZetHQbwbg3WBc1NRyQB7cDrt2teUWO7txrsZMV71/5heCr lx844n0dbf3KceSPCLwFohNUG/0cpzNFKqui2/28hxMyONXpgsnsFg1TGXI6ehI9 2++Z/q3TzKehBnGl6q/iW6wZi8iWhEBq/I5PB7BmYAPjW4z5YcfVvLhzu+kBin2y a/IlhVWvuYfZzUCqc4Mdy/JNT2JSglrrURMv7xFXCALOGZdcHcDbQ== 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 4fs8h59gqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:17 +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 676GuK9r027179; Thu, 6 Aug 2026 17:07:16 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fsu4qv86d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:16 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 676H7CEh35193124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Aug 2026 17:07:12 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD6A92004F; Thu, 6 Aug 2026 17:07:12 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 65FE620040; Thu, 6 Aug 2026 17:07:08 +0000 (GMT) Received: from localhost.localdomain (unknown [9.39.29.233]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Aug 2026 17:07:08 +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, Gautam Menghani Subject: [PATCH v7 3/4] KVM: PPC: Book3S HV: Add support for compat CPU capabilities for KVM on PowerNV Date: Thu, 6 Aug 2026 22:36:44 +0530 Message-ID: <20260806170645.11892-4-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260806170645.11892-1-amachhiw@linux.ibm.com> References: <20260806170645.11892-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-Info: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfX0yCfz5mMpgvI 1cnABRKDnHez0P4BX7wZC4x06D2amM3xPU0KdHe+PhjA0oSrXEVHoDw+jJVNb04OSkH5K4EULOx EPgUPHWfLKHCsOeZ7Yt3SXjZPtXA2lI= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfX9MvE3AaHZ4zL ziAXDij/lu9mFLsM6Xk4FKtoYw64Nip7QUd9I0QFHnRgd1xGDNLo3FfxxRhHB3uCSRW7lFsFCar IeXTmANbn9Sh5bKG0iT7PQ4RZm+4w7kv3JKviWA6TsCbFmx4neXXZdx+cTDuyenKH9XZcDpVY1g T2oFfz9GWgOwcHfK1IkYYp2S1qCiiMY4+CSu0YSgk07lEoTHFo7FPLzXAqqUypJYHOwhxx3al1W vvCb1CzDIOgU7A3SK434a/Eep58q9ERJGrsheO0Q99tJXI7XE7AgYS6IlqpPUrK9mRkrVBGm6zW xvUc0t4UGYoWoZTF/bZGlfxBUabxjzaxjsT2KwDSCDo2r/8Kiyown5ym6hf99XxzOh7Upo6DHap KdsLgEo/xCYoZI4qdD46JIs/rv2FCV6OnN0TJKTexHSskdkr8Vv/HjkZNWghMVePpqdxs9QU0y4 rgTb/pguL6zVxXMicPA== X-Authority-Analysis: v=2.4 cv=SI1ykuvH c=1 sm=1 tr=0 ts=6a74bf45 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=jUdWb-NNBahwQYUnPB4A:9 X-Proofpoint-ORIG-GUID: vCfhGG6qW97fI-tVMJhJ0cdl5PPjASml X-Proofpoint-GUID: f-mfj4m961nYMKtJ0-UUgSaEHB8x6QgH 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-06_01,2026-08-05_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608060131 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 Signed-off-by: Amit Machhiwal Reviewed-by: Ritesh Harjani (IBM) --- 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 Fri Oct 2 01:07:28 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 199FF383985; Thu, 6 Aug 2026 17:07:35 +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=1786036057; cv=none; b=SrOLJmDvbqTSTKC3bs9nk9dYzV1nkcTuU4OOEZnLHhJN9N/1h75rDjWLSJWWrqEHx/0xlhoZfYyheTKgtSBQS1Wc/zPFbBKI5vTcMvCUTI1Nd+XKVk9rNF+WMFqWNhptJ0FtSta8WfNexXCQHHmPeijrC/5cenRlbuc1CcaOX/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786036057; c=relaxed/simple; bh=7k4XtMe2X04yNyNj2a01UGr7fn5/nj2GLM2BeexsB/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uWUT+hGev9yKO3CHzL5JHZydf8wceNoai3p7PgB3Ql10CSwDQoBO/M2dhs+Hz5InsARKZa5Ifd5j+mdz3D5eaMMCj3jBz7xgPijOTLWJdOvnPMHYhyhYbIWJEpE3SAyXQDrHKKT0itrDC98RSs4GGyu0Qah5jxlpkmKJJXIOmDI= 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=ZigxcZTb; 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="ZigxcZTb" 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 676EnPmo2964624; Thu, 6 Aug 2026 17:07: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=lJjm7fV9B3IrJoKoO lwYmwHQt7I4o7Y3zjGXhi8HHGE=; b=ZigxcZTbkpm59014cbIZ/DmqwmeuUwkdg Z2i9M6P5TeJmSLqC/AGy208z9zT2bDtKWu/KWtOWL0aFN7ONraRtmR506Nn4CmL8 rkbOAhuw8LGmjqbTvl2zhFAqwrZwOF/tN/qTUkKy9bKMd2YBb0lAo0klvlDaGaED ulGbWxYHQrtwygh4dYvYt363xrOEQ+mglnpIym1w22tSYcRXu+tyrRqXLWkT6cm+ c2S0ffqBlblA+jl1E4IKUVQ+7ka98ozi6WjNXBoov1u3KGWkdYRipOoo0D6c83vZ g0tJ6JK0/wPTvPxt7vEJeiq49odDW0sC7ttjwhQYjVvGhP0HA+ftA== 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 4fs8h59grg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:23 +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 676GuGCl004002; Thu, 6 Aug 2026 17:07:22 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fswtyuw6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 06 Aug 2026 17:07:22 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 676H7JXn25952600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 6 Aug 2026 17:07:19 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F02E220043; Thu, 6 Aug 2026 17:07:18 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E2542004B; Thu, 6 Aug 2026 17:07:15 +0000 (GMT) Received: from localhost.localdomain (unknown [9.39.29.233]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 6 Aug 2026 17:07: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, Gautam Menghani Subject: [PATCH v7 4/4] KVM: PPC: Document KVM_PPC_GET_COMPAT_CAPS ioctl Date: Thu, 6 Aug 2026 22:36:45 +0530 Message-ID: <20260806170645.11892-5-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260806170645.11892-1-amachhiw@linux.ibm.com> References: <20260806170645.11892-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-Info: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfX/27nE8Rhlb3C UYsmk+BQeItAWU7usouu63M6HKB4a9Nr07hPN/wJlslNuGEjFM33WZIJmx2rlu3s7QBDaoIYPWH wgzl30LN6LnsBNd9Z6WDscjlK8Y8c4w= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA2MDEzMSBTYWx0ZWRfXxvjbhlhYrdMZ Yc/ITkwUrMM5WzihO8hRozRs3Kv3sylx8HZPnbIWKpTV5+R4yAkNUzophI5a5zA5A+nAKwCOzB6 PR+N/MbH5s0WQaoOjd1ilxk5dM3PEE4eg83x8eS83ugCIbJ5Os8C8W90X3a+gYLdUDa2ay2tOye zwb3sPp2qFd/pTP6PMhxEwyy1JngDyCoX3g2+3ZdYE2DUdOG9fKPmQyPztF8g1hFDHMRc2BDAke rWaY0ietaQkXKw67I6AEgxFnE2ehXGd/e3nZN0v9QJQn8zpWbFedQR0T8LMjLlesBqMvXfZDYQJ 1LALgY+Tq0ohaTuOyu3Or1A2u6bEQtFOSSj3K23tF4itDbyUebLtfh8ugNMkD7vde1V2XoMtRwL sppm58GnWreTzoixx6VIkFIRLaJ4Bm4ZlpadceqWPHJZ4c9LuV98az5ts9gjFl+eSdE6Zuiu5XX jpSaVW262rUGYkQ2wlg== X-Authority-Analysis: v=2.4 cv=SI1ykuvH c=1 sm=1 tr=0 ts=6a74bf4c cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=hQeoMbdVOOR6M4iuoH8A:9 X-Proofpoint-ORIG-GUID: 6616m_niNNu7FcKrIYBn4hbKJwqXpNWC X-Proofpoint-GUID: uNKFwZfwU-lddH9JFZG3s1Fy6uF6DjKt 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-06_01,2026-08-05_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608060131 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, the extensible size-based versioning contract using KVM_PPC_COMPAT_CAPS_SIZE_VER0, 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 Signed-off-by: Amit Machhiwal --- Documentation/virt/kvm/api.rst | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index e3003a241d5b..22fedb0aa34b 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -6566,6 +6566,85 @@ 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`` is larger than the kernel's struct size + (new userspace on old kernel); 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: if userspace passes a struct smaller +than the current kernel version (``size >=3D KVM_PPC_COMPAT_CAPS_SIZE_VER0= ``), +the kernel zero-pads unknown trailing fields. If userspace passes a larger +struct (``size > sizeof(struct kvm_ppc_compat_caps)``), the kernel writes +back its own struct size into the ``size`` field and returns ``-E2BIG``, +allowing userspace to discover the kernel's struct size and retry. +``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)