diff mbox series

[v2] drm/virtio: document drm_dev_set_unique workaround

Message ID 20181024144252.16518-1-emil.l.velikov@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/virtio: document drm_dev_set_unique workaround | expand

Commit Message

Emil Velikov Oct. 24, 2018, 2:42 p.m. UTC
From: Emil Velikov <emil.velikov@collabora.com>

A while back we removed it, yet that lead to regressions. At some later
point, I've attempted to remove it again without fully grasping the
unique (pun intended) situation that virtio is in.

Add a bulky comment to document why the call should stay as-is, for the
next person who's around.

As a Tl;Dr: virtio sits on top of struct virtio_device, which confuses
dev_is_pci(), wrong info gets sent to userspace and X doesn't start.
Driver needs to explicitly call drm_dev_set_unique() to keep it working.

v2: Fix handful of typos (Laszlo)

Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
Thanks for the quick feedback and corrections Laszlo. They're spot-on
and I've addressed them all here.

Sending it out for posterity-sake. Modulo any objections I'll merge
this via drm-misc.
---
 drivers/gpu/drm/virtio/virtgpu_drm_bus.c | 31 ++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

Comments

Gerd Hoffmann Oct. 30, 2018, 5:34 a.m. UTC | #1
On Wed, Oct 24, 2018 at 03:42:52PM +0100, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov@collabora.com>
> 
> A while back we removed it, yet that lead to regressions. At some later
> point, I've attempted to remove it again without fully grasping the
> unique (pun intended) situation that virtio is in.
> 
> Add a bulky comment to document why the call should stay as-is, for the
> next person who's around.
> 
> As a Tl;Dr: virtio sits on top of struct virtio_device, which confuses
> dev_is_pci(), wrong info gets sent to userspace and X doesn't start.
> Driver needs to explicitly call drm_dev_set_unique() to keep it working.
> 
> v2: Fix handful of typos (Laszlo)
> 
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>

> Sending it out for posterity-sake. Modulo any objections I'll merge
> this via drm-misc.

Ah, good, leaving merging to you then ;)

cheers,
  Gerd
Emil Velikov Oct. 30, 2018, 3:54 p.m. UTC | #2
On Tue, 30 Oct 2018 at 05:34, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Wed, Oct 24, 2018 at 03:42:52PM +0100, Emil Velikov wrote:
> > From: Emil Velikov <emil.velikov@collabora.com>
> >
> > A while back we removed it, yet that lead to regressions. At some later
> > point, I've attempted to remove it again without fully grasping the
> > unique (pun intended) situation that virtio is in.
> >
> > Add a bulky comment to document why the call should stay as-is, for the
> > next person who's around.
> >
> > As a Tl;Dr: virtio sits on top of struct virtio_device, which confuses
> > dev_is_pci(), wrong info gets sent to userspace and X doesn't start.
> > Driver needs to explicitly call drm_dev_set_unique() to keep it working.
> >
> > v2: Fix handful of typos (Laszlo)
> >
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Cc: Hans de Goede <hdegoede@redhat.com>
> > Cc: Laszlo Ersek <lersek@redhat.com>
> > Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
> > Reviewed-by: Laszlo Ersek <lersek@redhat.com>
>
> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
>
Thanks Gerd.

> > Sending it out for posterity-sake. Modulo any objections I'll merge
> > this via drm-misc.
>
> Ah, good, leaving merging to you then ;)
>
I've pushed the commit to drm-misc with Laszlo's RB a bit before your reply.
Hope it's not a problem, but for the future I'll be more patient.

-Emil
diff mbox series

Patch

diff --git a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
index 757ca28ab93e..0887e0b64b9c 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
@@ -53,6 +53,37 @@  int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
 									  0,
 									  "virtiodrmfb");
 
+		/*
+		 * Normally the drm_dev_set_unique() call is done by core DRM.
+		 * The following comment covers, why virtio cannot rely on it.
+		 *
+		 * Unlike the other virtual GPU drivers, virtio abstracts the
+		 * underlying bus type by using struct virtio_device.
+		 *
+		 * Hence the dev_is_pci() check, used in core DRM, will fail
+		 * and the unique returned will be the virtio_device "virtio0",
+		 * while a "pci:..." one is required.
+		 *
+		 * A few other ideas were considered:
+		 * - Extend the dev_is_pci() check [in drm_set_busid] to
+		 *   consider virtio.
+		 *   Seems like a bigger hack than what we have already.
+		 *
+		 * - Point drm_device::dev to the parent of the virtio_device
+		 *   Semantic changes:
+		 *   * Using the wrong device for i2c, framebuffer_alloc and
+		 *     prime import.
+		 *   Visual changes:
+		 *   * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer,
+		 *     will print the wrong information.
+		 *
+		 * We could address the latter issues, by introducing
+		 * drm_device::bus_dev, ... which would be used solely for this.
+		 *
+		 * So for the moment keep things as-is, with a bulky comment
+		 * for the next person who feels like removing this
+		 * drm_dev_set_unique() quirk.
+		 */
 		snprintf(unique, sizeof(unique), "pci:%s", pname);
 		ret = drm_dev_set_unique(dev, unique);
 		if (ret)