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 03153C433F5 for ; Thu, 3 Feb 2022 08:24:07 +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:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eso9CM6oCNWIIet2H6gJMVx4WAfR5ALyf7APueNDHjM=; b=W0DxmFXVtx+g/y gUpuivwMoyg59pN5N1QDJv0MZ+2+ipHd7o35cbglhrPM4fMndmfbEuAqIhL4rXSaCGIRF4FNpbc9+ Dgd13HmdxCe/SOyAkUaB1W3sLyYsW3TfmnWFttsZrc6Ta4SaAbX+Oe0Wbcr9lTtGM4NAOFt97HxQM noBPNFv7Rr3qUwO7e4agAbYt2F4mNoaXpZxhhLR8NM0WkDYaljJftfj56pMlJFr25ySDpxk7EWBz9 21WpxdYbhkvSXQAosHm7wfnfGOcQel5hlrz9fnOvUuauN9yi7YZ/ZljtmdOJqImx30WYCEiJihL/U jMoe5f+8le8Ov6z90o1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFXOF-000JPE-9l; Thu, 03 Feb 2022 08:22:51 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFXNl-000JGL-KO for linux-arm-kernel@lists.infradead.org; Thu, 03 Feb 2022 08:22:23 +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 ams.source.kernel.org (Postfix) with ESMTPS id 53EB9B83357; Thu, 3 Feb 2022 08:22:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0AB9C340EF; Thu, 3 Feb 2022 08:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643876539; bh=8jCf61pkTqIBDHzESWbAnf0m3fer/XFFks/FD/selZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z7q+TvJToyaOFd2XAnaK9K7MwLwixuIYRly+nMAvlmKxG6BDDIlkL8PNAsvH+OIYi /3HIzXrkPcGQPtrzdOIxQJb+dcrIu3aIFEn7AIzuK00vxknUIJNqwnmKaToBmxYLWp bx4c4jvF4HbfBZG22FT+HMVgGT+uSXix5FCvB7ocqGF4csm6Yo+YNGZYVJMXK0VkdO crfNuMrvIIagm/8z7ThorkfTpEDpXSE1ivxPxLZ+iU0LlLAIT0hUVBp/WBW8TWmFwi v38boWGOu96YKfs2YJtsFrQ3irn+X6SgFDE/lXG0VD6tmuAJuxcM6ixP7t38LotEez Xf371QJ9J1yKA== From: Ard Biesheuvel To: linux@armlinux.org.uk Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Steven Rostedt , Sudeep Holla , Cristian Marussi , Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Linus Walleij , Masami Hiramatsu Subject: [PATCH v3 02/13] ARM: ftrace: use ADD not POP to counter PUSH at entry Date: Thu, 3 Feb 2022 09:21:53 +0100 Message-Id: <20220203082204.1176734-3-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220203082204.1176734-1-ardb@kernel.org> References: <20220203082204.1176734-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2348; h=from:subject; bh=8jCf61pkTqIBDHzESWbAnf0m3fer/XFFks/FD/selZ4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh+5CW4Bnn35uqHkG+RiUOeMyw82M9ZD3mBtYZIine WdlPPBaJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYfuQlgAKCRDDTyI5ktmPJGsXC/ 9SNr0fr7qeoaNFmwSRnYyGJzBeU7P4hUy0ClAQnkHHRIbgdZNmNo/5wwmgB3TBUzVS3moASRNqxgsX lc1GcPoykK5km4JwpbUr+YFhf/2//5oj6Nf1pGnDNQvDA3NCLjd4+RNW8KLeuSTol48HP6JJWs+C7D y0oc+Ea/c0oSv0j95YGs19s2GCL4qq9JDiZl388EZMZU3nfiiraoX/6KCdi3TkFdCQM7/maeE3nvYV WX3nHGKw/A8Lk66uFvg/VE/PUaWwN7iNSz03C4ogj3g0DLH+kLan9UwvVU+SqNfDWqOppzOVnKOJE/ nVTZlhCU+O/P8OGmTt8LrUHLuAV9mL6Fpok8ub8ddSJNF86h7mfrjBFW8KoHbHVZrxd3zItD4yaGQS FezMQH1aPlV2FlHWXapRwn2HxVTB3GUkWrPP2V2qZQ/X1THGtHL6SIPHk+F3ZwYD2ChSROoyFHOwXP FCTHxFWT6ShAXYVHXmf+BeQADJ5glAAPNhpMS3RD5qDRk= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220203_002221_983302_68DBCECE X-CRM114-Status: GOOD ( 20.08 ) 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 The compiler emitted hook used for ftrace consists of a PUSH {LR} to preserve the link register, followed by a branch-and-link (BL) to __gnu_mount_nc. Dynamic ftrace patches away the latter to turn the combined sequence into a NOP, using a POP {LR} instruction. This is not necessary, since the link register does not get clobbered in this case, and simply adding #4 to the stack pointer is sufficient, and avoids a memory access that may take a few cycles to resolve depending on the micro-architecture. Signed-off-by: Ard Biesheuvel Reviewed-by: Nick Desaulniers Reviewed-by: Linus Walleij Reviewed-by: Steven Rostedt (Google) --- arch/arm/kernel/entry-ftrace.S | 2 +- arch/arm/kernel/ftrace.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S index f4886fb6e9ba..dca12a09322a 100644 --- a/arch/arm/kernel/entry-ftrace.S +++ b/arch/arm/kernel/entry-ftrace.S @@ -27,7 +27,7 @@ * allows it to be clobbered in subroutines and doesn't use it to hold * parameters.) * - * When using dynamic ftrace, we patch out the mcount call by a "pop {lr}" + * When using dynamic ftrace, we patch out the mcount call by a "add sp, #4" * instead of the __gnu_mcount_nc call (see arch/arm/kernel/ftrace.c). */ diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index a006585e1c09..811cadf7eefc 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -24,10 +24,21 @@ #include #include +/* + * The compiler emitted profiling hook consists of + * + * PUSH {LR} + * BL __gnu_mcount_nc + * + * To turn this combined sequence into a NOP, we need to restore the value of + * SP before the PUSH. Let's use an ADD rather than a POP into LR, as LR is not + * modified anyway, and reloading LR from memory is highly likely to be less + * efficient. + */ #ifdef CONFIG_THUMB2_KERNEL -#define NOP 0xf85deb04 /* pop.w {lr} */ +#define NOP 0xf10d0d04 /* add.w sp, sp, #4 */ #else -#define NOP 0xe8bd4000 /* pop {lr} */ +#define NOP 0xe28dd004 /* add sp, sp, #4 */ #endif #ifdef CONFIG_DYNAMIC_FTRACE -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel