From nobody Sat Apr 11 23:04: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=1772783963; cv=none; d=zohomail.com; s=zohoarc; b=dWh9AMeJ3YHl3jUVy3uSTXVbeB/tdyydGCWiTOaQNQcS0Qy1yVmnOwZE7aw6y3V7lNVfeBQuzEWlyaoI3XyHTmJiCSReGi8DVcTGR4olHjFSlrSxrpttMxo/FXgQQOJFDwDjupdupOUHgEb6g120E9B0vGa8epEOYC8YaCb4Mqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772783963; h=Content-Type: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=XhMMsyuNqxqx54T1OMmdgINiRA0qeWFXPChvfberBDE=; b=ZRN+nKO29SJJn6JGxsfZx8ShA7v0zbDr+fUguKnDzGYL0TUfOpIpPTJDpauU/CxMx+hNMlR6w6aAJo6u7/DEnxoPs8FlgTcNK/ywbpBBhCi9kQBr3aOj/HUmDby3/6w++ivkUWEHEw+Z5XkFRYZ/zq8UoWKe7u+A0HRLAKGJPL8= 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 1772783963394471.213467799431; Thu, 5 Mar 2026 23:59:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyQ4j-0007So-A7; Fri, 06 Mar 2026 02:58:21 -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 1vyQ4i-0007SB-5H for qemu-devel@nongnu.org; Fri, 06 Mar 2026 02:58:20 -0500 Received: from p-west2-cluster1-host11-snip4-10.eps.apple.com ([57.103.68.33] helo=outbound.mr.icloud.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyQ4f-00065c-Ud for qemu-devel@nongnu.org; Fri, 06 Mar 2026 02:58:19 -0500 Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-100-percent-3 (Postfix) with ESMTPS id B08E21800135; Fri, 6 Mar 2026 07:58:15 +0000 (UTC) Received: from localhost.localdomain (unknown [17.57.152.38]) by p00-icloudmta-asmtp-us-west-2a-100-percent-3 (Postfix) with ESMTPSA id 12B6A18001A7; Fri, 6 Mar 2026 07:58:12 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; t=1772783897; x=1775375897; bh=XhMMsyuNqxqx54T1OMmdgINiRA0qeWFXPChvfberBDE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:x-icloud-hme; b=JXev3j002/Qn6b6hNlBG8bmujauHJNHAqK6DhXMot9f75M8XjsPyEh9Bob9ZkaXxPuXGm8Iic8GZMIMJaQgzGSFk2sjoBheJfC9PMxhRqFOEWBjgTymYkCU8kJ4VJnuYQ21vvUsxkLHHDF8qIG+8GVt16x/Em7EoDNUOoKMBHaS8aiPORiIJ0vQzd3C1gKwNIykXJIsfgqeVrenXnU1lPfzym+NnalYnbWO1UGhV2OzGcyrXA2xxbKQTG01Txb3my8l4p9T45HdRlLCbZep59iNZGo5Y5Cg2Rzx4q2os/5rjzCuMoZcpUhQMG3czjC0pILzd5Ej9BdmK8YpEIozosQ== mail-alias-created-date: 1752046281608 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Cameron Esfahani , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , qemu-arm@nongnu.org, Phil Dennis-Jordan , Peter Maydell , Mads Ynddal , Alexander Graf , Roman Bolshakov , Mohamed Mediouni Subject: [PATCH v13 05/17] hw/intc: arm_gicv3_hvf: save/restore Apple GIC state Date: Fri, 6 Mar 2026 08:57:44 +0100 Message-ID: <20260306075756.88922-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260306075756.88922-1-mohamed@unpredictable.fr> References: <20260306075756.88922-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: qGw-ey-Dc9Kl5Gwh5qigbYcUzQ3N2x2a X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzA2MDA3NSBTYWx0ZWRfXwuWZTAS/Z9Hx HTQz9exXNhFr2Ka/NmOpvGhlQUyJFoor8yqkJqxFpQCB/Uyc9GelNlkA+uGjCKhFKXeh+BradHf mqaHaDdPcHRm8UlC7dGH7tWrbLZhilzBVGZ5vTHOFTRn8Szo2tMFRQmwAiKePVXqvWTh3KCNIAY J9XPjpgCrJpvLQcHO7yP107m8EOGMfchrXpbKuB21JxVtJwZ3lbv/vqv5R2SmRjeOBCTiAuPc3+ goYh/TvrkqgF/qJqHNJJ3NeDYhXcROutd886mMpRmYil8c/sfrI4/cgzmoG2MjqpsdsuvJhXdr6 EaFeRf8iBpIoRRPvdhLsqzDtPzH8jWJXdVZcSnedX1kGyqrFIY7DnBSsyw6v+o= X-Proofpoint-ORIG-GUID: qGw-ey-Dc9Kl5Gwh5qigbYcUzQ3N2x2a X-Authority-Info-Out: v=2.4 cv=ArvjHe9P c=1 sm=1 tr=0 ts=69aa8918 cx=c_apl:c_pps:t_out a=9OgfyREA4BUYbbCgc0Y0oA==:117 a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=KKAkSRfTAAAA:8 a=kNOF8fv34t_zTB2Y_VIA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-06_02,2026-03-04_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 clxscore=1030 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2603060075 X-JNJ: AAAAAAABNQ/FdLk++zi7tdLLt1agwTB1y0ur/W/myN52FsSDEZkBS4lLPNTgG7d83VQgT49scz6yNYIWvyGripem8afkBauGeegVb0yTPFnffb/fWgsPwycq+auq/MKzdoOIrdgcTi/PtAGu3duxblwQVeXmJnnLkhPbZrgHUN8Lh8UkVIcfEaTnzpUBvty9nfpSGUjpNuslajfp0qV9eAd/bylLcf7GQGqxRlJe0AC459ceEtqValX2MVPZzjsgAktQqr4clCrofqux+oDxtCbQpix4UXL+sxdzIjYBUBeistZ7KS5jrk31MHw88ov5R8GPAcVglSHcip7tuXowsfYkb+GI9Oi0jIjCBz5Si6iwPVbZxxtSrDk30ByqjxS5shIrvG3rTjz2n61l241+huYoh7q2XskmyU81cQZqB+EfgYCzQVhjgb6qoyLrR06kepMKsjwEaU3fsjWPE2s5NaTglWgVqtRoBzhzGeVH6yE4IExhVqqusKr8YQHnb8DQVKSrZaFfnAxD2q6GEc4yJnzyzbS5A1Zg1JDFsjYIyrqwvhEncGBGKO7woMQ5sXHmJEfM+Ws9avn4DoS8s6LNx4Gs4M9X1cZgIbZyS6wKS/Z2tVc3xx1Gha4kTM72PjrruDdKszlWq1Jvzh1CXrO5up5THMevDMH3YwtQtn5Y8ZgpJJOzQTfezQYpFIimoFqD94N/nutOHAhdkIAj1FLIT4yav2AMQRCRPsvuPshk/iQ8Ruo//b6b1M/PzWD8rOIIcqIsy3SbuOs/AsGV/dHVNa8fvv6YMXbWbJ/MCyOhTcVS9TTteO8= 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.68.33; envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.icloud.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.892, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.622, 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: 1772783966192154100 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 that use the hardwar= e GIC. Signed-off-by: Mohamed Mediouni Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/intc/arm_gicv3_common.c | 1 + hw/intc/arm_gicv3_hvf.c | 95 ++++++++++++++++++++++++++++-- hw/intc/arm_gicv3_hvf_stub.c | 25 ++++++++ hw/intc/meson.build | 1 + include/hw/intc/arm_gicv3_common.h | 3 + 5 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 hw/intc/arm_gicv3_hvf_stub.c diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index 9200671c7a..9c3fb2f4bf 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -305,6 +305,7 @@ static const VMStateDescription vmstate_gicv3 =3D { .subsections =3D (const VMStateDescription * const []) { &vmstate_gicv3_gicd_no_migration_shift_bug, &vmstate_gicv3_gicd_nmi, + &vmstate_gicv3_hvf, NULL } }; diff --git a/hw/intc/arm_gicv3_hvf.c b/hw/intc/arm_gicv3_hvf.c index d6a46b7d53..f2249a7e7c 100644 --- a/hw/intc/arm_gicv3_hvf.c +++ b/hw/intc/arm_gicv3_hvf.c @@ -13,6 +13,7 @@ #include "qemu/error-report.h" #include "qemu/module.h" #include "system/runstate.h" +#include "migration/vmstate.h" #include "system/hvf.h" #include "system/hvf_int.h" #include "hvf_arm.h" @@ -30,8 +31,13 @@ struct HVFARMGICv3Class { =20 typedef struct HVFARMGICv3Class HVFARMGICv3Class; =20 -/* This is reusing the GICv3State typedef from ARM_GICV3_ITS_COMMON */ -DECLARE_OBJ_CHECKERS(GICv3State, HVFARMGICv3Class, +typedef struct HVFGICv3State { + GICv3State gicv3_state; + uint32_t size; + void *state; +} HVFGICv3State; + +DECLARE_OBJ_CHECKERS(HVFGICv3State, HVFARMGICv3Class, HVF_GICV3, TYPE_HVF_GICV3); =20 /* @@ -656,7 +662,7 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] =3D { static void hvf_gicv3_realize(DeviceState *dev, Error **errp) { ERRP_GUARD(); - GICv3State *s =3D HVF_GICV3(dev); + GICv3State *s =3D (GICv3State *)HVF_GICV3(dev); HVFARMGICv3Class *kgc =3D HVF_GICV3_GET_CLASS(s); int i; =20 @@ -703,6 +709,87 @@ static void hvf_gicv3_realize(DeviceState *dev, Error = **errp) } } =20 +/* + * HVF doesn't have a way to save the RDIST pending tables + * to guest memory, only to an opaque data structure. + */ +static bool gicv3_is_hvf(void *opaque) +{ + return hvf_enabled() && hvf_irqchip_in_kernel(); +} + +static int hvf_gic_opaque_state_save(void* opaque) +{ + HVFGICv3State* gic =3D opaque; + 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."); + os_release(gic_state); + return 1; + } + gic->state =3D g_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."); + os_release(gic_state); + return 1; + } + + os_release(gic_state); + return 0; +} + +static int hvf_gic_opaque_state_free(void* opaque) +{ + HVFGICv3State* gic =3D opaque; + free(gic->state); + return 0; +} + +static int hvf_gic_opaque_state_restore(void* opaque, int version_id) +{ + HVFGICv3State* gic =3D opaque; + 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; +} + +const VMStateDescription vmstate_gicv3_hvf =3D { + .name =3D "arm_gicv3/hvf_gic_state", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D gicv3_is_hvf, + .pre_save =3D hvf_gic_opaque_state_save, + .post_save =3D hvf_gic_opaque_state_free, + .post_load =3D hvf_gic_opaque_state_restore, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(size, HVFGICv3State), + VMSTATE_VBUFFER_ALLOC_UINT32(state, + HVFGICv3State, 0, 0, + size), + VMSTATE_END_OF_LIST() + }, +}; + static void hvf_gicv3_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -722,7 +809,7 @@ static void hvf_gicv3_class_init(ObjectClass *klass, co= nst void *data) static const TypeInfo hvf_arm_gicv3_info =3D { .name =3D TYPE_HVF_GICV3, .parent =3D TYPE_ARM_GICV3_COMMON, - .instance_size =3D sizeof(GICv3State), + .instance_size =3D sizeof(HVFGICv3State), .class_init =3D hvf_gicv3_class_init, .class_size =3D sizeof(HVFARMGICv3Class), }; diff --git a/hw/intc/arm_gicv3_hvf_stub.c b/hw/intc/arm_gicv3_hvf_stub.c new file mode 100644 index 0000000000..a587332c7c --- /dev/null +++ b/hw/intc/arm_gicv3_hvf_stub.c @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * ARM Generic Interrupt Controller using HVF platform support stub + * + * Copyright (c) 2026 Mohamed Mediouni + * + */ +#include "qemu/osdep.h" +#include "hw/intc/arm_gicv3_common.h" +#include "migration/vmstate.h" +#include "qemu/typedefs.h" + +static bool needed_never(void *opaque) +{ + return false; +} + +const VMStateDescription vmstate_gicv3_hvf =3D { + .name =3D "arm_gicv3/hvf_gic_state", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D needed_never, + .version_id =3D 1, + .minimum_version_id =3D 1, +}; diff --git a/hw/intc/meson.build b/hw/intc/meson.build index b7baf8a0f6..c6de2d9d00 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -43,6 +43,7 @@ arm_common_ss.add(when: 'CONFIG_ARM_GICV3', if_true: file= s('arm_gicv3_cpuif.c')) specific_ss.add(when: 'CONFIG_ARM_GIC_KVM', if_true: files('arm_gic_kvm.c'= )) specific_ss.add(when: ['CONFIG_WHPX', 'TARGET_AARCH64'], if_true: files('a= rm_gicv3_whpx.c')) specific_ss.add(when: ['CONFIG_HVF', 'CONFIG_ARM_GICV3'], if_true: files('= arm_gicv3_hvf.c')) +specific_ss.add(when: ['CONFIG_HVF', 'CONFIG_ARM_GICV3'], if_false: files(= 'arm_gicv3_hvf_stub.c')) specific_ss.add(when: ['CONFIG_ARM_GIC_KVM', 'TARGET_AARCH64'], if_true: f= iles('arm_gicv3_kvm.c', 'arm_gicv3_its_kvm.c')) arm_common_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_nvic.c')) specific_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_irqmp.c')) diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3= _common.h index 9adcab0a0c..03ab3e8f2f 100644 --- a/include/hw/intc/arm_gicv3_common.h +++ b/include/hw/intc/arm_gicv3_common.h @@ -339,4 +339,7 @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_h= andler handler, */ const char *gicv3_class_name(void); =20 +/* HVF vGIC-specific state: stubbed out on a build with HVF disabled */ +extern const VMStateDescription vmstate_gicv3_hvf; + #endif --=20 2.50.1 (Apple Git-155)