Re: [PATCH v6 22/25] x86/asm: annotate indirect jumps

From: Sami Tolvanen
Date: Fri Nov 13 2020 - 18:31:53 EST


On Fri, Nov 13, 2020 at 2:34 PM Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> On Fri, Nov 13, 2020 at 12:24:32PM -0800, Sami Tolvanen wrote:
> > > I still don't see this warning for some reason.
> >
> > Do you have CONFIG_XEN enabled? I can reproduce this on ToT master as follows:
> >
> > $ git rev-parse HEAD
> > 585e5b17b92dead8a3aca4e3c9876fbca5f7e0ba
> > $ make defconfig && \
> > ./scripts/config -e HYPERVISOR_GUEST -e PARAVIRT -e XEN && \
> > make olddefconfig && \
> > make -j110
> > ...
> > $ ./tools/objtool/objtool check -arfld vmlinux.o 2>&1 | grep secondary
> > vmlinux.o: warning: objtool: __startup_secondary_64()+0x2: return with
> > modified stack frame
> >
> > > Is it fixed by adding cpu_bringup_and_idle() to global_noreturns[] in
> > > tools/objtool/check.c?
> >
> > No, that didn't fix the warning. Here's what I tested:
>
> I think this fixes it:
>
> From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Subject: [PATCH] x86/xen: Fix objtool vmlinux.o validation of xen hypercalls
>
> Objtool vmlinux.o validation is showing warnings like the following:
>
> # tools/objtool/objtool check -barfld vmlinux.o
> vmlinux.o: warning: objtool: __startup_secondary_64()+0x2: return with modified stack frame
> vmlinux.o: warning: objtool: xen_hypercall_set_trap_table()+0x0: <=== (sym)
>
> Objtool falls through all the empty hypercall text and gets confused
> when it encounters the first real function afterwards. The empty unwind
> hints in the hypercalls aren't working for some reason. Replace them
> with a more straightforward use of STACK_FRAME_NON_STANDARD.
>
> Reported-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> ---
> arch/x86/xen/xen-head.S | 9 ++++-----
> include/linux/objtool.h | 8 ++++++++
> 2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
> index 2d7c8f34f56c..3c538b1ff4a6 100644
> --- a/arch/x86/xen/xen-head.S
> +++ b/arch/x86/xen/xen-head.S
> @@ -6,6 +6,7 @@
>
> #include <linux/elfnote.h>
> #include <linux/init.h>
> +#include <linux/objtool.h>
>
> #include <asm/boot.h>
> #include <asm/asm.h>
> @@ -67,14 +68,12 @@ SYM_CODE_END(asm_cpu_bringup_and_idle)
> .pushsection .text
> .balign PAGE_SIZE
> SYM_CODE_START(hypercall_page)
> - .rept (PAGE_SIZE / 32)
> - UNWIND_HINT_EMPTY
> - .skip 32
> - .endr
> + .skip PAGE_SIZE
>
> #define HYPERCALL(n) \
> .equ xen_hypercall_##n, hypercall_page + __HYPERVISOR_##n * 32; \
> - .type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32
> + .type xen_hypercall_##n, @function; .size xen_hypercall_##n, 32; \
> + STACK_FRAME_NON_STANDARD xen_hypercall_##n
> #include <asm/xen-hypercalls.h>
> #undef HYPERCALL
> SYM_CODE_END(hypercall_page)
> diff --git a/include/linux/objtool.h b/include/linux/objtool.h
> index 577f51436cf9..746617265236 100644
> --- a/include/linux/objtool.h
> +++ b/include/linux/objtool.h
> @@ -109,6 +109,12 @@ struct unwind_hint {
> .popsection
> .endm
>
> +.macro STACK_FRAME_NON_STANDARD func:req
> + .pushsection .discard.func_stack_frame_non_standard
> + .long \func - .
> + .popsection
> +.endm
> +
> #endif /* __ASSEMBLY__ */
>
> #else /* !CONFIG_STACK_VALIDATION */
> @@ -123,6 +129,8 @@ struct unwind_hint {
> .macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0
> .endm
> #endif
> +.macro STACK_FRAME_NON_STANDARD func:req
> +.endm

This macro needs to be before the #endif, so it's defined only for
assembly code. This breaks my arm64 builds even though x86 curiously
worked just fine.

Sami