KVM/x86: make function emulator_do_task_switch as noinline_for_stack
PATCH v2 1/1 KVM/x86: make function emulator_do_task_switch as noinline_for_stack
From: Peng Hao <[email protected]>
When KASAN is enabled and built with clang:
clang reportarch/x86/kvm/emulate.c:3022:5: error: stack frame size (2488) exceeds limit (2048) in 'emulator_task_switch' [-Werror,-Wframe-larger-than] int emulator_task_switch(struct x86_emulate_ctxt *ctxt,
^
since emulator_do_task_switch() consumes a lot of stack space, mark it as noinline_for_stack to prevent it from blowing up emulator_task_switch()'s stack size.
--- arch/x86/kvm/emulate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/emulate.c +1 -1
@@ -2918,7 +2918,7 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt, u16 old_tss_sel,return load_state_from_tss32 (ctxt, &tss_seg); } -static int emulator_do_task_switch (struct x86_emulate_ctxt *ctxt, +static noinline_for_stack int emulator_do_task_switch(struct x86_emulate_ctxt *ctxt,u16 tss_selector,int idt_index,int reason,bool has_error_code,u32 error_code) {
Signature · 1 line
2.27.0
Sean Christopherson
maintainerQuoted 11 lines · On Fri, Jul 12, 2024, [email protected] wrote:
From: Peng Hao <[email protected]>
When KASAN is enabled and built with clang:
clang reportarch/x86/kvm/emulate.c:3022:5: error: stack frame size (2488) exceeds limit (2048) in 'emulator_task_switch' [-Werror,-Wframe-larger-than] int emulator_task_switch(structx86_emulate_ctxt*ctxt,^since
emulator_do_task_switch()consumes a lot of stack space, mark it asnoinline_for_stackto prevent it from blowing up emulator_task_switch()'s stack size.
No, sprinkling noinline to combat KASAN stack frame sizes is not a maintainable approach. Practically speaking, KASAN + -Werror + FRAME_WARN=2048 is not a sane config.
Quoted 21 lines
Signed-off-by Peng Hao <[email protected]>--- arch/x86/kvm/emulate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/emulate.c +1
-1@@ -2918,7 +2918,7 @@ static int task_switch_32(struct x86_emulate_ctxt *ctxt, u16 old_tss_sel,return load_state_from_tss32 (ctxt, &tss_seg); } -static int emulator_do_task_switch (struct x86_emulate_ctxt *ctxt, +static noinline_for_stack int emulator_do_task_switch(struct x86_emulate_ctxt *ctxt,u16 tss_selector,int idt_index,int reason,bool has_error_code,u32 error_code) {Signature · 1 line
2.27.0