From: Jason Gunthorpe <jgg@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Zeng Tao <prime.zeng@hisilicon.com>,
linuxarm@huawei.com, Cornelia Huck <cohuck@redhat.com>,
Kevin Tian <kevin.tian@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Xu <peterx@redhat.com>,
Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
Michel Lespinasse <walken@google.com>,
Jann Horn <jannh@google.com>, Max Gurtovoy <mgurtovoy@nvidia.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfio/pci: make the vfio_pci_mmap_fault reentrant
Date: Mon, 8 Mar 2021 19:43:53 -0400 [thread overview]
Message-ID: <20210308234353.GB4247@nvidia.com> (raw)
In-Reply-To: <20210308132106.49da42e2@omen.home.shazbot.org>
On Mon, Mar 08, 2021 at 01:21:06PM -0700, Alex Williamson wrote:
> > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> > index 65e7e6b..6928c37 100644
> > +++ b/drivers/vfio/pci/vfio_pci.c
> > @@ -1613,6 +1613,7 @@ 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 pfn;
> >
> > mutex_lock(&vdev->vma_lock);
> > down_read(&vdev->memory_lock);
> > @@ -1623,18 +1624,23 @@ static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf)
> > goto up_out;
> > }
> >
> > - if (__vfio_pci_add_vma(vdev, vma)) {
> > - ret = VM_FAULT_OOM;
> > + if (!follow_pfn(vma, vma->vm_start, &pfn)) {
> > mutex_unlock(&vdev->vma_lock);
> > goto up_out;
Gah, no new follow_pfn users please we are trying to delete this
stuff..
I believe the right fix is to change the fault handler to use
vmf_insert_pfn_prot() which has all the right locking/etc
The
> I'm surprised that it's left to the fault handler to provide this
> serialization, is this because we're filling the entire vma rather than
> only the faulting page?
I think it is because remap_pfn is not intended to be called from a
fault handler. The fault handler APIs seem to be named vmf_* ..
If you want to use remap API it has to be done and managed outside the
fault handler. Ie when the MMIO transitions from valid->invalid vfio-pci
wipes the address space, when it transitions from invalid->valid it
calls remap_pfn. vfio-pci provides its own locking to protect these
state transitions. fault simply always triggers sigbus
I recall we discussed this design when you made the original patches
but I don't completely recall why it ended this way, however I think
the reason might disappear after the address_space conversion in your
other series.
Jason
prev parent reply other threads:[~2021-03-08 23:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-08 11:11 [PATCH] vfio/pci: make the vfio_pci_mmap_fault reentrant Zeng Tao
2021-03-08 20:21 ` Alex Williamson
2021-03-08 22:56 ` Peter Xu
2021-03-09 3:49 ` 答复: " Zengtao (B)
2021-03-09 12:46 ` Jason Gunthorpe
2021-03-09 15:29 ` Alex Williamson
2021-03-09 16:40 ` Jason Gunthorpe
2021-03-09 18:47 ` Peter Xu
2021-03-09 19:26 ` Alex Williamson
2021-03-09 19:48 ` Peter Xu
2021-03-09 20:11 ` Alex Williamson
2021-03-09 21:00 ` Peter Xu
2021-03-09 21:43 ` Alex Williamson
2021-03-09 19:56 ` Alex Williamson
2021-03-09 23:45 ` Jason Gunthorpe
2021-03-10 6:23 ` Alex Williamson
2021-03-09 23:41 ` Jason Gunthorpe
2021-03-10 6:08 ` Alex Williamson
2021-03-11 3:32 ` 答复: " Zengtao (B)
2021-03-08 23:43 ` Jason Gunthorpe [this message]
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=20210308234353.GB4247@nvidia.com \
--to=jgg@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=giovanni.cabiddu@intel.com \
--cc=jannh@google.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mgurtovoy@nvidia.com \
--cc=peterx@redhat.com \
--cc=prime.zeng@hisilicon.com \
--cc=walken@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.