From patchwork Wed Apr 20 16:00:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 12820539 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 349EAC433F5 for ; Wed, 20 Apr 2022 16:01:56 +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=lz69CM8NWZYg4NK/Rp71cggoHibNvGDoe27FAWnfOVo=; b=Z/+vZmj+t9bjzY WX/7CmgY+WKsU3mhuowG4rQtk7mTDYXVVNbxPm96kpKzujq6sHGsP/y5wawduSH5WNDZw+4zXuWNr aJVFfHQAiVF8+56cKJipOAH6BDXR0DcFE87Bov9wPcDwc5kqtT1Gv4EeLPj26HeAfL6eUKKzcJArw eDEpdV3Bx6oMQltnVPPrSzQ45NYqIK2TNoMbfD9uOzCMl7QOMffqnaFZzOCXrj4qZ+zm4P2JbG+TR ZpqMJ/oYlfPGwrBdb7L2+Jvu9lz3ndtRrX/z4gC1wHZiKrBoYGKXmllLDcSBFeTPrZKEAbed/XSu8 W1XP8Xog6GR49EB8J3ng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhCl6-009cm7-53; Wed, 20 Apr 2022 16:00:48 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhCkx-009cjJ-HW for linux-arm-kernel@lists.infradead.org; Wed, 20 Apr 2022 16:00:41 +0000 Received: by mail-pj1-x102c.google.com with SMTP id ga4-20020a17090b038400b001d4b33c74ccso1459791pjb.1 for ; Wed, 20 Apr 2022 09:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mqAuKIhNdsp4YazTmRTCNyekK9gIf2Fr30HqL/AT21U=; b=kcTggueZRyBry2gNLm758/g56VWZ6JLMZqrhmtnu/mTu6AG5AKp98T2/e+NZ0mZCHn /ewQjLbya27pojASo2zlW5t4flIEBnTrqUqO2FDTrIAyMUfcz+0j6ghO32pe9e5YgbnP 3R9gqCTEIG+I8FZ1wk0ezM7/Hi7y/Z9uobefgSM4Mj6oUgaNBUn5W/5rEWB2/eyCPGb9 vKrW5gIfDoJjYE0tOK8TAYwgb3w7hWRYzi3gqWgdp/f2QH0q1sfGPMgCX4EQ9YTycKN8 KSWGSW8V90co+8ZiDg7jZH9PO+osz0qgSckg6/V4U0tVBWQtR2wxlC++hP+A1MDFABHk q/Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mqAuKIhNdsp4YazTmRTCNyekK9gIf2Fr30HqL/AT21U=; b=f+j5j6PkVSBifx3tvLxpyiNObEvaZufeq3Veec7IT/Kdqj0j5nWrfDtY6SbisI4tl/ tPmaVNgfmSb1ZRlrxXQvshM3DbXqTCYP65IJqbCvbH8o/xZRirGCuAE/q/jjP1t8s7M2 Ye8XGrq9mEOJjxGKhYm9A7zhGua98joB3MZeKdI5YuAtu6vGjMBo4cTK9C5i2bSRbLxE JYSsShlut0Ky0YWlLrWcWisWwb4qwQYcc/v1wNpQc8UdWLCeIwqOqkUWA3bcCxYSoFSr jXc1Nsu9Qds5RhALKwaRGQn0oCQ2mmTwMeUF7eWz4Bg2+tuQUnc0f/P8zMfGrqco57K+ Vvgg== X-Gm-Message-State: AOAM533lqD12uPsMhPX1qGpjpYPVSHtBcAQXcoWUxiEFz7WpVBoIMp0b qUuHAk5TrwYhRaq9Zyh8P+Rs2Q== X-Google-Smtp-Source: ABdhPJxVGJb3srX6pyTEy8ykmEVC+CHqgaIViUcFSo9c8mikW+xm1RdaEcr6PMdPCjgljwCI/dWg5g== X-Received: by 2002:a17:90b:1886:b0:1cb:8e79:8ebb with SMTP id mn6-20020a17090b188600b001cb8e798ebbmr5232229pjb.176.1650470436565; Wed, 20 Apr 2022 09:00:36 -0700 (PDT) Received: from localhost.localdomain ([2409:8a28:e66:6380:7568:1633:647:d3a2]) by smtp.gmail.com with ESMTPSA id h18-20020a63c012000000b0039cc3c323f7sm20198676pgg.33.2022.04.20.09.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 09:00:36 -0700 (PDT) From: Chengming Zhou To: rostedt@goodmis.org, mark.rutland@arm.com, mingo@redhat.com, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, dave.hansen@linux.intel.com, broonie@kernel.org, ardb@kernel.org Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, songmuchun@bytedance.com, zhengqi.arch@bytedance.com, Chengming Zhou Subject: [PATCH v5 2/2] arm64/ftrace: Make function graph use ftrace directly Date: Thu, 21 Apr 2022 00:00:06 +0800 Message-Id: <20220420160006.17880-2-zhouchengming@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420160006.17880-1-zhouchengming@bytedance.com> References: <20220420160006.17880-1-zhouchengming@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220420_090039_642737_EE83E81A X-CRM114-Status: GOOD ( 19.67 ) 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 As we do in commit 0c0593b45c9b ("x86/ftrace: Make function graph use ftrace directly"), we don't need special hook for graph tracer, but instead we use graph_ops:func function to install return_hooker. Since commit 3b23e4991fb6 ("arm64: implement ftrace with regs") add implementation for FTRACE_WITH_REGS on arm64, we can easily adopt the same cleanup on arm64. And this cleanup only changes the FTRACE_WITH_REGS implementation, so the mcount-based implementation is unaffected. While in theory it would be possible to make a similar cleanup for !FTRACE_WITH_REGS, this will require rework of the core code, and so for now we only change the FTRACE_WITH_REGS implementation. Tested-by: Mark Rutland Reviewed-by: Mark Rutland Signed-off-by: Chengming Zhou --- v5: - Add reason why this patch only changed FTRACE_WITH_REGS implementation in the commit message as suggested by Mark. - Change to use nicer comment in ftrace_graph_func() as suggested by Mark, because the previous comment sounds like there's an bug to be fixed. - Add Tested-by and Reviewed-by tags from Mark, thanks. v3: - Add comments in ftrace_graph_func() as suggested by Steve. Thanks. v2: - Remove FTRACE_WITH_REGS ftrace_graph_caller asm, thanks Mark. --- arch/arm64/include/asm/ftrace.h | 7 +++++++ arch/arm64/kernel/entry-ftrace.S | 17 ----------------- arch/arm64/kernel/ftrace.c | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 1494cfa8639b..dbc45a4157fa 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -80,8 +80,15 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr) #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS struct dyn_ftrace; +struct ftrace_ops; +struct ftrace_regs; + int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #define ftrace_init_nop ftrace_init_nop + +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs); +#define ftrace_graph_func ftrace_graph_func #endif #define ftrace_return_address(n) return_address(n) diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S index e535480a4069..d42a205ef625 100644 --- a/arch/arm64/kernel/entry-ftrace.S +++ b/arch/arm64/kernel/entry-ftrace.S @@ -97,12 +97,6 @@ SYM_CODE_START(ftrace_common) SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL) bl ftrace_stub -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) // ftrace_graph_caller(); - nop // If enabled, this will be replaced - // "b ftrace_graph_caller" -#endif - /* * At the callsite x0-x8 and x19-x30 were live. Any C code will have preserved * x19-x29 per the AAPCS, and we created frame records upon entry, so we need @@ -127,17 +121,6 @@ ftrace_common_return: ret x9 SYM_CODE_END(ftrace_common) -#ifdef CONFIG_FUNCTION_GRAPH_TRACER -SYM_CODE_START(ftrace_graph_caller) - ldr x0, [sp, #S_PC] - sub x0, x0, #AARCH64_INSN_SIZE // ip (callsite's BL insn) - add x1, sp, #S_LR // parent_ip (callsite's LR) - ldr x2, [sp, #PT_REGS_SIZE] // parent fp (callsite's FP) - bl prepare_ftrace_return - b ftrace_common_return -SYM_CODE_END(ftrace_graph_caller) -#endif - #else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ /* diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index 4506c4a90ac1..f447c4a36f69 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -268,6 +268,22 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent, } #ifdef CONFIG_DYNAMIC_FTRACE + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs) +{ + /* + * When DYNAMIC_FTRACE_WITH_REGS is selected, `fregs` can never be NULL + * and arch_ftrace_get_regs(fregs) will always give a non-NULL pt_regs + * in which we can safely modify the LR. + */ + struct pt_regs *regs = arch_ftrace_get_regs(fregs); + unsigned long *parent = (unsigned long *)&procedure_link_pointer(regs); + + prepare_ftrace_return(ip, parent, frame_pointer(regs)); +} +#else /* * Turn on/off the call to ftrace_graph_caller() in ftrace_caller() * depending on @enable. @@ -297,5 +313,6 @@ int ftrace_disable_ftrace_graph_caller(void) { return ftrace_modify_graph_caller(false); } +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */