linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Jan Kara <jack@suse.cz>, Waiman Long <longman@redhat.com>,
	Ingo Molnar <mingo@kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: DEBUG_RWSEMS warning from thaw_super()
Date: Mon, 14 May 2018 15:16:24 +0300	[thread overview]
Message-ID: <CAOQ4uxjZAU=rKK3qFUZOp+=0EJ9j9BbMAUAwkAoN7kOCC4B8_Q@mail.gmail.com> (raw)
In-Reply-To: <20180514115149.GA8905@redhat.com>

On Mon, May 14, 2018 at 2:51 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> On 05/14, Amir Goldstein wrote:
>>
>> On Mon, May 14, 2018 at 12:50 PM, Jan Kara <jack@suse.cz> wrote:
>> > On Sun 13-05-18 18:04:04, Oleg Nesterov wrote:
>> >> On 05/13, Amir Goldstein wrote:
>> >> >
>> >> > Since kernel v4.17-rc1 and DEBUG_RWSEMS, I see the
>> >> > warning below after filesystem freeze/thaw.
>> >> >
>> >> > This is a case where one process acquires a bunch of rwsem
>> >> > and another process releases them.
>> >> >
>> >> > To convey this use case to lockdep, freeze_super() calls
>> >> > lockdep_sb_freeze_release() on exit and thaw_super()
>> >> > calls lockdep_sb_freeze_acquire() on entry.
>> >>
>> >> This was already discussed, but I forgot the result...
>> >>
>> >> So once again, why we can't simply update percpu_rwsem_acquire() ?
>> >> Or we can check CONFIG_RWSEM_SPIN_ON_OWNER to match percpu_rwsem_release(),
>> >> but CONFIG_DEBUG_RWSEMS explains the purpose better.
>> >
>> > Yeah, what you suggests seems reasonable to me. So feel free to add:
>> >
>> > Acked-by: Jan Kara <jack@suse.cz>
>> >
>>
>> How about this version? A bit more prudent and also addresses the
>> TODO in commit 55cc156505f2 ("percpu-rwsem: introduce
>> percpu_rwsem_release() and percpu_rwsem_acquire()")
>
> Well, to me this looks like unnecessary overcomplication...
>
> In any case the patch looks technically wrong, afaics
> rwsem_can_spin_on_owner() will crash if it hits owner == RWSEM_USER_OWNED.
>

Fair enough. I can drop RWSEM_USER_OWNED.
Do you think I should keep percpu_rwsem_{set,clear}_owner()
helpers?

Thanks,
Amir.

> Oleg.
>
>> diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
>> index b1f37a89e368..323d5ba6a60d 100644
>> --- a/include/linux/percpu-rwsem.h
>> +++ b/include/linux/percpu-rwsem.h
>> @@ -127,13 +127,16 @@ extern void percpu_free_rwsem(struct
>> percpu_rw_semaphore *);
>>  #define percpu_rwsem_assert_held(sem)                          \
>>         lockdep_assert_held(&(sem)->rw_sem)
>>
>> +extern void percpu_rwsem_set_user_owned(struct percpu_rw_semaphore *sem);
>> +extern void percpu_rwsem_set_owner(struct percpu_rw_semaphore *sem);
>> +
>>  static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem,
>>                                         bool read, unsigned long ip)
>>  {
>>         lock_release(&sem->rw_sem.dep_map, 1, ip);
>>  #ifdef CONFIG_RWSEM_SPIN_ON_OWNER
>>         if (!read)
>> -               sem->rw_sem.owner = NULL;
>> +               percpu_rwsem_set_user_owned(sem);
>>  #endif
>>  }
>>
>> @@ -141,6 +144,10 @@ static inline void percpu_rwsem_acquire(struct
>> percpu_rw_semaphore *sem,
>>                                         bool read, unsigned long ip)
>>  {
>>         lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip);
>> +#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
>> +       if (!read)
>> +               percpu_rwsem_set_owner(sem);
>> +#endif
>>  }
>>
>>  #endif
>> diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c
>> index 883cf1b92d90..afa65915541f 100644
>> --- a/kernel/locking/percpu-rwsem.c
>> +++ b/kernel/locking/percpu-rwsem.c
>> @@ -7,6 +7,8 @@
>>  #include <linux/sched.h>
>>  #include <linux/errno.h>
>>
>> +#include "rwsem.h"
>> +
>>  int __percpu_init_rwsem(struct percpu_rw_semaphore *sem,
>>                         const char *name, struct lock_class_key *rwsem_key)
>>  {
>> @@ -190,3 +192,17 @@ void percpu_up_write(struct percpu_rw_semaphore *sem)
>>         rcu_sync_exit(&sem->rss);
>>  }
>>  EXPORT_SYMBOL_GPL(percpu_up_write);
>> +
>> +void percpu_rwsem_set_user_owned(struct percpu_rw_semaphore *sem)
>> +{
>> +       DEBUG_RWSEMS_WARN_ON(sem->rw_sem.owner != current);
>> +       sem->rw_sem.owner = RWSEM_USER_OWNED;
>> +}
>> +EXPORT_SYMBOL_GPL(percpu_rwsem_set_user_owned);
>> +
>> +void percpu_rwsem_set_owner(struct percpu_rw_semaphore *sem)
>> +{
>> +       DEBUG_RWSEMS_WARN_ON(sem->rw_sem.owner != RWSEM_USER_OWNED);
>> +       sem->rw_sem.owner = current;
>> +}
>> +EXPORT_SYMBOL_GPL(percpu_rwsem_set_user_owned);
>> diff --git a/kernel/locking/rwsem.h b/kernel/locking/rwsem.h
>> index a17cba8d94bb..f686596ec033 100644
>> --- a/kernel/locking/rwsem.h
>> +++ b/kernel/locking/rwsem.h
>> @@ -11,10 +11,14 @@
>>   *  2) RWSEM_READER_OWNED
>>   *     - lock is currently or previously owned by readers (lock is free
>>   *       or not set by owner yet)
>> - *  3) Other non-zero value
>> + *  3) RWSEM_USER_OWNED
>> + *     - lock is currently owned by userspace (previously owned by writer
>> + *       and should be handed over to a new writer before being freed)
>> + *  4) Other non-zero value
>>   *     - a writer owns the lock
>>   */
>>  #define RWSEM_READER_OWNED     ((struct task_struct *)1UL)
>> +#define RWSEM_USER_OWNED       ((struct task_struct *)2UL)
>>
>>  #ifdef CONFIG_DEBUG_RWSEMS
>>  # define DEBUG_RWSEMS_WARN_ON(c)       DEBUG_LOCKS_WARN_ON(c)
>

      reply	other threads:[~2018-05-14 12:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-13 14:02 DEBUG_RWSEMS warning from thaw_super() Amir Goldstein
2018-05-13 16:04 ` Oleg Nesterov
2018-05-14  9:50   ` Jan Kara
2018-05-14 11:32     ` Amir Goldstein
2018-05-14 11:51       ` Oleg Nesterov
2018-05-14 12:16         ` Amir Goldstein [this message]

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='CAOQ4uxjZAU=rKK3qFUZOp+=0EJ9j9BbMAUAwkAoN7kOCC4B8_Q@mail.gmail.com' \
    --to=amir73il@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).