LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* DEBUG_RWSEMS warning from thaw_super()
@ 2018-05-13 14:02 Amir Goldstein
  2018-05-13 16:04 ` Oleg Nesterov
  0 siblings, 1 reply; 6+ messages in thread
From: Amir Goldstein @ 2018-05-13 14:02 UTC (permalink / raw)
  To: Waiman Long
  Cc: Ingo Molnar, linux-fsdevel, linux-kernel, Jan Kara,
	Oleg Nesterov, Al Viro

Hi Waiman,

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.

These annotations don't seem to have any effect on the
DEBUG_RWSEMS owner checks.

What do you think is the best way to resolve this issue?

Thanks,
Amir.

----------------------
root@kvm-xfstests:~# fsfreeze -f /vdf
root@kvm-xfstests:~# fsfreeze -u /vdf
[   20.302978] ------------[ cut here ]------------
[   20.305016] DEBUG_LOCKS_WARN_ON(sem->owner != get_current())
[   20.305029] WARNING: CPU: 1 PID: 1401 at
/home/amir/build/src/linux/kernel/locking/rwsem.c:133
up_write+0x59/0x79
[   20.311252] CPU: 1 PID: 1401 Comm: fsfreeze Not tainted
4.17.0-rc3-xfstests-00049-g39e47bf59eb3 #3276
[   20.314808] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014
[   20.318403] RIP: 0010:up_write+0x59/0x79
[   20.320928] RSP: 0018:ffffc90000717e48 EFLAGS: 00010286
[   20.322955] RAX: 0000000000000030 RBX: ffff880078f1c680 RCX: ffff880078e42200
[   20.325665] RDX: ffffffff810cc9c1 RSI: 0000000000000001 RDI: 0000000000000202
[   20.328844] RBP: ffffc90000717e80 R08: 0000000000000001 R09: 0000000000000001
[   20.332340] R10: ffffc90000717c58 R11: ffffffff836807ad R12: ffff880078f1c388
[   20.335095] R13: ffff880078a8b980 R14: 0000000000000000 R15: 00000000fffffff7
[   20.338009] FS:  00007fb61ca42700(0000) GS:ffff88007f400000(0000)
knlGS:0000000000000000
[   20.341423] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   20.343772] CR2: 00007fb61c559b30 CR3: 0000000078da6000 CR4: 00000000000006e0
[   20.346463] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[   20.349201] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[   20.351960] Call Trace:
[   20.352911]  percpu_up_write+0x1f/0x28
[   20.354344]  thaw_super_locked+0xdf/0x120
[   20.355944]  do_vfs_ioctl+0x270/0x5f1
[   20.357390]  ? __se_sys_newfstat+0x2e/0x39
[   20.358969]  ? entry_SYSCALL_64_after_hwframe+0x59/0xbe
[   20.360991]  ksys_ioctl+0x52/0x71
[   20.362384]  __x64_sys_ioctl+0x16/0x19
[   20.363702]  do_syscall_64+0x5d/0x167
[   20.365099]  entry_SYSCALL_64_after_hwframe+0x49/0xbe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: DEBUG_RWSEMS warning from thaw_super()
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2018-05-13 16:04 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Waiman Long, Ingo Molnar, linux-fsdevel, linux-kernel, Jan Kara, Al Viro

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.

Oleg.

--- x/include/linux/percpu-rwsem.h
+++ x/include/linux/percpu-rwsem.h
@@ -141,6 +141,10 @@ static inline void percpu_rwsem_acquire(
 					bool read, unsigned long ip)
 {
 	lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip);
+#ifdef CONFIG_DEBUG_RWSEMS
+	if (!read)
+		sem->rw_sem.owner = current;
+#endif
 }
 
 #endif

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: DEBUG_RWSEMS warning from thaw_super()
  2018-05-13 16:04 ` Oleg Nesterov
@ 2018-05-14  9:50   ` Jan Kara
  2018-05-14 11:32     ` Amir Goldstein
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2018-05-14  9:50 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Amir Goldstein, Waiman Long, Ingo Molnar, linux-fsdevel,
	linux-kernel, Jan Kara, Al Viro

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>
	
								Honza

> --- x/include/linux/percpu-rwsem.h
> +++ x/include/linux/percpu-rwsem.h
> @@ -141,6 +141,10 @@ static inline void percpu_rwsem_acquire(
>  					bool read, unsigned long ip)
>  {
>  	lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip);
> +#ifdef CONFIG_DEBUG_RWSEMS
> +	if (!read)
> +		sem->rw_sem.owner = current;
> +#endif
>  }
>  
>  #endif
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: DEBUG_RWSEMS warning from thaw_super()
  2018-05-14  9:50   ` Jan Kara
@ 2018-05-14 11:32     ` Amir Goldstein
  2018-05-14 11:51       ` Oleg Nesterov
  0 siblings, 1 reply; 6+ messages in thread
From: Amir Goldstein @ 2018-05-14 11:32 UTC (permalink / raw)
  To: Jan Kara
  Cc: Oleg Nesterov, Waiman Long, Ingo Molnar, linux-fsdevel,
	linux-kernel, Al Viro

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()")

Sorry for spaces instead of tabs, I'll re-post properly if this is acked.

Thanks,
Amir.

-----
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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: DEBUG_RWSEMS warning from thaw_super()
  2018-05-14 11:32     ` Amir Goldstein
@ 2018-05-14 11:51       ` Oleg Nesterov
  2018-05-14 12:16         ` Amir Goldstein
  0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2018-05-14 11:51 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Jan Kara, Waiman Long, Ingo Molnar, linux-fsdevel, linux-kernel, Al Viro

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.

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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: DEBUG_RWSEMS warning from thaw_super()
  2018-05-14 11:51       ` Oleg Nesterov
@ 2018-05-14 12:16         ` Amir Goldstein
  0 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2018-05-14 12:16 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Jan Kara, Waiman Long, Ingo Molnar, linux-fsdevel, linux-kernel, Al Viro

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)
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-05-14 12:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).