From mboxrd@z Thu Jan 1 00:00:00 1970 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 73D4E4B04B4; Sat, 8 Aug 2026 15:47:20 +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=1786204041; cv=none; b=SuFMyc2hjCZAkfpNwgOaUCojGsd3UOrAfmd8guQWAsGg8PhBIjkgVbqQn7FVZehZlgnzIKvEfMOB9AeWTpJtdoSW5FfmAIPkH/n/uSGCAjXhgkVNdMOY4//shnXui3tqdIEckQ/HQhIY1bU/t/ut2qONFUHK0/gd7itUweXSmBc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786204041; c=relaxed/simple; bh=W+zDyckWcaqeFwDmOuqw8+SF74+4tO84NyhlK2Cp7LQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c1jQIZ9V6enD6fB721DIEwdYb7KpbbNjcputUxX/5WvY1m2xWDgskFoe4bv8CAeGKoTg8PFT8ychrU+1/7HggK6ZHi0Q82CgjtxwoCbsF+JkMLWzNBPCswA8KUm+f8imWHc7O/Tdk4CuA/VzyI7b3scI6IUG7dquwJgGWBN1Sks= 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=IXluFmCR; 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="IXluFmCR" 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 678E1ln6259289; Sat, 8 Aug 2026 15:47:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=pp1; bh=FrIH1BwpV+FxMvs8gwOSN9G7HnHmcc /DVjgKEncP+Fk=; b=IXluFmCReS72oCFUx9rLFcMJ9f/yJdrKe5X9V3sbloZYdF SRiO3uQ4VQ+Z0KwLnPVbfMYiFIK5emc5VDCv+2flpeU/u8hnfob8pqUYu40W21rS 8Q/yMej0hPicV3ezcB85Nsxe8f8Nh+8pvmyhP1CknuZiOMBbRh0ZFJSb1ssc2068 +AlUpzVotJNWsjevvV0mtW1pTsx7NctXI0w854/KlTYFXxvIhxIaqEKJLbY3NzCX 5oIQK6xwhGwzJToCLBMyzoqXtBlYLP91tC6cH06do92me7S5MSo7nFpUjSj2WkIz MjMqnxV2V4G/vqcR4NXP7LHeri5K6ZMvqAT3M85Q== 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 4fwvkchfgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 15:47:01 +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 678FfM2W022128; Sat, 8 Aug 2026 15:47:00 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4fsu4r411y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 08 Aug 2026 15:47:00 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 678FkvIP49807640 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Aug 2026 15:46:57 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 007A120043; Sat, 8 Aug 2026 15:46:56 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B6BA20040; Sat, 8 Aug 2026 15:46:54 +0000 (GMT) Received: from fedora (unknown [9.5.7.39]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTPS; Sat, 8 Aug 2026 15:46:53 +0000 (GMT) Date: Sat, 8 Aug 2026 21:17:01 +0530 From: Amit Machhiwal To: Ritesh Harjani Cc: Amit Machhiwal , linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan , Vaibhav Jain , Anushree Mathur , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Jonathan Corbet , Shuah Khan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Gautam Menghani Subject: Re: [PATCH v8 1/4] KVM: PPC: Introduce KVM_CAP_PPC_COMPAT_CAPS and wire up ioctl Message-ID: <20260808211615.fb580df8-72-amachhiw@linux.ibm.com> Mail-Followup-To: Ritesh Harjani , linuxppc-dev@lists.ozlabs.org, Madhavan Srinivasan , Vaibhav Jain , Anushree Mathur , Paolo Bonzini , Nicholas Piggin , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Jonathan Corbet , Shuah Khan , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Gautam Menghani References: <20260807172433.82045-1-amachhiw@linux.ibm.com> <20260807172433.82045-2-amachhiw@linux.ibm.com> <33wpl93b.ritesh.list@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33wpl93b.ritesh.list@gmail.com> X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: j4pVYzYdoZRZ-U3rgaTnNgutwnthaIxI X-Authority-Analysis: v=2.4 cv=J86aKgnS c=1 sm=1 tr=0 ts=6a774f76 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=kj9zAlcOel0A:10 a=Sv0fKeRqtYgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=GS9XHCjG0vJnGz0bkuEA:9 a=CjuIK1q_8ugA:10 X-Proofpoint-ORIG-GUID: rwUD4KyU_OQVmlz7QKZ90lFsrhrZs0_j X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA4MDEzMyBTYWx0ZWRfX3M1+TSfnxxfC kNTxMImUEns/RGp0MoyOHwl8hCQhc4Y9L7GuFefCQX8+MXGun1o3Q4nQwu57xWLe+TRxqdbivEd Yh7mowd0L1YjD2yJusRP3Cv8W+fCWkj+oyjeibgCey0DH2VHS3g0cjhCKrGwShkEaRVOcY1jXFn LPPmzOhDsO5hQyfr4VqQl97x3c4/fJw+qB6buWUAXLHyKdS/fYOFHDaXlJ+THLEp7qhAxikHazr plI8MDxiXQ2pm4o2b3DKP89lKzrcIdDUZ8AAtKO+P6cIdG4eko4Lr/9WJLyQd2gLaC1LBGaPrx8 mo1ER1RH9at3HISLN+9F2kxZxMIeL9UzGrTaDCVp8uzGuCljBvvq1dGeUNTP6sf0ZHsnYhM/L/I PWwuIfOFk5m9NPdCpLAAn0n4PxqhEeeLfir3jkMw0Pqpg4ujwqg5VGZECKsMEUy9Y61y9JShqVW 6yqQZG3cDp52GpeGj3Q== X-Proofpoint-Spam-Info: AW1haW4tMjYwODA4MDEzMyBTYWx0ZWRfX7AV8sYm4erfQ QAnykkoVE3sZlYx44mNJt5hIiChyiND/cRGHZzDgzwIf5n11XX4yqFX4OPUF4xfe52QFdF3s9+k QI2fXQnPkaJb6xINllP7B+UqNWf2le8= 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-2608080133 On 2026/08/08 06:30 AM, Ritesh Harjani wrote: > Amit Machhiwal writes: > > > 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 > > Signed-off-by: Amit Machhiwal > > --- > > Changes in this version: > > - Add PAGE_SIZE guard after get_user() to bound the check_zeroed_user() > > scan in the usize > ksize path [Ritesh] > > - Drop manual usize > sizeof(host_caps) pre-check; delegate entirely to > > copy_struct_from_user() which succeeds on zero trailing bytes and > > returns -E2BIG only on non-zero trailing bytes; handle -E2BIG with > > ksize writeback and -EFAULT escalation if put_user() fails [Ritesh] > > - Fix host_caps.size on success path: use min_t(u64, usize, > > sizeof(host_caps)) so new userspace with zero trailing bytes gets back > > the number of bytes the kernel actually populated, not usize [Ritesh] > > > > Thanks for addressing them! > The only remaining comments from Sashiko now are because, it cannot find > the implementation of ->get_compat_caps() since it is in the next patch. Yes, correct. > > So as for this patch, the changes looks good to me. Please feel free to > add: > > Reviewed-by: Ritesh Harjani (IBM) Thanks for the review, Ritesh! Will carry the Reviewed-by in v9. ~Amit