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 09DB3CCF9E3 for ; Tue, 4 Nov 2025 07:42:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A23EF10E53B; Tue, 4 Nov 2025 07:42:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="kdsRpZgL"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id B4B6610E53A; Tue, 4 Nov 2025 07:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1762242152; bh=Y3sxHbgdsw/zK5KujxmAhyHTOwoUJceuYijGgqI1be0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kdsRpZgLocXboI8/Ies+ryE2Rytn1iYmrFeJRdco+U/6MnmlxUUbPTnFoVT6q68ol VIf9sCMqYD6yQZEQT+l2vtSVR/a5hO5KTilgxNRbDuUiOClTC0PEp5gJjIlxpXRA/a gF3TWkMw1sbNRG3hjJXAQnoI6fkUGB3hBP8BB4YWIXeWup2OXYSAr6iFYOa6vn3mOg SMjIyQHE/TqfR4q9Hb0TZqNQuUbGSZ9TNfR9HBKjZb4mMyC+b+KpUHQHREZOTl45x2 SbwUfPi8xOCg6wV6JJQnzR3zckDiBNK5n9XjJB5EG6QWecl+l2uxZ66w+usZL1DGGH w/o9uyoR0ay5Q== Received: from fedora (unknown [IPv6:2a01:e0a:2c:6930:d919:a6e:5ea1:8a9f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id 675CA17E0927; Tue, 4 Nov 2025 08:42:31 +0100 (CET) Date: Tue, 4 Nov 2025 08:42:27 +0100 From: Boris Brezillon To: Akash Goel Cc: Steven Price , dri-devel@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Faith Ekstrand , Thierry Reding , Mikko Perttunen , Melissa Wen , =?UTF-8?B?TWHDrXJh?= Canal , Lucas De Marchi , Thomas =?UTF-8?B?SGVsbHN0csO2bQ==?= , Rodrigo Vivi , Frank Binns , Matt Coster , Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , Alex Deucher , Christian =?UTF-8?B?S8O2bmln?= , amd-gfx@lists.freedesktop.org, kernel@collabora.com Subject: Re: [PATCH v5 02/16] drm/shmem: Provide a generic {begin, end}_cpu_access() implementation Message-ID: <20251104084227.0c078eb8@fedora> In-Reply-To: <662c54eb-1ecb-4383-9405-a2d200a0bea6@arm.com> References: <20251030140525.366636-1-boris.brezillon@collabora.com> <20251030140525.366636-3-boris.brezillon@collabora.com> <662c54eb-1ecb-4383-9405-a2d200a0bea6@arm.com> Organization: Collabora X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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" On Mon, 3 Nov 2025 20:34:39 +0000 Akash Goel wrote: > On 10/30/25 14:05, Boris Brezillon wrote: > > The default implementation simply takes care of invalidating/flushing > > caches around CPU accesses. It takes care of both the exporter and > > the importers, which forces us to overload the default > > ::[un]map_dma_buf() implementation provided by drm_gem.c to store the > > sgt. > > > > v5: > > - New patch > > > > Signed-off-by: Boris Brezillon > > --- > > drivers/gpu/drm/drm_gem_shmem_helper.c | 114 +++++++++++++++++++++++++ > > include/drm/drm_gem_shmem_helper.h | 10 +++ > > 2 files changed, 124 insertions(+) > > > > diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c > > index dc94a27710e5..e49c75739c20 100644 > > --- a/drivers/gpu/drm/drm_gem_shmem_helper.c > > +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c > > @@ -893,6 +893,120 @@ struct drm_gem_object *drm_gem_shmem_prime_import_no_map(struct drm_device *dev, > > } > > EXPORT_SYMBOL_GPL(drm_gem_shmem_prime_import_no_map); > > > > +/** > > + * drm_gem_shmem_prime_unmap_dma_buf - Default unmap_dma_buf() for exported buffers > > + * @attach: attachment > > + * @sgt: SG table to unmap > > + * @dir: type of access done by this attachment > > + * > > + * Default implementation for dma_buf_ops::map_dma_buf(). This is just a wrapper > > + * around drm_gem_map_dma_buf() that lets us set the dma_buf_attachment::priv > > + * to the sgt so that drm_gem_shmem_prime_{begin,end}_cpu_access() can sync > > + * around CPU accesses. > > + */ > > +struct sg_table * > > +drm_gem_shmem_prime_map_dma_buf(struct dma_buf_attachment *attach, > > + enum dma_data_direction dir) > > +{ > > + struct sg_table *sgt = drm_gem_map_dma_buf(attach, dir); > > + > > + if (!IS_ERR(sgt)) > > + attach->priv = sgt; > > + > > + return sgt; > > +} > > +EXPORT_SYMBOL_GPL(drm_gem_shmem_prime_map_dma_buf); > > + > > +/** > > + * drm_gem_shmem_prime_unmap_dma_buf - Default unmap_dma_buf() for exported buffers > > + * @attach: attachment > > + * @sgt: SG table to unmap > > + * @dir: type of access done by this attachment > > + * > > + * Default implementation for dma_buf_ops::unmap_dma_buf(). This is just a wrapper > > + * around drm_gem_unmap_dma_buf() that lets us reset the dma_buf_attachment::priv > > + * field so that drm_gem_shmem_prime_{begin,end}_cpu_access() don't consider it > > + * as a mapped attachment to sync against. > > + */ > > +void drm_gem_shmem_prime_unmap_dma_buf(struct dma_buf_attachment *attach, > > + struct sg_table *sgt, > > + enum dma_data_direction dir) > > +{ > > + attach->priv = NULL; > > + drm_gem_unmap_dma_buf(attach, sgt, dir); > > +} > > +EXPORT_SYMBOL_GPL(drm_gem_shmem_prime_unmap_dma_buf); > > + > > +/** > > + * drm_gem_shmem_prime_begin_cpu_access - Default end_cpu_access() for exported buffers > > > Sorry nitpick. There is a typo here. Should be 'Default begin_cpu_access()`. Nice catch. Will fix in v6.