]> git.baikalelectronics.ru Git - kernel.git/commit
vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 25 Oct 2022 19:31:14 +0000 (20:31 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:38 +0000 (13:32 +0100)
commit8b6bdfe9a95e39f0ec88e4e05b7f5a39b7c97751
treebcd1092a4ee10b88cab41efec7e4742a7f8d1500
parentd0487663d008f4a88e616e40abb638ec43dc8fb5
vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps

[ Upstream commit ca8a6f21a580547a360c6190153d1752e809ba2f ]

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: cee037ae658d ("vfio: Add an IOVA bitmap support")
Reported-by: Avihai Horon <avihaih@nvidia.com>
Tested-by: Avihai Horon <avihaih@nvidia.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Link: https://lore.kernel.org/r/20221025193114.58695-3-joao.m.martins@oracle.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/vfio/iova_bitmap.c