Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp139897lqn; Thu, 11 Apr 2024 17:18:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUtJ9MhaEcsC3ZXNcGluK0HBCKD5BlAnjc3qOdk8uzz11sPyemNqNCJnkEC/824QtRIBnuXPuWOr+HjKrO7DbBCizmNXF/HLtrwnftfug== X-Google-Smtp-Source: AGHT+IGUHj2p/iZtPLLCzazTa4W0NsD+6eokin9dzPY2pOKjwYBH6lNN+kyrQN9d71XSc/PXUd85 X-Received: by 2002:a17:90b:1b46:b0:2a4:a35f:b88e with SMTP id nv6-20020a17090b1b4600b002a4a35fb88emr1191014pjb.36.1712881088232; Thu, 11 Apr 2024 17:18:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712881088; cv=pass; d=google.com; s=arc-20160816; b=J+pkIDAenI6rbb0PrQJJgyabzwXudyboElj0YLXKn35Pe+GLWjS7B0zwJgfWgViw2r pU6cvUCduAV4MQMyQgTBV07HYyVzztcyguQknTftGr9nfYzrRPOfAt7CtK1WyDTJXVl2 JWuaQmsRak7w3X4NrNuKlMODXT++Zy2spT5BiBcOcB0FW3OXfcz7+eZczx4TDUnhBfDb P90jqqhKtzFcM6JKXUZd3t3tuWaSXgRsWxur5voD2mfYDE8+7z551D4Csa0hK8TTGxcA G063YmJeaA3B7YPP0bnYi/Gga3qTyskHPOiGkNN/QyXilrS5dxYCw4t6DzMCKGUHuvBz QSCw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=Zf+HTFpj8I9//v34h6ZpxRqKnTpj+6KrGfJr8S0wU4M=; fh=OUw7AodoZ7bocVJt0cINE2rNtImLIOjLZSJIP5rxm48=; b=UKvClvZJJKcWQ41PINK7pQoKTV9zqzQCEqLY+idf1cO7gtpp1/m6NQbFLy93SBkR93 EQ4seeziGAyjpcSayLUqnj0kFXYcEP/AJQFjcGfHu3SS6BWBUdNWdpYeQLks0x6RqCGs uQ3aDeWQJzckqSNbItu7pvD7uGrtpaIYFXsovyjQ8WknZ8+vDZJCUSXzVJWLESjng0+r o1BOzmbyICneLfByW3nDa0AXdflXSqymnqXLOOJ7kI1RBMzVKo+2PTFYY+aLcZA+/EZN 0WEMB1DDz+BLUZysWy6YfqbEncuYdi8HanSgdhV9uX53SLw9xgrL8Vmn98++NweLk0ug eXTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=gxbzRCXd; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-141746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id my5-20020a17090b4c8500b002a25eb1c69fsi2408129pjb.50.2024.04.11.17.18.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 17:18:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141746-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=@linux.microsoft.com header.s=default header.b=gxbzRCXd; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-141746-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141746-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com 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 E1C14287286 for ; Fri, 12 Apr 2024 00:18:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01B034431; Fri, 12 Apr 2024 00:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="gxbzRCXd" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECC5036C; Fri, 12 Apr 2024 00:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712881072; cv=none; b=MAGFfNK6AqOshpk/B0SHANbvZtmq3JceTwfYzLy4eKScjxSIix08IQZG8pzShTYQ/oj4hVTjpH3xEAiI0msuK7/WpR6uIeyBSwA7YTx8STTET2lUAC5sQ1notSXuCStNakT1ogz8vSs6iqR1lhkz2y3jnTzkrJrdT6bv9X5KG/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712881072; c=relaxed/simple; bh=50OZ7JlsHKGdWRWX51fnAYktmg1ytZjQKr9Ej9/1m/k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rKNgtWFSq9CPjk3Y0juLQLHIgTGlHDYAYxDh4SMGSWmuNEd+jDi1maXsEZasDIt0A/uMaoAgC3mkkRt1lyFTpaMK06W+sLfHfAjCd0TMBPTn0TeJp34R7Y37Aa41XjcIF4DIT7PVjJWaQDKUA3BoHzfEmQgOBEOqD0j7hIeTRp4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=gxbzRCXd; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from localhost.localdomain (unknown [4.155.48.125]) by linux.microsoft.com (Postfix) with ESMTPSA id 8EAF620EC32A; Thu, 11 Apr 2024 17:17:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8EAF620EC32A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1712881070; bh=Zf+HTFpj8I9//v34h6ZpxRqKnTpj+6KrGfJr8S0wU4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gxbzRCXdxkh7guY72Vjlr4GXwwDz/oDF8Eatxa7mIohHFZCqOF9dasRz5CahhOdqi a+8VRDzXhA0FsgyMBsGIknlRahgQwf0bnfrLiLb8atgrXcjG3UXDNxjEPaNZAjBDLK /zJyh+x1chEATmdXUDtzUh9r2iSb+YAUi/o+IBYI= From: Beau Belgrave To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, primiano@google.com, aahringo@redhat.com, dcook@linux.microsoft.com Subject: [RFC PATCH 3/4] perf/core: Factor perf_output_sample_udump() Date: Fri, 12 Apr 2024 00:17:31 +0000 Message-Id: <20240412001732.475-4-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412001732.475-1-beaub@linux.microsoft.com> References: <20240412001732.475-1-beaub@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit We now have two user dump sources (stack and tls). Both are doing the same logic to ensure the user dump ABI output is properly handled. The only difference is one gets the address within the method, and the other is passed the address. Add perf_output_sample_udump() and utilize it for both stack and tls sample dumps. The sp register is now fetched outside of this method and passed to it. This allows both stack and tls to utilize the same code. Signed-off-by: Beau Belgrave --- kernel/events/core.c | 68 +++++++++++++------------------------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index f848bf4be9bd..6b3cf5afdd32 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6998,47 +6998,10 @@ perf_sample_dump_size(u16 dump_size, u16 header_size, u64 task_size) } static void -perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size, - struct pt_regs *regs) -{ - /* Case of a kernel thread, nothing to dump */ - if (!regs) { - u64 size = 0; - perf_output_put(handle, size); - } else { - unsigned long sp; - unsigned int rem; - u64 dyn_size; - - /* - * We dump: - * static size - * - the size requested by user or the best one we can fit - * in to the sample max size - * data - * - user stack dump data - * dynamic size - * - the actual dumped size - */ - - /* Static size. */ - perf_output_put(handle, dump_size); - - /* Data. */ - sp = perf_user_stack_pointer(regs); - rem = __output_copy_user(handle, (void *) sp, dump_size); - dyn_size = dump_size - rem; - - perf_output_skip(handle, rem); - - /* Dynamic size. */ - perf_output_put(handle, dyn_size); - } -} - -static void -perf_output_sample_utls(struct perf_output_handle *handle, u64 addr, - u64 dump_size, struct pt_regs *regs) +perf_output_sample_udump(struct perf_output_handle *handle, + unsigned long addr, + u64 dump_size, + struct pt_regs *regs) { /* Case of a kernel thread, nothing to dump */ if (!regs) { @@ -7054,7 +7017,7 @@ perf_output_sample_utls(struct perf_output_handle *handle, u64 addr, * - the size requested by user or the best one we can fit * in to the sample max size * data - * - user tls dump data + * - user dump data * dynamic size * - the actual dumped size */ @@ -7507,9 +7470,16 @@ void perf_output_sample(struct perf_output_handle *handle, } if (sample_type & PERF_SAMPLE_STACK_USER) { - perf_output_sample_ustack(handle, - data->stack_user_size, - data->regs_user.regs); + struct pt_regs *regs = data->regs_user.regs; + unsigned long sp = 0; + + if (regs) + sp = perf_user_stack_pointer(regs); + + perf_output_sample_udump(handle, + sp, + data->stack_user_size, + regs); } if (sample_type & PERF_SAMPLE_WEIGHT_TYPE) @@ -7551,10 +7521,10 @@ void perf_output_sample(struct perf_output_handle *handle, perf_output_put(handle, data->code_page_size); if (sample_type & PERF_SAMPLE_TLS_USER) { - perf_output_sample_utls(handle, - data->tls_addr, - data->tls_user_size, - data->regs_user.regs); + perf_output_sample_udump(handle, + data->tls_addr, + data->tls_user_size, + data->regs_user.regs); } if (sample_type & PERF_SAMPLE_AUX) { -- 2.34.1