From patchwork Fri Dec 8 10:29:31 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: 175759 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5364818vqy; Fri, 8 Dec 2023 02:31:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnpe68QvpN1zYuOUDUp/7Lt53vgVcn7j0ITUPy1XYBo9bQegYhRe617of9sI5FRY8Uspil X-Received: by 2002:a05:6a20:daaa:b0:190:3d8d:a0bc with SMTP id iy42-20020a056a20daaa00b001903d8da0bcmr567358pzb.13.1702031515103; Fri, 08 Dec 2023 02:31:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702031515; cv=none; d=google.com; s=arc-20160816; b=A1OvdNduBgm5b2e0cd+gGnjApIJFMPcHmx2uy3qfimrUq13CcA3dCICB05CPlQy/u3 1j0JwhVT2imSvxn9cEU1lR98ABGIHcT1LuW3595BLlfEX7L9lc8P/oTx3XpWIMW1OKpi cc5FccNtzIN6oayy4n9YZ7/R0OZaIQpF4RbIGpU2WodqzI1ce0gu/dPiVhHgjbNZXG7P PaOQk3/dZO0+NG0a3EnIqTL8Sb5kyykKZoXf35IeJ3GmHe7N6Yey+0sRwOEAv3ugdNVS vAfsQf6w5OidVJ+Xgi5PR/58oDBr8ln+JdjTg7VgLU2QSKpe4teGwe7ORGboJ1xfD3bw T85A== 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=DVs9oqOktQK8VdkuWvMxKXjdWDaZc3LzFv4fFVIyVBfBWYcG7zRQnWRYBSz6C868mD wOzAEzsvJzw0pmtZr6A9mKNE952iRaOksJLqX3T30gakznqeDy5DebkaG5tGH79IMnG/ FR5eNvISiEDQ2w8VkYqggaqiu5NhSahx0xKB9RNxtTFV4S9/A05FD/ki1ksHmrmH6IHW 6vwFZFPA/xSjwEBt84gMujWyGCWawtTu0TtUV9nl+kTKf6D/VTRswE6DLJh9LYoOk10O d7kLAUFnlkqEIrEB08HfdeZHn5kFHkGU5IBJuh7dc/bm4Klzel2OngS08EL2I9sqWESQ Gf6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n7Re6rUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id mi9-20020a17090b4b4900b0028a09a28496si1517550pjb.66.2023.12.08.02.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 02:31:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n7Re6rUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 0DFE9805A7EA; Fri, 8 Dec 2023 02:31:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573620AbjLHKat (ORCPT + 99 others); Fri, 8 Dec 2023 05:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235867AbjLHKaL (ORCPT ); Fri, 8 Dec 2023 05:30:11 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E3CD1BE3 for ; Fri, 8 Dec 2023 02:29:38 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFA15C43391; Fri, 8 Dec 2023 10:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702031377; bh=JC1iyaIU7mWHHBTGXNCiN27YHUuUtROsifUJHNlxJlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n7Re6rUO6fn9k4hVJEvPaax3RsF8sF/iz/MGcYJm/ESScLZGLdvsKZR2NaUCzQT+h 1UddnQcN9e739IL0Z2KqPLqwGbyw31Ehmveu9YxnVQKhbGW48hngQbxSahDp513zAQ BMQ5TltayWO0lhiaX0mViMkSvHtBi5VmMPbiDqiwnL3lwg7nI17p0knTYGzHbS/y0d IbGdz//IeqHF05UCiL9XP1t9ucFHAx0g9GmEKJFi5FnilNuHrvVu1fMNUjECaWDUKh xa2NX2RCk/vX2Eimf9ghf22I8XdIRPBQ+yWS70ASxa6vkNm9CIdec8pLh5aIx4x1qp FpQrsmLSV0biA== 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 v4 26/33] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Fri, 8 Dec 2023 19:29:31 +0900 Message-Id: <170203137075.579004.6040641469988010653.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170203105427.579004.8033550792660734570.stgit@devnote2> References: <170203105427.579004.8033550792660734570.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 02:31:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784709397617837922 X-GMAIL-MSGID: 1784709397617837922 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.