kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test
@ 2021-12-16 16:52 Vitaly Kuznetsov
  2021-12-16 16:52 ` [PATCH v2 1/2] KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible CPUIDs Vitaly Kuznetsov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2021-12-16 16:52 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, oliver.sang,
	Like Xu, linux-kernel

This is a continuation of "KVM: selftests: Avoid KVM_SET_CPUID2 after 
KVM_RUN in vmx_pmu_msrs_test" work. Instead of fixing the immediate issue,
drop incorrect check in KVM which was making the result of host initiated
writes to MSR_IA32_PERF_CAPABILITIES dependent on guest visible CPUIDs and
the corresponding tests in vmx_pmu_msrs_test, this will also make the issue
reported by kernel test robot to go away.

Vitaly Kuznetsov (2):
  KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible
    CPUIDs
  KVM: x86: Drop guest CPUID check for host initiated writes to
    MSR_IA32_PERF_CAPABILITIES

 arch/x86/kvm/x86.c                              |  2 +-
 .../selftests/kvm/x86_64/vmx_pmu_msrs_test.c    | 17 -----------------
 2 files changed, 1 insertion(+), 18 deletions(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible CPUIDs
  2021-12-16 16:52 [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Vitaly Kuznetsov
@ 2021-12-16 16:52 ` Vitaly Kuznetsov
  2021-12-16 16:52 ` [PATCH v2 2/2] KVM: x86: Drop guest CPUID check for host initiated writes to MSR_IA32_PERF_CAPABILITIES Vitaly Kuznetsov
  2021-12-19 19:24 ` [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2021-12-16 16:52 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, oliver.sang,
	Like Xu, linux-kernel

Host initiated writes to MSR_IA32_PERF_CAPABILITIES should not depend
on guest visible CPUIDs and (incorrect) KVM logic implementing it is
about to change. Also, KVM_SET_CPUID{,2} after KVM_RUN is now forbidden
and causes test to fail.

Reported-by: kernel test robot <oliver.sang@intel.com>
Fixes: feb627e8d6f6 ("KVM: x86: Forbid KVM_SET_CPUID{,2} after KVM_RUN")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 .../selftests/kvm/x86_64/vmx_pmu_msrs_test.c    | 17 -----------------
 1 file changed, 17 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c b/tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c
index 23051d84b907..2454a1f2ca0c 100644
--- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_msrs_test.c
@@ -110,22 +110,5 @@ int main(int argc, char *argv[])
 	ret = _vcpu_set_msr(vm, 0, MSR_IA32_PERF_CAPABILITIES, PMU_CAP_LBR_FMT);
 	TEST_ASSERT(ret == 0, "Bad PERF_CAPABILITIES didn't fail.");
 
-	/* testcase 4, set capabilities when we don't have PDCM bit */
-	entry_1_0->ecx &= ~X86_FEATURE_PDCM;
-	vcpu_set_cpuid(vm, VCPU_ID, cpuid);
-	ret = _vcpu_set_msr(vm, 0, MSR_IA32_PERF_CAPABILITIES, host_cap.capabilities);
-	TEST_ASSERT(ret == 0, "Bad PERF_CAPABILITIES didn't fail.");
-
-	/* testcase 5, set capabilities when we don't have PMU version bits */
-	entry_1_0->ecx |= X86_FEATURE_PDCM;
-	eax.split.version_id = 0;
-	entry_1_0->ecx = eax.full;
-	vcpu_set_cpuid(vm, VCPU_ID, cpuid);
-	ret = _vcpu_set_msr(vm, 0, MSR_IA32_PERF_CAPABILITIES, PMU_CAP_FW_WRITES);
-	TEST_ASSERT(ret == 0, "Bad PERF_CAPABILITIES didn't fail.");
-
-	vcpu_set_msr(vm, 0, MSR_IA32_PERF_CAPABILITIES, 0);
-	ASSERT_EQ(vcpu_get_msr(vm, VCPU_ID, MSR_IA32_PERF_CAPABILITIES), 0);
-
 	kvm_vm_free(vm);
 }
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] KVM: x86: Drop guest CPUID check for host initiated writes to MSR_IA32_PERF_CAPABILITIES
  2021-12-16 16:52 [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Vitaly Kuznetsov
  2021-12-16 16:52 ` [PATCH v2 1/2] KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible CPUIDs Vitaly Kuznetsov
@ 2021-12-16 16:52 ` Vitaly Kuznetsov
  2021-12-19 19:24 ` [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2021-12-16 16:52 UTC (permalink / raw)
  To: kvm, Paolo Bonzini
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, oliver.sang,
	Like Xu, linux-kernel

The ability to write to MSR_IA32_PERF_CAPABILITIES from the host should
not depend on guest visible CPUID entries, even if just to allow
creating/restoring guest MSRs and CPUIDs in any sequence.

Fixes: 27461da31089 ("KVM: x86/pmu: Support full width counting")
Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0cf1082455df..9a2972fdae82 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3413,7 +3413,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 
 		if (!msr_info->host_initiated)
 			return 1;
-		if (guest_cpuid_has(vcpu, X86_FEATURE_PDCM) && kvm_get_msr_feature(&msr_ent))
+		if (kvm_get_msr_feature(&msr_ent))
 			return 1;
 		if (data & ~msr_ent.data)
 			return 1;
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test
  2021-12-16 16:52 [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Vitaly Kuznetsov
  2021-12-16 16:52 ` [PATCH v2 1/2] KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible CPUIDs Vitaly Kuznetsov
  2021-12-16 16:52 ` [PATCH v2 2/2] KVM: x86: Drop guest CPUID check for host initiated writes to MSR_IA32_PERF_CAPABILITIES Vitaly Kuznetsov
@ 2021-12-19 19:24 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-12-19 19:24 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, oliver.sang,
	Like Xu, linux-kernel

On 12/16/21 17:52, Vitaly Kuznetsov wrote:
> This is a continuation of "KVM: selftests: Avoid KVM_SET_CPUID2 after
> KVM_RUN in vmx_pmu_msrs_test" work. Instead of fixing the immediate issue,
> drop incorrect check in KVM which was making the result of host initiated
> writes to MSR_IA32_PERF_CAPABILITIES dependent on guest visible CPUIDs and
> the corresponding tests in vmx_pmu_msrs_test, this will also make the issue
> reported by kernel test robot to go away.
> 
> Vitaly Kuznetsov (2):
>    KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible
>      CPUIDs
>    KVM: x86: Drop guest CPUID check for host initiated writes to
>      MSR_IA32_PERF_CAPABILITIES
> 
>   arch/x86/kvm/x86.c                              |  2 +-
>   .../selftests/kvm/x86_64/vmx_pmu_msrs_test.c    | 17 -----------------
>   2 files changed, 1 insertion(+), 18 deletions(-)
> 

Queued, thanks,

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-19 19:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 16:52 [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Vitaly Kuznetsov
2021-12-16 16:52 ` [PATCH v2 1/2] KVM: selftests: vmx_pmu_msrs_test: Drop tests mangling guest visible CPUIDs Vitaly Kuznetsov
2021-12-16 16:52 ` [PATCH v2 2/2] KVM: x86: Drop guest CPUID check for host initiated writes to MSR_IA32_PERF_CAPABILITIES Vitaly Kuznetsov
2021-12-19 19:24 ` [PATCH v2 0/2] KVM: x86: Fix MSR_IA32_PERF_CAPABILITIES writes check and vmx_pmu_msrs_test Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).