@@ -541,34 +541,34 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot)
541
541
fput (file );
542
542
}
543
543
544
- static int __kvm_gmem_get_pfn (struct file * file , struct kvm_memory_slot * slot ,
545
- gfn_t gfn , kvm_pfn_t * pfn , int * max_order , bool prepare )
544
+ static struct folio *
545
+ __kvm_gmem_get_pfn (struct file * file , struct kvm_memory_slot * slot ,
546
+ gfn_t gfn , kvm_pfn_t * pfn , int * max_order , bool prepare )
546
547
{
547
548
pgoff_t index = gfn - slot -> base_gfn + slot -> gmem .pgoff ;
548
549
struct kvm_gmem * gmem = file -> private_data ;
549
550
struct folio * folio ;
550
551
struct page * page ;
551
- int r ;
552
552
553
553
if (file != slot -> gmem .file ) {
554
554
WARN_ON_ONCE (slot -> gmem .file );
555
- return - EFAULT ;
555
+ return ERR_PTR ( - EFAULT ) ;
556
556
}
557
557
558
558
gmem = file -> private_data ;
559
559
if (xa_load (& gmem -> bindings , index ) != slot ) {
560
560
WARN_ON_ONCE (xa_load (& gmem -> bindings , index ));
561
- return - EIO ;
561
+ return ERR_PTR ( - EIO ) ;
562
562
}
563
563
564
564
folio = kvm_gmem_get_folio (file_inode (file ), index , prepare );
565
565
if (IS_ERR (folio ))
566
- return PTR_ERR ( folio ) ;
566
+ return folio ;
567
567
568
568
if (folio_test_hwpoison (folio )) {
569
569
folio_unlock (folio );
570
570
folio_put (folio );
571
- return - EHWPOISON ;
571
+ return ERR_PTR ( - EHWPOISON ) ;
572
572
}
573
573
574
574
page = folio_file_page (folio , index );
@@ -577,25 +577,25 @@ static int __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
577
577
if (max_order )
578
578
* max_order = 0 ;
579
579
580
- r = 0 ;
581
-
582
580
folio_unlock (folio );
583
-
584
- return r ;
581
+ return folio ;
585
582
}
586
583
587
584
int kvm_gmem_get_pfn (struct kvm * kvm , struct kvm_memory_slot * slot ,
588
585
gfn_t gfn , kvm_pfn_t * pfn , int * max_order )
589
586
{
590
587
struct file * file = kvm_gmem_get_file (slot );
591
- int r ;
588
+ struct folio * folio ;
592
589
593
590
if (!file )
594
591
return - EFAULT ;
595
592
596
- r = __kvm_gmem_get_pfn (file , slot , gfn , pfn , max_order , true);
593
+ folio = __kvm_gmem_get_pfn (file , slot , gfn , pfn , max_order , true);
597
594
fput (file );
598
- return r ;
595
+ if (IS_ERR (folio ))
596
+ return PTR_ERR (folio );
597
+
598
+ return 0 ;
599
599
}
600
600
EXPORT_SYMBOL_GPL (kvm_gmem_get_pfn );
601
601
@@ -625,6 +625,7 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
625
625
626
626
npages = min_t (ulong , slot -> npages - (start_gfn - slot -> base_gfn ), npages );
627
627
for (i = 0 ; i < npages ; i += (1 << max_order )) {
628
+ struct folio * folio ;
628
629
gfn_t gfn = start_gfn + i ;
629
630
kvm_pfn_t pfn ;
630
631
@@ -633,9 +634,11 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
633
634
break ;
634
635
}
635
636
636
- ret = __kvm_gmem_get_pfn (file , slot , gfn , & pfn , & max_order , false);
637
- if (ret )
637
+ folio = __kvm_gmem_get_pfn (file , slot , gfn , & pfn , & max_order , false);
638
+ if (IS_ERR (folio )) {
639
+ ret = PTR_ERR (folio );
638
640
break ;
641
+ }
639
642
640
643
if (!IS_ALIGNED (gfn , (1 << max_order )) ||
641
644
(npages - i ) < (1 << max_order ))
@@ -644,7 +647,7 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
644
647
p = src ? src + i * PAGE_SIZE : NULL ;
645
648
ret = post_populate (kvm , gfn , pfn , p , max_order , opaque );
646
649
647
- put_page ( pfn_to_page ( pfn ) );
650
+ folio_put ( folio );
648
651
if (ret )
649
652
break ;
650
653
}
0 commit comments