From 1d5f84f349d27f1d3ea6a0a6261253269fc1cf68 Mon Sep 17 00:00:00 2001 From: Tomita Moeko Date: Tue, 6 May 2025 01:02:58 +0800 Subject: [PATCH] vfio/igd: Always emulate ASLS (OpRegion) register MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ASLS register represents the base address of OpRegion, and it is programmed with HPA. In IGD passthrough scenario, it needs to be reprogrammed with GPA by guest firmware. To prevent guest accessing wrong memory range, ASLS should always be emulated and cleared. In GVT-g scenario, emulating ASLS is unnecessary as access is handled by kvmgt backend [1]. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/i915/gvt/cfg_space.c?h=v6.14#n295 Signed-off-by: Tomita Moeko Reviewed-by: Corvin Köhne Reviewed-by: Alex Williamson Tested-by: Alex Williamson Link: https://lore.kernel.org/qemu-devel/20250505170305.23622-3-tomitamoeko@gmail.com Signed-off-by: Cédric Le Goater --- hw/vfio/igd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index e06484c9112..b1fce76f725 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -182,10 +182,6 @@ static bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, trace_vfio_pci_igd_opregion_enabled(vdev->vbasedev.name); - pci_set_long(vdev->pdev.config + IGD_ASLS, 0); - pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0); - pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0); - return true; } @@ -584,7 +580,15 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp) if ((vdev->features & VFIO_FEATURE_ENABLE_IGD_LPC) && !vfio_pci_igd_setup_lpc_bridge(vdev, errp)) { goto error; - } + } + + /* + * ASLS (OpRegion address) is read-only, emulated + * It contains HPA, guest firmware need to reprogram it with GPA. + */ + pci_set_long(vdev->pdev.config + IGD_ASLS, 0); + pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0); + pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0); /* * Allow user to override dsm size using x-igd-gms option, in multiples of -- 2.47.2