Skip to content

Commit 900eeca

Browse files
Lara Lazierbonzini
authored andcommitted
target/i386: Added VGIF feature
VGIF allows STGI and CLGI to execute in guest mode and control virtual interrupts in guest mode. When the VGIF feature is enabled then: * executing STGI in the guest sets bit 9 of the VMCB offset 60h. * executing CLGI in the guest clears bit 9 of the VMCB offset 60h. Signed-off-by: Lara Lazier <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 97afb47 commit 900eeca

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

target/i386/cpu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,8 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
631631
#define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \
632632
CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A)
633633
#define TCG_EXT4_FEATURES 0
634-
#define TCG_SVM_FEATURES CPUID_SVM_NPT
634+
#define TCG_SVM_FEATURES (CPUID_SVM_NPT | CPUID_SVM_VGIF | \
635+
CPUID_SVM_SVME_ADDR_CHK)
635636
#define TCG_KVM_FEATURES 0
636637
#define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \
637638
CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX | \

target/i386/svm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#define V_IRQ_SHIFT 8
1010
#define V_IRQ_MASK (1 << V_IRQ_SHIFT)
1111

12+
#define V_GIF_ENABLED_SHIFT 25
13+
#define V_GIF_ENABLED_MASK (1 << V_GIF_ENABLED_SHIFT)
14+
15+
#define V_GIF_SHIFT 9
16+
#define V_GIF_MASK (1 << V_GIF_SHIFT)
17+
1218
#define V_INTR_PRIO_SHIFT 16
1319
#define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT)
1420

target/i386/tcg/sysemu/svm_helper.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ static inline bool is_efer_invalid_state (CPUX86State *env)
121121
return false;
122122
}
123123

124+
static inline bool virtual_gif_enabled(CPUX86State *env, uint32_t *int_ctl)
125+
{
126+
if (likely(env->hflags & HF_GUEST_MASK)) {
127+
*int_ctl = x86_ldl_phys(env_cpu(env),
128+
env->vm_vmcb + offsetof(struct vmcb, control.int_ctl));
129+
return (env->features[FEAT_SVM] & CPUID_SVM_VGIF)
130+
&& (*int_ctl & V_GIF_ENABLED_MASK);
131+
}
132+
return false;
133+
}
134+
124135
void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)
125136
{
126137
CPUState *cs = env_cpu(env);
@@ -510,13 +521,29 @@ void helper_vmsave(CPUX86State *env, int aflag)
510521
void helper_stgi(CPUX86State *env)
511522
{
512523
cpu_svm_check_intercept_param(env, SVM_EXIT_STGI, 0, GETPC());
513-
env->hflags2 |= HF2_GIF_MASK;
524+
525+
CPUState *cs = env_cpu(env);
526+
uint32_t int_ctl;
527+
if (virtual_gif_enabled(env, &int_ctl)) {
528+
x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
529+
int_ctl | V_GIF_MASK);
530+
} else {
531+
env->hflags2 |= HF2_GIF_MASK;
532+
}
514533
}
515534

516535
void helper_clgi(CPUX86State *env)
517536
{
518537
cpu_svm_check_intercept_param(env, SVM_EXIT_CLGI, 0, GETPC());
519-
env->hflags2 &= ~HF2_GIF_MASK;
538+
539+
CPUState *cs = env_cpu(env);
540+
uint32_t int_ctl;
541+
if (virtual_gif_enabled(env, &int_ctl)) {
542+
x86_stl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
543+
int_ctl & ~V_GIF_MASK);
544+
} else {
545+
env->hflags2 &= ~HF2_GIF_MASK;
546+
}
520547
}
521548

522549
bool cpu_svm_has_intercept(CPUX86State *env, uint32_t type)

0 commit comments

Comments
 (0)