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 E0726CCF9E3 for ; Mon, 10 Nov 2025 09:34:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3DCF610E2BF; Mon, 10 Nov 2025 09:34:07 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E8CE10E2BF for ; Mon, 10 Nov 2025 09:34:06 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4A4742B; Mon, 10 Nov 2025 01:33:58 -0800 (PST) Received: from [10.57.72.117] (unknown [10.57.72.117]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C5E8B3F63F; Mon, 10 Nov 2025 01:34:04 -0800 (PST) Message-ID: <1c84e306-7e60-4f3e-b2b1-4ee2c2dc37fb@arm.com> Date: Mon, 10 Nov 2025 09:34:02 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/panthor: Flush shmem writes before mapping buffers CPU-uncached To: Boris Brezillon , Liviu Dudau , =?UTF-8?Q?Adri=C3=A1n_Larumbe?= Cc: dri-devel@lists.freedesktop.org, kernel@collabora.com References: <20251107171214.1186299-1-boris.brezillon@collabora.com> From: Steven Price Content-Language: en-GB In-Reply-To: <20251107171214.1186299-1-boris.brezillon@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 07/11/2025 17:12, Boris Brezillon wrote: > The shmem layer zeroes out the new pages using cached mappings, and if > we don't CPU-flush we might leave dirty cachelines behind, leading to > potential data leaks and/or asynchronous buffer corruption when dirty > cachelines are evicted. > > Fixes: 8a1cc07578bf ("drm/panthor: Add GEM logical block") > Signed-off-by: Boris Brezillon Reviewed-by: Steven Price > --- > drivers/gpu/drm/panthor/panthor_gem.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c > index f369cc3e2a5f..2c12c1c58e2b 100644 > --- a/drivers/gpu/drm/panthor/panthor_gem.c > +++ b/drivers/gpu/drm/panthor/panthor_gem.c > @@ -281,6 +281,23 @@ panthor_gem_create_with_handle(struct drm_file *file, > > panthor_gem_debugfs_set_usage_flags(bo, 0); > > + /* If this is a write-combine mapping, we query the sgt to force a CPU > + * cache flush (dma_map_sgtable() is called when the sgt is created). > + * This ensures the zero-ing is visible to any uncached mapping created > + * by vmap/mmap. > + * FIXME: Ideally this should be done when pages are allocated, not at > + * BO creation time. > + */ > + if (shmem->map_wc) { > + struct sg_table *sgt; > + > + sgt = drm_gem_shmem_get_pages_sgt(shmem); > + if (IS_ERR(sgt)) { > + ret = PTR_ERR(sgt); > + goto out_put_gem; > + } > + } > + > /* > * Allocate an id of idr table where the obj is registered > * and handle has the id what user can see. > @@ -289,6 +306,7 @@ panthor_gem_create_with_handle(struct drm_file *file, > if (!ret) > *size = bo->base.base.size; > > +out_put_gem: > /* drop reference from allocate - handle holds it now. */ > drm_gem_object_put(&shmem->base); >