Re: [PATCH] drm/imagination: drop redundant zeroing of new GEM objects

From: Guillaume La Roque

Date: Mon Nov 23 2026 - 08:57:11 EST


Hi Gyeyoung,

thanks for the review.

Le 22/11/2026 à 08:55, Gyeyoung Baek a écrit :
Hi Guillaume,

On Wed, Nov 11, 2026 at 6:43 PM Guillaume La Roque
<glaroque@xxxxxxxxxxxx> wrote:
pvr_gem_object_create() clears every new object through a CPU mapping
so that userspace never sees data left by a previous owner of the
pages [1]. shmem already guarantees that: it clears each page it
allocates, and the dma_sync_sgtable_for_device() call that follows
makes those zeroes visible to the GPU. The second pass, write-combined
on non-coherent devices, only adds latency.
I'm not very familiar with shmem, so I'd like to ask: is this zeroing
something shmem guarantees, or just a current implementation detail?
From what I see in the code, it is guaranteed by shmem, not just an
implementation detail. The zeroing is done in shmem_get_folio_gfp():

          if (sgp != SGP_WRITE && !folio_test_uptodate(folio)) {
                  long i, n = folio_nr_pages(folio);

                  for (i = 0; i < n; i++)
                          clear_highpage(folio_page(folio, i));
                  flush_dcache_folio(folio);
                  folio_mark_uptodate(folio);
          }

pvr objects get their pages through drm_gem_shmem_get_pages_sgt() ->
drm_gem_get_pages() -> shmem_read_folio_gfp(), which uses SGP_CACHE.
Each object is a new shmem file, so all its folios are newly allocated
and not uptodate, and they are always cleared here.

panfrost and panthor already rely on this too, they never clear new
objects. There is even a comment about it in should_map_wc() in both
drivers:

    /* We can't do uncached mappings if the device is coherent,
    * because the zeroing done by the shmem layer at page allocation
    * time happens on a cached mapping which isn't CPU-flushed ...

For pvr there is no problem with that: coherent devices always get
PVR_BO_CPU_CACHED, and on non-coherent ones the zeroes are flushed by
dma_map_sgtable() and by the dma_sync_sgtable_for_device() already done
in pvr_gem_object_create().

Since the driver would now rely on it, could you spell out in the
commit message where the zeroing happens and why it can be relied on?

i will add these detail in commit message in v2 if it look ok for you.

Regards
Guillaume