From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B750ACFD2F6 for ; Thu, 27 Nov 2025 08:58:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E39610E754; Thu, 27 Nov 2025 08:58:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="mwKgxhsJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="rHu+2cCh"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="mwKgxhsJ"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="rHu+2cCh"; dkim-atps=neutral Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 048CD10E754 for ; Thu, 27 Nov 2025 08:58:58 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 92D0B5BCC5; Thu, 27 Nov 2025 08:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1764233936; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=eCh39bHAncG6kTiYfEQ/zZomkXk677ON4qVpuJ0u/Vk=; b=mwKgxhsJxfsvWKW4jsn59lf8FS3nEeqFiV6+ITHCzuHjrZjf99witF3l2qS6OatFoFDREJ w27um/FAbBBmtQcnrtdLgUIfLTpX9ADySsIIJ7oyfn7qrosGs+9e4vidtR5003hGg2+PM+ MOkMvKMsTsgqY9YxKDHza/kZvBGDKdM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1764233936; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=eCh39bHAncG6kTiYfEQ/zZomkXk677ON4qVpuJ0u/Vk=; b=rHu+2cChUZ1Z15AlTzO8k5kOJxyhBcFzyRWKfwCYZsr2BZG6qRkmM24juElogJLdrgl0uJ tNRSFUlx6pSNhhDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1764233936; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=eCh39bHAncG6kTiYfEQ/zZomkXk677ON4qVpuJ0u/Vk=; b=mwKgxhsJxfsvWKW4jsn59lf8FS3nEeqFiV6+ITHCzuHjrZjf99witF3l2qS6OatFoFDREJ w27um/FAbBBmtQcnrtdLgUIfLTpX9ADySsIIJ7oyfn7qrosGs+9e4vidtR5003hGg2+PM+ MOkMvKMsTsgqY9YxKDHza/kZvBGDKdM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1764233936; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=eCh39bHAncG6kTiYfEQ/zZomkXk677ON4qVpuJ0u/Vk=; b=rHu+2cChUZ1Z15AlTzO8k5kOJxyhBcFzyRWKfwCYZsr2BZG6qRkmM24juElogJLdrgl0uJ tNRSFUlx6pSNhhDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C25633EA63; Thu, 27 Nov 2025 08:58:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id pRotLc8SKGntRQAAD6G6ig (envelope-from ); Thu, 27 Nov 2025 08:58:55 +0000 Message-ID: <0d1fe2cf-dbda-4e64-bc3b-a2c9c0887820@suse.de> Date: Thu, 27 Nov 2025 09:58:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 01/16] drm/prime: Simplify life of drivers needing custom dma_buf_ops From: Thomas Zimmermann To: Boris Brezillon , Steven Price Cc: dri-devel@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , David Airlie , Simona Vetter , Faith Ekstrand , Thierry Reding , Mikko Perttunen , Melissa Wen , =?UTF-8?Q?Ma=C3=ADra_Canal?= , Lucas De Marchi , =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= , Rodrigo Vivi , Frank Binns , Matt Coster , Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , Alex Deucher , =?UTF-8?Q?Christian_K=C3=B6nig?= , amd-gfx@lists.freedesktop.org, kernel@collabora.com References: <20251126124455.3656651-1-boris.brezillon@collabora.com> <20251126124455.3656651-2-boris.brezillon@collabora.com> <2e789ff6-b79f-4577-bc69-f74dfed6acfa@suse.de> Content-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3JNsheAAK+Xc9baj0LGIc8T9uiEWHBnCH+RdhgATnWW GKdDegUR5BkDfDg5O/FISymJBHx2Dyoklv5g4BzkgqTqwmaYzsl8UxZKvbaxq0zbehDda8lv hFXodNFMAgTLJlLuDYOGLK2AwbrS3Sp0AEbkpdJBb44qVlGm5bApZouHeJ/+n+7r12+lqdsA EQEAAcLAdgQYAQgAIAIbDBYhBHIX+6yM6c9jRKFo5WgNwR1TC3ojBQJftOH6AAoJEGgNwR1T C3ojVSkIALpAPkIJPQoURPb1VWjh34l0HlglmYHvZszJWTXYwavHR8+k6Baa6H7ufXNQtThR yIxJrQLW6rV5lm7TjhffEhxVCn37+cg0zZ3j7zIsSS0rx/aMwi6VhFJA5hfn3T0TtrijKP4A SAQO9xD1Zk9/61JWk8OysuIh7MXkl0fxbRKWE93XeQBhIJHQfnc+YBLprdnxR446Sh8Wn/2D Ya8cavuWf2zrB6cZurs048xe0UbSW5AOSo4V9M0jzYI4nZqTmPxYyXbm30Kvmz0rYVRaitYJ 4kyYYMhuULvrJDMjZRvaNe52tkKAvMevcGdt38H4KSVXAylqyQOW5zvPc4/sq9c= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; RCPT_COUNT_TWELVE(0.00)[27]; TAGGED_RCPT(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; R_RATELIMIT(0.00)[to_ip_from(RLq3cifbxyhc6qbbynzfc6amns)]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[lists.freedesktop.org,linux.intel.com,kernel.org,gmail.com,ffwll.ch,collabora.com,nvidia.com,igalia.com,intel.com,imgtec.com,oss.qualcomm.com,linux.dev,poorly.run,somainline.org,amd.com]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid, suse.com:url, imap1.dmz-prg2.suse.org:helo] X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" Hi Am 27.11.25 um 09:42 schrieb Thomas Zimmermann: > Hi > > Am 27.11.25 um 09:34 schrieb Thomas Zimmermann: >> Hi >> >> Am 26.11.25 um 13:44 schrieb Boris Brezillon: >>> drm_gem_is_prime_exported_dma_buf() checks the dma_buf->ops against >>> drm_gem_prime_dmabuf_ops, which makes it impossible to use if the >>> driver implements custom dma_buf_ops. Instead of duplicating a bunch >>> of helpers to work around it, let's provide a way for drivers to >>> expose their custom dma_buf_ops so the core prime helpers can rely on >>> that instead of hardcoding &drm_gem_prime_dmabuf_ops. >> >> This can't go in as-is. I've spent an awful amount of patches on >> removing buffer callbacks from struct drm_driver. Let's please not go >> back to that. >> >>> >>> v5: >>> - New patch >>> >>> v6: >>> - Pass custom dma_buf_ops directly instead of through a getter >>> >>> Signed-off-by: Boris Brezillon >>> --- >>>   drivers/gpu/drm/drm_prime.c | 10 ++++++++-- >>>   include/drm/drm_drv.h       |  8 ++++++++ >>>   2 files changed, 16 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c >>> index 21809a82187b..86fd95f0c105 100644 >>> --- a/drivers/gpu/drm/drm_prime.c >>> +++ b/drivers/gpu/drm/drm_prime.c >>> @@ -904,6 +904,12 @@ unsigned long >>> drm_prime_get_contiguous_size(struct sg_table *sgt) >>>   } >>>   EXPORT_SYMBOL(drm_prime_get_contiguous_size); >>>   +static const struct dma_buf_ops * >>> +drm_gem_prime_get_dma_buf_ops(struct drm_device *dev) >>> +{ >>> +    return dev->driver->dma_buf_ops ?: &drm_gem_prime_dmabuf_ops; >>> +} >>> + >>>   /** >>>    * drm_gem_prime_export - helper library implementation of the >>> export callback >>>    * @obj: GEM object to export >>> @@ -920,7 +926,7 @@ struct dma_buf *drm_gem_prime_export(struct >>> drm_gem_object *obj, >>>       struct dma_buf_export_info exp_info = { >>>           .exp_name = KBUILD_MODNAME, /* white lie for debug */ >>>           .owner = dev->driver->fops->owner, >>> -        .ops = &drm_gem_prime_dmabuf_ops, >>> +        .ops = drm_gem_prime_get_dma_buf_ops(dev), >> >> Rather provide a new function drm_gem_prime_export_with_ops() that >> takes an additional dma_ops instance. The current >> drm_gem_prime_export() would call it with &drm_gem_prime_dmabuf_ops. >> >> If this really does not work, you could add a pointer to dma_buf_ops >> to drm_gem_object_funcs and fetch that from drm_gem_prime_export(). >> We already vm_ops there. >> >> Other drivers, such as amdgpu, would also benefit from such a change >> >>>           .size = obj->size, >>>           .flags = flags, >>>           .priv = obj, >>> @@ -947,7 +953,7 @@ bool drm_gem_is_prime_exported_dma_buf(struct >>> drm_device *dev, >>>   { >>>       struct drm_gem_object *obj = dma_buf->priv; >>>   -    return (dma_buf->ops == &drm_gem_prime_dmabuf_ops) && >>> (obj->dev == dev); >>> +    return dma_buf->ops == drm_gem_prime_get_dma_buf_ops(dev) && >>> obj->dev == dev; > > On a second thought, we probably cannot be sure that dma_buf->priv > really is a GEM object until we tested the ops field. :/  IIRC that's > why the ops test goes first and the test for obj->dev goes second. So > neither solution works. I think, instead of looking at the ops field, the test could look at dma_buf->owner == dev->driver->fops->owner.  This will tell if the dma_buf comes from the same driver and hence is a GEM object. In the next step, do obj->dev == dev as before.  This will also allow drivers like amdgpu to use the helper for testing. See [1]. [1] https://elixir.bootlin.com/linux/v6.17.9/source/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c#L512 Best regards Thomas > > Best regards > Thomas > >> >> This is a bit more complicated and the test has been a pain point >> before. For this case, I think we should add a GEM callback for this >> >> struct drm_gem_object_funcs { >>     bool (*exported_by)(struct drm_gem_object *obj, struct drm_device >> *dev) >> } >> >> next to the existing export callback. >> >> And drm_gem_is_prime_exported_dma_buf would then do >> >> { >>     if (obj->funcs->exported_by) >>        return obj->funcs-> >>    return /* what we currently test */ >> } >> >> IIRC amdgpu would again benefit from this. >> >> These changes will isolate dma_buf handling near GEM code, keep >> drm_driver clean, and even allow for a driver to have different >> implementations of dma_buf_ops. >> >> Best regards >> Thomas >> >>>   } >>>   EXPORT_SYMBOL(drm_gem_is_prime_exported_dma_buf); >>>   diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h >>> index 42fc085f986d..1c6dae60d523 100644 >>> --- a/include/drm/drm_drv.h >>> +++ b/include/drm/drm_drv.h >>> @@ -431,6 +431,14 @@ struct drm_driver { >>>        * some examples. >>>        */ >>>       const struct file_operations *fops; >>> + >>> +    /** >>> +     * @dma_buf_ops: >>> +     * >>> +     * dma_buf_ops to use for buffers exported by this driver. When >>> NULL, >>> +     * the drm_prime logic defaults to &drm_gem_prime_dmabuf_ops. >>> +     */ >>> +    const struct dma_buf_ops *dma_buf_ops; >>>   }; >>>     void *__devm_drm_dev_alloc(struct device *parent, >> > -- -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)