From: Alex Williamson <alex.williamson@redhat.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"ajones@ventanamicro.com" <ajones@ventanamicro.com>,
"Zhao, Yan Y" <yan.y.zhao@intel.com>,
"jgg@nvidia.com" <jgg@nvidia.com>,
"peterx@redhat.com" <peterx@redhat.com>
Subject: Re: [PATCH 2/2] vfio/pci: Use unmap_mapping_range()
Date: Wed, 29 May 2024 20:22:01 -0600 [thread overview]
Message-ID: <20240529202201.7b55549b.alex.williamson@redhat.com> (raw)
In-Reply-To: <BN9PR11MB52769DB022895F3D310F52458CF32@BN9PR11MB5276.namprd11.prod.outlook.com>
On Thu, 30 May 2024 00:09:49 +0000
"Tian, Kevin" <kevin.tian@intel.com> wrote:
> > From: Alex Williamson <alex.williamson@redhat.com>
> > Sent: Friday, May 24, 2024 3:56 AM
> >
> > -/* Caller holds vma_lock */
> > -static int __vfio_pci_add_vma(struct vfio_pci_core_device *vdev,
> > - struct vm_area_struct *vma)
> > +static int vma_to_pfn(struct vm_area_struct *vma, unsigned long *pfn)
> > {
> > - struct vfio_pci_mmap_vma *mmap_vma;
> > -
> > - mmap_vma = kmalloc(sizeof(*mmap_vma), GFP_KERNEL_ACCOUNT);
> > - if (!mmap_vma)
> > - return -ENOMEM;
> > -
> > - mmap_vma->vma = vma;
> > - list_add(&mmap_vma->vma_next, &vdev->vma_list);
> > + struct vfio_pci_core_device *vdev = vma->vm_private_data;
> > + int index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT -
> > PAGE_SHIFT);
> > + u64 pgoff;
> >
> > - return 0;
> > -}
> > + if (index >= VFIO_PCI_ROM_REGION_INDEX ||
> > + !vdev->bar_mmap_supported[index] || !vdev->barmap[index])
> > + return -EINVAL;
>
> Is a WARN_ON() required here? If those checks fail vfio_pci_core_mmap()
> will return error w/o installing vm_ops.
I think these tests largely come from previous iterations of the patch
where this function had more versatility, because yes, they do exactly
duplicate tests that we would have already passed before we established
this function in the vm_ops.fault path.
We could therefore wrap this in a WARN_ON, but actually with the
current usage it's really just a sanity test that vma->vm_pgoff hasn't
changed. We don't change barmap or bar_mmap_supported while the device
is opened. Is it all too much paranoia and we should remove the test
entirely and have this function return void?
> > @@ -2506,17 +2373,11 @@ static int vfio_pci_dev_set_hot_reset(struct
> > vfio_device_set *dev_set,
> > struct vfio_pci_group_info *groups,
> > struct iommufd_ctx *iommufd_ctx)
>
> the comment before this function should be updated too:
>
> /*
> * We need to get memory_lock for each device, but devices can share mmap_lock,
> * therefore we need to zap and hold the vma_lock for each device, and only then
> * get each memory_lock.
> */
Good catch. I think I'd just delete this comment altogether and expand
the existing comment in the loop body as:
/*
* Take the memory write lock for each device and zap BAR
* mappings to prevent the user accessing the device while in
* reset. Locking multiple devices is prone to deadlock,
* runaway and unwind if we hit contention.
*/
if (!down_write_trylock(&vdev->memory_lock)) {
ret = -EBUSY;
break;
}
Sound good? Thanks,
Alex
next prev parent reply other threads:[~2024-05-30 2:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 19:56 [PATCH 0/2] vfio/pci: vfio device address space mapping Alex Williamson
2024-05-23 19:56 ` [PATCH 1/2] vfio: Create vfio_fs_type with inode per device Alex Williamson
2024-05-24 13:24 ` Jason Gunthorpe
2024-05-29 23:59 ` Tian, Kevin
2024-05-23 19:56 ` [PATCH 2/2] vfio/pci: Use unmap_mapping_range() Alex Williamson
2024-05-24 0:39 ` Yan Zhao
2024-05-24 0:49 ` Peter Xu
2024-05-24 1:47 ` Yan Zhao
2024-05-28 18:42 ` Alex Williamson
2024-05-29 2:29 ` Yan Zhao
2024-05-29 3:12 ` Alex Williamson
2024-05-29 6:34 ` Yan Zhao
2024-05-29 16:50 ` Alex Williamson
2024-05-30 7:46 ` Yan Zhao
2024-05-24 8:40 ` Tian, Kevin
2024-05-24 13:22 ` Jason Gunthorpe
2024-05-24 23:15 ` Peter Xu
2024-05-24 13:42 ` Jason Gunthorpe
2024-05-30 0:09 ` Tian, Kevin
2024-05-30 2:22 ` Alex Williamson [this message]
2024-05-30 2:47 ` Tian, Kevin
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=20240529202201.7b55549b.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=ajones@ventanamicro.com \
--cc=jgg@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=yan.y.zhao@intel.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