From nobody Sat Nov 15 09:08:47 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=1753710146; cv=none; d=zohomail.com; s=zohoarc; b=BEFx0utqHQUEp32ZizrWm5WBof+nwBRFRxzsGoUiEqPZwOlTaJJuzp9soQCDBQghKNoI1825af4qOYNOOEYN5EIaigRIruvxm4pP2ysn7y3rEOtfPKJ+jPZe/e1j7LbCjXMvC2OmONErdz8QeiXGQMgckg114L9QS6uNw8i9rpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1753710146; 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=c/oL7OjYIpt+sPV/F/Cyl432Di6BlTkdRZZGD4dnHjQ=; b=KHGARcqhJX+LtWalvV5LYD0ERog9L0ryM35w4u/2NAVKsjgA30rrzypd6rCbFEbn/c3gTAbjGAe6kNwT1p2f61bTniuhiD1JszKWOdiAPjiZA1mDFo8nJXukRVU0JHJ2L98D8wJfMjjvUaF4siqM21UQLy7MMM2Fu2aJSWSobYw= 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 1753710146378500.03262601010135; Mon, 28 Jul 2025 06:42:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ugO6x-0005uQ-UT; Mon, 28 Jul 2025 09:41:52 -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 1ugO6n-0004fD-B7 for qemu-devel@nongnu.org; Mon, 28 Jul 2025 09:41:42 -0400 Received: from p-east3-cluster5-host10-snip4-10.eps.apple.com ([57.103.86.231] 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 1ugO6f-0004I0-MB for qemu-devel@nongnu.org; Mon, 28 Jul 2025 09:41:36 -0400 Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-100-percent-3 (Postfix) with ESMTPS id 5200618001CB; Mon, 28 Jul 2025 13:41:29 +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-3 (Postfix) with ESMTPSA id DD7711819D21; Mon, 28 Jul 2025 13:41:25 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr; s=sig1; bh=c/oL7OjYIpt+sPV/F/Cyl432Di6BlTkdRZZGD4dnHjQ=; h=From:To:Subject:Date:Message-Id:MIME-Version:x-icloud-hme; b=cD0ufjKVgF8byLlwgo3anP3CDvSOdFHrqX7eMliMY3kGS4/eCJ4Oekm0juq6ywxX5C4392A9J6x3EpW5+aVfcwxoZOFtSuB0Znb2xrSBKEplVSzFswakh9t0kNObLU5qkEFBE1H+vjn1fbhgvEyUYiQ1tFaefTbVgHWDTEY5ftrKCEwidVO6sqVAmsp+bQEJIKmCvbfkYjkPcg3Sdk5gh2IOiH6e7G8p9dgTEHWazZdpEYEanHZFuC6TLk9hciXf02K4dJHzvBDRA78+DiPpZfcP1W3F8AYwnku0Gk0+YxBEh5Vz8lwH6+23GgndUbQ3Z3qk+yFQFl03JYif1c6lCg== X-Client-IP: 46.189.47.18 From: Mohamed Mediouni To: qemu-devel@nongnu.org Cc: Mads Ynddal , Paolo Bonzini , Shannon Zhao , Phil Dennis-Jordan , Igor Mammedov , qemu-arm@nongnu.org, Alexander Graf , Roman Bolshakov , Peter Maydell , "Michael S. Tsirkin" , Ani Sinha , Cameron Esfahani , Mohamed Mediouni Subject: [PATCH v5 05/13] hvf: save/restore Apple GIC state Date: Mon, 28 Jul 2025 15:41:06 +0200 Message-Id: <20250728134114.77545-6-mohamed@unpredictable.fr> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250728134114.77545-1-mohamed@unpredictable.fr> References: <20250728134114.77545-1-mohamed@unpredictable.fr> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzI4MDEwMSBTYWx0ZWRfX1/9G4goj5Z55 6a5qTEJVDJtNSge/9cLm8qy8rIc0aDQENwUGzJ4yxYlUER1HXN0UiLI53HCda+KiSbbG/Ttg38+ H3yk+wsfMHnISsn8kwzMyW7EyOG0oUI5ryFrgE0Xt2p5ssvdzORzSiGElATzsiK3M9yuC+rM3KU Cb7FVSPW9PPBiwHYih4c9aoctw/z1uPc7YboKgCwvs7V3D1GjG8NL6P1TmnuKh4pyAvSnsCIy2g 4ysR5Fv2SIniv10C+hlq8Att/qwBKjKmUXmNxkbBJC5YjguwPAoDN060CBR66Amx+qRzYOkPE= X-Proofpoint-GUID: HvT7R71efXJ-TgKqpbSyaKfkjTDjQolQ X-Proofpoint-ORIG-GUID: HvT7R71efXJ-TgKqpbSyaKfkjTDjQolQ 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_03,2025-07-28_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 clxscore=1030 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 mlxlogscore=820 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.22.0-2506270000 definitions=main-2507280101 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.86.231; envelope-from=mohamed@unpredictable.fr; helo=outbound.qs.icloud.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1753710148282116600 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 4ac42bda32..f14a3a3cbd 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" @@ -2174,15 +2175,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(); } @@ -2192,6 +2261,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)