@@ -504,7 +504,7 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
504
504
return r ;
505
505
}
506
506
507
- static void vhost_vdpa_iotlb_unmap (struct vhost_vdpa * v , u64 start , u64 last )
507
+ static void vhost_vdpa_pa_unmap (struct vhost_vdpa * v , u64 start , u64 last )
508
508
{
509
509
struct vhost_dev * dev = & v -> vdev ;
510
510
struct vhost_iotlb * iotlb = dev -> iotlb ;
@@ -526,6 +526,11 @@ static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v, u64 start, u64 last)
526
526
}
527
527
}
528
528
529
+ static void vhost_vdpa_iotlb_unmap (struct vhost_vdpa * v , u64 start , u64 last )
530
+ {
531
+ return vhost_vdpa_pa_unmap (v , start , last );
532
+ }
533
+
529
534
static void vhost_vdpa_iotlb_free (struct vhost_vdpa * v )
530
535
{
531
536
struct vhost_dev * dev = & v -> vdev ;
@@ -606,38 +611,28 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, u64 iova, u64 size)
606
611
}
607
612
}
608
613
609
- static int vhost_vdpa_process_iotlb_update (struct vhost_vdpa * v ,
610
- struct vhost_iotlb_msg * msg )
614
+ static int vhost_vdpa_pa_map (struct vhost_vdpa * v ,
615
+ u64 iova , u64 size , u64 uaddr , u32 perm )
611
616
{
612
617
struct vhost_dev * dev = & v -> vdev ;
613
- struct vhost_iotlb * iotlb = dev -> iotlb ;
614
618
struct page * * page_list ;
615
619
unsigned long list_size = PAGE_SIZE / sizeof (struct page * );
616
620
unsigned int gup_flags = FOLL_LONGTERM ;
617
621
unsigned long npages , cur_base , map_pfn , last_pfn = 0 ;
618
622
unsigned long lock_limit , sz2pin , nchunks , i ;
619
- u64 iova = msg -> iova ;
623
+ u64 start = iova ;
620
624
long pinned ;
621
625
int ret = 0 ;
622
626
623
- if (msg -> iova < v -> range .first || !msg -> size ||
624
- msg -> iova > U64_MAX - msg -> size + 1 ||
625
- msg -> iova + msg -> size - 1 > v -> range .last )
626
- return - EINVAL ;
627
-
628
- if (vhost_iotlb_itree_first (iotlb , msg -> iova ,
629
- msg -> iova + msg -> size - 1 ))
630
- return - EEXIST ;
631
-
632
627
/* Limit the use of memory for bookkeeping */
633
628
page_list = (struct page * * ) __get_free_page (GFP_KERNEL );
634
629
if (!page_list )
635
630
return - ENOMEM ;
636
631
637
- if (msg -> perm & VHOST_ACCESS_WO )
632
+ if (perm & VHOST_ACCESS_WO )
638
633
gup_flags |= FOLL_WRITE ;
639
634
640
- npages = PFN_UP (msg -> size + (iova & ~PAGE_MASK ));
635
+ npages = PFN_UP (size + (iova & ~PAGE_MASK ));
641
636
if (!npages ) {
642
637
ret = - EINVAL ;
643
638
goto free ;
@@ -651,7 +646,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
651
646
goto unlock ;
652
647
}
653
648
654
- cur_base = msg -> uaddr & PAGE_MASK ;
649
+ cur_base = uaddr & PAGE_MASK ;
655
650
iova &= PAGE_MASK ;
656
651
nchunks = 0 ;
657
652
@@ -682,7 +677,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
682
677
csize = PFN_PHYS (last_pfn - map_pfn + 1 );
683
678
ret = vhost_vdpa_map (v , iova , csize ,
684
679
PFN_PHYS (map_pfn ),
685
- msg -> perm );
680
+ perm );
686
681
if (ret ) {
687
682
/*
688
683
* Unpin the pages that are left unmapped
@@ -711,7 +706,7 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
711
706
712
707
/* Pin the rest chunk */
713
708
ret = vhost_vdpa_map (v , iova , PFN_PHYS (last_pfn - map_pfn + 1 ),
714
- PFN_PHYS (map_pfn ), msg -> perm );
709
+ PFN_PHYS (map_pfn ), perm );
715
710
out :
716
711
if (ret ) {
717
712
if (nchunks ) {
@@ -730,13 +725,33 @@ static int vhost_vdpa_process_iotlb_update(struct vhost_vdpa *v,
730
725
for (pfn = map_pfn ; pfn <= last_pfn ; pfn ++ )
731
726
unpin_user_page (pfn_to_page (pfn ));
732
727
}
733
- vhost_vdpa_unmap (v , msg -> iova , msg -> size );
728
+ vhost_vdpa_unmap (v , start , size );
734
729
}
735
730
unlock :
736
731
mmap_read_unlock (dev -> mm );
737
732
free :
738
733
free_page ((unsigned long )page_list );
739
734
return ret ;
735
+
736
+ }
737
+
738
+ static int vhost_vdpa_process_iotlb_update (struct vhost_vdpa * v ,
739
+ struct vhost_iotlb_msg * msg )
740
+ {
741
+ struct vhost_dev * dev = & v -> vdev ;
742
+ struct vhost_iotlb * iotlb = dev -> iotlb ;
743
+
744
+ if (msg -> iova < v -> range .first || !msg -> size ||
745
+ msg -> iova > U64_MAX - msg -> size + 1 ||
746
+ msg -> iova + msg -> size - 1 > v -> range .last )
747
+ return - EINVAL ;
748
+
749
+ if (vhost_iotlb_itree_first (iotlb , msg -> iova ,
750
+ msg -> iova + msg -> size - 1 ))
751
+ return - EEXIST ;
752
+
753
+ return vhost_vdpa_pa_map (v , msg -> iova , msg -> size , msg -> uaddr ,
754
+ msg -> perm );
740
755
}
741
756
742
757
static int vhost_vdpa_process_iotlb_msg (struct vhost_dev * dev ,
0 commit comments