From: Matthew Rosato <mjrosato@linux.ibm.com>
To: "Tian, Kevin" <kevin.tian@intel.com>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"Liu, Yi L" <yi.l.liu@intel.com>,
"jgg@nvidia.com" <jgg@nvidia.com>
Cc: "cohuck@redhat.com" <cohuck@redhat.com>,
"farman@linux.ibm.com" <farman@linux.ibm.com>,
"pmorel@linux.ibm.com" <pmorel@linux.ibm.com>,
"borntraeger@linux.ibm.com" <borntraeger@linux.ibm.com>,
"frankja@linux.ibm.com" <frankja@linux.ibm.com>,
"imbrenda@linux.ibm.com" <imbrenda@linux.ibm.com>,
"david@redhat.com" <david@redhat.com>,
"akrowiak@linux.ibm.com" <akrowiak@linux.ibm.com>,
"jjherne@linux.ibm.com" <jjherne@linux.ibm.com>,
"pasic@linux.ibm.com" <pasic@linux.ibm.com>,
"zhenyuw@linux.intel.com" <zhenyuw@linux.intel.com>,
"Wang, Zhi A" <zhi.a.wang@intel.com>, "Christopherson, ,
Sean" <seanjc@google.com>,
"linux-s390@vger.kernel.org" <linux-s390@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"intel-gvt-dev@lists.freedesktop.org"
<intel-gvt-dev@lists.freedesktop.org>,
"intel-gfx@lists.freedesktop.org"
<intel-gfx@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] vfio: fix deadlock between group lock and kvm lock
Date: Wed, 1 Feb 2023 09:27:45 -0500 [thread overview]
Message-ID: <9b6c0c4d-57c9-6a9a-379e-82f073b73988@linux.ibm.com> (raw)
In-Reply-To: <BN9PR11MB5276E39EE37A7BA2E1B896278CD19@BN9PR11MB5276.namprd11.prod.outlook.com>
On 2/1/23 1:13 AM, Tian, Kevin wrote:
>> From: Matthew Rosato <mjrosato@linux.ibm.com>
>> Sent: Wednesday, February 1, 2023 4:07 AM
>>
>> - device->kvm = kvm;
>> + /*
>> + * Get the KVM pointer currently associated with the group, if there
>> + * is one, and obtain a reference now that will be held until the
>> + * open_count reaches 0. Save the pointer in the device for use by
>> + * drivers.
>> + */
>> + spin_lock_irqsave(&group->kvm_ref_lock, flags);
>> + if (group->kvm && vfio_kvm_get_kvm_safe(device, group->kvm))
>> + device->kvm = group->kvm;
>> + spin_unlock_irqrestore(&group->kvm_ref_lock, flags);
>> +
>
> No group reference in vfio_main.c.
OK -- I think to do that I'll have to move the lock/unlock of the dev_set lock to group.c right before we call vfio_device_{open,close} and check open_count there to make decisions about the kvm ref (before calling vfio_device_open to decide to get kvm ref, after returning from vfio_device_open to see if we to drop ref on error, after close to see if we need to drop ref).
>
> btw Yi, looks the deadlock issue also exists in your cdev work.
>
> kvm_vfio_release() holds kvm lock and then try to acquire
> device->device_set->lock in vfio_device_file_set_kvm().
>
> vfio_device_ioctl_bind_iommufd() holds device->device_set->lock
> and then call vfio_device_open() which finally hit kvm lock
> acquisition in driver's open_device routine (e.g. vfio-ap).
>
> A similar fix is required in your series.
>
> Thanks
> Kevin
next prev parent reply other threads:[~2023-02-01 14:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-31 20:06 Matthew Rosato
2023-01-31 20:25 ` Jason Gunthorpe
2023-02-01 12:43 ` Liu, Yi L
2023-02-01 14:42 ` Matthew Rosato
2023-02-02 3:08 ` Liu, Yi L
2023-02-01 6:13 ` Tian, Kevin
2023-02-01 14:27 ` Matthew Rosato [this message]
2023-02-01 12:42 ` Liu, Yi L
2023-02-01 14:41 ` Matthew Rosato
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=9b6c0c4d-57c9-6a9a-379e-82f073b73988@linux.ibm.com \
--to=mjrosato@linux.ibm.com \
--cc=akrowiak@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=farman@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=jgg@nvidia.com \
--cc=jjherne@linux.ibm.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=pmorel@linux.ibm.com \
--cc=seanjc@google.com \
--cc=yi.l.liu@intel.com \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@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
all inboxes | Powered by JetHome®