Re: [PATCH 12/16] mm: update resctl to use mmap_prepare, mmap_complete, mmap_abort

Jason Gunthorpe
2025-09-08T13:24:53Z

On Mon, Sep 08, 2025 at 12:10:43PM +0100, Lorenzo Stoakes wrote:
> resctl uses remap_pfn_range(), but holds a mutex over the
> operation. Therefore, establish the mutex in mmap_prepare(), release it in
> mmap_complete() and release it in mmap_abort() should the operation fail.

The mutex can't do anything relative to remap_pfn, no reason to hold it.

> @@ -1053,15 +1087,11 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)
> return -ENOSPC;
> }
>
> - memset(plr->kmem + off, 0, vsize);
> + /* No CoW allowed so don't need to specify pfn. */
> + remap_pfn_range_prepare(desc, 0);

This would be a good place to make a more generic helper..

ret = remap_pfn_no_cow(desc, phys);

And it can consistently check for !shared internally.

Store phys in the desc and use common code to trigger the PTE population
during complete.

Jason