Skip to contentSkip to conversation

KVM: SVM: Virtual GIF

PATCH Applied Janakarajan Natarajan 3 participants 5 messages Aug 23, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover KVM: SVM: Virtual GIF

This patchset adds support for the Virtual GIF (vGIF) feature. This feature allows the STGI and CLGI instructions to be executed in the Guest Mode and not require a #VMEXIT. With this, virtual interrupts can be controlled in the Guest Mode while still allowing physical interrupts to be intercepted by the hypervisor.

In order to provide this ability, two new bits are added to the VMCB at offset 60h:

* Bit 9 - VGIF value

	 : 0 -> Virtual interrupts are masked
	 : 1 -> Virtual interrupts are unmasked

* Bit 25 - AMD Virtual GIF enabled for this guest

	 : 0 -> Disabled
	 : 1 -> Enabled

When a VMRUN is executed and Bit 25 is set, the processor uses Bit 9 as the starting value of the virtual GIF. It then provides masking capability for when virtual interrupts are taken. Bit 9 is writeable by the hypervisor and loaded on VMRUN and saved on #VMEXIT. STGI/CLGI executed in the Guest Mode sets or clears the virtual GIF.

The advantage of this feature will be the greatly reduced number of world switches to support the STGI and CLGI instructions by the outermost hypervisor at Current Privilege Level (CPL) 0.

This has been tested with Xen, Hyper-V and KVM as the nested hypervisor.

v1->v2:

* Updated patch description and changed cpufeature definition to be similar to AMD documentation.

* Updated NMI logic. STGI intercept added to assit in opening NMI window. Suggested by Radim.

Janakarajan Natarajan (2):
KVM: SVM: Add Virtual GIF feature definition
KVM: SVM: Enable Virtual GIF feature

 arch/x86/include/asm/cpufeatures.h |  1 +
 arch/x86/include/asm/svm.h         |  6 ++++
 arch/x86/kvm/svm.c                 | 62 +++++++++++++++++++++++++++++++++-----
 3 files changed, 62 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 KVM: SVM: Add Virtual GIF feature definition

Add a new cpufeature definition for Virtual GIF.

---
 arch/x86/include/asm/cpufeatures.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +1 -0
index ca3c48c..0e25e7a 100644
@@ -287,6 +287,7 @@
 #define X86_FEATURE_PFTHRESHOLD (15*32+12) /* pause filter threshold */
 #define X86_FEATURE_AVIC	(15*32+13) /* Virtual Interrupt Controller */
 #define X86_FEATURE_VIRTUAL_VMLOAD_VMSAVE (15*32+15) /* Virtual VMLOAD VMSAVE */
+#define X86_FEATURE_VGIF	(15*32+16) /* Virtual GIF */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 16 */
 #define X86_FEATURE_AVX512VBMI  (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
Signature · 1 line
2.7.4
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] KVM: SVM: Add Virtual GIF feature definition

Quoted 13 lines · Janakarajan Natarajan

Add a new cpufeature definition for Virtual GIF.

---
 arch/x86/include/asm/cpufeatures.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpufeatures.h +0 -0
index ca3c48c..0e25e7a 100644

arch/x86/include/asm/cpufeatures.h line 293

Quoted 7 lines
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -287,6 +287,7 @@
 #define X86_FEATURE_PFTHRESHOLD (15*32+12) /* pause filter threshold */
 #define X86_FEATURE_AVIC	(15*32+13) /* Virtual Interrupt Controller */
 #define X86_FEATURE_VIRTUAL_VMLOAD_VMSAVE (15*32+15) /* Virtual VMLOAD VMSAVE */
+#define X86_FEATURE_VGIF	(15*32+16) /* Virtual GIF */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx), word 16 */
 #define X86_FEATURE_AVX512VBMI  (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/
Signature · 5 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 
#3 lore raw

PATCH v2 2/2 KVM: SVM: Enable Virtual GIF feature

In reply to Janakarajan Natarajan

Enable the Virtual GIF feature. This is done by setting bit 25 at position 60h in the vmcb.

With this feature enabled, the processor uses bit 9 at position 60h as the virtual GIF when executing STGI/CLGI instructions.

Since the execution of STGI by the L1 hypervisor does not cause a return to the outermost (L0) hypervisor, the enable_irq_window and enable_nmi_window are modified.

The IRQ window will be opened even if GIF is not set, under the assumption that on resuming the L1 hypervisor the IRQ will be held pending until the processor executes the STGI instruction.

For the NMI window, the STGI intercept is set. This will assist in opening the window only when GIF=1.

---
 arch/x86/include/asm/svm.h |  6 +++++
 arch/x86/kvm/svm.c         | 62 ++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 61 insertions(+), 7 deletions(-)
arch/x86/include/asm/svm.h +6 -0
index 58fffe7..14835dd 100644
@@ -107,6 +107,9 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
 #define V_IRQ_SHIFT 8
 #define V_IRQ_MASK (1 << V_IRQ_SHIFT)
 
+#define V_GIF_SHIFT 9
+#define V_GIF_MASK (1 << V_GIF_SHIFT)
+
 #define V_INTR_PRIO_SHIFT 16
 #define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT)
 
@@ -116,6 +119,9 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
 #define V_INTR_MASKING_SHIFT 24
 #define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT)
 
+#define V_GIF_ENABLE_SHIFT 25
+#define V_GIF_ENABLE_MASK (1 << V_GIF_ENABLE_SHIFT)
+
 #define AVIC_ENABLE_SHIFT 31
 #define AVIC_ENABLE_MASK (1 << AVIC_ENABLE_SHIFT)
 
arch/x86/kvm/svm.c +55 -7

121 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Applied
#4 lore raw
In reply to Janakarajan Natarajan
Quoted 29 lines · Janakarajan Natarajan

This patchset adds support for the Virtual GIF (vGIF) feature. This feature allows the STGI and CLGI instructions to be executed in the Guest Mode and not require a #VMEXIT. With this, virtual interrupts can be controlled in the Guest Mode while still allowing physical interrupts to be intercepted by the hypervisor.

In order to provide this ability, two new bits are added to the VMCB at offset 60h:

* Bit 9 - VGIF value

	 : 0 -> Virtual interrupts are masked
	 : 1 -> Virtual interrupts are unmasked

* Bit 25 - AMD Virtual GIF enabled for this guest

	 : 0 -> Disabled
	 : 1 -> Enabled

When a VMRUN is executed and Bit 25 is set, the processor uses Bit 9 as the starting value of the virtual GIF. It then provides masking capability for when virtual interrupts are taken. Bit 9 is writeable by the hypervisor and loaded on VMRUN and saved on #VMEXIT. STGI/CLGI executed in the Guest Mode sets or clears the virtual GIF.

The advantage of this feature will be the greatly reduced number of world switches to support the STGI and CLGI instructions by the outermost hypervisor at Current Privilege Level (CPL) 0.

This has been tested with Xen, Hyper-V and KVM as the nested hypervisor.

Quoted 7 lines

v1->v2:

* Updated patch description and changed cpufeature definition to be similar to AMD documentation.

* Updated NMI logic. STGI intercept added to assit in opening NMI window. Suggested by Radim.

Applied, thanks.

Paolo

Quoted 9 lines

Janakarajan Natarajan (2):
KVM: SVM: Add Virtual GIF feature definition
KVM: SVM: Enable Virtual GIF feature

 arch/x86/include/asm/cpufeatures.h |  1 +
 arch/x86/include/asm/svm.h         |  6 ++++
 arch/x86/kvm/svm.c                 | 62 +++++++++++++++++++++++++++++++++-----
 3 files changed, 62 insertions(+), 7 deletions(-)