All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/asm: Force native_apic_mem_read to use mov
@ 2022-08-11 18:00 Adam Dunlap
  2022-08-11 19:27 ` Sean Christopherson
  2022-08-11 19:53 ` [PATCH] " H. Peter Anvin
  0 siblings, 2 replies; 21+ messages in thread
From: Adam Dunlap @ 2022-08-11 18:00 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	Kirill A. Shutemov, Sean Christopherson,
	Kuppuswamy Sathyanarayanan, Andi Kleen, Adam Dunlap, Ben Dooks,
	linux-kernel, llvm
  Cc: Jacob Xu, Alper Gun, Marc Orr

Previously, when compiled with clang, native_apic_mem_read gets inlined
into __xapic_wait_icr_idle and optimized to a testl instruction. When
run in a VM with SEV-ES enabled, it attempts to emulate this
instruction, but the emulator does not support it. Instead, use inline
assembly to force native_apic_mem_read to use the mov instruction which
is supported by the emulator.

Signed-off-by: Adam Dunlap <acdunlap@google.com>
Reviewed-by: Marc Orr <marcorr@google.com>
Reviewed-by: Jacob Xu <jacobhxu@google.com>
---
 arch/x86/include/asm/apic.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 3415321c8240..281db79e76a9 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -109,7 +109,18 @@ static inline void native_apic_mem_write(u32 reg, u32 v)
 
 static inline u32 native_apic_mem_read(u32 reg)
 {
-	return *((volatile u32 *)(APIC_BASE + reg));
+	volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg);
+	u32 out;
+
+	/*
+	 * Functionally, what we want to do is simply return *addr. However,
+	 * this accesses an MMIO which may need to be emulated in some cases.
+	 * The emulator doesn't necessarily support all instructions, so we
+	 * force the read from addr to use a mov instruction.
+	 */
+	asm_inline("movl %1, %0" : "=r"(out) : "m"(*addr));
+
+	return out;
 }
 
 extern void native_apic_wait_icr_idle(void);
-- 
2.37.1.559.g78731f0fdb-goog


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2023-11-17 19:23 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 18:00 [PATCH] x86/asm: Force native_apic_mem_read to use mov Adam Dunlap
2022-08-11 19:27 ` Sean Christopherson
2022-08-11 19:57   ` H. Peter Anvin
2022-08-11 20:03     ` Sean Christopherson
2022-08-12  4:40       ` H. Peter Anvin
2022-08-12 18:32         ` Adam Dunlap
2022-08-12 18:35           ` [PATCH v2] " Adam Dunlap
2022-09-08 17:04             ` [PATCH v2 RESEND] " Adam Dunlap
2022-09-14 11:13               ` Peter Gonda
2022-09-14 11:59                 ` Marc Orr
2022-09-14 11:59                   ` Marc Orr
2022-09-15  7:51                     ` Tom Lendacky
2022-09-14 12:03                 ` Dave Hansen
2022-09-14 16:22                   ` Sean Christopherson
2022-09-15  8:09                     ` Peter Gonda
     [not found]                       ` <CAMBK9=YB=8EQymDUda300qPFAL1=7dzC61c0pshrWEC5ibrUfQ@mail.gmail.com>
2022-10-03 23:07                         ` Adam Dunlap
     [not found]                         ` <B7175642-351D-44A0-B7AD-E69C6B64FC18@zytor.com>
2022-10-05 13:28                           ` Tom Lendacky
2022-11-17 21:23                             ` Marc Orr
2023-11-17 18:14                               ` Sidharth Telang
2023-11-17 19:23                                 ` Dave Hansen
2022-08-11 19:53 ` [PATCH] " H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.