Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3070815rdh; Mon, 27 Nov 2023 06:03:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEdxXGgJaXpOxPAIzdDZTN94tDzj8rtRm5ljss+Pw8Jy2hd9FwAp1GXBsrgUZisHEbyltO X-Received: by 2002:a25:2057:0:b0:da3:74ad:e05e with SMTP id g84-20020a252057000000b00da374ade05emr7788806ybg.40.1701093834601; Mon, 27 Nov 2023 06:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701093834; cv=none; d=google.com; s=arc-20160816; b=EN6+2Jo96JcC6RAhWkcRW3F9xIs0to526hVGoKAHWXzrR88DlDQ+qn3F6GqQT0AAx7 4FmeRIqm0WxxAoIX7qpPzg0jNr5maZgjvmL7y6qJbROwQZgspyEYveXqiDyDZndVUGDU 8Mu9DR+YTSlERYxoJsrkgH0Ts0YPuZCSLChRoTpf+8UA+nnqrZel1EOEgRSOsPa3WZGJ 3gHBDoJUmZ79eSl/e1p5ODN9cRdmKpgSibG60OfPsPgHfNQQIn2SIMGcRsvzqp1cTfA1 pgwq4agyZ4IMRFobHULoq+pQn+tZeQX3NYHc5OBHiNCY80o7U37sM2rISjex3dIduggy 11mQ== 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=6CvyDT2/9dgk4JdmyncNzCvoFxaDuIj66p5rM2LDAl8=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=0NwjB/3q0/AMaEupENYpmD1Jtwsc0CFUuOmFupBH/7WizSUtOG4DzAuQCnCsrPiMQ8 M9rzwZkelhwGjd3HKBG8DjdIqmRJVCVTm2Jp2eA6eN+V020YPdHzsxr61pyk/v9o5cos eBqVo8qR6JeEw58ZBO4gnTeKiWMipfMuxCzn3MBnWpawBqcagvSFC6lxVGyrRCFVmEZM SDnV584Xjt18P8V48gRmScuNcQMYgF1LSoq7Pmz4UxtX6xKZ9ZKxDK41w5ySclvS4r8J l1kV/6eL79TBO/cHtpvEz6dSD4mZ0UEp04Bg6AquPFEkQURw4mR2xYaT6Rwef80YiEr8 8COw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iJ9hUKCt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p127-20020a252985000000b00d9acd9b2088si6342062ybp.620.2023.11.27.06.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:03:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iJ9hUKCt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 2A9FE809E708; Mon, 27 Nov 2023 06:03:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233638AbjK0ODh (ORCPT + 99 others); Mon, 27 Nov 2023 09:03:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233584AbjK0OBY (ORCPT ); Mon, 27 Nov 2023 09:01:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 052362D62 for ; Mon, 27 Nov 2023 05:58:23 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C868AC433C9; Mon, 27 Nov 2023 13:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701093502; bh=JC1iyaIU7mWHHBTGXNCiN27YHUuUtROsifUJHNlxJlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iJ9hUKCtm++6tbn9WwWC/r9c8LS7rx/iAPHHhGedM7Sz5lACR88lDa8IPsc6CW4dU 5NXgtoQmB65TRBkfEUHx5Dh3Mnup9XqbfAX22r9tk5iQSfgJ36su0sl9Kqagw9/p4/ kbTid5I3BwtjB80sJzhubR1Nl4NrtQSlJZidHDYtAU6wMBg7sXS1b03RI9WQYsWBOJ /KDVr5gpGqneUDI0P9DMIHnRwzEQQwLfxt+/l+Kry046ECesp5zz3jq2kzMi5v54uw pz7VAre8BdVHo741Q2OTMkJjyDCx7RepvPOS5CiKi94CY3u+aEq08+gP9pr9qob+uP 5YxLdNwK/ASRA== 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 v3 26/33] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Mon, 27 Nov 2023 22:58:16 +0900 Message-Id: <170109349587.343914.12760806372446369018.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170109317214.343914.4784420430328654397.stgit@devnote2> References: <170109317214.343914.4784420430328654397.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 06:03:51 -0800 (PST) From: Masami Hiramatsu (Google) Add ftrace_partial_regs() which converts the ftrace_regs to pt_regs. If the architecture defines its own ftrace_regs, this copies partial registers to pt_regs and returns it. If not, ftrace_regs is the same as pt_regs and ftrace_partial_regs() will return ftrace_regs::regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes from previous series: NOTHING, just forward ported. --- arch/arm64/include/asm/ftrace.h | 11 +++++++++++ include/linux/ftrace.h | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index efd5dbf74dd6..31051fa2b4d9 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -143,6 +143,17 @@ ftrace_override_function_with_return(struct ftrace_regs *fregs) fregs->pc = fregs->lr; } +static __always_inline struct pt_regs * +ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) +{ + memcpy(regs->regs, fregs->regs, sizeof(u64) * 9); + regs->sp = fregs->sp; + regs->pc = fregs->pc; + regs->regs[29] = fregs->fp; + regs->regs[30] = fregs->lr; + return regs; +} + int ftrace_regs_query_register_offset(const char *name); int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index a72a2eaec576..515ec804d605 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -173,6 +173,23 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs return arch_ftrace_get_regs(fregs); } +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || \ + defined(CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST) + +static __always_inline struct pt_regs * +ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs) +{ + /* + * If CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST=y, ftrace_regs memory + * layout is the same as pt_regs. So always returns that address. + * Since arch_ftrace_get_regs() will check some members and may return + * NULL, we can not use it. + */ + return &fregs->regs; +} + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST */ + /* * When true, the ftrace_regs_{get,set}_*() functions may be used on fregs. * Note: this can be true even when ftrace_get_regs() cannot provide a pt_regs.