From patchwork Thu Nov 3 17:05:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13030746 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 78BF0C433FE for ; Thu, 3 Nov 2022 17:17:39 +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: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:In-Reply-To:References: List-Owner; bh=ifWuEqkGQhrwU6OzTNrN0SNBfqdL7FdIJthPYCSEI88=; b=fbIMM/Px4poUdu IIbzM0lKZTMSQL2VlaN2gMMGo/s4gzAER4ThH2Q66xQM3DWtBGGIGXNk20+v1kUWv4sgd7AzYXO26 cdzWoMZQF4FKseCdqgxY5Xh1A+BdYH/BMitpFZeJK/8G+pip5e9FoR/LUxxQpmPcfCB1q+pd7S3Ew 6L5VpRQ7ybwNyT0eY4uec3lUsXqEDPq6CljLYpv5HsBeqj1we6YYO32N/FpXd88r99sgR4vI4/ocj fnQ/9ZbCkj0+blOhLgMjC5EA8+KEAdfcFv2BzMDTIa+RGsHDmLT50oX1V134pOLLOckrT7qjMEnf8 m5erOL6Ku+6htPjelA7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqdpI-00107I-Gq; Thu, 03 Nov 2022 17:16:25 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqdem-000vSe-W8 for linux-arm-kernel@lists.infradead.org; Thu, 03 Nov 2022 17:05:35 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 533C61FB; Thu, 3 Nov 2022 10:05:35 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8B1683F5A1; Thu, 3 Nov 2022 10:05:27 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, mhiramat@kernel.org, revest@chromium.org, rostedt@goodmis.org, will@kernel.org Subject: [PATCH v2 0/4] arm64/ftrace: move to DYNAMIC_FTRACE_WITH_ARGS Date: Thu, 3 Nov 2022 17:05:16 +0000 Message-Id: <20221103170520.931305-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221103_100533_172008_28DDBDFB X-CRM114-Status: GOOD ( 15.01 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This series replaces arm64's support for FTRACE_WITH_REGS with support for FTRACE_WITH_ARGS. This removes some overhead and complexity, and removes some latent issues with inconsistent presentation of struct pt_regs (which can only be reliably saved/restored at exception boundaries). The existing FTRACE_WITH_REGS support was added for two major reasons: (1) To make it possible to use the ftrace graph tracer with pointer authentication, where it's necessary to snapshot/manipulate the LR before it is signed by the instrumented function. (2) To make it possible to implement LIVEPATCH in future, where we need to hook function entry before an instrumented function manipulates the stack or argument registers. Practically speaking, we need to preserve the argument/return registers, PC, LR, and SP. Neither of these requires the full set of pt_regs, and only requires us to save/restore a subset of registers used for passing arguments/return-values and context/return information (which is the minimum set we always need to save/restore today). As there is no longer a need to save different sets of registers for different features, we no longer need distinct `ftrace_caller` and `ftrace_regs_caller` trampolines. This allows the trampoline assembly to be simpler, and simplifies code which previously had to handle the two trampolines. I've tested this with the ftrace selftests, where there are no unexpected failures. I plan to build atop this with subsequent patches to add per-callsite ftrace_ops, and I'm sending these patches on their own as I think they make sense regardless. Since v1 [1]: * Change ifdeferry per Steve's request * Add ftrace_regs_query_register_offset() per Masami's request * Fix a bunch of typos [1] https://lore.kernel.org/lkml/20221024140846.3555435-1-mark.rutland@arm.com This series can be found in my 'arm64/ftrace/minimal-regs' branch on kernel.org: https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/ git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git This version is tagged as: arm64-ftrace-minimal-regs-20221103 Thanks, Mark. Mark Rutland (4): ftrace: pass fregs to arch_ftrace_set_direct_caller() ftrace: rename ftrace_instruction_pointer_set() -> ftrace_regs_set_instruction_pointer() ftrace: abstract DYNAMIC_FTRACE_WITH_ARGS accesses ftrace: arm64: move from REGS to ARGS arch/arm64/Kconfig | 18 +++-- arch/arm64/Makefile | 2 +- arch/arm64/include/asm/ftrace.h | 72 ++++++++++++++++-- arch/arm64/kernel/asm-offsets.c | 13 ++++ arch/arm64/kernel/entry-ftrace.S | 117 ++++++++++++------------------ arch/arm64/kernel/ftrace.c | 82 ++++++++++++--------- arch/arm64/kernel/module.c | 3 - arch/powerpc/include/asm/ftrace.h | 24 +++++- arch/s390/include/asm/ftrace.h | 29 +++++++- arch/x86/include/asm/ftrace.h | 49 +++++++++---- include/linux/ftrace.h | 47 +++++++++--- kernel/livepatch/patch.c | 2 +- kernel/trace/Kconfig | 6 +- kernel/trace/ftrace.c | 3 +- 14 files changed, 309 insertions(+), 158 deletions(-) Reviewed-by: Steven Rostedt (Google) Reviewed-by: Masami Hiramatsu (Google)