On Tue, 20 Jun 2023 13:24:57 -0400
Joel Upham <jupham125@gmail.com> wrote:
> Resetting pci devices after s3 causes guest freezes, as xen usually
> likes to handle resetting devices.
I'd prefer Xen side being fixed instead of hacking reset logic in qemu/q35.
Handling of ACPI and initialization of memory is done in hvmloader from my understanding.
What I noticed was when qemu attempted to reset devices, they became unusable or would freeze the guest. It is very possible
that I am missing something that piix is doing to correctly reset, so any input I can get to make this better
is welcome.
> Signed-off-by: Joel Upham <jupham125@gmail.com>
> ---
> hw/acpi/ich9.c | 12 ++++++++----
> hw/pci-host/q35.c | 3 ++-
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> index 1c236be1c7..234706a191 100644
> --- a/hw/acpi/ich9.c
> +++ b/hw/acpi/ich9.c
> @@ -143,7 +143,8 @@ static int ich9_pm_post_load(void *opaque, int version_id)
> {
> ICH9LPCPMRegs *pm = opaque;
> uint32_t pm_io_base = pm->pm_io_base;
> - pm->pm_io_base = 0;
> + if (!xen_enabled())
> + pm->pm_io_base = 0;
> ich9_pm_iospace_update(pm, pm_io_base);
> return 0;
> }
> @@ -274,7 +275,10 @@ static void pm_reset(void *opaque)
> acpi_pm1_evt_reset(&pm->acpi_regs);
> acpi_pm1_cnt_reset(&pm->acpi_regs);
> acpi_pm_tmr_reset(&pm->acpi_regs);
> - acpi_gpe_reset(&pm->acpi_regs);
> + /* Noticed guest freezing in xen when this was reset after S3. */
> + if (!xen_enabled()) {
> + acpi_gpe_reset(&pm->acpi_regs);
> + }
>
> pm->smi_en = 0;
> if (!pm->smm_enabled) {
> @@ -322,7 +326,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, qemu_irq sci_irq)
> acpi_pm_tco_init(&pm->tco_regs, &pm->io);
> }
>
> - if (pm->acpi_pci_hotplug.use_acpi_hotplug_bridge) {
> + if (pm->acpi_pci_hotplug.use_acpi_hotplug_bridge || xen_enabled()) {
> acpi_pcihp_init(OBJECT(lpc_pci),
> &pm->acpi_pci_hotplug,
> pci_get_bus(lpc_pci),
> @@ -345,7 +349,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm, qemu_irq sci_irq)
> legacy_acpi_cpu_hotplug_init(pci_address_space_io(lpc_pci),
> OBJECT(lpc_pci), &pm->gpe_cpu, ICH9_CPU_HOTPLUG_IO_BASE);
>
> - if (pm->acpi_memory_hotplug.is_enabled) {
> + if (pm->acpi_memory_hotplug.is_enabled || xen_enabled()) {
> acpi_memory_hotplug_init(pci_address_space_io(lpc_pci), OBJECT(lpc_pci),
> &pm->acpi_memory_hotplug,
> ACPI_MEMORY_HOTPLUG_BASE);
> diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
> index 1fe4e5a5c9..5891839ce9 100644
> --- a/hw/pci-host/q35.c
> +++ b/hw/pci-host/q35.c
> @@ -580,7 +580,8 @@ static void mch_reset(DeviceState *qdev)
> d->config[MCH_HOST_BRIDGE_F_SMBASE] = 0;
> d->wmask[MCH_HOST_BRIDGE_F_SMBASE] = 0xff;
>
> - mch_update(mch);
> + if (!xen_enabled())
> + mch_update(mch);
> }
>
> static void mch_realize(PCIDevice *d, Error **errp)