]> git.baikalelectronics.ru Git - kernel.git/commit
vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries
authorJoao Martins <joao.m.martins@oracle.com>
Tue, 29 Nov 2022 13:12:35 +0000 (13:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:41 +0000 (13:32 +0100)
commit2ad128fd93e2368575ac559477ce48718466c940
tree9db16bc3efc7a22e4424323358c72dcbd5a2fb0f
parent2200c991dd5898d4145629f5663f5b5f049f4e95
vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries

[ Upstream commit daeabea4892bce74ad33c86f73fd317306dfa3a7 ]

Commit ca8a6f21a580 ("vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps")
had fixed the unaligned bitmaps by capping the remaining iterable set at
the start of the bitmap. Although, that mistakenly worked around
iova_bitmap_set() incorrectly setting bits across page boundary.

Fix this by reworking the loop inside iova_bitmap_set() to iterate over a
range of bits to set (cur_bit .. last_bit) which may span different pinned
pages, thus updating @page_idx and @offset as it sets the bits. The
previous cap to the first page is now adjusted to be always accounted
rather than when there's only a non-zero pgoff.

While at it, make @page_idx , @offset and @nbits to be unsigned int given
that it won't be more than 512 and 4096 respectively (even a bigger
PAGE_SIZE or a smaller struct page size won't make this bigger than the
above 32-bit max). Also, delete the stale kdoc on Return type.

Cc: Avihai Horon <avihaih@nvidia.com>
Fixes: ca8a6f21a580 ("vfio/iova_bitmap: Fix PAGE_SIZE unaligned bitmaps")
Co-developed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Avihai Horon <avihaih@nvidia.com>
Link: https://lore.kernel.org/r/20221129131235.38880-1-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