Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-31 Thread Zhang, Xiong Y
> On Fri, 31 Mar 2017 19:03:49 +0200
> Igor Mammedov  wrote:
> 
> > On Thu, 30 Mar 2017 20:55:11 -0600
> > Alex Williamson  wrote:
> >
> > > On Fri, 31 Mar 2017 02:27:11 +
> > > "Zhang, Xiong Y"  wrote:
> > >
> > > > > On Thu, 30 Mar 2017 18:27:21 +0800
> > > > > Xiong Zhang  wrote:
> > > > >
> > > > > > This reverts commit
> c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> > > > > >
> > > > > > The original patch intend to prevent linux i915 driver from using
> > > > > > stolen meory. But this patch breaks windows IGD driver loading on
> > > > > > Gen9+, as IGD HW will use stolen memory on Gen9+, once windows
> IGD
> > > > > > driver see zero size stolen memory, it will unload.
> > > > > > Meanwhile stolen memory will be disabled in 915 when i915 run as
> > > > > > a guest.
> > > > >
> > > > > Does this mean that legacy mode IGD assignment is not going to work
> > > > > on Gen9+ with Windows?  Will it continue to work with Gen8-?
> > > > [Zhang, Xiong Y] I try to use the following qemu command to enable
> legacy mode on SKyLake, but It seems the entry point of wins IGD driver isn't
> called(I couldn't confirm this as I don't have the source code, but I didn't 
> see
> any IGD driver info from windbg while I could see many info in upt mode), so
> driver doesn't bind to IGD after win 8.1 boot up.
> > > >   #qemu-system-x86_64 -M pc -enable-kvm -smp 2 -m 2G  -vga none
> -nographic -cpu host -hda "$IMAGE" -device
> vfio-pci,host=00:02.0,x-vga=true,id=hostdev0,bus=pci.0,addr=0x2
> > > > Is this the right method to enable legacy mode ?
> > >
> > > Yeah, that should do it.  x-vga should not be necessary, but shouldn't
> > > hurt IIRC.  Any dmesg errors regarding the ROM?  I think we have
> > > trouble with the ROM if the host is booted in UEFI mode.
> >
> > 1.
> > here is dmesg messages when host is booted with CSM mode enabled
> > and host's bios load option rom on boot:
> >
> > [165041.359929] vfio-pci :00:02.0: vgaarb: changed VGA decodes:
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> > [165073.898940] vfio-pci :00:02.0: vgaarb: changed VGA decodes:
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> > [165074.687515] vfio-pci :00:02.0: enabling device (0400 -> 0403)
> > [165074.791598] vfio_ecap_init: :00:02.0 hiding ecap 0x1b@0x100
> >
> > have output on monitor connected via HDMI
> >
> > 2.
> > and here is dmesg in pure UEFI mode (where host's bios doesn't load option
> rom):
> >
> > [   21.034983] vfio-pci :00:02.0: vgaarb: changed VGA decodes:
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> > [   22.025361] vfio_ecap_init: :00:02.0 hiding ecap 0x1b@0x100
> > [   22.030970] vfio-pci :00:02.0: Invalid PCI ROM header signature:
> expecting 0xaa55, got 0x
> > [   22.031036] vfio-pci :00:02.0: Invalid PCI ROM header signature:
> expecting 0xaa55, got 0x
> > [   24.738793] vfio-pci :00:02.0: Invalid PCI ROM header signature:
> expecting 0xaa55, got 0x
> > [   27.776904] vfio-pci :00:02.0: vgaarb: changed VGA decodes:
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> >
> > no output on monitor connected via HDMI when using Kabylake CPU
> (HD630)
> > but pure UEFI mode used to work (external output) with Skylake CPU
> (HD510)
> 
> In my limited experience, I've never been able to use IGD assignment on
> a pure UEFI host unless I provide the ROM via file.  For instance on my
> laptop I switched to CSM and booted a live CD to dump the ROM, which I
> can then use regardless of the host BIOS mode.
> 
> I just updated my rom-parser to include a version to fixup ROMs for
> vendor/device ID and checksum which should help with this:
> 
> https://github.com/awilliam/rom-parser
> 
> Update the device ID to match your ROM and let it fix the checksum.
> Maybe Xiong has some insight into why the VGA ROM often doesn't seem to
> exist on native pure UEFI hosts.
> 
[Zhang, Xiong Y] According to my limited UEFI knowledge, I could explain this, 
but it may be wrong.
VGA ROM seems a graphic driver in bios, and supply graphic service to grub and 
the early phase of OS.
The content of IGD VGA ROM is filled by system bios.
1. turn on csm, bios supply legacy bios intxx service to grub and OS. VGA ROM 
contain a 16 bit image as a vga bios. 
This image is what we want in vfio legacy mode. 
2. turn off csm, it is native uefi mode and supply uefi runtime service to grub 
and OS, the interface is gst->ConOut and gst->RuntimeServices.
The backend of gst->ConOut for graphic card is GOP(graphics output protocol). 
How to implement IGD GOP, it could be a 32 bit image in VGA ROM, or a uefi 
driver. So in native uefi, VGA ROM could be one of three form:
a. no contents,  GOP uefi driver in bios could implement all the function.
b. 32 bit image   supply driver for GOP
c. 16 bit image + 32 bit image

Attach UEFI GOP definition:
11.9 Graphics Output Protocol
The goal of this section is to replace the 

Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-31 Thread Alex Williamson
On Fri, 31 Mar 2017 19:03:49 +0200
Igor Mammedov  wrote:

> On Thu, 30 Mar 2017 20:55:11 -0600
> Alex Williamson  wrote:
> 
> > On Fri, 31 Mar 2017 02:27:11 +
> > "Zhang, Xiong Y"  wrote:
> >   
> > > > On Thu, 30 Mar 2017 18:27:21 +0800
> > > > Xiong Zhang  wrote:
> > > > 
> > > > > This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> > > > >
> > > > > The original patch intend to prevent linux i915 driver from using
> > > > > stolen meory. But this patch breaks windows IGD driver loading on
> > > > > Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
> > > > > driver see zero size stolen memory, it will unload.
> > > > > Meanwhile stolen memory will be disabled in 915 when i915 run as
> > > > > a guest.
> > > > 
> > > > Does this mean that legacy mode IGD assignment is not going to work
> > > > on Gen9+ with Windows?  Will it continue to work with Gen8-?
> > > [Zhang, Xiong Y] I try to use the following qemu command to enable legacy 
> > > mode on SKyLake, but It seems the entry point of wins IGD driver isn't 
> > > called(I couldn't confirm this as I don't have the source code, but I 
> > > didn't see any IGD driver info from windbg while I could see many info in 
> > > upt mode), so driver doesn't bind to IGD after win 8.1 boot up.
> > >   #qemu-system-x86_64 -M pc -enable-kvm -smp 2 -m 2G  -vga none 
> > > -nographic -cpu host -hda "$IMAGE" -device 
> > > vfio-pci,host=00:02.0,x-vga=true,id=hostdev0,bus=pci.0,addr=0x2
> > > Is this the right method to enable legacy mode ?  
> > 
> > Yeah, that should do it.  x-vga should not be necessary, but shouldn't
> > hurt IIRC.  Any dmesg errors regarding the ROM?  I think we have
> > trouble with the ROM if the host is booted in UEFI mode.  
> 
> 1.
> here is dmesg messages when host is booted with CSM mode enabled
> and host's bios load option rom on boot:
> 
> [165041.359929] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> [165073.898940] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> [165074.687515] vfio-pci :00:02.0: enabling device (0400 -> 0403)
> [165074.791598] vfio_ecap_init: :00:02.0 hiding ecap 0x1b@0x100
> 
> have output on monitor connected via HDMI
> 
> 2.
> and here is dmesg in pure UEFI mode (where host's bios doesn't load option 
> rom):
> 
> [   21.034983] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> [   22.025361] vfio_ecap_init: :00:02.0 hiding ecap 0x1b@0x100
> [   22.030970] vfio-pci :00:02.0: Invalid PCI ROM header signature: 
> expecting 0xaa55, got 0x
> [   22.031036] vfio-pci :00:02.0: Invalid PCI ROM header signature: 
> expecting 0xaa55, got 0x
> [   24.738793] vfio-pci :00:02.0: Invalid PCI ROM header signature: 
> expecting 0xaa55, got 0x
> [   27.776904] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
> olddecodes=io+mem,decodes=io+mem:owns=io+mem
> 
> no output on monitor connected via HDMI when using Kabylake CPU (HD630)
> but pure UEFI mode used to work (external output) with Skylake CPU (HD510)

In my limited experience, I've never been able to use IGD assignment on
a pure UEFI host unless I provide the ROM via file.  For instance on my
laptop I switched to CSM and booted a live CD to dump the ROM, which I
can then use regardless of the host BIOS mode.

I just updated my rom-parser to include a version to fixup ROMs for
vendor/device ID and checksum which should help with this:

https://github.com/awilliam/rom-parser

Update the device ID to match your ROM and let it fix the checksum.
Maybe Xiong has some insight into why the VGA ROM often doesn't seem to
exist on native pure UEFI hosts.

> > ---
> my test config is Win10 guest + IGD drivers 4534 build (installed by win 
> update)
> i3-7100T on C236 chipset with following libvirt config
> 
>   
> ...
> 
>   
>   
> 
>   
>function='0x0'/>
> 
> 
>   
>   
> 
>   
>function='0x0'/>
> 
>   
>   
> 
> 
> 
> 

Hmm, neither of these should be necessary, legacy mode IGD support
should active both automatically.  Thanks,

Alex



Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-31 Thread Igor Mammedov
On Thu, 30 Mar 2017 20:55:11 -0600
Alex Williamson  wrote:

> On Fri, 31 Mar 2017 02:27:11 +
> "Zhang, Xiong Y"  wrote:
> 
> > > On Thu, 30 Mar 2017 18:27:21 +0800
> > > Xiong Zhang  wrote:
> > >   
> > > > This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> > > >
> > > > The original patch intend to prevent linux i915 driver from using
> > > > stolen meory. But this patch breaks windows IGD driver loading on
> > > > Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
> > > > driver see zero size stolen memory, it will unload.
> > > > Meanwhile stolen memory will be disabled in 915 when i915 run as
> > > > a guest.  
> > > 
> > > Does this mean that legacy mode IGD assignment is not going to work
> > > on Gen9+ with Windows?  Will it continue to work with Gen8-?  
> > [Zhang, Xiong Y] I try to use the following qemu command to enable legacy 
> > mode on SKyLake, but It seems the entry point of wins IGD driver isn't 
> > called(I couldn't confirm this as I don't have the source code, but I 
> > didn't see any IGD driver info from windbg while I could see many info in 
> > upt mode), so driver doesn't bind to IGD after win 8.1 boot up.
> >   #qemu-system-x86_64 -M pc -enable-kvm -smp 2 -m 2G  -vga none -nographic 
> > -cpu host -hda "$IMAGE" -device 
> > vfio-pci,host=00:02.0,x-vga=true,id=hostdev0,bus=pci.0,addr=0x2
> > Is this the right method to enable legacy mode ?
> 
> Yeah, that should do it.  x-vga should not be necessary, but shouldn't
> hurt IIRC.  Any dmesg errors regarding the ROM?  I think we have
> trouble with the ROM if the host is booted in UEFI mode.

1.
here is dmesg messages when host is booted with CSM mode enabled
and host's bios load option rom on boot:

[165041.359929] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
olddecodes=io+mem,decodes=io+mem:owns=io+mem
[165073.898940] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
olddecodes=io+mem,decodes=io+mem:owns=io+mem
[165074.687515] vfio-pci :00:02.0: enabling device (0400 -> 0403)
[165074.791598] vfio_ecap_init: :00:02.0 hiding ecap 0x1b@0x100

have output on monitor connected via HDMI

2.
and here is dmesg in pure UEFI mode (where host's bios doesn't load option rom):

[   21.034983] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
olddecodes=io+mem,decodes=io+mem:owns=io+mem
[   22.025361] vfio_ecap_init: :00:02.0 hiding ecap 0x1b@0x100
[   22.030970] vfio-pci :00:02.0: Invalid PCI ROM header signature: 
expecting 0xaa55, got 0x
[   22.031036] vfio-pci :00:02.0: Invalid PCI ROM header signature: 
expecting 0xaa55, got 0x
[   24.738793] vfio-pci :00:02.0: Invalid PCI ROM header signature: 
expecting 0xaa55, got 0x
[   27.776904] vfio-pci :00:02.0: vgaarb: changed VGA decodes: 
olddecodes=io+mem,decodes=io+mem:owns=io+mem

no output on monitor connected via HDMI when using Kabylake CPU (HD630)
but pure UEFI mode used to work (external output) with Skylake CPU (HD510)


---
my test config is Win10 guest + IGD drivers 4534 build (installed by win update)
i3-7100T on C236 chipset with following libvirt config

  
...

  
  

  
  


  
  

  
  

  
  




  

> > 
> > > Please clarify Gen9+, is this Kaby Lake?  
> > [Zhang, Xiong Y] Gen 9+ is SkyLake and later.
> 
> Ok, then I cannot test since I only have access to BDW.  We do have
> users that might start complaining if this is a new change in the
> Windows driver for SKL+.
I can with testing it, just tell me what host/guest settings combination I 
should test it with.

>  
> > > I assume this patch is intended for QEMU 2.9, it's helpful to make that
> > > explicit during the rc freeze.  Thanks,  
> > [Zhang, Xiong Y] Yes, as the original patch has entered into Qemu 2.9 rc1. 
> > So this reverted patch should be entered into the later 2.9 rc.
> > Sorry for the troubles.
> 
> Ok, no problem.  Thanks,
> 
> Alex 
> 
> 




Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-31 Thread Zhang, Xiong Y
> On Fri, 31 Mar 2017 02:27:11 +
> "Zhang, Xiong Y"  wrote:
> 
> > > On Thu, 30 Mar 2017 18:27:21 +0800
> > > Xiong Zhang  wrote:
> > >
> > > > This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> > > >
> > > > The original patch intend to prevent linux i915 driver from using
> > > > stolen meory. But this patch breaks windows IGD driver loading on
> > > > Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
> > > > driver see zero size stolen memory, it will unload.
> > > > Meanwhile stolen memory will be disabled in 915 when i915 run as
> > > > a guest.
> > >
> > > Does this mean that legacy mode IGD assignment is not going to work
> > > on Gen9+ with Windows?  Will it continue to work with Gen8-?
> > [Zhang, Xiong Y] I try to use the following qemu command to enable legacy
> mode on SKyLake, but It seems the entry point of wins IGD driver isn't 
> called(I
> couldn't confirm this as I don't have the source code, but I didn't see any 
> IGD
> driver info from windbg while I could see many info in upt mode), so driver
> doesn't bind to IGD after win 8.1 boot up.
> >   #qemu-system-x86_64 -M pc -enable-kvm -smp 2 -m 2G  -vga none
> -nographic -cpu host -hda "$IMAGE" -device
> vfio-pci,host=00:02.0,x-vga=true,id=hostdev0,bus=pci.0,addr=0x2
> > Is this the right method to enable legacy mode ?
> 
> Yeah, that should do it.  x-vga should not be necessary, but shouldn't
> hurt IIRC.  Any dmesg errors regarding the ROM?  I think we have
> trouble with the ROM if the host is booted in UEFI mode.
[Zhang, Xiong Y] My host boot in legacy bios mode. After adding x-igd-gms in 
legacy mode, win 8.1 IGD driver could bind to IGD, and win 8.1 runs good. 
thanks
> 
> >
> > > Please clarify Gen9+, is this Kaby Lake?
> > [Zhang, Xiong Y] Gen 9+ is SkyLake and later.
> 
> Ok, then I cannot test since I only have access to BDW.  We do have
> users that might start complaining if this is a new change in the
> Windows driver for SKL+.
> 
> > > I assume this patch is intended for QEMU 2.9, it's helpful to make that
> > > explicit during the rc freeze.  Thanks,
> > [Zhang, Xiong Y] Yes, as the original patch has entered into Qemu 2.9 rc1. 
> > So
> this reverted patch should be entered into the later 2.9 rc.
> > Sorry for the troubles.
> 
> Ok, no problem.  Thanks,
> 
> Alex




Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-30 Thread Alex Williamson
On Fri, 31 Mar 2017 02:27:11 +
"Zhang, Xiong Y"  wrote:

> > On Thu, 30 Mar 2017 18:27:21 +0800
> > Xiong Zhang  wrote:
> >   
> > > This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> > >
> > > The original patch intend to prevent linux i915 driver from using
> > > stolen meory. But this patch breaks windows IGD driver loading on
> > > Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
> > > driver see zero size stolen memory, it will unload.
> > > Meanwhile stolen memory will be disabled in 915 when i915 run as
> > > a guest.  
> > 
> > Does this mean that legacy mode IGD assignment is not going to work
> > on Gen9+ with Windows?  Will it continue to work with Gen8-?  
> [Zhang, Xiong Y] I try to use the following qemu command to enable legacy 
> mode on SKyLake, but It seems the entry point of wins IGD driver isn't 
> called(I couldn't confirm this as I don't have the source code, but I didn't 
> see any IGD driver info from windbg while I could see many info in upt mode), 
> so driver doesn't bind to IGD after win 8.1 boot up.
>   #qemu-system-x86_64 -M pc -enable-kvm -smp 2 -m 2G  -vga none -nographic 
> -cpu host -hda "$IMAGE" -device 
> vfio-pci,host=00:02.0,x-vga=true,id=hostdev0,bus=pci.0,addr=0x2
> Is this the right method to enable legacy mode ?

Yeah, that should do it.  x-vga should not be necessary, but shouldn't
hurt IIRC.  Any dmesg errors regarding the ROM?  I think we have
trouble with the ROM if the host is booted in UEFI mode.

> 
> > Please clarify Gen9+, is this Kaby Lake?  
> [Zhang, Xiong Y] Gen 9+ is SkyLake and later.

Ok, then I cannot test since I only have access to BDW.  We do have
users that might start complaining if this is a new change in the
Windows driver for SKL+.
 
> > I assume this patch is intended for QEMU 2.9, it's helpful to make that
> > explicit during the rc freeze.  Thanks,  
> [Zhang, Xiong Y] Yes, as the original patch has entered into Qemu 2.9 rc1. So 
> this reverted patch should be entered into the later 2.9 rc.
> Sorry for the troubles.

Ok, no problem.  Thanks,

Alex 




Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-30 Thread Zhang, Xiong Y
> On Thu, 30 Mar 2017 18:27:21 +0800
> Xiong Zhang  wrote:
> 
> > This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> >
> > The original patch intend to prevent linux i915 driver from using
> > stolen meory. But this patch breaks windows IGD driver loading on
> > Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
> > driver see zero size stolen memory, it will unload.
> > Meanwhile stolen memory will be disabled in 915 when i915 run as
> > a guest.
> 
> Does this mean that legacy mode IGD assignment is not going to work
> on Gen9+ with Windows?  Will it continue to work with Gen8-?
[Zhang, Xiong Y] I try to use the following qemu command to enable legacy mode 
on SKyLake, but It seems the entry point of wins IGD driver isn't called(I 
couldn't confirm this as I don't have the source code, but I didn't see any IGD 
driver info from windbg while I could see many info in upt mode), so driver 
doesn't bind to IGD after win 8.1 boot up.
  #qemu-system-x86_64 -M pc -enable-kvm -smp 2 -m 2G  -vga none -nographic -cpu 
host -hda "$IMAGE" -device 
vfio-pci,host=00:02.0,x-vga=true,id=hostdev0,bus=pci.0,addr=0x2
Is this the right method to enable legacy mode ?

> Please clarify Gen9+, is this Kaby Lake?
[Zhang, Xiong Y] Gen 9+ is SkyLake and later.

> I assume this patch is intended for QEMU 2.9, it's helpful to make that
> explicit during the rc freeze.  Thanks,
[Zhang, Xiong Y] Yes, as the original patch has entered into Qemu 2.9 rc1. So 
this reverted patch should be entered into the later 2.9 rc.
Sorry for the troubles.




Re: [Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-30 Thread Alex Williamson
On Thu, 30 Mar 2017 18:27:21 +0800
Xiong Zhang  wrote:

> This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.
> 
> The original patch intend to prevent linux i915 driver from using
> stolen meory. But this patch breaks windows IGD driver loading on
> Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
> driver see zero size stolen memory, it will unload.
> Meanwhile stolen memory will be disabled in 915 when i915 run as
> a guest.

Does this mean that legacy mode IGD assignment is not going to work
on Gen9+ with Windows?  Will it continue to work with Gen8-?

Please clarify Gen9+, is this Kaby Lake?

I assume this patch is intended for QEMU 2.9, it's helpful to make that
explicit during the rc freeze.  Thanks,

Alex

> Signed-off-by: Xiong Zhang 
> ---
>  hw/vfio/pci-quirks.c | 65 
> ++--
>  1 file changed, 27 insertions(+), 38 deletions(-)
> 
> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
> index e995e32..e9b493b 100644
> --- a/hw/vfio/pci-quirks.c
> +++ b/hw/vfio/pci-quirks.c
> @@ -1367,45 +1367,14 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
> *vdev, int nr)
>  uint16_t cmd_orig, cmd;
>  Error *err = NULL;
>  
> -/* This must be an Intel VGA device. */
> -if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
> -!vfio_is_vga(vdev) || nr != 4) {
> -return;
> -}
> -
> -/*
> - * IGD is not a standard, they like to change their specs often.  We
> - * only attempt to support back to SandBridge and we hope that newer
> - * devices maintain compatibility with generation 8.
> - */
> -gen = igd_gen(vdev);
> -if (gen != 6 && gen != 8) {
> -error_report("IGD device %s is unsupported by IGD quirks, "
> - "try SandyBridge or newer", vdev->vbasedev.name);
> -return;
> -}
> -
> -/*
> - * Regardless of running in UPT or legacy mode, the guest graphics
> - * driver may attempt to use stolen memory, however only legacy mode
> - * has BIOS support for reserving stolen memory in the guest VM.
> - * Emulate the GMCH register in all cases and zero out the stolen
> - * memory size here. Legacy mode may request allocation and re-write
> - * this below.
> - */
> -gmch = vfio_pci_read_config(>pdev, IGD_GMCH, 4);
> -gmch &= ~((gen < 8 ? 0x1f : 0xff) << (gen < 8 ? 3 : 8));
> -
> -/* GMCH is read-only, emulated */
> -pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
> -pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
> -pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
> -
>  /*
> - * This must be at address 00:02.0 for us to even onsider enabling
> - * legacy mode.  The vBIOS has dependencies on the PCI bus address.
> + * This must be an Intel VGA device at address 00:02.0 for us to even
> + * consider enabling legacy mode.  The vBIOS has dependencies on the
> + * PCI bus address.
>   */
> -if (>pdev != pci_find_device(pci_device_root_bus(>pdev),
> +if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
> +!vfio_is_vga(vdev) || nr != 4 ||
> +>pdev != pci_find_device(pci_device_root_bus(>pdev),
> 0, PCI_DEVFN(0x2, 0))) {
>  return;
>  }
> @@ -1425,6 +1394,18 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
> *vdev, int nr)
>  }
>  
>  /*
> + * IGD is not a standard, they like to change their specs often.  We
> + * only attempt to support back to SandBridge and we hope that newer
> + * devices maintain compatibility with generation 8.
> + */
> +gen = igd_gen(vdev);
> +if (gen != 6 && gen != 8) {
> +error_report("IGD device %s is unsupported in legacy mode, "
> + "try SandyBridge or newer", vdev->vbasedev.name);
> +return;
> +}
> +
> +/*
>   * Most of what we're doing here is to enable the ROM to run, so if
>   * there's no ROM, there's no point in setting up this quirk.
>   * NB. We only seem to get BIOS ROMs, so a UEFI VM would need CSM 
> support.
> @@ -1479,6 +1460,8 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
> *vdev, int nr)
>  goto out;
>  }
>  
> +gmch = vfio_pci_read_config(>pdev, IGD_GMCH, 4);
> +
>  /*
>   * If IGD VGA Disable is clear (expected) and VGA is not already enabled,
>   * try to enable it.  Probably shouldn't be using legacy mode without 
> VGA,
> @@ -1549,11 +1532,12 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
> *vdev, int nr)
>   * when IVD (IGD VGA Disable) is clear, but the claim is that it's 
> unused,
>   * so let's not waste VM memory for it.
>   */
> +gmch &= ~((gen < 8 ? 0x1f : 0xff) << (gen < 8 ? 3 : 8));
> +
>  if (vdev->igd_gms) {
>  if (vdev->igd_gms <= 0x10) {
>  gms_mb = vdev->igd_gms * 32;
>   

[Qemu-devel] [PATCH] Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

2017-03-30 Thread Xiong Zhang
This reverts commit c2b2e158cc7b1cb431bd6039824ec13c3184a775.

The original patch intend to prevent linux i915 driver from using
stolen meory. But this patch breaks windows IGD driver loading on
Gen9+, as IGD HW will use stolen memory on Gen9+, once windows IGD
driver see zero size stolen memory, it will unload.
Meanwhile stolen memory will be disabled in 915 when i915 run as
a guest.

Signed-off-by: Xiong Zhang 
---
 hw/vfio/pci-quirks.c | 65 ++--
 1 file changed, 27 insertions(+), 38 deletions(-)

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index e995e32..e9b493b 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -1367,45 +1367,14 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 uint16_t cmd_orig, cmd;
 Error *err = NULL;
 
-/* This must be an Intel VGA device. */
-if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
-!vfio_is_vga(vdev) || nr != 4) {
-return;
-}
-
-/*
- * IGD is not a standard, they like to change their specs often.  We
- * only attempt to support back to SandBridge and we hope that newer
- * devices maintain compatibility with generation 8.
- */
-gen = igd_gen(vdev);
-if (gen != 6 && gen != 8) {
-error_report("IGD device %s is unsupported by IGD quirks, "
- "try SandyBridge or newer", vdev->vbasedev.name);
-return;
-}
-
-/*
- * Regardless of running in UPT or legacy mode, the guest graphics
- * driver may attempt to use stolen memory, however only legacy mode
- * has BIOS support for reserving stolen memory in the guest VM.
- * Emulate the GMCH register in all cases and zero out the stolen
- * memory size here. Legacy mode may request allocation and re-write
- * this below.
- */
-gmch = vfio_pci_read_config(>pdev, IGD_GMCH, 4);
-gmch &= ~((gen < 8 ? 0x1f : 0xff) << (gen < 8 ? 3 : 8));
-
-/* GMCH is read-only, emulated */
-pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
-pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
-pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
-
 /*
- * This must be at address 00:02.0 for us to even onsider enabling
- * legacy mode.  The vBIOS has dependencies on the PCI bus address.
+ * This must be an Intel VGA device at address 00:02.0 for us to even
+ * consider enabling legacy mode.  The vBIOS has dependencies on the
+ * PCI bus address.
  */
-if (>pdev != pci_find_device(pci_device_root_bus(>pdev),
+if (!vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, PCI_ANY_ID) ||
+!vfio_is_vga(vdev) || nr != 4 ||
+>pdev != pci_find_device(pci_device_root_bus(>pdev),
0, PCI_DEVFN(0x2, 0))) {
 return;
 }
@@ -1425,6 +1394,18 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 }
 
 /*
+ * IGD is not a standard, they like to change their specs often.  We
+ * only attempt to support back to SandBridge and we hope that newer
+ * devices maintain compatibility with generation 8.
+ */
+gen = igd_gen(vdev);
+if (gen != 6 && gen != 8) {
+error_report("IGD device %s is unsupported in legacy mode, "
+ "try SandyBridge or newer", vdev->vbasedev.name);
+return;
+}
+
+/*
  * Most of what we're doing here is to enable the ROM to run, so if
  * there's no ROM, there's no point in setting up this quirk.
  * NB. We only seem to get BIOS ROMs, so a UEFI VM would need CSM support.
@@ -1479,6 +1460,8 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 goto out;
 }
 
+gmch = vfio_pci_read_config(>pdev, IGD_GMCH, 4);
+
 /*
  * If IGD VGA Disable is clear (expected) and VGA is not already enabled,
  * try to enable it.  Probably shouldn't be using legacy mode without VGA,
@@ -1549,11 +1532,12 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
  * when IVD (IGD VGA Disable) is clear, but the claim is that it's unused,
  * so let's not waste VM memory for it.
  */
+gmch &= ~((gen < 8 ? 0x1f : 0xff) << (gen < 8 ? 3 : 8));
+
 if (vdev->igd_gms) {
 if (vdev->igd_gms <= 0x10) {
 gms_mb = vdev->igd_gms * 32;
 gmch |= vdev->igd_gms << (gen < 8 ? 3 : 8);
-pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
 } else {
 error_report("Unsupported IGD GMS value 0x%x", vdev->igd_gms);
 vdev->igd_gms = 0;
@@ -1573,6 +1557,11 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
 bdsm_size, sizeof(*bdsm_size));
 
+/* GMCH is read-only, emulated */
+pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
+pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
+