[Devel] [PATCH hci-8.1 5/5] mm: allow MADV_DOEXEC on a VFIO mapping not faulted in yet
Andrey Drobyshev
andrey.drobyshev at virtuozzo.com
Fri Oct 23 19:53:43 MSK 2026
The NVIDIA vGPU mdev driver doesn't map BAR1 in its mmap(): it only
installs a ->fault() handler, which sets VM_PFNMAP on the first access
by the guest. Until the guest touches BAR1, e.g. right after the VM
starts or with no guest driver loaded, the mapping is a shared file
mapping without VM_PFNMAP, so MADV_DOEXEC refuses it with -EINVAL and
qemu-update of the VM fails.
Don't test VM_PFNMAP, take any shared mapping of a file. MADV_DOEXEC
still admits only VFIO files. vma_dup() handles such a mapping like a
faulted-in one: there are no PTEs to copy yet, and the first access in
the new process goes to the driver's ->fault() handler as usual.
https://virtuozzo.atlassian.net/browse/VSTOR-150595
Fixes: 95e14696fa3f ("mm: allow MADV_DOEXEC on shared PFN mappings of device memory")
Feature: oracle/mm: MADV_DOEXEC madvise() flag
Assisted-by: LLM
Signed-off-by: Andrey Drobyshev <andrey.drobyshev at virtuozzo.com>
---
include/linux/mm.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 496cbdfc7141..9addd5ce2ea5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1020,12 +1020,12 @@ static inline bool vma_is_anonymous(struct vm_area_struct *vma)
/*
* Shared PFN mapping of a file, such as a device BAR mapped through VFIO.
+ * A driver may set VM_PFNMAP only on the first fault, so don't test it.
* Its vm_ops may be NULL, so it must be tested before vma_is_anonymous().
*/
static inline bool vma_is_shared_pfnmap(struct vm_area_struct *vma)
{
- return vma->vm_file &&
- (vma->vm_flags & (VM_SHARED | VM_PFNMAP)) == (VM_SHARED | VM_PFNMAP);
+ return vma->vm_file && (vma->vm_flags & VM_SHARED);
}
/*
--
2.47.1
More information about the Devel
mailing list