mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Lance Yang <ioworker0@gmail.com>
Cc: akpm@linux-foundation.org, zi.li@linux.dev,
	anna.schumaker@oracle.com, boqun.feng@gmail.com,
	joel.granados@kernel.org, jstultz@google.com,
	kent.overstreet@linux.dev, leonylgao@tencent.com,
	linux-kernel@vger.kernel.org, longman@redhat.com,
	mhiramat@kernel.org, mingo@redhat.com, mingzhe.yang@ly.com,
	peterz@infradead.org, rostedt@goodmis.org,
	senozhatsky@chromium.org, tfiga@chromium.org, will@kernel.org,
	Lance Yang <lance.yang@linux.dev>
Subject: Re: [PATCH RFC 1/3] locking/rwsem: make owner helpers globally available
Date: Tue, 24 Jun 2025 09:17:31 +0900	[thread overview]
Message-ID: <20250624091731.f4d3cf296943ce45e97a631f@kernel.org> (raw)
In-Reply-To: <20250612042005.99602-2-lance.yang@linux.dev>

On Thu, 12 Jun 2025 12:19:24 +0800
Lance Yang <ioworker0@gmail.com> wrote:

> From: Lance Yang <lance.yang@linux.dev>
> 
> In preparation for extending blocker tracking to support rwsems, make the
> rwsem_owner() and is_rwsem_reader_owned() helpers globally available for
> determining if the blocker is a writer or one of the readers.
> 

Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks!

> Signed-off-by: Lance Yang <lance.yang@linux.dev>
> ---
>  include/linux/rwsem.h  | 12 ++++++++++++
>  kernel/locking/rwsem.c |  8 +++++---
>  2 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
> index c8b543d428b0..544853bed5b9 100644
> --- a/include/linux/rwsem.h
> +++ b/include/linux/rwsem.h
> @@ -132,6 +132,18 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem)
>  	return !list_empty(&sem->wait_list);
>  }
>  
> +#if defined(CONFIG_DEBUG_RWSEMS) || defined(CONFIG_DETECT_HUNG_TASK_BLOCKER)
> +/*
> + * Return just the real task structure pointer of the owner
> + */
> +extern struct task_struct *rwsem_owner(struct rw_semaphore *sem);
> +
> +/*
> + * Return true if the rwsem is owned by a reader.
> + */
> +extern bool is_rwsem_reader_owned(struct rw_semaphore *sem);
> +#endif
> +
>  #else /* !CONFIG_PREEMPT_RT */
>  
>  #include <linux/rwbase_rt.h>
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 2ddb827e3bea..6cb29442d4fc 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -181,11 +181,11 @@ static inline void rwsem_set_reader_owned(struct rw_semaphore *sem)
>  	__rwsem_set_reader_owned(sem, current);
>  }
>  
> -#ifdef CONFIG_DEBUG_RWSEMS
> +#if defined(CONFIG_DEBUG_RWSEMS) || defined(CONFIG_DETECT_HUNG_TASK_BLOCKER)
>  /*
>   * Return just the real task structure pointer of the owner
>   */
> -static inline struct task_struct *rwsem_owner(struct rw_semaphore *sem)
> +struct task_struct *rwsem_owner(struct rw_semaphore *sem)
>  {
>  	return (struct task_struct *)
>  		(atomic_long_read(&sem->owner) & ~RWSEM_OWNER_FLAGS_MASK);
> @@ -194,7 +194,7 @@ static inline struct task_struct *rwsem_owner(struct rw_semaphore *sem)
>  /*
>   * Return true if the rwsem is owned by a reader.
>   */
> -static inline bool is_rwsem_reader_owned(struct rw_semaphore *sem)
> +bool is_rwsem_reader_owned(struct rw_semaphore *sem)
>  {
>  	/*
>  	 * Check the count to see if it is write-locked.
> @@ -205,7 +205,9 @@ static inline bool is_rwsem_reader_owned(struct rw_semaphore *sem)
>  		return false;
>  	return rwsem_test_oflags(sem, RWSEM_READER_OWNED);
>  }
> +#endif
>  
> +#ifdef CONFIG_DEBUG_RWSEMS
>  /*
>   * With CONFIG_DEBUG_RWSEMS configured, it will make sure that if there
>   * is a task pointer in owner of a reader-owned rwsem, it will be the
> -- 
> 2.49.0
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2025-06-24  0:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12  4:19 [PATCH RFC 0/3] extend hung task blocker tracking to rwsems Lance Yang
2025-06-12  4:19 ` [PATCH RFC 1/3] locking/rwsem: make owner helpers globally available Lance Yang
2025-06-24  0:17   ` Masami Hiramatsu [this message]
2025-06-24  1:35     ` Lance Yang
2025-06-12  4:19 ` [PATCH RFC 2/3] locking/rwsem: clear reader-owner on unlock to reduce false positives Lance Yang
2025-06-24  0:26   ` Masami Hiramatsu
2025-06-24  1:44     ` Lance Yang
2025-06-24  3:53       ` Masami Hiramatsu
2025-06-24  5:02         ` Lance Yang
2025-06-24  6:13           ` Masami Hiramatsu
2025-06-24  7:38             ` Lance Yang
2025-06-12  4:19 ` [PATCH RFC 3/3] hung_task: extend hung task blocker tracking to rwsems Lance Yang
2025-06-24  3:57   ` Masami Hiramatsu
2025-06-24  4:25     ` Lance Yang
2025-06-23 12:33 ` [PATCH RFC 0/3] " Lance Yang

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=20250624091731.f4d3cf296943ce45e97a631f@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=anna.schumaker@oracle.com \
    --cc=boqun.feng@gmail.com \
    --cc=ioworker0@gmail.com \
    --cc=joel.granados@kernel.org \
    --cc=jstultz@google.com \
    --cc=kent.overstreet@linux.dev \
    --cc=lance.yang@linux.dev \
    --cc=leonylgao@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=mingzhe.yang@ly.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=tfiga@chromium.org \
    --cc=will@kernel.org \
    --cc=zi.li@linux.dev \
    /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®