Skip to content

Commit 3560c0d

Browse files
author
Alex Williamson
committed
vfio/type1: Use consistent types for page counts
JIRA: https://issues.redhat.com/browse/RHEL-85587 commit 0635559 Author: Alex Williamson <alex.williamson@redhat.com> Date: Tue Feb 18 15:22:04 2025 -0700 vfio/type1: Use consistent types for page counts Page count should more consistently be an unsigned long when passed as an argument while functions returning a number of pages should use a signed long to allow for -errno. vaddr_get_pfns() can therefore be upgraded to return long, though in practice it's currently limited by the batch capacity. In fact, the batch indexes are noted to never hold negative values, so while it doesn't make sense to bloat the structure with unsigned longs in this case, it does make sense to specify these as unsigned. No change in behavior expected. Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com> Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20250218222209.1382449-5-alex.williamson@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 860cd61 commit 3560c0d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ struct vfio_dma {
104104
struct vfio_batch {
105105
struct page **pages; /* for pin_user_pages_remote */
106106
struct page *fallback_page; /* if pages alloc fails */
107-
int capacity; /* length of pages array */
108-
int size; /* of batch currently */
109-
int offset; /* of next entry in pages */
107+
unsigned int capacity; /* length of pages array */
108+
unsigned int size; /* of batch currently */
109+
unsigned int offset; /* of next entry in pages */
110110
};
111111

112112
struct vfio_iommu_group {
@@ -561,14 +561,14 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
561561
* initial offset. For VM_PFNMAP pfns, only the returned number of pfns and
562562
* returned initial pfn are provided; subsequent pfns are contiguous.
563563
*/
564-
static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
565-
long npages, int prot, unsigned long *pfn,
566-
struct vfio_batch *batch)
564+
static long vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
565+
unsigned long npages, int prot, unsigned long *pfn,
566+
struct vfio_batch *batch)
567567
{
568-
long pin_pages = min_t(long, npages, batch->capacity);
568+
unsigned long pin_pages = min_t(unsigned long, npages, batch->capacity);
569569
struct vm_area_struct *vma;
570570
unsigned int flags = 0;
571-
int ret;
571+
long ret;
572572

573573
if (prot & IOMMU_WRITE)
574574
flags |= FOLL_WRITE;
@@ -613,7 +613,7 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
613613
* first page and all consecutive pages with the same locking.
614614
*/
615615
static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
616-
long npage, unsigned long *pfn_base,
616+
unsigned long npage, unsigned long *pfn_base,
617617
unsigned long limit, struct vfio_batch *batch)
618618
{
619619
unsigned long pfn;
@@ -725,7 +725,7 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
725725
}
726726

727727
static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
728-
unsigned long pfn, long npage,
728+
unsigned long pfn, unsigned long npage,
729729
bool do_accounting)
730730
{
731731
long unlocked = 0, locked = 0;

0 commit comments

Comments
 (0)