mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Yanfei Xu <yanfei.xu@windriver.com>
Cc: mingo@redhat.com, will@kernel.org, longman@redhat.com,
	boqun.feng@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] locking/rwsem: disable preemption for spinning region
Date: Fri, 15 Oct 2021 12:13:59 +0200	[thread overview]
Message-ID: <YWlUZ5BlUZRA7LGR@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20211013134154.1085649-3-yanfei.xu@windriver.com>

On Wed, Oct 13, 2021 at 09:41:53PM +0800, Yanfei Xu wrote:
> The spinning region rwsem_spin_on_owner() should not be preempted,
> however the rwsem_down_write_slowpath() invokes it and don't disable
> preemption. Fix it by adding a pair of preempt_disable/enable().

I'm thinking we should do this patch before #1, otherwise we have a
single patch window where we'll trigger the assertion, no?

> 
> Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
> ---
>  kernel/locking/rwsem.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 7b5af452ace2..06925b43c3e7 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -1024,6 +1024,7 @@ rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
>  	enum writer_wait_state wstate;
>  	struct rwsem_waiter waiter;
>  	struct rw_semaphore *ret = sem;
> +	enum owner_state owner_state;
>  	DEFINE_WAKE_Q(wake_q);
>  
>  	/* do optimistic spinning and steal lock if possible */
> @@ -1099,9 +1100,13 @@ rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
>  		 * In this case, we attempt to acquire the lock again
>  		 * without sleeping.
>  		 */
> -		if (wstate == WRITER_HANDOFF &&
> -		    rwsem_spin_on_owner(sem) == OWNER_NULL)
> -			goto trylock_again;
> +		if (wstate == WRITER_HANDOFF) {
> +			preempt_disable();
> +			owner_state = rwsem_spin_on_owner(sem);
> +			preempt_enable();
> +			if (owner_state == OWNER_NULL)
> +				goto trylock_again;
> +		}
>  
>  		/* Block until there are no active lockers. */
>  		for (;;) {
> -- 
> 2.27.0
> 

  reply	other threads:[~2021-10-15 10:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-13 13:41 [PATCH V2 0/3] misc patches for mutex and rwsem Yanfei Xu
2021-10-13 13:41 ` [PATCH V2 1/3] locking: remove rcu_read_lock/unlock as we already disabled preemption Yanfei Xu
2021-10-19 15:35   ` [tip: locking/core] locking: Remove rcu_read_{,un}lock() for preempt_{dis,en}able() tip-bot2 for Yanfei Xu
2021-10-13 13:41 ` [PATCH v2 2/3] locking/rwsem: disable preemption for spinning region Yanfei Xu
2021-10-15 10:13   ` Peter Zijlstra [this message]
2021-10-15 10:20     ` Peter Zijlstra
2021-10-15 12:33       ` Xu, Yanfei
2021-10-19 15:35   ` [tip: locking/core] locking/rwsem: Disable " tip-bot2 for Yanfei Xu
2021-10-13 13:41 ` [PATCH V2 3/3] locking/rwsem: fix comments about reader optimistic lock stealing conditions Yanfei Xu
2021-10-19 15:35   ` [tip: locking/core] locking/rwsem: Fix " tip-bot2 for Yanfei Xu
2021-10-13 21:08 ` [PATCH V2 0/3] misc patches for mutex and rwsem Waiman Long

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=YWlUZ5BlUZRA7LGR@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=will@kernel.org \
    --cc=yanfei.xu@windriver.com \
    /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®