linux-stable/arch
Adam Dunlap d6decf4a4a x86/apic: Force native_apic_mem_read() to use the MOV instruction
commit 5ce344beac upstream.

When done from a virtual machine, instructions that touch APIC memory
must be emulated. By convention, MMIO accesses are typically performed
via io.h helpers such as readl() or writeq() to simplify instruction
emulation/decoding (ex: in KVM hosts and SEV guests) [0].

Currently, native_apic_mem_read() does not follow this convention,
allowing the compiler to emit instructions other than the MOV
instruction generated by readl(). In particular, when the kernel is
compiled with clang and run as a SEV-ES or SEV-SNP guest, the compiler
would emit a TESTL instruction which is not supported by the SEV-ES
emulator, causing a boot failure in that environment. It is likely the
same problem would happen in a TDX guest as that uses the same
instruction emulator as SEV-ES.

To make sure all emulators can emulate APIC memory reads via MOV, use
the readl() function in native_apic_mem_read(). It is expected that any
emulator would support MOV in any addressing mode as it is the most
generic and is what is usually emitted currently.

The TESTL instruction is emitted when native_apic_mem_read() is inlined
into apic_mem_wait_icr_idle(). The emulator comes from
insn_decode_mmio() in arch/x86/lib/insn-eval.c. It's not worth it to
extend insn_decode_mmio() to support more instructions since, in theory,
the compiler could choose to output nearly any instruction for such
reads which would bloat the emulator beyond reason.

  [0] https://lore.kernel.org/all/20220405232939.73860-12-kirill.shutemov@linux.intel.com/

  [ bp: Massage commit message, fix typos. ]

Signed-off-by: Adam Dunlap <acdunlap@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Tested-by: Kevin Loughlin <kevinloughlin@google.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20240318230927.2191933-1-acdunlap@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-17 11:23:40 +02:00
..
alpha RTC for 6.8 2024-01-18 17:25:39 -08:00
arc work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
arm ARM: OMAP2+: fix USB regression on Nokia N8x0 2024-04-17 11:23:26 +02:00
arm64 arm64: dts: imx8-ss-dma: fix spi lpcg indices 2024-04-17 11:23:39 +02:00
csky work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
hexagon hexagon: vmlinux.lds.S: handle attributes section 2024-04-03 15:32:39 +02:00
loongarch LoongArch/crypto: Clean up useless assignment operations 2024-04-03 15:32:25 +02:00
m68k kbuild: use 4-space indentation when followed by conditionals 2024-02-15 06:05:44 +09:00
microblaze Microblaze patches for 6.8-rc1 2024-01-17 11:27:23 -08:00
mips mips: cm: Convert __mips_cm_l2sync_phys_base() to weak function 2024-03-26 18:17:21 -04:00
nios2 percpu: 2024-01-18 15:01:28 -08:00
openrisc
parisc prctl: generalize PR_SET_MDWE support check to be per-arch 2024-04-03 15:32:37 +02:00
powerpc mm/treewide: replace pud_large() with pud_leaf() 2024-04-10 16:38:00 +02:00
riscv riscv: process: Fix kernel gp leakage 2024-04-10 16:38:20 +02:00
s390 s390/entry: align system call table on 8 bytes 2024-04-10 16:38:20 +02:00
sh sh updates for v6.8 2024-01-20 09:24:06 -08:00
sparc mm/treewide: replace pud_large() with pud_leaf() 2024-04-10 16:38:00 +02:00
um work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
x86 x86/apic: Force native_apic_mem_read() to use the MOV instruction 2024-04-17 11:23:40 +02:00
xtensa work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
.gitignore
Kconfig scs: add CONFIG_MMU dependency for vfree_atomic() 2024-01-25 23:52:21 -08:00