From patchwork Fri Feb 23 01:33:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 205175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp324857dyb; Thu, 22 Feb 2024 17:32:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUvEK7lxhTyrOnDvQSqQuf0MTkeTUQfjlNOqUJ5qYma7TSpjaYNmdHDqarTC+LjldhIZJvWq1BZ6F4ZsAt5xDYJXepfAQ== X-Google-Smtp-Source: AGHT+IFuq6AmFnPt4gBEOvg6zN8eksrM9aZiy3iUQEHgu49TkDtfVxAo/N89SddB+cik/7asaP59 X-Received: by 2002:a17:906:1455:b0:a3e:e84a:ccfb with SMTP id q21-20020a170906145500b00a3ee84accfbmr261584ejc.9.1708651964569; Thu, 22 Feb 2024 17:32:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708651964; cv=pass; d=google.com; s=arc-20160816; b=YBJE8ebL3LL4ynrCtfJNy/iAIXEcH7YPwpxbLmejH30FegjOSFhCgO13XpENeUDtP9 xON+Zp1d/q/xMtS5MjR76mcSc+nPg/ayuZ1Arr2kUx7gauE4SaCejw54VXVaw6WQ/TA5 fJCm75FzIcT6n9x5Wno4xW0zXpPPfbxZEDPRwRCUujrVG9p4SmUDmKScWmm5sSbVQiL8 efp+byYJA1Sdj6urDCquCtk1zFgJk84l3hby1zjydTUtCw/W4nMgGcDUtRof/qDgmK0Y VSuww3LyX10gRtfD72DmOYZDmKzkwvjpK1YqeoDZZK5GF2e+bQoUZYrXQN15TMiNo/2X y/TA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=7pH4//TEkI7dtvMdaeNspDgpuqgeN9SAjnDTQt5xltg=; fh=TdZ0M6+ZhUU2JkCc5zvDTA1ryfZXsigMobkRM04iH2Q=; b=TLCALllMIwrn6bPYWrpxBBr1FOvdMUqNsp39S2/jY/Bh5l39pt3nXdewnln1Z7Uozy epANWO80HPZKYj+Fbym2c0rXp06odWYzVEN9E8cMQD/1dT87IESNLKlttc+CabmD4HKG 0FX1Z6PyoWhZpYOtf0eeEQSbFYkKp0gAbWxvfWiGmq7zdRmiZTShCtLjSOU1KIs8Aisa OwwNKHt5Kjqx9tbsCOQRIdfNVVDi2426+PLxWkCFpFiK8NgUiUFNhpsyMf2qVUMKt2Gq q8Mx9NhbIM8MCxt+h3BSolAyN3oHX/66wO0fXaGZdw195TF50s5r1jx++Y/69DDAJ0EE 0dCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p6-20020a170906604600b00a3d62db0d5csi5920864ejj.911.2024.02.22.17.32.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 17:32:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.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 222881F23D42 for ; Fri, 23 Feb 2024 01:32:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06D3BC8E0; Fri, 23 Feb 2024 01:31:55 +0000 (UTC) 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 7AAB7947A; Fri, 23 Feb 2024 01:31:53 +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=1708651913; cv=none; b=ln4vu36wAu5+SQCI5K3clWmjcb9b6bxw34N/v+loxJudjW5MVOo6r6/DSniul6597bkBEJ/C8PX7wWHKlUsbptiXKiO5IxfL8QaWv/s0ZIGx/yypp7mO84LSHNeHFJRE/xsxhOw2osEtnGqlk7uN7a5wg+R+NL4b78w9ji++eaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708651913; c=relaxed/simple; bh=2Ho0hHkQMrTftOpqELU+854wFjDx4nQbuKE5ycj4g5g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=XMbeaQWxorxEfzszs0UTqjaQIDmXS23Dnsiq++q1QRjDLgiPMGIn6jRpAd3pfXvu0/4fuT31HOCSnt4oghXRvfD4GoXZ8yokAvLKWWnxmYlQky0Q5yFjKNFmyBdBOvw1b7wFxfaiWf0eBD3soj+Yaa8mNxBvrEwuoGPA4AtL5No= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1382C433F1; Fri, 23 Feb 2024 01:31:52 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rdKRc-00000006og7-2y8r; Thu, 22 Feb 2024 20:33:44 -0500 Message-ID: <20240223013344.570525723@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 22 Feb 2024 20:33:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Vincent Donnefort Subject: [PATCH 1/2] tracing: Fix snapshot counter going between two tracers that use it References: <20240223013323.798805901@goodmis.org> 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: 1791651442526227216 X-GMAIL-MSGID: 1791651442526227216 From: "Steven Rostedt (Google)" Running the ftrace selftests caused the ring buffer mapping test to fail. Investigating, I found that the snapshot counter would be incremented every time a tracer that uses the snapshot is enabled even if the snapshot was used by the previous tracer. That is: # cd /sys/kernel/tracing # echo wakeup_rt > current_tracer # echo wakeup_dl > current_tracer # echo nop > current_tracer would leave the snapshot counter at 1 and not zero. That's because the enabling of wakeup_dl would increment the counter again but the setting the tracer to nop would only decrement it once. Do not arm the snapshot for a tracer if the previous tracer already had it armed. Fixes: 16f7e48ffc53a ("tracing: Add snapshot refcount") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index b7a870c8ae2a..480201c3b36e 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6164,7 +6164,7 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf) tracing_disarm_snapshot(tr); } - if (t->use_max_tr) { + if (!had_max_tr && t->use_max_tr) { ret = tracing_arm_snapshot_locked(tr); if (ret) goto out; From patchwork Fri Feb 23 01:33:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 205174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp324850dyb; Thu, 22 Feb 2024 17:32:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX7pQ34tKGwHa8hfKqjd5iiqoEjChfgN2983ej5C0nem2rAIpnVZ5fRKL5hR+VGcKBA0nN3hk6/h9OxxxqImfXa76PV7w== X-Google-Smtp-Source: AGHT+IFllkH5qx3367Wsv3yZ6iQwMOKgFfsgbvgHNZ2hgStuB7r70mQ2M2I66v8z/wsx4a8+qkgZ X-Received: by 2002:ae9:e407:0:b0:785:d3e7:3b2 with SMTP id q7-20020ae9e407000000b00785d3e703b2mr767597qkc.24.1708651963698; Thu, 22 Feb 2024 17:32:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708651963; cv=pass; d=google.com; s=arc-20160816; b=Paf61AMlT04nN5O7NptngobA09fGfqnlbxDRK1z1FLand/09F6NZMjrk65Ze23efZR A74fVCuwcgN/vrD1HJf9g1xe0qCTPJojaAvSrfvZypOIxgJ7TS1l7wc2fsiKApHqXJXO Q8FmLxRl+UalGhRog4Rt/KKAWV8ju0ArQUWwptIrLAnWIosmZ5EN8mxbMg5oCb1aFQ1O p2i1GDG8KdfJ69swGywMtmngjho5Zp0ai95mhsXqfrGVMgdej2v9ewxJeLn5XBLRN6Id g4+9/JkjLmSp3Ksmwf9BDP5CWxK6f6gMx/SHCI7AItUloj1u8zfwPGj/fphE3BmIev9q XrTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=DgyNBhv9go7d2AQN9Qu1JPjxec4gStJBIjs3HgocguY=; fh=TdZ0M6+ZhUU2JkCc5zvDTA1ryfZXsigMobkRM04iH2Q=; b=ymsFH2QbTyWXtSaTFL8bMHvSVTYXoZrxWisb1ZvmTzOz5nrO2SxiLftOiNrUiYqdz2 Y9uVJYTIjXpeloMN7/Zhmwc5k0UNY8qA9pbwBmUrgAq57GFbz86WZfmyt445SOIuWmRC WAlD8WKojuwW7eo5NQ+7ncG4QHvToghWxqTxtYW0ZRu8UxxniSkNtBsh3QFOKODPu19w CODtynDJjX365btdFylDvHlXuqauL4Z+dgqWfTVODOhZAZvXFQQAoelGEDPLLi5PxtTZ PORQh0Wcj3JGN4I9gbodule/BqZQZs9nHiWsnvKRBfa5Be9h0YHe0aaOrot56i2AG7SU FV1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i5-20020a37c205000000b00787324e97eesi14243727qkm.661.2024.02.22.17.32.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 17:32:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77628-ouuuleilei=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7CA6A1C21D1D for ; Fri, 23 Feb 2024 01:32:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0729BD26B; Fri, 23 Feb 2024 01:31:55 +0000 (UTC) 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 7AA482C9E; Fri, 23 Feb 2024 01:31:53 +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=1708651913; cv=none; b=NVWNr7TBS7cuB1UlCsMQlKomQd+6B7uRMXdXELEmQGoLPNXHtm7p5ZbV6fQrUnVzwZ2gExHoTvr5vroW5SHuW1lOKjsm4HbN+ADiepkPZGOvNOJd2yynZzhR21OIIUzx2JdIAyJDislNxzMZIODo6r9YUBSM5g0OQ7+Ov2+rZM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708651913; c=relaxed/simple; bh=4NKBpeaolII1sBupq/IxTuoIHTKsguTYUdtlaE5KXXQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WHPhmHMCVUaFXBdBSoW9KAK31QxLqpAQrqw1tX4C4Am8PqDxEwCEQihhBhbnS+AcPS0LBvRXtCkG//weOW7/zNEut5UDscK7K8noIptkO3mMKn0uHDoTi396D2hoStWL8qXQu+ri6rb2giGji2+fUYi6mNed/YCGK9MqG2kWvKs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24CF8C43390; Fri, 23 Feb 2024 01:31:53 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rdKRc-00000006ogb-3daK; Thu, 22 Feb 2024 20:33:44 -0500 Message-ID: <20240223013344.729055907@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 22 Feb 2024 20:33:25 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Vincent Donnefort Subject: [PATCH 2/2] tracing: Decrement the snapshot if the snapshot trigger fails to register References: <20240223013323.798805901@goodmis.org> 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: 1791651441218936041 X-GMAIL-MSGID: 1791651441218936041 From: "Steven Rostedt (Google)" Running the ftrace selftests caused the ring buffer mapping test to fail. Investigating, I found that the snapshot counter would be incremented every time a snapshot trigger was added, even if that snapshot trigger failed. # cd /sys/kernel/tracing # echo "snapshot" > events/sched/sched_process_fork/trigger # echo "snapshot" > events/sched/sched_process_fork/trigger -bash: echo: write error: File exists That second one that fails increments the snapshot counter but doesn't decrement it. It needs to be decremented when the snapshot fails. Fixes: 16f7e48ffc53a ("tracing: Add snapshot refcount") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_trigger.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c index 62e4f58b8671..4bec043c8690 100644 --- a/kernel/trace/trace_events_trigger.c +++ b/kernel/trace/trace_events_trigger.c @@ -1491,7 +1491,10 @@ register_snapshot_trigger(char *glob, if (ret < 0) return ret; - return register_trigger(glob, data, file); + ret = register_trigger(glob, data, file); + if (ret < 0) + tracing_disarm_snapshot(file->tr); + return ret; } static void unregister_snapshot_trigger(char *glob,