From nobody Sun Jul 26 11:01:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1782883481; cv=none; d=zohomail.com; s=zohoarc; b=jdxjCKkKf+bB634rkWBTWKus7X+NnAF1aM3WsZuN5l4dq29fXblXL7i91iNfYoGGP0AHm/LZx3/W6j8Lx3WtE3Srs8gorEM86f50hwwY6gfdNkcS4LRER8w1kDfwMKLmdJWBGXfMOBR4HMvQ13VcpO07dERekn/3cqcK445oKFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782883481; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=djYiciTOY1LazIZfVu0lv7Rc+0cP6IKZ+ziP+ett4Mk=; b=Zkisie0rSSNpwzjWYg4L0Yv5FpvDG6kVvlqvbbNQoKTmEVbxXpRQpDDqhOSodiaCnRCH4npfe771Xb7S8yVX+u4ryZGE2j10yM1j80o+WjtmlAt855Mka68+mYpRiZEHd+6GIAn2G+qnfu4Zx/MRBvRBffxcn+oDNp5GMKnwtm0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1782883481564499.43593634118554; Tue, 30 Jun 2026 22:24:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wenQi-0005E6-FS; Wed, 01 Jul 2026 01:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wenQd-0005DD-TT; Wed, 01 Jul 2026 01:24:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wenQc-0006rF-4G; Wed, 01 Jul 2026 01:24:07 -0400 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 6613ITPq3867661; Wed, 1 Jul 2026 05:24:04 GMT 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 4f26n5tp7c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 05:24:03 +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 6615JgdV022029; Wed, 1 Jul 2026 05:24:02 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4f2tbhdpyj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 05:24:02 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6615NwXf46530840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Jul 2026 05:23:58 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BD7E20049; Wed, 1 Jul 2026 05:23:58 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C343320040; Wed, 1 Jul 2026 05:23:55 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.211.190]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Jul 2026 05:23:55 +0000 (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=djYiciTOY1LazIZfV u0lv7Rc+0cP6IKZ+ziP+ett4Mk=; b=e9aA8VtGGBJgZzsRCdafPHEo3fHztzWrS xMersYXruaV2ENuj9u2/fQK65s4LrNLd0yLn9NqKjfALgAnZA8F3rZxCFvUk5Ceo DiI+OnNv1HoH2WzglhlCXkHlesTMVaQSM2xi825siFcU92t9m9IM9rJrVzjEleqe rRaMQtGCzFT3rp0TqeYThTE9hC3Ar7u1RkrJc9GeYR8uEGXsFJ2NsebmhkB1xT9f QbSf/gkBVe9WZzY4i0NHP1F3ZgrpDmpUApBnFJRNC32EFwKD6xh4I3OBUN4ujb56 +uIKPZ5pXX0+nSTFwCScIc3dzQPl9Ezn4cYj3Im1UR7+QaqxMp0eA== From: Amit Machhiwal To: qemu-ppc@nongnu.org, Harsh Prateek Bora Cc: Amit Machhiwal , Vaibhav Jain , Nicholas Piggin , Chinmay Rath , Glenn Miles , Paolo Bonzini , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v4 1/3] [DO_NOT_MERGE] linux-headers: Add uapi header changes Date: Wed, 1 Jul 2026 10:53:39 +0530 Message-ID: <20260701052341.62289-2-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260701052341.62289-1-amachhiw@linux.ibm.com> References: <20260701052341.62289-1-amachhiw@linux.ibm.com> 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: AW1haW4tMjYwNzAxMDA1MiBTYWx0ZWRfXwXecdgsGa3O6 3DqwVEwiQANjp66JzdVowjaY44kVKVkHj6EdLtH/OCeAjxIUlMN6Kg4hYdt9qgRnpkqop58ih7b wi1VyiKIICodbFsO0W14ToMlGj4rjDWYVoFTJhcmGTqO4b77Lsl+1EUbtuDTJx9dVbU16/fphG5 opcYH7QhEUo4rpxZRaw+4UpXdNeZzqRUFj6+oW3OzlDu6v1o7Ku86uIVeBi6DrnfuZB9cPUH85L ul6HpRGMw+V2x/QyvEaYQZaEZtYSNitP6+tmrpQu/D/p/6XryydutSC19txbbiDObRyiCoTh+Sd BE/2oQTdyDgoXbcbY/xPJ6AlDLkigsiyTCXII3TAjpiJDCU7/WZh6LrKXjtNM6yvdXV701mZXl9 0TeXwfE+Z0WvbIynQO6yPsNrZZOkyaIW3XzLKMZtmHb9ze/36Y5A1Q/Nr/coWF4VqUiSdJcUlT1 J/ERZ1KrAXspN2GXq3g== X-Authority-Analysis: v=2.4 cv=V45NF+ni c=1 sm=1 tr=0 ts=6a44a474 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=MBz6HKjOuQBNVPZFXNsA:9 X-Proofpoint-ORIG-GUID: 5Ba5R1ss5CozZLULh-WMhnNbrwg79i-9 X-Proofpoint-GUID: WpVQtmguszroi2JYXzDnhFy6wc7SAEJu X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAxMDA1MiBTYWx0ZWRfX/Ys7dZlLsZcq KgDmM+JLKlGahbA/OGEivt0g/dJAUKSOhRpJ07INUNB3lT94q8Hli5LZGZQsvJoxy5CdHbUI+R/ 3zgbUg4fHRtcqw7ljOhmnt0QhHidGyc= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-07-01_01,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607010052 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=amachhiw@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1782883483950158500 Content-Type: text/plain; charset="utf-8" This is a temporary patch intended for review and testing purposes only. It syncs the QEMU linux-headers with the kernel v5 changes that introduce the KVM_PPC_GET_COMPAT_CAPS ioctl for querying host CPU compatibility capabilities. The struct kvm_ppc_compat_caps places 'size' as the first field as required by copy_struct_from/to_user() versioning, with KVM_PPC_COMPAT_CAPS_SIZE_VER0 (24) defined as the frozen version-floor constant. The capability number is KVM_CAP_PPC_COMPAT_CAPS (250) and the ioctl is defined as _IO so the ioctl number remains stable if the struct grows in future versions. Capability bit definitions for POWER9, POWER10, and POWER11 compatibility modes are also included. The actual header sync will be done via scripts/update-linux-headers.sh once the kernel changes [1] are merged upstream. [1] https://lore.kernel.org/all/20260628083352.118b631-1-amachhiw@linux.ibm= .com/ Signed-off-by: Amit Machhiwal --- Changes in v4: - Changed ioctl definition from _IOWR to _IO to match kernel v5. - The ioctl number must remain stable if the struct grows; the size field is read first by the kernel via get_user() before any copy_struct_from_user() call. linux-headers/asm-powerpc/kvm.h | 20 ++++++++++++++++++++ linux-headers/linux/kvm.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/linux-headers/asm-powerpc/kvm.h b/linux-headers/asm-powerpc/kv= m.h index 077c5437f521..e42c86481320 100644 --- a/linux-headers/asm-powerpc/kvm.h +++ b/linux-headers/asm-powerpc/kvm.h @@ -437,6 +437,26 @@ 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 = */ + +/* + * 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/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 50e87ed72c20..6aa70b8d2e61 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -985,6 +985,8 @@ struct kvm_enable_cap { #define KVM_CAP_S390_USER_OPEREXEC 246 #define KVM_CAP_S390_KEYOP 247 #define KVM_CAP_S390_VSIE_ESAMODE 248 +#define KVM_CAP_S390_HPAGE_2G 249 +#define KVM_CAP_PPC_COMPAT_CAPS 250 =20 struct kvm_irq_routing_irqchip { __u32 irqchip; @@ -1329,6 +1331,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, 0xe4) =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 Sun Jul 26 11:01:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1782883482; cv=none; d=zohomail.com; s=zohoarc; b=dFsQ4iEAAMiUw98f1k+BN6Da+QJeipRxlJXUkTp41cwWiy53FfBH2cw6Q+0xdH2nN7bJNXgbaH4+Spb9LgP+T3C/xC6pvD6YYv8mgb3Zjcx2lWhIjArziLFOuKsRiAFMdVDRsBMxZwsvAUO6oiCC9nhU9GTVGYs6bLR4/1cJFmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782883482; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ycHh8YWky6M2U5WpcgzdlLDTxNHEDLB2b4+wAt3PiEo=; b=gt42C/Psx83/KiCG9W1UckcW3pXZqrN6+Cn4BCj+hUWnU+gxu8whlGhigZH9JKEIb/Xc2DSNSAof1O+pw5hmt/dYyD9I8BpRK4IJ4LuWosQhf2RQoeak1ficqUfSXGkjlojanPDB4fNDfnVbHGNeE2NLYEZZB43ZuERYlv5fwNg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1782883482590635.1869481456253; Tue, 30 Jun 2026 22:24:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wenQo-0005FH-Bt; Wed, 01 Jul 2026 01:24:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wenQk-0005Ee-OS; Wed, 01 Jul 2026 01:24:14 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wenQi-0006rj-6u; Wed, 01 Jul 2026 01:24:13 -0400 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 6613IPal3925383; Wed, 1 Jul 2026 05:24:10 GMT 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 4f26pe2q49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 05:24:10 +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 6615Jabh005574; Wed, 1 Jul 2026 05:24:09 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4f2ruqdy1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 05:24:09 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6615O5VO42991962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Jul 2026 05:24:05 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 78ED220049; Wed, 1 Jul 2026 05:24:05 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE3A120040; Wed, 1 Jul 2026 05:24:02 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.211.190]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Jul 2026 05:24:02 +0000 (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=ycHh8YWky6M2U5Wpc gzdlLDTxNHEDLB2b4+wAt3PiEo=; b=fhfV7Rc2k3QLL1bM2dLWKXNhU3ML6GxjL 4G8oTZX/8AhXyejPV8va5MEO9pSjSM4uAjlflnKFHuqblP40VkaxEHhCvK8iZAJW l6haIKzV9qaUFTkI1o7fOMiuV47N5bqC1zbPPHWsqt7e//8R8TsfnGENxdLlad6D LgM91yiLIb6M5oQfmp+B8pHi1AWL1yGgWkiLZvy34CBVzQ+3/vQtx4hUoHgBYHgJ V1KXP7rqO3iutmNsB3FvHaR4szgWfGEljQSjPWlt6x4rU54Z7qmESybunj19xhyD bumksWcXeIQCa4shxg3X3edfK9WH6XdfxQdwfYFyHkjiApNkQWBbw== From: Amit Machhiwal To: qemu-ppc@nongnu.org, Harsh Prateek Bora Cc: Amit Machhiwal , Vaibhav Jain , Nicholas Piggin , Chinmay Rath , Glenn Miles , Paolo Bonzini , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v4 2/3] target/ppc/kvm: Add support for querying host compatibility mode Date: Wed, 1 Jul 2026 10:53:40 +0530 Message-ID: <20260701052341.62289-3-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260701052341.62289-1-amachhiw@linux.ibm.com> References: <20260701052341.62289-1-amachhiw@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: UUhOgQjF6XzooNUPOEoOFW7IAZZwOnxI X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAxMDA1MiBTYWx0ZWRfX5yCPodqPAoUh FmZQRbC8HHCl2d/fNTPWLeDyIqtr3p8eWd95eidl7L5lsBd7i8/NpPff3KWHmQ4wzvSjjsS0NKH 4B3lCSnZn0L80xBOv/X/8GywmOQYrwo= X-Authority-Analysis: v=2.4 cv=edsNubEH c=1 sm=1 tr=0 ts=6a44a47a cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=MQa1r56DKncGqAxa_z4A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzAxMDA1MiBTYWx0ZWRfX4rWPsaq8Ep6k Yb3I9OLDr3WtUVU3bmuZFN5ubXYQQVvD2tQMnOYWaunQLy5aQ3h/74ll1YdeWs3rz3THulD4QC9 w5z3y7GXNnLxI373XYQJZlJY+tYSQw8WFpNY6FN2pb51cCA9PAiP4RZ1K0jshuAiu0OFj1dSCeD q7QSBMdwyoDJ/tt53eJ6KRWI+EDh6Sy853FYFKPNoO5UQYwC51kNTYRvnVTI01xxZC3QAhL0m3W SrNgYFs+2Shh9ARXruPpZvEU5wmlWoFQ5KTEBtg9iBRR5SXHz6vfuoW/y57cA37FXWRfYWOmcUa KPcHrqDh1d99BYjUc2yHRUfKayCntjHEu/85SEeELmC9GhqQ5QSFPOYKyz0kFE2o1HvOZyFcRYP 8WUwLu2k4CawThYHl1fcg9/PNZ/U0V6/VXWWUws2odtir+Vds6sknj+iFu7c9orMrHucreDPDXy j+LRQcznX+NQ+nKXjxA== X-Proofpoint-ORIG-GUID: HkHNPIdDznWlxOzZZsVKjlqYY89b2cvk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-07-01_01,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 adultscore=0 impostorscore=0 bulkscore=0 spamscore=0 suspectscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607010052 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=amachhiw@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1782883484019158500 Content-Type: text/plain; charset="utf-8" Add infrastructure to query the host CPU compatibility mode via the KVM_PPC_GET_COMPAT_CAPS ioctl. This allows QEMU to determine if the host is running in a compatibility mode (e.g., a Power11 processor operating in Power10 compatibility mode). The kvmppc_get_compat_caps() function issues the ioctl and returns the compat_capabilities bitmap. The kvm_ppc_host_compat_pvr() function derives the effective PVR from the bitmap using ctz64() to find the lowest set bit (highest supported compat level in IBM MSB-0 numbering). The struct kvm_ppc_compat_caps places 'size' first and userspace sets it to sizeof(struct kvm_ppc_compat_caps) before calling the ioctl. The kernel uses copy_struct_from/to_user() to handle forward and backward ABI compatibility: an older userspace with a smaller struct gets trailing fields zero-padded. When newer userspace passes a larger struct to an older kernel (usize > ksize), the kernel unconditionally returns -E2BIG and writes its own ksize back into host_compat.size. QEMU detects this, validates the returned size against KVM_PPC_COMPAT_CAPS_SIZE_VER0, and retries with that size. Additionally, cas_check_pvr() in hw/ppc/spapr_hcall.c is updated to prevent fallback to raw mode when the host is running in compatibility mode. This ensures that nested guests cannot exceed the host's compatibility level. The call is guarded with kvm_enabled() since kvm_ppc_host_compat_pvr() invokes kvm_vm_ioctl() which dereferences kvm_state; without the guard, a TCG guest on a CONFIG_KVM=3Dy binary would segfault. If the capability is not supported or the query fails, the functions return 0, allowing fallback to existing behavior. Signed-off-by: Amit Machhiwal --- Changes in v4: - Replaced fprintf(stderr, ...) with error_report() for error reporting in kvmppc_get_compat_caps(). - Replaced __builtin_ctzll() with the portable ctz64() helper. - Simplified kvm_ppc_host_compat_pvr() to switch directly on the capability bit value (e.g. KVM_PPC_COMPAT_CAP_POWER9) instead of a derived index, removing the KVM_PPC_COMPAT_CAP_P*_IDX defines from kvm_ppc.h. - Dropped the post-ioctl size mismatch check; it is not meaningful with the copy_struct_from/to_user() model. - Added a function comment to kvm_ppc_host_compat_pvr(). - Guarded the kvm_ppc_host_compat_pvr() call in cas_check_pvr() with kvm_enabled() to prevent a segfault when QEMU is built with CONFIG_KVM=3Dy but run as a TCG guest (kvm_state is NULL in that case). hw/ppc/spapr_hcall.c | 14 +++++++++ target/ppc/kvm.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ target/ppc/kvm_ppc.h | 7 +++++ 3 files changed, 96 insertions(+) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 23bcd788daf6..708902934cff 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1136,6 +1136,7 @@ static uint32_t cas_check_pvr(PowerPCCPU *cpu, uint32= _t max_compat, { bool explicit_match =3D false; /* Matched the CPU's real PVR */ uint32_t best_compat =3D 0; + uint32_t compat_host_pvr =3D 0; int i; =20 /* @@ -1163,6 +1164,19 @@ static uint32_t cas_check_pvr(PowerPCCPU *cpu, uint3= 2_t max_compat, } } =20 + if (explicit_match && kvm_enabled()) { + compat_host_pvr =3D kvm_ppc_host_compat_pvr(); + /* + * If the host is booted in a compatibility mode, do not try booti= ng in + * the raw mode as it may allow KVM guests to boot with a higher C= PU + * version compared to what host was booted with; which should not= be + * allowed. + */ + if (compat_host_pvr) { + explicit_match =3D false; + } + } + *raw_mode_supported =3D explicit_match; =20 /* Parsing finished */ diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index b94c2997a07f..b1b596f004ef 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2602,6 +2602,81 @@ bool kvmppc_supports_ail_3(void) return cap_ail_mode_3; } =20 +#if defined(TARGET_PPC64) +static target_ulong kvmppc_get_compat_caps(void) +{ + struct kvm_ppc_compat_caps host_compat; + int ret; + + if (!kvm_check_extension(kvm_state, KVM_CAP_PPC_COMPAT_CAPS)) { + return 0; + } + + /* + * Set size to sizeof(struct kvm_ppc_compat_caps) so the kernel applies + * copy_struct_from/to_user() versioning. size must be >=3D VER0. + */ + memset(&host_compat, 0, sizeof(host_compat)); + host_compat.size =3D sizeof(host_compat); + + ret =3D kvm_vm_ioctl(kvm_state, KVM_PPC_GET_COMPAT_CAPS, &host_compat); + if (ret =3D=3D -E2BIG && host_compat.size >=3D KVM_PPC_COMPAT_CAPS_SIZ= E_VER0) { + /* + * Kernel is older and knows only a smaller struct version. It + * wrote back its ksize into host_compat.size. Retry with that + * size so the kernel accepts the call. + * + * When a VER1 struct is introduced, add a check here: + * if (host_compat.size >=3D KVM_PPC_COMPAT_CAPS_SIZE_VER1) { ..= . } + */ + uint64_t ksize =3D host_compat.size; + memset(&host_compat, 0, sizeof(host_compat)); + host_compat.size =3D ksize; + ret =3D kvm_vm_ioctl(kvm_state, KVM_PPC_GET_COMPAT_CAPS, &host_com= pat); + } + + if (ret < 0) { + error_report("KVM: failed to get host CPU compat capabilities: %s", + strerror(-ret)); + return 0; + } + + return host_compat.compat_capabilities & KVM_PPC_COMPAT_BITMASK; +} + +/* + * Return the effective host PVR based on the CPU compatibility mode + * reported by KVM. Returns 0 if no compat mode is active or the + * capability is not supported, in which case the caller falls back + * to the raw hardware PVR. + */ +uint32_t kvm_ppc_host_compat_pvr(void) +{ + uint32_t compat_host_pvr =3D 0; + uint64_t cap_idx =3D 0; + target_ulong host_caps =3D kvmppc_get_compat_caps(); + + if (host_caps) { + cap_idx =3D 1ULL << ctz64(host_caps); + switch (cap_idx) { + case KVM_PPC_COMPAT_CAP_POWER9: + compat_host_pvr =3D CPU_POWERPC_POWER9_DD22; + break; + case KVM_PPC_COMPAT_CAP_POWER10: + compat_host_pvr =3D CPU_POWERPC_POWER10_DD20; + break; + case KVM_PPC_COMPAT_CAP_POWER11: + compat_host_pvr =3D CPU_POWERPC_POWER11_DD20; + break; + default: + break; + } + } + + return compat_host_pvr; +} +#endif /* TARGET_PPC64 */ + PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) { uint32_t host_pvr =3D mfpvr(); diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 742881231e16..195dbaac5e17 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -81,6 +81,8 @@ bool kvmppc_supports_ail_3(void); int kvmppc_enable_hwrng(void); int kvmppc_put_books_sregs(PowerPCCPU *cpu); PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void); + +uint32_t kvm_ppc_host_compat_pvr(void); void kvmppc_check_papr_resize_hpt(Error **errp); int kvmppc_resize_hpt_prepare(PowerPCCPU *cpu, target_ulong flags, int shi= ft); int kvmppc_resize_hpt_commit(PowerPCCPU *cpu, target_ulong flags, int shif= t); @@ -440,6 +442,11 @@ static inline PowerPCCPUClass *kvm_ppc_get_host_cpu_cl= ass(void) return NULL; } =20 +static inline uint32_t kvm_ppc_host_compat_pvr(void) +{ + return 0; +} + static inline void kvmppc_check_papr_resize_hpt(Error **errp) { } --=20 2.50.1 (Apple Git-155) From nobody Sun Jul 26 11:01:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1782883485; cv=none; d=zohomail.com; s=zohoarc; b=cLH/By3mKJDwxR9s/zn0CMLHguDRXNUfmGD3mvPkWaoB53nZONz3zYo0J1nyxAOaU09yy0//n/BRPF2QkW2A9g3Obvrzl0J1umCIzqlVM0F4dMGsqT+WwRhwrIWJm61YiUl3/d/Q3peuVgchVi9X9fLZygxxlKgzp+5n+X+Irsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1782883485; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DvUNM2yInTrMM5EIJza3iZuXRbSUIN7ITRWGH8qgp5w=; b=gz06h/7/4bTMsPcQh4xt+yJMLMleyU5kjXgNmZgMK9z/3f0PsDHy/4UdX/yrMlXWF1N0hC3MUV63ybm3Wgz/Wok0HNRJ9C+hRHescrOTNkYboWkksnVfgs/Wk9JmycStB3ZCvKyp61/AxM+wopOBuxN4W/vhSCqT5T/V96wZQuQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178288348500320.256517771625454; Tue, 30 Jun 2026 22:24:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wenQy-0005Kq-1X; Wed, 01 Jul 2026 01:24:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wenQq-0005HP-Ed; Wed, 01 Jul 2026 01:24:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wenQo-0006vA-Rd; Wed, 01 Jul 2026 01:24:20 -0400 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 6613ITPv3867661; Wed, 1 Jul 2026 05:24:17 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4f26n5tp9d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 05:24:16 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6615JrWK013686; Wed, 1 Jul 2026 05:24:15 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4f2u2gdmav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Jul 2026 05:24:15 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6615OC6v43778380 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Jul 2026 05:24:12 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 11A9E20049; Wed, 1 Jul 2026 05:24:12 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5EF5520040; Wed, 1 Jul 2026 05:24:09 +0000 (GMT) Received: from localhost.localdomain (unknown [9.124.211.190]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 1 Jul 2026 05:24:09 +0000 (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=DvUNM2yInTrMM5EIJ za3iZuXRbSUIN7ITRWGH8qgp5w=; b=AL+w5b2V8SbcNO8waMNtCWbLSYVEMQaba fCPyWipDINFw7LEygHrCTKpjb/MvVYaCvthzyTFoD8SSicGvTck9xNcW5XtgYN6i 3DqBlUm5YQssE2zmqtI5nPI43fR7PSTDIQh9Gvm12d5hnkM9BZJ2ekJ9cULcPKKA 1qq9Hm6AwdzmZfP6dkWN4FbD30Ktk7Jx+X0rR8/MrUKsRh/OnkYBZQK9j1qiYC7s Ni7euZBIpTJQP1f/X+vFvuv2kwi8E4thBhtV4D2i8j7LHrajEupJIOQDxBNqVs0k f1Wn86KIMGso0ojAKmVcrYC65hUTr0n5TPAJYspvLI4DUYUlZCkFw== From: Amit Machhiwal To: qemu-ppc@nongnu.org, Harsh Prateek Bora Cc: Amit Machhiwal , Vaibhav Jain , Nicholas Piggin , Chinmay Rath , Glenn Miles , Paolo Bonzini , kvm@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v4 3/3] target/ppc/kvm: Use host compatibility mode for nested guests Date: Wed, 1 Jul 2026 10:53:41 +0530 Message-ID: <20260701052341.62289-4-amachhiw@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260701052341.62289-1-amachhiw@linux.ibm.com> References: <20260701052341.62289-1-amachhiw@linux.ibm.com> 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: AW1haW4tMjYwNzAxMDA1MiBTYWx0ZWRfX5jSXwfx9kSox 3x46C58zdm+ZokOp0SHPIksr/cq0+GYs4O5I5SSpusbiybarJy6I1Cj0HT5RF9kgEZKfgFzNtds M94G82q808fsR0Pq7Ic2BVzGj34PeKmGW4DvYQmEcFxUezUHaKNB0ETajhS6Pd4EUCA0r7yy/++ AjGCGJtv6Rzq/gQ6vfcCDERaxyyaINWT6SUINv/55ZR4+cp++QyqFQW1aZnPWZLuwc417/4P92B PEKHLjLGVgvMZ8EvtNc923vrPi3LSqptJIqvR10DVer0WcGI9Ljt2c/0sbH8G4b12Ud35PiGoBp OOwSPeMiwa1ULSh9zKuR27h4TCHONlQaV8JVOelw/AhXHTxTUfqqMKo+avoQCkVk5b6UAboswG9 nV3C0JB7pe4WE0fvRsrCEEYPoy++dXOEneczOxvRYruuqf8a1JUIf3HQ48tKQ7ES1A72w4V9orl uBfkYx1iaiyWksRdgIg== X-Authority-Analysis: v=2.4 cv=V45NF+ni c=1 sm=1 tr=0 ts=6a44a481 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=RAioF0-LDSMA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VnNF1IyMAAAA:8 a=tLWNhYkk1iXv8su3ZXkA:9 X-Proofpoint-ORIG-GUID: jcaUA9SlAEktDljjTf_IrN-n87U3FoFk X-Proofpoint-GUID: Tnr6WQQhpftfhf4iWK7RLncCxdx15OGK X-Proofpoint-Spam-Info: AW1haW4tMjYwNzAxMDA1MiBTYWx0ZWRfXwKVhQ8cLwaLC iGBJP6gh1lFSyiU1KSBH6v5YBPSpeUnJfzZ2GOJAfQTP/gJhAv9ZyuW9zKo0v+P63JCXenj47ko GMLjEidqis0PtEDxVxtFWfx6vHvkIsg= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-07-01_01,2026-06-26_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607010052 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=amachhiw@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1782883485624158500 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). When running nested KVM guests, QEMU currently derives the host CPU type using mfpvr(), which reflects the physical processor version. This can result in a mismatch between the CPU model used by QEMU and the compatibility mode enforced by the host, leading to guest boot failures such as "KVM-NESTEDv2: couldn't set guest wide elements". Update kvm_ppc_get_host_cpu_class() to check if the host is running in a compatibility mode using kvm_ppc_host_compat_pvr(). When available, use the compatibility PVR instead of the raw hardware PVR when selecting the CPU model. This ensures that QEMU selects a CPU model consistent with the host compatibility mode, allowing nested guests to boot correctly. The guard uses #if defined(TARGET_PPC64) to prevent build breakage on ppc32 targets where the POWER9/10/11 PVR constants are not defined. Signed-off-by: Amit Machhiwal --- Changes in v4: - Updated commit log - Added a #ifndef CONFIG_KVM compile-time assertion inside the TARGET_PPC64 guard as a sanity check, since kvm_ppc_get_host_cpu_class() is only ever built with CONFIG_KVM=3Dy. target/ppc/kvm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index b1b596f004ef..105b838cdef9 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2682,6 +2682,18 @@ PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) uint32_t host_pvr =3D mfpvr(); PowerPCCPUClass *pvr_pcc; =20 +#if defined(TARGET_PPC64) +#ifndef CONFIG_KVM +#error "CONFIG_KVM is not enabled" +#endif + uint32_t compat_host_pvr; + + compat_host_pvr =3D kvm_ppc_host_compat_pvr(); + if (compat_host_pvr) { + host_pvr =3D compat_host_pvr; + } +#endif /* TARGET_PPC64 */ + pvr_pcc =3D ppc_cpu_class_by_pvr(host_pvr); if (pvr_pcc =3D=3D NULL) { pvr_pcc =3D ppc_cpu_class_by_pvr_mask(host_pvr); --=20 2.50.1 (Apple Git-155)