[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 41/62] target-i386: mask NMIs on entry to SMM
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 41/62] target-i386: mask NMIs on entry to SMM |
Date: |
Fri, 5 Jun 2015 17:15:42 +0200 |
QEMU is not blocking NMIs on entry to SMM. Implementing this has to
cover a few corner cases, because:
- NMIs can then be enabled by an IRET instruction and there
is no mechanism to _set_ the "NMIs masked" flag on exit from SMM:
"A special case can occur if an SMI handler nests inside an NMI handler
and then another NMI occurs. [...] When the processor enters SMM while
executing an NMI handler, the processor saves the SMRAM state save map
but does not save the attribute to keep NMI interrupts disabled.
- However, there is some hidden state, because "If NMIs were blocked
before the SMI occurred [and no IRET is executed while in SMM], they
are blocked after execution of RSM." This is represented by the new
HF2_SMM_INSIDE_NMI_MASK bit. If it is zero, NMIs are _unblocked_
on exit from RSM.
Signed-off-by: Paolo Bonzini <address@hidden>
---
target-i386/cpu.h | 20 +++++++++++---------
target-i386/smm_helper.c | 9 +++++++++
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 7a06495..9dae9ab 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -180,15 +180,17 @@
/* hflags2 */
-#define HF2_GIF_SHIFT 0 /* if set CPU takes interrupts */
-#define HF2_HIF_SHIFT 1 /* value of IF_MASK when entering SVM */
-#define HF2_NMI_SHIFT 2 /* CPU serving NMI */
-#define HF2_VINTR_SHIFT 3 /* value of V_INTR_MASKING bit */
-
-#define HF2_GIF_MASK (1 << HF2_GIF_SHIFT)
-#define HF2_HIF_MASK (1 << HF2_HIF_SHIFT)
-#define HF2_NMI_MASK (1 << HF2_NMI_SHIFT)
-#define HF2_VINTR_MASK (1 << HF2_VINTR_SHIFT)
+#define HF2_GIF_SHIFT 0 /* if set CPU takes interrupts */
+#define HF2_HIF_SHIFT 1 /* value of IF_MASK when entering SVM */
+#define HF2_NMI_SHIFT 2 /* CPU serving NMI */
+#define HF2_VINTR_SHIFT 3 /* value of V_INTR_MASKING bit */
+#define HF2_SMM_INSIDE_NMI_SHIFT 4 /* CPU serving SMI nested inside NMI */
+
+#define HF2_GIF_MASK (1 << HF2_GIF_SHIFT)
+#define HF2_HIF_MASK (1 << HF2_HIF_SHIFT)
+#define HF2_NMI_MASK (1 << HF2_NMI_SHIFT)
+#define HF2_VINTR_MASK (1 << HF2_VINTR_SHIFT)
+#define HF2_SMM_INSIDE_NMI_MASK (1 << HF2_SMM_INSIDE_NMI_SHIFT)
#define CR0_PE_SHIFT 0
#define CR0_MP_SHIFT 1
diff --git a/target-i386/smm_helper.c b/target-i386/smm_helper.c
index b9971b6..6207c3a 100644
--- a/target-i386/smm_helper.c
+++ b/target-i386/smm_helper.c
@@ -52,6 +52,11 @@ void do_smm_enter(X86CPU *cpu)
log_cpu_state_mask(CPU_LOG_INT, CPU(cpu), CPU_DUMP_CCOP);
env->hflags |= HF_SMM_MASK;
+ if (env->hflags2 & HF2_NMI_MASK) {
+ env->hflags2 |= HF2_SMM_INSIDE_NMI_MASK;
+ } else {
+ env->hflags2 |= HF2_NMI_MASK;
+ }
cpu_smm_update(env);
sm_state = env->smbase + 0x8000;
@@ -307,6 +312,10 @@ void helper_rsm(CPUX86State *env)
env->smbase = x86_ldl_phys(cs, sm_state + 0x7ef8) & ~0x7fff;
}
#endif
+ if ((env->hflags2 & HF2_SMM_INSIDE_NMI_MASK) == 0) {
+ env->hflags2 &= ~HF2_NMI_MASK;
+ }
+ env->hflags2 &= ~HF2_SMM_INSIDE_NMI_MASK;
env->hflags &= ~HF_SMM_MASK;
cpu_smm_update(env);
--
2.4.1
- [Qemu-devel] [PULL 30/62] memory: use atomic ops for setting dirty memory bits, (continued)
- [Qemu-devel] [PULL 30/62] memory: use atomic ops for setting dirty memory bits, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 31/62] migration: move dirty bitmap sync to ram_addr.h, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 33/62] memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 32/62] memory: replace cpu_physical_memory_reset_dirty() with test-and-clear, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 34/62] memory: use mr->ram_addr in "is this RAM?" assertions, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 35/62] icount: implement a new icount_sleep mode toggleing real-time cpu sleep, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 36/62] icount: add sleep parameter to the icount option to set icount_sleep mode, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 37/62] icount: print a warning if there is no more deadline in sleep=no mode, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 38/62] target-i386: introduce cpu_get_mem_attrs, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 40/62] target-i386: Use correct memory attributes for ioport accesses, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 41/62] target-i386: mask NMIs on entry to SMM,
Paolo Bonzini <=
- [Qemu-devel] [PULL 42/62] target-i386: set G=1 in SMM big real mode selectors, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 43/62] target-i386: wake up processors that receive an SMI, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 44/62] pflash_cfi01: change big-endian property to BIT type, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 45/62] pflash_cfi01: change to new-style MMIO accessors, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 39/62] target-i386: Use correct memory attributes for memory accesses, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 46/62] pflash_cfi01: add secure property, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 47/62] vl: allow full-blown QemuOpts syntax for -global, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 48/62] qom: add object_property_add_const_link, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 49/62] vl: run "late" notifiers immediately, Paolo Bonzini, 2015/06/05
- [Qemu-devel] [PULL 50/62] target-i386: create a separate AddressSpace for each CPU, Paolo Bonzini, 2015/06/05