On Mon, Mar 03, 2025 at 05:11:31PM +0100, Paolo Bonzini wrote: > On 3/3/25 02:23, Yan Zhao wrote: > > On Sat, Mar 01, 2025 at 02:34:26AM -0500, Paolo Bonzini wrote: > > > From: Yan Zhao <yan.y.zhao@xxxxxxxxx> > > > > > > Introduce supported_quirks in kvm_caps to store platform-specific force-enabled > > > quirks. Any quirk removed from kvm_caps.supported_quirks will never be > > > included in kvm->arch.disabled_quirks, and will cause the ioctl to fail if > > > passed to KVM_ENABLE_CAP(KVM_CAP_DISABLE_QUIRKS2). > > > > > > Signed-off-by: Yan Zhao <yan.y.zhao@xxxxxxxxx> > > > Message-ID: <20250224070832.31394-1-yan.y.zhao@xxxxxxxxx> > > > Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> > > > --- > > > arch/x86/kvm/x86.c | 7 ++++--- > > > arch/x86/kvm/x86.h | 2 ++ > > > 2 files changed, 6 insertions(+), 3 deletions(-) > > > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > > index fd0a44e59314..a97e58916b6a 100644 > > > --- a/arch/x86/kvm/x86.c > > > +++ b/arch/x86/kvm/x86.c > > > @@ -4782,7 +4782,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) > > > r = enable_pmu ? KVM_CAP_PMU_VALID_MASK : 0; > > > break; > > > case KVM_CAP_DISABLE_QUIRKS2: > > > - r = KVM_X86_VALID_QUIRKS; > > > + r = kvm_caps.supported_quirks; > > > > As the concern raised in [1], it's confusing for > > KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT to be present on AMD's platforms while not > > present on Intel's non-self-snoop platforms. > > To make it less confusing, let's rename it to > KVM_X86_QUIRK_IGNORE_GUEST_PAT. So if userspace wants to say "I don't want Hmm, it looks that quirk IGNORE_GUEST_PAT is effectively always enabled on Intel platforms without enabling EPT. And kvm_mmu_may_ignore_guest_pat() does not care quirk IGNORE_GUEST_PAT on AMD or on Intel when enable_ept is 0. bool kvm_mmu_may_ignore_guest_pat(struct kvm *kvm) { return shadow_memtype_mask && kvm_check_has_quirk(kvm, KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT); } After renaming the quirk, should we also hide quirk IGNORE_GUEST_PAT from being exposed in KVM_CAP_DISABLE_QUIRKS2 when enable_ept is 0? However, doing so will complicate kvm_noncoherent_dma_assignment_start_or_stop(). > KVM to ignore guest's PAT!", it can do so easily: > > - it can check unconditionally that the quirk is included in > KVM_CAP_DISABLE_QUIRKS2, and it will pass on both Intel with self-snoop with > AMD; So, when userspace finds the quirk IGNORE_GUEST_PAT is exposed in KVM_CAP_DISABLE_QUIRKS2, it cannot treat this as an implication that KVM is currently ignoring guest PAT, but it only means that this is a new KVM with quirk IGNORE_GUEST_PAT taken into account. > - it can pass it unconditionally to KVM_X86_QUIRK_IGNORE_GUEST_PAT, knowing > that PAT will be honored. For AMD, since userspace does not explicitly disable quirk IGNORE_GUEST_PAT, you introduced kvm_caps.inapplicable_quirks to allow IGNORE_GUEST_PAT to be listed in KVM_CAP_DISABLED_QUIRKS.