Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2198635rdd; Fri, 12 Jan 2024 02:21:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHePOWEBvNvkWjsRLLcHBnFhMPz5CCEfDQSc/5u1rIWnwSOz4LZm7K5qCLZLZJ2fR39r+Kp X-Received: by 2002:a05:6a20:871c:b0:199:915d:b93e with SMTP id e28-20020a056a20871c00b00199915db93emr533913pzf.42.1705054888805; Fri, 12 Jan 2024 02:21:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705054888; cv=none; d=google.com; s=arc-20160816; b=qgZaoBigJzfKKjNtHvo/xu8WMUW8ck8U81N8Q+7GCgwCkixvslFb5aK2WPZy9fZSBh nefsrml57WdFnicE5mS4l9r3yrGAgJ7fxv0m4WVfsK3Gv9wAPRUO3h1XrKbhukTv6tkT /y/67V22PtUlFjcO6xPm4MO7FgAJLWsR5DFBDXToTnk6pbS+A6CDjjPLUrBLv+cX3eKE kdAZp5M/cnDXhJgv5EQ59XhOOU7Z/YVigha6UIlWoindgPWiXX3PhVeLDMLZ6FjGg+35 PLesEMhwhyJwq4XCahXCtLcFwxyFWoU7HLGqt1BOzds9V6iYRVK6IM4WjdsBeehUiKUH K2SA== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j14-20020a17090a31ce00b0028be1b567bdsi2810661pjf.180.2024.01.12.02.21.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 02:21:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24576-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24576-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 31442B23A78 for ; Fri, 12 Jan 2024 10:20:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF9B56166C; Fri, 12 Jan 2024 10:16:26 +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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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.