[PATCH RFT 0/3] mm, drm: ensure .fault() does not have to be followed by .pfn_mkwrite() for write faults

From: Paolo Bonzini

Date: Fri Jul 31 2026 - 13:26:53 EST


Warning - DRM parts (i.e. most of the patches) untested; I have Cc'd
the reporter to help with testing these patches.

Right now, users of .pfn_mkwrite() have no way to create a PTE
that has gone through maybe_mkwrite(). Because vma_set_page_prot()
will have cleared the writable PTE bit, users of fixup_user_fault()
will see a read-only PTE and have no clue that the page needs
a *second* fault to reach its final status.

Handling this in fixup_user_fault() is problematic: the information
about the presence of *_mkwrite is only recorded in vma->vm_page_prot,
which is an opaque pgprot_t, therefore only follow_pfnmap_start()
knows how to retrieve it.

There are actually some preexisting functions that suggest how
this is supposed to be handled, namely vmf_insert_page_mkwrite() and
vmf_insert_pfn_pmd(). So, this series adjusts mm/memory.c to export
two new functions vmf_insert_pfn_mkwrite() and __vmf_insert_pfn_prot(),
and then teaches drm's two users of .pfn_mkwrite() to call them. Let
me know if I should use another name like vmf_insert_pfn_prot_mkwrite(),
instead of the "__"-prefixed one.

The drm_gem_shmem_helper case was reported as a KVM regression, while
the vmwgfx one was found by inspection of .pfn_mkwrite() implementors.

Thanks,

Paolo

Paolo Bonzini (3):
mm: export variants of vmf_insert_pfn* for use with pfn_mkwrite()
drm/shmem_helper: use vmf_insert_pfn_mkwrite()
drm/ttm, drm/vmwgfx: directly create writable PTEs when mkwrite is
in use

drivers/gpu/drm/drm_gem_shmem_helper.c | 38 +++++------
drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 +-
drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c | 44 +++++++------
include/linux/mm.h | 4 ++
mm/huge_memory.c | 2 +-
mm/memory.c | 75 ++++++++++++++++------
6 files changed, 107 insertions(+), 59 deletions(-)

--
2.55.0