Skip to content

Commit 3526d74

Browse files
committed
Merge tag 'x86-urgent-2026-05-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Ingo Molnar: - On SEV guests, handle set_memory_{encrypted,decrypted}() failures more conservatively by assuming that all affected pages are unencrypted (Carlos López) - Disable broadcast TLB flush when PCID is disabled (Tom Lendacky) - Fix VMX vs. hrtimer_rearm_deferred() regression (Peter Zijlstra) - Move IRQ/NMI dispatch code from KVM into x86 core, to prepare for a KVM x2apic fix (Peter Zijlstra) - Fix incorrect munmap() size on map_vdso() failure (Guilherme Giacomo Simoes) * tag 'x86-urgent-2026-05-24' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: virt: sev-guest: Explicitly leak pages in unknown state x86/mm: Disable broadcast TLB flush when PCID is disabled x86/kvm/vmx: Fix VMX vs hrtimer_rearm_deferred() x86/kvm/vmx: Move IRQ/NMI dispatch from KVM into x86 core x86/vdso: Fix incorrect size in munmap() on map_vdso() failure
2 parents a674bf7 + fd948c3 commit 3526d74

15 files changed

Lines changed: 141 additions & 72 deletions

File tree

arch/x86/entry/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ CFLAGS_REMOVE_syscall_64.o = $(CC_FLAGS_FTRACE)
1313
CFLAGS_syscall_32.o += -fno-stack-protector
1414
CFLAGS_syscall_64.o += -fno-stack-protector
1515

16-
obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o
16+
obj-y := entry.o entry_$(BITS).o syscall_$(BITS).o common.o
1717

1818
obj-y += vdso/
1919
obj-y += vsyscall/

arch/x86/entry/common.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#include <linux/entry-common.h>
4+
#include <linux/kvm_types.h>
5+
#include <linux/hrtimer_rearm.h>
6+
#include <asm/fred.h>
7+
#include <asm/desc.h>
8+
9+
#if IS_ENABLED(CONFIG_KVM_INTEL)
10+
/*
11+
* On VMX, NMIs and IRQs (as configured by KVM) are acknowledged by hardware as
12+
* part of the VM-Exit, i.e. the event itself is consumed as part the VM-Exit.
13+
* x86_entry_from_kvm() is invoked by KVM to effectively forward NMIs and IRQs
14+
* to the kernel for servicing. On SVM, a.k.a. AMD, the NMI/IRQ VM-Exit is
15+
* purely a signal that an NMI/IRQ is pending, i.e. the event that triggered
16+
* the VM-Exit is held pending until it's unblocked in the host.
17+
*/
18+
noinstr void x86_entry_from_kvm(unsigned int event_type, unsigned int vector)
19+
{
20+
if (event_type == EVENT_TYPE_EXTINT) {
21+
#ifdef CONFIG_X86_64
22+
/*
23+
* Use FRED dispatch, even when running IDT. The dispatch
24+
* tables are kept in sync between FRED and IDT, and the FRED
25+
* dispatch works well with CFI.
26+
*/
27+
fred_entry_from_kvm(event_type, vector);
28+
#else
29+
idt_entry_from_kvm(vector);
30+
#endif
31+
/*
32+
* Strictly speaking, only the NMI path requires noinstr.
33+
*/
34+
instrumentation_begin();
35+
/*
36+
* KVM/VMX will dispatch from IRQ-disabled but for a context
37+
* that will have IRQs-enabled. This confuses the entry code
38+
* and it will not have reprogrammed the timer. Do so now.
39+
*/
40+
hrtimer_rearm_deferred();
41+
instrumentation_end();
42+
43+
return;
44+
}
45+
46+
WARN_ON_ONCE(event_type != EVENT_TYPE_NMI);
47+
48+
#ifdef CONFIG_X86_64
49+
if (cpu_feature_enabled(X86_FEATURE_FRED))
50+
return fred_entry_from_kvm(event_type, vector);
51+
#endif
52+
53+
/*
54+
* Notably, we must use IDT dispatch for NMI when running in IDT mode.
55+
* The FRED NMI context is significantly different and will not work
56+
* right (specifically FRED fixed the NMI recursion issue).
57+
*/
58+
idt_entry_from_kvm(vector);
59+
}
60+
EXPORT_SYMBOL_FOR_KVM(x86_entry_from_kvm);
61+
#endif

arch/x86/entry/entry.S

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,49 @@ THUNK warn_thunk_thunk, __warn_thunk
7575
#if defined(CONFIG_STACKPROTECTOR) && defined(CONFIG_SMP)
7676
EXPORT_SYMBOL(__ref_stack_chk_guard);
7777
#endif
78+
79+
#if IS_ENABLED(CONFIG_KVM_INTEL)
80+
.macro IDT_DO_EVENT_IRQOFF call_insn call_target
81+
/*
82+
* Unconditionally create a stack frame, getting the correct RSP on the
83+
* stack (for x86-64) would take two instructions anyways, and RBP can
84+
* be used to restore RSP to make objtool happy (see below).
85+
*/
86+
push %_ASM_BP
87+
mov %_ASM_SP, %_ASM_BP
88+
89+
#ifdef CONFIG_X86_64
90+
/*
91+
* Align RSP to a 16-byte boundary (to emulate CPU behavior) before
92+
* creating the synthetic interrupt stack frame for the IRQ/NMI.
93+
*/
94+
and $-16, %rsp
95+
push $__KERNEL_DS
96+
push %rbp
97+
#endif
98+
pushf
99+
push $__KERNEL_CS
100+
\call_insn \call_target
101+
102+
/*
103+
* "Restore" RSP from RBP, even though IRET has already unwound RSP to
104+
* the correct value. objtool doesn't know the callee will IRET and,
105+
* without the explicit restore, thinks the stack is getting walloped.
106+
* Using an unwind hint is problematic due to x86-64's dynamic alignment.
107+
*/
108+
leave
109+
RET
110+
.endm
111+
112+
.pushsection .text, "ax"
113+
SYM_FUNC_START(idt_do_interrupt_irqoff)
114+
IDT_DO_EVENT_IRQOFF CALL_NOSPEC _ASM_ARG1
115+
SYM_FUNC_END(idt_do_interrupt_irqoff)
116+
.popsection
117+
118+
.pushsection .noinstr.text, "ax"
119+
SYM_FUNC_START(idt_do_nmi_irqoff)
120+
IDT_DO_EVENT_IRQOFF call asm_exc_nmi_kvm_vmx
121+
SYM_FUNC_END(idt_do_nmi_irqoff)
122+
.popsection
123+
#endif

arch/x86/entry/entry_64_fred.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,4 @@ SYM_FUNC_START(asm_fred_entry_from_kvm)
147147
RET
148148

149149
SYM_FUNC_END(asm_fred_entry_from_kvm)
150-
EXPORT_SYMBOL_FOR_KVM(asm_fred_entry_from_kvm);
151150
#endif

arch/x86/entry/vdso/vma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int map_vdso(const struct vdso_image *image, unsigned long addr)
178178
if (IS_ERR(vma)) {
179179
ret = PTR_ERR(vma);
180180
do_munmap(mm, text_start, image->size, NULL);
181-
do_munmap(mm, addr, image->size, NULL);
181+
do_munmap(mm, addr, VDSO_NR_PAGES * PAGE_SIZE, NULL);
182182
goto up_fail;
183183
}
184184

arch/x86/include/asm/desc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ extern void idt_setup_traps(void);
438438
extern void idt_setup_apic_and_irq_gates(void);
439439
extern bool idt_is_f00f_address(unsigned long address);
440440

441+
extern void idt_do_interrupt_irqoff(unsigned long address);
442+
extern void idt_do_nmi_irqoff(void);
443+
extern void idt_entry_from_kvm(unsigned int vector);
444+
441445
#ifdef CONFIG_X86_64
442446
extern void idt_setup_early_pf(void);
443447
#else

arch/x86/include/asm/desc_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct gate_struct {
145145
typedef struct gate_struct gate_desc;
146146

147147
#ifndef _SETUP
148-
static inline unsigned long gate_offset(const gate_desc *g)
148+
static __always_inline unsigned long gate_offset(const gate_desc *g)
149149
{
150150
#ifdef CONFIG_X86_64
151151
return g->offset_low | ((unsigned long)g->offset_middle << 16) |

arch/x86/include/asm/entry-common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ static __always_inline void arch_exit_to_user_mode(void)
9797
}
9898
#define arch_exit_to_user_mode arch_exit_to_user_mode
9999

100+
extern void x86_entry_from_kvm(unsigned int entry_type, unsigned int vector);
101+
100102
#endif

arch/x86/include/asm/fred.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ static __always_inline unsigned long fred_event_data(struct pt_regs *regs) { ret
110110
static inline void cpu_init_fred_exceptions(void) { }
111111
static inline void cpu_init_fred_rsps(void) { }
112112
static inline void fred_complete_exception_setup(void) { }
113-
static inline void fred_entry_from_kvm(unsigned int type, unsigned int vector) { }
114113
static inline void fred_sync_rsp0(unsigned long rsp0) { }
115114
static inline void fred_update_rsp0(void) { }
116115
#endif /* CONFIG_X86_FRED */

arch/x86/kernel/cpu/cpuid-deps.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static const struct cpuid_dep cpuid_deps[] = {
9292
{ X86_FEATURE_FRED, X86_FEATURE_LKGS },
9393
{ X86_FEATURE_SPEC_CTRL_SSBD, X86_FEATURE_SPEC_CTRL },
9494
{ X86_FEATURE_LASS, X86_FEATURE_SMAP },
95+
{ X86_FEATURE_INVLPGB, X86_FEATURE_PCID },
9596
{}
9697
};
9798

0 commit comments

Comments
 (0)