Skip to content

KVM: MMU: Fix a refcount bug with ZONE_DEVICE pages

Sean Christopherson kvm lkml 2 versions – Applied

Status from this message: Queued, thanks -- the other two will wait for after the merge window to

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 4 repliesApplied
  2. v12 patches 22 repliesSuperseded

Changes in v2 from the cover letter

- Remove the kvm_is_zone_device_pfn(pfn) check from kvm_get_pfn(). It's not entirely clear whether or not the hva_to_pfn_remapped() case is actually broken, e.g. KVM's page fault handler is likely ok, whereas not calling get_page() willl definitely cause breakage as KVM would later call put_page() on the pfn/page. [Paolo]

- WARN if kvm_is_zone_device_pfn() is called without the underlying page being pinned. This won't necessarily catch all bugs, e.g. if the above hva_to_pfn_remapped case is indeed broken, but will prevent completely bogus usage. [Dan]

- Remove the is_error_pfn() check from transparent_hugepage_adjust() instead of carrying it forward into the new kvm_is_hugepage_allowed() helper. [Paolo]

[1] http://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/3KVM: MMU: Do not treat ZONE_DEVICE pages as being reservedarch/x86/kvm/mmu.c include/linux/kvm_host.h virt/kvm/kvm_main.c+28 -74 replies
2/3KVM: x86/mmu: Remove superfluous is_error_pfn() check from THP adjustarch/x86/kvm/mmu.c+1 -10 replies
3/3KVM: x86/mmu: Add helper to consolidate huge page promotionarch/x86/kvm/mmu.c+9 -60 replies

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

PatchDavid HildenbrandDan Williams
1/3Debugged-by A-b A-b
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] KVM: MMU: Fix a refcount bug with ZONE_DEVICE pages

This mini-series fixes a suspected, but technically unconfirmed, bug in KVM related to ZONE_DEVICE pages. The suspected issue is that KVM treats ZONE_DEVICE pages as reserved PFNs, and so doesn't put references to such pages when dropping references via KVM's generic kvm_release_pfn_clean().

David Hildenbrand uncovered the bug during a discussion about removing PG_reserved from ZONE_DEVICE pages, after Dan Williams pointed out[1] that there was a bug report from Adam Borowski[2] that was likely related to KVM's interaction with PageReserved().

Patch 1/3 contains the actual fix, patches 2/3 and 3/3 are minor cleanup that is mostly unrelated, but dependent and prompted by the fix itself.

v2:
- Remove the kvm_is_zone_device_pfn(pfn) check from kvm_get_pfn(). It's not entirely clear whether or not the hva_to_pfn_remapped() case is actually broken, e.g. KVM's page fault handler is likely ok, whereas not calling get_page() willl definitely cause breakage as KVM would later call put_page() on the pfn/page. [Paolo]

- WARN if kvm_is_zone_device_pfn() is called without the underlying page being pinned. This won't necessarily catch all bugs, e.g. if the above hva_to_pfn_remapped case is indeed broken, but will prevent completely bogus usage. [Dan]

- Remove the is_error_pfn() check from transparent_hugepage_adjust() instead of carrying it forward into the new kvm_is_hugepage_allowed() helper. [Paolo]

[1] http://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]

Sean Christopherson (3):
KVM: MMU: Do not treat ZONE_DEVICE pages as being reserved
KVM: x86/mmu: Remove superfluous is_error_pfn() check from THP adjust
KVM: x86/mmu: Add helper to consolidate huge page promotion

 arch/x86/kvm/mmu.c       | 15 +++++++++------
 include/linux/kvm_host.h |  1 +
 virt/kvm/kvm_main.c      | 26 +++++++++++++++++++++++---
 3 files changed, 33 insertions(+), 9 deletions(-)
Signature · 1 line
2.24.0