[PATCH v2 0/5] Small changes related to prefetch and spurious faults

Yan Zhao posted 5 patches 9 months ago
arch/x86/kvm/mmu.h         | 3 +++
arch/x86/kvm/mmu/mmu.c     | 6 ++++--
arch/x86/kvm/mmu/tdp_mmu.c | 9 ++++-----
3 files changed, 11 insertions(+), 7 deletions(-)
[PATCH v2 0/5] Small changes related to prefetch and spurious faults
Posted by Yan Zhao 9 months ago
Hi

This is v2 of the series for some small changes related to
prefetch/prefault and spurious faults.

Patch 1: Checks if a shadow-present old SPTE is leaf to determine a
         prefetch fault is spurious.

Patch 2: Merges the checks for prefetch and is_access_allowed() for
         spurious faults into a common path.

Patch 3: Adds a warning when the PFN changes on a spurious fault in the TDP
         MMU

Patch 4: Adds a warning when the PFN changes on a shadow-present SPTE in
         the shadow MMU. This implementation differs from the v1
         discussion. Upon reconsideration, I realized that WARN_ON_ONCE()
         in mmu_spte_update() cannot warn when the PFN changes on a
         shadow-present SPTE. Add the warning in mmu_set_spte() and have 
         the prefetch fault to leverage the warning.

Patch 5: Checks req and frees obsolete roots in each MMU reload.

With below scenario
1. add a memslot with size 4K
2. prefault GPA A in the memslot
3. delete the memslot
4. re-add the memslot with size 2M
5. prefault GPA A again.

Patch 1 is required if zap all quirk is disabled in step 3.
Patch 5 is required if zap all is performed in step 3 and if step 2/5 are
        executed before any vcpu_run().

Change log:
v2:
- Check both fault->prefetch and is_access_allowed() in patch 2. (Sean)
- Split patch 3 in v1 into patches 3 and 4.
- Only warn on PFN changes in case of spurious fault in TDP MMU in patch 3.
  (Sean).
- Add patch 4 to warn on PFN changes on shadow-present SPTE in shadow MMU.
- Move kvm_mmu_free_obsolete_roots() from kvm_arch_vcpu_pre_fault_memory()
  to kvm_mmu_reload() in patch 5. (Sean)

Thanks
Yan

v1: https://lore.kernel.org/all/20250207030640.1585-1-yan.y.zhao@intel.com

Yan Zhao (5):
  KVM: x86/mmu: Further check old SPTE is leaf for spurious prefetch
    fault
  KVM: x86/tdp_mmu: Merge prefetch and access checks for spurious faults
  KVM: x86/tdp_mmu: WARN if PFN changes for spurious faults
  KVM: x86/mmu: Warn if PFN changes on shadow-present SPTE in shadow MMU
  KVM: x86/mmu: Check and free obsolete roots in kvm_mmu_reload()

 arch/x86/kvm/mmu.h         | 3 +++
 arch/x86/kvm/mmu/mmu.c     | 6 ++++--
 arch/x86/kvm/mmu/tdp_mmu.c | 9 ++++-----
 3 files changed, 11 insertions(+), 7 deletions(-)

base-commit: c9ea48bb6ee6b28bbc956c1e8af98044618fed5e
-- 
2.43.2
Re: [PATCH v2 0/5] Small changes related to prefetch and spurious faults
Posted by Sean Christopherson 7 months, 2 weeks ago
On Tue, 18 Mar 2025 09:30:37 +0800, Yan Zhao wrote:
> This is v2 of the series for some small changes related to
> prefetch/prefault and spurious faults.
> 
> Patch 1: Checks if a shadow-present old SPTE is leaf to determine a
>          prefetch fault is spurious.
> 
> Patch 2: Merges the checks for prefetch and is_access_allowed() for
>          spurious faults into a common path.
> 
> [...]

Applied 1-4 to kvm-x86 mmu, and patch 5 to fixes.  Thanks!

[1/5] KVM: x86/mmu: Further check old SPTE is leaf for spurious prefetch fault
      https://github.com/kvm-x86/linux/commit/ea9fcdf76d3d
[2/5] KVM: x86/tdp_mmu: Merge prefetch and access checks for spurious faults
      https://github.com/kvm-x86/linux/commit/d17cc13cc484
[3/5] KVM: x86/tdp_mmu: WARN if PFN changes for spurious faults
      https://github.com/kvm-x86/linux/commit/988da7820206
[4/5] KVM: x86/mmu: Warn if PFN changes on shadow-present SPTE in shadow MMU
      https://github.com/kvm-x86/linux/commit/11d45175111d
[5/5] KVM: x86/mmu: Check and free obsolete roots in kvm_mmu_reload()
      https://github.com/kvm-x86/linux/commit/20a6cff3b283
--
https://github.com/kvm-x86/linux/tree/next