diff mbox series

KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN

Message ID 20240613021920.46508-1-flyingpeng@tencent.com (mailing list archive)
State New, archived
Headers show
Series KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN | expand

Commit Message

Hao Peng June 13, 2024, 2:19 a.m. UTC
From: Peng Hao <flyingpeng@tencent.com>

 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.

Signed-off-by: Peng Hao <flyingpeng@tencent.com>
---
 arch/x86/kvm/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Sean Christopherson June 13, 2024, 7:17 p.m. UTC | #1
On Thu, Jun 13, 2024, flyingpenghao@gmail.com wrote:
> From: Peng Hao <flyingpeng@tencent.com>
> 
>  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.

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 <seanjc@google.com>
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.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/Kconfig | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 80e5afde69f4..e12733574e92 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -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
diff mbox series

Patch

diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index addc44fc7187..2165262c1497 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -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 \