[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210325132551.4c7ce805@omen.home.shazbot.org>
Date: Thu, 25 Mar 2021 13:25:51 -0600
From: Alex Williamson <alex.williamson@...hat.com>
To: Daniel Jordan <daniel.m.jordan@...cle.com>
Cc: Cornelia Huck <cohuck@...hat.com>,
Jason Gunthorpe <jgg@...dia.com>,
Matthew Wilcox <willy@...radead.org>,
Pavel Tatashin <pasha.tatashin@...een.com>,
Steven Sistare <steven.sistare@...cle.com>,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] vfio/type1: Empty batch for pfnmap pages
On Wed, 24 Mar 2021 21:05:52 -0400
Daniel Jordan <daniel.m.jordan@...cle.com> wrote:
> When vfio_pin_pages_remote() returns with a partial batch consisting of
> a single VM_PFNMAP pfn, a subsequent call will unfortunately try
> restoring it from batch->pages, resulting in vfio mapping the wrong page
> and unbalancing the page refcount.
>
> Prevent the function from returning with this kind of partial batch to
> avoid the issue. There's no explicit check for a VM_PFNMAP pfn because
> it's awkward to do so, so infer it from characteristics of the batch
> instead. This may result in occasional false positives but keeps the
> code simpler.
>
> Fixes: 4d83de6da265 ("vfio/type1: Batch page pinning")
> Link: https://lkml.kernel.org/r/20210323133254.33ed9161@omen.home.shazbot.org/
> Reported-by: Alex Williamson <alex.williamson@...hat.com>
> Suggested-by: Alex Williamson <alex.williamson@...hat.com>
> Signed-off-by: Daniel Jordan <daniel.m.jordan@...cle.com>
> ---
>
> Alex, I couldn't immediately find a way to trigger this bug, but I can
> run your test case if you like.
>
> This is the minimal fix, but it should still protect all calls of
> vfio_batch_unpin() from this problem.
Thanks, applied to my for-linus branch for v5.12. The attached unit
test triggers the issue, I don't have any real world examples and was
only just experimenting with this for another series earlier this week.
Thanks,
Alex
View attachment "alternate-pfnmap.c" of type "text/x-c++src" (8080 bytes)
Powered by blists - more mailing lists