Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp554059lqh; Tue, 7 May 2024 07:19:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3IvVJHS/a6Jeu9VIkxkmeLCWhFFjeRSuTX1b42TRMeWKRZzBhzdetWji38tf/vOOY2sKLFolOm8VHroEQMyxfJsSsC4nimAuzRbUZcw== X-Google-Smtp-Source: AGHT+IFn3RFfkc5i/y4N+hKJb0YKNrE+Mt2jFzhBfh5fPC2jgTfLJuVQrdnI8SXao0cIadNzExQ/ X-Received: by 2002:a17:902:ea8c:b0:1e0:bae4:48f9 with SMTP id x12-20020a170902ea8c00b001e0bae448f9mr12067132plb.32.1715091564401; Tue, 07 May 2024 07:19:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715091564; cv=pass; d=google.com; s=arc-20160816; b=Lcg/QW9yU9ps9IkLMVbkA4cdWT5iABVapLBKMVxd0NunkeNoDUOzeHBOTGJkMePwZK mBt4yL+CMkWy37Ma2lp24wJSyQfE3VFFWLaAfAGaaL4ZubsJvnhFOwLE48srJn7dS8fg eiGH/AuvpfBqBXqMAdceXlg8hSsr0kEnf74x09NzZjeBBjA0IFp9x0aikLKid5Toa+xD jjXF4Zp8swk7FeR63EQsl7OFphIiub4eGpUR4TgX2KG9TZc0gTYsiCbYZNK8e3BncTf6 tqW/U0M3hW5x3Z0I7iz9aN/PY31Aa2f2/0pS/5Kmg976eWHUAfQvb9NX5awfnH2ttx2m vpCg== ARC-Message-Signature: i=2; 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=HR1ypc0MeE/yesrt78JF0NXPZ5N9uzKcDc7/i0wM1D0=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=cHsWnmiRUvTChF6NBTMqPcg5S+bz9EnHp3iKlv7/tKU/8Z4P6p9DITRuptPS5EbLOV Pc6zGTyGus0Jr1R3R81ZCmtedJH3HM0ETawf3MNnhx+PDokwjzl08zWSR4uXfeNPig0W 6wQiqLCeiC9U/W3CM/NCeoiJJUG7m882NGd+G4hInhVsceWipeSEXBb8Ulk03V42s2uo +WWJy2OlHvNj1Osrbt5MaALxEBsf8SfwOrtGoZ7KFunu2gToPSpjgyGkLu+L5rjOIZJ/ 3ZQg4GncV7wcj873Awjm7ep25HlMjmJu6HUWotOZbb9vA7Tz0otqZ2LLy9K80JkIyu5G W3uQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrBgtx6W; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171532-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k2-20020a170902d58200b001e215883ff4si10678180plh.516.2024.05.07.07.19.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:19:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrBgtx6W; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171532-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 05495286CCF for ; Tue, 7 May 2024 14:16:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F86016D4F6; Tue, 7 May 2024 14:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KrBgtx6W" 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 2981016D4C7; Tue, 7 May 2024 14:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091192; cv=none; b=iDbvawaZGr1f+SI1DwZXlrbk/XCvwr70CniMWm8XifVpKha+SBVcC2ymKnKsouLqws+KgVUzjDshtAtr0K9l5/a1JY95TskfBDJInqhhfBfTCKIiaGd+O/ma2AkBCOTefbvW5BHRQNYbO9u5T7QGo9FzNITakxoN1B+h4xC42uI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715091192; c=relaxed/simple; bh=F/5hB5CzMWe4nQKT2gznRSR97PiPR7KTsolXy0a3F1A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ulmAtHVdrkWpP/tGZ/DlhAb62kVIwmsy+nsxFs4Mf0LiXCiSZRADBhdE+t0xxJcuQoqijK43JLntXGObTKiNd6u4gxwK9SuNG14ZsYD3WzQTHZmXzw0wIvWZK+ZZ8d5sx03Eyya/zfR96LlFCqhTtcux0EsrurwC9jtKJYwZRUs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KrBgtx6W; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0EF3C2BBFC; Tue, 7 May 2024 14:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715091191; bh=F/5hB5CzMWe4nQKT2gznRSR97PiPR7KTsolXy0a3F1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KrBgtx6WfRe7YQXZuplatpa6XaxcnzjlbTJGW77VYePk1PX4qECveKlaPYS0PqI2o johLiR+fE85kDw9kl2w/7Eeg3UBaQlTWOGZQYIPcTpO5frE+6ut9LdJRt1SnTd/+xs 2MlKiOFms6sauat7GTF2F1kQRQ2imJAIOlX+2aMUa2xwOq+TPzx/1O+apgVLP+ioG9 aolkzZhrbQQScvFSa4mt4uqN8bZ3u7f6TWSZItMWAgxbyR5gfj0llQrtxXOdWOVBNB dnszLvsAq9jPACZeA7v7DbwXTzd1Dvq3763kjzeYmwvilWMVZpz5DnlyCN7O/7Fq0Y R7QVWQEt4noAA== 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 v10 26/36] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Tue, 7 May 2024 23:13:05 +0900 Message-Id: <171509118545.162236.6341151588067717667.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <171509088006.162236.7227326999861366050.stgit@devnote2> References: <171509088006.162236.7227326999861366050.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. This is for the eBPF which needs this to keep the same pt_regs interface to access registers. Thus when replacing the pt_regs with ftrace_regs in fprobes (which is used by kprobe_multi eBPF event), this will be used. 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 in v8: - Add the reason why this required in changelog. 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 ac82dc43a57d..aab2b7a0f78c 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -143,6 +143,17 @@ ftrace_regs_get_frame_pointer(const struct ftrace_regs *fregs) return fregs->fp; } +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 ff2966a1b529..914f451b0d69 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -177,6 +177,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.