From: Alex Williamson <alex.williamson@redhat.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
peterx@redhat.com, prime.zeng@hisilicon.com, cohuck@redhat.com
Subject: Re: [PATCH] vfio/pci: Handle concurrent vma faults
Date: Wed, 10 Mar 2021 11:34:06 -0700 [thread overview]
Message-ID: <20210310113406.6f029fcf@omen.home.shazbot.org> (raw)
In-Reply-To: <20210310181446.GZ2356281@nvidia.com>
On Wed, 10 Mar 2021 14:14:46 -0400
Jason Gunthorpe <jgg@nvidia.com> wrote:
> On Wed, Mar 10, 2021 at 10:53:29AM -0700, Alex Williamson wrote:
>
> > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> > index 65e7e6b44578..ae723808e08b 100644
> > +++ b/drivers/vfio/pci/vfio_pci.c
> > @@ -1573,6 +1573,11 @@ static int __vfio_pci_add_vma(struct vfio_pci_device *vdev,
> > {
> > struct vfio_pci_mmap_vma *mmap_vma;
> >
> > + list_for_each_entry(mmap_vma, &vdev->vma_list, vma_next) {
> > + if (mmap_vma->vma == vma)
> > + return 0; /* Swallow the error, the vma is tracked */
> > + }
> > +
> > mmap_vma = kmalloc(sizeof(*mmap_vma), GFP_KERNEL);
> > if (!mmap_vma)
> > return -ENOMEM;
> > @@ -1612,31 +1617,32 @@ static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf)
> > {
> > struct vm_area_struct *vma = vmf->vma;
> > struct vfio_pci_device *vdev = vma->vm_private_data;
> > - vm_fault_t ret = VM_FAULT_NOPAGE;
> > + unsigned long vaddr = vma->vm_start, pfn = vma->vm_pgoff;
> > + vm_fault_t ret = VM_FAULT_SIGBUS;
> >
> > mutex_lock(&vdev->vma_lock);
> > down_read(&vdev->memory_lock);
> >
> > - if (!__vfio_pci_memory_enabled(vdev)) {
> > - ret = VM_FAULT_SIGBUS;
> > - mutex_unlock(&vdev->vma_lock);
> > + if (!__vfio_pci_memory_enabled(vdev))
> > goto up_out;
> > +
> > + for (; vaddr < vma->vm_end; vaddr += PAGE_SIZE, pfn++) {
> > + ret = vmf_insert_pfn_prot(vma, vaddr, pfn,
> > + pgprot_decrypted(vma->vm_page_prot));
>
> I investigated this, I think the above pgprot_decrypted() should be
> moved here:
>
> static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)
> {
> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> + vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
>
>
> And since:
>
> vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, unsigned long addr,
> unsigned long pfn)
> {
> return vmf_insert_pfn_prot(vma, addr, pfn, vma->vm_page_prot);
>
> The above can just use vfm_insert_pfn()
Cool, easy enough. Thanks for looking.
> The only thing that makes me nervous about this arrangment is loosing
> the track_pfn_remap() which was in remap_pfn_range() - I think it
> means we miss out on certain PAT manipulations.. I *suspect* this is
> not a problem for VFIO because it will rely on the MTRRs generally on
> x86 - but I also don't know this mechanim too well.
Yeah, for VM use cases the MTRRs generally override.
> I think after the address_space changes this should try to stick with
> a normal io_rmap_pfn_range() done outside the fault handler.
I assume you're suggesting calling io_remap_pfn_range() when device
memory is enabled, do you mean using vma_interval_tree_foreach() like
unmap_mapping_range() does to avoid re-adding a vma list? Thanks,
Alex
next prev parent reply other threads:[~2021-03-10 18:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-10 17:53 Alex Williamson
2021-03-10 18:14 ` Jason Gunthorpe
2021-03-10 18:34 ` Alex Williamson [this message]
2021-03-10 18:40 ` Jason Gunthorpe
2021-03-10 20:06 ` Peter Xu
2021-03-11 11:35 ` Christoph Hellwig
2021-03-11 16:35 ` Peter Xu
2021-03-12 19:16 ` Alex Williamson
2021-03-12 19:41 ` Jason Gunthorpe
2021-03-12 20:09 ` Alex Williamson
2021-03-12 20:58 ` Alex Williamson
2021-03-13 0:03 ` Jason Gunthorpe
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=20210310113406.6f029fcf@omen.home.shazbot.org \
--to=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=jgg@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=prime.zeng@hisilicon.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
all inboxes | Powered by JetHome®