Received: by 10.223.148.5 with SMTP id 5csp7696495wrq; Thu, 18 Jan 2018 08:28:22 -0800 (PST) X-Google-Smtp-Source: ACJfBouMDnIYSnIUnpkPF8bpF1QvjrrPFJsrwZLLLr+N3vexaLIT/wYeHHVZkQqLEzS+oUroTrc1 X-Received: by 10.101.82.1 with SMTP id o1mr26917784pgp.259.1516292902635; Thu, 18 Jan 2018 08:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516292902; cv=none; d=google.com; s=arc-20160816; b=u6CG9BQjlyOC/ujMOlOwv7LwoyEn4iU6x12L1+plVi7pyyxrak+5qwznAeBQNHzS9q 7vzSYpyVurp/qRadiNhRQfgGAx9dyCBgZ+dkh/+rUT0vNAkmmHHQLydQxDXkW3eGwF9V vGk++6+vO+yam3fEcAChgEPHSjJflFC76S72TBQzaUKPQg81inEbIhmJasb5gO2rFGbj 69ALWkGoGMRF++PXMrDS4mbeZNM+EklYwXCXlPy7uza/eDLtLeZbHDVkPiMCr6n3jVKA l9unsTPL7/F2wT+cF1l4jWbfHYmj1qIGdLWEhNw405ICwv8U+DLnHy3CA1m/Q+bXKtRc AhEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=WujiV2STfWG55R4bUOHXhaGgG/2tb3YCuin4zqFwBl4=; b=mkfY4YQ4NiYIoKPqVC6hoPmPgh24y8TxPwnz1N70lVHYMzJWNA1e4PDygWvuBqxc3L 8tHbbn2kli4YfbNf7B2cRzU5Dn6hie+SRHzhIWFexG/hUsj9yZgANf5Cwdi7ZSQMIbYJ POr/UyQ0G4BczmQ03as2WcvTIvyJMg7m8pVwt7VlxPJoXlksxY3umm4aZlUqf7loZQT6 SOqargu2CAsKb9HdAoHt3+XuDCJcMpgJAs6aTHgVWU2bv2McwGUuApYDRB/b6jofGpe5 jJBdL08c7/8evFMC4PktfqMZF7ZwXKg6IMHPdxngoYhceL35LQFsON2VhHf+i1ufXC49 JvZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fVUDcC7a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si6472295pgb.461.2018.01.18.08.28.08; Thu, 18 Jan 2018 08:28:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fVUDcC7a; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932958AbeARPwZ (ORCPT + 99 others); Thu, 18 Jan 2018 10:52:25 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:43175 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932948AbeARPwQ (ORCPT ); Thu, 18 Jan 2018 10:52:16 -0500 Received: by mail-pg0-f67.google.com with SMTP id n17so6986045pgf.10 for ; Thu, 18 Jan 2018 07:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WujiV2STfWG55R4bUOHXhaGgG/2tb3YCuin4zqFwBl4=; b=fVUDcC7aYoSnXwUE/AwIXDj9xTKoshUjXJc2c/xKIkGqlaxL7f2/AWGi3mYnjGSvyQ EGO9hxpjk6XknSjNl8z4BpaxNjt2wj3A3QIog3TWZ/TbtYooTrkJV2YKKTON0Za6pgCA P9fazKVTJ40cEfI/tBXOIGn8EoD0mupdXF3Fko2WHVmgVp8BdLJkugWdY9geYCT50Owg aI0Y2vlnypEllO16nB2s5R/bGVIrIBArX99zsDo+gNf8Plw1Ij4FZmlfEBtovDN+n2cW 1S7IglKiykeeYUqvXlm2b7Wv51cED8qRJUFqlxs71NfWF2Vb5oRFmEebaMOxTqn9un0B fCrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WujiV2STfWG55R4bUOHXhaGgG/2tb3YCuin4zqFwBl4=; b=cfnFLKa0DM0XrhJcQ2h25SQrNhGgukVEnHo1nZE42EZywiEkB8Qdq6Kndsd21tkbUi dw74mJW4qyMgOqZgsI2B1KP7rD1PFKfxnsvkTdlUWktacnFLtspdR7hI8JT+8CSSOlrs 8RFx9keIf5zU0RGQN19tX9plcZL9eE5thzDjciQefotJnWFAcrvqmMuMbqBjCHZvS+rk fVuhqbCTVIaDABKBg+R/87m+4F79yu0O9OPp8E7zh3JeLJSfDXN+Big7qnhIga5VmMWL hjSLwewp2i5vXfGToOfKiEXAKeRzJpEHXzS1SYphYT3FOl1SdHS8mj1ZgFXgQIvUO6h5 CPFw== X-Gm-Message-State: AKwxytfAURRuuWKkT40w3uAQVc5oKt2pJH/3G2YNB39o9Qq8OUhOpVEh XQJcL6QlBNbae1vafRJOwyE= X-Received: by 10.99.177.76 with SMTP id g12mr15014870pgp.269.1516290379556; Thu, 18 Jan 2018 07:46:19 -0800 (PST) Received: from localhost.localdomain (114-37-171-238.dynamic-ip.hinet.net. [114.37.171.238]) by smtp.gmail.com with ESMTPSA id f188sm14571465pfc.22.2018.01.18.07.46.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 07:46:18 -0800 (PST) From: Alan Kao X-Google-Original-From: Alan Kao To: Palmer Dabbelt , Albert Ou , Steven Rostedt , Ingo Molnar , Masahiro Yamada , Kamil Rytarowski , Andrew Morton , patches@groups.riscv.org, linux-kernel@vger.kernel.org, Stefan O'Rear Cc: Alan Kao , Greentime Hu Subject: [PATCH v3 5/6] riscv/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Date: Thu, 18 Jan 2018 23:45:44 +0800 Message-Id: <20180118154545.17987-6-alankao@andestech.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180118154545.17987-1-alankao@andestech.com> References: <20180118154545.17987-1-alankao@andestech.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Cc: Greentime Hu Signed-off-by: Alan Kao --- arch/riscv/Kconfig | 1 + arch/riscv/kernel/ftrace.c | 17 ++++++ arch/riscv/kernel/mcount-dyn.S | 124 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index a5c5c88700d4..bb2c64976583 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -119,6 +119,7 @@ config ARCH_RV64I select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FTRACE_MCOUNT_RECORD select HAVE_DYNAMIC_FTRACE + select HAVE_DYNAMIC_FTRACE_WITH_REGS endchoice diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index dce1286af9b0..3922b29c107b 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -105,6 +105,23 @@ int __init ftrace_dyn_arch_init(void) } #endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, + unsigned long addr) +{ + unsigned int offset = (unsigned int)(old_addr - rec->ip); + unsigned int auipc_call = to_auipc_insn(offset); + unsigned int jalr_call = to_jalr_insn(offset); + unsigned int calls[2] = {auipc_call, jalr_call}; + int ret = ftrace_check_current_call(rec->ip, calls); + + if (ret) + return ret; + + return __ftrace_modify_call(rec->ip, addr, true); +} +#endif + #ifdef CONFIG_FUNCTION_GRAPH_TRACER /* * Most of this function is copied from arm64. diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index c8959bdd4f38..e123ab7a8f32 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -115,3 +115,127 @@ ftrace_call: RESTORE_ABI_STATE ret ENDPROC(ftrace_caller) + + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + .macro SAVE_ALL + addi sp, sp, -(PT_SIZE_ON_STACK+16) + sd s0, (PT_SIZE_ON_STACK)(sp) + sd ra, (PT_SIZE_ON_STACK+8)(sp) + addi s0, sp, (PT_SIZE_ON_STACK+16) + + sd x1, PT_RA(sp) + sd x2, PT_SP(sp) + sd x3, PT_GP(sp) + sd x4, PT_TP(sp) + sd x5, PT_T0(sp) + sd x6, PT_T1(sp) + sd x7, PT_T2(sp) + sd x8, PT_S0(sp) + sd x9, PT_S1(sp) + sd x10, PT_A0(sp) + sd x11, PT_A1(sp) + sd x12, PT_A2(sp) + sd x13, PT_A3(sp) + sd x14, PT_A4(sp) + sd x15, PT_A5(sp) + sd x16, PT_A6(sp) + sd x17, PT_A7(sp) + sd x18, PT_S2(sp) + sd x19, PT_S3(sp) + sd x20, PT_S4(sp) + sd x21, PT_S5(sp) + sd x22, PT_S6(sp) + sd x23, PT_S7(sp) + sd x24, PT_S8(sp) + sd x25, PT_S9(sp) + sd x26, PT_S10(sp) + sd x27, PT_S11(sp) + sd x28, PT_T3(sp) + sd x29, PT_T4(sp) + sd x30, PT_T5(sp) + sd x31, PT_T6(sp) + .endm + + .macro RESTORE_ALL + ld x1, PT_RA(sp) + ld x2, PT_SP(sp) + ld x3, PT_GP(sp) + ld x4, PT_TP(sp) + ld x5, PT_T0(sp) + ld x6, PT_T1(sp) + ld x7, PT_T2(sp) + ld x8, PT_S0(sp) + ld x9, PT_S1(sp) + ld x10, PT_A0(sp) + ld x11, PT_A1(sp) + ld x12, PT_A2(sp) + ld x13, PT_A3(sp) + ld x14, PT_A4(sp) + ld x15, PT_A5(sp) + ld x16, PT_A6(sp) + ld x17, PT_A7(sp) + ld x18, PT_S2(sp) + ld x19, PT_S3(sp) + ld x20, PT_S4(sp) + ld x21, PT_S5(sp) + ld x22, PT_S6(sp) + ld x23, PT_S7(sp) + ld x24, PT_S8(sp) + ld x25, PT_S9(sp) + ld x26, PT_S10(sp) + ld x27, PT_S11(sp) + ld x28, PT_T3(sp) + ld x29, PT_T4(sp) + ld x30, PT_T5(sp) + ld x31, PT_T6(sp) + + ld s0, (PT_SIZE_ON_STACK)(sp) + ld ra, (PT_SIZE_ON_STACK+8)(sp) + addi sp, sp, (PT_SIZE_ON_STACK+16) + .endm + + .macro RESTORE_GRAPH_REG_ARGS + ld a0, PT_T0(sp) + ld a1, PT_T1(sp) +#ifdef HAVE_FUNCTION_GRAPH_FP_TEST + ld a2, PT_T2(sp) +#endif + .endm + +/* + * Most of the contents are the same as ftrace_caller. + */ +ENTRY(ftrace_regs_caller) + /* + * a3: the address of all registers in the stack + */ + ld a1, -8(s0) + addi a0, ra, -MCOUNT_INSN_SIZE + la t5, function_trace_op + ld a2, 0(t5) + addi a3, sp, -(PT_SIZE_ON_STACK+16) + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + addi t0, s0, -8 + mv t1, a0 +#ifdef HAVE_FUNCTION_GRAPH_FP_TEST + ld t2, -16(s0) +#endif +#endif + SAVE_ALL + +ftrace_regs_call: + .global ftrace_regs_call + addi x0, x0, 0 + addi x0, x0, 0 + +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + RESTORE_GRAPH_REG_ARGS + call ftrace_graph_caller +#endif + + RESTORE_ALL + ret +ENDPROC(ftrace_regs_caller) +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ -- 2.15.1