Virtual GIF
cover Virtual GIF
On AMD family 17h processors, there is a feature called virtual GIF. This allows a nested hypervisor to preform a CLGI or STGI without needing to be intercepted by the host hypervisor. For more information about it please see:
AMD64 Architecture Programmer’s Manual Volume 2: System Programming
http://support.amd.com/TechDocs/24593.pdf
Section: Virtual GIF (Section 15.33.2)
This patch series adds support to check for and enable the virtual GIF features if available.
These patches were tested on a AMD family 17h (EPYC 7401) system.
Brian Woods (2):
x86/svm: Add virtual GIF feature definition
x86/svm: Add virtual GIF support
xen/arch/x86/hvm/svm/nestedsvm.c | 7 ++++++- xen/arch/x86/hvm/svm/svm.c | 1 + xen/arch/x86/hvm/svm/vmcb.c | 9 +++++++++ xen/include/asm-x86/hvm/svm/svm.h | 2 ++ xen/include/asm-x86/hvm/svm/vmcb.h | 6 ++++-- 5 files changed, 22 insertions(+), 3 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/2 x86/svm: Add virtual GIF feature definition
Add support for enabling the virtual GIF feature.
--- xen/include/asm-x86/hvm/svm/svm.h | 2 ++ xen/include/asm-x86/hvm/svm/vmcb.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-)
xen/include/asm-x86/hvm/svm/svm.h +2 -0
@@ -64,6 +64,7 @@ extern u32 svm_feature_flags;#define SVM_FEATURE_FLUSHBYASID 6/* TLB flush by ASID support */ #define SVM_FEATURE_DECODEASSISTS 7/* Decode assists support */ #define SVM_FEATURE_PAUSEFILTER 10/* Pause intercept filter support */ +#define SVM_FEATURE_VGIF 16/* Virtual GIF */ #define cpu_has_svm_feature (f) test_bit(f, &svm_feature_flags)#define cpu_has_svm_npt cpu_has_svm_feature(SVM_FEATURE_NPT)
@@ -72,6 +73,7 @@ extern u32 svm_feature_flags;#define cpu_has_svm_nrips cpu_has_svm_feature(SVM_FEATURE_NRIPS)#define cpu_has_svm_cleanbits cpu_has_svm_feature(SVM_FEATURE_VMCBCLEAN)#define cpu_has_svm_decode cpu_has_svm_feature(SVM_FEATURE_DECODEASSISTS) +#define cpu_has_svm_vgif cpu_has_svm_feature(SVM_FEATURE_VGIF)#define cpu_has_pause_filter cpu_has_svm_feature(SVM_FEATURE_PAUSEFILTER)#define cpu_has_tsc_ratio cpu_has_svm_feature(SVM_FEATURE_TSCRATEMSR)
xen/include/asm-x86/hvm/svm/vmcb.h +4 -2
@@ -325,12 +325,14 @@ typedef union { u64 tpr: 8; u64 irq: 1; - u64 rsvd0: 7; + u64 vgif: 1; + u64 rsvd0: 6; u64 prio: 4; u64 ign_tpr: 1; u64 rsvd1: 3; u64 intr_masking: 1; - u64 rsvd2: 7; + u64 vgif_enable: 1; + u64 rsvd2: 6; u64 vector: 8; u64 rsvd3: 24; } fields;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 x86/svm: Add virtual GIF support
In reply to Brian WoodsThis patch detects and enables Virtual GIF if available. This allows a nested hypervisor to perform STGIs and CLGIs without having to be intercepted by host hypervisor.
--- xen/arch/x86/hvm/svm/nestedsvm.c | 7 ++++++- xen/arch/x86/hvm/svm/svm.c | 1 + xen/arch/x86/hvm/svm/vmcb.c | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/svm/nestedsvm.c +6 -1
@@ -1597,8 +1597,13 @@ bool_t nestedsvm_gif_isset(struct vcpu *v) {struct nestedsvm *svm = &vcpu_nestedsvm (v); +struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; -return (!!svm->ns_gif); +/* get the vmcb gif value if using vgif */ +if ( cpu_has_svm_vgif ) +return (!!vmcb->_vintr.fields.vgif); +else +return (!!svm->ns_gif); }void svm_vmexit_do_stgi (struct cpu_user_regs *regs,struct vcpu *v)
xen/arch/x86/hvm/svm/svm.c +1 -0
@@ -1669,6 +1669,7 @@ const struct hvm_function_table * __init start_svm(void)P (cpu_has_svm_nrips,"Next-RIP Saved on #VMEXIT" );P (cpu_has_svm_cleanbits,"VMCB Clean Bits" );P (cpu_has_svm_decode,"DecodeAssists" ); +P (cpu_has_svm_vgif,"Virtual GIF" );P (cpu_has_pause_filter,"Pause-Intercept Filter" );P (cpu_has_tsc_ratio,"TSC Rate MSR" );#undef P
xen/arch/x86/hvm/svm/vmcb.c +9 -0
@@ -206,6 +206,15 @@ static int construct_vmcb(struct vcpu *v) vmcb->_exception_intercepts |= (1U << TRAP_page_fault); } +/* if available, enable and configure virtual gif */ +if ( cpu_has_svm_vgif ) + { + vmcb->_vintr.fields.vgif =1 ; + vmcb->_vintr.fields.vgif_enable =1 ; + vmcb->_general2_intercepts &= ~GENERAL2_INTERCEPT_STGI ; + vmcb->_general2_intercepts &= ~GENERAL2_INTERCEPT_CLGI ; + } +if ( cpu_has_pause_filter ) { vmcb->_pause_filter_count =SVM_PAUSEFILTER_INIT ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH 2/2] x86/svm: Add virtual GIF support
Quoted 16 lines · Brian Woods
This patch detects and enables Virtual GIF if available. This allows a nested hypervisor to perform STGIs and CLGIs without having to be intercepted by host hypervisor.
Signed-off-by Brian Woods <[email protected]>--- xen/arch/x86/hvm/svm/nestedsvm.c | 7 ++++++- xen/arch/x86/hvm/svm/svm.c | 1 + xen/arch/x86/hvm/svm/vmcb.c | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-)xen/arch/x86/hvm/svm/nestedsvm.c +0
-0
xen/arch/x86/hvm/svm/nestedsvm.c bool_t · line 1597
Quoted 1 line
xen/arch/x86/hvm/svm/nestedsvm.c +0
-0@@ -1597,8 +1597,13 @@ bool_t nestedsvm_gif_isset(struct vcpu *v)
bool_t used to be char, which is why this function had !! semantics.
Since 4.7, bool_t switched to being a C99 bool, and we've been slowly updating the codebase to match.
Please would you update the prototype to use bool, and drop the now-unnecessary !!'s
xen/arch/x86/hvm/svm/nestedsvm.c bool_t · line 1603
Quoted 7 lines
xen/arch/x86/hvm/svm/nestedsvm.c +3
-1{struct nestedsvm *svm = &vcpu_nestedsvm (v); +struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb; -return (!!svm->ns_gif); +/* get the vmcb gif value if using vgif */ +if ( cpu_has_svm_vgif )
vmcb->_vintr.fields.vgif_enabled ?
While the two are synonymous at the moment, this would be more accurate. Also, in some copious free time, I'd like to add the ability to control the L0 hypervisor features on a per-guest basis, so you can sensibly test a domain with and without (in this case) VGIF support on the same host without hacking at the hypervisor.
~Andrew
Quoted 28 lines
xen/arch/x86/hvm/svm/nestedsvm.c +3
-0+return (!!vmcb->_vintr.fields.vgif); + else + return (!!svm->ns_gif); }void svm_vmexit_do_stgi (struct cpu_user_regs *regs,struct vcpu *v)xen/arch/x86/hvm/svm/svm.c +1
-0@@ -1669,6 +1669,7 @@ const struct hvm_function_table * __init start_svm(void)P (cpu_has_svm_nrips,"Next-RIP Saved on #VMEXIT" );P (cpu_has_svm_cleanbits,"VMCB Clean Bits" );P (cpu_has_svm_decode,"DecodeAssists" ); +P (cpu_has_svm_vgif,"Virtual GIF" );P (cpu_has_pause_filter,"Pause-Intercept Filter" );P (cpu_has_tsc_ratio,"TSC Rate MSR" );#undef Pxen/arch/x86/hvm/svm/vmcb.c +2
-0@@ -206,6 +206,15 @@ static int construct_vmcb(struct vcpu *v) vmcb->_exception_intercepts |= (1U << TRAP_page_fault); } +/* if available, enable and configure virtual gif */ +if ( cpu_has_svm_vgif )
xen/arch/x86/hvm/svm/vmcb.c static int construct_vmcb(struct vcpu *v) · line 220
Quoted 10 lines
xen/arch/x86/hvm/svm/vmcb.c +7
-0+ { + vmcb->_vintr.fields.vgif =1 ; + vmcb->_vintr.fields.vgif_enable =1 ; + vmcb->_general2_intercepts &= ~GENERAL2_INTERCEPT_STGI ; + vmcb->_general2_intercepts &= ~GENERAL2_INTERCEPT_CLGI ; + } +if ( cpu_has_pause_filter ) { vmcb->_pause_filter_count =SVM_PAUSEFILTER_INIT ;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel