KVM Archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] vfio/pci: Collect hot-reset devices to local buffer
Date: Tue, 7 May 2024 13:54:50 -0300	[thread overview]
Message-ID: <20240507165450.GI4718@ziepe.ca> (raw)
In-Reply-To: <20240503143138.3562116-1-alex.williamson@redhat.com>

On Fri, May 03, 2024 at 08:31:36AM -0600, Alex Williamson wrote:
> Lockdep reports the below circular locking dependency issue.  The
> mmap_lock acquisition while holding pci_bus_sem is due to the use of
> copy_to_user() from within a pci_walk_bus() callback.
> 
> Building the devices array directly into the user buffer is only for
> convenience.  Instead we can allocate a local buffer for the array,
> bounded by the number of devices on the bus/slot, fill the device
> information into this local buffer, then copy it into the user buffer
> outside the bus walk callback.

> Chain exists of:
>   &vdev->vma_lock --> pci_bus_sem --> &mm->mmap_lock
> 
>  Possible unsafe locking scenario:
> 
> block dm-0: the capability attribute has been deprecated.
>        CPU0                    CPU1
>        ----                    ----
>   rlock(&mm->mmap_lock);
>                                lock(pci_bus_sem);
>                                lock(&mm->mmap_lock);
>   lock(&vdev->vma_lock);
> 
>  *** DEADLOCK ***

 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>  drivers/vfio/pci/vfio_pci_core.c | 78 ++++++++++++++++++++------------
>  1 file changed, 49 insertions(+), 29 deletions(-)

I feel like I created this bug...

It is sad we have to allocate kernel memory, but can't think of a
better option.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason

  reply	other threads:[~2024-05-07 16:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 14:31 [PATCH] vfio/pci: Collect hot-reset devices to local buffer Alex Williamson
2024-05-07 16:54 ` Jason Gunthorpe [this message]
2024-05-13  7:51 ` Liu, Yi L
2024-05-16 17:44   ` Alex Williamson
2024-05-17  7:40     ` Liu, Yi L

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=20240507165450.GI4718@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=alex.williamson@redhat.com \
    --cc=kvm@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).