Skip to content

KVM: x86: Introduce quirk KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT

Yan Zhao kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3KVM: x86: Introduce supported_quirks for platform-specific valid quirksarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c arch/x86/kvm/x86.h+11 -80 replies
2/3KVM: x86: Introduce Intel specific quirk KVM_X86_QUIRK_EPT_IGNORE_GUEST_PATDocumentation/virt/kvm/api.rst arch/x86/include/uapi/asm/kvm.h arch/x86/kvm/mmu.h +3 more+72 -140 replies
3/3KVM: TDX: Always honor guest PAT on TDX enabled platformsDocumentation/virt/kvm/api.rst arch/x86/kvm/vmx/main.c arch/x86/kvm/vmx/tdx.c+17 -90 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] KVM: x86: Introduce quirk KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT

This series introduces a quirk KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT as suggested by Paolo and Sean [1].

The purpose of introducing this quirk is to allow KVM to honor guest PAT on Intel platforms with self-snoop feature. This support was previously reverted by commit 9d70f3fec144 ("Revert "KVM: VMX: Always honor guest PAT on CPUs that support self-snoop"") due to a reported broken of an old bochs driver which incorrectly set memory type to UC but did not expect that UC would be very slow on certain Intel platforms.

Sean previously suggested to bottom out if the UC slowness issue is working as intended so that we can enable the quirk only when the VMs are affected by the old unmodifiable guests [2]. After consulting with CPU architects, it's told that this behavior is expected on ICX/SPR Xeon platforms due to the snooping implementation.

So, implement the quirk such that KVM enables it by default on all Intel non-TDX platforms while having the quirk explicitly reference the old unmodifiable guests that rely on KVM to force memory type to WB. Newer userspace can disable the quirk by default and only leave it enabled if an old unmodifiable guest is an concern.

The quirk is platform-specific valid, available only on Intel non-TDX platforms. It is absent on Intel TDX and AMD platforms, where KVM always honors guest PAT.

Patch 1 does the preparation of making quirks platform-specific valid. Patch 2 makes the quirk to be present on Intel and absent on AMD. Patch 3 makes the quirk to be absent on Intel TDX and self-snoop a hard
dependency to enable TDX [3].
As a new platform, TDX is always running on CPUs with self-snoop feature. It has no worry to break old yet unmodifiable guests. Simply have KVM always honor guest PAT on TDX enabled platforms. Attaching/detaching non-coherent DMA devices would not lead to mirrored EPTs being zapped for TDs then. A previous attempt for this purpose is at [4].

This series is based on kvm-coco-queue. It was supposed to be included in TDX's "the rest" section. We post it separately to start review earlier.

Patches 1 and 2 are changes to the generic code, which can also be applied to kvm/queue. A proposal is to have them go into kvm/queue and we rebase on that.

Patch 3 can be included in TDX's "the rest" section in the end.

Thanks
Yan

[1] https://lore.kernel.org/kvm/CABgObfa=t1dGR5cEhbUqVWTD03vZR4QrzEUgHxq+3JJ7YsA9pA@mail.gmail.com
[2] https://lore.kernel.org/kvm/[email protected]
[3] https://lore.kernel.org/kvm/[email protected]
[4] https://lore.kernel.org/kvm/[email protected]

Yan Zhao (3):
KVM: x86: Introduce supported_quirks for platform-specific valid
quirks
KVM: x86: Introduce Intel specific quirk
KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT
KVM: TDX: Always honor guest PAT on TDX enabled platforms

 Documentation/virt/kvm/api.rst  | 30 +++++++++++++++++++++++++
 arch/x86/include/asm/kvm_host.h |  2 +-
 arch/x86/include/uapi/asm/kvm.h |  1 +
 arch/x86/kvm/mmu.h              |  2 +-
 arch/x86/kvm/mmu/mmu.c          | 14 +++++++-----
 arch/x86/kvm/vmx/main.c         |  1 +
 arch/x86/kvm/vmx/tdx.c          |  5 +++++
 arch/x86/kvm/vmx/vmx.c          | 39 +++++++++++++++++++++++++++------
 arch/x86/kvm/x86.c              |  7 +++---
 arch/x86/kvm/x86.h              | 12 +++++-----
 10 files changed, 91 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.2