[PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups

Sean Christopherson posted 16 patches 9 months ago
There is a newer version of this series
arch/x86/include/asm/kvm_host.h |  45 ++++-----
arch/x86/kvm/mmu.h              |   4 +-
arch/x86/kvm/mmu/mmu.c          | 159 +++++++++++++++++++-------------
arch/x86/kvm/mmu/mmu_internal.h |  24 ++++-
arch/x86/kvm/mmu/mmutrace.h     |   2 +-
arch/x86/kvm/svm/svm.c          |   9 ++
6 files changed, 151 insertions(+), 92 deletions(-)
[PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups
Posted by Sean Christopherson 9 months ago
This is a combination of prep work for TDX and SNP, and a clean up of the
page fault path to (hopefully) make it easier to follow the rules for
private memory, noslot faults, writes to read-only slots, etc.

Paolo, this is the series I mentioned in your TDX/SNP prep work series.
Stating the obvious, these

  KVM: x86/mmu: Pass full 64-bit error code when handling page faults
  KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler

are the drop-in replacements.

Isaku Yamahata (1):
  KVM: x86/mmu: Pass full 64-bit error code when handling page faults

Sean Christopherson (15):
  KVM: x86/mmu: Exit to userspace with -EFAULT if private fault hits
    emulation
  KVM: x86: Remove separate "bit" defines for page fault error code
    masks
  KVM: x86: Define more SEV+ page fault error bits/flags for #NPF
  KVM: x86/mmu: Use synthetic page fault error code to indicate private
    faults
  KVM: x86/mmu: WARN if upper 32 bits of legacy #PF error code are
    non-zero
  KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler
  KVM: x86/mmu: WARN and skip MMIO cache on private, reserved page
    faults
  KVM: x86/mmu: Move private vs. shared check above slot validity checks
  KVM: x86/mmu: Don't force emulation of L2 accesses to non-APIC
    internal slots
  KVM: x86/mmu: Explicitly disallow private accesses to emulated MMIO
  KVM: x86/mmu: Move slot checks from __kvm_faultin_pfn() to
    kvm_faultin_pfn()
  KVM: x86/mmu: Handle no-slot faults at the beginning of
    kvm_faultin_pfn()
  KVM: x86/mmu: Set kvm_page_fault.hva to KVM_HVA_ERR_BAD for "no slot"
    faults
  KVM: x86/mmu: Initialize kvm_page_fault's pfn and hva to error values
  KVM: x86/mmu: Sanity check that __kvm_faultin_pfn() doesn't create
    noslot pfns

 arch/x86/include/asm/kvm_host.h |  45 ++++-----
 arch/x86/kvm/mmu.h              |   4 +-
 arch/x86/kvm/mmu/mmu.c          | 159 +++++++++++++++++++-------------
 arch/x86/kvm/mmu/mmu_internal.h |  24 ++++-
 arch/x86/kvm/mmu/mmutrace.h     |   2 +-
 arch/x86/kvm/svm/svm.c          |   9 ++
 6 files changed, 151 insertions(+), 92 deletions(-)


base-commit: ec1e3d33557babed2c2c2c7da6e84293c2f56f58
-- 
2.44.0.278.ge034bb2e1d-goog
Re: [PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups
Posted by Paolo Bonzini 7 months, 1 week ago
On Wed, Feb 28, 2024 at 3:41 AM Sean Christopherson <seanjc@google.com> wrote:
>
> This is a combination of prep work for TDX and SNP, and a clean up of the
> page fault path to (hopefully) make it easier to follow the rules for
> private memory, noslot faults, writes to read-only slots, etc.
>
> Paolo, this is the series I mentioned in your TDX/SNP prep work series.
> Stating the obvious, these
>
>   KVM: x86/mmu: Pass full 64-bit error code when handling page faults
>   KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler
>
> are the drop-in replacements.

Applied to kvm-coco-queue, thanks, and these to kvm/queue as well:

 KVM: x86/mmu: Exit to userspace with -EFAULT if private fault hits emulation
 KVM: x86: Remove separate "bit" defines for page fault error code masks
 KVM: x86: Define more SEV+ page fault error bits/flags for #NPF
 KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler
 KVM: x86/mmu: Pass full 64-bit error code when handling page faults
 KVM: x86/mmu: WARN if upper 32 bits of legacy #PF error code are non-zero

I have made a little hack for kvm-coco-queue, preserving for now the
usage of PFERR_GUEST_ENC_MASK in case people were relying on the
branch, to limit the rebase pain.

The remaining parts are split into a "[TO SQUASH] KVM: x86/mmu: Use
synthetic page fault error code to indicate private faults" commit at
the end of the branch.

Paolo

> Isaku Yamahata (1):
>   KVM: x86/mmu: Pass full 64-bit error code when handling page faults
>
> Sean Christopherson (15):
>   KVM: x86/mmu: Exit to userspace with -EFAULT if private fault hits
>     emulation
>   KVM: x86: Remove separate "bit" defines for page fault error code
>     masks
>   KVM: x86: Define more SEV+ page fault error bits/flags for #NPF
>   KVM: x86/mmu: Use synthetic page fault error code to indicate private
>     faults
>   KVM: x86/mmu: WARN if upper 32 bits of legacy #PF error code are
>     non-zero
>   KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler
>   KVM: x86/mmu: WARN and skip MMIO cache on private, reserved page
>     faults
>   KVM: x86/mmu: Move private vs. shared check above slot validity checks
>   KVM: x86/mmu: Don't force emulation of L2 accesses to non-APIC
>     internal slots
>   KVM: x86/mmu: Explicitly disallow private accesses to emulated MMIO
>   KVM: x86/mmu: Move slot checks from __kvm_faultin_pfn() to
>     kvm_faultin_pfn()
>   KVM: x86/mmu: Handle no-slot faults at the beginning of
>     kvm_faultin_pfn()
>   KVM: x86/mmu: Set kvm_page_fault.hva to KVM_HVA_ERR_BAD for "no slot"
>     faults
>   KVM: x86/mmu: Initialize kvm_page_fault's pfn and hva to error values
>   KVM: x86/mmu: Sanity check that __kvm_faultin_pfn() doesn't create
>     noslot pfns
>
>  arch/x86/include/asm/kvm_host.h |  45 ++++-----
>  arch/x86/kvm/mmu.h              |   4 +-
>  arch/x86/kvm/mmu/mmu.c          | 159 +++++++++++++++++++-------------
>  arch/x86/kvm/mmu/mmu_internal.h |  24 ++++-
>  arch/x86/kvm/mmu/mmutrace.h     |   2 +-
>  arch/x86/kvm/svm/svm.c          |   9 ++
>  6 files changed, 151 insertions(+), 92 deletions(-)
>
>
> base-commit: ec1e3d33557babed2c2c2c7da6e84293c2f56f58
> --
> 2.44.0.278.ge034bb2e1d-goog
>
Re: [PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups
Posted by Xiaoyao Li 7 months, 1 week ago
On 4/17/2024 8:48 PM, Paolo Bonzini wrote:
> On Wed, Feb 28, 2024 at 3:41 AM Sean Christopherson <seanjc@google.com> wrote:
>>
>> This is a combination of prep work for TDX and SNP, and a clean up of the
>> page fault path to (hopefully) make it easier to follow the rules for
>> private memory, noslot faults, writes to read-only slots, etc.
>>
>> Paolo, this is the series I mentioned in your TDX/SNP prep work series.
>> Stating the obvious, these
>>
>>    KVM: x86/mmu: Pass full 64-bit error code when handling page faults
>>    KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler
>>
>> are the drop-in replacements.
> 
> Applied to kvm-coco-queue, thanks, and these to kvm/queue as well:
> 
>   KVM: x86/mmu: Exit to userspace with -EFAULT if private fault hits emulation
>   KVM: x86: Remove separate "bit" defines for page fault error code masks
>   KVM: x86: Define more SEV+ page fault error bits/flags for #NPF
>   KVM: x86: Move synthetic PFERR_* sanity checks to SVM's #NPF handler
>   KVM: x86/mmu: Pass full 64-bit error code when handling page faults
>   KVM: x86/mmu: WARN if upper 32 bits of legacy #PF error code are non-zero

Paolo,

It seems you forgot to incorporate the review comment into the patch 
before you queued them to kvm/queue.

e.g., the comment from Dongli to

KVM: x86: Define more SEV+ page fault error bits/flags for #NPF

https://lore.kernel.org/all/12f0b643-e2e8-8a9a-b264-5c7c460f1a24@oracle.com/

Re: [PATCH 00/16] KVM: x86/mmu: Page fault and MMIO cleanups
Posted by Sean Christopherson 7 months, 1 week ago
On Wed, Apr 17, 2024, Paolo Bonzini wrote:
> On Wed, Feb 28, 2024 at 3:41 AM Sean Christopherson <seanjc@google.com> wrote:
> I have made a little hack for kvm-coco-queue, preserving for now the
> usage of PFERR_GUEST_ENC_MASK in case people were relying on the
> branch, to limit the rebase pain.
> 
> The remaining parts are split into a "[TO SQUASH] KVM: x86/mmu: Use
> synthetic page fault error code to indicate private faults" commit at
> the end of the branch.

Ahh, I should have read this before reviewing the other patches.  Thanks!