From nobody Mon Mar 2 10:49:18 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=unpredictable.fr ARC-Seal: i=1; a=rsa-sha256; t=1772316574; cv=none; d=zohomail.com; s=zohoarc; b=aCXdQuZsXcRMVK5Y4/I0vQovCIAqWtHogK3bbUiAeR70t+U5ZbvSF4JZVpELXjboRCe1EluB65qrbdZKSwoy/vSN44X8gx9/Shjo5W/Pxxrj4P9aDE0BQMZGewx0371QRDG7/sjfMFaI5m0HrJQVehoaZ3AH7NQgJ5OE6Fb+mXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772316574; 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=xOhk+UpBTuUEo2kxPpkLtZpzA8dOZaP9D9fzqCaqzkM=; b=R3m7kNLJS/5p8eSGucm0qjlPaZ1cbZWDVk2BxLkd3OrsFUOjDaXNDcWakPG4OqBPgw6VqbykCn3TKwqbw+fv0MLBZnH+ulC4DPqT1IjypsRZgHdROHnFc/wdJDbUfJG18jXBk8/JKTTVRavv0mWxKT6Z4ehTKKFuUjrth+Onyn4= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772316574068361.4408913561632; Sat, 28 Feb 2026 14:09:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vwSUY-0002Ss-RN; Sat, 28 Feb 2026 17:08:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vwSUW-0002RO-Nb for qemu-devel@nongnu.org; Sat, 28 Feb 2026 17:08:52 -0500 Received: from qs-2004d-snip4-11.eps.apple.com ([57.103.84.43] helo=outbound.qs.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vwSUU-0005me-Ku for qemu-devel@nongnu.org; Sat, 28 Feb 2026 17:08:52 -0500 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-9 (Postfix) with ESMTPS id 14EB41800396; Sat, 28 Feb 2026 22:08:49 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-9 (Postfix) with ESMTPSA id 8373718000A4; Sat, 28 Feb 2026 22:08:47 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1772316530; x=1774908530; bh=xOhk+UpBTuUEo2kxPpkLtZpzA8dOZaP9D9fzqCaqzkM=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=XYLEauuduxDX3SgJsgBlR26rbJeNvrHdm6Rn984xIhka7/5uc5C6e71VYZzINFCM0wY8HfwXZFjX04bJV+vJnM9JyVJRlY1ubo37xZQXJMO6P+pOxNUFcXPj9VNWQ3SaX0/MHfcvX76JzUh0k9/PCzOBLo4HdvF5s1+S1sH9/USmHcg6f/Nq8oNRZcTERxyeQkclnlY63VkqJTb11djHacuKX9+zk3Egmo+42+awepEGB+Krn40wwnc7h74rDyMmXRS0CtT8GKaGmdaxwaMPLllhqUxAuMR3Owszt4aFx9unItdr/4m0bXLiIqQ5+wUtGqSa5hGJKp7phG6GaeddWQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Peter Maydell , Phil Dennis-Jordan , Paolo Bonzini , Alexander Graf , Mads Ynddal , Cameron Esfahani , qemu-arm@nongnu.org, Roman Bolshakov , Mohamed Mediouni Subject: [PATCH v11 05/12] hw/arm, target/arm: nested virtualisation on HVF Date: Sat, 28 Feb 2026 23:08:30 +0100 Message-ID: <20260228220837.35275-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260228220837.35275-1-mohamed@unpredictable.fr> References: <20260228220837.35275-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Info-Out: v=2.4 cv=MKZtWcZl c=1 sm=1 tr=0 ts=69a36771 cx=c_apl:c_apl_out:c_pps a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=YLAFOksV-_wk3IE7wuMA:9 X-Proofpoint-GUID: JNh9e8lxXOVhoXiDNR3dMnvVdAIwegQ8 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjI4MDIwNyBTYWx0ZWRfXzL03nXpUDUqM tpd5FuiN50vLBKR41J8iK294gAXnXbBwmr4AsVJSMl8+rBsXmAa7zpYEowxq/ZI3N1Bla3x97BB 27VaUbCwYr7PG8udKjFSWG4pEvliKPd7iYxQnTI+onRNjG7g6LEilCVHIvrMo0KgJYGs4C+elHo r1lgo8Y3JS0jEmP1VC7oIatIkH44BEiFGLfWsqLKv7QOG5YDRc+ZyiOtWMlmilkyDHc1z2uro5i k1YngUbPWLm6V5/H5ymgip7yvL2L33dS5ccgwkQ8+zg9NA1vxLz+hY4kY+C4tIefWkoBtXVPuEz heHwFLqvTW1q5SDP3yI7KkKpz403s3i9vNDBiaruY3zuBwd8Q7nOGfkf3y4uf0= X-Proofpoint-ORIG-GUID: JNh9e8lxXOVhoXiDNR3dMnvVdAIwegQ8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-28_07,2026-02-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=831 malwarescore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 clxscore=1030 bulkscore=0 phishscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602280207 X-JNJ: AAAAAAABa96Vuw+x15HbOTdCEZwS7U5G6T27r0xhq9Kl3YCU9ZoMrhQ0ECo0dkhj0zaMZ2LFxdyQDBxhKaFwa8wekYjX0CCzKvmxJaHG4WCytqgh58uWdmVL5P7gHm6BRqYAF9Sh8EPruBb6KMK/TEv2rtiuarqH4aO0aumyTtX3UsC/fp/TZC9GBfcbWsrd8qsiPNCT02ZHqOZeJExJc8mV7eT+LtCqwNT5iVq6gMjuZyYlBvuxAtab/sF9I9VWUVzx4rf/Eujwh7wOXMZkLqZZ/SPgGlprGK+CU2I6KrVJaBCyfqsLH8x1qXwMaYbUfUOWHfVWcKbywwsZ3sxDojrlFoojgamDcAng5sl25PYwHuyC+xcdBH0L8Sv2Fj5AeRMN4/EakI0gHGDGWHdc48XH4xDQZsttgpRcw4EFSEO9ZqLvNeiZmTsTIx7acid9QphFYqAAJynwYwfXgnpKify6wMzDMQJ9ILTHJGVaCFRoGCaPdqjyARVv9XzKFSwRMDhAPTT2SgLaAXMel6xTqWJxHyP/S3mgS9FH8HP721HVdeCthbKYxTAYLpM/5IOQcqVBEJJY+1Pi+70xJC3cPe7IF49yjvEpdz50fmXadwGbfZ9RFuLB7sKwYfdn/jlw2hIzTPFJNpQ24NmgatVS2wUX3RMfs/MNQWei0ZHDJSR4lGkiK9eJVFkFkHfHjHMhJc+0wjRxXCgV3VnZbPpbXg== 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=lists.gnu.org; Received-SPF: pass client-ip=57.103.84.43; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.966, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.722, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 @unpredictable.fr) X-ZM-MESSAGEID: 1772316576093158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Mohamed Mediouni --- accel/hvf/hvf-all.c | 1 + accel/stubs/hvf-stub.c | 1 + hw/arm/virt.c | 5 +++++ include/system/hvf.h | 5 +++++ target/arm/hvf/hvf.c | 36 ++++++++++++++++++++++++++++++++++-- 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c index 929f53fd37..88f6d5accb 100644 --- a/accel/hvf/hvf-all.c +++ b/accel/hvf/hvf-all.c @@ -25,6 +25,7 @@ =20 bool hvf_allowed; bool hvf_kernel_irqchip; +bool hvf_nested_virt; =20 const char *hvf_return_string(hv_return_t ret) { diff --git a/accel/stubs/hvf-stub.c b/accel/stubs/hvf-stub.c index 6bd08759ba..cec1cbb056 100644 --- a/accel/stubs/hvf-stub.c +++ b/accel/stubs/hvf-stub.c @@ -11,3 +11,4 @@ =20 bool hvf_allowed; bool hvf_kernel_irqchip; +bool hvf_nested_virt; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8db5611f7f..3fa4f41821 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2662,6 +2662,11 @@ static void virt_set_virt(Object *obj, bool value, E= rror **errp) VirtMachineState *vms =3D VIRT_MACHINE(obj); =20 vms->virt =3D value; + /* + * At this point, HVF is not initialised yet. + * However, it needs to know if nested virt is enabled at init time. + */ + hvf_nested_virt_enable(value); } =20 static bool virt_get_highmem(Object *obj, Error **errp) diff --git a/include/system/hvf.h b/include/system/hvf.h index dc8da85979..0f0632f7ae 100644 --- a/include/system/hvf.h +++ b/include/system/hvf.h @@ -28,9 +28,14 @@ extern bool hvf_allowed; #define hvf_enabled() (hvf_allowed) extern bool hvf_kernel_irqchip; #define hvf_irqchip_in_kernel() (hvf_kernel_irqchip) +extern bool hvf_nested_virt; +#define hvf_nested_virt_enabled() (hvf_nested_virt) +#define hvf_nested_virt_enable(enable) hvf_nested_virt =3D enable #else /* !CONFIG_HVF_IS_POSSIBLE */ #define hvf_enabled() 0 #define hvf_irqchip_in_kernel() 0 +#define hvf_nested_virt_enabled() 0 +#define hvf_nested_virt_enable(enable) 0 #endif /* !CONFIG_HVF_IS_POSSIBLE */ =20 #define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf") diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index a22b544afe..a80c5f8384 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -27,6 +27,7 @@ #include "system/memory.h" #include "hw/core/boards.h" #include "hw/core/irq.h" +#include "hw/arm/virt.h" #include "qemu/main-loop.h" #include "system/cpus.h" #include "arm-powerctl.h" @@ -842,6 +843,10 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFe= atures *ahcf) (1ULL << ARM_FEATURE_PMU) | (1ULL << ARM_FEATURE_GENERIC_TIMER); =20 + if (hvf_nested_virt_enabled()) { + ahcf->features |=3D 1ULL << ARM_FEATURE_EL2; + } + for (i =3D 0; i < ARRAY_SIZE(regs); i++) { r |=3D hv_vcpu_config_get_feature_reg(config, regs[i].reg, &host_isar.idregs[regs[i].inde= x]); @@ -949,6 +954,15 @@ void hvf_arch_vcpu_destroy(CPUState *cpu) assert_hvf_ok(ret); } =20 +static bool hvf_arm_el2_supported(void) +{ + bool is_nested_virt_supported; + hv_return_t ret =3D hv_vm_config_get_el2_supported(&is_nested_virt_sup= ported); + assert_hvf_ok(ret); + return is_nested_virt_supported; +} + + hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range) { hv_return_t ret; @@ -960,6 +974,18 @@ hv_return_t hvf_arch_vm_create(MachineState *ms, uint3= 2_t pa_range) } chosen_ipa_bit_size =3D pa_range; =20 + if (hvf_nested_virt_enabled()) { + if (!hvf_arm_el2_supported()) { + error_report("Nested virtualization not supported on this syst= em."); + goto cleanup; + } + ret =3D hv_vm_config_set_el2_enabled(config, true); + if (ret !=3D HV_SUCCESS) { + error_report("Failed to enable nested virtualization."); + goto cleanup; + } + } + ret =3D hv_vm_create(config); if (hvf_irqchip_in_kernel()) { /* @@ -1110,6 +1136,13 @@ static void hvf_psci_cpu_off(ARMCPU *arm_cpu) assert(ret =3D=3D QEMU_ARM_POWERCTL_RET_SUCCESS); } =20 +static int hvf_psci_get_target_el(void) +{ + if (hvf_nested_virt_enabled()) { + return 2; + } + return 1; +} /* * Handle a PSCI call. * @@ -1131,7 +1164,6 @@ static bool hvf_handle_psci_call(CPUState *cpu, int *= excp_ret) CPUState *target_cpu_state; ARMCPU *target_cpu; target_ulong entry; - int target_el =3D 1; int32_t ret =3D 0; =20 trace_arm_psci_call(param[0], param[1], param[2], param[3], @@ -1185,7 +1217,7 @@ static bool hvf_handle_psci_call(CPUState *cpu, int *= excp_ret) entry =3D param[2]; context_id =3D param[3]; ret =3D arm_set_cpu_on(mpidr, entry, context_id, - target_el, target_aarch64); + hvf_psci_get_target_el(), target_aarch64); break; case QEMU_PSCI_0_1_FN_CPU_OFF: case QEMU_PSCI_0_2_FN_CPU_OFF: --=20 2.50.1 (Apple Git-155)