Skip to contentSkip to conversation

Virtual GIF

PATCH New Brian Woods 1 participant 3 messages Nov 16, 2017

lore
Share & tools
lore
#0 lore raw

v3 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 an AMD family 17h (EPYC 7401) system.

Changes since v2:
- Removed else in vgif init code in vmcb.c due to it being unnecessary

Changes since v1:
- Change a test condition from if it had the vgif feature to if it's enabled in the vmcb
- Update for the use of C99 bool type
- Added else in vgif init code in vmcb.c

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
#1 lore raw

PATCH v3 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
index 0956f860ef..ec1eda6a3e 100644
@@ -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
index 01ce20b0bd..595cfcf57b 100644
@@ -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
#2 lore raw

PATCH v3 2/2 x86/svm: Add virtual GIF support

In reply to 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.

---
 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
index 1de896e456..0705cf9cb8 100644
@@ -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 ( vmcb->_vintr.fields.vgif_enable )
+        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
index b9cf423fd9..6b7a462fcb 100644
@@ -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
index 997e7597e0..5a714be8f2 100644
@@ -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