Re: [PATCH 5/8] mmap locking API: convert nested write lock sites
From: Matthew Wilcox
Date: Thu Mar 26 2020 - 08:09:37 EST
On Thu, Mar 26, 2020 at 12:02:33AM -0700, Michel Lespinasse wrote:
> @@ -47,9 +48,9 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
> * when the new ->mm is used for the first time.
> */
> __switch_mm(&new->context.id);
> - down_write_nested(&new->mmap_sem, 1);
> + mmap_write_lock_nested(new, 1);
> uml_setup_stubs(new);
> - mmap_write_unlock(new);
> + mmap_write_unlock_nested(new);
This is a bit of an oddity. We don't usually have an unlock_nested()
variant (a quick grep finds only something complicated in reiserfs).
That's because it's legitimate to release locks in a different order from
the one they were acquired in (eg lock A, lock B, unlock A, unlock B), and
it's not clear whether "nested" would follow the lock (ie unlock_nested B)
or whether it would follow the code (ie unlock_nested A).
Does your future API require knowing the nested nature at the unlock
point? And if so, does it require it for A or B in the above scenario?
And how does it mix with lock A or B being of a different type (eg a
plain mutex or a spinlock)?