svm: support VMCB cleanbits
PATCH 1/1 svm: support VMCB cleanbits
Hi,
Attached patch implements the VMCB cleanbits SVM feature.
Upcoming AMD CPUs introduce them and they are basically hints for the CPU which vmcb values can be re-used from the previous VMRUN instruction.
Each bit represents a certain set of fields in the VMCB. Setting a bit tells the cpu it can re-use the cached value from the previous VMRUN.
Clearing a bit tells the cpu to reload the values from the given VMCB.
Christoph
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
# HG changeset patch
# User cegger
# Date 1292410191 -3600
vmcb cleanbits
xen/arch/x86/hvm/svm/Makefile +1 -0
@@ -3,5 +3,6 @@ obj-y += emulate.o obj-y += entry.o obj-y += intr.o obj-y += svm.o +obj-y += svmcleanbits.o obj-y += vmcb.o obj-y += vpmu.o
xen/arch/x86/hvm/svm/asid.c +6 -4
@@ -21,6 +21,7 @@#include <xen/lib.h> #include <xen/perfc.h> #include <asm/hvm/svm/asid.h> +#include <asm/hvm/svm/svmcleanbits.h> #include <asm/amd.h> void svm_asid_init (struct cpuinfo_x86 *c)
@@ -41,18 +42,19 @@ void svm_asid_init(struct cpuinfo_x86 *c asmlinkage void svm_asid_handle_vmrun(void) {struct vcpu *curr = current; +struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb;bool_t need_flush =hvm_asid_handle_vmenter ();/* ASID 0 indicates that ASIDs are disabled. */ if ( curr->arch.hvm_vcpu.asid ==0 ) { - curr->arch.hvm_svm.vmcb->guest_asid =1 ; - curr->arch.hvm_svm.vmcb->tlb_control =1 ; +svm_set_asid (vmcb,1 ); + vmcb->tlb_control =1 ;return ; } - curr->arch.hvm_svm.vmcb->guest_asid = curr->arch.hvm_vcpu.asid; - curr->arch.hvm_svm.vmcb->tlb_control = need_flush; +svm_set_asid (vmcb, curr->arch.hvm_vcpu.asid); + vmcb->tlb_control = need_flush; }/*
xen/arch/x86/hvm/svm/intr.c +4 -3
@@ -32,6 +32,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vlapic.h> #include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm/svmcleanbits.h> #include <asm/hvm/svm/intr.h> #include <xen/event.h> #include <xen/kernel.h>
@@ -56,7 +57,7 @@ static void svm_inject_nmi(struct vcpu ** SVM does not virtualise the NMI mask, so we emulate it by intercepting * the next IRET and blocking NMI injection until the intercept triggers. */ - vmcb->general1_intercepts |=GENERAL1_INTERCEPT_IRET ; +svm_set_general1_intercept (vmcb,GENERAL1_INTERCEPT_IRET ); }static void svm_inject_extint (struct vcpu *v,int vector)
@@ -108,8 +109,8 @@ static void enable_intr_window(struct vc intr.fields.vector =0 ; intr.fields.prio = intack.vector >>4 ; intr.fields.ign_tpr = (intack.source != hvm_intsrc_lapic); - vmcb->vintr = intr; - vmcb->general1_intercepts |=GENERAL1_INTERCEPT_VINTR ; +svm_set_vintr (vmcb, vintr, intr); +svm_set_general1_intercept (vmcb,GENERAL1_INTERCEPT_VINTR ); } asmlinkage void svm_intr_assist(void)
xen/arch/x86/hvm/svm/svm.c +80 -58
344 lines not on this page · raw message
xen/arch/x86/hvm/svm/svmcleanbits.c new file +57 -0
57 lines not on this page · raw message
xen/arch/x86/hvm/svm/vmcb.c +16 -43
101 lines not on this page · raw message
xen/include/asm-x86/hvm/svm/svm.h +2 -0
@@ -68,12 +68,14 @@ extern u32 svm_feature_flags;#define SVM_FEATURE_LBRV 1#define SVM_FEATURE_SVML 2#define SVM_FEATURE_NRIPS 3 +#define SVM_FEATURE_CLEAN 5#define SVM_FEATURE_PAUSEF 10#define cpu_has_svm_npt test_bit(SVM_FEATURE_NPT, &svm_feature_flags)#define cpu_has_svm_lbrv test_bit(SVM_FEATURE_LBRV, &svm_feature_flags)#define cpu_has_svm_svml test_bit(SVM_FEATURE_SVML, &svm_feature_flags)#define cpu_has_svm_nrips test_bit(SVM_FEATURE_NRIPS, &svm_feature_flags) +#define cpu_has_svm_cleanbits test_bit(SVM_FEATURE_CLEAN, &svm_feature_flags)#define cpu_has_pause_filter test_bit(SVM_FEATURE_PAUSEF, &svm_feature_flags)#endif /* __ASM_X86_HVM_SVM_H__ */
xen/include/asm-x86/hvm/svm/svmcleanbits.h new file +192 -0
192 lines not on this page · raw message
xen/include/asm-x86/hvm/svm/vmcb.h +22 -6
@@ -366,6 +366,26 @@ typedef union } fields; } __attribute__ ((packed)) lbrctrl_t; +typedef union +{ +uint32_t bytes; +struct + { +uint32_t intercepts:1 ; +uint32_t iopm:1 ; +uint32_t asid:1 ; +uint32_t tpr:1 ; +uint32_t np:1 ; +uint32_t cr:1 ; +uint32_t dr:1 ; +uint32_t dt:1 ; +uint32_t seg:1 ; +uint32_t cr2:1 ; +uint32_t lbr:1 ; +uint32_t resv:21 ; + } fields; +} __attribute__ ((packed))vmcbcleanbits_t ; +struct vmcb_struct {u32 cr_intercepts;/* offset 0x00 */ u32 dr_intercepts;/* offset 0x04 */
@@ -397,7 +417,8 @@ struct vmcb_struct {eventinj_t eventinj;/* offset 0xA8 */ u64 h_cr3;/* offset 0xB0 */ lbrctrl_t lbr_control;/* offset 0xB8 */ -u64 res09;/* offset 0xC0 */ +vmcbcleanbits_t cleanbits;/* offset 0xC0 */ +u32 res09;/* offset 0xC4 */ u64 nextrip;/* offset 0xC8 */ u64 res10a[102 ];/* offset 0xD0 pad to save area */
@@ -481,11 +502,6 @@ int svm_create_vmcb(struct vcpu *v);void svm_destroy_vmcb (struct vcpu *v);void setup_vmcb_dump (void ); - -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), 0) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), 1) -#endif /* ASM_X86_HVM_SVM_VMCS_H__ */ /*
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi,
Thanks for the patch!
Quoted 9 lines · Christoph Egger
xen/arch/x86/hvm/svm/svm.c +1
-0@@ -660,16 +671,17 @@ static void svm_ctxt_switch_to(struct vcstatic void svm_do_resume (struct vcpu *v) { +struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;bool_t debug_state = v->domain->debugger_attached;if (unlikely (v->arch.hvm_vcpu.debug_state_latch != debug_state) ) {
xen/arch/x86/hvm/svm/svm.c static void svm_ctxt_switch_to(struct vc · line 684
Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +4
-4-uint32_t mask = (1U << TRAP_debug) | (1U << TRAP_int3); v->arch.hvm_vcpu.debug_state_latch = debug_state;if ( debug_state ) - v->arch.hvm_svm.vmcb->exception_intercepts |= mask; -else - v->arch.hvm_svm.vmcb->exception_intercepts &= ~mask; + { +svm_set_exception_intercept (vmcb, TRAP_debug); +svm_set_exception_intercept (vmcb, TRAP_int3); + }
This seems to change the logic so it doesn't clear the intercepts if debug_state == 0. Is that OK?
More generally, I'm not sure I like having all the VMCB accessor functions in files called "cleanbits" -- wouldn't it make sense to have all that in the vmcb files so people will see them and know to use them? You could rename the actual vmcb fields as well to catch anyone writing them directly, e.g. in forward-ported patches.
Cheers,
Tim.
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 12 lines · On Wednesday 15 December 2010 12:27:51 Tim Deegan wrote:
Hi,
Thanks for the patch!
Quoted 7 lines · Christoph Egger
(quoted diff) +1
-0@@ -660,16 +671,17 @@ static void svm_ctxt_switch_to(struct vc static void svm_do_resume(struct vcpu *v) { + struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; bool_t debug_state = v->domain->debugger_attached;
Quoted 15 lines
Review static void svm_ctxt_switch_to(struct vc · line 684
Quoted 12 lines
(quoted diff) +4
-4if ( unlikely(v->arch.hvm_vcpu.debug_state_latch != debug_state) ) { - uint32_t mask = (1U << TRAP_debug) | (1U << TRAP_int3); v->arch.hvm_vcpu.debug_state_latch = debug_state; if ( debug_state ) - v->arch.hvm_svm.vmcb->exception_intercepts |= mask; - else - v->arch.hvm_svm.vmcb->exception_intercepts &= ~mask; + { + svm_set_exception_intercept(vmcb, TRAP_debug); + svm_set_exception_intercept(vmcb, TRAP_int3); + }This seems to change the logic so it doesn't clear the intercepts if
debug_state== 0. Is that OK?
No, that's not ok. I fixed that in the new patch.
Quoted 5 lines
More generally, I'm not sure I like having all the VMCB accessor functions in files called "cleanbits" -- wouldn't it make sense to have all that in the vmcb files so people will see them and know to use them? You could rename the actual vmcb fields as well to catch anyone writing them directly, e.g. in forward-ported patches.
I renamed the 'svmcleanbits.[ch]' files to 'vmc_funcs.[ch]'
Thanks for your review.
Christoph
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
# HG changeset patch
# User cegger
# Date 1292415876 -3600
vmcb cleanbits
xen/arch/x86/hvm/svm/Makefile +1 -0
@@ -3,5 +3,6 @@ obj-y += emulate.o obj-y += entry.o obj-y += intr.o obj-y += svm.o +obj-y += vmcb_funcs.o obj-y += vmcb.o obj-y += vpmu.o
xen/arch/x86/hvm/svm/asid.c +6 -4
@@ -21,6 +21,7 @@#include <xen/lib.h> #include <xen/perfc.h> #include <asm/hvm/svm/asid.h> +#include <asm/hvm/svm/vmcb_funcs.h> #include <asm/amd.h> void svm_asid_init (struct cpuinfo_x86 *c)
@@ -41,18 +42,19 @@ void svm_asid_init(struct cpuinfo_x86 *c asmlinkage void svm_asid_handle_vmrun(void) {struct vcpu *curr = current; +struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb;bool_t need_flush =hvm_asid_handle_vmenter ();/* ASID 0 indicates that ASIDs are disabled. */ if ( curr->arch.hvm_vcpu.asid ==0 ) { - curr->arch.hvm_svm.vmcb->guest_asid =1 ; - curr->arch.hvm_svm.vmcb->tlb_control =1 ; +svm_set_asid (vmcb,1 ); + vmcb->tlb_control =1 ;return ; } - curr->arch.hvm_svm.vmcb->guest_asid = curr->arch.hvm_vcpu.asid; - curr->arch.hvm_svm.vmcb->tlb_control = need_flush; +svm_set_asid (vmcb, curr->arch.hvm_vcpu.asid); + vmcb->tlb_control = need_flush; }/*
xen/arch/x86/hvm/svm/intr.c +4 -3
@@ -32,6 +32,7 @@#include <asm/hvm/support.h> #include <asm/hvm/vlapic.h> #include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm/vmcb_funcs.h> #include <asm/hvm/svm/intr.h> #include <xen/event.h> #include <xen/kernel.h>
@@ -56,7 +57,7 @@ static void svm_inject_nmi(struct vcpu ** SVM does not virtualise the NMI mask, so we emulate it by intercepting * the next IRET and blocking NMI injection until the intercept triggers. */ - vmcb->general1_intercepts |=GENERAL1_INTERCEPT_IRET ; +svm_set_general1_intercept (vmcb,GENERAL1_INTERCEPT_IRET ); }static void svm_inject_extint (struct vcpu *v,int vector)
@@ -108,8 +109,8 @@ static void enable_intr_window(struct vc intr.fields.vector =0 ; intr.fields.prio = intack.vector >>4 ; intr.fields.ign_tpr = (intack.source != hvm_intsrc_lapic); - vmcb->vintr = intr; - vmcb->general1_intercepts |=GENERAL1_INTERCEPT_VINTR ; +svm_set_vintr (vmcb, vintr, intr); +svm_set_general1_intercept (vmcb,GENERAL1_INTERCEPT_VINTR ); } asmlinkage void svm_intr_assist(void)
xen/arch/x86/hvm/svm/svm.c +78 -59
342 lines not on this page · raw message
xen/arch/x86/hvm/svm/vmcb.c +16 -43
101 lines not on this page · raw message
xen/arch/x86/hvm/svm/vmcb_funcs.c new file +57 -0
57 lines not on this page · raw message
xen/include/asm-x86/hvm/svm/svm.h +2 -0
@@ -68,12 +68,14 @@ extern u32 svm_feature_flags;#define SVM_FEATURE_LBRV 1#define SVM_FEATURE_SVML 2#define SVM_FEATURE_NRIPS 3 +#define SVM_FEATURE_CLEAN 5#define SVM_FEATURE_PAUSEF 10#define cpu_has_svm_npt test_bit(SVM_FEATURE_NPT, &svm_feature_flags)#define cpu_has_svm_lbrv test_bit(SVM_FEATURE_LBRV, &svm_feature_flags)#define cpu_has_svm_svml test_bit(SVM_FEATURE_SVML, &svm_feature_flags)#define cpu_has_svm_nrips test_bit(SVM_FEATURE_NRIPS, &svm_feature_flags) +#define cpu_has_svm_cleanbits test_bit(SVM_FEATURE_CLEAN, &svm_feature_flags)#define cpu_has_pause_filter test_bit(SVM_FEATURE_PAUSEF, &svm_feature_flags)#endif /* __ASM_X86_HVM_SVM_H__ */
xen/include/asm-x86/hvm/svm/vmcb.h +22 -6
@@ -366,6 +366,26 @@ typedef union } fields; } __attribute__ ((packed)) lbrctrl_t; +typedef union +{ +uint32_t bytes; +struct + { +uint32_t intercepts:1 ; +uint32_t iopm:1 ; +uint32_t asid:1 ; +uint32_t tpr:1 ; +uint32_t np:1 ; +uint32_t cr:1 ; +uint32_t dr:1 ; +uint32_t dt:1 ; +uint32_t seg:1 ; +uint32_t cr2:1 ; +uint32_t lbr:1 ; +uint32_t resv:21 ; + } fields; +} __attribute__ ((packed))vmcbcleanbits_t ; +struct vmcb_struct {u32 cr_intercepts;/* offset 0x00 */ u32 dr_intercepts;/* offset 0x04 */
@@ -397,7 +417,8 @@ struct vmcb_struct {eventinj_t eventinj;/* offset 0xA8 */ u64 h_cr3;/* offset 0xB0 */ lbrctrl_t lbr_control;/* offset 0xB8 */ -u64 res09;/* offset 0xC0 */ +vmcbcleanbits_t cleanbits;/* offset 0xC0 */ +u32 res09;/* offset 0xC4 */ u64 nextrip;/* offset 0xC8 */ u64 res10a[102 ];/* offset 0xD0 pad to save area */
@@ -481,11 +502,6 @@ int svm_create_vmcb(struct vcpu *v);void svm_destroy_vmcb (struct vcpu *v);void setup_vmcb_dump (void ); - -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int enable); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), 0) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), 1) -#endif /* ASM_X86_HVM_SVM_VMCS_H__ */ /*
xen/include/asm-x86/hvm/svm/vmcb_funcs.h new file +192 -0
192 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 12 lines · Christoph Egger
Quoted 2 lines · On Wednesday 15 December 2010 12:27:51 Tim Deegan wrote:
This seems to change the logic so it doesn't clear the intercepts if
debug_state== 0. Is that OK?No, that's not ok. I fixed that in the new patch.
Quoted 5 lines
More generally, I'm not sure I like having all the VMCB accessor functions in files called "cleanbits" -- wouldn't it make sense to have all that in the vmcb files so people will see them and know to use them? You could rename the actual vmcb fields as well to catch anyone writing them directly, e.g. in forward-ported patches.
Quoted 3 lines
I renamed the 'svmcleanbits.[ch]' files to 'vmc_funcs.[ch]'
Thanks for your review.
I went through this patch quite brutally when I applied it (c/s 22546). In particular I made the VMCB field accessor functions more consistent in name and semantics, and pulled out their implementations into a common macro to make the code clearer.
There should be no significant changes compared with your patch *EXCEPT*:
1. Updates to the MSR and I/O bitmaps do not affect clear bits
2. Updates to lbr_control.enable do not affect clear bits
3. Updates to debugctlmsr *do* affect clear bits
In the above I am following what is described in AMD Volume 2 Section 15.15.3 "VMCB Clean Field".
I note that the MSRPM_BASE and IOPM_BASE fields are listed as cacheable, but *no* mention is made of caching the bitmap contents.
Also, bit 10 (LBR) has debugctlmsr listed as cacheable, but again *no* mention is made of the lbr_control.enable bit flag.
If any of the above is wrong, then: (a) the reference manual should be fixed; (b) I would accept a fixup patch, with a patch description explaininbg why behaviour is deviating from cleanbits behaviour describved in the latest version of the AMD reference manuals.
-- Keir
Quoted 5 lines
Signed-off-by Wei Huang <[email protected]>Signed-off-by Christoph Egger <[email protected]>Christoph
Hi Keir,
Thanks for putting up this patch. I think the comments you made are correct after reading the spec again. Christoph and I misread some APM content. :-(
Thanks again,
-Wei
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: Wednesday, December 15, 2010 10:56 AM
To: Egger, Christoph; Tim Deegan
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH] svm: support VMCB cleanbits
Quoted 12 lines · Christoph Egger
Quoted 2 lines · On Wednesday 15 December 2010 12:27:51 Tim Deegan wrote:
This seems to change the logic so it doesn't clear the intercepts if
debug_state== 0. Is that OK?No, that's not ok. I fixed that in the new patch.
Quoted 5 lines
More generally, I'm not sure I like having all the VMCB accessor functions in files called "cleanbits" -- wouldn't it make sense to have all that in the vmcb files so people will see them and know to use them? You could rename the actual vmcb fields as well to catch anyone writing them directly, e.g. in forward-ported patches.
Quoted 3 lines
I renamed the 'svmcleanbits.[ch]' files to 'vmc_funcs.[ch]'
Thanks for your review.
I went through this patch quite brutally when I applied it (c/s 22546). In particular I made the VMCB field accessor functions more consistent in name and semantics, and pulled out their implementations into a common macro to make the code clearer.
There should be no significant changes compared with your patch *EXCEPT*:
1. Updates to the MSR and I/O bitmaps do not affect clear bits
2. Updates to lbr_control.enable do not affect clear bits
3. Updates to debugctlmsr *do* affect clear bits
In the above I am following what is described in AMD Volume 2 Section 15.15.3 "VMCB Clean Field".
I note that the MSRPM_BASE and IOPM_BASE fields are listed as cacheable, but *no* mention is made of caching the bitmap contents.
Also, bit 10 (LBR) has debugctlmsr listed as cacheable, but again *no* mention is made of the lbr_control.enable bit flag.
If any of the above is wrong, then: (a) the reference manual should be fixed; (b) I would accept a fixup patch, with a patch description explaininbg why behaviour is deviating from cleanbits behaviour describved in the latest version of the AMD reference manuals.
-- Keir
Quoted 5 lines
Signed-off-by Wei Huang <[email protected]>Signed-off-by Christoph Egger <[email protected]>Christoph
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 4 lines · Wei
Hi Keir,
Thanks for putting up this patch. I think the comments you made are correct after reading the spec again. Christoph and I misread some APM content. :-(
No problem then. It would be good to know that the applied patch works and with the same performance win as you saw with your original patch.
-- Keir
Quoted 69 lines
Thanks again,
-Wei-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: Wednesday, December 15, 2010 10:56 AM
To: Egger, Christoph; Tim Deegan
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH] svm: support VMCB cleanbitsQuoted 12 lines · Christoph Egger
Quoted 2 lines · On Wednesday 15 December 2010 12:27:51 Tim Deegan wrote:
This seems to change the logic so it doesn't clear the intercepts if
debug_state== 0. Is that OK?No, that's not ok. I fixed that in the new patch.
Quoted 5 lines
More generally, I'm not sure I like having all the VMCB accessor functions in files called "cleanbits" -- wouldn't it make sense to have all that in the vmcb files so people will see them and know to use them? You could rename the actual vmcb fields as well to catch anyone writing them directly, e.g. in forward-ported patches.
Quoted 3 lines
I renamed the 'svmcleanbits.[ch]' files to 'vmc_funcs.[ch]'
Thanks for your review.
I went through this patch quite brutally when I applied it (c/s 22546). In particular I made the VMCB field accessor functions more consistent in name and semantics, and pulled out their implementations into a common macro to make the code clearer.
There should be no significant changes compared with your patch *EXCEPT*:
1. Updates to the MSR and I/O bitmaps do not affect clear bits
2. Updates to lbr_control.enable do not affect clear bits
3. Updates to debugctlmsr *do* affect clear bitsIn the above I am following what is described in AMD Volume 2 Section 15.15.3 "VMCB Clean Field".
I note that the
MSRPM_BASEandIOPM_BASEfields are listed as cacheable, but *no* mention is made of caching the bitmap contents.Also, bit 10 (LBR) has debugctlmsr listed as cacheable, but again *no* mention is made of the lbr_control.enable bit flag.
If any of the above is wrong, then: (a) the reference manual should be fixed; (b) I would accept a fixup patch, with a patch description explaininbg why behaviour is deviating from cleanbits behaviour describved in the latest version of the AMD reference manuals.
-- Keir
Quoted 5 lines
Signed-off-by Wei Huang <[email protected]>Signed-off-by Christoph Egger <[email protected]>Christoph
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel