From patchwork Mon Dec 18 13:15: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: 180409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1236518dyi; Mon, 18 Dec 2023 05:25:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8j6xO0tGLrEyfzRHcxargUK5Ja12JBSlYSplmKM40AJI6pDOuigtP0PVRODK3XLkQCv5/ X-Received: by 2002:a05:6a20:560c:b0:190:2d3d:b08a with SMTP id ir12-20020a056a20560c00b001902d3db08amr17330025pzc.18.1702905949330; Mon, 18 Dec 2023 05:25:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702905949; cv=none; d=google.com; s=arc-20160816; b=xUi5cKE1cSwsPw9d5PEzW70xNr3kmxw0Zj2wv84iiuRHgExrnZ53JeI44maUwz0NHG uesl8WTj5MdDo3MGvbGYOa0oBId27kVgPZgujPaBR9KB8FJ0evKBJiD/GlTq19pr8M7o HM4bBOBGvEFvfS0QKlQV56qKIUmDhApiziarDBhn0g8xFxcAMzI6Bqqle3yA+DfaAeNu KPb8tII4h7db7QPaWP8cGCvXKrJIXsbtJbqSX9xGcqCXzbzU7tF+ZEdF4qVRY7jE6bsW KsfGJYLPQKjejYh+jwxkL1SyhHyCAQFklZwE57HFCMn+a5In/9mo9OGttzu3mRwSOBNd e76A== 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=DTVHGVwQZZBvqCqPcw35Ltjz0zNvoABeQNqXyujJvmA=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=X28XS7TwRHX2PL+HbITUI3HLw95fbSezVLUqRTK2Q2jXTPs7aMy3tugw+QuhI7A+qy DIuvbB+rvQcGyPoBnJ1KiVoJF1G9uevlTZECeV5GS5gs+c7YhAjRb6Kfzde25ny8PFcf kX2eM8h3FseULGkHJ10JwNh9yDXpvRDJ00QQem40Hzdo700UDdsa2wQjypz206kH1n/u HlAlajffpRCftUUMiQvdTgcO8R6Q8DoKEgyoFzINt7tBRw4PfaBMgijyfTRG5oDag+Aj XK6VuZJJBhspJKC4OF5fw9WPeCLFKzXvHVJH8K0k3aiHnQ1xoi7z1lRcaBM7PMB45ckM P9jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MW3jbQAF; spf=pass (google.com: domain of linux-kernel+bounces-3727-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3727-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f7-20020a635547000000b005855f67e490si17971864pgm.690.2023.12.18.05.25.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 05:25:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3727-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MW3jbQAF; spf=pass (google.com: domain of linux-kernel+bounces-3727-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3727-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BA84528531E for ; Mon, 18 Dec 2023 13:22:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C9D274094; Mon, 18 Dec 2023 13:15:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MW3jbQAF" 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 219D342364; Mon, 18 Dec 2023 13:15:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68185C433C8; Mon, 18 Dec 2023 13:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702905354; bh=pPNJXjygt/V4vNYQ4X8NJkqM9twm0EdHZQuhceTJqsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MW3jbQAFUY++NKujPrh3jiyQS0LoHlI+A+kZKcQJLi0s180v6xCV9CGus7fmtqi7D ByE2fltburI8QA/1NDWiV1iSGk6tJsxZi3NXM+5/RBhpOvfrlUYDkBUmRicYuUgwO8 0QgoB1AmHAndv5A3xSDG56lgfLUxHrUPCuNMACr9WOBTRE+a/cMEFe7UqVcVhH4Oxx vRUvHm80kOeiBkUdo+Exanm9NU2Oll9o7R2Obqo59BjQNzNTviTasjJIh519mgYasn ismkfK21vdI/cx5c3SX2JHl2EMdMtiUS4LFGBGQzSRiDiuhx+dirIJAHcILPcLZkZB 9T1AboeN2OQKw== 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 21/34] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Mon, 18 Dec 2023 22:15:47 +0900 Message-Id: <170290534735.220107.11399065444521677554.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: 1785626309103443416 X-GMAIL-MSGID: 1785626309103443416 From: Masami Hiramatsu (Google) Support HAVE_FUNCTION_GRAPH_FREGS on x86-64, which saves ftrace_regs on the stack in ftrace_graph return trampoline so that the callbacks can access registers via ftrace_regs APIs. Note that this only recovers 'rax' and 'rdx' registers because other registers are not used anymore and recovered by caller. 'rax' and 'rdx' will be used for passing the return value. Signed-off-by: Masami Hiramatsu (Google) --- Changes in v3: - Add a comment about rip. Changes in v2: - Save rsp register and drop clearing orig_ax. --- arch/x86/Kconfig | 3 ++- arch/x86/kernel/ftrace_64.S | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 3762f41bb092..3b955c9e4eb6 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -219,7 +219,8 @@ config X86 select HAVE_FAST_GUP select HAVE_FENTRY if X86_64 || DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD - select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER + select HAVE_FUNCTION_GRAPH_FREGS if HAVE_DYNAMIC_FTRACE_WITH_ARGS + select HAVE_FUNCTION_GRAPH_RETVAL if !HAVE_DYNAMIC_FTRACE_WITH_ARGS select HAVE_FUNCTION_GRAPH_TRACER if X86_32 || (X86_64 && DYNAMIC_FTRACE) select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index 214f30e9f0c0..8a16f774604e 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -348,21 +348,42 @@ STACK_FRAME_NON_STANDARD_FP(__fentry__) SYM_CODE_START(return_to_handler) UNWIND_HINT_UNDEFINED ANNOTATE_NOENDBR - subq $24, %rsp + /* + * Save the registers requires for ftrace_regs; + * rax, rcx, rdx, rdi, rsi, r8, r9 and rbp + */ + subq $(FRAME_SIZE), %rsp + movq %rax, RAX(%rsp) + movq %rcx, RCX(%rsp) + movq %rdx, RDX(%rsp) + movq %rsi, RSI(%rsp) + movq %rdi, RDI(%rsp) + movq %r8, R8(%rsp) + movq %r9, R9(%rsp) + movq %rbp, RBP(%rsp) + /* + * orig_ax is not cleared because it is used for indicating the direct + * trampoline in the fentry. And rip is not set because we don't know + * the correct return address here. + */ + + leaq FRAME_SIZE(%rsp), %rcx + movq %rcx, RSP(%rsp) - /* Save the return values */ - movq %rax, (%rsp) - movq %rdx, 8(%rsp) - movq %rbp, 16(%rsp) movq %rsp, %rdi call ftrace_return_to_handler movq %rax, %rdi - movq 8(%rsp), %rdx - movq (%rsp), %rax - addq $24, %rsp + /* + * Restore only rax and rdx because other registers are not used + * for return value nor callee saved. Caller will reuse/recover it. + */ + movq RDX(%rsp), %rdx + movq RAX(%rsp), %rax + + addq $(FRAME_SIZE), %rsp /* * Jump back to the old return address. This cannot be JMP_NOSPEC rdi * since IBT would demand that contain ENDBR, which simply isn't so for