From patchwork Fri Jan 12 10:16:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 187686 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp78695dyc; Fri, 12 Jan 2024 02:20:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqb8ljosQIiCBbRmLXlFuARh1HMn2M1ng5ZavEwx8laNA01+aIPqY9UCW9o/v+TaegPWZR X-Received: by 2002:a2e:8090:0:b0:2cd:34e2:b7e9 with SMTP id i16-20020a2e8090000000b002cd34e2b7e9mr288541ljg.52.1705054835552; Fri, 12 Jan 2024 02:20:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705054835; cv=none; d=google.com; s=arc-20160816; b=CjkKaBYTE/W3CLSaBekZjKqjm+0lCGOGZ+Uwe6bydHTGeD4teqTN/unc5bOaGEe3eJ 7/8aVG5l74EmNI6CDYxzGXC85oYRTIiwyci+UJd7JDxV/L/zTDj7hV9daefK3hNObnbe WN8ajvaKNLdJz4dEZMqN+zsNf0HpQ4Z5gDnKvkMNLil0XAenko76thlK+MDPrRxbc31C TdJVHCFmgAeOMa78jteXxR2c4EtJ6GUtIziq3ORP+xRLqEfeZ+8mpn4/U0m1fFzFq+W/ WePVcJvPRMbhqZg8G9bQ1Ng/vMFjyzeuLlRdhWRFziCZ/3JMcfd/6wpPcsyDI3TW6oU2 wp+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=6CvyDT2/9dgk4JdmyncNzCvoFxaDuIj66p5rM2LDAl8=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=hMWyAk2HFHzgmxTBD/bHfsePGRRdB7nXETe+LG+Jcj4r7/k1A9qAKj7J7BmH0Qtrus biLX5Lj1jggfBv5B1mGEdPiqCLTVJvtC/E+ASv9K/JFRl92CTJjUdnlxVbH7P24Cqaid Fgszq7DqYMf//wvB999oltm0hCn2bnspsbjtdJIlb9nOTMa5N9tyI7KCTlPLm95HXDeL YVW6vmDvVdDflZX1/XNgF/Q8DM5AVss2TkDbeKiPx8EHl+a58yMBUEL3RqPrIovJTkZ2 odH/7lJIbdLXSxboGSx3++qIUARIcAFjl9NoLveNw6zddPF+e6EfxRELphcScZRGd+Qt xlog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lPorhJkH; spf=pass (google.com: domain of linux-kernel+bounces-24576-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24576-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id er6-20020a056402448600b0055468afa598si1304461edb.125.2024.01.12.02.20.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:20:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24576-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lPorhJkH; spf=pass (google.com: domain of linux-kernel+bounces-24576-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24576-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2951B1F23D75 for ; Fri, 12 Jan 2024 10:20:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C8175FF0D; Fri, 12 Jan 2024 10:16:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lPorhJkH" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE27A64CC4; Fri, 12 Jan 2024 10:16:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26B04C433C7; Fri, 12 Jan 2024 10:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705054585; bh=JC1iyaIU7mWHHBTGXNCiN27YHUuUtROsifUJHNlxJlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lPorhJkHRuSBb5mqIzorwQUYPmVRo89tUoEyuJR2Jalj3rkWbL/QU+HvU+TCqh3k4 zO9GmQD+M6nQaH/SVIBGxuJM/RFKMBznFpMfgcdqC/uaMUpPISCzP7axJL8crlnd9Q fZF6xqGRwdFiUWat0fXBZLdHH5YYIpsirAW01GLosp0JbM3ReC2Cl0sYARJubQdCa7 LVyzXBvEsTR58vHq31eavpyx6yqOhKOsUFX8Dk1igWc2Qf4cEVYhTMueK9SVxSXvLl be7iS3/wbu9kwCsIQ0N0ycNXpnUUIA/kPO/PXPD2j4drS0B02Nvn6oUEwUrkgVj/ln 6yhY6px026plg== 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 v6 28/36] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Fri, 12 Jan 2024 19:16:19 +0900 Message-Id: <170505457974.459169.12611245988226659386.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170505424954.459169.10630626365737237288.stgit@devnote2> References: <170505424954.459169.10630626365737237288.stgit@devnote2> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787879579272774743 X-GMAIL-MSGID: 1787879579272774743 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.