From patchwork Mon Nov 27 13:58:16 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: 170164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3136078vqx; Mon, 27 Nov 2023 06:03:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXCDi6Obg74XwErKh4NwB/n86B+yQjAghHl3Nc6Ltq1Khvr+nUgfRf2fKo/3DZFU/2sUZ8 X-Received: by 2002:a25:870b:0:b0:da0:c887:36cb with SMTP id a11-20020a25870b000000b00da0c88736cbmr9879996ybl.45.1701093836999; Mon, 27 Nov 2023 06:03:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701093836; cv=none; d=google.com; s=arc-20160816; b=kkhK1BhZNLO6SlpMxQy6vycu/rFVNIZfeSafsNOLO/IW8++FpaHKoieSt0lnPFl2om hbuVfUHA41rT0F1mNOUFk3ifLOfoputzzKTCdKI+trNI0T4cB64r7KkrX+DtxsJ9ky5C UvUx281KUTRudih8Ts+3bYOvvmst/zOknoCsmh0vywsSbiuABFAMez3LWS2kRgl1QFKj WHZ9zhbOjLEH51RTrOVbmACNUAfIQjx6BpwU10mjwYLZ1MMGeDXgoX0fGY/kei5cU2An wpxYkiGdx78NjPZ2YdvVKf/OpzcA/DZAbQZHTTRtTguJwSeosNxb6IsaCm3HvAcz6STz NPTg== 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 Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o8-20020a257308000000b00da232c6af74si6167657ybc.328.2023.11.27.06.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:03:56 -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 0A704805BCA5; Mon, 27 Nov 2023 06:03:50 -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 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:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783726171079613963 X-GMAIL-MSGID: 1783726171079613963 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.