Skip to content

Commit d3fccc7

Browse files
Ard Biesheuvelbonzini
authored andcommitted
kvm: fix kvm_is_mmio_pfn() and rename to kvm_is_reserved_pfn()
This reverts commit 85c8555 ("KVM: check for !is_zero_pfn() in kvm_is_mmio_pfn()") and renames the function to kvm_is_reserved_pfn. The problem being addressed by the patch above was that some ARM code based the memory mapping attributes of a pfn on the return value of kvm_is_mmio_pfn(), whose name indeed suggests that such pfns should be mapped as device memory. However, kvm_is_mmio_pfn() doesn't do quite what it says on the tin, and the existing non-ARM users were already using it in a way which suggests that its name should probably have been 'kvm_is_reserved_pfn' from the beginning, e.g., whether or not to call get_page/put_page on it etc. This means that returning false for the zero page is a mistake and the patch above should be reverted. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent bb55e9b commit d3fccc7

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎arch/ia64/kvm/kvm-ia64.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
15631563

15641564
for (i = 0; i < npages; i++) {
15651565
pfn = gfn_to_pfn(kvm, base_gfn + i);
1566-
if (!kvm_is_mmio_pfn(pfn)) {
1566+
if (!kvm_is_reserved_pfn(pfn)) {
15671567
kvm_set_pmt_entry(kvm, base_gfn + i,
15681568
pfn << PAGE_SHIFT,
15691569
_PAGE_AR_RWX | _PAGE_MA_WB);

‎arch/x86/kvm/mmu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep)
630630
* kvm mmu, before reclaiming the page, we should
631631
* unmap it from mmu first.
632632
*/
633-
WARN_ON(!kvm_is_mmio_pfn(pfn) && !page_count(pfn_to_page(pfn)));
633+
WARN_ON(!kvm_is_reserved_pfn(pfn) && !page_count(pfn_to_page(pfn)));
634634

635635
if (!shadow_accessed_mask || old_spte & shadow_accessed_mask)
636636
kvm_set_pfn_accessed(pfn);
@@ -2461,7 +2461,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
24612461
spte |= PT_PAGE_SIZE_MASK;
24622462
if (tdp_enabled)
24632463
spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn,
2464-
kvm_is_mmio_pfn(pfn));
2464+
kvm_is_reserved_pfn(pfn));
24652465

24662466
if (host_writable)
24672467
spte |= SPTE_HOST_WRITEABLE;
@@ -2737,7 +2737,7 @@ static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu,
27372737
* PT_PAGE_TABLE_LEVEL and there would be no adjustment done
27382738
* here.
27392739
*/
2740-
if (!is_error_noslot_pfn(pfn) && !kvm_is_mmio_pfn(pfn) &&
2740+
if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn) &&
27412741
level == PT_PAGE_TABLE_LEVEL &&
27422742
PageTransCompound(pfn_to_page(pfn)) &&
27432743
!has_wrprotected_page(vcpu->kvm, gfn, PT_DIRECTORY_LEVEL)) {

‎include/linux/kvm_host.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ void kvm_arch_sync_events(struct kvm *kvm);
703703
int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
704704
void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
705705

706-
bool kvm_is_mmio_pfn(pfn_t pfn);
706+
bool kvm_is_reserved_pfn(pfn_t pfn);
707707

708708
struct kvm_irq_ack_notifier {
709709
struct hlist_node link;

‎virt/kvm/kvm_main.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ EXPORT_SYMBOL_GPL(kvm_rebooting);
107107

108108
static bool largepages_enabled = true;
109109

110-
bool kvm_is_mmio_pfn(pfn_t pfn)
110+
bool kvm_is_reserved_pfn(pfn_t pfn)
111111
{
112112
if (pfn_valid(pfn))
113-
return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
113+
return PageReserved(pfn_to_page(pfn));
114114

115115
return true;
116116
}
@@ -1321,7 +1321,7 @@ static pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
13211321
else if ((vma->vm_flags & VM_PFNMAP)) {
13221322
pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) +
13231323
vma->vm_pgoff;
1324-
BUG_ON(!kvm_is_mmio_pfn(pfn));
1324+
BUG_ON(!kvm_is_reserved_pfn(pfn));
13251325
} else {
13261326
if (async && vma_is_valid(vma, write_fault))
13271327
*async = true;
@@ -1427,7 +1427,7 @@ static struct page *kvm_pfn_to_page(pfn_t pfn)
14271427
if (is_error_noslot_pfn(pfn))
14281428
return KVM_ERR_PTR_BAD_PAGE;
14291429

1430-
if (kvm_is_mmio_pfn(pfn)) {
1430+
if (kvm_is_reserved_pfn(pfn)) {
14311431
WARN_ON(1);
14321432
return KVM_ERR_PTR_BAD_PAGE;
14331433
}
@@ -1456,7 +1456,7 @@ EXPORT_SYMBOL_GPL(kvm_release_page_clean);
14561456

14571457
void kvm_release_pfn_clean(pfn_t pfn)
14581458
{
1459-
if (!is_error_noslot_pfn(pfn) && !kvm_is_mmio_pfn(pfn))
1459+
if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn))
14601460
put_page(pfn_to_page(pfn));
14611461
}
14621462
EXPORT_SYMBOL_GPL(kvm_release_pfn_clean);
@@ -1477,7 +1477,7 @@ static void kvm_release_pfn_dirty(pfn_t pfn)
14771477

14781478
void kvm_set_pfn_dirty(pfn_t pfn)
14791479
{
1480-
if (!kvm_is_mmio_pfn(pfn)) {
1480+
if (!kvm_is_reserved_pfn(pfn)) {
14811481
struct page *page = pfn_to_page(pfn);
14821482
if (!PageReserved(page))
14831483
SetPageDirty(page);
@@ -1487,14 +1487,14 @@ EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty);
14871487

14881488
void kvm_set_pfn_accessed(pfn_t pfn)
14891489
{
1490-
if (!kvm_is_mmio_pfn(pfn))
1490+
if (!kvm_is_reserved_pfn(pfn))
14911491
mark_page_accessed(pfn_to_page(pfn));
14921492
}
14931493
EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed);
14941494

14951495
void kvm_get_pfn(pfn_t pfn)
14961496
{
1497-
if (!kvm_is_mmio_pfn(pfn))
1497+
if (!kvm_is_reserved_pfn(pfn))
14981498
get_page(pfn_to_page(pfn));
14991499
}
15001500
EXPORT_SYMBOL_GPL(kvm_get_pfn);

0 commit comments

Comments
 (0)