]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfio/type1: Use consistent types for page counts
authorAlex Williamson <alex.williamson@redhat.com>
Tue, 18 Feb 2025 22:22:04 +0000 (15:22 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Thu, 27 Feb 2025 18:55:54 +0000 (11:55 -0700)
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>
drivers/vfio/vfio_iommu_type1.c

index fafd8af125c77b63dd7f284414bef84f22a49f77..ce661f03f13917e45e96f5a76f68697ec420cf13 100644 (file)
@@ -103,9 +103,9 @@ struct vfio_dma {
 struct vfio_batch {
        struct page             **pages;        /* for pin_user_pages_remote */
        struct page             *fallback_page; /* if pages alloc fails */
-       int                     capacity;       /* length of pages array */
-       int                     size;           /* of batch currently */
-       int                     offset;         /* of next entry in pages */
+       unsigned int            capacity;       /* length of pages array */
+       unsigned int            size;           /* of batch currently */
+       unsigned int            offset;         /* of next entry in pages */
 };
 
 struct vfio_iommu_group {
@@ -560,14 +560,14 @@ static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
  * initial offset.  For VM_PFNMAP pfns, only the returned number of pfns and
  * returned initial pfn are provided; subsequent pfns are contiguous.
  */
-static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
-                         long npages, int prot, unsigned long *pfn,
-                         struct vfio_batch *batch)
+static long vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
+                          unsigned long npages, int prot, unsigned long *pfn,
+                          struct vfio_batch *batch)
 {
-       long pin_pages = min_t(long, npages, batch->capacity);
+       unsigned long pin_pages = min_t(unsigned long, npages, batch->capacity);
        struct vm_area_struct *vma;
        unsigned int flags = 0;
-       int ret;
+       long ret;
 
        if (prot & IOMMU_WRITE)
                flags |= FOLL_WRITE;
@@ -612,7 +612,7 @@ done:
  * first page and all consecutive pages with the same locking.
  */
 static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
-                                 long npage, unsigned long *pfn_base,
+                                 unsigned long npage, unsigned long *pfn_base,
                                  unsigned long limit, struct vfio_batch *batch)
 {
        unsigned long pfn;
@@ -724,7 +724,7 @@ unpin_out:
 }
 
 static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
-                                   unsigned long pfn, long npage,
+                                   unsigned long pfn, unsigned long npage,
                                    bool do_accounting)
 {
        long unlocked = 0, locked = 0;