Is this understanding correct? > But KVM_CHECK_EXTENSION(KVM_CAP_DISABLE_QUIRKS2) will *not* include the > quirk on Intel without self-snoop, which lets userspace detect the condition > and raise an error. This is better than introducing a new case in the API > "the bit is returned by KVM_CHECK_EXTENSION, but rejected by > KVM_ENABLE_CAP". Such a new case would inevitably lead to > KVM_CAP_DISABLE_QUIRKS3. :) Agreed. Thanks for the explanation:) > > > Or what about introduce kvm_caps.force_enabled_quirk? > > > > if (!static_cpu_has(X86_FEATURE_SELFSNOOP)) > > kvm_caps.force_enabled_quirks |= KVM_X86_QUIRK_EPT_IGNORE_GUEST_PAT; > > That would also make it harder for userspace to understand what's going on. Right. > > [1] https://lore.kernel.org/all/Z8UBpC76CyxCIRiU@xxxxxxxxxxxxxxxxxxxxxxxxx/ > > > break; > > > case KVM_CAP_X86_NOTIFY_VMEXIT: > > > r = kvm_caps.has_notify_vmexit; > > > @@ -6521,11 +6521,11 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, > > > switch (cap->cap) { > > > case KVM_CAP_DISABLE_QUIRKS2: > > > r = -EINVAL; > > > - if (cap->args[0] & ~KVM_X86_VALID_QUIRKS) > > > + if (cap->args[0] & ~kvm_caps.supported_quirks) > > > break; > > > fallthrough; > > > case KVM_CAP_DISABLE_QUIRKS: > > > - kvm->arch.disabled_quirks = cap->args[0]; > > > + kvm->arch.disabled_quirks = cap->args[0] & kvm_caps.supported_quirks; > > > > Will this break the uapi of KVM_CAP_DISABLE_QUIRKS? > > My understanding is that only KVM_CAP_DISABLE_QUIRKS2 filters out invalid > > quirks. > > The difference between KVM_CAP_DISABLE_QUIRKS and KVM_CAP_DISABLE_QUIRKS2 is > only that invalid values do not cause an error; but userspace cannot know > what is in kvm->arch.disabled_quirks, so KVM can change the value that is > stored there. Ah, it makes sense. Thanks Yan > > > > r = 0; > > > break; > > > case KVM_CAP_SPLIT_IRQCHIP: { > > > @@ -9775,6 +9775,7 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) > > > kvm_host.xcr0 = xgetbv(XCR_XFEATURE_ENABLED_MASK); > > > kvm_caps.supported_xcr0 = kvm_host.xcr0 & KVM_SUPPORTED_XCR0; > > > } > > > + kvm_caps.supported_quirks = KVM_X86_VALID_QUIRKS; > > > kvm_caps.inapplicable_quirks = 0; > > > rdmsrl_safe(MSR_EFER, &kvm_host.efer); > > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > > > index 9af199c8e5c8..f2672b14388c 100644 > > > --- a/arch/x86/kvm/x86.h > > > +++ b/arch/x86/kvm/x86.h > > > @@ -34,6 +34,8 @@ struct kvm_caps { > > > u64 supported_xcr0; > > > u64 supported_xss; > > > u64 supported_perf_cap; > > > + > > > + u64 supported_quirks; > > > u64 inapplicable_quirks; > > > }; > > > -- > > > 2.43.5 > > > > > > > > >