lkml.org 
[lkml]   [2021]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 4/4] vfio-pci/zdev: Introduce the zPCI I/O vfio region
On Wed, 20 Jan 2021 14:21:59 +0100
Niklas Schnelle <schnelle@linux.ibm.com> wrote:

> On 1/19/21 9:02 PM, Matthew Rosato wrote:
> > Some s390 PCI devices (e.g. ISM) perform I/O operations that have very
> .. snip ...
> > +
> > +static size_t vfio_pci_zdev_io_rw(struct vfio_pci_device *vdev,
> > + char __user *buf, size_t count,
> > + loff_t *ppos, bool iswrite)
> > +{
> ... snip ...
> > + /*
> > + * For now, the largest allowed block I/O is advertised as PAGE_SIZE,
> > + * and cannot exceed a page boundary - so a single page is enough. The
> > + * guest should have validated this but let's double-check that the
> > + * request will not cross a page boundary.
> > + */
> > + if (((region->req.gaddr & ~PAGE_MASK)
> > + + region->req.len - 1) & PAGE_MASK) {
> > + return -EIO;
> > + }
> > +
> > + mutex_lock(&zdev->lock);
>
> I plan on using the zdev->lock for preventing concurrent zPCI devices
> removal/configuration state changes between zPCI availability/error
> events and enable_slot()/disable_slot() and /sys/bus/pci/devices/<dev>/recover.
>
> With that use in place using it here causes a deadlock when doing
> "echo 0 > /sys/bus/pci/slots/<fid>/power from the host for an ISM device
> attached to a guest.
>
> This is because the (soft) hot unplug will cause vfio to notify QEMU, which
> sends a deconfiguration request to the guest, which then tries to
> gracefully shutdown the device. During that shutdown the device will
> be accessed, running into this code path which then blocks on
> the lock held by the disable_slot() code which waits on vfio
> releasing the device.
>
> Alex may correct me if I'm wrong but I think instead vfio should
> be holding the PCI device lock via pci_device_lock(pdev).

There be dragons in device_lock, which is why we have all the crude
try-lock semantics in reset paths. Don't use it trivially. Device
lock is not necessary here otherwise, the device is bound to a driver
and has an open userspace file descriptor through which the user is
performing this access. The device can't be removed without unbinding
the driver, which can't happen while the user still has open files to
it. Thanks,

Alex

\
 
 \ /
  Last update: 2021-01-21 21:53    [W:0.205 / U:0.340 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site