x86: kmsan: fix boot failure due to instrumentation
PATCH 1/1 x86: kmsan: fix boot failure due to instrumentation
Instrumenting sev.c and mem_encrypt_identity.c with KMSAN will result in kernel being unable to boot. Some of the code are invoked too early in boot stage that before kmsan is ready.
This change disable kmsan instrumentation for above two files to fix the boot failure.
--- arch/x86/kernel/Makefile | 1 + arch/x86/mm/Makefile | 1 + 2 files changed, 2 insertions(+)
arch/x86/kernel/Makefile +1 -0
@@ -33,6 +33,7 @@ KASAN_SANITIZE_sev.o := n KCSAN_SANITIZE := n KMSAN_SANITIZE_head$(BITS).o := n KMSAN_SANITIZE_nmi.o := n +KMSAN_SANITIZE_sev.o := n # If instrumentation of the following files is enabled, boot hangs during # first second.
arch/x86/mm/Makefile +1 -0
@@ -16,6 +16,7 @@ KASAN_SANITIZE_pgprot.o := n KCSAN_SANITIZE := n # Avoid recursion by not calling KMSAN hooks for CEA code. KMSAN_SANITIZE_cpu_entry_area.o := n +KMSAN_SANITIZE_mem_encrypt_identity.o := n ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_mem_encrypt.o = -pg
Signature · 1 line
2.25.1
Borislav Petkov
maintainerQuoted 3 lines · Changbin Du
Instrumenting
sev.candmem_encrypt_identity.cwith KMSAN will result in kernel being unable to boot. Some of the code are invoked too early in boot stage that before kmsan is ready.
How do you trigger this?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 7 lines · Borislav Petkov
Quoted 3 lines · Changbin Du
Instrumenting
sev.candmem_encrypt_identity.cwith KMSAN will result in kernel being unable to boot. Some of the code are invoked too early in boot stage that before kmsan is ready.How do you trigger this?
I run the kernel in qemu. One of the calltrace is:
(gdb) bt
#0 find_cc_blob (bp=0x14700 <exception_stacks+30464>) at arch/x86/kernel/sev.c:2067 #1 0x0000000003daeaab in snp_init (bp=0x14700 <exception_stacks+30464>) at arch/x86/kernel/sev.c:2098 #2 0x0000000003db3d69 in sme_enable (bp=0x14700 <exception_stacks+30464>) at arch/x86/mm/mem_encrypt_identity.c:516 #3 0x000000000100003e in startup_64 () at arch/x86/kernel/head_64.S:99 #4 0x0000000000000000 in ?? ()
find_cc_blob() has instrumentation enabled and panic when accessing shadow memory.
Quoted 5 lines
Signature · 4 lines
Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Signature · 2 lines
Cheers, Changbin Du
Borislav Petkov
maintainerQuoted 2 lines · Changbin Du
find_cc_blob()has instrumentation enabled and panic when accessing shadow memory.
Thanks, I was able to reproduce. With KMSAN enabled, a 5sec guest turns into a 2 minute snooze fest. :-)
Oh well.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette[tip: x86/sev] x86/sev: Disable KMSAN for memory encryption TUs
In reply to Changbin DuThe following commit has been merged into the x86/sev branch of tip:
The following commit has been merged into the x86/sev branch of tip:
Commit-ID: c0935fca6ba4799e5efc6daeee37887e84707d01 Gitweb: https://git.kernel.org/tip/c0935fca6ba4799e5efc6daeee37887e84707d01 Author: Changbin Du <[email protected]> AuthorDate: Fri, 08 Mar 2024 12:44:01 +08:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Fri, 08 Mar 2024 08:59:22 +01:00
x86/sev: Disable KMSAN for memory encryption TUs
Instrumenting sev.c and mem_encrypt_identity.c with KMSAN will result in a triple-faulting kernel. Some of the code is invoked too early during boot, before KMSAN is ready.
Disable KMSAN instrumentation for the two translation units.
[ bp: Massage commit message. ]
--- arch/x86/kernel/Makefile | 1 + arch/x86/mm/Makefile | 1 + 2 files changed, 2 insertions(+)
arch/x86/kernel/Makefile +1 -0
@@ -33,6 +33,7 @@ KASAN_SANITIZE_sev.o := n KCSAN_SANITIZE := n KMSAN_SANITIZE_head$(BITS).o := n KMSAN_SANITIZE_nmi.o := n +KMSAN_SANITIZE_sev.o := n # If instrumentation of the following files is enabled, boot hangs during # first second.
arch/x86/mm/Makefile +1 -0
@@ -16,6 +16,7 @@ KASAN_SANITIZE_pgprot.o := n KCSAN_SANITIZE := n # Avoid recursion by not calling KMSAN hooks for CEA code. KMSAN_SANITIZE_cpu_entry_area.o := n +KMSAN_SANITIZE_mem_encrypt_identity.o := n ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_mem_encrypt.o = -pg