mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Jeff Barnes <jeffbarnes@linux.microsoft.com>
Cc: mhiramat@kernel.org, shuah@kernel.org,
	mathieu.desnoyers@efficios.com, reddybalavignesh9979@gmail.com,
	richard.weiyang@gmail.com, michael.bommarito@gmail.com,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 2/3] tracing/user_events: Share event state with existing threads
Date: Mon, 23 Nov 2026 16:56:32 -0500	[thread overview]
Message-ID: <20261123165632.2c8ee68c@gandalf.local.home> (raw)
In-Reply-To: <20261006164720.3940272-3-jeffbarnes@linux.microsoft.com>

On Tue,  6 Oct 2026 12:47:19 -0400
Jeff Barnes <jeffbarnes@linux.microsoft.com> wrote:

>  static void user_event_mm_attach(struct user_event_mm *user_mm, struct task_struct *t)
>  {
>  	unsigned long flags;
> @@ -817,14 +831,18 @@ void user_event_mm_remove(struct task_struct *t)
>  	might_sleep();
>  
>  	mm = t->user_event_mm;
> +
> +	spin_lock_irqsave(&user_event_mms_lock, flags);
> +
>  	t->user_event_mm = NULL;
>  
> -	/* Clone will increment the tasks, only remove if last clone */
> -	if (!refcount_dec_and_test(&mm->tasks))
> +	/* Clones and attached tasks increment this count. */
> +	if (!refcount_dec_and_test(&mm->tasks)) {
> +		spin_unlock_irqrestore(&user_event_mms_lock, flags);
>  		return;
> +	}
>  
> -	/* Remove the mm from the list, so it can no longer be enabled */
> -	spin_lock_irqsave(&user_event_mms_lock, flags);
> +	/* Prevent new tasks from attaching after the last-task transition. */
>  	list_del_rcu(&mm->mms_link);
>  	spin_unlock_irqrestore(&user_event_mms_lock, flags);


Actually the above can be written better as:

@@ -832,26 +832,22 @@ static void delayed_user_event_mm_put(struct work_struct *work)
 void user_event_mm_remove(struct task_struct *t)
 {
 	struct user_event_mm *mm;
-	unsigned long flags;
 
 	might_sleep();
 
 	mm = t->user_event_mm;
 
-	spin_lock_irqsave(&user_event_mms_lock, flags);
+	scoped_guard(spinlock_irqsave, &user_event_mms_lock) {
+		t->user_event_mm = NULL;
 
-	t->user_event_mm = NULL;
+		/* Clones and attached tasks increment this count. */
+		if (!refcount_dec_and_test(&mm->tasks))
+			return;
 
-	/* Clones and attached tasks increment this count. */
-	if (!refcount_dec_and_test(&mm->tasks)) {
-		spin_unlock_irqrestore(&user_event_mms_lock, flags);
-		return;
+		/* Prevent new tasks from attaching after the last-task transition. */
+		list_del_rcu(&mm->mms_link);
 	}
 
-	/* Prevent new tasks from attaching after the last-task transition. */
-	list_del_rcu(&mm->mms_link);
-	spin_unlock_irqrestore(&user_event_mms_lock, flags);
-
 	/*
 	 * We need to wait for currently occurring writes to stop within
 	 * the mm. This is required since exit_mm() snaps the current rss
>  
> @@ -894,11 +912,25 @@ static bool
>  current_user_event_enabler_exists(struct user_event_group *group,
>  				  unsigned long uaddr, unsigned char bit)
>  {
> -	struct user_event_mm *user_mm = current_user_event_mm();
> +	struct user_event_mm *user_mm = current->user_event_mm;
> +	unsigned long flags;
>  	bool exists;
>  
>  	lockdep_assert_held(&group->reg_mutex);
>  
> +	if (!user_mm) {
> +		spin_lock_irqsave(&user_event_mms_lock, flags);
> +
> +		user_mm = user_event_mm_find_locked(current->mm);
> +
> +		if (user_mm) {
> +			refcount_inc(&user_mm->tasks);
> +			current->user_event_mm = user_mm;
> +		}
> +
> +		spin_unlock_irqrestore(&user_event_mms_lock, flags);
> +	}

and this with:

@@ -919,22 +915,17 @@ current_user_event_enabler_exists(struct user_event_group *group,
 				  unsigned long uaddr, unsigned char bit)
 {
 	struct user_event_mm *user_mm = current->user_event_mm;
-	unsigned long flags;
 	bool exists;
 
 	lockdep_assert_held(&group->reg_mutex);
 
 	if (!user_mm) {
-		spin_lock_irqsave(&user_event_mms_lock, flags);
-
+		guard(spinlock_irqsave)(&user_event_mms_lock);
 		user_mm = user_event_mm_find_locked(current->mm);
-
 		if (user_mm) {
 			refcount_inc(&user_mm->tasks);
 			current->user_event_mm = user_mm;
 		}
-
-		spin_unlock_irqrestore(&user_event_mms_lock, flags);
 	}
 
 	if (!user_mm)

-- Steve

> +
>  	if (!user_mm)
>  		return false;
>  
> @@ -906,8 +938,6 @@ current_user_event_enabler_exists(struct user_event_group *group,
>  	exists = user_event_enabler_exists(user_mm, uaddr, bit);
>  	mutex_unlock(&event_mutex);
>  
> -	user_event_mm_put(user_mm);
> -
>  	return exists;
>  }
>  


  reply	other threads:[~2026-11-23 21:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 15:39 [PATCH 0/2] tracing/user_events: Share state between " Jeff Barnes
2026-10-02 15:39 ` [PATCH 1/2] selftests/user_events: Test registration from " Jeff Barnes
2026-10-02 15:39 ` [PATCH 2/2] tracing/user_events: Share tracing state between " Jeff Barnes
2026-10-06 16:47 ` [PATCH v2 0/3] tracing/user_events: Share state with " Jeff Barnes
2026-10-06 16:47   ` [PATCH v2 1/3] tracing/user_events: Serialize duplicate enabler lookup with event removal Jeff Barnes
2026-10-06 16:47   ` [PATCH v2 2/3] tracing/user_events: Share event state with existing threads Jeff Barnes
2026-11-23 21:56     ` Steven Rostedt [this message]
2026-10-06 16:47   ` [PATCH v2 3/3] selftests/user_events: Test registration from " Jeff Barnes
2026-10-19 14:23   ` [PATCH v2 0/3] tracing/user_events: Share state with " Jeff Barnes
2026-10-19 14:39     ` Steven Rostedt
2026-11-10 22:50       ` Jeff Barnes
2026-11-12  9:25         ` Steven Rostedt
2026-11-16 22:27           ` Beau Belgrave

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123165632.2c8ee68c@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=jeffbarnes@linux.microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=michael.bommarito@gmail.com \
    --cc=reddybalavignesh9979@gmail.com \
    --cc=richard.weiyang@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®