Skip to content

Commit fce92dc

Browse files
Xiao Guangrongavikivity
authored andcommitted
KVM: MMU: filter out the mmio pfn from the fault pfn
If the page fault is caused by mmio, the gfn can not be found in memslots, and 'bad_pfn' is returned on gfn_to_hva path, so we can use 'bad_pfn' to identify the mmio page fault. And, to clarify the meaning of mmio pfn, we return fault page instead of bad page when the gfn is not allowd to prefetch Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
1 parent c370795 commit fce92dc

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎arch/x86/kvm/mmu.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,8 +2085,8 @@ static pfn_t pte_prefetch_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn,
20852085

20862086
slot = gfn_to_memslot_dirty_bitmap(vcpu, gfn, no_dirty_log);
20872087
if (!slot) {
2088-
get_page(bad_page);
2089-
return page_to_pfn(bad_page);
2088+
get_page(fault_page);
2089+
return page_to_pfn(fault_page);
20902090
}
20912091

20922092
hva = gfn_to_hva_memslot(slot, gfn);

‎include/linux/kvm_host.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,17 @@ static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm)
327327
static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
328328

329329
extern struct page *bad_page;
330+
extern struct page *fault_page;
331+
330332
extern pfn_t bad_pfn;
333+
extern pfn_t fault_pfn;
331334

332335
int is_error_page(struct page *page);
333336
int is_error_pfn(pfn_t pfn);
334337
int is_hwpoison_pfn(pfn_t pfn);
335338
int is_fault_pfn(pfn_t pfn);
339+
int is_noslot_pfn(pfn_t pfn);
340+
int is_invalid_pfn(pfn_t pfn);
336341
int kvm_is_error_hva(unsigned long addr);
337342
int kvm_set_memory_region(struct kvm *kvm,
338343
struct kvm_userspace_memory_region *mem,

‎virt/kvm/kvm_main.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ static bool largepages_enabled = true;
101101
static struct page *hwpoison_page;
102102
static pfn_t hwpoison_pfn;
103103

104-
static struct page *fault_page;
105-
static pfn_t fault_pfn;
104+
struct page *fault_page;
105+
pfn_t fault_pfn;
106106

107107
inline int kvm_is_mmio_pfn(pfn_t pfn)
108108
{
@@ -931,6 +931,18 @@ int is_fault_pfn(pfn_t pfn)
931931
}
932932
EXPORT_SYMBOL_GPL(is_fault_pfn);
933933

934+
int is_noslot_pfn(pfn_t pfn)
935+
{
936+
return pfn == bad_pfn;
937+
}
938+
EXPORT_SYMBOL_GPL(is_noslot_pfn);
939+
940+
int is_invalid_pfn(pfn_t pfn)
941+
{
942+
return pfn == hwpoison_pfn || pfn == fault_pfn;
943+
}
944+
EXPORT_SYMBOL_GPL(is_invalid_pfn);
945+
934946
static inline unsigned long bad_hva(void)
935947
{
936948
return PAGE_OFFSET;

0 commit comments

Comments
 (0)