From patchwork Sun Sep 24 13:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 144077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668219vqu; Sun, 24 Sep 2023 06:37:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpyqVUpNOQpLQ6keoQ87IppIM273q27Nh0G2jf+a8OnqsLK/5UJ0zZqkts3kaDXHw4CkAm X-Received: by 2002:a05:6808:14c7:b0:3a7:4e0c:faa2 with SMTP id f7-20020a05680814c700b003a74e0cfaa2mr5408695oiw.27.1695562645632; Sun, 24 Sep 2023 06:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562645; cv=none; d=google.com; s=arc-20160816; b=KdmM4e4daHDo+XjKuMR682mgwNdGyBYEXRvBdYCnxgmxFqpVCpi0B6/rBgJC2z8MUy tGS+nv7k4iYtDp7jpio2q4mkpTFVI+OBInRAMg76GJNC0PhYuITokSUByOVU9XJdB0HS tAwYrYGfTWBmhzYfMaA//w6kwZdGMZmljvr7dLG3QMm0X1iT4jIn2TXIf6dNyY1JmuQX FYfe72a1jbKzPV4Hxx+j9Mn4ZUjvRrMueKLk5IBAK2WPEbtumrgyp2PylOzZdHP7k+5T uA2BxF8Qxu9Gsuw5i+z/kYVoo5ej1e4TCKRn5TK6Wh8KlGZORfhhHohFC/49cagOnavV LEmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nx4/xRf8O07J/m0o1KCUS43kr0+rGIsEw2cAKhWVGno=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=dzKturTQK8+5mEkG2Gsyygpqpkmnetf6PsfG/NMAYlD+QfsITZ5zbgSlWome8UsAt8 //kekNuWTijaKaEa/TFhAF0abc2qZ5EpMUmsv4syKAVkXCXJTBIeKSrBgtoP1MOL9zNw TckRpexH2RyjpNMZenN5VlUr8A0vAYheQyyfnSsNG1dpUqmIe245yYChYb0XoQvwrvCh iY0E+X7Pd5tTnUS53w61Ta8ATqzZYYWAM+8YMNlfwo3Kk/+3asFQtcq39oiK7thLtrtc A99hNvb1ruidmVu4BW5/A/PdWo6rAsWQZWMsytPpEWVnzqOcjgi6igEglLVblCeEu6X/ M4SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oqIRRymL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l3-20020a63ea43000000b00573fbbb7803si7575735pgk.613.2023.09.24.06.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:37:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oqIRRymL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 54139830D345; Sun, 24 Sep 2023 06:37:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbjIXNhX (ORCPT + 30 others); Sun, 24 Sep 2023 09:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231211AbjIXNhJ (ORCPT ); Sun, 24 Sep 2023 09:37:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B533E40 for ; Sun, 24 Sep 2023 06:36:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1710AC433C8; Sun, 24 Sep 2023 13:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562565; bh=LhYnyuDASlXkoXmwCgKG/bRCaq518SQW1Kv1bqMglGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oqIRRymLElY+P25kTdNjEVyJB1A9ldCYTxgORJ2fY34/Up+1xmNu/blxLvgvO5d9v YiLVnE8f+DqJ9TRtFd+qISOHrQMIzP3no7VHIYYfltA8O88TF9oWSzN1loDL1H8+Av y2pog5Q99aZxCYiO+eGs+EcZEK5QCFRKxQ1H0BoMXnKzdM7ZmuvT++GsX3E5aZ6zkP RcNxCFEkV5UQYuJsW4OtyYkLV7KQiGlqwJLrJvlkTB1UERoEbXgseOI6XFhvKBFitR O+Q57mxrGf5S2tiOPkc0LYv4MVrdrsoBejfM774lHvH+n9ZtLBCoy5+6jnf/Ar9sx+ WlJQquCgwUxMg== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: [PATCH v5 01/12] riscv: ftrace: Fix to pass correct ftrace_regs to ftrace_func_t functions Date: Sun, 24 Sep 2023 22:35:59 +0900 Message-Id: <169556255915.146934.16583650430641758878.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:37:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926297083225504 X-GMAIL-MSGID: 1777926297083225504 From: Masami Hiramatsu (Google) Since ftrace_func_t requires to pass 'struct ftrace_regs *' as the 4th argument even if FTRACE_OPS_FL_SAVE_REGS is not set, ftrace_caller must pass 'struct ftrace_regs *', which is a partial pt_regs, on the stack to the ftrace_func_t functions, so that the ftrace_func_t functions can access some partial registers. Fix to allocate 'struct ftrace_regs' (which has the same size of 'struct pt_regs') on the stack and save partial (argument) registers on it instead of reduced size custom data structure. Fixes: afc76b8b8011 ("riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT") Signed-off-by: Masami Hiramatsu (Google) --- arch/riscv/kernel/mcount-dyn.S | 65 +++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 669b8697aa38..84963680eff4 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -14,46 +14,37 @@ .text #define FENTRY_RA_OFFSET 8 -#define ABI_SIZE_ON_STACK 80 -#define ABI_A0 0 -#define ABI_A1 8 -#define ABI_A2 16 -#define ABI_A3 24 -#define ABI_A4 32 -#define ABI_A5 40 -#define ABI_A6 48 -#define ABI_A7 56 -#define ABI_T0 64 -#define ABI_RA 72 .macro SAVE_ABI - addi sp, sp, -ABI_SIZE_ON_STACK - - REG_S a0, ABI_A0(sp) - REG_S a1, ABI_A1(sp) - REG_S a2, ABI_A2(sp) - REG_S a3, ABI_A3(sp) - REG_S a4, ABI_A4(sp) - REG_S a5, ABI_A5(sp) - REG_S a6, ABI_A6(sp) - REG_S a7, ABI_A7(sp) - REG_S t0, ABI_T0(sp) - REG_S ra, ABI_RA(sp) + addi sp, sp, -PT_SIZE_ON_STACK + + /* Save t0 as epc for ftrace_regs_get_instruction_pointer() */ + REG_S t0, PT_EPC(sp) + REG_S a0, PT_A0(sp) + REG_S a1, PT_A1(sp) + REG_S a2, PT_A2(sp) + REG_S a3, PT_A3(sp) + REG_S a4, PT_A4(sp) + REG_S a5, PT_A5(sp) + REG_S a6, PT_A6(sp) + REG_S a7, PT_A7(sp) + REG_S t0, PT_T0(sp) + REG_S ra, PT_RA(sp) .endm .macro RESTORE_ABI - REG_L a0, ABI_A0(sp) - REG_L a1, ABI_A1(sp) - REG_L a2, ABI_A2(sp) - REG_L a3, ABI_A3(sp) - REG_L a4, ABI_A4(sp) - REG_L a5, ABI_A5(sp) - REG_L a6, ABI_A6(sp) - REG_L a7, ABI_A7(sp) - REG_L t0, ABI_T0(sp) - REG_L ra, ABI_RA(sp) - - addi sp, sp, ABI_SIZE_ON_STACK + REG_L a0, PT_A0(sp) + REG_L a1, PT_A1(sp) + REG_L a2, PT_A2(sp) + REG_L a3, PT_A3(sp) + REG_L a4, PT_A4(sp) + REG_L a5, PT_A5(sp) + REG_L a6, PT_A6(sp) + REG_L a7, PT_A7(sp) + REG_L t0, PT_T0(sp) + REG_L ra, PT_RA(sp) + + addi sp, sp, PT_SIZE_ON_STACK .endm #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS @@ -96,8 +87,8 @@ ftrace_call: call ftrace_stub #ifdef CONFIG_FUNCTION_GRAPH_TRACER - addi a0, sp, ABI_RA - REG_L a1, ABI_T0(sp) + addi a0, sp, PT_RA + REG_L a1, PT_T0(sp) addi a1, a1, -FENTRY_RA_OFFSET #ifdef HAVE_FUNCTION_GRAPH_FP_TEST mv a2, s0