Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp94909rdh; Mon, 18 Dec 2023 05:30:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNkcimHq2L+FGHRmaP7Xz9qiXsBFV0iibD8acIn4c8ajyp4c5GE9z0zU5B7Mp8N/V/DDzP X-Received: by 2002:a17:90a:1fc6:b0:28b:6ec2:7400 with SMTP id z6-20020a17090a1fc600b0028b6ec27400mr941960pjz.20.1702906211296; Mon, 18 Dec 2023 05:30:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702906211; cv=none; d=google.com; s=arc-20160816; b=nGCfxabfTZykXVj/JlJEknjp74grhL5SFZRcvGZVvAzisZGitlaDMb9Lxk6vLe2g5G Xpdkxh/A6qxAtgePkxJJarvVFGPb2bQiNuqe517DE7en0SGmV3YjHIlEMZ4gZxhP8eTx QivnWPDoRJ8tNoQ4Wt+n+2D+NYv6KSBKgMFqCkfGQKDR5SnxYFw7NN6HpUotJ/UiVdBg FhCRSN6PAp6eV/FcUCTfO+KwtZrToMrT7kgCcxK9HuXuMDRxbZJQGXiJBDYi0lpuX81D VP5Ai/K5idveqZSR+6gsveXdL20srZuk1Xf8t2I2kxOrVjL9UQ7sEJhPe6J3Bb5g9tF4 D1sQ== 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=gFuv9keQQ8M6ZJ7ooNXAXk3fJSiRrsxoxU9Mp9hDtJ2UBpglrDorpfgub5SzoBPwth j8t8+2XT1QoeAPIJQsSdvUfLcX1eM8oKqxBKmZocJEDai/m9ZEtXcQaAxIFvX4vCErml d572DDxXy7ZT7mnygdxwOEoqOkqZQb5YD+knuLeOQufo8LIMoe4fJtFw8a282OZBBN0I NvTrSLCO4g85mTb0szDO0d6fw+jBhhJn/ns8ymWjIi/NtyD6T55HUpmj63oOojxO4ww0 UOc5oGjSyhLOWHeRPDR1ghWv809fESQgmMZ8HMlbaNYU0UUzMxn0PocNpYoELpi2F/yl YRtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="c2fvl/hv"; spf=pass (google.com: domain of linux-kernel+bounces-3732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3732-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. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u8-20020a17090a400800b0028b7acbeecbsi2192950pjc.128.2023.12.18.05.30.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:30:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="c2fvl/hv"; spf=pass (google.com: domain of linux-kernel+bounces-3732-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3732-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 92BA7B20A9C for ; Mon, 18 Dec 2023 13:24:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13D2E42A9C; Mon, 18 Dec 2023 13:16:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c2fvl/hv" X-Original-To: linux-kernel@vger.kernel.org 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 039354FF96; Mon, 18 Dec 2023 13:16:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84AC7C433C7; Mon, 18 Dec 2023 13:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702905413; bh=JC1iyaIU7mWHHBTGXNCiN27YHUuUtROsifUJHNlxJlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c2fvl/hvNhxVth2WjDLp2sQI3pw3EuXWMsH7iRxwLRhoEyQ43Tjc6vtan4xB4UonL YHDGOHDTx7VfbGvQVqDeSDz4jcPPRc7YwDzVL2PJ71/VbrJrsyYE/BTJq7hAfwdnNB awYIrMg087iRS7W/pZ2mwdclx/39RNCr3vWR9Rglk8icFZ+sm+VC2l7wjaFTbcN9iL CBYu/uh3YcmNIzw1tGD5bp0U93EGCLpiRdv2zvEewPyl9s/Xsd32L3KNLDnVSO3bgR IN8R664KVFIT0ouFUXk/Fby/O5kYczO4Y+tEsY1NkAsoFMnIdxcTfZG61UTnQpf9ZJ TcHGAwYYeu9GA== 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 26/34] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Mon, 18 Dec 2023 22:16:47 +0900 Message-Id: <170290540756.220107.1659081779918417989.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170290509018.220107.1347127510564358608.stgit@devnote2> References: <170290509018.220107.1347127510564358608.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.