Re: [kvm-unit-tests PATCH v2 0/4] Better backtraces for leaf functions

Sean Christopherson
2025-11-17T22:19:05Z

On Sat, Nov 15, 2025, Mathias Krause wrote:
> On 14.11.25 19:25, Sean Christopherson wrote:
> > On Mon, 15 Sep 2025 23:54:28 +0200, Mathias Krause wrote:
> >> This is v2 of [1], trying to enhance backtraces involving leaf
> >> functions.
> >>
> >> This version fixes backtraces on ARM and ARM64 as well, as ARM currently
> >> fails hard for leaf functions lacking a proper stack frame setup, making
> >> it dereference invalid pointers. ARM64 just skips frames, much like x86
> >> does.
> >>
> >> [...]
> >
> > Applied to kvm-x86 next, thanks!
>
> Thanks a lot, Sean!
>
> > P.S. This also prompted me to get pretty_print_stacks.py working in my
> > environment, so double thanks!
>
> Haha, you're welcome! :D
>
> >
> > [1/4] Makefile: Provide a concept of late CFLAGS
> > https://github.com/kvm-x86/kvm-unit-tests/commit/816fe2d45aed
> > [2/4] x86: Better backtraces for leaf functions
> > https://github.com/kvm-x86/kvm-unit-tests/commit/f01ea38a385a

Spoke too soon :-(

The x86 change breaks the realmode test. I didn't try hard to debug, as that
test is brittle, e.g. see https://lore.kernel.org/all/20240604143507.1041901-1-pbonzini@redhat.com.

I can't for the life of me figure out how to get Makefile variables to do what I
want, so for now I'm going to drop the x86 change so as not to block the rest of
the stuff I've got applied.

I'll keep the rest applied, so just resubmit the x86 patch against kvm-x86/next.

FWIW, conceptually I think we want something like this:

diff --git a/x86/Makefile.common b/x86/Makefile.common
index be18a77a..65e41578 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -44,6 +44,7 @@ COMMON_CFLAGS += -O1
KEEP_FRAME_POINTER := y

ifneq ($(KEEP_FRAME_POINTER),)
+ifneq ($(no_profiling),y)
# Fake profiling to force the compiler to emit a frame pointer setup also in
# leaf function (-mno-omit-leaf-frame-pointer doesn't work, unfortunately).
#
@@ -53,6 +54,7 @@ ifneq ($(KEEP_FRAME_POINTER),)
# during compilation makes this do "The Right Thing."
LATE_CFLAGS += $(call cc-option, -pg -mnop-mcount, "")
endif
+endif

FLATLIBS = lib/libcflat.a

@@ -120,6 +122,7 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o $(SRCDIR)/$(TEST_DIR)/realmode.
$(LD) -m elf_i386 -nostdlib -o $@ \
-T $(SRCDIR)/$(TEST_DIR)/realmode.lds $(filter %.o, $^)

+$(TEST_DIR)/realmode.o: no_profiling = y
$(TEST_DIR)/realmode.o: bits = $(realmode_bits)

$(TEST_DIR)/access_test.$(bin): $(TEST_DIR)/access.o

> > [3/4] arm64: Better backtraces for leaf functions
> > https://github.com/kvm-x86/kvm-unit-tests/commit/da1804215c8e
> > [4/4] arm: Fix backtraces involving leaf functions
> > https://github.com/kvm-x86/kvm-unit-tests/commit/c885c94f523e
> >
> > --
> > https://github.com/kvm-x86/kvm-unit-tests/tree/next
>