* [PATCH] KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN
@ 2024-06-13 2:19 flyingpenghao
2024-06-13 19:17 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: flyingpenghao @ 2024-06-13 2:19 UTC (permalink / raw)
To: seanjc, pbonzini; +Cc: kvm, Peng Hao
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(+)
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 \
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN
2024-06-13 2:19 [PATCH] KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN flyingpenghao
@ 2024-06-13 19:17 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2024-06-13 19:17 UTC (permalink / raw)
To: flyingpenghao; +Cc: pbonzini, kvm, Peng Hao
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
--
2.45.2.627.g7a2c4fd464-goog
From 2e20a81fbafb10eae6727fdf314404b67b449492 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <seanjc@google.com>
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 <seanjc@google.com>
---
arch/x86/kvm/Kconfig | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index e12733574e92..34f047426a71 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -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.
--
2.45.2.627.g7a2c4fd464-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-13 19:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 2:19 [PATCH] KVM/x86: increase frame warning limit in emulate when using KASAN or KCSAN flyingpenghao
2024-06-13 19:17 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox