From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77615EB64D9 for ; Thu, 15 Jun 2023 13:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240363AbjFONfd (ORCPT ); Thu, 15 Jun 2023 09:35:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344471AbjFONfD (ORCPT ); Thu, 15 Jun 2023 09:35:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7217E30DB for ; Thu, 15 Jun 2023 06:34:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9BD660F85 for ; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FF3BC433C9; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n79-000TlJ-0A; Thu, 15 Jun 2023 09:34:15 -0400 Message-ID: <20230615133414.865893768@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:32 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Daniel Bristot de Oliveira , Daniel Bristot de Oliveira Subject: [for-linus][PATCH 01/15] tracing/rv/rtla: Update MAINTAINERS file to point to proper mailing list References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" The mailing list that goes to linux-trace-devel is for the tracing libraries, and the patchwork associated to the tracing libraries keys off of that mailing list. For anything that lives in the Linux kernel proper (including the tools directory) must go through linux-trace-kernel, as the patchwork to that list keys off of the Linux kernel proper. Update the MAINTAINERS file to reflect the proper mailing lists. Link: https://lore.kernel.org/linux-trace-kernel/20230529044002.0481452b@ro= rschach.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Daniel Bristot de Oliveira Signed-off-by: Steven Rostedt (Google) Acked-by: Daniel Bristot de Oliveira --- MAINTAINERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 27ef11624748..725d35b5d328 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17806,7 +17806,7 @@ F: tools/testing/selftests/rtc/ Real-time Linux Analysis (RTLA) tools M: Daniel Bristot de Oliveira M: Steven Rostedt -L: linux-trace-devel@vger.kernel.org +L: linux-trace-kernel@vger.kernel.org S: Maintained F: Documentation/tools/rtla/ F: tools/tracing/rtla/ @@ -18368,7 +18368,7 @@ F: drivers/infiniband/ulp/rtrs/ RUNTIME VERIFICATION (RV) M: Daniel Bristot de Oliveira M: Steven Rostedt -L: linux-trace-devel@vger.kernel.org +L: linux-trace-kernel@vger.kernel.org S: Maintained F: Documentation/trace/rv/ F: include/linux/rv.h --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9C0BEB64DA for ; Thu, 15 Jun 2023 13:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344240AbjFONfj (ORCPT ); Thu, 15 Jun 2023 09:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344485AbjFONfD (ORCPT ); Thu, 15 Jun 2023 09:35:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D2430DE for ; Thu, 15 Jun 2023 06:34:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E038E63759 for ; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55D1BC433CB; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n79-000Tlr-0p; Thu, 15 Jun 2023 09:34:15 -0400 Message-ID: <20230615133415.070156632@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:33 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , sunliming , Beau Belgrave Subject: [for-linus][PATCH 02/15] tracing/user_events: Prevent same name but different args event References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming User processes register name_args for events. If the same name but different args event are registered. The trace outputs of second event are printed as the first event. This is incorrect. Return EADDRINUSE back to the user process if the same name but different a= rgs event has being registered. Link: https://lore.kernel.org/linux-trace-kernel/20230529032100.286534-1-su= nliming@kylinos.cn Signed-off-by: sunliming Reviewed-by: Masami Hiramatsu (Google) Acked-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 36 +++++++++++++++---- .../selftests/user_events/ftrace_test.c | 6 ++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index dbb14705d0d3..37a38496a6be 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1786,6 +1786,8 @@ static int user_event_parse(struct user_event_group *= group, char *name, int ret; u32 key; struct user_event *user; + int argc =3D 0; + char **argv; =20 /* Prevent dyn_event from racing */ mutex_lock(&event_mutex); @@ -1793,13 +1795,35 @@ static int user_event_parse(struct user_event_group= *group, char *name, mutex_unlock(&event_mutex); =20 if (user) { - *newuser =3D user; - /* - * Name is allocated by caller, free it since it already exists. - * Caller only worries about failure cases for freeing. - */ - kfree(name); + if (args) { + argv =3D argv_split(GFP_KERNEL, args, &argc); + if (!argv) { + ret =3D -ENOMEM; + goto error; + } + + ret =3D user_fields_match(user, argc, (const char **)argv); + argv_free(argv); + + } else + ret =3D list_empty(&user->fields); + + if (ret) { + *newuser =3D user; + /* + * Name is allocated by caller, free it since it already exists. + * Caller only worries about failure cases for freeing. + */ + kfree(name); + } else { + ret =3D -EADDRINUSE; + goto error; + } + return 0; +error: + refcount_dec(&user->refcnt); + return ret; } =20 user =3D kzalloc(sizeof(*user), GFP_KERNEL_ACCOUNT); diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/test= ing/selftests/user_events/ftrace_test.c index 7c99cef94a65..6e8c4b47281c 100644 --- a/tools/testing/selftests/user_events/ftrace_test.c +++ b/tools/testing/selftests/user_events/ftrace_test.c @@ -228,6 +228,12 @@ TEST_F(user, register_events) { ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); ASSERT_EQ(0, reg.write_index); =20 + /* Multiple registers to same name but different args should fail */ + reg.enable_bit =3D 29; + reg.name_args =3D (__u64)"__test_event u32 field1;"; + ASSERT_EQ(-1, ioctl(self->data_fd, DIAG_IOCSREG, ®)); + ASSERT_EQ(EADDRINUSE, errno); + /* Ensure disabled */ self->enable_fd =3D open(enable_file, O_RDWR); ASSERT_NE(-1, self->enable_fd); --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 151FAEB64D9 for ; Thu, 15 Jun 2023 13:35:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344003AbjFONfg (ORCPT ); Thu, 15 Jun 2023 09:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344484AbjFONfD (ORCPT ); Thu, 15 Jun 2023 09:35:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5046430E0 for ; Thu, 15 Jun 2023 06:34:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 15584637DA for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7872DC43391; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n79-000TmP-1U; Thu, 15 Jun 2023 09:34:15 -0400 Message-ID: <20230615133415.275901907@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:34 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , sunliming Subject: [for-linus][PATCH 03/15] tracing/user_events: Handle matching arguments that is null from dyn_events References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming When A registering user event from dyn_events has no argments, it will pass= the matching check, regardless of whether there is a user event with the same n= ame and arguments. Add the matching check when the arguments of registering user event is null. Link: https://lore.kernel.org/linux-trace-kernel/20230529065110.303440-1-su= nliming@kylinos.cn Signed-off-by: sunliming Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index 37a38496a6be..afe61dc86543 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1745,6 +1745,8 @@ static bool user_event_match(const char *system, cons= t char *event, =20 if (match && argc > 0) match =3D user_fields_match(user, argc, argv); + else if (match && argc =3D=3D 0) + match =3D list_empty(&user->fields); =20 return match; } --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A4CDEB64D9 for ; Thu, 15 Jun 2023 13:35:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344294AbjFONfu (ORCPT ); Thu, 15 Jun 2023 09:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344574AbjFONfL (ORCPT ); Thu, 15 Jun 2023 09:35:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A38C2960 for ; Thu, 15 Jun 2023 06:34:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F5E4637EE for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A30F5C43395; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n79-000Tmx-28; Thu, 15 Jun 2023 09:34:15 -0400 Message-ID: <20230615133415.478015212@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:35 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , sunliming Subject: [for-linus][PATCH 04/15] tracing: Modify print_fields() for fields output order References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming Now the print_fields() print trace event fields in reverse order. Modify it to the positive sequence. Example outputs for a user event: test0 u32 count1; u32 count2 Output before: example-2547 [000] ..... 325.666387: test0: count2=3D0x2 (2) count1= =3D0x1 (1) Output after: example-2742 [002] ..... 429.769370: test0: count1=3D0x1 (1) count2= =3D0x2 (2) Link: https://lore.kernel.org/linux-trace-kernel/20230525085232.5096-1-sunl= iming@kylinos.cn Fixes: 80a76994b2d88 ("tracing: Add "fields" option to show raw trace event= fields") Signed-off-by: sunliming Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 15f05faaae44..1e33f367783e 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -847,7 +847,7 @@ static void print_fields(struct trace_iterator *iter, s= truct trace_event_call *c int ret; void *pos; =20 - list_for_each_entry(field, head, link) { + list_for_each_entry_reverse(field, head, link) { trace_seq_printf(&iter->seq, " %s=3D", field->name); if (field->offset + field->size > iter->ent_size) { trace_seq_puts(&iter->seq, ""); --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C92EB64D9 for ; Thu, 15 Jun 2023 13:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344458AbjFONg4 (ORCPT ); Thu, 15 Jun 2023 09:36:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344351AbjFONgU (ORCPT ); Thu, 15 Jun 2023 09:36:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56FD63582 for ; Thu, 15 Jun 2023 06:35:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7EFC6633FE for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB406C433CA; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n79-000TnV-2o; Thu, 15 Jun 2023 09:34:15 -0400 Message-ID: <20230615133415.683635706@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:36 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave , sunliming Subject: [for-linus][PATCH 05/15] tracing/user_events: Fix the incorrect trace record for empty arguments events References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming The user_events support events that has empty arguments. But the trace event is discarded and not really committed when the arguments is empty. Fix this by not attempting to copy in zero-length data. Link: https://lkml.kernel.org/r/20230606062027.1008398-2-sunliming@kylinos.= cn Acked-by: Beau Belgrave Acked-by: Masami Hiramatsu (Google) Signed-off-by: sunliming Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index afe61dc86543..49914b6cb651 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1432,7 +1432,7 @@ static void user_event_ftrace(struct user_event *user= , struct iov_iter *i, if (unlikely(!entry)) return; =20 - if (unlikely(!copy_nofault(entry + 1, i->count, i))) + if (unlikely(i->count !=3D 0 && !copy_nofault(entry + 1, i->count, i))) goto discard; =20 if (!list_empty(&user->validators) && @@ -1473,7 +1473,7 @@ static void user_event_perf(struct user_event *user, = struct iov_iter *i, =20 perf_fetch_caller_regs(regs); =20 - if (unlikely(!copy_nofault(perf_entry + 1, i->count, i))) + if (unlikely(i->count !=3D 0 && !copy_nofault(perf_entry + 1, i->count, = i))) goto discard; =20 if (!list_empty(&user->validators) && --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 598B9EB64D9 for ; Thu, 15 Jun 2023 13:37:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344418AbjFONg7 (ORCPT ); Thu, 15 Jun 2023 09:36:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344361AbjFONgV (ORCPT ); Thu, 15 Jun 2023 09:36:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96DE7358B for ; Thu, 15 Jun 2023 06:35:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 86325638B3 for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19F1C433CC; Thu, 15 Jun 2023 13:34:16 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7A-000To3-0E; Thu, 15 Jun 2023 09:34:16 -0400 Message-ID: <20230615133415.888378523@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:37 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave , sunliming Subject: [for-linus][PATCH 06/15] selftests/user_events: Add ftrace self-test for empty arguments events References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming Tests to ensure events that has empty arguments can input trace record correctly when using ftrace. Link: https://lkml.kernel.org/r/20230606062027.1008398-3-sunliming@kylinos.= cn Acked-by: Beau Belgrave Acked-by: Masami Hiramatsu (Google) Signed-off-by: sunliming Signed-off-by: Steven Rostedt (Google) --- .../selftests/user_events/ftrace_test.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/test= ing/selftests/user_events/ftrace_test.c index 6e8c4b47281c..abfb49558a26 100644 --- a/tools/testing/selftests/user_events/ftrace_test.c +++ b/tools/testing/selftests/user_events/ftrace_test.c @@ -316,6 +316,39 @@ TEST_F(user, write_events) { ASSERT_EQ(EINVAL, errno); } =20 +TEST_F(user, write_empty_events) { + struct user_reg reg =3D {0}; + struct iovec io[1]; + int before =3D 0, after =3D 0; + + reg.size =3D sizeof(reg); + reg.name_args =3D (__u64)"__test_event"; + reg.enable_bit =3D 31; + reg.enable_addr =3D (__u64)&self->check; + reg.enable_size =3D sizeof(self->check); + + io[0].iov_base =3D ®.write_index; + io[0].iov_len =3D sizeof(reg.write_index); + + /* Register should work */ + ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); + ASSERT_EQ(0, reg.write_index); + ASSERT_EQ(0, self->check); + + /* Enable event */ + self->enable_fd =3D open(enable_file, O_RDWR); + ASSERT_NE(-1, write(self->enable_fd, "1", sizeof("1"))) + + /* Event should now be enabled */ + ASSERT_EQ(1 << reg.enable_bit, self->check); + + /* Write should make it out to ftrace buffers */ + before =3D trace_bytes(); + ASSERT_NE(-1, writev(self->data_fd, (const struct iovec *)io, 1)); + after =3D trace_bytes(); + ASSERT_GT(after, before); +} + TEST_F(user, write_fault) { struct user_reg reg =3D {0}; struct iovec io[2]; --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7D4EEB64DA for ; Thu, 15 Jun 2023 13:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245731AbjFONg3 (ORCPT ); Thu, 15 Jun 2023 09:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344753AbjFONfY (ORCPT ); Thu, 15 Jun 2023 09:35:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36CD30F8 for ; Thu, 15 Jun 2023 06:34:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B75636371C for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32EC1C433C9; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7A-000Tob-0r; Thu, 15 Jun 2023 09:34:16 -0400 Message-ID: <20230615133416.089967064@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:38 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave , sunliming Subject: [for-linus][PATCH 07/15] selftests/user_events: Clear the events after perf self-test References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming When the self test is completed, perf self-test left the user events not to be cleared. Clear the events by unregister and delete the event. Link: https://lkml.kernel.org/r/20230606062027.1008398-4-sunliming@kylinos.= cn Acked-by: Beau Belgrave Acked-by: Masami Hiramatsu (Google) Signed-off-by: sunliming Signed-off-by: Steven Rostedt (Google) --- .../testing/selftests/user_events/perf_test.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/testing/selftests/user_events/perf_test.c b/tools/testin= g/selftests/user_events/perf_test.c index a070258d4449..e97f24ab6e2f 100644 --- a/tools/testing/selftests/user_events/perf_test.c +++ b/tools/testing/selftests/user_events/perf_test.c @@ -81,6 +81,32 @@ static int get_offset(void) return offset; } =20 +static int clear(int *check) +{ + struct user_unreg unreg =3D {0}; + + unreg.size =3D sizeof(unreg); + unreg.disable_bit =3D 31; + unreg.disable_addr =3D (__u64)check; + + int fd =3D open(data_file, O_RDWR); + + if (fd =3D=3D -1) + return -1; + + if (ioctl(fd, DIAG_IOCSUNREG, &unreg) =3D=3D -1) + if (errno !=3D ENOENT) + return -1; + + if (ioctl(fd, DIAG_IOCSDEL, "__test_event") =3D=3D -1) + if (errno !=3D ENOENT) + return -1; + + close(fd); + + return 0; +} + FIXTURE(user) { int data_fd; int check; @@ -93,6 +119,9 @@ FIXTURE_SETUP(user) { =20 FIXTURE_TEARDOWN(user) { close(self->data_fd); + + if (clear(&self->check) !=3D 0) + printf("WARNING: Clear didn't work!\n"); } =20 TEST_F(user, perf_write) { --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15CC1EB64D9 for ; Thu, 15 Jun 2023 13:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344476AbjFONhI (ORCPT ); Thu, 15 Jun 2023 09:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344388AbjFONgX (ORCPT ); Thu, 15 Jun 2023 09:36:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DE002D5F for ; Thu, 15 Jun 2023 06:35:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F026C63904 for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 646BBC433CB; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7A-000TpB-1W; Thu, 15 Jun 2023 09:34:16 -0400 Message-ID: <20230615133416.288344909@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:39 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave , sunliming Subject: [for-linus][PATCH 08/15] selftests/user_events: Add perf self-test for empty arguments events References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: sunliming Tests to ensure events that has empty arguments can input trace record correctly when using perf. Link: https://lkml.kernel.org/r/20230606062027.1008398-5-sunliming@kylinos.= cn Acked-by: Beau Belgrave Acked-by: Masami Hiramatsu (Google) Signed-off-by: sunliming Signed-off-by: Steven Rostedt (Google) --- .../testing/selftests/user_events/perf_test.c | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/testing/selftests/user_events/perf_test.c b/tools/testin= g/selftests/user_events/perf_test.c index e97f24ab6e2f..8b09be566fa2 100644 --- a/tools/testing/selftests/user_events/perf_test.c +++ b/tools/testing/selftests/user_events/perf_test.c @@ -189,6 +189,59 @@ TEST_F(user, perf_write) { ASSERT_EQ(0, self->check); } =20 +TEST_F(user, perf_empty_events) { + struct perf_event_attr pe =3D {0}; + struct user_reg reg =3D {0}; + struct perf_event_mmap_page *perf_page; + int page_size =3D sysconf(_SC_PAGESIZE); + int id, fd; + __u32 *val; + + reg.size =3D sizeof(reg); + reg.name_args =3D (__u64)"__test_event"; + reg.enable_bit =3D 31; + reg.enable_addr =3D (__u64)&self->check; + reg.enable_size =3D sizeof(self->check); + + /* Register should work */ + ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); + ASSERT_EQ(0, reg.write_index); + ASSERT_EQ(0, self->check); + + /* Id should be there */ + id =3D get_id(); + ASSERT_NE(-1, id); + + pe.type =3D PERF_TYPE_TRACEPOINT; + pe.size =3D sizeof(pe); + pe.config =3D id; + pe.sample_type =3D PERF_SAMPLE_RAW; + pe.sample_period =3D 1; + pe.wakeup_events =3D 1; + + /* Tracepoint attach should work */ + fd =3D perf_event_open(&pe, 0, -1, -1, 0); + ASSERT_NE(-1, fd); + + perf_page =3D mmap(NULL, page_size * 2, PROT_READ, MAP_SHARED, fd, 0); + ASSERT_NE(MAP_FAILED, perf_page); + + /* Status should be updated */ + ASSERT_EQ(1 << reg.enable_bit, self->check); + + /* Ensure write shows up at correct offset */ + ASSERT_NE(-1, write(self->data_fd, ®.write_index, + sizeof(reg.write_index))); + val =3D (void *)(((char *)perf_page) + perf_page->data_offset); + ASSERT_EQ(PERF_RECORD_SAMPLE, *val); + + munmap(perf_page, page_size * 2); + close(fd); + + /* Status should be updated */ + ASSERT_EQ(0, self->check); +} + int main(int argc, char **argv) { return test_harness_run(argc, argv); --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BE30EB64D9 for ; Thu, 15 Jun 2023 13:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344408AbjFONgY (ORCPT ); Thu, 15 Jun 2023 09:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344734AbjFONfY (ORCPT ); Thu, 15 Jun 2023 09:35:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B44A3AB8 for ; Thu, 15 Jun 2023 06:34:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B8DCF639D3 for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94D82C43391; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7A-000Tpl-2A; Thu, 15 Jun 2023 09:34:16 -0400 Message-ID: <20230615133416.491731786@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:40 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Christian Brauner , Beau Belgrave Subject: [for-linus][PATCH 09/15] tracing/user_events: Remove user_ns walk for groups References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave During discussions it was suggested that user_ns is not a good place to try to attach a tracing namespace. The current code has stubs to enable that work that are very likely to change and incur a performance cost. Remove the user_ns walk when creating a group and determining the system name to use, since it's unlikely user_ns will be used in the future. Link: https://lore.kernel.org/all/20230601-urenkel-holzofen-cd9403b9cadd@br= auner/ Link: https://lore.kernel.org/linux-trace-kernel/20230601224928.301-1-beaub= @linux.microsoft.com Suggested-by: Christian Brauner Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 42 ++++---------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index 49914b6cb651..cf6d4c02c363 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -182,21 +182,11 @@ static void user_event_group_destroy(struct user_even= t_group *group) kfree(group); } =20 -static char *user_event_group_system_name(struct user_namespace *user_ns) +static char *user_event_group_system_name(void) { char *system_name; int len =3D sizeof(USER_EVENTS_SYSTEM) + 1; =20 - if (user_ns !=3D &init_user_ns) { - /* - * Unexpected at this point: - * We only currently support init_user_ns. - * When we enable more, this will trigger a failure so log. - */ - pr_warn("user_events: Namespace other than init_user_ns!\n"); - return NULL; - } - system_name =3D kmalloc(len, GFP_KERNEL); =20 if (!system_name) @@ -207,34 +197,12 @@ static char *user_event_group_system_name(struct user= _namespace *user_ns) return system_name; } =20 -static inline struct user_event_group -*user_event_group_from_user_ns(struct user_namespace *user_ns) -{ - if (user_ns =3D=3D &init_user_ns) - return init_group; - - return NULL; -} - static struct user_event_group *current_user_event_group(void) { - struct user_namespace *user_ns =3D current_user_ns(); - struct user_event_group *group =3D NULL; - - while (user_ns) { - group =3D user_event_group_from_user_ns(user_ns); - - if (group) - break; - - user_ns =3D user_ns->parent; - } - - return group; + return init_group; } =20 -static struct user_event_group -*user_event_group_create(struct user_namespace *user_ns) +static struct user_event_group *user_event_group_create(void) { struct user_event_group *group; =20 @@ -243,7 +211,7 @@ static struct user_event_group if (!group) return NULL; =20 - group->system_name =3D user_event_group_system_name(user_ns); + group->system_name =3D user_event_group_system_name(); =20 if (!group->system_name) goto error; @@ -2603,7 +2571,7 @@ static int __init trace_events_user_init(void) if (!fault_cache) return -ENOMEM; =20 - init_group =3D user_event_group_create(&init_user_ns); + init_group =3D user_event_group_create(); =20 if (!init_group) { kmem_cache_destroy(fault_cache); --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 040C2EB64D9 for ; Thu, 15 Jun 2023 13:37:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344421AbjFONhE (ORCPT ); Thu, 15 Jun 2023 09:37:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344374AbjFONgV (ORCPT ); Thu, 15 Jun 2023 09:36:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E534358E for ; Thu, 15 Jun 2023 06:35:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DE6B863B6C for ; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBD5DC433C8; Thu, 15 Jun 2023 13:34:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7A-000TqK-2p; Thu, 15 Jun 2023 09:34:16 -0400 Message-ID: <20230615133416.688476874@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:41 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 10/15] tracing/user_events: Store register flags on events References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave Currently we don't have any available flags for user processes to use to indicate options for user_events. We will soon have a flag to indicate the event should or should not auto-delete once it's not being used by anyone. Add a reg_flags field to user_events and parameters to existing functions to allow for this in future patches. Link: https://lkml.kernel.org/r/20230614163336.5797-2-beaub@linux.microsoft= .com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index cf6d4c02c363..629823e21447 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -87,6 +87,7 @@ struct user_event { struct list_head validators; refcount_t refcnt; int min_size; + int reg_flags; char status; }; =20 @@ -165,7 +166,7 @@ typedef void (*user_event_func_t) (struct user_event *u= ser, struct iov_iter *i, =20 static int user_event_parse(struct user_event_group *group, char *name, char *args, char *flags, - struct user_event **newuser); + struct user_event **newuser, int reg_flags); =20 static struct user_event_mm *user_event_mm_get(struct user_event_mm *mm); static struct user_event_mm *user_event_mm_get_all(struct user_event *user= ); @@ -810,7 +811,8 @@ static struct list_head *user_event_get_fields(struct t= race_event_call *call) * Upon success user_event has its ref count increased by 1. */ static int user_event_parse_cmd(struct user_event_group *group, - char *raw_command, struct user_event **newuser) + char *raw_command, struct user_event **newuser, + int reg_flags) { char *name =3D raw_command; char *args =3D strpbrk(name, " "); @@ -824,7 +826,7 @@ static int user_event_parse_cmd(struct user_event_group= *group, if (flags) *flags++ =3D '\0'; =20 - return user_event_parse(group, name, args, flags, newuser); + return user_event_parse(group, name, args, flags, newuser, reg_flags); } =20 static int user_field_array_size(const char *type) @@ -1588,7 +1590,7 @@ static int user_event_create(const char *raw_command) =20 mutex_lock(&group->reg_mutex); =20 - ret =3D user_event_parse_cmd(group, name, &user); + ret =3D user_event_parse_cmd(group, name, &user, 0); =20 if (!ret) refcount_dec(&user->refcnt); @@ -1751,7 +1753,7 @@ static int user_event_trace_register(struct user_even= t *user) */ static int user_event_parse(struct user_event_group *group, char *name, char *args, char *flags, - struct user_event **newuser) + struct user_event **newuser, int reg_flags) { int ret; u32 key; @@ -1846,6 +1848,8 @@ static int user_event_parse(struct user_event_group *= group, char *name, if (ret) goto put_user_lock; =20 + user->reg_flags =3D reg_flags; + /* Ensure we track self ref and caller ref (2) */ refcount_set(&user->refcnt, 2); =20 @@ -2144,7 +2148,7 @@ static long user_events_ioctl_reg(struct user_event_f= ile_info *info, return ret; } =20 - ret =3D user_event_parse_cmd(info->group, name, &user); + ret =3D user_event_parse_cmd(info->group, name, &user, reg.flags); =20 if (ret) { kfree(name); --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B17CEB64D9 for ; Thu, 15 Jun 2023 13:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344424AbjFONgd (ORCPT ); Thu, 15 Jun 2023 09:36:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344132AbjFONfa (ORCPT ); Thu, 15 Jun 2023 09:35:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28432947 for ; Thu, 15 Jun 2023 06:34:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AB38E637EB for ; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24850C433C0; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7B-000Tqs-0F; Thu, 15 Jun 2023 09:34:17 -0400 Message-ID: <20230615133416.895403445@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:42 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 11/15] tracing/user_events: Track refcount consistently via put/get References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave Various parts of the code today track user_event's refcnt field directly via a refcount_add/dec. This makes it hard to modify the behavior of the last reference decrement in all code paths consistently. For example, in the future we will auto-delete events upon the last reference going away. This last reference could happen in many places, but we want it to be consistently handled. Add user_event_get() and user_event_put() for the add/dec. Update all places where direct refcounts are being used to utilize these new functions. In each location pass if event_mutex is locked or not. This allows us to drop events automatically in future patches clearly. Ensure when caller states the lock is held, it really is (or is not) held. Link: https://lkml.kernel.org/r/20230614163336.5797-3-beaub@linux.microsoft= .com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 69 +++++++++++++++++++------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index 629823e21447..c064458eea5c 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -177,6 +177,28 @@ static u32 user_event_key(char *name) return jhash(name, strlen(name), 0); } =20 +static struct user_event *user_event_get(struct user_event *user) +{ + refcount_inc(&user->refcnt); + + return user; +} + +static void user_event_put(struct user_event *user, bool locked) +{ +#ifdef CONFIG_LOCKDEP + if (locked) + lockdep_assert_held(&event_mutex); + else + lockdep_assert_not_held(&event_mutex); +#endif + + if (unlikely(!user)) + return; + + refcount_dec(&user->refcnt); +} + static void user_event_group_destroy(struct user_event_group *group) { kfree(group->system_name); @@ -228,12 +250,13 @@ static struct user_event_group *user_event_group_crea= te(void) return NULL; }; =20 -static void user_event_enabler_destroy(struct user_event_enabler *enabler) +static void user_event_enabler_destroy(struct user_event_enabler *enabler, + bool locked) { list_del_rcu(&enabler->mm_enablers_link); =20 /* No longer tracking the event via the enabler */ - refcount_dec(&enabler->event->refcnt); + user_event_put(enabler->event, locked); =20 kfree(enabler); } @@ -295,7 +318,7 @@ static void user_event_enabler_fault_fixup(struct work_= struct *work) =20 /* User asked for enabler to be removed during fault */ if (test_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(enabler))) { - user_event_enabler_destroy(enabler); + user_event_enabler_destroy(enabler, true); goto out; } =20 @@ -470,14 +493,12 @@ static bool user_event_enabler_dup(struct user_event_= enabler *orig, if (!enabler) return false; =20 - enabler->event =3D orig->event; + enabler->event =3D user_event_get(orig->event); enabler->addr =3D orig->addr; =20 /* Only dup part of value (ignore future flags, etc) */ enabler->values =3D orig->values & ENABLE_VAL_DUP_MASK; =20 - refcount_inc(&enabler->event->refcnt); - /* Enablers not exposed yet, RCU not required */ list_add(&enabler->mm_enablers_link, &mm->enablers); =20 @@ -594,7 +615,7 @@ static void user_event_mm_destroy(struct user_event_mm = *mm) struct user_event_enabler *enabler, *next; =20 list_for_each_entry_safe(enabler, next, &mm->enablers, mm_enablers_link) - user_event_enabler_destroy(enabler); + user_event_enabler_destroy(enabler, false); =20 mmdrop(mm->mm); kfree(mm); @@ -749,7 +770,7 @@ static struct user_event_enabler * exit or run exec(), which includes forks and clones. */ if (!*write_result) { - refcount_inc(&enabler->event->refcnt); + user_event_get(user); list_add_rcu(&enabler->mm_enablers_link, &user_mm->enablers); } =20 @@ -1337,10 +1358,8 @@ static struct user_event *find_user_event(struct use= r_event_group *group, *outkey =3D key; =20 hash_for_each_possible(group->register_table, user, node, key) - if (!strcmp(EVENT_NAME(user), name)) { - refcount_inc(&user->refcnt); - return user; - } + if (!strcmp(EVENT_NAME(user), name)) + return user_event_get(user); =20 return NULL; } @@ -1554,12 +1573,12 @@ static int user_event_reg(struct trace_event_call *= call, =20 return ret; inc: - refcount_inc(&user->refcnt); + user_event_get(user); update_enable_bit_for(user); return 0; dec: update_enable_bit_for(user); - refcount_dec(&user->refcnt); + user_event_put(user, true); return 0; } =20 @@ -1593,7 +1612,7 @@ static int user_event_create(const char *raw_command) ret =3D user_event_parse_cmd(group, name, &user, 0); =20 if (!ret) - refcount_dec(&user->refcnt); + user_event_put(user, false); =20 mutex_unlock(&group->reg_mutex); =20 @@ -1794,7 +1813,7 @@ static int user_event_parse(struct user_event_group *= group, char *name, =20 return 0; error: - refcount_dec(&user->refcnt); + user_event_put(user, false); return ret; } =20 @@ -1883,7 +1902,7 @@ static int delete_user_event(struct user_event_group = *group, char *name) if (!user) return -ENOENT; =20 - refcount_dec(&user->refcnt); + user_event_put(user, true); =20 if (!user_event_last_ref(user)) return -EBUSY; @@ -2042,9 +2061,7 @@ static int user_events_ref_add(struct user_event_file= _info *info, for (i =3D 0; i < count; ++i) new_refs->events[i] =3D refs->events[i]; =20 - new_refs->events[i] =3D user; - - refcount_inc(&user->refcnt); + new_refs->events[i] =3D user_event_get(user); =20 rcu_assign_pointer(info->refs, new_refs); =20 @@ -2158,7 +2175,7 @@ static long user_events_ioctl_reg(struct user_event_f= ile_info *info, ret =3D user_events_ref_add(info, user); =20 /* No longer need parse ref, ref_add either worked or not */ - refcount_dec(&user->refcnt); + user_event_put(user, false); =20 /* Positive number is index and valid */ if (ret < 0) @@ -2307,7 +2324,7 @@ static long user_events_ioctl_unreg(unsigned long uar= g) set_bit(ENABLE_VAL_FREEING_BIT, ENABLE_BITOPS(enabler)); =20 if (!test_bit(ENABLE_VAL_FAULTING_BIT, ENABLE_BITOPS(enabler))) - user_event_enabler_destroy(enabler); + user_event_enabler_destroy(enabler, true); =20 /* Removed at least one */ ret =3D 0; @@ -2365,7 +2382,6 @@ static int user_events_release(struct inode *node, st= ruct file *file) struct user_event_file_info *info =3D file->private_data; struct user_event_group *group; struct user_event_refs *refs; - struct user_event *user; int i; =20 if (!info) @@ -2389,12 +2405,9 @@ static int user_events_release(struct inode *node, s= truct file *file) * The underlying user_events are ref counted, and cannot be freed. * After this decrement, the user_events may be freed elsewhere. */ - for (i =3D 0; i < refs->count; ++i) { - user =3D refs->events[i]; + for (i =3D 0; i < refs->count; ++i) + user_event_put(refs->events[i], false); =20 - if (user) - refcount_dec(&user->refcnt); - } out: file->private_data =3D NULL; =20 --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1CA6EB64D9 for ; Thu, 15 Jun 2023 13:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344320AbjFONgp (ORCPT ); Thu, 15 Jun 2023 09:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344199AbjFONfe (ORCPT ); Thu, 15 Jun 2023 09:35:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F943586 for ; Thu, 15 Jun 2023 06:35:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DE6F463A1F for ; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49212C433C8; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7B-000TrS-0v; Thu, 15 Jun 2023 09:34:17 -0400 Message-ID: <20230615133417.099572277@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:43 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 12/15] tracing/user_events: Add auto cleanup and future persist flag References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave Currently user events need to be manually deleted via the delete IOCTL call or via the dynamic_events file. Most operators and processes wish to have these events auto cleanup when they are no longer used by anything to prevent them piling without manual maintenance. However, some operators may not want this, such as pre-registering events via the dynamic_events tracefs file. Update user_event_put() to attempt an auto delete of the event if it's the last reference. The auto delete must run in a work queue to ensure proper behavior of class->reg() invocations that don't expect the call to go away from underneath them during the unregister. Add work_struct to user_event struct to ensure we can do this reliably. Add a persist flag, that is not yet exposed, to ensure we can toggle between auto-cleanup and leaving the events existing in the future. When a non-zero flag is seen during register, return -EINVAL to ensure ABI is clear for the user processes while we work out the best approach for persistent events. Link: https://lkml.kernel.org/r/20230614163336.5797-4-beaub@linux.microsoft= .com Link: https://lore.kernel.org/linux-trace-kernel/20230518093600.3f119d68@ro= rschach.local.home/ Suggested-by: Steven Rostedt Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 139 ++++++++++++++++++++++++++++--- 1 file changed, 126 insertions(+), 13 deletions(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index c064458eea5c..8df0550415e7 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -49,6 +49,18 @@ #define EVENT_STATUS_PERF BIT(1) #define EVENT_STATUS_OTHER BIT(7) =20 +/* + * User register flags are not allowed yet, keep them here until we are + * ready to expose them out to the user ABI. + */ +enum user_reg_flag { + /* Event will not delete upon last reference closing */ + USER_EVENT_REG_PERSIST =3D 1U << 0, + + /* This value or above is currently non-ABI */ + USER_EVENT_REG_MAX =3D 1U << 1, +}; + /* * Stores the system name, tables, and locks for a group of events. This * allows isolation for events by various means. @@ -85,6 +97,7 @@ struct user_event { struct hlist_node node; struct list_head fields; struct list_head validators; + struct work_struct put_work; refcount_t refcnt; int min_size; int reg_flags; @@ -171,6 +184,7 @@ static int user_event_parse(struct user_event_group *gr= oup, char *name, static struct user_event_mm *user_event_mm_get(struct user_event_mm *mm); static struct user_event_mm *user_event_mm_get_all(struct user_event *user= ); static void user_event_mm_put(struct user_event_mm *mm); +static int destroy_user_event(struct user_event *user); =20 static u32 user_event_key(char *name) { @@ -184,19 +198,103 @@ static struct user_event *user_event_get(struct user= _event *user) return user; } =20 +static void delayed_destroy_user_event(struct work_struct *work) +{ + struct user_event *user =3D container_of( + work, struct user_event, put_work); + + mutex_lock(&event_mutex); + + if (!refcount_dec_and_test(&user->refcnt)) + goto out; + + if (destroy_user_event(user)) { + /* + * The only reason this would fail here is if we cannot + * update the visibility of the event. In this case the + * event stays in the hashtable, waiting for someone to + * attempt to delete it later. + */ + pr_warn("user_events: Unable to delete event\n"); + refcount_set(&user->refcnt, 1); + } +out: + mutex_unlock(&event_mutex); +} + static void user_event_put(struct user_event *user, bool locked) { -#ifdef CONFIG_LOCKDEP - if (locked) - lockdep_assert_held(&event_mutex); - else - lockdep_assert_not_held(&event_mutex); -#endif + bool delete; =20 if (unlikely(!user)) return; =20 - refcount_dec(&user->refcnt); + /* + * When the event is not enabled for auto-delete there will always + * be at least 1 reference to the event. During the event creation + * we initially set the refcnt to 2 to achieve this. In those cases + * the caller must acquire event_mutex and after decrement check if + * the refcnt is 1, meaning this is the last reference. When auto + * delete is enabled, there will only be 1 ref, IE: refcnt will be + * only set to 1 during creation to allow the below checks to go + * through upon the last put. The last put must always be done with + * the event mutex held. + */ + if (!locked) { + lockdep_assert_not_held(&event_mutex); + delete =3D refcount_dec_and_mutex_lock(&user->refcnt, &event_mutex); + } else { + lockdep_assert_held(&event_mutex); + delete =3D refcount_dec_and_test(&user->refcnt); + } + + if (!delete) + return; + + /* + * We now have the event_mutex in all cases, which ensures that + * no new references will be taken until event_mutex is released. + * New references come through find_user_event(), which requires + * the event_mutex to be held. + */ + + if (user->reg_flags & USER_EVENT_REG_PERSIST) { + /* We should not get here when persist flag is set */ + pr_alert("BUG: Auto-delete engaged on persistent event\n"); + goto out; + } + + /* + * Unfortunately we have to attempt the actual destroy in a work + * queue. This is because not all cases handle a trace_event_call + * being removed within the class->reg() operation for unregister. + */ + INIT_WORK(&user->put_work, delayed_destroy_user_event); + + /* + * Since the event is still in the hashtable, we have to re-inc + * the ref count to 1. This count will be decremented and checked + * in the work queue to ensure it's still the last ref. This is + * needed because a user-process could register the same event in + * between the time of event_mutex release and the work queue + * running the delayed destroy. If we removed the item now from + * the hashtable, this would result in a timing window where a + * user process would fail a register because the trace_event_call + * register would fail in the tracing layers. + */ + refcount_set(&user->refcnt, 1); + + if (WARN_ON_ONCE(!schedule_work(&user->put_work))) { + /* + * If we fail we must wait for an admin to attempt delete or + * another register/close of the event, whichever is first. + */ + pr_warn("user_events: Unable to queue delayed destroy\n"); + } +out: + /* Ensure if we didn't have event_mutex before we unlock it */ + if (!locked) + mutex_unlock(&event_mutex); } =20 static void user_event_group_destroy(struct user_event_group *group) @@ -793,7 +891,12 @@ static struct user_event_enabler static __always_inline __must_check bool user_event_last_ref(struct user_event *user) { - return refcount_read(&user->refcnt) =3D=3D 1; + int last =3D 0; + + if (user->reg_flags & USER_EVENT_REG_PERSIST) + last =3D 1; + + return refcount_read(&user->refcnt) =3D=3D last; } =20 static __always_inline __must_check @@ -1609,7 +1712,8 @@ static int user_event_create(const char *raw_command) =20 mutex_lock(&group->reg_mutex); =20 - ret =3D user_event_parse_cmd(group, name, &user, 0); + /* Dyn events persist, otherwise they would cleanup immediately */ + ret =3D user_event_parse_cmd(group, name, &user, USER_EVENT_REG_PERSIST); =20 if (!ret) user_event_put(user, false); @@ -1780,6 +1884,10 @@ static int user_event_parse(struct user_event_group = *group, char *name, int argc =3D 0; char **argv; =20 + /* User register flags are not ready yet */ + if (reg_flags !=3D 0 || flags !=3D NULL) + return -EINVAL; + /* Prevent dyn_event from racing */ mutex_lock(&event_mutex); user =3D find_user_event(group, name, &key); @@ -1869,8 +1977,13 @@ static int user_event_parse(struct user_event_group = *group, char *name, =20 user->reg_flags =3D reg_flags; =20 - /* Ensure we track self ref and caller ref (2) */ - refcount_set(&user->refcnt, 2); + if (user->reg_flags & USER_EVENT_REG_PERSIST) { + /* Ensure we track self ref and caller ref (2) */ + refcount_set(&user->refcnt, 2); + } else { + /* Ensure we track only caller ref (1) */ + refcount_set(&user->refcnt, 1); + } =20 dyn_event_init(&user->devent, &user_event_dops); dyn_event_add(&user->devent, &user->call); @@ -2092,8 +2205,8 @@ static long user_reg_get(struct user_reg __user *ureg= , struct user_reg *kreg) if (ret) return ret; =20 - /* Ensure no flags, since we don't support any yet */ - if (kreg->flags !=3D 0) + /* Ensure only valid flags */ + if (kreg->flags & ~(USER_EVENT_REG_MAX-1)) return -EINVAL; =20 /* Ensure supported size */ --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C05CFEB64DC for ; Thu, 15 Jun 2023 13:36:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344443AbjFONgl (ORCPT ); Thu, 15 Jun 2023 09:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344171AbjFONfb (ORCPT ); Thu, 15 Jun 2023 09:35:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B492729 for ; Thu, 15 Jun 2023 06:35:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EB8E86399E for ; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 684D8C433CA; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7B-000Ts1-1Z; Thu, 15 Jun 2023 09:34:17 -0400 Message-ID: <20230615133417.304604444@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:44 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 13/15] selftests/user_events: Ensure auto cleanup works as expected References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave User events now auto cleanup upon the last reference put. Update ftrace_test to ensure this works as expected. Ensure EBUSY delays while event is being deleted do not cause transient failures by waiting and re-attempting. Link: https://lkml.kernel.org/r/20230614163336.5797-5-beaub@linux.microsoft= .com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- .../selftests/user_events/ftrace_test.c | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/test= ing/selftests/user_events/ftrace_test.c index abfb49558a26..eb6904d89f14 100644 --- a/tools/testing/selftests/user_events/ftrace_test.c +++ b/tools/testing/selftests/user_events/ftrace_test.c @@ -102,30 +102,56 @@ static int get_print_fmt(char *buffer, int len) return -1; } =20 +static bool wait_for_delete(void) +{ + int i; + + for (i =3D 0; i < 1000; ++i) { + int fd =3D open(enable_file, O_RDONLY); + + if (fd =3D=3D -1) + return true; + + close(fd); + usleep(1000); + } + + return false; +} + static int clear(int *check) { struct user_unreg unreg =3D {0}; + int fd; =20 unreg.size =3D sizeof(unreg); unreg.disable_bit =3D 31; unreg.disable_addr =3D (__u64)check; =20 - int fd =3D open(data_file, O_RDWR); + fd =3D open(data_file, O_RDWR); =20 if (fd =3D=3D -1) return -1; =20 if (ioctl(fd, DIAG_IOCSUNREG, &unreg) =3D=3D -1) if (errno !=3D ENOENT) - return -1; - - if (ioctl(fd, DIAG_IOCSDEL, "__test_event") =3D=3D -1) - if (errno !=3D ENOENT) - return -1; + goto fail; + + if (ioctl(fd, DIAG_IOCSDEL, "__test_event") =3D=3D -1) { + if (errno =3D=3D EBUSY) { + if (!wait_for_delete()) + goto fail; + } else if (errno !=3D ENOENT) + goto fail; + } =20 close(fd); =20 return 0; +fail: + close(fd); + + return -1; } =20 static int check_print_fmt(const char *event, const char *expected, int *c= heck) @@ -155,9 +181,8 @@ static int check_print_fmt(const char *event, const cha= r *expected, int *check) /* Register should work */ ret =3D ioctl(fd, DIAG_IOCSREG, ®); =20 - close(fd); - if (ret !=3D 0) { + close(fd); printf("Reg failed in fmt\n"); return ret; } @@ -165,6 +190,8 @@ static int check_print_fmt(const char *event, const cha= r *expected, int *check) /* Ensure correct print_fmt */ ret =3D get_print_fmt(print_fmt, sizeof(print_fmt)); =20 + close(fd); + if (ret !=3D 0) return ret; =20 @@ -256,10 +283,10 @@ TEST_F(user, register_events) { unreg.disable_bit =3D 30; ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSUNREG, &unreg)); =20 - /* Delete should work only after close and unregister */ + /* Delete should have been auto-done after close and unregister */ close(self->data_fd); - self->data_fd =3D open(data_file, O_RDWR); - ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSDEL, "__test_event")); + + ASSERT_EQ(true, wait_for_delete()); } =20 TEST_F(user, write_events) { --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2478EEB64D9 for ; Thu, 15 Jun 2023 13:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232615AbjFONhL (ORCPT ); Thu, 15 Jun 2023 09:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344389AbjFONgX (ORCPT ); Thu, 15 Jun 2023 09:36:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0092D76 for ; Thu, 15 Jun 2023 06:35:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1BF6D63C87 for ; Thu, 15 Jun 2023 13:34:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8888AC43391; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7B-000Tsb-2D; Thu, 15 Jun 2023 09:34:17 -0400 Message-ID: <20230615133417.503900831@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:45 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 14/15] selftests/user_events: Adapt dyn_test to non-persist events References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave Now that user_events does not honor persist events the dynamic_events file cannot be easily used to test parsing and matching cases. Update dyn_test to use the direct ABI file instead of dynamic_events so that we still have testing coverage until persist events and dynamic_events file integration has been decided. Link: https://lkml.kernel.org/r/20230614163336.5797-6-beaub@linux.microsoft= .com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- .../testing/selftests/user_events/dyn_test.c | 177 ++++++++++++++---- 1 file changed, 136 insertions(+), 41 deletions(-) diff --git a/tools/testing/selftests/user_events/dyn_test.c b/tools/testing= /selftests/user_events/dyn_test.c index 8879a7b04c6a..d6979a48478f 100644 --- a/tools/testing/selftests/user_events/dyn_test.c +++ b/tools/testing/selftests/user_events/dyn_test.c @@ -16,42 +16,140 @@ =20 #include "../kselftest_harness.h" =20 -const char *dyn_file =3D "/sys/kernel/tracing/dynamic_events"; -const char *clear =3D "!u:__test_event"; +const char *abi_file =3D "/sys/kernel/tracing/user_events_data"; +const char *enable_file =3D "/sys/kernel/tracing/events/user_events/__test= _event/enable"; =20 -static int Append(const char *value) +static bool wait_for_delete(void) { - int fd =3D open(dyn_file, O_RDWR | O_APPEND); - int ret =3D write(fd, value, strlen(value)); + int i; + + for (i =3D 0; i < 1000; ++i) { + int fd =3D open(enable_file, O_RDONLY); + + if (fd =3D=3D -1) + return true; + + close(fd); + usleep(1000); + } + + return false; +} + +static int reg_event(int fd, int *check, int bit, const char *value) +{ + struct user_reg reg =3D {0}; + + reg.size =3D sizeof(reg); + reg.name_args =3D (__u64)value; + reg.enable_bit =3D bit; + reg.enable_addr =3D (__u64)check; + reg.enable_size =3D sizeof(*check); + + if (ioctl(fd, DIAG_IOCSREG, ®) =3D=3D -1) + return -1; + + return 0; +} + +static int unreg_event(int fd, int *check, int bit) +{ + struct user_unreg unreg =3D {0}; + + unreg.size =3D sizeof(unreg); + unreg.disable_bit =3D bit; + unreg.disable_addr =3D (__u64)check; + + return ioctl(fd, DIAG_IOCSUNREG, &unreg); +} + +static int parse(int *check, const char *value) +{ + int fd =3D open(abi_file, O_RDWR); + int ret; + + if (fd =3D=3D -1) + return -1; + + /* Until we have persist flags via dynamic events, use the base name */ + if (value[0] !=3D 'u' || value[1] !=3D ':') { + close(fd); + return -1; + } + + ret =3D reg_event(fd, check, 31, value + 2); + + if (ret !=3D -1) { + if (unreg_event(fd, check, 31) =3D=3D -1) + printf("WARN: Couldn't unreg event\n"); + } =20 close(fd); + return ret; } =20 -#define CLEAR() \ +static int check_match(int *check, const char *first, const char *second, = bool *match) +{ + int fd =3D open(abi_file, O_RDWR); + int ret =3D -1; + + if (fd =3D=3D -1) + return -1; + + if (reg_event(fd, check, 31, first) =3D=3D -1) + goto cleanup; + + if (reg_event(fd, check, 30, second) =3D=3D -1) { + if (errno =3D=3D EADDRINUSE) { + /* Name is in use, with different fields */ + *match =3D false; + ret =3D 0; + } + + goto cleanup; + } + + *match =3D true; + ret =3D 0; +cleanup: + unreg_event(fd, check, 31); + unreg_event(fd, check, 30); + + close(fd); + + wait_for_delete(); + + return ret; +} + +#define TEST_MATCH(x, y) \ do { \ - int ret =3D Append(clear); \ - if (ret =3D=3D -1) \ - ASSERT_EQ(ENOENT, errno); \ + bool match; \ + ASSERT_NE(-1, check_match(&self->check, x, y, &match)); \ + ASSERT_EQ(true, match); \ } while (0) =20 -#define TEST_PARSE(x) \ +#define TEST_NMATCH(x, y) \ do { \ - ASSERT_NE(-1, Append(x)); \ - CLEAR(); \ + bool match; \ + ASSERT_NE(-1, check_match(&self->check, x, y, &match)); \ + ASSERT_EQ(false, match); \ } while (0) =20 -#define TEST_NPARSE(x) ASSERT_EQ(-1, Append(x)) +#define TEST_PARSE(x) ASSERT_NE(-1, parse(&self->check, x)) + +#define TEST_NPARSE(x) ASSERT_EQ(-1, parse(&self->check, x)) =20 FIXTURE(user) { + int check; }; =20 FIXTURE_SETUP(user) { - CLEAR(); } =20 FIXTURE_TEARDOWN(user) { - CLEAR(); + wait_for_delete(); } =20 TEST_F(user, basic_types) { @@ -95,33 +193,30 @@ TEST_F(user, size_types) { TEST_NPARSE("u:__test_event char a 20"); } =20 -TEST_F(user, flags) { - /* Should work */ - TEST_PARSE("u:__test_event:BPF_ITER u32 a"); - /* Forward compat */ - TEST_PARSE("u:__test_event:BPF_ITER,FLAG_FUTURE u32 a"); -} - TEST_F(user, matching) { - /* Register */ - ASSERT_NE(-1, Append("u:__test_event struct custom a 20")); - /* Should not match */ - TEST_NPARSE("!u:__test_event struct custom b"); - /* Should match */ - TEST_PARSE("!u:__test_event struct custom a"); - /* Multi field reg */ - ASSERT_NE(-1, Append("u:__test_event u32 a; u32 b")); - /* Non matching cases */ - TEST_NPARSE("!u:__test_event u32 a"); - TEST_NPARSE("!u:__test_event u32 b"); - TEST_NPARSE("!u:__test_event u32 a; u32 "); - TEST_NPARSE("!u:__test_event u32 a; u32 a"); - /* Matching case */ - TEST_PARSE("!u:__test_event u32 a; u32 b"); - /* Register */ - ASSERT_NE(-1, Append("u:__test_event u32 a; u32 b")); - /* Ensure trailing semi-colon case */ - TEST_PARSE("!u:__test_event u32 a; u32 b;"); + /* Single name matches */ + TEST_MATCH("__test_event u32 a", + "__test_event u32 a"); + + /* Multiple names match */ + TEST_MATCH("__test_event u32 a; u32 b", + "__test_event u32 a; u32 b"); + + /* Multiple names match with dangling ; */ + TEST_MATCH("__test_event u32 a; u32 b", + "__test_event u32 a; u32 b;"); + + /* Single name doesn't match */ + TEST_NMATCH("__test_event u32 a", + "__test_event u32 b"); + + /* Multiple names don't match */ + TEST_NMATCH("__test_event u32 a; u32 b", + "__test_event u32 b; u32 a"); + + /* Types don't match */ + TEST_NMATCH("__test_event u64 a; u64 b", + "__test_event u32 a; u32 b"); } =20 int main(int argc, char **argv) --=20 2.39.2 From nobody Sat Feb 7 18:15:14 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE72AEB64D9 for ; Thu, 15 Jun 2023 13:36:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344432AbjFONgg (ORCPT ); Thu, 15 Jun 2023 09:36:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344169AbjFONfb (ORCPT ); Thu, 15 Jun 2023 09:35:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F9C22D4C for ; Thu, 15 Jun 2023 06:35:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E751263BBE for ; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C481CC433CD; Thu, 15 Jun 2023 13:34:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1q9n7B-000TtA-2s; Thu, 15 Jun 2023 09:34:17 -0400 Message-ID: <20230615133417.709819338@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 15 Jun 2023 09:05:46 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 15/15] tracing/user_events: Document auto-cleanup and remove dyn_event refs References: <20230615130531.200384328@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave Now user_events auto-cleanup upon the last reference by default. This makes it not possible to use the dynamics event file via tracefs. Document that auto-cleanup is enabled by default and remove the refernce to /sys/kernel/tracing/dynamic_events file to make this clear. Link: https://lkml.kernel.org/r/20230614163336.5797-7-beaub@linux.microsoft= .com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- Documentation/trace/user_events.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Documentation/trace/user_events.rst b/Documentation/trace/user= _events.rst index f79987e16cf4..e7b07313550a 100644 --- a/Documentation/trace/user_events.rst +++ b/Documentation/trace/user_events.rst @@ -14,10 +14,6 @@ Programs can view status of the events via /sys/kernel/tracing/user_events_status and can both register and write data out via /sys/kernel/tracing/user_events_data. =20 -Programs can also use /sys/kernel/tracing/dynamic_events to register and -delete user based events via the u: prefix. The format of the command to -dynamic_events is the same as the ioctl with the u: prefix applied. - Typically programs will register a set of events that they wish to expose = to tools that can read trace_events (such as ftrace and perf). The registrati= on process tells the kernel which address and bit to reflect if any tool has @@ -144,6 +140,9 @@ its name. Delete will only succeed if there are no refe= rences left to the event (in both user and kernel space). User programs should use a separate= file to request deletes than the one used for registration due to this. =20 +**NOTE:** By default events will auto-delete when there are no references = left +to the event. Flags in the future may change this logic. + Unregistering ------------- If after registering an event it is no longer wanted to be updated then it= can --=20 2.39.2