@@ -311,8 +311,8 @@ static int viommu_send_req_sync(struct viommu_dev *viommu, void *buf,
311
311
*
312
312
* On success, return the new mapping. Otherwise return NULL.
313
313
*/
314
- static int viommu_add_mapping (struct viommu_domain * vdomain , unsigned long iova ,
315
- phys_addr_t paddr , size_t size , u32 flags )
314
+ static int viommu_add_mapping (struct viommu_domain * vdomain , u64 iova , u64 end ,
315
+ phys_addr_t paddr , u32 flags )
316
316
{
317
317
unsigned long irqflags ;
318
318
struct viommu_mapping * mapping ;
@@ -323,7 +323,7 @@ static int viommu_add_mapping(struct viommu_domain *vdomain, unsigned long iova,
323
323
324
324
mapping -> paddr = paddr ;
325
325
mapping -> iova .start = iova ;
326
- mapping -> iova .last = iova + size - 1 ;
326
+ mapping -> iova .last = end ;
327
327
mapping -> flags = flags ;
328
328
329
329
spin_lock_irqsave (& vdomain -> mappings_lock , irqflags );
@@ -338,26 +338,24 @@ static int viommu_add_mapping(struct viommu_domain *vdomain, unsigned long iova,
338
338
*
339
339
* @vdomain: the domain
340
340
* @iova: start of the range
341
- * @size: size of the range. A size of 0 corresponds to the entire address
342
- * space.
341
+ * @end: end of the range
343
342
*
344
- * On success, returns the number of unmapped bytes (>= size)
343
+ * On success, returns the number of unmapped bytes
345
344
*/
346
345
static size_t viommu_del_mappings (struct viommu_domain * vdomain ,
347
- unsigned long iova , size_t size )
346
+ u64 iova , u64 end )
348
347
{
349
348
size_t unmapped = 0 ;
350
349
unsigned long flags ;
351
- unsigned long last = iova + size - 1 ;
352
350
struct viommu_mapping * mapping = NULL ;
353
351
struct interval_tree_node * node , * next ;
354
352
355
353
spin_lock_irqsave (& vdomain -> mappings_lock , flags );
356
- next = interval_tree_iter_first (& vdomain -> mappings , iova , last );
354
+ next = interval_tree_iter_first (& vdomain -> mappings , iova , end );
357
355
while (next ) {
358
356
node = next ;
359
357
mapping = container_of (node , struct viommu_mapping , iova );
360
- next = interval_tree_iter_next (node , iova , last );
358
+ next = interval_tree_iter_next (node , iova , end );
361
359
362
360
/* Trying to split a mapping? */
363
361
if (mapping -> iova .start < iova )
@@ -656,8 +654,8 @@ static void viommu_domain_free(struct iommu_domain *domain)
656
654
{
657
655
struct viommu_domain * vdomain = to_viommu_domain (domain );
658
656
659
- /* Free all remaining mappings (size 2^64) */
660
- viommu_del_mappings (vdomain , 0 , 0 );
657
+ /* Free all remaining mappings */
658
+ viommu_del_mappings (vdomain , 0 , ULLONG_MAX );
661
659
662
660
if (vdomain -> viommu )
663
661
ida_free (& vdomain -> viommu -> domain_ids , vdomain -> id );
@@ -742,6 +740,7 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova,
742
740
{
743
741
int ret ;
744
742
u32 flags ;
743
+ u64 end = iova + size - 1 ;
745
744
struct virtio_iommu_req_map map ;
746
745
struct viommu_domain * vdomain = to_viommu_domain (domain );
747
746
@@ -752,7 +751,7 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova,
752
751
if (flags & ~vdomain -> map_flags )
753
752
return - EINVAL ;
754
753
755
- ret = viommu_add_mapping (vdomain , iova , paddr , size , flags );
754
+ ret = viommu_add_mapping (vdomain , iova , end , paddr , flags );
756
755
if (ret )
757
756
return ret ;
758
757
@@ -761,7 +760,7 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova,
761
760
.domain = cpu_to_le32 (vdomain -> id ),
762
761
.virt_start = cpu_to_le64 (iova ),
763
762
.phys_start = cpu_to_le64 (paddr ),
764
- .virt_end = cpu_to_le64 (iova + size - 1 ),
763
+ .virt_end = cpu_to_le64 (end ),
765
764
.flags = cpu_to_le32 (flags ),
766
765
};
767
766
@@ -770,7 +769,7 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova,
770
769
771
770
ret = viommu_send_req_sync (vdomain -> viommu , & map , sizeof (map ));
772
771
if (ret )
773
- viommu_del_mappings (vdomain , iova , size );
772
+ viommu_del_mappings (vdomain , iova , end );
774
773
775
774
return ret ;
776
775
}
@@ -783,7 +782,7 @@ static size_t viommu_unmap(struct iommu_domain *domain, unsigned long iova,
783
782
struct virtio_iommu_req_unmap unmap ;
784
783
struct viommu_domain * vdomain = to_viommu_domain (domain );
785
784
786
- unmapped = viommu_del_mappings (vdomain , iova , size );
785
+ unmapped = viommu_del_mappings (vdomain , iova , iova + size - 1 );
787
786
if (unmapped < size )
788
787
return 0 ;
789
788
0 commit comments