[PATCH 00/10] vfio/igd: Remove legacy mode

Tomita Moeko posted 10 patches 1 month ago
hw/vfio/igd.c        | 476 ++++++++++++++-----------------------------
hw/vfio/pci-quirks.c |  51 +----
hw/vfio/pci.c        |  33 +--
hw/vfio/pci.h        |  12 +-
4 files changed, 166 insertions(+), 406 deletions(-)
[PATCH 00/10] vfio/igd: Remove legacy mode
Posted by Tomita Moeko 1 month ago
This patchset removes some legacy checks and converts the legacy mode
implicitly enabled by BDF 00:02.0 into x-igd-* options, including:
* Removing PCI ROM BAR and VGA IO/MMIO range check before applying quirk
* Using unified x-igd-opregion option for OpRegion access.
* Introducing new x-igd-lpc option for the LPC bridge / Host bridge ID
  quirk. Currently this is only supported on i440fx.
* Extending quirk support when IGD is not assigned to BDF 00:02.0

The first 2 patches of this patchset was taken from a previous one,
details can be found at:
https://lore.kernel.org/all/20250124191245.12464-1-tomitamoeko@gmail.com/

This patchest was mainly tested on Alder Lake UHD770, with Debian 12
(kernel 6.1), Windows 11 (driver 32.0.101.6458) and Intel GOP driver
17.0.1081.

If the design is good to go, I will update the documentation also.

A open question is whether the old legacy mode behavior should be kept
or not. Checking if all the condition of legacy mode were met and
toggling correspoding options is more complicated then I expected :(
Any ideas would be appreciated.


Tomita Moeko (10):
  vfio/igd: Remove GTT write quirk in IO BAR 4
  vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size
  vfio/igd: Remove rombar check for legacy mode
  vfio/igd: Remove implicit VGA access enabled by legacy mode
  vfio/pci: Make vfio_populate_vga static
  vfio/igd: Consolidate OpRegion initialization into a single function
  vfio/igd: Move LPC bridge initialization to a separate function
  vfio/pci: Add placeholder for device-specific config space quirks
  vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk
  vfio/igd: Replace legacy mode with options

 hw/vfio/igd.c        | 476 ++++++++++++++-----------------------------
 hw/vfio/pci-quirks.c |  51 +----
 hw/vfio/pci.c        |  33 +--
 hw/vfio/pci.h        |  12 +-
 4 files changed, 166 insertions(+), 406 deletions(-)

-- 
2.47.2
Re: [PATCH 00/10] vfio/igd: Remove legacy mode
Posted by Alex Williamson 1 month ago
On Tue, 25 Feb 2025 02:29:17 +0800
Tomita Moeko <tomitamoeko@gmail.com> wrote:

> This patchset removes some legacy checks and converts the legacy mode
> implicitly enabled by BDF 00:02.0 into x-igd-* options, including:
> * Removing PCI ROM BAR and VGA IO/MMIO range check before applying quirk
> * Using unified x-igd-opregion option for OpRegion access.
> * Introducing new x-igd-lpc option for the LPC bridge / Host bridge ID
>   quirk. Currently this is only supported on i440fx.
> * Extending quirk support when IGD is not assigned to BDF 00:02.0
> 
> The first 2 patches of this patchset was taken from a previous one,
> details can be found at:
> https://lore.kernel.org/all/20250124191245.12464-1-tomitamoeko@gmail.com/
> 
> This patchest was mainly tested on Alder Lake UHD770, with Debian 12
> (kernel 6.1), Windows 11 (driver 32.0.101.6458) and Intel GOP driver
> 17.0.1081.
> 
> If the design is good to go, I will update the documentation also.
> 
> A open question is whether the old legacy mode behavior should be kept
> or not. Checking if all the condition of legacy mode were met and
> toggling correspoding options is more complicated then I expected :(
> Any ideas would be appreciated.

I dusted off a working IGD assignment configuration on an i7-7700 Kaby
Lake system with HD630 graphics.  This series breaks it a couple times.

First, while the host system itself may support UEFI (some systems may
not), I had dumped the VGA ROM in CSM mode and run the VM with SeaBIOS.
Therefore it needs VGA support.  This is the recommended configuration
for legacy mode in our current documentation.  Patch 4/ requires that I
add x-vga to continue using this VM.

Then of course since this VM is specifically using legacy mode, patch
10/ requires that I also add both x-igd-opregion and x-igd-lpc.

Therefore I go from a VM that works with IGD assignment in legacy mode,
with no unsupported options:

<domain type="kvm">
    ...
    <type arch="x86_64" machine="pc-i440fx-10.0">hvm</type>
    ...
    <hostdev mode="subsystem" type="pci" managed="yes">
      <source>
        <address domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
      </source>
      <rom file="/var/lib/libvirt/images/igd-i7-7700.rom"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
    </hostdev>

To one that requires multiple unsupported, experimental options:

<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
    ...
    <type arch="x86_64" machine="pc-i440fx-10.0">hvm</type>
    ...
    <hostdev mode="subsystem" type="pci" managed="yes">
      <source>
        <address domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
      </source>
      <alias name="ua-igd"/>
      <rom file="/var/lib/libvirt/images/igd-i7-7700.rom"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
    </hostdev>
  ...
  <qemu:override>
    <qemu:device alias="ua-igd">
      <qemu:frontend>
        <qemu:property name="x-vga" type="bool" value="true"/>
        <qemu:property name="x-igd-opregion" type="bool" value="true"/>
        <qemu:property name="x-igd-lpc" type="bool" value="true"/>
      </qemu:frontend>
    </qemu:device>
  </qemu:override>

I don't know how we justify this within our defacto support contract
with users.  Legacy mode needs to continue to exist and be
automatically enabled unless we want to figure out a deprecation
process for it and queue this sort of change for sometime in the
future.  Thanks,

Alex
Re: [PATCH 00/10] vfio/igd: Remove legacy mode
Posted by Cédric Le Goater 1 month ago
Hello Tomita,

+Corvin

On 2/24/25 19:29, Tomita Moeko wrote:
> This patchset removes some legacy checks and converts the legacy mode
> implicitly enabled by BDF 00:02.0 into x-igd-* options, including:
> * Removing PCI ROM BAR and VGA IO/MMIO range check before applying quirk
> * Using unified x-igd-opregion option for OpRegion access.
> * Introducing new x-igd-lpc option for the LPC bridge / Host bridge ID
>    quirk. Currently this is only supported on i440fx.
> * Extending quirk support when IGD is not assigned to BDF 00:02.0
> 
> The first 2 patches of this patchset was taken from a previous one,
> details can be found at:
> https://lore.kernel.org/all/20250124191245.12464-1-tomitamoeko@gmail.com/
> 
> This patchest was mainly tested on Alder Lake UHD770, with Debian 12
> (kernel 6.1), Windows 11 (driver 32.0.101.6458) and Intel GOP driver
> 17.0.1081.

Did you try a Linux guest ?

Could you provide the QEMU command line please ? I would like to
reproduce on the AlderLake-S GT1 system I have access to.

Also, since you spent quite of lot time on IGD support, would you
mind adding a vfio-igd entry in the MAINTAINERS file and propose
your self as a maintainer ? The aim would be to keep you informed
of the proposed changes on the vfio-igd device, not to handle PRs.
  
> If the design is good to go, I will update the documentation also.

yes please.

> A open question is whether the old legacy mode behavior should be kept
> or not. Checking if all the condition of legacy mode were met and
> toggling correspoding options is more complicated then I expected :(
> Any ideas would be appreciated.

I will let Alex comment,

Thanks,

C.

  
> Tomita Moeko (10):
>    vfio/igd: Remove GTT write quirk in IO BAR 4
>    vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size
>    vfio/igd: Remove rombar check for legacy mode
>    vfio/igd: Remove implicit VGA access enabled by legacy mode
>    vfio/pci: Make vfio_populate_vga static
>    vfio/igd: Consolidate OpRegion initialization into a single function
>    vfio/igd: Move LPC bridge initialization to a separate function
>    vfio/pci: Add placeholder for device-specific config space quirks
>    vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk
>    vfio/igd: Replace legacy mode with options
> 
>   hw/vfio/igd.c        | 476 ++++++++++++++-----------------------------
>   hw/vfio/pci-quirks.c |  51 +----
>   hw/vfio/pci.c        |  33 +--
>   hw/vfio/pci.h        |  12 +-
>   4 files changed, 166 insertions(+), 406 deletions(-)
>
Re: [PATCH 00/10] vfio/igd: Remove legacy mode
Posted by Tomita Moeko 1 month ago
Hello Cédric,

On 2/27/25 16:28, Cédric Le Goater wrote:
> Hello Tomita,
> 
> +Corvin
> 
> On 2/24/25 19:29, Tomita Moeko wrote:
>> This patchset removes some legacy checks and converts the legacy mode
>> implicitly enabled by BDF 00:02.0 into x-igd-* options, including:
>> * Removing PCI ROM BAR and VGA IO/MMIO range check before applying quirk
>> * Using unified x-igd-opregion option for OpRegion access.
>> * Introducing new x-igd-lpc option for the LPC bridge / Host bridge ID
>>    quirk. Currently this is only supported on i440fx.
>> * Extending quirk support when IGD is not assigned to BDF 00:02.0
>>
>> The first 2 patches of this patchset was taken from a previous one,
>> details can be found at:
>> https://lore.kernel.org/all/20250124191245.12464-1-tomitamoeko@gmail.com/
>>
>> This patchest was mainly tested on Alder Lake UHD770, with Debian 12
>> (kernel 6.1), Windows 11 (driver 32.0.101.6458) and Intel GOP driver
>> 17.0.1081.
> 
> Did you try a Linux guest ?
> 
> Could you provide the QEMU command line please ? I would like to
> reproduce on the AlderLake-S GT1 system I have access to.

Ofcourse I did. The command line I used is:
./qemu-system-x86_64 --enable-kvm \
  -cpu host -smp 4 -m 8G -nodefaults -serial mon:stdio \
  -device vfio-pci,host=00:02.0,id=hostdev0,addr=0x2,x-igd-opregion=on \
  -drive id=drive0,if=none,file=debian-vm.qcow2,format=qcow2 \
  -netdev bridge,id=net0,br=br0 \
  -device virtio-blk-pci,drive=drive0,id=virtio-blk-pci0,addr=0x3 \
  -device virtio-net-pci,netdev=net0,addr=0x4 \
  -usb -device usb-host,hostbus=1,hostaddr=5 \
  -pflash /usr/share/OVMF/OVMF_CODE_4M.fd

My guest is running Debian 11 with 6.1.0-31 kernel. Screenshot at
https://imgur.com/a/gsHBpnn

As there is no EFI GOP driver, display can only work after i915 driver
initialized it. For Linux guest, x-igd-opregion=on is not a must as
init_vbt_missing_defaults in i915 driver mocks one if VBT in OpRegion
is not present. Looks like most desktop motherboards follows that intel
default display output configuration.

Note that currently IGD passthrough quirks only takes effect when IGD
is exposed as VGA controller, that is to say, the primary GPU must be
set to IGD in host BIOS.

Btw, If your IGD device is exposed as Display Controller, you may also
try the kernel patch at [1], and remove the vfio_is_vga check in qemu
igd.c. I'm going to make a correspoding change in qemu side after that
kernel patch gets merged.

[1] https://lore.kernel.org/all/20250123163416.7653-1-tomitamoeko@gmail.com/

If it is still not working, adding drm_debug=0x02 in kernel cmdline
enables verbose log. Related options are "Bit 1 (0x02)  will enable
DRIVER messages (drm controller code)" and  "Bit 2 (0x04)  will enable
KMS messages (modesetting code)", 0x06 for both of them.

> Also, since you spent quite of lot time on IGD support, would you
> mind adding a vfio-igd entry in the MAINTAINERS file and propose
> your self as a maintainer ? The aim would be to keep you informed
> of the proposed changes on the vfio-igd device, not to handle PRs.

Sure, I'd be glad to be a maintainer.

>> If the design is good to go, I will update the documentation also.
> 
> yes please.

I will add the documentation in v2. For now, let me wait for Alex
comment first.

Thanks,
Moeko

>> A open question is whether the old legacy mode behavior should be kept
>> or not. Checking if all the condition of legacy mode were met and
>> toggling correspoding options is more complicated then I expected :(
>> Any ideas would be appreciated.
> 
> I will let Alex comment,
> 
> Thanks,
> 
> C.
> 
>  
>> Tomita Moeko (10):
>>    vfio/igd: Remove GTT write quirk in IO BAR 4
>>    vfio/igd: Do not include GTT stolen size in etc/igd-bdsm-size
>>    vfio/igd: Remove rombar check for legacy mode
>>    vfio/igd: Remove implicit VGA access enabled by legacy mode
>>    vfio/pci: Make vfio_populate_vga static
>>    vfio/igd: Consolidate OpRegion initialization into a single function
>>    vfio/igd: Move LPC bridge initialization to a separate function
>>    vfio/pci: Add placeholder for device-specific config space quirks
>>    vfio/igd: Refactor vfio_probe_igd_bar4_quirk into pci config quirk
>>    vfio/igd: Replace legacy mode with options
>>
>>   hw/vfio/igd.c        | 476 ++++++++++++++-----------------------------
>>   hw/vfio/pci-quirks.c |  51 +----
>>   hw/vfio/pci.c        |  33 +--
>>   hw/vfio/pci.h        |  12 +-
>>   4 files changed, 166 insertions(+), 406 deletions(-)
>>
>