From patchwork Tue Feb 6 15:12:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 197500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1612587dyb; Tue, 6 Feb 2024 07:20:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdICB6aZwKeUkCcG5ReqS2tXbWQTuPy0RPr80r2lyZNfWDXoSTdO6y/rNcQLTUEggTHZk/ X-Received: by 2002:aa7:c909:0:b0:55e:f51c:8cde with SMTP id b9-20020aa7c909000000b0055ef51c8cdemr2248906edt.39.1707232848305; Tue, 06 Feb 2024 07:20:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707232848; cv=pass; d=google.com; s=arc-20160816; b=DSADVaQkMWqfTocf084V0eHpCoKElN1GiP+pq5qU+P0s3vRtm+n+DF02zC/uEf+IA8 egYPwvais733jsvYY9NcxFb2E07HjIPsVfdDmUROKyNaaTiurqOZUG8/4woSN1BqznYm lpCW7NWnHv2S9zzCCx2slTY/NrnOXoWxcLbH5F2/IZMwTBDVKGFsLHdX+CSLGxP4gnqP Bm6DnnlyYyg9EKKcMmn8QmHext0h/BPYx8C78C2o+GdpxsXicYwTFV9pndOkLGU8EA9u q66uspDagqPMUuIXnkZl5qW4btsInAKmH4tW5NH5jxQAR2awJfTTUBx3ckT8TAX0Zwhs 6FvA== 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=6CvyDT2/9dgk4JdmyncNzCvoFxaDuIj66p5rM2LDAl8=; fh=mIrsM//rfcPHIwg1VLg5BOvbmTpCK3t+e3X9uEuWrZ8=; b=sLLKPGZdjkCA/AHtoB/8wZTDEH2DhnBLfSnZPMGiEKNWBIV7Iz6Qc5JusuNR/s8BAB T/ne+q2Zqd1sLlXsAYdGq8qzk+iJdAZcjuWwdwN/lbJLUYZD7ANl9Us1uMYRHszO8SwE 9s4vcrcVBXvVjyn0VLV5MM+XlDxuLeBPYewwGJiY3JXMEXhg7eu62FbnFbQSqWvZjb6j 5/m9w5MVTh7PMQOHhXBOSk67GQcW6WoNYtNtm3wvc0ukqo42oYYacWd85UZfu5pQ1n8r 8dpVUzh+XJ7AL+HgbTmPtRJJwsC7usGXAXRa/3CfPZnvgJTgPw/SAZ8CdNGnJlqSGbON J9BA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kCkrcUek; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55213-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55213-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCU+4bMDM5Z16sx5yo+LtWSnk2c4t4jIf/cXe+kmpppcj9Pp8smy64/LqMl2Jn6ZO8rtBYuu/Z5U8vJIw7EIaFcV/VUXGg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w12-20020a056402070c00b0055feb285760si1160627edx.331.2024.02.06.07.20.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 07:20:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55213-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=kCkrcUek; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55213-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55213-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 E35C31F24E39 for ; Tue, 6 Feb 2024 15:20:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF2E013B2AB; Tue, 6 Feb 2024 15:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kCkrcUek" 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 13432135A46; Tue, 6 Feb 2024 15:12:46 +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=1707232367; cv=none; b=ASvLUZi2/8qRmYa0B9bTMoed13OIpB6IjJGLl0xALKLMT+EjCyQoddq92wGi3oHNX7LO21kGfFvFPufViagAIIc2kY35hrVHwPRXnoouNeqZHrbvfZQvFhoaI/LvpO4/PbGP+Y/kCcEEXvE7S0FuTJIb4mEG80EzyOdeQs227jY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707232367; c=relaxed/simple; bh=JC1iyaIU7mWHHBTGXNCiN27YHUuUtROsifUJHNlxJlc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ZtaymrTQwyQljcdkOL1+oxplOi1MBhzAHrxNCSUWke+v2HTYhD6fF7vRFPF13kItb8zPLxbpR7H2gepT6O1lbZX4ug46/W+Y2nPtOO/9j6e/ONNNF1apZyUtjzJusWGU42pnLtMjXyHjUcCI+jO61cJ+v1OPKLv2LWUMQgXZ/yg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kCkrcUek; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B91FC433F1; Tue, 6 Feb 2024 15:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707232366; bh=JC1iyaIU7mWHHBTGXNCiN27YHUuUtROsifUJHNlxJlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kCkrcUekzwol6q7xY4KN9mdGIpvgQZ345e7elqG4p2/q3c1f678J6xUrOjXl8/cGa 0J9eUke7xFc7qnEO+0qOm5U7vUnfjW6Cs+0t1lUeGh+UEKyNjfV7/3XjsMy2tuWkut gjq8bm7XyzBfwfjnOJOwdruv/g+i6gDAZR0YFT04LhhnlmT6LSqdwJkOCH/cu9ctXE 209VEndnyrX5qyPrPiZv/S9s7eI9m4yObjI2CwKrSzdoiou1PutWHSpXWu/P6q9fg1 8irylQvdCKrlcRr5Yy21UQEjq+6D9j8rV4WLzDUVfLiEdNWcQFhqlsZ9SRlCVWxhNN 5oJyhhvkrosvA== 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 v7 28/36] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Wed, 7 Feb 2024 00:12:40 +0900 Message-Id: <170723236068.502590.9568421023325291255.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <170723204881.502590.11906735097521170661.stgit@devnote2> References: <170723204881.502590.11906735097521170661.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: 1790163391050455008 X-GMAIL-MSGID: 1790163391050455008 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.