LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2 0/3] KVM: VMX: Clean up RTIT MAXPHYADDR usage
@ 2020-09-23 16:36 Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 1/3] KVM: VMX: Use precomputed MAXPHYADDR for RTIT base MSR check Sean Christopherson
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sean Christopherson @ 2020-09-23 16:36 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
Stop using cpuid_query_maxphyaddr() for a random RTIT MSR check and
unexport said function to discourage future use.
v2:
- Rebased to kvm/queue, commit e1ba1a15af73 ("KVM: SVM: Enable INVPCID
feature on AMD").
Sean Christopherson (3):
KVM: VMX: Use precomputed MAXPHYADDR for RTIT base MSR check
KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function
KVM: x86: Unexport cpuid_query_maxphyaddr()
arch/x86/kvm/cpuid.c | 1 -
arch/x86/kvm/vmx/vmx.c | 11 +++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
--
2.28.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] KVM: VMX: Use precomputed MAXPHYADDR for RTIT base MSR check
2020-09-23 16:36 [PATCH v2 0/3] KVM: VMX: Clean up RTIT MAXPHYADDR usage Sean Christopherson
@ 2020-09-23 16:36 ` Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 3/3] KVM: x86: Unexport cpuid_query_maxphyaddr() Sean Christopherson
2 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2020-09-23 16:36 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
Use cpuid_maxphyaddr() instead of cpuid_query_maxphyaddr() for the
RTIT base MSR check. There is no reason to recompute MAXPHYADDR as the
precomputed version is synchronized with CPUID updates, and
MSR_IA32_RTIT_OUTPUT_BASE is not written between stuffing CPUID and
refreshing vcpu->arch.maxphyaddr.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 6f9a0c6d5dc5..be82da055fc4 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -147,7 +147,7 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
RTIT_STATUS_BYTECNT))
#define MSR_IA32_RTIT_OUTPUT_BASE_MASK \
- (~((1UL << cpuid_query_maxphyaddr(vcpu)) - 1) | 0x7f)
+ (~((1UL << cpuid_maxphyaddr(vcpu)) - 1) | 0x7f)
/*
* These 2 parameters are used to config the controls for Pause-Loop Exiting:
--
2.28.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function
2020-09-23 16:36 [PATCH v2 0/3] KVM: VMX: Clean up RTIT MAXPHYADDR usage Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 1/3] KVM: VMX: Use precomputed MAXPHYADDR for RTIT base MSR check Sean Christopherson
@ 2020-09-23 16:36 ` Sean Christopherson
2020-09-23 17:07 ` Paolo Bonzini
2020-09-23 16:36 ` [PATCH v2 3/3] KVM: x86: Unexport cpuid_query_maxphyaddr() Sean Christopherson
2 siblings, 1 reply; 6+ messages in thread
From: Sean Christopherson @ 2020-09-23 16:36 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
Replace the subtly not-a-constant MSR_IA32_RTIT_OUTPUT_BASE_MASK with a
proper helper function to check whether or not the specified base is
valid. Blindly referencing the local 'vcpu' is especially nasty.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
arch/x86/kvm/vmx/vmx.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index be82da055fc4..0d41faf63b57 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -146,9 +146,6 @@ module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
RTIT_STATUS_ERROR | RTIT_STATUS_STOPPED | \
RTIT_STATUS_BYTECNT))
-#define MSR_IA32_RTIT_OUTPUT_BASE_MASK \
- (~((1UL << cpuid_maxphyaddr(vcpu)) - 1) | 0x7f)
-
/*
* These 2 parameters are used to config the controls for Pause-Loop Exiting:
* ple_gap: upper bound on the amount of time between two successive
@@ -1037,6 +1034,12 @@ static inline bool pt_can_write_msr(struct vcpu_vmx *vmx)
!(vmx->pt_desc.guest.ctl & RTIT_CTL_TRACEEN);
}
+static inline bool pt_output_base_valid(struct kvm_vcpu *vcpu, u64 base)
+{
+ /* The base must be 128-byte aligned and a legal physical address. */
+ return !(base & (~((1UL << cpuid_maxphyaddr(vcpu)) - 1) | 0x7f));
+}
+
static inline void pt_load_msr(struct pt_ctx *ctx, u32 addr_range)
{
u32 i;
@@ -2167,7 +2170,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
!intel_pt_validate_cap(vmx->pt_desc.caps,
PT_CAP_single_range_output))
return 1;
- if (data & MSR_IA32_RTIT_OUTPUT_BASE_MASK)
+ if (!pt_output_base_valid(vcpu, data))
return 1;
vmx->pt_desc.guest.output_base = data;
break;
--
2.28.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] KVM: x86: Unexport cpuid_query_maxphyaddr()
2020-09-23 16:36 [PATCH v2 0/3] KVM: VMX: Clean up RTIT MAXPHYADDR usage Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 1/3] KVM: VMX: Use precomputed MAXPHYADDR for RTIT base MSR check Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function Sean Christopherson
@ 2020-09-23 16:36 ` Sean Christopherson
2 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2020-09-23 16:36 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, kvm, linux-kernel
Stop exporting cpuid_query_maxphyaddr() now that it's not being abused
by VMX.
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
arch/x86/kvm/cpuid.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 3fd6eec202d7..dc95b638911e 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -186,7 +186,6 @@ int cpuid_query_maxphyaddr(struct kvm_vcpu *vcpu)
not_found:
return 36;
}
-EXPORT_SYMBOL_GPL(cpuid_query_maxphyaddr);
/* when an old userspace process fills a new kernel module */
int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
--
2.28.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function
2020-09-23 16:36 ` [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function Sean Christopherson
@ 2020-09-23 17:07 ` Paolo Bonzini
2020-09-24 18:01 ` Sean Christopherson
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2020-09-23 17:07 UTC (permalink / raw)
To: Sean Christopherson
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On 23/09/20 18:36, Sean Christopherson wrote:
> +static inline bool pt_output_base_valid(struct kvm_vcpu *vcpu, u64 base)
> +{
> + /* The base must be 128-byte aligned and a legal physical address. */
> + return !(base & (~((1UL << cpuid_maxphyaddr(vcpu)) - 1) | 0x7f));
> +}
The fact that you deemed a comment necessary says something already. :)
What about:
return !kvm_mmu_is_illegal_gpa(vcpu, base) && !(base & 0x7f);
(where this new usage makes it obvious that mmu should have been vcpu).
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function
2020-09-23 17:07 ` Paolo Bonzini
@ 2020-09-24 18:01 ` Sean Christopherson
0 siblings, 0 replies; 6+ messages in thread
From: Sean Christopherson @ 2020-09-24 18:01 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
linux-kernel
On Wed, Sep 23, 2020 at 07:07:22PM +0200, Paolo Bonzini wrote:
> On 23/09/20 18:36, Sean Christopherson wrote:
> > +static inline bool pt_output_base_valid(struct kvm_vcpu *vcpu, u64 base)
> > +{
> > + /* The base must be 128-byte aligned and a legal physical address. */
> > + return !(base & (~((1UL << cpuid_maxphyaddr(vcpu)) - 1) | 0x7f));
> > +}
>
> The fact that you deemed a comment necessary says something already. :)
> What about:
>
> return !kvm_mmu_is_illegal_gpa(vcpu, base) && !(base & 0x7f);
>
> (where this new usage makes it obvious that mmu should have been vcpu).
Ya. I think it was a sort of sunk cost fallacy. Dammit, I spent all that
time figuring out what this code does, I'm keeping it!!!
v3 incoming...
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-09-24 18:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 16:36 [PATCH v2 0/3] KVM: VMX: Clean up RTIT MAXPHYADDR usage Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 1/3] KVM: VMX: Use precomputed MAXPHYADDR for RTIT base MSR check Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 2/3] KVM: VMX: Replace MSR_IA32_RTIT_OUTPUT_BASE_MASK with helper function Sean Christopherson
2020-09-23 17:07 ` Paolo Bonzini
2020-09-24 18:01 ` Sean Christopherson
2020-09-23 16:36 ` [PATCH v2 3/3] KVM: x86: Unexport cpuid_query_maxphyaddr() Sean Christopherson
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).