Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1504565lqb; Sun, 26 May 2024 04:29:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhwtqsqOlWSAnfKlLtdQ8ruaUTZwT/slIQaigq7ob0idH6+iCFwxKKZpQnLd6knuYTCBjWls+3k06lu6hwRat9ZEI0qunpM80bS+fcKQ== X-Google-Smtp-Source: AGHT+IG8XqSnDtZHX/4FygSgxX9DHxM8TWeNIGVx4+kyYqMty1awmpEpdx4dlxejjyU+YY00dLEA X-Received: by 2002:a81:a184:0:b0:627:dde3:fa79 with SMTP id 00721157ae682-62a08dc08e5mr68896927b3.22.1716722998249; Sun, 26 May 2024 04:29:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716722998; cv=pass; d=google.com; s=arc-20160816; b=ay2QQ/UnSm3Pxaos8ZwHulNRs/6C7zMquhSjJKFVcRZcm5Yg1k6VRABaMUa6Lr1I/J 3qGtTpfmsScyvMIezdscpfB4oEVDn14s4WpoTYlSdsHuVJ+QuqtI1STwAe0X7KFY0UJl mQAnC0CsCL3mH0UFygYb/UcD0RGCIIF3ETilsAAfz4aTSSBWboE4QKtOE7YdfWRrFYk2 qmPk5IrCafdwXr2KLxuNIkM8qqNySTqw5IF1eNR9U57Hvj66NFZSmMZGdi5gBIeZunm+ cgS1iVup9jik5CjMVM9tLkJ+liAjCqyxVin2+A1/jgnof0FA9aoCb02hhhU8igZEMpk4 0rYA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=QAQfWvd3nmcnR5EidU0DiImMMPxXcL5PouM/aKZ2j7s=; fh=ZoNARUFHXnucz/7/MkZ8zwhVk0iv1TOAxzBV6pVWG+o=; b=A0u78K2ucP2d+3cNVr4SQx1/dYjgMm8aIPp9RIIFeryJ3rPT/VH+wK0N98O4mm0qjX 284Su3VXS0UUib9E4brIS4fSoV8RGnV38zmSiFNEkkbIjq7N8x3KHzKPclZaIokLibUP GU79xYjSFrn+q3SFv4kVXH1ko8b8hnR0UWld2SH4W70t9WIh8NFJwN2BRN4rbUi95BV6 hcree7+YEPu8omRsViuLUxJO17S3pJOobWC02XgEKRb9Gkiw7UEtrJaz0OxVu4h3ErF0 cYYgJGrZNXDKzTZATHuRvB96hdEY/SNPSTQYGzF87iagxf6qWG3IkppYBsW/t0g2Rwp4 6udA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KCpMMGsf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-189724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ad75aca882si20311726d6.75.2024.05.26.04.29.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 04:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=KCpMMGsf; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-189724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E78A41C208C3 for ; Sun, 26 May 2024 11:29:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6160FC2D6; Sun, 26 May 2024 11:29:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KCpMMGsf" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B9A979DF; Sun, 26 May 2024 11:29:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716722990; cv=none; b=UKg2HDPIh8Vq+PvTHXGZP19p0l21h9og4649+SNgF8+eIr7clpe8A1I5OAdHxVG74iYeUqd+ujbS8f9xI5uY+POts9NhoOR3i6F3eBZ2fXP7OYRUaq+Hk2/pfqmln4sFZyNsl7NopZYn3S+ptLGprZ4feCmgzFatNR7cYs7bEHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716722990; c=relaxed/simple; bh=m7WE6uRCBwWdaM+TANh0R3QQ5W14DekpE2GAH0HVaoY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=TpN9Pyd8Z6jPFmmT9BvNdlwVKMVq2yfVGvLGJoa4ZfPEyK4Ceauatk9xRBWD7hcRuvb35UWIBxKpn8lFdPWaRzu2LZY6lcfdTpOhCEKlsNNAE99Rm9o+/oQvnhjS1jfThEGPwT/Q/4zp1OhiGAHnBjgeIO+trmqWYuxEdstgJNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KCpMMGsf; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f47f0d8ec9so4173365ad.3; Sun, 26 May 2024 04:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716722988; x=1717327788; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QAQfWvd3nmcnR5EidU0DiImMMPxXcL5PouM/aKZ2j7s=; b=KCpMMGsfd1+6uWQ2jenZ6pHrZZX0D7izW8O91vFQCZwWYsSEXqUrk3W+1xSqLDg1Mi Dw92GSAKLNl71vUH+xLRoAf/3t/5xfYLhjzh8CD3ySWqTxIqtc5GgVsFOC3t0SEiXIfs I0vEmX9A9dnwT2I/nSirAsaQferXZFKc7/LEXFwqi4KFILnWqO0Yqf1gIVE96+tsUukW /FulpPoGMYX4E7/uZZcTn3/x0y27PuSwUeuKtO3YnLGdxXpAmlaSCjZTjoVJDu/75g4I wMNcYaKZ7hwb5X/eHdZgNWI3TMCspvQ4fhPevozLh7byRGLWQEDCNdsFBzeveNZdGEtB kfOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716722988; x=1717327788; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QAQfWvd3nmcnR5EidU0DiImMMPxXcL5PouM/aKZ2j7s=; b=awkPcy+tWF9sBMjZxoxDqTviSwoO1YO8knayRE+vDUldqxqi0EpFWLNRa0NNlT59ge 7vBw4uZ5m1n2+g0bKOO4dKTmqZK5uUTqTe76/Iin/FDa4Kp0sT0v9sxfpJXWMKYTWULL q2K06koydNJps7a114CqepL4fflSLD1kd/+iicuXvaV+sL2nSDFwmz4bMVWqCsjVqHaM 19P3g2K9sktPq7pjPYr60PhP983yQ6o1Fpk3Q/qxD0RWgWrtdCS1HmHsr21XOFT2W2Gp 1N9IkCTJe1fE81B5eNawVfQlnHzaYWWt8BMsjyFMR4vARAVqbO5H0C2/iWkOrAsk11p8 ao2g== X-Forwarded-Encrypted: i=1; AJvYcCUasnocNRFzj2UR6m1K4g6UX8YwwvzlGeZmfzEXzrqFeMz9w2fQCjqy4DStY1BuRtnxHBKH6iSDEvN7zvx5TnbIAQGwLbuWtRmuRasemhYeYdHn X-Gm-Message-State: AOJu0YyErNdKyrHc4D4G0dvIsIXa0j8anHEe/SrYdEbozebOzCcCOuEr PQg84uMGpNS9gLBpQ92lqhqJYEjU2SNDrNjHGGWShXGcjhMogDO7 X-Received: by 2002:a17:903:41ce:b0:1f4:5477:4bfe with SMTP id d9443c01a7336-1f454774e3cmr60787325ad.69.1716722988355; Sun, 26 May 2024 04:29:48 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:13a:f00:f3a2:fbda:2824:ae0e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f44c970ca0sm43429925ad.142.2024.05.26.04.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 04:29:48 -0700 (PDT) From: Tatsuya S To: rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, mathieu.desnoyers@efficios.com Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Tatsuya S Subject: [PATCH] ftrace: Fix stack trace entry generated by ftrace_pid_func() Date: Sun, 26 May 2024 20:25:11 +0900 Message-ID: <20240526112658.46740-1-tatsuya.s2862@gmail.com> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On setting set_ftrace_pid, a extra entry generated by ftrace_pid_func() is shown on stack trace(CONFIG_UNWINDER_FRAME_POINTER=y). [004] ..... 68.459382: => 0xffffffffa00090af => ksys_read => __x64_sys_read => x64_sys_call => do_syscall_64 => entry_SYSCALL_64_after_hwframe To resolve this issue, increment skip count in function_stack_trace_call() if pids are set. Signed-off-by: Tatsuya S --- include/linux/ftrace.h | 1 + kernel/trace/ftrace.c | 2 +- kernel/trace/trace_functions.c | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 800995c425e0..d14447c0d0e9 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -666,6 +666,7 @@ unsigned long ftrace_location(unsigned long ip); unsigned long ftrace_location_range(unsigned long start, unsigned long end); unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec); unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec); +bool ftrace_pids_enabled(struct ftrace_ops *ops); extern ftrace_func_t ftrace_trace_function; diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 65208d3b5ed9..e8ddd56d1e55 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -99,7 +99,7 @@ struct ftrace_ops *function_trace_op __read_mostly = &ftrace_list_end; /* What to set function_trace_op to */ static struct ftrace_ops *set_function_trace_op; -static bool ftrace_pids_enabled(struct ftrace_ops *ops) +bool ftrace_pids_enabled(struct ftrace_ops *ops) { struct trace_array *tr; diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c index 9f1bfbe105e8..455c9a880199 100644 --- a/kernel/trace/trace_functions.c +++ b/kernel/trace/trace_functions.c @@ -223,6 +223,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip, long disabled; int cpu; unsigned int trace_ctx; + int skip = STACK_SKIP; if (unlikely(!tr->function_enabled)) return; @@ -239,7 +240,11 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip, if (likely(disabled == 1)) { trace_ctx = tracing_gen_ctx_flags(flags); trace_function(tr, ip, parent_ip, trace_ctx); - __trace_stack(tr, trace_ctx, STACK_SKIP); +#ifdef CONFIG_UNWINDER_FRAME_POINTER + if (ftrace_pids_enabled(op)) + skip++; +#endif + __trace_stack(tr, trace_ctx, skip); } atomic_dec(&data->disabled); -- 2.45.1