From nobody Sun Nov 24 08:21:52 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725446909; cv=none; d=zohomail.com; s=zohoarc; b=mExjxf8l6L122dEXC8As7dZw0CLvvsvS661QTLmFqErhDTVqf/NNnGAEs3LEQJRqsGOYEz4LuR9aoREZqNVyzYNMwGZtGUREA43wp3HUFXFv7fiMuWVQvkXDSZQpjE2eTwfNRdgk18nNoV4Hbonzbx7C8Jx7tZ/duLv2Keom10I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725446909; 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=cDC0etd2SKJruRA72QwNhJqmvZ7shApjs+188SV92Gg=; b=YzdavrGupK3pRHzEu6UOHaJA7qYC+fRB7hk4xr8ge7ZfiMJ34yqZ/2vVaLosytImLPBxAQDA53mgzLcTM2/3CLOM/z6/vc7qALwGrcpkDBYa0MmhFsPgpu+7sanfcigoyaAAWxkeGw7FFbofIX22yyVnaqzSihjTieG8b66tepo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725446909668276.16951220402916; Wed, 4 Sep 2024 03:48:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slnUn-00019u-Do; Wed, 04 Sep 2024 06:44:17 -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 1slnUf-0000hu-Bc for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:44:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slnUb-0001pp-IA for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:44:07 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-634-xuwXhF_FPBuVzeZtzKrsFg-1; Wed, 04 Sep 2024 06:37:50 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 906AD19560B5; Wed, 4 Sep 2024 10:37:48 +0000 (UTC) Received: from rh-jmarcin.redhat.com (unknown [10.45.225.176]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF6B5195605A; Wed, 4 Sep 2024 10:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725446644; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cDC0etd2SKJruRA72QwNhJqmvZ7shApjs+188SV92Gg=; b=WCeGo9bcXj/4Q681n3K/pCeIIxXgH56iGeWsLW+TqypNYYldH1jzbRVZPFECsSr2AKYfVq kuXt0F9w1gJQ9Ena36tr6d6/1bK+yRQzwg9iEZDEZ5YUHCMyj1tzO5kPSJ1qGZsFSCB24j g6k+xGH+waGN6klu3ph83j/VpGivpwg= X-MC-Unique: xuwXhF_FPBuVzeZtzKrsFg-1 From: Juraj Marcin To: qemu-devel@nongnu.org Cc: Juraj Marcin , David Hildenbrand , Peter Maydell Subject: [PATCH v3 1/4] reset: Use ResetType for qemu_devices_reset() and MachineClass::reset() Date: Wed, 4 Sep 2024 12:37:12 +0200 Message-ID: <20240904103722.946194-2-jmarcin@redhat.com> In-Reply-To: <20240904103722.946194-1-jmarcin@redhat.com> References: <20240904103722.946194-1-jmarcin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=jmarcin@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @redhat.com) X-ZM-MESSAGEID: 1725446910320116600 Content-Type: text/plain; charset="utf-8" Currently, both qemu_devices_reset() and MachineClass::reset() use ShutdownCause for the reason of the reset. However, the Resettable interface uses ResetState, so ShutdownCause needs to be translated to ResetType somewhere. Translating it qemu_devices_reset() makes adding new reset types harder, as they cannot always be matched to a single ShutdownCause here, and devices may need to check the ResetType to determine what to reset and if to reset at all. This patch moves this translation up in the call stack to qemu_system_reset() and updates all MachineClass children to use the ResetType instead. Signed-off-by: Juraj Marcin Reviewed-by: David Hildenbrand Reviewed-by: Peter Maydell --- hw/arm/aspeed.c | 4 ++-- hw/arm/mps2-tz.c | 4 ++-- hw/core/reset.c | 5 +---- hw/hppa/machine.c | 4 ++-- hw/i386/microvm.c | 4 ++-- hw/i386/pc.c | 6 +++--- hw/ppc/pegasos2.c | 4 ++-- hw/ppc/pnv.c | 4 ++-- hw/ppc/spapr.c | 6 +++--- hw/s390x/s390-virtio-ccw.c | 4 ++-- include/hw/boards.h | 3 ++- include/sysemu/reset.h | 5 +++-- system/runstate.c | 13 +++++++++++-- 13 files changed, 37 insertions(+), 29 deletions(-) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index fd5603f7aa..cbca7685da 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -1529,12 +1529,12 @@ static void aspeed_machine_bletchley_class_init(Obj= ectClass *oc, void *data) aspeed_machine_class_init_cpus_defaults(mc); } =20 -static void fby35_reset(MachineState *state, ShutdownCause reason) +static void fby35_reset(MachineState *state, ResetType type) { AspeedMachineState *bmc =3D ASPEED_MACHINE(state); AspeedGPIOState *gpio =3D &bmc->soc->gpio; =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); =20 /* Board ID: 7 (Class-1, 4 slots) */ object_property_set_bool(OBJECT(gpio), "gpioV4", true, &error_fatal); diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c index aec57c0d68..8edf57a66d 100644 --- a/hw/arm/mps2-tz.c +++ b/hw/arm/mps2-tz.c @@ -1254,7 +1254,7 @@ static void mps2_set_remap(Object *obj, const char *v= alue, Error **errp) } } =20 -static void mps2_machine_reset(MachineState *machine, ShutdownCause reason) +static void mps2_machine_reset(MachineState *machine, ResetType type) { MPS2TZMachineState *mms =3D MPS2TZ_MACHINE(machine); =20 @@ -1264,7 +1264,7 @@ static void mps2_machine_reset(MachineState *machine,= ShutdownCause reason) * reset see the correct mapping. */ remap_memory(mms, mms->remap); - qemu_devices_reset(reason); + qemu_devices_reset(type); } =20 static void mps2tz_class_init(ObjectClass *oc, void *data) diff --git a/hw/core/reset.c b/hw/core/reset.c index 58dfc8db3d..14a2639fbf 100644 --- a/hw/core/reset.c +++ b/hw/core/reset.c @@ -170,11 +170,8 @@ void qemu_unregister_resettable(Object *obj) resettable_container_remove(get_root_reset_container(), obj); } =20 -void qemu_devices_reset(ShutdownCause reason) +void qemu_devices_reset(ResetType type) { - ResetType type =3D (reason =3D=3D SHUTDOWN_CAUSE_SNAPSHOT_LOAD) ? - RESET_TYPE_SNAPSHOT_LOAD : RESET_TYPE_COLD; - /* Reset the simulation */ resettable_reset(OBJECT(get_root_reset_container()), type); } diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index 5d0a8739de..8259fe2e38 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -642,12 +642,12 @@ static void machine_HP_C3700_init(MachineState *machi= ne) machine_HP_common_init_tail(machine, pci_bus, translate); } =20 -static void hppa_machine_reset(MachineState *ms, ShutdownCause reason) +static void hppa_machine_reset(MachineState *ms, ResetType type) { unsigned int smp_cpus =3D ms->smp.cpus; int i; =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); =20 /* Start all CPUs at the firmware entry point. * Monarch CPU will initialize firmware, secondary CPUs diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 40edcee7af..8ae4dff7f2 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -462,7 +462,7 @@ static void microvm_machine_state_init(MachineState *ma= chine) microvm_devices_init(mms); } =20 -static void microvm_machine_reset(MachineState *machine, ShutdownCause rea= son) +static void microvm_machine_reset(MachineState *machine, ResetType type) { MicrovmMachineState *mms =3D MICROVM_MACHINE(machine); CPUState *cs; @@ -475,7 +475,7 @@ static void microvm_machine_reset(MachineState *machine= , ShutdownCause reason) mms->kernel_cmdline_fixed =3D true; } =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); =20 CPU_FOREACH(cs) { cpu =3D X86_CPU(cs); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 7779c88a91..d5cf2309c9 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1706,12 +1706,12 @@ static void pc_machine_initfn(Object *obj) qemu_add_machine_init_done_notifier(&pcms->machine_done); } =20 -static void pc_machine_reset(MachineState *machine, ShutdownCause reason) +static void pc_machine_reset(MachineState *machine, ResetType type) { CPUState *cs; X86CPU *cpu; =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); =20 /* Reset APIC after devices have been reset to cancel * any changes that qemu_devices_reset() might have done. @@ -1726,7 +1726,7 @@ static void pc_machine_reset(MachineState *machine, S= hutdownCause reason) static void pc_machine_wakeup(MachineState *machine) { cpu_synchronize_all_states(); - pc_machine_reset(machine, SHUTDOWN_CAUSE_NONE); + pc_machine_reset(machine, RESET_TYPE_COLD); cpu_synchronize_all_post_reset(); } =20 diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c index 9b0a6b70ab..8ff4a00c34 100644 --- a/hw/ppc/pegasos2.c +++ b/hw/ppc/pegasos2.c @@ -291,14 +291,14 @@ static void pegasos2_superio_write(uint8_t addr, uint= 8_t val) cpu_physical_memory_write(PCI1_IO_BASE + 0x3f1, &val, 1); } =20 -static void pegasos2_machine_reset(MachineState *machine, ShutdownCause re= ason) +static void pegasos2_machine_reset(MachineState *machine, ResetType type) { Pegasos2MachineState *pm =3D PEGASOS2_MACHINE(machine); void *fdt; uint64_t d[2]; int sz; =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); if (!pm->vof) { return; /* Firmware should set up machine so nothing to do */ } diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 3526852685..988fd55d88 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -709,13 +709,13 @@ static void pnv_powerdown_notify(Notifier *n, void *o= paque) } } =20 -static void pnv_reset(MachineState *machine, ShutdownCause reason) +static void pnv_reset(MachineState *machine, ResetType type) { PnvMachineState *pnv =3D PNV_MACHINE(machine); IPMIBmc *bmc; void *fdt; =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); =20 /* * The machine should provide by default an internal BMC simulator. diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 370d7c35d3..95dbb91ba0 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1725,7 +1725,7 @@ void spapr_check_mmu_mode(bool guest_radix) } } =20 -static void spapr_machine_reset(MachineState *machine, ShutdownCause reaso= n) +static void spapr_machine_reset(MachineState *machine, ResetType type) { SpaprMachineState *spapr =3D SPAPR_MACHINE(machine); PowerPCCPU *first_ppc_cpu; @@ -1733,7 +1733,7 @@ static void spapr_machine_reset(MachineState *machine= , ShutdownCause reason) void *fdt; int rc; =20 - if (reason !=3D SHUTDOWN_CAUSE_SNAPSHOT_LOAD) { + if (type !=3D RESET_TYPE_SNAPSHOT_LOAD) { /* * Record-replay snapshot load must not consume random, this was * already replayed from initial machine reset. @@ -1762,7 +1762,7 @@ static void spapr_machine_reset(MachineState *machine= , ShutdownCause reason) spapr_setup_hpt(spapr); } =20 - qemu_devices_reset(reason); + qemu_devices_reset(type); =20 spapr_ovec_cleanup(spapr->ov5_cas); spapr->ov5_cas =3D spapr_ovec_new(); diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index c483ff8064..3471abb58b 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -440,7 +440,7 @@ static void s390_pv_prepare_reset(S390CcwMachineState *= ms) s390_pv_prep_reset(); } =20 -static void s390_machine_reset(MachineState *machine, ShutdownCause reason) +static void s390_machine_reset(MachineState *machine, ResetType type) { S390CcwMachineState *ms =3D S390_CCW_MACHINE(machine); enum s390_reset reset_type; @@ -472,7 +472,7 @@ static void s390_machine_reset(MachineState *machine, S= hutdownCause reason) * Device reset includes CPU clear resets so this has to be * done AFTER the unprotect call above. */ - qemu_devices_reset(reason); + qemu_devices_reset(type); s390_crypto_reset(); =20 /* configure and start the ipl CPU only */ diff --git a/include/hw/boards.h b/include/hw/boards.h index 48ff6d8b93..3e8a6986cd 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -10,6 +10,7 @@ #include "qemu/module.h" #include "qom/object.h" #include "hw/core/cpu.h" +#include "hw/resettable.h" =20 #define TYPE_MACHINE_SUFFIX "-machine" =20 @@ -253,7 +254,7 @@ struct MachineClass { const char *deprecation_reason; =20 void (*init)(MachineState *state); - void (*reset)(MachineState *state, ShutdownCause reason); + void (*reset)(MachineState *state, ResetType type); void (*wakeup)(MachineState *state); int (*kvm_type)(MachineState *machine, const char *arg); =20 diff --git a/include/sysemu/reset.h b/include/sysemu/reset.h index ae436044a9..0e297c0e02 100644 --- a/include/sysemu/reset.h +++ b/include/sysemu/reset.h @@ -27,6 +27,7 @@ #ifndef QEMU_SYSEMU_RESET_H #define QEMU_SYSEMU_RESET_H =20 +#include "hw/resettable.h" #include "qapi/qapi-events-run-state.h" =20 typedef void QEMUResetHandler(void *opaque); @@ -110,7 +111,7 @@ void qemu_unregister_reset(QEMUResetHandler *func, void= *opaque); =20 /** * qemu_devices_reset: Perform a complete system reset - * @reason: reason for the reset + * @reason: type of the reset * * This function performs the low-level work needed to do a complete reset * of the system (calling all the callbacks registered with @@ -121,6 +122,6 @@ void qemu_unregister_reset(QEMUResetHandler *func, void= *opaque); * If you want to trigger a system reset from, for instance, a device * model, don't use this function. Use qemu_system_reset_request(). */ -void qemu_devices_reset(ShutdownCause reason); +void qemu_devices_reset(ResetType type); =20 #endif diff --git a/system/runstate.c b/system/runstate.c index a0e2a5fd22..c2c9afa905 100644 --- a/system/runstate.c +++ b/system/runstate.c @@ -32,6 +32,7 @@ #include "exec/cpu-common.h" #include "gdbstub/syscalls.h" #include "hw/boards.h" +#include "hw/resettable.h" #include "migration/misc.h" #include "migration/postcopy-ram.h" #include "monitor/monitor.h" @@ -507,15 +508,23 @@ static int qemu_debug_requested(void) void qemu_system_reset(ShutdownCause reason) { MachineClass *mc; + ResetType type; =20 mc =3D current_machine ? MACHINE_GET_CLASS(current_machine) : NULL; =20 cpu_synchronize_all_states(); =20 + switch (reason) { + case SHUTDOWN_CAUSE_SNAPSHOT_LOAD: + type =3D RESET_TYPE_SNAPSHOT_LOAD; + break; + default: + type =3D RESET_TYPE_COLD; + } if (mc && mc->reset) { - mc->reset(current_machine, reason); + mc->reset(current_machine, type); } else { - qemu_devices_reset(reason); + qemu_devices_reset(type); } switch (reason) { case SHUTDOWN_CAUSE_NONE: --=20 2.46.0 From nobody Sun Nov 24 08:21:52 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725446673; cv=none; d=zohomail.com; s=zohoarc; b=d8tdM0XvgukuaxSzJ8ulIxo/KFbmBrdUezjWDq0wJE406sLvG/T6ySHdNE8t5/8aTWh7yVZnyxfuSf0UqELU8SJt/MWiacaQQylXHSbcgUqeL6/sokXf8GQ4h+krKZPE7qcc3fRIhFN32c36LLC/E/xHbjuFjcECUnn11K0SAvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725446673; 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=eSq36wEoFMQt1F3L+hqPt13HrcODhRNsn708OxHwApw=; b=lUfKj7Ll3vlq0DGXxyM1deYLecJEW2Swu/lj6a4ig0y8pns/XuqDEMqlhpVrwNIHMCZRClCe/xcTAi5V9idS3NfQCUHwH+hgXRO0tF6Cy039R2yw07ARSOWL2+BT2qBFG0ojoJHVYEZuM8We6zMtHB99/kGtm9kuqNyGYYcqb+4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725446673684116.21945304211022; Wed, 4 Sep 2024 03:44:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slnUp-0001nv-PO; Wed, 04 Sep 2024 06:44:19 -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 1slnUc-0000Uo-Bm for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:44:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slnUa-0001pX-Bl for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:44:06 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-oSqZ8Bo1NJuYaNltTtPxYg-1; Wed, 04 Sep 2024 06:37:53 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D7E3E19560BD; Wed, 4 Sep 2024 10:37:52 +0000 (UTC) Received: from rh-jmarcin.redhat.com (unknown [10.45.225.176]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DE06195605A; Wed, 4 Sep 2024 10:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725446643; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eSq36wEoFMQt1F3L+hqPt13HrcODhRNsn708OxHwApw=; b=MKWS7diOhGt4p3jpBey7KR6XadL4DDsv/v7cfij9s0FmSLamanXGimgKmmZMAe9Z4pHjf/ 1EcPRTDVG6MPUbg171hZIfmrGLFZPnlX5NFOgkKL1Ix5QNBkjHJ+1SWQlkAtpui65Mt76D OrcFFYjXqNSO6mG3+Q9zcYnBvtCkTC8= X-MC-Unique: oSqZ8Bo1NJuYaNltTtPxYg-1 From: Juraj Marcin To: qemu-devel@nongnu.org Cc: Juraj Marcin , David Hildenbrand , Peter Maydell Subject: [PATCH v3 2/4] reset: Add RESET_TYPE_WAKEUP Date: Wed, 4 Sep 2024 12:37:13 +0200 Message-ID: <20240904103722.946194-3-jmarcin@redhat.com> In-Reply-To: <20240904103722.946194-1-jmarcin@redhat.com> References: <20240904103722.946194-1-jmarcin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=jmarcin@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @redhat.com) X-ZM-MESSAGEID: 1725446675148116600 Content-Type: text/plain; charset="utf-8" Some devices need to distinguish cold start reset from waking up from a suspended state. This patch adds new value to the enum, and updates the i386 wakeup method to use this new reset type. Signed-off-by: Juraj Marcin Reviewed-by: David Hildenbrand --- docs/devel/reset.rst | 11 +++++++++++ hw/i386/pc.c | 2 +- include/hw/resettable.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst index 9746a4e8a0..bb94271c1c 100644 --- a/docs/devel/reset.rst +++ b/docs/devel/reset.rst @@ -44,6 +44,17 @@ The Resettable interface handles reset types with an enu= m ``ResetType``: value on each cold reset, such as RNG seed information, and which they must not reinitialize on a snapshot-load reset. =20 +``RESET_TYPE_WAKEUP`` + If the machine supports waking up from a suspended state and needs to re= set + its devices during wake-up (from the ``MachineClass::wakeup()`` method),= this + reset type should be used for such a request. Devices can utilize this r= eset + type to differentiate the reset requested during machine wake-up from ot= her + reset requests. For example, RAM content must not be lost during wake-up= , and + memory devices like virtio-mem that provide additional RAM must not reset + such state during wake-ups, but might do so during cold resets. However,= this + reset type should not be used for wake-up detection, as not every machine + type issues a device reset request during wake-up. + Devices which implement reset methods must treat any unknown ``ResetType`` as equivalent to ``RESET_TYPE_COLD``; this will reduce the amount of existing code we need to change if we add more types in future. diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d5cf2309c9..fc7d363f59 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1726,7 +1726,7 @@ static void pc_machine_reset(MachineState *machine, R= esetType type) static void pc_machine_wakeup(MachineState *machine) { cpu_synchronize_all_states(); - pc_machine_reset(machine, RESET_TYPE_COLD); + pc_machine_reset(machine, RESET_TYPE_WAKEUP); cpu_synchronize_all_post_reset(); } =20 diff --git a/include/hw/resettable.h b/include/hw/resettable.h index 7e249deb8b..edb1f1361b 100644 --- a/include/hw/resettable.h +++ b/include/hw/resettable.h @@ -29,6 +29,7 @@ typedef struct ResettableState ResettableState; * Types of reset. * * + Cold: reset resulting from a power cycle of the object. + * + Wakeup: reset resulting from a wake-up from a suspended state. * * TODO: Support has to be added to handle more types. In particular, * ResettableState structure needs to be expanded. @@ -36,6 +37,7 @@ typedef struct ResettableState ResettableState; typedef enum ResetType { RESET_TYPE_COLD, RESET_TYPE_SNAPSHOT_LOAD, + RESET_TYPE_WAKEUP, } ResetType; =20 /* --=20 2.46.0 From nobody Sun Nov 24 08:21:52 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725446769; cv=none; d=zohomail.com; s=zohoarc; b=bpiqjQPXl7LaCVuoiLz5ifIbh8+UjBbhlwBZLQNPyfEa+dcG6aOhkGhUx/a9IrP7lO44oqjkU1g46stfQ/ET/mDUxu5sIrBkQko/7qcOWdE7BY2K3mauJwmagqEdCDkkoPuVkqw6agFe/GBouw6aukF9KlGF3AobWtNTdGQN6v8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725446769; 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=BH2nZ069vTgdVPVcpqPPG8whg4igkAfJo9IWQrDvPsY=; b=KD9QahBP4qT03zOlZLBLbUUyuCiSp+b0MBWumYzHV6oH1otkyc03RYswgd11zpXcTnYKS+GfJyFJ6/qYNRsIY3Jp4sdZ4b7e34Xfj3UGfOq8LpKCDRj11Ey5DiN11u0iv7cgGxjNK5plQdCpyn3188c9SRc9t0WByVvQltwzH7o= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725446769309201.85946824205257; Wed, 4 Sep 2024 03:46:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slnVf-0000b0-GC; Wed, 04 Sep 2024 06:45:11 -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 1slnVb-0000Mp-7t for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:45:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slnVY-0002A6-Q3 for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:45:06 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-83-czZSIrFeM5uX_cElknGRPw-1; Wed, 04 Sep 2024 06:37:58 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 76C7819560A5; Wed, 4 Sep 2024 10:37:57 +0000 (UTC) Received: from rh-jmarcin.redhat.com (unknown [10.45.225.176]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6D0ED1955D44; Wed, 4 Sep 2024 10:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725446703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BH2nZ069vTgdVPVcpqPPG8whg4igkAfJo9IWQrDvPsY=; b=MBLprpd7NUOXBCArn7K10j6wHNPxwf7SvL53f59Q1d+xTW/s3YuIEBznvi2vTeK1W8+YKI Str0BsWekT0Jzq892UjwaRWMac42K587h3+swSwgW2vyMF2FV9A34D9SVg8jYlQRJ+iKGF /DgzQDBzMMtsO8GHvPbjK6FGAYTOzO4= X-MC-Unique: czZSIrFeM5uX_cElknGRPw-1 From: Juraj Marcin To: qemu-devel@nongnu.org Cc: Juraj Marcin , David Hildenbrand , Peter Maydell Subject: [PATCH v3 3/4] virtio-mem: Use new Resettable framework instead of LegacyReset Date: Wed, 4 Sep 2024 12:37:14 +0200 Message-ID: <20240904103722.946194-4-jmarcin@redhat.com> In-Reply-To: <20240904103722.946194-1-jmarcin@redhat.com> References: <20240904103722.946194-1-jmarcin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.133.124; envelope-from=jmarcin@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @redhat.com) X-ZM-MESSAGEID: 1725446771528116600 Content-Type: text/plain; charset="utf-8" LegacyReset does not pass ResetType to the reset callback method, which the new Resettable framework uses. Due to this, virtio-mem cannot use the new RESET_TYPE_WAKEUP to skip the reset during wake-up from a suspended state. This patch adds overrides Resettable interface methods in VirtIOMEMClass to use the new Resettable framework and replaces qemu_[un]register_reset() calls with qemu_[un]register_resettable(). Signed-off-by: Juraj Marcin Reviewed-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 38 +++++++++++++++++++++------------- include/hw/virtio/virtio-mem.h | 4 ++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index ef64bf1b4a..aeee381eb2 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -895,18 +895,6 @@ static int virtio_mem_validate_features(VirtIODevice *= vdev) return 0; } =20 -static void virtio_mem_system_reset(void *opaque) -{ - VirtIOMEM *vmem =3D VIRTIO_MEM(opaque); - - /* - * During usual resets, we will unplug all memory and shrink the usable - * region size. This is, however, not possible in all scenarios. Then, - * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL= ). - */ - virtio_mem_unplug_all(vmem); -} - static void virtio_mem_prepare_mr(VirtIOMEM *vmem) { const uint64_t region_size =3D memory_region_size(&vmem->memdev->mr); @@ -1123,7 +1111,7 @@ static void virtio_mem_device_realize(DeviceState *de= v, Error **errp) vmstate_register_any(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_early, vmem); } - qemu_register_reset(virtio_mem_system_reset, vmem); + qemu_register_resettable(OBJECT(vmem)); =20 /* * Set ourselves as RamDiscardManager before the plug handler maps the @@ -1143,7 +1131,7 @@ static void virtio_mem_device_unrealize(DeviceState *= dev) * found via an address space anymore. Unset ourselves. */ memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL); - qemu_unregister_reset(virtio_mem_system_reset, vmem); + qemu_unregister_resettable(OBJECT(vmem)); if (vmem->early_migration) { vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_ea= rly, vmem); @@ -1843,12 +1831,31 @@ static void virtio_mem_unplug_request_check(VirtIOM= EM *vmem, Error **errp) } } =20 +static ResettableState *virtio_mem_get_reset_state(Object *obj) +{ + VirtIOMEM *vmem =3D VIRTIO_MEM(obj); + return &vmem->reset_state; +} + +static void virtio_mem_system_reset_hold(Object *obj, ResetType type) +{ + VirtIOMEM *vmem =3D VIRTIO_MEM(obj); + + /* + * During usual resets, we will unplug all memory and shrink the usable + * region size. This is, however, not possible in all scenarios. Then, + * the guest has to deal with this manually (VIRTIO_MEM_REQ_UNPLUG_ALL= ). + */ + virtio_mem_unplug_all(vmem); +} + static void virtio_mem_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); VirtIOMEMClass *vmc =3D VIRTIO_MEM_CLASS(klass); RamDiscardManagerClass *rdmc =3D RAM_DISCARD_MANAGER_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); =20 device_class_set_props(dc, virtio_mem_properties); dc->vmsd =3D &vmstate_virtio_mem; @@ -1875,6 +1882,9 @@ static void virtio_mem_class_init(ObjectClass *klass,= void *data) rdmc->replay_discarded =3D virtio_mem_rdm_replay_discarded; rdmc->register_listener =3D virtio_mem_rdm_register_listener; rdmc->unregister_listener =3D virtio_mem_rdm_unregister_listener; + + rc->get_state =3D virtio_mem_get_reset_state; + rc->phases.hold =3D virtio_mem_system_reset_hold; } =20 static const TypeInfo virtio_mem_info =3D { diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h index 5f5b02b8f9..a1af144c28 100644 --- a/include/hw/virtio/virtio-mem.h +++ b/include/hw/virtio/virtio-mem.h @@ -14,6 +14,7 @@ #define HW_VIRTIO_MEM_H =20 #include "standard-headers/linux/virtio_mem.h" +#include "hw/resettable.h" #include "hw/virtio/virtio.h" #include "qapi/qapi-types-misc.h" #include "sysemu/hostmem.h" @@ -115,6 +116,9 @@ struct VirtIOMEM { =20 /* listeners to notify on plug/unplug activity. */ QLIST_HEAD(, RamDiscardListener) rdl_list; + + /* State of the resettable container */ + ResettableState reset_state; }; =20 struct VirtIOMEMClass { --=20 2.46.0 From nobody Sun Nov 24 08:21:52 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1725446877; cv=none; d=zohomail.com; s=zohoarc; b=ZnEW1k/h+zd+29PZmXtbxb7S7qSmBxZBCiXT+zwoHJLsbuntOY/tTHdRttEP/HjQRHKQGWuj9TGJiK826CHDA4yhSYE9ezDfwKukft1uqIlT2CT8I8EWhgG/sj9N8H4QfdS34L9tvbnjJnw1dQ/6nYal5VseNN+2iJV7N6iWdJQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725446877; 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=RBfTLrt0IJ3bIc4wcoVt1ra0+tOl5RxGmL3k9Bo2YpY=; b=GP97OJme/oFaKZsqNhSnRzWwnK07AKmqh3+N6dLxU5Yl8zsMb+qV93IX16OCb8N8zJSJXdLgwKeLZrx//1c47c8vwSEC03NWebhBD0twr2bJQ6SoU4sUOWaHhN7JGpQ7T1Tak/A/A/ClSmXORNw5qaDQ2yrNap//QdVDvfvXEvo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1725446877233771.2370886536362; Wed, 4 Sep 2024 03:47:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1slnUr-0001tm-5x; Wed, 04 Sep 2024 06:44:21 -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 1slnUj-0000y0-3g for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:44:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1slnUh-0001rk-AQ for qemu-devel@nongnu.org; Wed, 04 Sep 2024 06:44:12 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-134-iPCLRTRQONmLszbm7JEfHw-1; Wed, 04 Sep 2024 06:38:02 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B06F61955D45; Wed, 4 Sep 2024 10:38:01 +0000 (UTC) Received: from rh-jmarcin.redhat.com (unknown [10.45.225.176]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E1D74195605A; Wed, 4 Sep 2024 10:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725446650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RBfTLrt0IJ3bIc4wcoVt1ra0+tOl5RxGmL3k9Bo2YpY=; b=DsgYqjDN+r1Pm9fp7+nDTKTGB2ZSL3+SnSAKIoDQVpN5QFSyl7XxHAHNC18JPEPK9JjsfZ 3aU8jSpiWzt3cUcOA/J+k33KObWqs4ac1YP6Iz0AfmO/OoF+O8gtfJEfdARAF9AExWBar7 zctFQMPbHheVMF4OkJEkka6GQSxOOpo= X-MC-Unique: iPCLRTRQONmLszbm7JEfHw-1 From: Juraj Marcin To: qemu-devel@nongnu.org Cc: Juraj Marcin , David Hildenbrand , Peter Maydell Subject: [PATCH v3 4/4] virtio-mem: Add support for suspend+wake-up with plugged memory Date: Wed, 4 Sep 2024 12:37:15 +0200 Message-ID: <20240904103722.946194-5-jmarcin@redhat.com> In-Reply-To: <20240904103722.946194-1-jmarcin@redhat.com> References: <20240904103722.946194-1-jmarcin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=170.10.129.124; envelope-from=jmarcin@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @redhat.com) X-ZM-MESSAGEID: 1725446878002116600 Content-Type: text/plain; charset="utf-8" Before, the virtio-mem device would unplug all the memory with any reset of the device, including during the wake-up of the guest from a suspended state. Due to this, the virtio-mem driver in the Linux kernel disallowed suspend-to-ram requests in the guest when the VIRTIO_MEM_F_PERSISTENT_SUSPEND feature is not exposed by QEMU. This patch adds the code to skip the reset on wake-up and exposes theVIRTIO_MEM_F_PERSISTENT_SUSPEND feature to the guest kernel driver when suspending is possible in QEMU (currently only x86). Signed-off-by: Juraj Marcin Reviewed-by: David Hildenbrand --- hw/virtio/virtio-mem.c | 10 ++++++++++ hw/virtio/virtio-qmp.c | 3 +++ 2 files changed, 13 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index aeee381eb2..ce228da369 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -883,6 +883,9 @@ static uint64_t virtio_mem_get_features(VirtIODevice *v= dev, uint64_t features, if (vmem->unplugged_inaccessible =3D=3D ON_OFF_AUTO_ON) { virtio_add_feature(&features, VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE); } + if (qemu_wakeup_suspend_enabled()) { + virtio_add_feature(&features, VIRTIO_MEM_F_PERSISTENT_SUSPEND); + } return features; } =20 @@ -1841,6 +1844,13 @@ static void virtio_mem_system_reset_hold(Object *obj= , ResetType type) { VirtIOMEM *vmem =3D VIRTIO_MEM(obj); =20 + /* + * When waking up from standby/suspend-to-ram, do not unplug any memor= y. + */ + if (type =3D=3D RESET_TYPE_WAKEUP) { + return; + } + /* * During usual resets, we will unplug all memory and shrink the usable * region size. This is, however, not possible in all scenarios. Then, diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 1dd96ed20f..cccc6fe761 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -450,6 +450,9 @@ static const qmp_virtio_feature_map_t virtio_mem_featur= e_map[] =3D { FEATURE_ENTRY(VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, \ "VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot = be " "accessed"), + FEATURE_ENTRY(VIRTIO_MEM_F_PERSISTENT_SUSPEND, \ + "VIRTIO_MEM_F_PERSISTENT_SUSPND: Plugged memory will remain " + "plugged when suspending+resuming"), { -1, "" } }; #endif --=20 2.46.0