stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: "Noralf Trønnes" <noralf@tronnes.org>,
	daniel@ffwll.ch, airlied@linux.ie,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	sumit.semwal@linaro.org, christian.koenig@amd.com,
	gregkh@linuxfoundation.org, hdegoede@redhat.com, sean@poorly.run,
	stern@rowland.harvard.edu, dan.carpenter@oracle.com
Cc: dri-devel@lists.freedesktop.org, Pavel Machek <pavel@ucw.cz>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Christoph Hellwig <hch@lst.de>,
	stable@vger.kernel.org
Subject: Re: [PATCH v7] drm: Use USB controller's DMA mask when importing dmabufs
Date: Wed, 3 Mar 2021 14:27:32 +0100	[thread overview]
Message-ID: <6689d8d4-2686-e16e-339a-6d95f6e98dab@suse.de> (raw)
In-Reply-To: <f1271ed4-1bb1-0fe6-a5b1-db9dbae575fe@tronnes.org>


[-- Attachment #1.1: Type: text/plain, Size: 4495 bytes --]

Hi,

thanks for reviewing. This will be fixed in the next iteration.

Best regards
Thomas

Am 03.03.21 um 11:58 schrieb Noralf Trønnes:
> 
> 
> Den 03.03.2021 09.45, skrev Thomas Zimmermann:
>> USB devices cannot perform DMA and hence have no dma_mask set in their
>> device structure. Therefore importing dmabuf into a USB-based driver
>> fails, which breaks joining and mirroring of display in X11.
>>
>> For USB devices, pick the associated USB controller as attachment device.
>> This allows the DRM import helpers to perform the DMA setup. If the DMA
>> controller does not support DMA transfers, we're out of luck and cannot
>> import. Our current USB-based DRM drivers don't use DMA, so the actual
>> DMA device is not important.
>>
>> Drivers should use DRM_GEM_SHMEM_DROVER_OPS_USB to initialize their
>> instance of struct drm_driver.
>>
> 
> This doesn't seem to be the case anymore.
> 
>> Tested by joining/mirroring displays of udl and radeon un der Gnome/X11.
> 
> s/un der/under/
> 
>>
>> v7:
>> 	* fix use-before-init bug in gm12u320 (Dan)
>> v6:
>> 	* implement workaround in DRM drivers and hold reference to
>> 	  DMA device while USB device is in use
>> 	* remove dev_is_usb() (Greg)
>> 	* collapse USB helper into usb_intf_get_dma_device() (Alan)
>> 	* integrate Daniel's TODO statement (Daniel)
>> 	* fix typos (Greg)
>> v5:
>> 	* provide a helper for USB interfaces (Alan)
>> 	* add FIXME item to documentation and TODO list (Daniel)
>> v4:
>> 	* implement workaround with USB helper functions (Greg)
>> 	* use struct usb_device->bus->sysdev as DMA device (Takashi)
>> v3:
>> 	* drop gem_create_object
>> 	* use DMA mask of USB controller, if any (Daniel, Christian, Noralf)
>> v2:
>> 	* move fix to importer side (Christian, Daniel)
>> 	* update SHMEM and CMA helpers for new PRIME callbacks
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Fixes: 6eb0233ec2d0 ("usb: don't inherity DMA properties for USB devices")
>> Tested-by: Pavel Machek <pavel@ucw.cz>
>> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Acked-by: Christian König <christian.koenig@amd.com>
>> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
>> Cc: Christoph Hellwig <hch@lst.de>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: <stable@vger.kernel.org> # v5.10+
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> ---
>>   Documentation/gpu/todo.rst      | 21 +++++++++++++++++++++
>>   drivers/gpu/drm/tiny/gm12u320.c | 28 ++++++++++++++++++++++++++--
>>   drivers/gpu/drm/udl/udl_drv.c   | 17 +++++++++++++++++
>>   drivers/gpu/drm/udl/udl_drv.h   |  1 +
>>   drivers/gpu/drm/udl/udl_main.c  |  9 +++++++++
>>   drivers/usb/core/usb.c          | 32 ++++++++++++++++++++++++++++++++
>>   include/linux/usb.h             |  2 ++
>>   7 files changed, 108 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/tiny/gm12u320.c b/drivers/gpu/drm/tiny/gm12u320.c
>> index 0b4f4f2af1ef..4fe372f43cf5 100644
>> --- a/drivers/gpu/drm/tiny/gm12u320.c
>> +++ b/drivers/gpu/drm/tiny/gm12u320.c
> 
> [...]
> 
>> @@ -638,12 +656,15 @@ static int gm12u320_usb_probe(struct usb_interface *interface,
>>   				      struct gm12u320_device, dev);
>>   	if (IS_ERR(gm12u320))
>>   		return PTR_ERR(gm12u320);
>> +	dev = &gm12u320->dev;
>> +
>> +	gm12u320->dmadev = usb_intf_get_dma_device(to_usb_interface(dev->dev));
>> +	if (!gm12u320->dmadev)
>> +		drm_warn(dev, "buffer sharing not supported"); /* not an error */
>>   
> 
> When implementing this in my own driver I discovered that this device
> ref will leak if probing fails after this.
> 
> I've done it like this:
> 
> 	gdrm->dmadev = usb_intf_get_dma_device(intf);
> 	if (!gdrm->dmadev)
> 		dev_warn(dev, "buffer sharing not supported");
> 
> 	ret = drm_dev_register(drm, 0);
> 	if (ret) {
> 		put_device(gdrm->dmadev);
> 		return ret;
> 	}
> 
> An even better solution would be to have a devm_ version of the function.
> 
> Noralf.
> 
>>   	INIT_DELAYED_WORK(&gm12u320->fb_update.work, gm12u320_fb_update_work);
>>   	mutex_init(&gm12u320->fb_update.lock);
>>   
>> -	dev = &gm12u320->dev;
>> -
>>   	ret = drmm_mode_config_init(dev);
>>   	if (ret)
>>   		return ret;

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

      reply	other threads:[~2021-03-03 13:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  8:45 [PATCH v7] drm: Use USB controller's DMA mask when importing dmabufs Thomas Zimmermann
2021-03-03 10:58 ` Noralf Trønnes
2021-03-03 13:27   ` Thomas Zimmermann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6689d8d4-2686-e16e-339a-6d95f6e98dab@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@linux.ie \
    --cc=christian.koenig@amd.com \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=hdegoede@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=noralf@tronnes.org \
    --cc=pavel@ucw.cz \
    --cc=sean@poorly.run \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=sumit.semwal@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).