Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3108478rdb; Tue, 6 Feb 2024 07:25:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IG73ZWFAhRiO/SK9It0GwOFzqLnk7GyVQNkp7b0LxEWVS7v2nl/iJythL94YBZKH/7jutjq X-Received: by 2002:a05:6a21:3405:b0:19e:9c30:cb3b with SMTP id yn5-20020a056a21340500b0019e9c30cb3bmr965699pzb.11.1707233137596; Tue, 06 Feb 2024 07:25:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707233137; cv=pass; d=google.com; s=arc-20160816; b=QD29zmYcwLdFrKIA/+OfUZCwKRC3eGjQb0Hy21zeg+1tuijyeEi+HkYFf9cKhymTwe xXiL+aLyYyIq1gvTmkzqSpa1PwEAjMaM9ixyvoR3pSYlphX/Kyf8nSzRHtKOWDwHUuqy tdSB3+x7DbrRBXxD7xM7G58u3Tb6UKkPC+mX6MNPSa34CVPr0uOZI5ONkDbTkZwkFg3L +y6D0TXjhQNEdev7NXrCjdHTSftNzo+DpFOGWLm5AxfZbIduVwSqj1wU6wD9pUr5vdy6 zCc4mDUfLpnK36uHHws4DczNe8K8mIngtbTfDFdVGWMLyo+p3mWNE6v0DEuXV3IDciL4 0YSA== 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=Tt9CuJVUqBOxHNUV/MUjZNddIcOyjajyY4hbmGAF7II=; fh=6KDc94APUcI5jg9frEgG09KCs8wFntu/xB9jItbw1oI=; b=Day8djuw+MqREEAWEFtG7zA+sj456FCQ9OmweUQFHe/gCsBGLCMeEVrklRLTmaoGns Hf7sz4rzOEdYppf6qzBdPfTIwGtuJaHtECuo/6TqcnBTlSAFzMvJThBdSRuuKFs5/vhI 2f7+X/E5KajLmP53VCUGzfXS+CnAjk0OUkRWVYglRZlGRtoKU50jSPU1PsYYQJGCCPVK 0/6L5fZ23n5K2ufZHcONg5cygywpZcc/QX95PEZ+slYxWRpUuqd7qIqDhgQ882kkHaKa rEmW+P/fFyljzyHcrB8Uu6MmQtwNt3O7yyp2AKxFDwusKQBaIKGcMRrX8FMzyCF1RlBz VRtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aS27veMw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55207-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55207-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWdEybCFZ2MxNUWmh+5+BthYsmDBGqnOoFiebXx8mpDMyllqrOyZ2K9xSyUHCLlQUgrdLsL2ix0wSLXklM0R6dew/cLEFlO96cphx/qPA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h8-20020a63c008000000b005cecbe69c23si1872462pgg.43.2024.02.06.07.25.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 07:25:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55207-linux.lists.archive=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=aS27veMw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-55207-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55207-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 47E7928FFF6 for ; Tue, 6 Feb 2024 15:18:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 152E513A276; Tue, 6 Feb 2024 15:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aS27veMw" 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 3D34113398C; Tue, 6 Feb 2024 15:12:01 +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=1707232321; cv=none; b=KmppwIiTOJgbC1lNSAoKfT63NFU3mhb6ndSJhkAUyI4Q9q3hqCc+06y0YD+xdeTeyzPFaaiXW6IQzMiiDhbuxn05Tmw2lrPATlfyTPjcZG1OkiFoYdN0xlqw05dJdsQqeI6fz+Ds139dXVR7JoMkxWHl0c2Xb89GPyW7Mrdw4xY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707232321; c=relaxed/simple; bh=9YSxRXR2HSbZYZbflQVAgOR2is0PYbfum3hhAgIy/jA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=DZEK0HtRTebFSpP8olD/sPlkzLTTzIz16VHHnWDqjLl9hJUmolYtijoPpKsQWES+mk+J41SfvvcKDTJrVN2pFpSp8DE3+j1wjLemQEgUeAAWDxNtw7UCEp1wEvn1bt66FR+0ls3MQZ6QGPWPu8M55Mk9RyHwlJNWyNdPKzBiGv8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aS27veMw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6F1EC433F1; Tue, 6 Feb 2024 15:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707232321; bh=9YSxRXR2HSbZYZbflQVAgOR2is0PYbfum3hhAgIy/jA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aS27veMwGRZG8E880jNoZMHZEjVF2UWAuNu7Wr7Nnwu0kBYaVKxyo8YyQcreyAFJ+ crxhYGzmhyfqHSMiXC2PzQfPCLyrDwqo72jfcHlVoHdAgDRMtCq2cpvIFgJ9rhDdFW Eyr/fyJDDLZtKxRckOz4W8fbRdfzMHqI/QYGLU4XY/26FA6LpylexMrReD6xGZ6usC ajSEeTXQxCmgbKxxSS9DTGCrmwAQeaRl7xM8hJe3Llb7cwXemi1qLVT/oF0S7B4GFx FAx4IhwZBl3PZCOOoq4YRmErnR4vn9WYo+fsqqIbjCeH32ncQ9tZ+PXdUHEDRBf0jN BSeHT2kaOAyyQ== 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 24/36] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Wed, 7 Feb 2024 00:11:56 +0900 Message-Id: <170723231592.502590.12367006830540525214.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 5edec175b9bf..ccf17d8b6f5f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -223,7 +223,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