From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04FD6C433EF for ; Tue, 1 Feb 2022 13:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HNeBTmhglbCnl9MbsmP9LBGs/IHWUguutlD+1zXlH6k=; b=TiOm4lpwJggSuR 0rATjI5Ih5yY68aLvcQceEfXC7Fm0yIQ7zdwOqKpgDO7ZcHGGTSUAumhP47IPv3aIoYbtu4i4WH3C hazI2hGXM913j29XID8XQAvFeXOpbFv2+C/pRaOlMcEPtijshbqXYz2qlLGQCDCj6LqVp1jCUgi60 rO2vQz/Ciq2sQ4l7rud0WF+ZTNj1mjg3XbUWzXtpD+4i17ShkCG5svCsZqKkD8rIn1JvXGW/7Dpf5 ERaYUh1uCvI/9IWDQ/klwzrv+WkSgcR+fvDvdt/o3NUsO+DWeVuSKgqBcdsDQIrhz0gt9a4KXXTLb DnxzGVjf6ToC0VY9UtHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEt3a-00CKhH-Ib; Tue, 01 Feb 2022 13:18:50 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEt3W-00CKgd-Tq for linux-arm-kernel@lists.infradead.org; Tue, 01 Feb 2022 13:18:48 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 113E161483; Tue, 1 Feb 2022 13:18:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0073BC340EB; Tue, 1 Feb 2022 13:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643721524; bh=sNVdD6cgYeu2gEMqySqyRZkEeN6jOn28sIEJQE7brWg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IxwzW3KdWShOnoZjuoOE+Knu0jool6Q5190DaG7G1lEkzY//LhhWpD3KTgKWYJIL+ BoLbmXxixUuj9P7I9euNfjHlfmM3rF5se68IISEy1VkjFqvuwgU06ZpJSmJkx/v/yR 1M263e7iDW3s/HcsD1dpnUr3KcYCDg38RsIn05I2Zo5cTFxxVSw1pvczBJljSW7W1E +PBxwIl3J3IJC4SS0YgBJ2vCCqHaF8eBW99M1dq5/mYBHxMZndy59Yl6hf/u6adIZ+ IWB4Y7prt5Kh6FR7aohoyZ81VOQseIWo8hr7IyPgjRKeC7jIm9QZe4PfxStPfYDFQt 8cbJLPF+h2cpw== Date: Tue, 1 Feb 2022 22:18:39 +0900 From: Masami Hiramatsu To: Ard Biesheuvel Cc: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org, Steven Rostedt , Sudeep Holla , Cristian Marussi , Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Linus Walleij , Masami Hiramatsu Subject: Re: [PATCH v2 09/12] ARM: kprobes: treat R7 as the frame pointer register in Thumb2 builds Message-Id: <20220201221839.2617126c5b19ca4caafe2851@kernel.org> In-Reply-To: <20220131170347.381551-10-ardb@kernel.org> References: <20220131170347.381551-1-ardb@kernel.org> <20220131170347.381551-10-ardb@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_051847_107473_86A337C2 X-CRM114-Status: GOOD ( 28.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 31 Jan 2022 18:03:44 +0100 Ard Biesheuvel wrote: > Thumb2 code uses R7 as the frame pointer rather than R11, because the > opcodes to access it are generally shorter. > > This means that there are cases where we cannot simply add it to the > clobber list of an asm() block, but need to preserve/restore it > explicitly, or the compiler may complain in some cases (e.g., Clang > builds with ftrace enabled). > > Since R11 is not special in that case, clobber it instead, and use it to > preserve/restore the value of R7. Thanks Ard for fixing thumb2 issue! BTW, have you build the kernel with CONFIG_KPROBES_SANITY_TEST=y? It should check the backtrace from kprobe and kretprobe at boot time. Thank you, > > Signed-off-by: Ard Biesheuvel > --- > arch/arm/include/asm/opcodes.h | 14 ++++++++ > arch/arm/probes/kprobes/actions-common.c | 6 ++-- > arch/arm/probes/kprobes/actions-thumb.c | 38 ++++++++++++++++---- > 3 files changed, 48 insertions(+), 10 deletions(-) > > diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h > index 38e3eabff5c3..9a6362408ea0 100644 > --- a/arch/arm/include/asm/opcodes.h > +++ b/arch/arm/include/asm/opcodes.h > @@ -230,4 +230,18 @@ extern __u32 __opcode_to_mem_thumb32(__u32); > ".short " __stringify(first) ", " __stringify(second) "\n\t" > #endif > > +/* > + * Which register to preserve and which register can be clobbered in inline asm > + * that needs to be compatible with code that emits frame pointers. > + */ > +#ifdef CONFIG_THUMB2_KERNEL > +#define FPREG_PRESERVE "r7" > +#define FPREG_CLOBBER "r11" > +#define FPREG_PRESERVE_R7 > +#else > +#define FPREG_PRESERVE "fp" > +#define FPREG_CLOBBER "r7" > +#define FPREG_PRESERVE_R11 > +#endif > + > #endif /* __ASM_ARM_OPCODES_H */ > diff --git a/arch/arm/probes/kprobes/actions-common.c b/arch/arm/probes/kprobes/actions-common.c > index 836aebe596cd..f0efe16e2fdb 100644 > --- a/arch/arm/probes/kprobes/actions-common.c > +++ b/arch/arm/probes/kprobes/actions-common.c > @@ -84,7 +84,7 @@ emulate_generic_r0_12_noflags(probes_opcode_t insn, > register void *rfn asm("lr") = asi->insn_fn; > > __asm__ __volatile__ ( > - "stmdb sp!, {%[regs], r11} \n\t" > + "stmdb sp!, {%[regs], " FPREG_PRESERVE "}\n\t" > "ldmia %[regs], {r0-r12} \n\t" > #if __LINUX_ARM_ARCH__ >= 6 > "blx %[fn] \n\t" > @@ -96,10 +96,10 @@ emulate_generic_r0_12_noflags(probes_opcode_t insn, > #endif > "ldr lr, [sp], #4 \n\t" /* lr = regs */ > "stmia lr, {r0-r12} \n\t" > - "ldr r11, [sp], #4 \n\t" > + "ldr " FPREG_PRESERVE ", [sp], #4\n\t" > : [regs] "=r" (rregs), [fn] "=r" (rfn) > : "0" (rregs), "1" (rfn) > - : "r0", "r2", "r3", "r4", "r5", "r6", "r7", > + : "r0", "r2", "r3", "r4", "r5", "r6", FPREG_CLOBBER, > "r8", "r9", "r10", "r12", "memory", "cc" > ); > } > diff --git a/arch/arm/probes/kprobes/actions-thumb.c b/arch/arm/probes/kprobes/actions-thumb.c > index 7884fcb81c26..873757326533 100644 > --- a/arch/arm/probes/kprobes/actions-thumb.c > +++ b/arch/arm/probes/kprobes/actions-thumb.c > @@ -447,14 +447,20 @@ t16_emulate_loregs(probes_opcode_t insn, > > __asm__ __volatile__ ( > "msr cpsr_fs, %[oldcpsr] \n\t" > +#ifdef FPREG_PRESERVE_R7 > + "mov fp, r7 \n\t" > +#endif > "ldmia %[regs], {r0-r7} \n\t" > "blx %[fn] \n\t" > "stmia %[regs], {r0-r7} \n\t" > +#ifdef FPREG_PRESERVE_R7 > + "mov r7, fp \n\t" > +#endif > "mrs %[newcpsr], cpsr \n\t" > : [newcpsr] "=r" (newcpsr) > : [oldcpsr] "r" (oldcpsr), [regs] "r" (regs), > [fn] "r" (asi->insn_fn) > - : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", > + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", FPREG_CLOBBER, > "lr", "memory", "cc" > ); > > @@ -524,15 +530,21 @@ t16_emulate_push(probes_opcode_t insn, > struct arch_probes_insn *asi, struct pt_regs *regs) > { > __asm__ __volatile__ ( > +#ifdef FPREG_PRESERVE_R7 > + "mov fp, r7 \n\t" > +#endif > "ldr r9, [%[regs], #13*4] \n\t" > "ldr r8, [%[regs], #14*4] \n\t" > "ldmia %[regs], {r0-r7} \n\t" > "blx %[fn] \n\t" > "str r9, [%[regs], #13*4] \n\t" > +#ifdef FPREG_PRESERVE_R7 > + "mov r7, fp \n\t" > +#endif > : > : [regs] "r" (regs), [fn] "r" (asi->insn_fn) > - : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", > - "lr", "memory", "cc" > + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", > + FPREG_CLOBBER, "lr", "memory", "cc" > ); > } > > @@ -558,15 +570,21 @@ t16_emulate_pop_nopc(probes_opcode_t insn, > struct arch_probes_insn *asi, struct pt_regs *regs) > { > __asm__ __volatile__ ( > +#ifdef FPREG_PRESERVE_R7 > + "mov fp, r7 \n\t" > +#endif > "ldr r9, [%[regs], #13*4] \n\t" > "ldmia %[regs], {r0-r7} \n\t" > "blx %[fn] \n\t" > "stmia %[regs], {r0-r7} \n\t" > "str r9, [%[regs], #13*4] \n\t" > +#ifdef FPREG_PRESERVE_R7 > + "mov r7, fp \n\t" > +#endif > : > : [regs] "r" (regs), [fn] "r" (asi->insn_fn) > - : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9", > - "lr", "memory", "cc" > + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r9", > + FPREG_CLOBBER, "lr", "memory", "cc" > ); > } > > @@ -577,15 +595,21 @@ t16_emulate_pop_pc(probes_opcode_t insn, > register unsigned long pc asm("r8"); > > __asm__ __volatile__ ( > +#ifdef FPREG_PRESERVE_R7 > + "mov fp, r7 \n\t" > +#endif > "ldr r9, [%[regs], #13*4] \n\t" > "ldmia %[regs], {r0-r7} \n\t" > "blx %[fn] \n\t" > "stmia %[regs], {r0-r7} \n\t" > "str r9, [%[regs], #13*4] \n\t" > +#ifdef FPREG_PRESERVE_R7 > + "mov r7, fp \n\t" > +#endif > : "=r" (pc) > : [regs] "r" (regs), [fn] "r" (asi->insn_fn) > - : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r9", > - "lr", "memory", "cc" > + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r9", > + FPREG_CLOBBER, "lr", "memory", "cc" > ); > > bx_write_pc(pc, regs); > -- > 2.30.2 > -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel