VFIO fixes 2017-03-31

- We can't disable stolen memory for UPT mode, it breaks Windows
    drivers on Gen9+ IGD (Xiong Zhang)
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.14 (GNU/Linux)
 
 iQIcBAABAgAGBQJY3oA8AAoJECObm247sIsi+P8P/1sUoO+VYEIxo719kN2Roi12
 Q8ZNkuveyBqWlMjuSPGv2bImwZkwJd0sMhEWaXwyYNg76R0tUDN4gakJT3m+2dMn
 vO4jNPkjvQTxi8RYia3MdwmZz7Mxr/hZuhytSXQkeBSqY7RB8UKiqzLy+CHmkjcm
 N5MAZkVq+auUxM2bBbXmls0yuS5PBoa2xDUwGr8omE99+AZWjvgXOEsuBqXVsVty
 //D2k+jZkakH8WraUgZGLr6UBfZ+Tpb21LzWycfer6CAQ7Eg3DyXXODMkvHcSOI5
 pUh8sxtTcWhiFRNgQRef8t3v4+Qk58SkddaMu42X0fAngWh8MnKgGTqVbe/cr5ec
 /HD/NtFMuZtYgL1WGJPPt/lsft8MUXjYEUVX7naKYGYYQCIC1dH6pjldobsZjQe5
 DTDjAHw+ET93TQwGR9fdaql4usEZRVoR/hazBtkR54iUmTZfZgBhFCpucdcK2Fvd
 RnuKpkB0HrKKbD0TtCjqd+G6w8H9o1sMD82wzPkFTl3/qhQTcSR/tc9ab6EeUYDS
 UMT2JX92Pf48aNg/o8d4YDr58VeneOb3guFDq/DB9SzD8we5ZCAPQ2B6bq369Hof
 rTYXopdZnrk/JQVo7eRMGvE1sLPT/4f3QLC2CgVtr7+0aHmg31h8RoaAzpmujJL1
 dNklQ5ZKD1pe3A81c7pA
 =eBZ3
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/awilliam/tags/vfio-updates-20170331.0' into staging

VFIO fixes 2017-03-31

 - We can't disable stolen memory for UPT mode, it breaks Windows
   drivers on Gen9+ IGD (Xiong Zhang)

# gpg: Signature made Fri 31 Mar 2017 17:13:48 BST
# gpg:                using RSA key 0x239B9B6E3BB08B22
# gpg: Good signature from "Alex Williamson <alex.williamson@redhat.com>"
# gpg:                 aka "Alex Williamson <alex@shazbot.org>"
# gpg:                 aka "Alex Williamson <alwillia@redhat.com>"
# gpg:                 aka "Alex Williamson <alex.l.williamson@gmail.com>"
# Primary key fingerprint: 42F6 C04E 540B D1A9 9E7B  8A90 239B 9B6E 3BB0 8B22

* remotes/awilliam/tags/vfio-updates-20170331.0:
  Revert "vfio/pci-quirks.c: Disable stolen memory for igd VFIO"

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2017-03-31 18:06:13 +01:00
commit 95b31d709b

View File

@ -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. */
/*
* 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 (!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(&vdev->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.
*/
if (&vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev),
!vfio_is_vga(vdev) || nr != 4 ||
&vdev->pdev != pci_find_device(pci_device_root_bus(&vdev->pdev),
0, PCI_DEVFN(0x2, 0))) {
return;
}
@ -1424,6 +1393,18 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
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 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.
@ -1479,6 +1460,8 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
goto out;
}
gmch = vfio_pci_read_config(&vdev->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);
pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
/* BDSM is read-write, emulated. The BIOS needs to be able to write it */
pci_set_long(vdev->pdev.config + IGD_BDSM, 0);
pci_set_long(vdev->pdev.wmask + IGD_BDSM, ~0);