From nobody Sat Nov 15 09:10:13 2025 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=1753682430; cv=none; d=zohomail.com; s=zohoarc; b=UY7eeQatRius3/sAwhS75z2HbCrjKIyar/B+7iMKjprzF77Triqaodv2tpwz8v3JUXwCeP5RXLgu+kORpxWI6ZVEEOU4lHQO+HmaLdwNQLiy4yD1soZQBMeHFgODGlzmd254tMHrbUHHGDmIB8WHUOp+6vezo4Uw64MVXw7RqX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753682430; 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=86A60wgLWJ4xc0K/iclPiV/M1o2YUtx5PvcnU99EgeY=; b=bx/ydVhjPuWIy9e9a3rumeLAECZHwMD64sEDQREhhPnPjcTgjICazmK1Cs4+T5rBXc4qGLLeeg9ybL6po04+QSHGY2S+2RR2q/hOm1sndPTGOQpxEfYQMp4dVSORFTLwsI4j/7pJvZtffi6LVHzs+N6tk1Xl10cs5iCja1srybA= 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 1753682430790523.7743858192536; Sun, 27 Jul 2025 23:00:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ugGt9-0000tg-Hi; Mon, 28 Jul 2025 01:59:07 -0400 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 1ugGrU-0007G7-Fn for qemu-devel@nongnu.org; Mon, 28 Jul 2025 01:57:28 -0400 Received: from p-east3-cluster6-host1-snip4-7.eps.apple.com ([57.103.85.138] 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 1ugGrR-0007DZ-7p for qemu-devel@nongnu.org; Mon, 28 Jul 2025 01:57:23 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-7 (Postfix) with ESMTPS id 70F2118000B0; Mon, 28 Jul 2025 05:57:16 +0000 (UTC) Received: from localhost.localdomain (qs-asmtp-me-k8s.p00.prod.me.com [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-100-percent-7 (Postfix) with ESMTPSA id BCD68180009A; Mon, 28 Jul 2025 05:57:13 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; bh=86A60wgLWJ4xc0K/iclPiV/M1o2YUtx5PvcnU99EgeY=; h=From:To:Subject:Date:Message-Id:MIME-Version:x-icloud-hme; b=YzYtqLjidbZcdaNaCOk+z83vDz84rw8mTNgthebOZiUupa1766j7dadB3llRmW+BzvNA8XGVPQuN0HZoRSWoiAJlO7ajqns72LixNnSV80ubPRtLeH5zwmrJTyaaf0tNAUL46S8QfsEswqjAanMvCiAbqmyOzPz3SksZvr/DqIRDdun2tOrZz59YA4MJ7TGoomdQICIVqL4cShyniB+oZkqjhQe3QCIoXo92RwspsO5EpJggM6+WOYkOm6txL/Omk4F9++Zt47nHLFuMWzCwenOByCL5KH9i9exzmF7tDUUVyO374Ar+Cxj1Se9coYxO6x2TNY4rL6UPaTF2PH4ysg== X-Client-IP: 46.189.47.18 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Alexander Graf , Peter Maydell , Mads Ynddal , "Michael S. Tsirkin" , Cameron Esfahani , Ani Sinha , Paolo Bonzini , Roman Bolshakov , Shannon Zhao , Phil Dennis-Jordan , Igor Mammedov , qemu-arm@nongnu.org, Mohamed Mediouni Subject: [PATCH v4 05/15] hvf: save/restore Apple GIC state Date: Mon, 28 Jul 2025 07:56:51 +0200 Message-Id: <20250728055701.38975-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250728055701.38975-1-mohamed@unpredictable.fr> References: <20250728055701.38975-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzI4MDA0MyBTYWx0ZWRfX4/8orIypeOx4 EiIR4IYF5mGWHJn6R7Dup+zo3WDLzHv+FES0kBE9ZJ7KcsLAGC8rrm0af+BMsBoZZeEWIQ0mfKP HkCeIWHYAyc4v/lZNzUk2XgaXpRHRdKMliEzOD7Jbd22eYYmY+iPIkCycx5HDz8ni97h3CVwQmH jOiCIFka4Gl1cDZJPGfJgXzmHAYTvMqZPkLYwZq7DQCGSQtzfykDohhFK4olAfRBUap3a0MGDgq dE5wWmIcMbup1Yv91PtM6QNOrdmYDmsn6tTOoiHpLriuPvWdkAM1UHsTtOzF99v8ciFTdVXBQ= X-Proofpoint-GUID: CVCjsihdzAaxyLqjKEbH8s1Hc_mg_OfT X-Proofpoint-ORIG-GUID: CVCjsihdzAaxyLqjKEbH8s1Hc_mg_OfT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-28_02,2025-07-24_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 clxscore=1030 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxlogscore=820 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.22.0-2506270000 definitions=main-2507280043 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.85.138; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.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_MSPIKE_H2=-0.01, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 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: 1753682432473116600 Content-Type: text/plain; charset="utf-8" On HVF, some of the GIC state is in an opaque Apple-provided structure. Save/restore that state to be able to save/restore VMs. Signed-off-by: Mohamed Mediouni --- target/arm/hvf/hvf.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index 7beb47caad..766b35f937 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -22,6 +22,7 @@ #include "cpu-sysregs.h" =20 #include +#include =20 #include "system/address-spaces.h" #include "system/memory.h" @@ -2169,15 +2170,83 @@ static const VMStateDescription vmstate_hvf_vtimer = =3D { }, }; =20 +/* Apple specific opaque state for the vGIC */ + +typedef struct HVGICState { + void *state; + uint32_t size; +} HVGICState; + +static HVGICState gic; + +static int hvf_gic_opaque_state_get(void) +{ + hv_gic_state_t gic_state; + hv_return_t err; + size_t size; + + gic_state =3D hv_gic_state_create(); + if (gic_state =3D=3D NULL) { + error_report("hvf: vgic: failed to create hv_gic_state_create."); + return 1; + } + err =3D hv_gic_state_get_size(gic_state, &size); + gic.size =3D size; + if (err !=3D HV_SUCCESS) { + error_report("hvf: vgic: failed to get GIC state size."); + return 1; + } + gic.state =3D malloc(gic.size); + err =3D hv_gic_state_get_data(gic_state, gic.state); + if (err !=3D HV_SUCCESS) { + error_report("hvf: vgic: failed to get GIC state."); + return 1; + } + return 0; +} + +static int hvf_gic_opaque_state_set(void) +{ + hv_return_t err; + if (!gic.size) { + return 0; + } + err =3D hv_gic_set_state(gic.state, gic.size); + if (err !=3D HV_SUCCESS) { + error_report("hvf: vgic: failed to restore GIC state."); + return 1; + } + return 0; +} + +static const VMStateDescription vmstate_hvf_gic =3D { + .name =3D "hvf-gic", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(size, HVGICState), + VMSTATE_VBUFFER_UINT32(state, + HVGICState, 0, 0, + size), + VMSTATE_END_OF_LIST() + }, +}; + static void hvf_vm_state_change(void *opaque, bool running, RunState state) { HVFVTimer *s =3D opaque; =20 if (running) { + if (hvf_irqchip_in_kernel()) { + hvf_gic_opaque_state_set(); + } /* Update vtimer offset on all CPUs */ hvf_state->vtimer_offset =3D mach_absolute_time() - s->vtimer_val; cpu_synchronize_all_states(); } else { + if (hvf_irqchip_in_kernel()) { + hvf_gic_opaque_state_get(); + } /* Remember vtimer value on every pause */ s->vtimer_val =3D hvf_vtimer_val_raw(); } @@ -2187,6 +2256,10 @@ int hvf_arch_init(void) { hvf_state->vtimer_offset =3D mach_absolute_time(); vmstate_register(NULL, 0, &vmstate_hvf_vtimer, &vtimer); + if (hvf_irqchip_in_kernel()) { + gic.size =3D 0; + vmstate_register(NULL, 0, &vmstate_hvf_gic, &gic); + } qemu_add_vm_change_state_handler(hvf_vm_state_change, &vtimer); =20 hvf_arm_init_debug(); --=20 2.39.5 (Apple Git-154)