Skip to contentSkip to conversation

vdso_join_timens() question

PATCH Christian Brauner 2 participants 3 messages Jun 11, 2020 – Jun 12, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hey,

I'm about to finish a patch to add CLONE_NEWTIME support to setns(). Since setns() now allows to attach to a multiple namespaces at the same time I've also reworked it to be atomic (already upstream). Either all namespaces are switched or no namespace is switched. All namespaces basically now have a commit mode after which installation should ideally not fail anymore. That could work for CLONE_NEWTIME too, I think. The only blocker to this is vdso_join_timens() which can fail due to mmap_write_lock_killable().

Is it possible to change this to mmap_write_lock()? So sm like:

arch/x86/entry/vdso/vma.c +1 -2
index ea7c1f0b79df..5c5b4cc61fce 100644
@@ -144,8 +144,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
        struct mm_struct *mm = task->mm;
        struct vm_area_struct *vma;
 
-       if (mmap_write_lock_killable(mm))
-               return -EINTR;
+       mmap_write_lock(mm);
 
        for (vma = mm->mmap; vma; vma = vma->vm_next) {
                unsigned long size = vma->vm_end - vma->vm_start;

vdso_join_timens() is called in two places. Once during fork() and once during timens_install(). I would only need the mmap_write_lock() change for the latter. So alternatively we could have:

__vdso_join_timens_unlocked()

and then have/expose:

vdso_join_timens_fork()

{
        if (mmap_write_lock_killable(mm))
                return -EINTR;
	__vdso_join_timens_unlocked()
	mmap_write_unlock(mm);
}

and

vdso_join_timens_install()

{
        mmap_write_lock(mm);
	__vdso_join_timens_unlocked()
	mmap_write_unlock(mm);
}

Thanks!
Christian

#1 lore raw

Hi Christian,

Quoted 18 lines · Christian Brauner

Hey,

I'm about to finish a patch to add CLONE_NEWTIME support to setns(). Since setns() now allows to attach to a multiple namespaces at the same time I've also reworked it to be atomic (already upstream). Either all namespaces are switched or no namespace is switched. All namespaces basically now have a commit mode after which installation should ideally not fail anymore. That could work for CLONE_NEWTIME too, I think. The only blocker to this is vdso_join_timens() which can fail due to mmap_write_lock_killable().

Is it possible to change this to mmap_write_lock()? So sm like:

arch/x86/entry/vdso/vma.c +0 -0
index ea7c1f0b79df..5c5b4cc61fce 100644

arch/x86/entry/vdso/vma.c int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) · line 150

Quoted 9 lines
arch/x86/entry/vdso/vma.c +1 -2
@@ -144,8 +144,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
        struct mm_struct *mm = task->mm;
        struct vm_area_struct *vma;
 
-       if (mmap_write_lock_killable(mm))
-               return -EINTR;
+       mmap_write_lock(mm);
 
        for (vma = mm->mmap; vma; vma = vma->vm_next) {
                unsigned long size = vma->vm_end - vma->vm_start;

I think, it should be fine.

I'm thinking if it actually could be downgraded to mmap_read_lock().. Probably, write lock was being over-cautious.

Quoted 16 lines

vdso_join_timens() is called in two places. Once during fork() and once during timens_install(). I would only need the mmap_write_lock() change for the latter. So alternatively we could have:

__vdso_join_timens_unlocked()

and then have/expose:

vdso_join_timens_fork()

{
        if (mmap_write_lock_killable(mm))
                return -EINTR;
	__vdso_join_timens_unlocked()
	mmap_write_unlock(mm);
}
Quoted 8 lines

and

vdso_join_timens_install()

{
        mmap_write_lock(mm);
	__vdso_join_timens_unlocked()
	mmap_write_unlock(mm);
}

I think it's not needed. On fork() it's called on creation of new timens:

: if (nsproxy->time_ns == nsproxy->time_ns_for_children)
: return 0;

So the vdso_join_timens() is called on setns() or on creation of new namespace, which both are quite heavy operations themselves (in sense of locking).

Thanks,
Dmitry

#2 lore raw
Quoted 24 lines · Dmitry Safonov

Hi Christian,

Quoted 21 lines · Christian Brauner

Hey,

I'm about to finish a patch to add CLONE_NEWTIME support to setns(). Since setns() now allows to attach to a multiple namespaces at the same time I've also reworked it to be atomic (already upstream). Either all namespaces are switched or no namespace is switched. All namespaces basically now have a commit mode after which installation should ideally not fail anymore. That could work for CLONE_NEWTIME too, I think. The only blocker to this is vdso_join_timens() which can fail due to mmap_write_lock_killable().

Is it possible to change this to mmap_write_lock()? So sm like:

arch/x86/entry/vdso/vma.c +0 -0
index ea7c1f0b79df..5c5b4cc61fce 100644
@@ -144,8 +144,7 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns)
        struct mm_struct *mm = task->mm;
        struct vm_area_struct *vma;
 
Quoted 8 lines

arch/x86/entry/vdso/vma.c int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) · line 150

Quoted 6 lines
arch/x86/entry/vdso/vma.c +1 -2
-       if (mmap_write_lock_killable(mm))
-               return -EINTR;
+       mmap_write_lock(mm);
 
        for (vma = mm->mmap; vma; vma = vma->vm_next) {
                unsigned long size = vma->vm_end - vma->vm_start;

I think, it should be fine.

Great! :)

Quoted 3 lines

I'm thinking if it actually could be downgraded to mmap_read_lock().. Probably, write lock was being over-cautious.

Let's use mmap_write_lock() for now and revisit this later, I guess.

Quoted 26 lines
Quoted 17 lines

vdso_join_timens() is called in two places. Once during fork() and once during timens_install(). I would only need the mmap_write_lock() change for the latter. So alternatively we could have:

__vdso_join_timens_unlocked()

and then have/expose:

vdso_join_timens_fork()

{
        if (mmap_write_lock_killable(mm))
                return -EINTR;
	__vdso_join_timens_unlocked()
	mmap_write_unlock(mm);
}
Quoted 8 lines

and

vdso_join_timens_install()

{
        mmap_write_lock(mm);
	__vdso_join_timens_unlocked()
	mmap_write_unlock(mm);
}
Quoted 8 lines

I think it's not needed. On fork() it's called on creation of new timens:

: if (nsproxy->time_ns == nsproxy->time_ns_for_children)
: return 0;

So the vdso_join_timens() is called on setns() or on creation of new namespace, which both are quite heavy operations themselves (in sense of locking).

Ok, great. It'll like be the week after next until I can send the patchset for setns(<nsfd>/<pidfd>, CLONE_NEWTIME) out.

Thanks!
Christian