Skip to content

Commit 598b217

Browse files
l1kgregkh
authored andcommitted
Revert "apple-gmux: lock iGP IO to protect from vgaarb changes"
commit d6fa758 upstream. Commit 4eebd5a ("apple-gmux: lock iGP IO to protect from vgaarb changes") amended this driver's ->probe hook to lock decoding of normal (non-legacy) I/O space accesses to the integrated GPU on dual-GPU MacBook Pros. The lock stays in place until the driver is unbound. The change was made to work around an issue with the out-of-tree nvidia graphics driver (available at http://www.nvidia.com/object/unix.html). It contains the following sequence in nvidia/nv.c: #if defined(CONFIG_VGA_ARB) && !defined(NVCPU_PPC64LE) #if defined(VGA_DEFAULT_DEVICE) vga_tryget(VGA_DEFAULT_DEVICE, VGA_RSRC_LEGACY_MASK); #endif vga_set_legacy_decoding(dev, VGA_RSRC_NONE); #endif This code was reported to cause deadlocks with VFIO already in 2013: https://devtalk.nvidia.com/default/topic/545560 I've reported the issue to Nvidia developers once more in 2017: https://www.spinics.net/lists/dri-devel/msg138754.html On the MacBookPro10,1, this code apparently breaks backlight control (which is handled by apple-gmux via an I/O region starting at 0x700), as reported by Petri Hodju: https://bugzilla.kernel.org/show_bug.cgi?id=86121 I tried to replicate Petri's observations on my MacBook9,1, which uses the same Intel Ivy Bridge + Nvidia GeForce GT 650M architecture, to no avail. On my machine apple-gmux' I/O region remains accessible even with the nvidia driver loaded and commit 4eebd5a reverted. Petri reported that apple-gmux becomes accessible again after a suspend/resume cycle because the BIOS changed the VGA routing on the root port to the Nvidia GPU. Perhaps this is a BIOS issue after all that can be fixed with an update? In any case, the change made by commit 4eebd5a has turned out to cause two new issues: * Wilfried Klaebe reports a deadlock when launching Xorg because it opens /dev/vga_arbiter and calls vga_get(), but apple-gmux is holding a lock on I/O space indefinitely. It looks like apple-gmux' current behavior is an abuse of the vgaarb API as locks are not meant to be held for longer periods: https://bugzilla.kernel.org/show_bug.cgi?id=88861#c11 https://bugzilla.kernel.org/attachment.cgi?id=217541 * On dual GPU MacBook Pros introduced since 2013, the integrated GPU is powergated on boot und thus becomes invisible to Linux unless a custom EFI protocol is used to leave it powered on. (A patch exists but is not in mainline yet due to several negative side effects.) On these machines, locking I/O to the integrated GPU (as done by 4eebd5a) fails and backlight control is therefore broken: https://bugzilla.kernel.org/show_bug.cgi?id=105051 So let's revert commit 4eebd5a please. Users experiencing the issue with the proprietary nvidia driver can comment out the above- quoted problematic code as a workaround (or try updating the BIOS). Cc: Petri Hodju <petrihodju@yahoo.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Bruno Prémont <bonbons@linux-vserver.org> Cc: Andy Ritger <aritger@nvidia.com> Cc: Ronald Tschalär <ronald@innovation.ch> Tested-by: Wilfried Klaebe <linux-kernel@lebenslange-mailadresse.de> Signed-off-by: Lukas Wunner <lukas@wunner.de> Cc: stable@vger.kernel.org Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e7cedb5 commit 598b217

1 file changed

Lines changed: 1 addition & 47 deletions

File tree

‎drivers/platform/x86/apple-gmux.c‎

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <linux/delay.h>
2525
#include <linux/pci.h>
2626
#include <linux/vga_switcheroo.h>
27-
#include <linux/vgaarb.h>
2827
#include <acpi/video.h>
2928
#include <asm/io.h>
3029

@@ -54,7 +53,6 @@ struct apple_gmux_data {
5453
bool indexed;
5554
struct mutex index_lock;
5655

57-
struct pci_dev *pdev;
5856
struct backlight_device *bdev;
5957

6058
/* switcheroo data */
@@ -599,23 +597,6 @@ static int gmux_resume(struct device *dev)
599597
return 0;
600598
}
601599

602-
static struct pci_dev *gmux_get_io_pdev(void)
603-
{
604-
struct pci_dev *pdev = NULL;
605-
606-
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev))) {
607-
u16 cmd;
608-
609-
pci_read_config_word(pdev, PCI_COMMAND, &cmd);
610-
if (!(cmd & PCI_COMMAND_IO))
611-
continue;
612-
613-
return pdev;
614-
}
615-
616-
return NULL;
617-
}
618-
619600
static int is_thunderbolt(struct device *dev, void *data)
620601
{
621602
return to_pci_dev(dev)->is_thunderbolt;
@@ -631,7 +612,6 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
631612
int ret = -ENXIO;
632613
acpi_status status;
633614
unsigned long long gpe;
634-
struct pci_dev *pdev = NULL;
635615

636616
if (apple_gmux_data)
637617
return -EBUSY;
@@ -682,31 +662,14 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
682662
ver_minor = (version >> 16) & 0xff;
683663
ver_release = (version >> 8) & 0xff;
684664
} else {
685-
pr_info("gmux device not present or IO disabled\n");
665+
pr_info("gmux device not present\n");
686666
ret = -ENODEV;
687667
goto err_release;
688668
}
689669
}
690670
pr_info("Found gmux version %d.%d.%d [%s]\n", ver_major, ver_minor,
691671
ver_release, (gmux_data->indexed ? "indexed" : "classic"));
692672

693-
/*
694-
* Apple systems with gmux are EFI based and normally don't use
695-
* VGA. In addition changing IO+MEM ownership between IGP and dGPU
696-
* disables IO/MEM used for backlight control on some systems.
697-
* Lock IO+MEM to GPU with active IO to prevent switch.
698-
*/
699-
pdev = gmux_get_io_pdev();
700-
if (pdev && vga_tryget(pdev,
701-
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM)) {
702-
pr_err("IO+MEM vgaarb-locking for PCI:%s failed\n",
703-
pci_name(pdev));
704-
ret = -EBUSY;
705-
goto err_release;
706-
} else if (pdev)
707-
pr_info("locked IO for PCI:%s\n", pci_name(pdev));
708-
gmux_data->pdev = pdev;
709-
710673
memset(&props, 0, sizeof(props));
711674
props.type = BACKLIGHT_PLATFORM;
712675
props.max_brightness = gmux_read32(gmux_data, GMUX_PORT_MAX_BRIGHTNESS);
@@ -822,10 +785,6 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
822785
err_notify:
823786
backlight_device_unregister(bdev);
824787
err_release:
825-
if (gmux_data->pdev)
826-
vga_put(gmux_data->pdev,
827-
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM);
828-
pci_dev_put(pdev);
829788
release_region(gmux_data->iostart, gmux_data->iolen);
830789
err_free:
831790
kfree(gmux_data);
@@ -845,11 +804,6 @@ static void gmux_remove(struct pnp_dev *pnp)
845804
&gmux_notify_handler);
846805
}
847806

848-
if (gmux_data->pdev) {
849-
vga_put(gmux_data->pdev,
850-
VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM);
851-
pci_dev_put(gmux_data->pdev);
852-
}
853807
backlight_device_unregister(gmux_data->bdev);
854808

855809
release_region(gmux_data->iostart, gmux_data->iolen);

0 commit comments

Comments
 (0)