KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN
PATCH 1/1 KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN
From: Peng Hao <[email protected]>
When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.
arch/x86/kvm/emulate.c:3022:5: error: stack frame size (2520) exceeds limit (2048) in 'emulator_task_switch' [-Werror,-Wframe-larger-than]
int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
^
599/2520 (23.77%) spills, 1921/2520 (76.23%) variables
so increase the limit for configurations that have KASAN or KCSAN enabled for not breaking the majority of builds.
--- arch/x86/kvm/Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/kvm/Makefile +6 -0
@@ -5,6 +5,12 @@ ccflags-$(CONFIG_KVM_WERROR) += -Werror include $(srctree)/virt/kvm/Makefile.kvm +ifneq ($(CONFIG_FRAME_WARN),0) +ifeq ($(filter y,$(CONFIG_KASAN)$(CONFIG_KCSAN)),y) +CFLAGS_emulate.o = -Wframe-larger-than=2520 +endif +endif + kvm-y += x86.o emulate.o i8259.o irq.o lapic.o \ i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \ debugfs.o mmu/mmu.o mmu/page_track.o \
Signature · 1 line
2.27.0
Sean Christopherson
maintainerQuoted 5 lines · On Thu, Jun 13, 2024, [email protected] wrote:
From: Peng Hao <[email protected]>
When building kernel with clang, which will typically
have sanitizers enabled, there is a warning about a large stack frame.
Quoted 8 lines
arch/x86/kvm/emulate.c:3022:5: error: stack frame size (2520) exceeds limit (2048) in 'emulator_task_switch' [-Werror,-Wframe-larger-than]
int emulator_task_switch(structx86_emulate_ctxt*ctxt,^599/2520 (23.77%) spills, 1921/2520 (76.23%) variables
so increase the limit for configurations that have KASAN or KCSAN enabled for not breaking the majority of builds.
Overriding -Wframe-larger-than in KVM isn't maintainble or robust, and KVM shouldn't discard the userspace configuration.
Can you provide the relevant pieces of your .config? KVM already guards against KASAN, so maybe it's just KCSAN that's problematic? If that's the case, then I believe the below two patches will do the trick.
If KVM_WERROR is enabled because WERROR is enabled, then that's working as intended, i.e. the problem is in the config, not in KVM.
From: Sean Christopherson <[email protected]>
Date: Thu, 13 Jun 2024 12:03:13 -0700
Subject: [PATCH 1/2] KVM: x86: Disallow KVM_WERROR if KCSAN and/or KMSAN is
enabled
Extend KVM_WERROR's incompatibility list to include KCSAN and KMSAN, in addition to the existing KASAN restriction. Like KASAN, KCSAN and KMSAN require more memory and can cause problems with FRAME_WARN.
--- arch/x86/kvm/Kconfig | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
arch/x86/kvm/Kconfig +8 -7
@@ -61,13 +61,14 @@ config KVM config KVM_WERROR bool "Compile KVM with -Werror" - # Disallow KVM's -Werror if KASAN is enabled, e.g. to guard against - # randomized configs from selecting KVM_WERROR=y, which doesn't play - # nice with KASAN. KASAN builds generates warnings for the default - # FRAME_WARN, i.e. KVM_WERROR=y with KASAN=y requires special tuning. - # Building KVM with -Werror and KASAN is still doable via enabling - # the kernel-wide WERROR=y. - depends on KVM && ((EXPERT && !KASAN) || WERROR) + # Disallow KVM's -Werror if one or more sanitizers that requires extra + # memory is enabled, e.g. to guard against randomized configs selecting + # KVM_WERROR=y. Sanitizers often trip FRAME_WARN in KVM, i.e. enabling + # sanitizers+KVM_WERROR typically requires a hand-tuned config. + # + # Note, building KVM with -Werror and sanitizers is still doable via + # enabling the kernel-wide WERROR=y. + depends on KVM && ((EXPERT && (!KASAN && !KCSAN && !KMSAN)) || WERROR) help Add -Werror to the build flags for KVM.
base-commit: e4e9e1067138e5620cf0500c3e5f6ebfb9d322c8
Signature · 17 lines
2.45.2.627.g7a2c4fd464-goog From 2e20a81fbafb10eae6727fdf314404b67b449492 Mon Sep 17 00:00:00 2001 From: Sean Christopherson <[email protected]> Date: Thu, 13 Jun 2024 12:06:36 -0700 Subject: [PATCH 2/2] KVM: x86: Disallow KVM_WERROR with sanitizers iff FRAME_WARN is enabled Allow KVM_WERROR to be enabled alongside sanitizers if FRAME_WARN is disabled, as the sanitizers are problematic only because they increase the stack footprint and cause FRAME_WARN to fire, i.e. KVM isn't fundamentally incompatible with the sanitizers. Signed-off-by: Sean Christopherson <[email protected]> --- arch/x86/kvm/Kconfig | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
arch/x86/kvm/Kconfig +5 -4
@@ -62,13 +62,14 @@ config KVM config KVM_WERROR bool "Compile KVM with -Werror" # Disallow KVM's -Werror if one or more sanitizers that requires extra - # memory is enabled, e.g. to guard against randomized configs selecting - # KVM_WERROR=y. Sanitizers often trip FRAME_WARN in KVM, i.e. enabling - # sanitizers+KVM_WERROR typically requires a hand-tuned config. + # memory is enabled and FRAME_WARN is also enabled, e.g. to guard + # against randomized configs selecting KVM_WERROR=y. Sanitizers often + # trip FRAME_WARN in KVM, i.e. enabling sanitizers+KVM_WERROR typically + # requires a hand-tuned config. # # Note, building KVM with -Werror and sanitizers is still doable via # enabling the kernel-wide WERROR=y. - depends on KVM && ((EXPERT && (!KASAN && !KCSAN && !KMSAN)) || WERROR) + depends on KVM && ((EXPERT && ((!KASAN && !KCSAN && !KMSAN) || FRAME_WARN=0)) || WERROR) help Add -Werror to the build flags for KVM.
Signature · 1 line
2.45.2.627.g7a2c4fd464-goog