* [PATCH 1/5] SVM: sync TPR value to V_TPR field in the VMCB
2008-04-16 14:51 [PATCH 0/5] SVM CR8 optimization patches Joerg Roedel
@ 2008-04-16 14:51 ` Joerg Roedel
2008-04-16 14:51 ` [PATCH 2/5] X86: export kvm_lapic_set_tpr to modules Joerg Roedel
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2008-04-16 14:51 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel
This patch adds syncing of the lapic.tpr field to the V_TPR field of the VMCB.
With this change we can safely remove the CR8 read intercept.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 3379e13..f8ce36e 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -486,8 +486,7 @@ static void init_vmcb(struct vcpu_svm *svm)
control->intercept_cr_read = INTERCEPT_CR0_MASK |
INTERCEPT_CR3_MASK |
- INTERCEPT_CR4_MASK |
- INTERCEPT_CR8_MASK;
+ INTERCEPT_CR4_MASK;
control->intercept_cr_write = INTERCEPT_CR0_MASK |
INTERCEPT_CR3_MASK |
@@ -1621,6 +1620,19 @@ static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
{
}
+static inline void sync_lapic_to_cr8(struct kvm_vcpu *vcpu)
+{
+ struct vcpu_svm *svm = to_svm(vcpu);
+ u64 cr8;
+
+ if (!irqchip_in_kernel(vcpu->kvm))
+ return;
+
+ cr8 = kvm_get_cr8(vcpu);
+ svm->vmcb->control.int_ctl &= ~V_TPR_MASK;
+ svm->vmcb->control.int_ctl |= cr8 & V_TPR_MASK;
+}
+
static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
struct vcpu_svm *svm = to_svm(vcpu);
@@ -1630,6 +1642,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
pre_svm_run(svm);
+ sync_lapic_to_cr8(vcpu);
+
save_host_msrs(vcpu);
fs_selector = read_fs();
gs_selector = read_gs();
--
1.5.3.7
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/5] X86: export kvm_lapic_set_tpr to modules
2008-04-16 14:51 [PATCH 0/5] SVM CR8 optimization patches Joerg Roedel
2008-04-16 14:51 ` [PATCH 1/5] SVM: sync TPR value to V_TPR field in the VMCB Joerg Roedel
@ 2008-04-16 14:51 ` Joerg Roedel
2008-04-16 14:51 ` [PATCH 3/5] SVM: sync V_TPR with LAPIC.TPR if CR8 write intercept is disabled Joerg Roedel
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2008-04-16 14:51 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel
This patch exports the kvm_lapic_set_tpr() function from the lapic code to
modules. It is required in the kvm-amd module to optimize CR8 intercepts.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/lapic.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 2ccf994..57ac4e4 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -822,6 +822,7 @@ void kvm_lapic_set_tpr(struct kvm_vcpu *vcpu, unsigned long cr8)
apic_set_tpr(apic, ((cr8 & 0x0f) << 4)
| (apic_get_reg(apic, APIC_TASKPRI) & 4));
}
+EXPORT_SYMBOL_GPL(kvm_lapic_set_tpr);
u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu)
{
--
1.5.3.7
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 3/5] SVM: sync V_TPR with LAPIC.TPR if CR8 write intercept is disabled
2008-04-16 14:51 [PATCH 0/5] SVM CR8 optimization patches Joerg Roedel
2008-04-16 14:51 ` [PATCH 1/5] SVM: sync TPR value to V_TPR field in the VMCB Joerg Roedel
2008-04-16 14:51 ` [PATCH 2/5] X86: export kvm_lapic_set_tpr to modules Joerg Roedel
@ 2008-04-16 14:51 ` Joerg Roedel
2008-04-16 14:51 ` [PATCH 4/5] SVM: disable CR8 intercept when tpr is not masking interrupts Joerg Roedel
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2008-04-16 14:51 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel
If the CR8 write intercept is disabled the V_TPR field of the VMCB needs to be
synced with the TPR field in the local apic.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f8ce36e..ee2ee83 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1620,6 +1620,16 @@ static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
{
}
+static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu)
+{
+ struct vcpu_svm *svm = to_svm(vcpu);
+
+ if (!(svm->vmcb->control.intercept_cr_write & INTERCEPT_CR8_MASK)) {
+ int cr8 = svm->vmcb->control.int_ctl & V_TPR_MASK;
+ kvm_lapic_set_tpr(vcpu, cr8);
+ }
+}
+
static inline void sync_lapic_to_cr8(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
@@ -1791,6 +1801,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
stgi();
+ sync_cr8_to_lapic(vcpu);
+
svm->next_rip = 0;
}
--
1.5.3.7
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 4/5] SVM: disable CR8 intercept when tpr is not masking interrupts
2008-04-16 14:51 [PATCH 0/5] SVM CR8 optimization patches Joerg Roedel
` (2 preceding siblings ...)
2008-04-16 14:51 ` [PATCH 3/5] SVM: sync V_TPR with LAPIC.TPR if CR8 write intercept is disabled Joerg Roedel
@ 2008-04-16 14:51 ` Joerg Roedel
2008-04-16 14:51 ` [PATCH 5/5] SVM: remove now obsolete FIXME comment Joerg Roedel
2008-04-18 16:07 ` [PATCH 0/5] SVM CR8 optimization patches Avi Kivity
5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2008-04-16 14:51 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel
This patch disables the intercept of CR8 writes if the TPR is not masking
interrupts. This reduces the total number CR8 intercepts to below 1 percent of
what we have without this patch using Windows 64 bit guests.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 31 +++++++++++++++++++++++++++----
1 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index ee2ee83..61bb2cb 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1502,6 +1502,27 @@ static void svm_set_irq(struct kvm_vcpu *vcpu, int irq)
svm_inject_irq(svm, irq);
}
+static void update_cr8_intercept(struct kvm_vcpu *vcpu)
+{
+ struct vcpu_svm *svm = to_svm(vcpu);
+ struct vmcb *vmcb = svm->vmcb;
+ int max_irr, tpr;
+
+ if (!irqchip_in_kernel(vcpu->kvm) || vcpu->arch.apic->vapic_addr)
+ return;
+
+ vmcb->control.intercept_cr_write &= ~INTERCEPT_CR8_MASK;
+
+ max_irr = kvm_lapic_find_highest_irr(vcpu);
+ if (max_irr == -1)
+ return;
+
+ tpr = kvm_lapic_get_cr8(vcpu) << 4;
+
+ if (tpr >= (max_irr & 0xf0))
+ vmcb->control.intercept_cr_write |= INTERCEPT_CR8_MASK;
+}
+
static void svm_intr_assist(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
@@ -1514,14 +1535,14 @@ static void svm_intr_assist(struct kvm_vcpu *vcpu)
SVM_EVTINJ_VEC_MASK;
vmcb->control.exit_int_info = 0;
svm_inject_irq(svm, intr_vector);
- return;
+ goto out;
}
if (vmcb->control.int_ctl & V_IRQ_MASK)
- return;
+ goto out;
if (!kvm_cpu_has_interrupt(vcpu))
- return;
+ goto out;
if (!(vmcb->save.rflags & X86_EFLAGS_IF) ||
(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) ||
@@ -1529,12 +1550,14 @@ static void svm_intr_assist(struct kvm_vcpu *vcpu)
/* unable to deliver irq, set pending irq */
vmcb->control.intercept |= (1ULL << INTERCEPT_VINTR);
svm_inject_irq(svm, 0x0);
- return;
+ goto out;
}
/* Okay, we can deliver the interrupt: grab it and update PIC state. */
intr_vector = kvm_cpu_get_interrupt(vcpu);
svm_inject_irq(svm, intr_vector);
kvm_timer_intr_post(vcpu, intr_vector);
+out:
+ update_cr8_intercept(vcpu);
}
static void kvm_reput_irq(struct vcpu_svm *svm)
--
1.5.3.7
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 5/5] SVM: remove now obsolete FIXME comment
2008-04-16 14:51 [PATCH 0/5] SVM CR8 optimization patches Joerg Roedel
` (3 preceding siblings ...)
2008-04-16 14:51 ` [PATCH 4/5] SVM: disable CR8 intercept when tpr is not masking interrupts Joerg Roedel
@ 2008-04-16 14:51 ` Joerg Roedel
2008-04-18 16:07 ` [PATCH 0/5] SVM CR8 optimization patches Avi Kivity
5 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2008-04-16 14:51 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel
With the usage of the V_TPR field this comment is now obsolet.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 7 -------
1 files changed, 0 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 61bb2cb..d643605 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -916,13 +916,6 @@ static void svm_set_segment(struct kvm_vcpu *vcpu,
}
-/* FIXME:
-
- svm(vcpu)->vmcb->control.int_ctl &= ~V_TPR_MASK;
- svm(vcpu)->vmcb->control.int_ctl |= (sregs->cr8 & V_TPR_MASK);
-
-*/
-
static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg)
{
return -EOPNOTSUPP;
--
1.5.3.7
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 0/5] SVM CR8 optimization patches
2008-04-16 14:51 [PATCH 0/5] SVM CR8 optimization patches Joerg Roedel
` (4 preceding siblings ...)
2008-04-16 14:51 ` [PATCH 5/5] SVM: remove now obsolete FIXME comment Joerg Roedel
@ 2008-04-18 16:07 ` Avi Kivity
5 siblings, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2008-04-18 16:07 UTC (permalink / raw)
To: Joerg Roedel; +Cc: kvm-devel
Joerg Roedel wrote:
> This patch series implements optimizations to the CR8 intercept handling in
> SVM. With these patches applied CR8 reads are not intercepted anymore. The
> writes to CR8 are only intercepted if the TPR masks interrupts. This
> significantly reduces the number of total CR8 intercepts when running Windows
> 64 bit versions. Some quick numbers:
>
> Boot and shudown of Vista 64:
>
> Without these patches: ~38.000.000 CR8 writes intercepted
> With these patches: ~38.000 CR8 writes intercepted
>
>
Applied all, thanks. Good patchset.
--
Any sufficiently difficult bug is indistinguishable from a feature.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
^ permalink raw reply [flat|nested] 7+ messages in thread