@@ -13,6 +13,18 @@ struct kvm_gmem {
13
13
struct list_head entry ;
14
14
};
15
15
16
+ /**
17
+ * folio_file_pfn - like folio_file_page, but return a pfn.
18
+ * @folio: The folio which contains this index.
19
+ * @index: The index we want to look up.
20
+ *
21
+ * Return: The pfn for this index.
22
+ */
23
+ static inline kvm_pfn_t folio_file_pfn (struct folio * folio , pgoff_t index )
24
+ {
25
+ return folio_pfn (folio ) + (index & (folio_nr_pages (folio ) - 1 ));
26
+ }
27
+
16
28
static int kvm_gmem_prepare_folio (struct inode * inode , pgoff_t index , struct folio * folio )
17
29
{
18
30
#ifdef CONFIG_HAVE_KVM_GMEM_PREPARE
@@ -22,7 +34,6 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol
22
34
list_for_each_entry (gmem , gmem_list , entry ) {
23
35
struct kvm_memory_slot * slot ;
24
36
struct kvm * kvm = gmem -> kvm ;
25
- struct page * page ;
26
37
kvm_pfn_t pfn ;
27
38
gfn_t gfn ;
28
39
int rc ;
@@ -34,13 +45,12 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol
34
45
if (!slot )
35
46
continue ;
36
47
37
- page = folio_file_page (folio , index );
38
- pfn = page_to_pfn (page );
48
+ pfn = folio_file_pfn (folio , index );
39
49
gfn = slot -> base_gfn + index - slot -> gmem .pgoff ;
40
- rc = kvm_arch_gmem_prepare (kvm , gfn , pfn , compound_order ( compound_head ( page ) ));
50
+ rc = kvm_arch_gmem_prepare (kvm , gfn , pfn , folio_order ( folio ));
41
51
if (rc ) {
42
- pr_warn_ratelimited ("gmem: Failed to prepare folio for index %lx GFN %llx PFN %llx error %d.\n" ,
43
- index , gfn , pfn , rc );
52
+ pr_warn_ratelimited ("gmem: Failed to prepare folio for GFN %llx PFN %llx error %d.\n" ,
53
+ gfn , pfn , rc );
44
54
return rc ;
45
55
}
46
56
}
@@ -548,7 +558,6 @@ __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
548
558
pgoff_t index = gfn - slot -> base_gfn + slot -> gmem .pgoff ;
549
559
struct kvm_gmem * gmem = file -> private_data ;
550
560
struct folio * folio ;
551
- struct page * page ;
552
561
553
562
if (file != slot -> gmem .file ) {
554
563
WARN_ON_ONCE (slot -> gmem .file );
@@ -571,9 +580,7 @@ __kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot,
571
580
return ERR_PTR (- EHWPOISON );
572
581
}
573
582
574
- page = folio_file_page (folio , index );
575
-
576
- * pfn = page_to_pfn (page );
583
+ * pfn = folio_file_pfn (folio , index );
577
584
if (max_order )
578
585
* max_order = 0 ;
579
586
0 commit comments