linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	Kirti Wankhede <kwankhede@nvidia.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	ldv-project@linuxtesting.org
Subject: Re: [PATCH] sample: vfio-mdev: avoid deadlock in mdev_access()
Date: Wed, 11 Jul 2018 13:30:26 -0600	[thread overview]
Message-ID: <20180711133026.5339589d@t450s.home> (raw)
In-Reply-To: <1530910206-24948-1-git-send-email-khoroshilov@ispras.ru>

On Fri,  6 Jul 2018 23:50:06 +0300
Alexey Khoroshilov <khoroshilov@ispras.ru> wrote:

> mdev_access() calls mbochs_get_page() with mdev_state->ops_lock held,
> while mbochs_get_page() locks the mutex by itself.
> It leads to unavoidable deadlock.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
> ---
>  samples/vfio-mdev/mbochs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
> index 2960e26c6ea4..6295a21381eb 100644
> --- a/samples/vfio-mdev/mbochs.c
> +++ b/samples/vfio-mdev/mbochs.c
> @@ -178,6 +178,8 @@ static const char *vbe_name(u32 index)
>  	return "(invalid)";
>  }
>  
> +static struct page *__mbochs_get_page(struct mdev_state *mdev_state,
> +				      pgoff_t pgoff);
>  static struct page *mbochs_get_page(struct mdev_state *mdev_state,
>  				    pgoff_t pgoff);
>  
> @@ -394,7 +396,7 @@ static ssize_t mdev_access(struct mdev_device *mdev, char *buf, size_t count,
>  		   MBOCHS_MEMORY_BAR_OFFSET + mdev_state->memsize) {
>  		pos -= MBOCHS_MMIO_BAR_OFFSET;
>  		poff = pos & ~PAGE_MASK;
> -		pg = mbochs_get_page(mdev_state, pos >> PAGE_SHIFT);
> +		pg = __mbochs_get_page(mdev_state, pos >> PAGE_SHIFT);
>  		map = kmap(pg);
>  		if (is_write)
>  			memcpy(map + poff, buf, count);

Looks good, applied to vfio for-linus branch for v4.18.  Thanks,

Alex

      reply	other threads:[~2018-07-11 19:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06 20:50 [PATCH] sample: vfio-mdev: avoid deadlock in mdev_access() Alexey Khoroshilov
2018-07-11 19:30 ` Alex Williamson [this message]

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=20180711133026.5339589d@t450s.home \
    --to=alex.williamson@redhat.com \
    --cc=khoroshilov@ispras.ru \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@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 NNTP newsgroup(s).