On Wed, 2020-10-07 at 00:54 +0200, Jann Horn wrote: > Until now, the mmap lock of the nascent mm was ordered inside the mmap lock > of the old mm (in dup_mmap() and in UML's activate_mm()). > A following patch will change the exec path to very broadly lock the > nascent mm, but fine-grained locking should still work at the same time for > the old mm. > > In particular, mmap locking calls are hidden behind the copy_from_user() > calls and such that are reached through functions like copy_strings() - > when a page fault occurs on a userspace memory access, the mmap lock > will be taken. > > To do this in a way that lockdep is happy about, let's turn around the lock > ordering in both places that currently nest the locks. > Since SINGLE_DEPTH_NESTING is normally used for the inner nesting layer, > make up our own lock subclass MMAP_LOCK_SUBCLASS_NASCENT and use that > instead. > > The added locking calls in exec_mmap() are temporary; the following patch > will move the locking out of exec_mmap(). > > Signed-off-by: Jann Horn <jannh@xxxxxxxxxx> > --- > arch/um/include/asm/mmu_context.h | 3 +-- > fs/exec.c | 4 ++++ > include/linux/mmap_lock.h | 23 +++++++++++++++++++++-- > kernel/fork.c | 7 ++----- > 4 files changed, 28 insertions(+), 9 deletions(-) > > diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h > index 17ddd4edf875..c13bc5150607 100644 > --- a/arch/um/include/asm/mmu_context.h > +++ b/arch/um/include/asm/mmu_context.h > @@ -48,9 +48,8 @@ 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); > - mmap_write_lock_nested(new, SINGLE_DEPTH_NESTING); > + mmap_assert_write_locked(new); > uml_setup_stubs(new); > - mmap_write_unlock(new); > } FWIW, this was I believe causing lockdep issues. I think I had previously determined that this was pointless, since it's still nascent and cannot be used yet? But I didn't really know for sure, and this patch was never applied: https://patchwork.ozlabs.org/project/linux-um/patch/20200604133752.397dedea0758.I7a24aaa26794eb3fa432003c1bf55cbb816489e2@changeid/ I guess your patches will also fix the lockdep complaints in UML in this area, I hope I'll be able to test it soon. johannes