qemu-cr16/hw/pci-host
Igor Mammedov 080b623ed4 q35: Fix migration of SMRAM state
When migrating, dst QEMU by default has SMRAM unlocked,
and since wmask is not migrated, the migrated value of
MCH_HOST_BRIDGE_F_SMBASE in config space fall to prey of

  mch_update_smbase_smram()
    ...
    if (pd->wmask[MCH_HOST_BRIDGE_F_SMBASE] == 0xff) {
        *reg = 0x00;

and is getting cleared and leads to unlocked smram
on dst even if on source it's been locked.

As Andrey has pointed out [1], we should derive wmask
from config and not other way around.

Drop offending chunk and resync wmask based on MCH_HOST_BRIDGE_F_SMBASE
register value. That would preserve the register during
migration and set smram regions into corresponding state.

What that changes is:
that it would let guest write junk values in register
(with no apparent effect) until it's stumbles upon
reserved 0x1 [|] 0x2 values, at which point it
would be only possible to lock register and trigger
switch to SMRAM blackhole in CPU AS.

While at it, fix up test by removing junk discard before negotiation hunk.

PS2:
Instead of adding a dedicated post_load handler for it,
reuse mch_update->mch_update_smbase_smram call chain
that is called on write/reset/post_load to be consistent
with how we handle mch registers.

PS3:
for prosterity here is erro message Andrey got due to this bug:
    qemu: vfio_container_dma_map(0x..., 0x0, 0xa0000, 0x....) = -22 (Invalid argument)
    qemu: hardware error: vfio: DMA mapping failed, unable to continue

1) https://patchew.org/QEMU/20251203180851.6390-1-arbn@yandex-team.com/

Fixes: f404220e27 ("q35: implement 128K SMRAM at default SMBASE address")
Reported-by: Andrey Ryabinin <arbn@yandex-team.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Andrey Ryabinin <arbn@yandex-team.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20251211165454.288476-1-imammedo@redhat.com>
(cherry picked from commit 66cf169e29b06dca104c5a229fba0da4ce33599c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2026-02-06 00:46:09 +03:00
..
articia.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
aspeed_pcie.c hw/pci-host/aspeed_pcie: Update ASPEED PCIe Root Port capabilities and enable MSI to support hotplug 2025-11-24 07:52:42 +01:00
astro.c hw/pci-host/astro: Don't call pci_regsiter_root_bus() in init 2025-09-23 16:52:50 -07:00
bonito.c qom: remove redundant typedef when use OBJECT_DECLARE_SIMPLE_TYPE 2025-10-28 08:08:04 +01:00
designware.c hw/pci-host/designware: Fix viewport configuration 2025-05-06 15:02:35 +01:00
dino.c hw/pci-host/dino: Don't call pci_register_root_bus() in init 2025-09-23 16:52:49 -07:00
fsl_imx8m_phy.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
gpex-acpi.c hw/pci-host/gpex-acpi: Fix _DSM function 0 support return value 2025-11-09 08:24:29 -05:00
gpex.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
grackle.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
gt64120.c qemu: Declare all load/store helper in 'qemu/bswap.h' 2025-07-15 02:56:39 -04:00
i440fx.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
Kconfig hw/pci-host/aspeed: Add AST2600 PCIe PHY model 2025-09-29 18:00:20 +02:00
meson.build hw/pci-host/aspeed: Add AST2600 PCIe PHY model 2025-09-29 18:00:20 +02:00
mv643xx.h mv64361: Add dummy gigabit ethernet PHY access registers 2023-07-07 04:18:26 -03:00
mv64361.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
pam.c hw/pci-host/pam: Make init_pam() usage more readable 2023-05-19 10:30:46 -04:00
pnv_phb.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
pnv_phb.h include/hw/ppc include/hw/pci-host: Drop extra typedefs 2023-01-20 07:25:22 +01:00
pnv_phb3.c qemu: Declare all load/store helper in 'qemu/bswap.h' 2025-07-15 02:56:39 -04:00
pnv_phb3_msi.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
pnv_phb3_pbcq.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
pnv_phb4.c qemu: Declare all load/store helper in 'qemu/bswap.h' 2025-07-15 02:56:39 -04:00
pnv_phb4_pec.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
ppc4xx_pci.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
ppc440_pcix.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
ppce500.c qemu: Declare all load/store helper in 'qemu/bswap.h' 2025-07-15 02:56:39 -04:00
q35.c q35: Fix migration of SMRAM state 2026-02-06 00:46:09 +03:00
raven.c hw/pci-host/raven: Simplify PCI bus creation 2025-10-28 08:19:16 +01:00
remote.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
sabre.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
sh_pci.c qemu: Declare all load/store helper in 'qemu/bswap.h' 2025-07-15 02:56:39 -04:00
trace-events hw/pci-host/aspeed: Add MSI support and per-RC IOMMU address space 2025-09-29 18:00:20 +02:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
uninorth.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
versatile.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00
xen_igd_pt.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
xilinx-pcie.c qom: Make InterfaceInfo[] uses const 2025-04-25 17:00:41 +02:00