Linux IOMMU Development
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Steven Sistare <steven.sistare@oracle.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>, iommu@lists.linux.dev
Subject: Re: mapping files for iommufd
Date: Mon, 12 Aug 2024 15:05:16 -0600	[thread overview]
Message-ID: <20240812150516.3e33c5c2.alex.williamson@redhat.com> (raw)
In-Reply-To: <684a3618-ee15-4f85-ab44-3de0527f91fa@oracle.com>

On Mon, 12 Aug 2024 14:56:03 -0400
Steven Sistare <steven.sistare@oracle.com> wrote:

> On 8/12/2024 2:40 PM, Jason Gunthorpe wrote:
> > On Mon, Aug 12, 2024 at 02:09:11PM -0400, Steven Sistare wrote:  
> >> I have been using QEMU to test legacy vfio vs iommufd compatibility vfio.
> >> I find that backing guest memory with an ext4 file /root/guest.ram
> >> succeeds for legacy but fails for iommufd, with EFAULT in
> >> IOMMU_IOAS_MAP -> ... __get_user_pages -> check_vma_flags.  Ditto for a
> >> hugetlbfs file.  This is with unmodified kernels, no live update changes.
> >>
> >> Is this expected?  
> > 
> > Yes - I'm surprised that VFIO is not failing though?
> > 
> > /*
> >   * Writing to file-backed mappings which require folio dirty tracking using GUP
> >   * is a fundamentally broken operation, as kernel write access to GUP mappings
> >   * do not adhere to the semantics expected by a file system.
> >   *
> >   * Consider the following scenario:-
> >   *
> >   * 1. A folio is written to via GUP which write-faults the memory, notifying
> >   *    the file system and dirtying the folio.
> >   * 2. Later, writeback is triggered, resulting in the folio being cleaned and
> >   *    the PTE being marked read-only.
> >   * 3. The GUP caller writes to the folio, as it is mapped read/write via the
> >   *    direct mapping.
> >   * 4. The GUP caller, now done with the page, unpins it and sets it dirty
> >   *    (though it does not have to).
> >   *
> >   * This results in both data being written to a folio without writenotify, and
> >   * the folio being dirtied unexpectedly (if the caller decides to do so).
> >   */
> > static bool writable_file_mapping_allowed(struct vm_area_struct *vma,
> > 					  unsigned long gup_flags)
> > {
> > 
> > Why doesn't that fail in the VFIO case? I didn't notice anything
> > special there that would make it work???  
> 
> vfio_dma_do_map -> vfio_pin_map_dma -> vfio_pin_pages_remote does not call GUP,
> it just grabs a reference to each page.

Can you be more specific, because...

vfio_pin_pages_remote
  vaddr_get_pfns
    pin_user_pages_remote
      __gup_longterm_locked
        __get_user_pages_locked
          __get_user_pages

Thanks,
Alex


  reply	other threads:[~2024-08-12 21:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-12 18:09 mapping files for iommufd Steven Sistare
2024-08-12 18:40 ` Jason Gunthorpe
2024-08-12 18:56   ` Steven Sistare
2024-08-12 21:05     ` Alex Williamson [this message]
2024-08-13 14:23       ` Steven Sistare
2024-08-13 14:36         ` Jason Gunthorpe
2024-08-13 15:13           ` Steven Sistare

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=20240812150516.3e33c5c2.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=steven.sistare@oracle.com \
    /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