Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Wanlong Gao <gaowanlong@huawei.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: <gaowanlong@huawei.com>, <kvm@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	"wencongyang (A)" <wencongyang2@huawei.com>,
	"Wangli (T)" <wangli74@huawei.com>,
	"Wanghui (John)" <john.wanghui@huawei.com>,
	guijianfeng <guijianfeng@huawei.com>
Subject: Race condition in vfio will cause deadwait
Date: Tue, 25 Jul 2017 21:30:04 +0800	[thread overview]
Message-ID: <4b8a662f-23fa-2777-a7ce-084a6f828f8f@huawei.com> (raw)
In-Reply-To: <03bf80d2-546d-614a-7af9-1f786fe01285@huawei.com>

From: Wen Congyang <wencongyang2@huawei.com>

Hi, Alex Williamson

When using vfio, we encounter a problem: too many lspci processes are blocked in D state.
I analyzed all processes, and found one process is blocked in pci_dev_lock(), another
process is blocked in vfio_del_group_put(). I checked the backtrace, and found the following
race condition:

Process A(use sysfs to unbind the device):
device_release_driver()
    device_lock(dev)
    __device_release_driver()
        dev->bus->remove(dev) // pci_device_remove()
            drv->remove(pci_dev) // vfio_pci_remove()
                vfio_del_group_dev()
                    vfio_device_put()
                    wait vfio_device is remove from the group. Process B gets vfio_device,
                    so we will wait it.

Process B:
vfio_group_fops_unl_ioctl()
    vfio_group_get_device_fd()
        vfio_device_get_from_name() // we get vfio_device here
        device->ops->open() // vfio_pci_open()
            vfio_pci_enable()
                pci_reset_function()
                    pci_dev_reset(dev, 0)
                        pci_dev_lock()
                            pci_cfg_access_lock(dev) // After this, lspci will be blocked
                            device_lock(&dev->dev) // the lock is hold by another process A

Now, Process A is waiting Process B, and Process B is waiting Process A.

I think we use pci_try_reset_function() to instead of pci_reset_function() can break this deadwait.


Thanks,
Wen Congyang

       reply	other threads:[~2017-07-25 13:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <03bf80d2-546d-614a-7af9-1f786fe01285@huawei.com>
2017-07-25 13:30 ` Wanlong Gao [this message]
2017-07-26 21:22   ` Race condition in vfio will cause deadwait Alex Williamson

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=4b8a662f-23fa-2777-a7ce-084a6f828f8f@huawei.com \
    --to=gaowanlong@huawei.com \
    --cc=alex.williamson@redhat.com \
    --cc=guijianfeng@huawei.com \
    --cc=john.wanghui@huawei.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wangli74@huawei.com \
    --cc=wencongyang2@huawei.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