KVM: SVM: Wrap access to intercept masks into functions
cover KVM: SVM: Wrap access to intercept masks into functions
Hi Avi, Hi Marcelo,
this patchset wraps the access to the intercept vectors in the VMCB into specific functions. There are two reasons for this:
1) In the nested-svm code the effective intercept masks are calculated from the host and the guest intercept masks. Whenever KVM changes the host intercept mask while the VCPU is in guest-mode the effective intercept masks need to be re-calculated. This is nicely wrapped into these functions now and makes the code more robust.
2) These changes make the implementation of the upcoming vmcb-clean-bits feature easier and also more robust (which was the main reason for writing this patchset).
These patches were developed on-top of the patch-set I sent yesterday. I tested these patches with various guests (Windows-64, Linux 32,32e and 64 as well as with nested-svm).
Regards,
Joerg
Summary:
arch/x86/include/asm/svm.h | 44 +++-- arch/x86/kvm/svm.c | 391 ++++++++++++++++++++++++-------------------- 2 files changed, 241 insertions(+), 194 deletions(-)
Joerg Roedel (6):
KVM: SVM: Add function to recalculate intercept masks
KVM: SVM: Add manipulation functions for CRx intercepts
KVM: SVM: Add manipulation functions for DRx intercepts
KVM: SVM: Add manipulation functions for exception intercepts
KVM: SVM: Add manipulation functions for misc intercepts
KVM: SVM: Use get_host_vmcb function in svm_get_msr for TSC
PATCH 1/6 KVM: SVM: Add function to recalculate intercept masks
This patch adds a function to recalculate the effective intercepts masks when the vcpu is in guest-mode and either the host or the guest intercept masks change.
--- arch/x86/kvm/svm.c | 43 ++++++++++++++++++++++++++----------------- 1 files changed, 26 insertions(+), 17 deletions(-)
arch/x86/kvm/svm.c +26 -17
@@ -192,6 +192,26 @@ static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu) return container_of(vcpu, struct vcpu_svm, vcpu); } +static void recalc_intercepts (struct vcpu_svm *svm) +{ +struct vmcb_control_area *c, *h; +struct nested_state *g; + +if (!is_guest_mode (&svm->vcpu)) +return ; + + c = &svm->vmcb->control; + h = &svm->nested.hsave->control; + g = &svm->nested; + + c->intercept_cr_read = h->intercept_cr_read | g->intercept_cr_read; + c->intercept_cr_write = h->intercept_cr_write | g->intercept_cr_write; + c->intercept_dr_read = h->intercept_dr_read | g->intercept_dr_read; + c->intercept_dr_write = h->intercept_dr_write | g->intercept_dr_write; + c->intercept_exceptions = h->intercept_exceptions | g->intercept_exceptions; + c->intercept = h->intercept | g->intercept; +} +static inline void enable_gif (struct vcpu_svm *svm) { svm->vcpu.arch.hflags |=HF_GIF_MASK ;
@@ -2272,23 +2292,6 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)/* We don't want to see VMMCALLs from a nested guest */ svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_VMMCALL ); -/* -* We don't want a nested guest to be more powerful than the guest, so -* all intercepts are ORed -*/ - svm->vmcb->control.intercept_cr_read |= - nested_vmcb->control.intercept_cr_read; - svm->vmcb->control.intercept_cr_write |= - nested_vmcb->control.intercept_cr_write; - svm->vmcb->control.intercept_dr_read |= - nested_vmcb->control.intercept_dr_read; - svm->vmcb->control.intercept_dr_write |= - nested_vmcb->control.intercept_dr_write; - svm->vmcb->control.intercept_exceptions |= - nested_vmcb->control.intercept_exceptions; - - svm->vmcb->control.intercept |= nested_vmcb->control.intercept; - svm->vmcb->control.lbr_ctl = nested_vmcb->control.lbr_ctl; svm->vmcb->control.int_vector = nested_vmcb->control.int_vector; svm->vmcb->control.int_state = nested_vmcb->control.int_state;
@@ -2301,6 +2304,12 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)/* Enter Guest-Mode */ enter_guest_mode (&svm->vcpu); +/* +* Merge guest and host intercepts - must be called with vcpu in +* guest-mode to take affect here +*/ +recalc_intercepts (svm); + svm->nested.vmcb = vmcb_gpa;enable_gif (svm);
Signature · 1 line
1.7.1
PATCH 2/6 KVM: SVM: Add manipulation functions for CRx intercepts
In reply to Joerg RoedelThis patch wraps changes to the CRx intercepts of SVM into seperate functions to abstract nested-svm better and prepare the implementation of the vmcb-clean-bits feature.
--- arch/x86/include/asm/svm.h | 15 +++-- arch/x86/kvm/svm.c | 119 +++++++++++++++++++++++--------------------- 2 files changed, 72 insertions(+), 62 deletions(-)
arch/x86/include/asm/svm.h +9 -6
@@ -51,8 +51,7 @@ enum {struct __attribute__ ((__packed__ ))vmcb_control_area { -u16 intercept_cr_read; -u16 intercept_cr_write; +u32 intercept_cr;u16 intercept_dr_read;u16 intercept_dr_write;u32 intercept_exceptions;
@@ -204,10 +203,14 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK#define SVM_SELECTOR_CODE_MASK (1 << 3) -#define INTERCEPT_CR0_MASK 1 -#define INTERCEPT_CR3_MASK (1 << 3) -#define INTERCEPT_CR4_MASK (1 << 4) -#define INTERCEPT_CR8_MASK (1 << 8) +#define INTERCEPT_CR0_READ 0 +#define INTERCEPT_CR3_READ 3 +#define INTERCEPT_CR4_READ 4 +#define INTERCEPT_CR8_READ 8 +#define INTERCEPT_CR0_WRITE (16 + 0) +#define INTERCEPT_CR3_WRITE (16 + 3) +#define INTERCEPT_CR4_WRITE (16 + 4) +#define INTERCEPT_CR8_WRITE (16 + 8)#define INTERCEPT_DR0_MASK 1#define INTERCEPT_DR1_MASK (1 << 1)
arch/x86/kvm/svm.c +63 -56
222 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 2/6] KVM: SVM: Add manipulation functions for CRx intercepts
Quoted 16 lines · Joerg Roedel
This patch wraps changes to the CRx intercepts of SVM into seperate functions to abstract nested-svm better and prepare the implementation of the vmcb-clean-bits feature.
Signed-off-by Joerg Roedel <[email protected]>--- arch/x86/include/asm/svm.h | 15 +++-- arch/x86/kvm/svm.c | 119 +++++++++++++++++++++++--------------------- 2 files changed, 72 insertions(+), 62 deletions(-)arch/x86/kvm/svm.c +0
-5- control->intercept_cr_read =INTERCEPT_CR0_MASK | -INTERCEPT_CR3_MASK | -INTERCEPT_CR4_MASK ; - - control->intercept_cr_write = INTERCEPT_CR0_MASK |
arch/x86/kvm/svm.c static void init_vmcb(struct vcpu_svm *svm) · line 807
Quoted 10 lines
arch/x86/kvm/svm.c +7
-3-INTERCEPT_CR3_MASK | -INTERCEPT_CR4_MASK | -INTERCEPT_CR8_MASK ; +set_cr_intercept (svm,INTERCEPT_CR0_READ ); +set_cr_intercept (svm,INTERCEPT_CR3_READ ); +set_cr_intercept (svm,INTERCEPT_CR4_READ ); +set_cr_intercept (svm,INTERCEPT_CR0_WRITE ); +set_cr_intercept (svm,INTERCEPT_CR3_WRITE ); +set_cr_intercept (svm,INTERCEPT_CR4_WRITE ); +set_cr_intercept (svm,INTERCEPT_CR8_WRITE );
Should clear hflags before using is_guest_mode().
Re: [PATCH 2/6] KVM: SVM: Add manipulation functions for CRx intercepts
Quoted 10 lines · Marcelo Tosatti
Quoted 9 lines · Joerg Roedel
(quoted diff) +1
-8- control->intercept_cr_read = INTERCEPT_CR0_MASK | - INTERCEPT_CR3_MASK | - INTERCEPT_CR4_MASK; - - control->intercept_cr_write = INTERCEPT_CR0_MASK | - INTERCEPT_CR3_MASK | - INTERCEPT_CR4_MASK | - INTERCEPT_CR8_MASK; + set_cr_intercept(svm, INTERCEPT_CR0_READ);
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ set_cr_intercept(svm, INTERCEPT_CR3_READ); + set_cr_intercept(svm, INTERCEPT_CR4_READ); + set_cr_intercept(svm, INTERCEPT_CR0_WRITE); + set_cr_intercept(svm, INTERCEPT_CR3_WRITE); + set_cr_intercept(svm, INTERCEPT_CR4_WRITE); + set_cr_intercept(svm, INTERCEPT_CR8_WRITE);Should clear hflags before using
is_guest_mode().
Right, thanks. Here is the updated patch.
Quoted 1 line
From
78e9a425d1440fdf9232e38dc3093127b96f26bbMon Sep 17 00:00:00 2001
From: Joerg Roedel <[email protected]>
Date: Tue, 30 Nov 2010 15:30:21 +0100
Subject: [PATCH 2/6] KVM: SVM: Add manipulation functions for CRx intercepts
This patch wraps changes to the CRx intercepts of SVM into seperate functions to abstract nested-svm better and prepare the implementation of the vmcb-clean-bits feature.
--- arch/x86/include/asm/svm.h | 15 +++-- arch/x86/kvm/svm.c | 120 +++++++++++++++++++++++-------------------- 2 files changed, 73 insertions(+), 62 deletions(-)
arch/x86/include/asm/svm.h +9 -6
@@ -51,8 +51,7 @@ enum {struct __attribute__ ((__packed__ ))vmcb_control_area { -u16 intercept_cr_read; -u16 intercept_cr_write; +u32 intercept_cr;u16 intercept_dr_read;u16 intercept_dr_write;u32 intercept_exceptions;
@@ -204,10 +203,14 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK#define SVM_SELECTOR_CODE_MASK (1 << 3) -#define INTERCEPT_CR0_MASK 1 -#define INTERCEPT_CR3_MASK (1 << 3) -#define INTERCEPT_CR4_MASK (1 << 4) -#define INTERCEPT_CR8_MASK (1 << 8) +#define INTERCEPT_CR0_READ 0 +#define INTERCEPT_CR3_READ 3 +#define INTERCEPT_CR4_READ 4 +#define INTERCEPT_CR8_READ 8 +#define INTERCEPT_CR0_WRITE (16 + 0) +#define INTERCEPT_CR3_WRITE (16 + 3) +#define INTERCEPT_CR4_WRITE (16 + 4) +#define INTERCEPT_CR8_WRITE (16 + 8)#define INTERCEPT_DR0_MASK 1#define INTERCEPT_DR1_MASK (1 << 1)
arch/x86/kvm/svm.c +64 -56
224 lines not on this page · raw message
Signature · 9 lines
1.7.1 -- AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
PATCH 3/6 KVM: SVM: Add manipulation functions for DRx intercepts
In reply to Joerg RoedelThis patch wraps changes to the DRx intercepts of SVM into seperate functions to abstract nested-svm better and prepare the implementation of the vmcb-clean-bits feature.
--- arch/x86/include/asm/svm.h | 27 +++++++++----- arch/x86/kvm/svm.c | 80 ++++++++++++++++++++++++-------------------- 2 files changed, 61 insertions(+), 46 deletions(-)
arch/x86/include/asm/svm.h +17 -10
@@ -52,8 +52,7 @@ enum {struct __attribute__ ((__packed__ ))vmcb_control_area {u32 intercept_cr; -u16 intercept_dr_read; -u16 intercept_dr_write; +u32 intercept_dr;u32 intercept_exceptions;u64 intercept;u8 reserved_1[42 ];
@@ -212,14 +211,22 @@ struct __attribute__ ((__packed__)) vmcb {#define INTERCEPT_CR4_WRITE (16 + 4)#define INTERCEPT_CR8_WRITE (16 + 8) -#define INTERCEPT_DR0_MASK 1 -#define INTERCEPT_DR1_MASK (1 << 1) -#define INTERCEPT_DR2_MASK (1 << 2) -#define INTERCEPT_DR3_MASK (1 << 3) -#define INTERCEPT_DR4_MASK (1 << 4) -#define INTERCEPT_DR5_MASK (1 << 5) -#define INTERCEPT_DR6_MASK (1 << 6) -#define INTERCEPT_DR7_MASK (1 << 7) +#define INTERCEPT_DR0_READ 0 +#define INTERCEPT_DR1_READ 1 +#define INTERCEPT_DR2_READ 2 +#define INTERCEPT_DR3_READ 3 +#define INTERCEPT_DR4_READ 4 +#define INTERCEPT_DR5_READ 5 +#define INTERCEPT_DR6_READ 6 +#define INTERCEPT_DR7_READ 7 +#define INTERCEPT_DR0_WRITE (16 + 0) +#define INTERCEPT_DR1_WRITE (16 + 1) +#define INTERCEPT_DR2_WRITE (16 + 2) +#define INTERCEPT_DR3_WRITE (16 + 3) +#define INTERCEPT_DR4_WRITE (16 + 4) +#define INTERCEPT_DR5_WRITE (16 + 5) +#define INTERCEPT_DR6_WRITE (16 + 6) +#define INTERCEPT_DR7_WRITE (16 + 7)#define SVM_EVTINJ_VEC_MASK 0xff
arch/x86/kvm/svm.c +44 -36
128 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 4/6 KVM: SVM: Add manipulation functions for exception intercepts
In reply to Joerg RoedelThis patch wraps changes to the exception intercepts of SVM into seperate functions to abstract nested-svm better and prepare the implementation of the vmcb-clean-bits feature.
--- arch/x86/kvm/svm.c | 58 ++++++++++++++++++++++++++-------------------------- 1 files changed, 29 insertions(+), 29 deletions(-)
arch/x86/kvm/svm.c +29 -29
@@ -259,6 +259,24 @@ static inline void clr_dr_intercept(struct vcpu_svm *svm, int bit)recalc_intercepts (svm); } +static inline void set_exception_intercept (struct vcpu_svm *svm,int bit) +{ +struct vmcb *vmcb =get_host_vmcb (svm); + + vmcb->control.intercept_exceptions |= (1U << bit); + +recalc_intercepts (svm); +} + +static inline void clr_exception_intercept (struct vcpu_svm *svm,int bit) +{ +struct vmcb *vmcb =get_host_vmcb (svm); + + vmcb->control.intercept_exceptions &= ~(1U << bit); + +recalc_intercepts (svm); +} +static inline void enable_gif (struct vcpu_svm *svm) { svm->vcpu.arch.hflags |=HF_GIF_MASK ;
@@ -840,10 +858,9 @@ static void init_vmcb(struct vcpu_svm *svm)set_dr_intercept (svm,INTERCEPT_DR6_WRITE );set_dr_intercept (svm,INTERCEPT_DR7_WRITE ); - control->intercept_exceptions = (1 <<PF_VECTOR ) | - (1 <<UD_VECTOR ) | - (1 <<MC_VECTOR ); - +set_exception_intercept (svm,PF_VECTOR ); +set_exception_intercept (svm,UD_VECTOR ); +set_exception_intercept (svm,MC_VECTOR ); control->intercept = (1ULL <<INTERCEPT_INTR ) | (1ULL << INTERCEPT_NMI) |
@@ -920,7 +937,7 @@ static void init_vmcb(struct vcpu_svm *svm) control->nested_ctl =1 ; control->intercept &= ~((1ULL <<INTERCEPT_TASK_SWITCH ) | (1ULL <<INTERCEPT_INVLPG )); - control->intercept_exceptions &= ~(1 <<PF_VECTOR ); +clr_exception_intercept (svm,PF_VECTOR );clr_cr_intercept (svm,INTERCEPT_CR3_READ );clr_cr_intercept (svm,INTERCEPT_CR3_WRITE ); save->g_pat =0x0007040600070406ULL ;
@@ -1381,20 +1398,18 @@ static void update_db_intercept(struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu); - svm->vmcb->control.intercept_exceptions &= - ~((1 <<DB_VECTOR ) | (1 <<BP_VECTOR )); +clr_exception_intercept (svm,DB_VECTOR ); +clr_exception_intercept (svm,BP_VECTOR );if (svm->nmi_singlestep) - svm->vmcb->control.intercept_exceptions |= (1 <<DB_VECTOR ); +set_exception_intercept (svm,DB_VECTOR );if (vcpu->guest_debug &KVM_GUESTDBG_ENABLE ) {if (vcpu->guest_debug & (KVM_GUESTDBG_SINGLESTEP |KVM_GUESTDBG_USE_HW_BP )) - svm->vmcb->control.intercept_exceptions |= -1 <<DB_VECTOR ; +set_exception_intercept (svm,DB_VECTOR );if (vcpu->guest_debug &KVM_GUESTDBG_USE_SW_BP ) - svm->vmcb->control.intercept_exceptions |= -1 <<BP_VECTOR ; +set_exception_intercept (svm,BP_VECTOR ); }else vcpu->guest_debug =0 ; }
@@ -1515,21 +1530,8 @@ static int ud_interception(struct vcpu_svm *svm)static void svm_fpu_activate (struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu); -u32 excp; - -if (is_guest_mode (vcpu)) { -u32 h_excp, n_excp; - h_excp = svm->nested.hsave->control.intercept_exceptions; - n_excp = svm->nested.intercept_exceptions; - h_excp &= ~(1 <<NM_VECTOR ); - excp = h_excp | n_excp; - }else { - excp = svm->vmcb->control.intercept_exceptions; - excp &= ~(1 <<NM_VECTOR ); - } - - svm->vmcb->control.intercept_exceptions = excp; +clr_exception_intercept (svm,NM_VECTOR ); svm->vcpu.fpu_active =1 ;update_cr0_intercept (svm);
@@ -3635,9 +3637,7 @@ static void svm_fpu_deactivate(struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu); - svm->vmcb->control.intercept_exceptions |=1 <<NM_VECTOR ; -if (is_guest_mode (vcpu)) - svm->nested.hsave->control.intercept_exceptions |=1 <<NM_VECTOR ; +set_exception_intercept (svm,NM_VECTOR );update_cr0_intercept (svm); }
Signature · 1 line
1.7.1
PATCH 5/6 KVM: SVM: Add manipulation functions for misc intercepts
In reply to Joerg RoedelThis patch wraps changes to the misc intercepts of SVM into seperate functions to abstract nested-svm better and prepare the implementation of the vmcb-clean-bits feature.
--- arch/x86/kvm/svm.c | 84 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 51 insertions(+), 33 deletions(-)
arch/x86/kvm/svm.c +51 -33
@@ -277,6 +277,24 @@ static inline void clr_exception_intercept(struct vcpu_svm *svm, int bit)recalc_intercepts (svm); } +static inline void set_intercept (struct vcpu_svm *svm,int bit) +{ +struct vmcb *vmcb =get_host_vmcb (svm); + + vmcb->control.intercept |= (1ULL << bit); + +recalc_intercepts (svm); +} + +static inline void clr_intercept (struct vcpu_svm *svm,int bit) +{ +struct vmcb *vmcb =get_host_vmcb (svm); + + vmcb->control.intercept &= ~(1ULL << bit); + +recalc_intercepts (svm); +} +static inline void enable_gif (struct vcpu_svm *svm) { svm->vcpu.arch.hflags |=HF_GIF_MASK ;
@@ -862,29 +880,29 @@ static void init_vmcb(struct vcpu_svm *svm)set_exception_intercept (svm,UD_VECTOR );set_exception_intercept (svm,MC_VECTOR ); - control->intercept = (1ULL <<INTERCEPT_INTR ) | - (1ULL <<INTERCEPT_NMI ) | - (1ULL <<INTERCEPT_SMI ) | - (1ULL <<INTERCEPT_SELECTIVE_CR0 ) | - (1ULL <<INTERCEPT_CPUID ) | - (1ULL <<INTERCEPT_INVD ) | - (1ULL <<INTERCEPT_HLT ) | - (1ULL <<INTERCEPT_INVLPG ) | - (1ULL <<INTERCEPT_INVLPGA ) | - (1ULL <<INTERCEPT_IOIO_PROT ) | - (1ULL <<INTERCEPT_MSR_PROT ) | - (1ULL <<INTERCEPT_TASK_SWITCH ) | - (1ULL <<INTERCEPT_SHUTDOWN ) | - (1ULL <<INTERCEPT_VMRUN ) | - (1ULL <<INTERCEPT_VMMCALL ) | - (1ULL <<INTERCEPT_VMLOAD ) | - (1ULL <<INTERCEPT_VMSAVE ) | - (1ULL <<INTERCEPT_STGI ) | - (1ULL <<INTERCEPT_CLGI ) | - (1ULL <<INTERCEPT_SKINIT ) | - (1ULL <<INTERCEPT_WBINVD ) | - (1ULL <<INTERCEPT_MONITOR ) | - (1ULL <<INTERCEPT_MWAIT ); +set_intercept (svm,INTERCEPT_INTR ); +set_intercept (svm,INTERCEPT_NMI ); +set_intercept (svm,INTERCEPT_SMI ); +set_intercept (svm,INTERCEPT_SELECTIVE_CR0 ); +set_intercept (svm,INTERCEPT_CPUID ); +set_intercept (svm,INTERCEPT_INVD ); +set_intercept (svm,INTERCEPT_HLT ); +set_intercept (svm,INTERCEPT_INVLPG ); +set_intercept (svm,INTERCEPT_INVLPGA ); +set_intercept (svm,INTERCEPT_IOIO_PROT ); +set_intercept (svm,INTERCEPT_MSR_PROT ); +set_intercept (svm,INTERCEPT_TASK_SWITCH ); +set_intercept (svm,INTERCEPT_SHUTDOWN ); +set_intercept (svm,INTERCEPT_VMRUN ); +set_intercept (svm,INTERCEPT_VMMCALL ); +set_intercept (svm,INTERCEPT_VMLOAD ); +set_intercept (svm,INTERCEPT_VMSAVE ); +set_intercept (svm,INTERCEPT_STGI ); +set_intercept (svm,INTERCEPT_CLGI ); +set_intercept (svm,INTERCEPT_SKINIT ); +set_intercept (svm,INTERCEPT_WBINVD ); +set_intercept (svm,INTERCEPT_MONITOR ); +set_intercept (svm,INTERCEPT_MWAIT ); control->iopm_base_pa = iopm_base; control->msrpm_base_pa =__pa (svm->msrpm);
@@ -935,8 +953,8 @@ static void init_vmcb(struct vcpu_svm *svm)if (npt_enabled) {/* Setup VMCB for Nested Paging */ control->nested_ctl =1 ; - control->intercept &= ~((1ULL <<INTERCEPT_TASK_SWITCH ) | - (1ULL <<INTERCEPT_INVLPG )); +clr_intercept (svm,INTERCEPT_TASK_SWITCH ); +clr_intercept (svm,INTERCEPT_INVLPG );clr_exception_intercept (svm,PF_VECTOR );clr_cr_intercept (svm,INTERCEPT_CR3_READ );clr_cr_intercept (svm,INTERCEPT_CR3_WRITE );
@@ -951,7 +969,7 @@ static void init_vmcb(struct vcpu_svm *svm)if (boot_cpu_has (X86_FEATURE_PAUSEFILTER )) { control->pause_filter_count =3000 ; - control->intercept |= (1ULL <<INTERCEPT_PAUSE ); +set_intercept (svm,INTERCEPT_PAUSE ); }enable_gif (svm);
@@ -1125,12 +1143,12 @@ static void svm_cache_reg(struct kvm_vcpu *vcpu, enum kvm_reg reg)static void svm_set_vintr (struct vcpu_svm *svm) { - svm->vmcb->control.intercept |=1ULL <<INTERCEPT_VINTR ; +set_intercept (svm,INTERCEPT_VINTR ); }static void svm_clear_vintr (struct vcpu_svm *svm) { - svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_VINTR ); +clr_intercept (svm,INTERCEPT_VINTR ); }static struct vmcb_seg *svm_seg (struct kvm_vcpu *vcpu,int seg)
@@ -2307,7 +2325,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm) }/* We don't want to see VMMCALLs from a nested guest */ - svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_VMMCALL ); +clr_intercept (svm,INTERCEPT_VMMCALL ); svm->vmcb->control.lbr_ctl = nested_vmcb->control.lbr_ctl; svm->vmcb->control.int_vector = nested_vmcb->control.int_vector;
@@ -2555,7 +2573,7 @@ static int cpuid_interception(struct vcpu_svm *svm)static int iret_interception (struct vcpu_svm *svm) { ++svm->vcpu.stat.nmi_window_exits; - svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_IRET ); +clr_intercept (svm,INTERCEPT_IRET ); svm->vcpu.arch.hflags |=HF_IRET_MASK ;return 1 ; }
@@ -3101,7 +3119,7 @@ static void svm_inject_nmi(struct kvm_vcpu *vcpu) svm->vmcb->control.event_inj =SVM_EVTINJ_VALID |SVM_EVTINJ_TYPE_NMI ; vcpu->arch.hflags |=HF_NMI_MASK ; - svm->vmcb->control.intercept |= (1ULL <<INTERCEPT_IRET ); +set_intercept (svm,INTERCEPT_IRET ); ++vcpu->stat.nmi_injections; }
@@ -3168,10 +3186,10 @@ static void svm_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked)if (masked) { svm->vcpu.arch.hflags |=HF_NMI_MASK ; - svm->vmcb->control.intercept |= (1ULL <<INTERCEPT_IRET ); +set_intercept (svm,INTERCEPT_IRET ); }else { svm->vcpu.arch.hflags &= ~HF_NMI_MASK ; - svm->vmcb->control.intercept &= ~(1ULL <<INTERCEPT_IRET ); +clr_intercept (svm,INTERCEPT_IRET ); } }
Signature · 1 line
1.7.1
PATCH 6/6 KVM: SVM: Use get_host_vmcb function in svm_get_msr for TSC
In reply to Joerg RoedelThis patch replaces the open-coded vmcb-selection for the TSC calculation with the new get_host_vmcb helper function introduced in this patchset.
--- arch/x86/kvm/svm.c | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-)
arch/x86/kvm/svm.c +2 -7
@@ -2628,14 +2628,9 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)switch (ecx) {case MSR_IA32_TSC : { -u64 tsc_offset; +struct vmcb *vmcb =get_host_vmcb (svm); -if (is_guest_mode (vcpu)) - tsc_offset = svm->nested.hsave->control.tsc_offset; -else - tsc_offset = svm->vmcb->control.tsc_offset; - - *data = tsc_offset +native_read_tsc (); + *data = vmcb->control.tsc_offset +native_read_tsc ();break ; }case MSR_STAR :
Signature · 1 line
1.7.1
Quoted 12 lines · Joerg Roedel
Hi Avi, Hi Marcelo,
this patchset wraps the access to the intercept vectors in the VMCB into specific functions. There are two reasons for this:
1) In the nested-svm code the effective intercept masks are calculated from the host and the guest intercept masks. Whenever KVM changes the host intercept mask while the VCPU is in guest-mode the effective intercept masks need to be re-calculated. This is nicely wrapped into these functions now and makes the code more robust.
Quoted 8 lines
2) These changes make the implementation of the upcoming vmcb-clean-bits feature easier and also more robust (which was the main reason for writing this patchset).
These patches were developed on-top of the patch-set I sent yesterday. I tested these patches with various guests (Windows-64, Linux 32,32e and 64 as well as with nested-svm).
Looks good.
One potential issue is that a series of set_intercept()s causes recalc_intercepts() to be called multiple times. If it turns out to be a problem, we can fix it by having an intercepts dirty bit and recalculating during guest entry if the bit is set.
Since it's nested svm only, I doubt we'll see a problem in the short term.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 22 lines · Avi Kivity
Quoted 12 lines · Joerg Roedel
Hi Avi, Hi Marcelo,
this patchset wraps the access to the intercept vectors in the VMCB into specific functions. There are two reasons for this:
1) In the nested-svm code the effective intercept masks are calculated from the host and the guest intercept masks. Whenever KVM changes the host intercept mask while the VCPU is in guest-mode the effective intercept masks need to be re-calculated. This is nicely wrapped into these functions now and makes the code more robust.
Quoted 8 lines
2) These changes make the implementation of the upcoming vmcb-clean-bits feature easier and also more robust (which was the main reason for writing this patchset).
These patches were developed on-top of the patch-set I sent yesterday. I tested these patches with various guests (Windows-64, Linux 32,32e and 64 as well as with nested-svm).
Quoted 8 lines
Looks good.
One potential issue is that a series of set_intercept()s causes
recalc_intercepts()to be called multiple times. If it turns out to be a problem, we can fix it by having an intercepts dirty bit and recalculating during guest entry if the bit is set.Since it's nested svm only, I doubt we'll see a problem in the short term.
Yes, we can optimize it if it turns out to be a problem. I thought that these changes happen infrequently enough and that there should be no more than 2-3 bits changed per exit-entry cycle at all.
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Marcelo Tosatti
AppliedQuoted 30 lines · Joerg Roedel
Hi Avi, Hi Marcelo,
this patchset wraps the access to the intercept vectors in the VMCB into specific functions. There are two reasons for this:
1) In the nested-svm code the effective intercept masks are calculated from the host and the guest intercept masks. Whenever KVM changes the host intercept mask while the VCPU is in guest-mode the effective intercept masks need to be re-calculated. This is nicely wrapped into these functions now and makes the code more robust.
2) These changes make the implementation of the upcoming vmcb-clean-bits feature easier and also more robust (which was the main reason for writing this patchset).
These patches were developed on-top of the patch-set I sent yesterday. I tested these patches with various guests (Windows-64, Linux 32,32e and 64 as well as with nested-svm).
Regards,
Joerg
Summary:
arch/x86/include/asm/svm.h | 44 +++-- arch/x86/kvm/svm.c | 391 ++++++++++++++++++++++++-------------------- 2 files changed, 241 insertions(+), 194 deletions(-)
Quoted 7 lines
Joerg Roedel (6):
KVM: SVM: Add function to recalculate intercept masks
KVM: SVM: Add manipulation functions for CRx intercepts
KVM: SVM: Add manipulation functions for DRx intercepts
KVM: SVM: Add manipulation functions for exception intercepts
KVM: SVM: Add manipulation functions for misc intercepts
KVM: SVM: Useget_host_vmcbfunction insvm_get_msrfor TSC
Applied, thanks.