Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] accel/thames: unzapped partial PFN mapping on error in thames_gem_shmem_mmap() --
commit 4ae1719a36f423f47f5340a069ad63c6b97c835f Author: Tomeu Vizoso <[email protected]> accel/thames: Install memory mappings populated and dirty This commit replaces drm_gem_shmem_object_mmap() with a custom mmap handler that populates page-backed buffers upfront using remap_pfn_range() with dirty and writable PTEs. > diff --git a/drivers/accel/thames/thames_gem.c > b/drivers/accel/thames/thames_gem.c > index 3c2846bb5297d..930444a732e78 100644 > --- a/drivers/accel/thames/thames_gem.c > +++ b/drivers/accel/thames/thames_gem.c > @@ -834,6 +834,50 @@ static void thames_gem_shmem_bo_free(struct > drm_gem_object *obj) > drm_gem_shmem_free(&bo->shmem); > } > > +/* > + * Every page installed now, dirty and writable: they are pinned for the > + * object's life, and the helper would take two faults on each. > + */ > +static int thames_gem_shmem_mmap(struct drm_gem_object *obj, struct > vm_area_struct *vma) > +{ > + struct thames_gem_object *bo = to_thames_bo(obj); > + unsigned long addr = vma->vm_start; > + struct scatterlist *sg; > + pgprot_t prot; > + unsigned int i; > + int ret; > + > + if (vma_is_cow_mapping(vma)) > + return -EINVAL; > + > + vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); > + > + prot = vm_get_page_prot(vma->vm_flags); > + if (vma->vm_flags & VM_WRITE) > + prot = pte_pgprot(pte_mkdirty(pte_mkwrite_novma(pfn_pte(0, > prot)))); > + vma->vm_page_prot = prot; > + > + for_each_sgtable_sg(bo->shmem.sgt, sg, i) { > + unsigned long len = min_t(unsigned long, sg->length, > vma->vm_end - addr); > + > + ret = remap_pfn_range(vma, addr, page_to_pfn(sg_page(sg)), len, > prot); > + if (ret) > + return ret; [Severity: Medium] If remap_pfn_range() fails after earlier scatterlist segments have already been mapped, does returning without zapping [vma->vm_start, addr) leave stale writable PTEs live while the GEM object is freed? remap_pfn_range_notrack() only zaps the single [addr, addr + len) range that failed, and VM_PFNMAP mappings do not hold page references. On error, drm_gem_mmap_obj() and drm_gem_mmap() drop their references to obj before __mmap_new_file_vma() calls unmap_region(). If another thread has closed the GEM handle concurrently, drm_gem_object_put() frees the backing shmem pages while other threads sharing vma->vm_mm can still write to [vma->vm_start, addr). Calling zap_vma_ptes(vma, vma->vm_start, addr - vma->vm_start) before returning on error would avoid this. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=11
