OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 5/5] mm: allow MADV_DOEXEC on a VFIO mapping not faulted in yet
Date: Fri, 23 Oct 2026 19:53:43 +0300	[thread overview]
Message-ID: <20261023165343.503945-6-andrey.drobyshev@virtuozzo.com> (raw)
In-Reply-To: <20261023165343.503945-1-andrey.drobyshev@virtuozzo.com>

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@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

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-10-23 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 16:53 [Devel] [PATCH hci-8.1 0/5] Support VM migration with mdev vGPUs Andrey Drobyshev
2026-10-23 16:53 ` [Devel] [PATCH hci-8.1 1/5] Revert "vfio: revert "iommu driver notify callback"" Andrey Drobyshev
2026-10-23 16:53 ` [Devel] [PATCH hci-8.1 2/5] Revert "vfio/type1: revert "implement " Andrey Drobyshev
2026-10-23 16:53 ` [Devel] [PATCH hci-8.1 3/5] Revert "vfio/type1: revert "block on invalid vaddr"" Andrey Drobyshev
2026-10-23 16:53 ` [Devel] [PATCH hci-8.1 4/5] Revert "vfio/type1: exclude mdevs from VFIO_UPDATE_VADDR" Andrey Drobyshev
2026-10-23 16:53 ` Andrey Drobyshev [this message]
2026-10-27 15:48 ` [Devel] [PATCH hci-8.1 0/5] Support VM migration with mdev vGPUs Andrey Drobyshev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261023165343.503945-6-andrey.drobyshev@virtuozzo.com \
    --to=andrey.drobyshev@virtuozzo.com \
    --cc=devel@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox