linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/qxl: get vga ioports
@ 2019-08-05  8:53 Gerd Hoffmann
  2019-08-05  9:18 ` [Spice-devel] " Frediano Ziglio
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Hoffmann @ 2019-08-05  8:53 UTC (permalink / raw)
  To: dri-devel
  Cc: Gerd Hoffmann, Dave Airlie, David Airlie, Daniel Vetter,
	open list:DRM DRIVER FOR QXL VIRTUAL GPU,
	open list:DRM DRIVER FOR QXL VIRTUAL GPU, open list

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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/qxl/qxl_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c
index b57a37543613..8a2e86adc423 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.c
+++ b/drivers/gpu/drm/qxl/qxl_drv.c
@@ -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);
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Spice-devel] [PATCH] drm/qxl: get vga ioports
  2019-08-05  8:53 [PATCH] drm/qxl: get vga ioports Gerd Hoffmann
@ 2019-08-05  9:18 ` Frediano Ziglio
  2019-08-05 10:50   ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Frediano Ziglio @ 2019-08-05  9:18 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: dri-devel, David Airlie, open list,
	open list:DRM DRIVER FOR QXL VIRTUAL GPU, Daniel Vetter,
	open list:DRM DRIVER FOR QXL VIRTUAL GPU, Dave Airlie

> 
> 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"

> first in pci scan order.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  drivers/gpu/drm/qxl/qxl_drv.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c
> index b57a37543613..8a2e86adc423 100644
> --- a/drivers/gpu/drm/qxl/qxl_drv.c
> +++ b/drivers/gpu/drm/qxl/qxl_drv.c
> @@ -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.

> +	}
> +
>  	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);

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?

>  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);

Frediano

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Spice-devel] [PATCH] drm/qxl: get vga ioports
  2019-08-05  9:18 ` [Spice-devel] " Frediano Ziglio
@ 2019-08-05 10:50   ` Gerd Hoffmann
  0 siblings, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2019-08-05 10:50 UTC (permalink / raw)
  To: Frediano Ziglio
  Cc: dri-devel, David Airlie, open list,
	open list:DRM DRIVER FOR QXL VIRTUAL GPU, Daniel Vetter,
	open list:DRM DRIVER FOR QXL VIRTUAL GPU, Dave Airlie

  Hi,

> > +	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).

> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-05 10:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-05  8:53 [PATCH] drm/qxl: get vga ioports Gerd Hoffmann
2019-08-05  9:18 ` [Spice-devel] " Frediano Ziglio
2019-08-05 10:50   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).