Skip to content

x86: Don't invoke asm_exc_nmi() on the kernel stack

Lai Jiangshan kvm lkml stable xen-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 20 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4x86/xen/entry: Rename xenpv_exc_nmi to noist_exc_nmiarch/x86/include/asm/idtentry.h arch/x86/kernel/nmi.c arch/x86/xen/enlighten_pv.c +1 more+13 -86 replies
2/4x86/entry: Use asm_noist_exc_nmi() for NMI in early booting stagearch/x86/include/asm/idtentry.h arch/x86/kernel/idt.c arch/x86/kernel/nmi.c+11 -617 replies
3/4KVM/VMX: Invoke NMI non-IST entry instead of IST entryarch/x86/kernel/nmi.c arch/x86/kvm/vmx/vmx.c+9 -24 replies
4/4KVM/VMX: Fold handle_interrupt_nmi_irqoff() into its solo callerarch/x86/kvm/vmx/vmx.c+8 -113 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchSteven Rostedt (VMware)Paolo BonziniJuergen Gross
SeriesA-b
1/4A-b
2/4A-b
3/4
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [PATCH 0/4] x86: Don't invoke asm_exc_nmi() on the kernel stack

From: Lai Jiangshan <[email protected]>

In VMX, the NMI handler needs to be invoked after NMI VM-Exit.

Before the commit 1a5488ef0dcf6 ("KVM: VMX: Invoke NMI handler via indirect call instead of INTn"), the work is done by INTn ("int $2").

But INTn microcode is relatively expensive, so the commit reworked NMI VM-Exit handling to invoke the kernel handler by function call. And INTn doesn't set the NMI blocked flag required by the linux kernel NMI entry. So moving away from INTn are very reasonable.

Yet some details were missed. After the said commit applied, the NMI entry pointer is fetched from the IDT table and called from the kernel stack. But the NMI entry pointer installed on the IDT table is asm_exc_nmi() which expects to be invoked on the IST stack by the ISA. And it relies on the "NMI executing" variable on the IST stack to work correctly. When it is unexpectedly called from the kernel stack, the RSP-located "NMI executing" variable is also on the kernel stack and is "uninitialized" and can cause the NMI entry to run in the wrong way.

During fixing the problem for KVM, I found that there might be the same problem for early booting stage where the IST is not set up. asm_exc_nmi() is not allowed to be used in this stage for the same reason about the RSP-located "NMI executing" variable.

For both cases, we should use asm_noist_exc_nmi() which is introduced in the patch 1 via renaming from an existing asm_xenpv_exc_nmi() and which is safe on the kernel stack.

https://lore.kernel.org/lkml/[email protected]/

Cc Thomas Gleixner <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Sean Christopherson <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Vitaly Kuznetsov <[email protected]>
Cc Wanpeng Li <[email protected]>
Cc Jim Mattson <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Uros Bizjak <[email protected]>
Cc Maxim Levitsky <[email protected]>

Lai Jiangshan (4):
x86/xen/entry: Rename xenpv_exc_nmi to noist_exc_nmi x86/entry: Use asm_noist_exc_nmi() for NMI in early booting stage KVM/VMX: Invoke NMI non-IST entry instead of IST entry KVM/VMX: fold handle_interrupt_nmi_irqoff() into its solo caller

 arch/x86/include/asm/idtentry.h |  4 +---
 arch/x86/kernel/idt.c           |  8 +++++++-
 arch/x86/kernel/nmi.c           | 12 ++++++++++++
 arch/x86/kvm/vmx/vmx.c          | 27 ++++++++++++++-------------
 arch/x86/xen/enlighten_pv.c     |  9 +++------
 arch/x86/xen/xen-asm.S          |  2 +-
 6 files changed, 38 insertions(+), 24 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b