linux-stable/arch/x86/include/asm
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
..
e820
fpu
numachip
shared
trace
uv
vdso
xen x86/xen: attempt to inflate the memory balloon on PVH 2024-04-13 13:10:10 +02:00
GEN-for-each-reg.h
Kbuild
acenv.h
acpi.h
acrn.h
agp.h
alternative.h
amd-ibs.h
amd_hsmp.h
amd_nb.h
apic.h x86/apic: Force native_apic_mem_read() to use the MOV instruction 2024-04-17 11:23:40 +02:00
apicdef.h
apm.h
arch_hweight.h
archrandom.h
asm-offsets.h
asm-prototypes.h x86/bugs: Fix the SRSO mitigation on Zen3/4 2024-04-03 15:32:49 +02:00
asm.h x86/sev: Fix position dependent variable references in startup code 2024-04-03 15:32:32 +02:00
atomic.h
atomic64_32.h
atomic64_64.h
audit.h
barrier.h
bios_ebda.h
bitops.h
boot.h x86/efistub: Remap kernel text read-only before dropping NX attribute 2024-04-10 16:38:23 +02:00
bootparam_utils.h
bug.h
bugs.h
cache.h
cacheflush.h
cacheinfo.h
ce4100.h
cfi.h
checksum.h
checksum_32.h
checksum_64.h
clocksource.h
cmdline.h
cmpxchg.h
cmpxchg_32.h
cmpxchg_64.h
coco.h x86/coco: Require seeding RNG with RDRAND on CoCo systems 2024-04-10 16:38:19 +02:00
compat.h
cpu.h
cpu_device_id.h
cpu_entry_area.h
cpufeature.h x86/cpufeatures: Add CPUID_LNX_5 to track recently added Linux-defined word 2024-04-10 16:38:01 +02:00
cpufeatures.h x86/bhi: Mitigate KVM by default 2024-04-10 16:38:24 +02:00
cpuid.h
cpuidle_haltpoll.h
cpumask.h
crash.h
crash_core.h crash: use macro to add crashk_res into iomem early for specific arch 2024-04-03 15:32:49 +02:00
current.h
debugreg.h
delay.h
desc.h
desc_defs.h
device.h
disabled-features.h x86/cpufeatures: Add new word for scattered features 2024-04-10 16:38:01 +02:00
div64.h
dma-mapping.h
dma.h
dmi.h
doublefault.h
dwarf2.h
edac.h
efi.h
elf.h
elfcore-compat.h
emergency-restart.h
emulate_prefix.h
enclu.h
entry-common.h x86/bugs: Use ALTERNATIVE() instead of mds_user_clear static key 2024-02-19 16:31:49 -08:00
espfix.h
exec.h
extable.h
extable_fixup_types.h
fb.h
fixmap.h
floppy.h
frame.h
fsgsbase.h
ftrace.h
futex.h
gart.h
genapic.h
geode.h
gsseg.h
hardirq.h
highmem.h
hpet.h
hugetlb.h
hw_breakpoint.h
hw_irq.h
hyperv-tlfs.h
hyperv_timer.h
hypervisor.h
i8259.h
ia32.h
ia32_unistd.h
ibt.h
idtentry.h
imr.h
inat.h
inat_types.h
init.h
insn-eval.h
insn.h
inst.h
intel-family.h x86/cpu: Add model number for Intel Clearwater Forest processor 2024-01-23 11:08:08 +01:00
intel-mid.h
intel_ds.h
intel_pconfig.h
intel_pt.h
intel_punit_ipc.h
intel_scu_ipc.h
intel_telemetry.h
invpcid.h
io.h x86/asm: Remove the __iomem annotation of movdir64b()'s dst argument 2024-03-26 18:16:30 -04:00
io_apic.h
io_bitmap.h
iomap.h
iommu.h
iosf_mbi.h
irq.h
irq_remapping.h
irq_stack.h
irq_vectors.h
irq_work.h
irqdomain.h
irqflags.h
ist.h
jailhouse_para.h
jump_label.h work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
kasan.h
kaslr.h
kbdleds.h
kdebug.h
kexec-bzimage64.h
kexec.h
kfence.h
kgdb.h
kmsan.h mm, kmsan: fix infinite recursion due to RCU critical section 2024-01-25 23:52:21 -08:00
kprobes.h
kvm-x86-ops.h
kvm-x86-pmu-ops.h
kvm_host.h KVM: x86: Give a hint when Win2016 might fail to boot due to XSAVES erratum 2024-01-31 16:21:00 -05:00
kvm_page_track.h
kvm_para.h
kvm_types.h
kvm_vcpu_regs.h
kvmclock.h
linkage.h
local.h
mach_timer.h
mach_traps.h
math_emu.h
mc146818rtc.h
mce.h
mem_encrypt.h x86/sme: Move early SME kernel encryption handling into .head.text 2024-04-10 16:38:23 +02:00
memtype.h
microcode.h
misc.h
mman.h
mmconfig.h
mmu.h
mmu_context.h
mmzone.h
mmzone_32.h
mmzone_64.h
module.h
mpspec.h
mpspec_def.h
mshyperv.h
msi.h
msr-index.h x86/bhi: Enumerate Branch History Injection (BHI) bug 2024-04-10 16:38:24 +02:00
msr-trace.h
msr.h
mtrr.h
mwait.h
nmi.h
nops.h
nospec-branch.h x86/bhi: Mitigate KVM by default 2024-04-10 16:38:24 +02:00
numa.h
numa_32.h
olpc.h
olpc_ofw.h
orc_header.h
orc_lookup.h
orc_types.h
page.h x86/mm: Ensure input to pfn_to_kaddr() is treated as a 64-bit type 2024-03-26 18:16:29 -04:00
page_32.h
page_32_types.h
page_64.h
page_64_types.h
page_types.h
paravirt.h
paravirt_api_clock.h
paravirt_types.h
parport.h
pc-conf-reg.h
pci-direct.h
pci-functions.h
pci.h
pci_x86.h
percpu.h
perf_event.h
perf_event_p4.h
pgalloc.h
pgtable-2level.h
pgtable-2level_types.h
pgtable-3level.h
pgtable-3level_types.h
pgtable-invert.h
pgtable.h
pgtable_32.h
pgtable_32_areas.h
pgtable_32_types.h
pgtable_64.h
pgtable_64_types.h
pgtable_areas.h
pgtable_types.h
pkeys.h
pkru.h
platform_sst_audio.h
pm-trace.h
posix_types.h
preempt.h
probe_roms.h
processor-cyrix.h
processor-flags.h
processor.h
prom.h
proto.h
pti.h
ptrace.h
purgatory.h
pvclock-abi.h
pvclock.h
qrwlock.h
qspinlock.h
qspinlock_paravirt.h
realmode.h
reboot.h
reboot_fixups.h
required-features.h x86/cpufeatures: Add new word for scattered features 2024-04-10 16:38:01 +02:00
resctrl.h
rmwcc.h work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
seccomp.h
sections.h
segment.h
serial.h
set_memory.h x86/mm: Regularize set_memory_p() parameters and make non-static 2024-03-01 08:31:41 +00:00
setup.h
setup_arch.h
sev-common.h
sev.h x86/sev: Move early startup code into .head.text section 2024-04-10 16:38:23 +02:00
sgx.h
shmparam.h
shstk.h
sigcontext.h
sigframe.h
sighandling.h
signal.h
simd.h
smap.h
smp.h
softirq_stack.h
sparsemem.h
spec-ctrl.h
special_insns.h x86/asm: Remove the __iomem annotation of movdir64b()'s dst argument 2024-03-26 18:16:30 -04:00
spinlock.h
spinlock_types.h
sta2x11.h
stackprotector.h
stacktrace.h
static_call.h
string.h
string_32.h
string_64.h
suspend.h
suspend_32.h x86/pm: Work around false positive kmemleak report in msr_build_context() 2024-04-03 15:32:28 +02:00
suspend_64.h
svm.h
switch_to.h
sync_bitops.h
sync_core.h
syscall.h x86/bhi: Add support for clearing branch history at syscall entry 2024-04-10 16:38:24 +02:00
syscall_wrapper.h x86/entry/ia32: Ensure s32 is sign extended to s64 2024-01-24 11:49:19 +01:00
syscalls.h
tdx.h
text-patching.h
thermal.h
thread_info.h
time.h
timer.h
timex.h
tlb.h
tlbbatch.h
tlbflush.h
topology.h
trace_clock.h
trap_pf.h
trapnr.h
traps.h
tsc.h
uaccess.h work around gcc bugs with 'asm goto' with outputs 2024-02-09 15:57:48 -08:00
uaccess_32.h
uaccess_64.h
umip.h
unaccepted_memory.h
unistd.h
unwind.h
unwind_hints.h
uprobes.h
user.h
user32.h
user_32.h
user_64.h
vdso.h
vermagic.h
vga.h
vgtod.h
vm86.h
vmalloc.h
vmware.h
vmx.h
vmxfeatures.h
vsyscall.h x86/mm: Move is_vsyscall_vaddr() into asm/vsyscall.h 2024-02-15 19:21:39 -08:00
vvar.h
word-at-a-time.h
x86_init.h x86/sev: Skip ROM range scans and validation for SEV-SNP guests 2024-04-03 15:32:51 +02:00
xor.h
xor_32.h
xor_64.h
xor_avx.h