From patchwork Mon Dec 18 13:16:47 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: 180405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1236187dyi; Mon, 18 Dec 2023 05:25:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgleqZlHGQ3ANUjO5W+fs0VHjweWLidjZf0RV0dYjXVIuLC1KprdbDpPjuFxCWRNFKSMI1 X-Received: by 2002:a17:906:4e8d:b0:a23:66d9:b9ed with SMTP id v13-20020a1709064e8d00b00a2366d9b9edmr128749eju.304.1702905914870; Mon, 18 Dec 2023 05:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702905914; cv=none; d=google.com; s=arc-20160816; b=gIKlb8ij+CIPpvaYind3oQQJMwiwvFFt5Ou6Raez4dSdRnE7xUgtHOuvPC+mGfBJcW eKJNiEeVL/5FZFhsKo79/wWQkcei3K7ID4fuIPhZTVwRuJMBVVpUM+CMSmy5i0zF0zIM upbOhm8GMyzJrwBsNDy2qjdD/ALVei+0Z30U6MO7evxNjVCLEARH2/FXU4DZqt61uHeR SDn/F10sdi5Z8qls60pcsFNZG1qa7QZpeXDh/QHZzixNaH2bXrGVIeBeQLY+KilMZxhU /jLH5SybS5gBtBAUmzotifjRHnnIEKD62yPT+FTok8RqUwmV0ZKlVv0p3ZRk++tdegLH wZhg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3732-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. [147.75.80.249]) by mx.google.com with ESMTPS id f1-20020a170906390100b00a23536fb932si1022331eje.854.2023.12.18.05.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:25:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3732-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3732-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 EF1411F23241 for ; Mon, 18 Dec 2023 13:24:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2007A74E29; Mon, 18 Dec 2023 13:16:57 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785626272158026336 X-GMAIL-MSGID: 1785626272158026336 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.