Skip to contentSkip to conversation

drm/qxl: get vga ioports

PATCH In review Gerd Hoffmann 2 participants 5 messages Aug 5, 2019

Subsystems (4)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH 1/1 drm/qxl: get vga ioports

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Reporducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being first in pci scan order.

---
 drivers/gpu/drm/qxl/qxl_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +10 -1
index b57a37543613..8a2e86adc423 100644
@@ -87,9 +87,15 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+	if (ret) {
+		DRM_ERROR("can't get legacy vga ports\n");
+		goto put_vga;
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
 	if (ret)
@@ -109,6 +115,8 @@ qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	vga_put(pdev, VGA_RSRC_LEGACY_IO);
 disable_pci:
 	pci_disable_device(pdev);
 free_dev:
@@ -126,6 +134,7 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);
Signature · 6 lines
2.18.1

_______________________________________________
Spice-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/spice-devel
#1 lore raw
Quoted 11 lines

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Reporducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being

typo: "Reporducer"

Quoted 12 lines

first in pci scan order.

---
 drivers/gpu/drm/qxl/qxl_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
index b57a37543613..8a2e86adc423 100644

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct · line 94

Quoted 8 lines
drivers/gpu/drm/qxl/qxl_drv.c +4 -0
@@ -87,9 +87,15 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+	if (ret) {
+		DRM_ERROR("can't get legacy vga ports\n");
+		goto put_vga;

I suppose that if this fails it's secondary so should continue. What happen configuring 2 QXL devices?
Only a card should provide VGA registers in the system so if any other card provide them QXL won't work.

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +3 -1
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 	if (ret)

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct · line 120

Quoted 6 lines
drivers/gpu/drm/qxl/qxl_drv.c +2 -0
@@ -109,6 +115,8 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	vga_put(pdev, VGA_RSRC_LEGACY_IO);

What happen if you didn't get the I/O? Maybe it's safe to just call vga_put and avoid adding an additional label here?

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_remove(struct pci_dev *pdev) · line 140

Quoted 11 lines
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 disable_pci:
 	pci_disable_device(pdev);

free_dev:

drivers/gpu/drm/qxl/qxl_drv.c +1 -0
@@ -126,6 +134,7 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);

Frediano

author maintainer
#2 lore raw

Hi,

Quoted 6 lines

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 93

Quoted 4 lines
drivers/gpu/drm/qxl/qxl_drv.c +4 -0
+	ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+	if (ret) {
+		DRM_ERROR("can't get legacy vga ports\n");
+		goto put_vga;

I suppose that if this fails it's secondary so should continue.

Ah, right, there are secondary qxl cards (without the vga compat bits). We should skip the call in that case (likewise for the cleanups).

Quoted 3 lines

What happen configuring 2 QXL devices?
Only a card should provide VGA registers in the system so if any other card provide them QXL won't work.

Well, with intel vgpu everything works fine with this patch. Probably i915 skips direct vga register access in case vga_get fails (because qxl grabed them first).

In any case I'd prefer to fail qxl initialization over continuing despite vga_get() having failed. The failure mode is rather awkward:
qemu thinks the qxl card is in vga mode while the guest kernel thinks qxl is in native mode. Guest keeps queuing commands until the ring is full while qemu never takes them out, so at some point the guest kernel blocks forever in qxl_ring_push().

cheers,
Gerd

author maintainer
#3 lore raw
In reply to Frediano Ziglio

Hi,

Quoted 6 lines

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 93

Quoted 4 lines
drivers/gpu/drm/qxl/qxl_drv.c +4 -0
+	ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+	if (ret) {
+		DRM_ERROR("can't get legacy vga ports\n");
+		goto put_vga;

I suppose that if this fails it's secondary so should continue.

Ah, right, there are secondary qxl cards (without the vga compat bits). We should skip the call in that case (likewise for the cleanups).

Quoted 3 lines

What happen configuring 2 QXL devices?
Only a card should provide VGA registers in the system so if any other card provide them QXL won't work.

Well, with intel vgpu everything works fine with this patch. Probably i915 skips direct vga register access in case vga_get fails (because qxl grabed them first).

In any case I'd prefer to fail qxl initialization over continuing despite vga_get() having failed. The failure mode is rather awkward:
qemu thinks the qxl card is in vga mode while the guest kernel thinks qxl is in native mode. Guest keeps queuing commands until the ring is full while qemu never takes them out, so at some point the guest kernel blocks forever in qxl_ring_push().

cheers,
Gerd

#4 lore raw
In reply to Gerd Hoffmann
Quoted 11 lines

qxl has two modes: "native" (used by the drm driver) and "vga" (vga compatibility mode, typically used for boot display and firmware framebuffers).

Accessing any vga ioport will switch the qxl device into vga mode. The qxl driver never does that, but other drivers accessing vga ports can trigger that too and therefore disturb qxl operation. So aquire the legacy vga ioports from vgaarb to avoid that.

Reporducer: Boot kvm guest with both qxl and i915 vgpu, with qxl being

typo: "Reporducer"

Quoted 12 lines

first in pci scan order.

---
 drivers/gpu/drm/qxl/qxl_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
index b57a37543613..8a2e86adc423 100644

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct · line 94

Quoted 8 lines
drivers/gpu/drm/qxl/qxl_drv.c +4 -0
@@ -87,9 +87,15 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	if (ret)
 		goto disable_pci;
 
+	ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
+	if (ret) {
+		DRM_ERROR("can't get legacy vga ports\n");
+		goto put_vga;

I suppose that if this fails it's secondary so should continue. What happen configuring 2 QXL devices?
Only a card should provide VGA registers in the system so if any other card provide them QXL won't work.

Quoted 10 lines
drivers/gpu/drm/qxl/qxl_drv.c +3 -1
+	}
+
 	ret = qxl_device_init(qdev, &qxl_driver, pdev);
 	if (ret)
-		goto disable_pci;
+		goto put_vga;
 
 	ret = qxl_modeset_init(qdev);
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 	if (ret)

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_probe(struct pci_dev *pdev, const struct · line 120

Quoted 6 lines
drivers/gpu/drm/qxl/qxl_drv.c +2 -0
@@ -109,6 +115,8 @@ qxl_pci_probe(struct pci_dev *pdev, const struct
 pci_device_id *ent)
 	qxl_modeset_fini(qdev);
 unload:
 	qxl_device_fini(qdev);
+put_vga:
+	vga_put(pdev, VGA_RSRC_LEGACY_IO);

What happen if you didn't get the I/O? Maybe it's safe to just call vga_put and avoid adding an additional label here?

drivers/gpu/drm/qxl/qxl_drv.c qxl_pci_remove(struct pci_dev *pdev) · line 140

Quoted 11 lines
drivers/gpu/drm/qxl/qxl_drv.c +0 -0
 disable_pci:
 	pci_disable_device(pdev);

free_dev:

drivers/gpu/drm/qxl/qxl_drv.c +1 -0
@@ -126,6 +134,7 @@ qxl_pci_remove(struct pci_dev *pdev)
 
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
+	vga_put(pdev, VGA_RSRC_LEGACY_IO);
 
 	dev->dev_private = NULL;
 	kfree(qdev);

Frediano