Patch "vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     vfio-iova_bitmap-fix-page_size-unaligned-bitmaps.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ab3ec39fbbec490d2114686ecaf6cc565e0136f1
Author: Joao Martins <joao.m.martins@xxxxxxxxxx>
Date:   Tue Oct 25 20:31:14 2022 +0100

    vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps
    
    [ Upstream commit f38044e5ef58ad0346fdabd7027ea5c1e1a3b624 ]
    
    iova_bitmap_set() doesn't consider the end of the page boundary when the
    first bitmap page offset isn't zero, and wrongly changes the consecutive
    page right after. Consequently this leads to missing dirty pages from
    reported by the device as seen from the VMM.
    
    The current logic iterates over a given number of base pages and clamps it
    to the remaining indexes to iterate in the last page.  Instead of having to
    consider extra pages to pin (e.g. first and extra pages), just handle the
    first page as its own range and let the rest of the bitmap be handled as if
    it was base page aligned.
    
    This is done by changing iova_bitmap_mapped_remaining() to return PAGE_SIZE
    - pgoff (on the first bitmap page), and leads to pgoff being set to 0 on
    following iterations.
    
    Fixes: 58ccf0190d19 ("vfio: Add an IOVA bitmap support")
    Reported-by: Avihai Horon <avihaih@xxxxxxxxxx>
    Tested-by: Avihai Horon <avihaih@xxxxxxxxxx>
    Signed-off-by: Joao Martins <joao.m.martins@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221025193114.58695-3-joao.m.martins@xxxxxxxxxx
    Signed-off-by: Alex Williamson <alex.williamson@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/vfio/iova_bitmap.c b/drivers/vfio/iova_bitmap.c
index 6631e8befe1b..2dd65f040127 100644
--- a/drivers/vfio/iova_bitmap.c
+++ b/drivers/vfio/iova_bitmap.c
@@ -295,11 +295,15 @@ void iova_bitmap_free(struct iova_bitmap *bitmap)
  */
 static unsigned long iova_bitmap_mapped_remaining(struct iova_bitmap *bitmap)
 {
-	unsigned long remaining;
+	unsigned long remaining, bytes;
+
+	/* Cap to one page in the first iteration, if PAGE_SIZE unaligned. */
+	bytes = !bitmap->mapped.pgoff ? bitmap->mapped.npages << PAGE_SHIFT :
+					PAGE_SIZE - bitmap->mapped.pgoff;
 
 	remaining = bitmap->mapped_total_index - bitmap->mapped_base_index;
 	remaining = min_t(unsigned long, remaining,
-	      (bitmap->mapped.npages << PAGE_SHIFT) / sizeof(*bitmap->bitmap));
+			  bytes / sizeof(*bitmap->bitmap));
 
 	return remaining;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux