unshare: Cleanup up the sys_unshare interface before we are committed.
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
[I seem to have had a send problem with the previous version of this message, so this is a slightly modified resend]
Linus,
Quoted 9 lines · Andrew Morton
Quoted 5 lines
iirc there was some discussion about this and it was explicitly decided to keep the CLONE flags.
Maybe Janak or Linus can comment?
My personal opinion is that having a different set of flags is more confusing
How is it confusing? And who is it confusing for?
It will potentially require kernel developers to think for just a moment about what is going on. But why care about them -- they don't have to *use* this interface; userland programmers do.
I have tried to argue in the clearest way I can that the current interface (uschare(CLONE_*) is confusing for *users* of this API. Do you care about the interface that is inflicted on users?
When you give users an interface with the same name, they expect it to do the same thing. When their expectations are broken, they write bugs. There are already precedents, with much less justification, for defining separate flag names for different interfaces. For example, poll() uses constants with names of the form POLL*, while epoll uses constant with *EXACTLY* the same meanings, but named EPOLL*.
Quoted 2 lines
and likely to result in problems later than having the same ones.
What problems do you think can occur? And what happens on the day when unshare() needs a flag that clone() does not have?
Quoted 1 line
Regardless, I'm not touching this for 2.6.16 any more,
By which time, the discussion is over. Since "we don't break userspace", we can't (shouldn't) reverse whatever goes into 2.6.16.
Cheers,
Michael
Signature · 8 lines
Michael Kerrisk maintainer of Linux man pages Sections 2, 3, 4, 5, and 7 Want to help with man page maintenance? Grab the latest tarball at ftp://ftp.win.tue.nl/pub/linux-local/manpages/, read the HOWTOHELP file and grep the source files for 'FIXME'.
Quoted 5 lines · Michael Kerrisk
Quoted 3 lines
My personal opinion is that having a different set of flags is more confusing
How is it confusing? And who is it confusing for?
It's confusing because
- it's just more flags to keep track of
- it's all the same issues that clone() has
- it's an opportunity for future incoherence
Quoted 3 lines
It will potentially require kernel developers to think for just a moment about what is going on. But why care about them -- they don't have to *use* this interface; userland programmers do.
All the confusion is equally a userland issue, don't try to just enforce your own opinions as somehow being "facts" by repeating them over and over again.
Linus
Linus,
Quoted 9 lines · Michael Kerrisk
Quoted 5 lines
Quoted 3 lines
My personal opinion is that having a different set of flags is more confusing
How is it confusing? And who is it confusing for?
It's confusing because
- it's just more flags to keep track of
Agreed, there is a "confusion cost" to that.
Quoted 1 line
- it's all the same issues that
clone()has
At the moment, but possibly not in the future (if one day usnhare() needs a flag that has no analogue in clone()).
Quoted 1 line
- it's an opportunity for future incoherence
Not sure what future incoherence you mean here. Anyway, we inject some incoherence *now* (some unshare() flags reverse their clone() counterparts, one does not).
Quoted 7 lines
Quoted 3 lines
It will potentially require kernel developers to think for just a moment about what is going on. But why care about them -- they don't have to *use* this interface; userland programmers do.
All the confusion is equally a userland issue, don't try to just enforce your own opinions as somehow being "facts" by repeating them over and over again.
I'm not trying to do that. I've repeated my statements because I haven't seen any clear counterarguments. I have a particular opinion about what constitutes confusion, and it comes from a perspective that focuses on the kernel-userland interface. I agree that it does create some "confusion cost" for userland programmers to add new flags. But _in my opinion_ that cost is outweighed by the greater "confusion costs" that I have described. Eric seemed to agree. Unfortunately for my argument, you and Janak don't ;-).
Cheers,
Michael
Signature · 8 lines
Michael Kerrisk maintainer of Linux man pages Sections 2, 3, 4, 5, and 7 Want to help with man page maintenance? Grab the latest tarball at ftp://ftp.win.tue.nl/pub/linux-local/manpages/, read the HOWTOHELP file and grep the source files for 'FIXME'.
Quoted 5 lines · Michael Kerrisk
Quoted 2 lines
- it's all the same issues that
clone()hasAt the moment, but possibly not in the future (if one day
usnhare()needs a flag that has no analogue inclone()).
I don't believe that.
If we have something we might want to unshare, that implies by definition that it was something we wanted to conditionally share in the first place.
IOW, it ends up being something that would be a clone() flag.
So I really do believe that there is a fundamental 1:1 between the flags. They aren't just "similar". They are very fundamentally about the same thing, and giving two different names to the same thing is CONFUSING.
Linus
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Michael Kerrisk
Quoted 2 lines
- it's all the same issues that
clone()hasAt the moment, but possibly not in the future (if one day
usnhare()needs a flag that has no analogue inclone()).I don't believe that.
Quoted 8 lines
If we have something we might want to unshare, that implies by definition that it was something we wanted to conditionally share in the first place.
IOW, it ends up being something that would be a
clone()flag.So I really do believe that there is a fundamental 1:1 between the flags. They aren't just "similar". They are very fundamentally about the same thing, and giving two different names to the same thing is CONFUSING.
The scary thing is that with only 7 things we can share or not, and a 32bit field we have only 7 bits left that we can define. Last count I think I know of at least that many additional global namespaces in the kernel.
On the confusing side. Unshare largely because it doesn't default to unsharing all of the thread state. Has the weird issue that unshare will automatically add bits you didn't ask for (so it can satisfy your request) and unsharing more than you requested. Clone when presented with the same situation returns an error.
So even while the resources are the same the interaction of the bits really is quite different between the two calls.
Eric
Quoted 31 lines · Eric W. Biederman
Quoted 10 lines · Linus Torvalds
Quoted 7 lines · Michael Kerrisk
Quoted 3 lines
- it's all the same issues that
clone()hasAt the moment, but possibly not in the future (if one day
usnhare()needs a flag that has no analogue inclone()).Quoted 9 lines
I don't believe that.
If we have something we might want to unshare, that implies by definition that it was something we wanted to conditionally share in the first place.
IOW, it ends up being something that would be a
clone()flag.So I really do believe that there is a fundamental 1:1 between the flags. They aren't just "similar". They are very fundamentally about the same thing, and giving two different names to the same thing is CONFUSING.
The scary thing is that with only 7 things we can share or not, and a 32bit field we have only 7 bits left that we can define. Last count I think I know of at least that many additional global namespaces in the kernel.
Quoted 7 lines
On the confusing side. Unshare largely because it doesn't default to unsharing all of the thread state. Has the weird issue that unshare will automatically add bits you didn't ask for (so it can satisfy your request) and unsharing more than you requested. Clone when presented with the same situation returns an error.
We are probably digressing from the original discussion but just wanted to point out that the situations presented to clone and unshare are a bit different. Clone returns an error because in the same call you are trying to provide illegal combination of flags. Like saying that you want a new namespace but want to share the filesystem. There is no way for clone to know which of the two flags to honor or ignore. Where as with unshare if you are trying to unshare namespace but are currently sharing filesystem, then it is possible to complete the request by unsharing filesystem as well . You may remember that the earlier incarnation of the unshare patch did return an error. However it was pointed out, and correctly so, that it is better to unshare appropriate related contexts.
-Janak
Quoted 12 lines
So even while the resources are the same the interaction of the bits really is quite different between the two calls.
Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Linus,
Quoted 7 lines · Michael Kerrisk
Quoted 5 lines
Quoted 2 lines
- it's all the same issues that
clone()hasAt the moment, but possibly not in the future (if one day
usnhare()needs a flag that has no analogue inclone()).
Quoted 7 lines
I don't believe that.
If we have something we might want to unshare, that implies by definition that it was something we wanted to conditionally share in the first place.
IOW, it ends up being something that would be a
clone()flag.
I should have been a little clearer. I was thinking of some orthogonal flag that would change the operation of unshare() itself (i.e., not some resource that was unshared, but something that changes how unshare() goes about its job). It would not make sense to call such a flag CLONE_xxx.
Quoted 3 lines
So I really do believe that there is a fundamental 1:1 between the flags. They aren't just "similar". They are very fundamentally about the same thing, and giving two different names to the same thing is CONFUSING.
This is your viewpoint ;-). Actually, it cuts through to the crux of the matter:
The existing flags are *about* the same fundamental things, but they *treat* those things in subtly different ways.
I believe that sentence summarises how our viewpoints differ, and explains why you think the names should be the *same*, while I think they should better be just *similar*.
As I said in an earlier message, when I wrote my test program I found myself getting confused about how CLONE_NEWNS worked, even though I had just drafted a manual page that clearly told me that CLONE_NEWNS did not reverse the clone() of the same name. I was CONFUSED. (That's a "fact" ;-).)
Maybe that is just a demonstration of the obvious: I'm not the sharpest tack in the box. But my feeling is that part of my confusion *arose from the naming of the flags*, and some others will be like me. This is my belief about the two possible alternatives:
a) Flags with names that are *similar but not the same* (CLONE_* vs UNSHARE_*) will give userland programmers what I think is the right clue about the reality: these flags are working with the same things, but treating them somewhat differently.
b) The flags have the *same* names. This will lead *some* programmers into thinking that the correspondence between the flags is *exact*. But that is not so.
I believe that the first possibility is less likely to lead to traps (bugs) based on false understanding. It also fits better with the possibility of a hypothetical "orthogonal unshare() flag".
Of course, I can construct a counterargument: some programmers will be smarter than me, and the ones who are like me will at least have my manual page to help them avoid trouble. Nevertheless, my gut feel is that the status quo is an example of weak user interface design which could bear improvement.
Cheers,
Michael
Signature · 8 lines
Michael Kerrisk maintainer of Linux man pages Sections 2, 3, 4, 5, and 7 Want to help with man page maintenance? Grab the latest tarball at ftp://ftp.win.tue.nl/pub/linux-local/manpages/, read the HOWTOHELP file and grep the source files for 'FIXME'.
Quoted 12 lines · Linus Torvalds
Quoted 5 lines · Michael Kerrisk
Quoted 2 lines
- it's all the same issues that
clone()hasAt the moment, but possibly not in the future (if one day
usnhare()needs a flag that has no analogue inclone()).I don't believe that.
If we have something we might want to unshare, that implies by definition that it was something we wanted to conditionally share in the first place.
Quoted 7 lines
IOW, it ends up being something that would be a
clone()flag.So I really do believe that there is a fundamental 1:1 between the flags. They aren't just "similar". They are very fundamentally about the same thing, and giving two different names to the same thing is CONFUSING.
Linus
Was there ever a good reason why we decided to flip the sense of the bits?
I put a together a patch to see what the code would look like:
- We actually can reuse between clone and unshare.
- We don't need the confusing case of when to add additional resources to unshare.
- There is less total code.
- We don't confuse users and developers about the inverted values of the clone bits.
kernel/fork.c | 105 ++++++++++++++++++++++++--------------------------------- 1 files changed, 45 insertions(+), 60 deletions(-)
28e4502c6d2ca48e0b4a08581123b2c3cf94454e
kernel/fork.c +45 -60
@@ -900,6 +900,36 @@ asmlinkage long sys_set_tid_address(int }/* +* Check constraints on flags passed to the clone or unshare system call. +*/ +static int check_clone_flags (unsigned long clone_flags) +{ +int err = -EINVAL ; +if ((clone_flags & (CLONE_NEWNS |CLONE_FS )) == (CLONE_NEWNS |CLONE_FS )) + goto out; + +/* +* Thread groups must share signals as well, and detached threads +* can only be started up within the thread group. +*/ +if ((clone_flags &CLONE_THREAD ) && !(clone_flags &CLONE_SIGHAND )) + goto out; + +/* +* Shared signal handlers imply shared VM. By way of the above, +* thread groups also imply shared VM. Blocking this case allows +* for various simplifications in other code. +*/ +if ((clone_flags &CLONE_SIGHAND ) && !(clone_flags &CLONE_VM )) + goto out; + +/* We made it here without problems */ + err =0 ; +out: +return err; +} + +/* * This creates a new process as a copy of the old one, * but does not actually start it yet. *
@@ -918,23 +948,9 @@ static task_t *copy_process(unsigned lonint retval;struct task_struct *p =NULL ; -if ((clone_flags & (CLONE_NEWNS |CLONE_FS )) == (CLONE_NEWNS |CLONE_FS )) -return ERR_PTR (-EINVAL ); - -/* -* Thread groups must share signals as well, and detached threads -* can only be started up within the thread group. -*/ -if ((clone_flags &CLONE_THREAD ) && !(clone_flags &CLONE_SIGHAND )) -return ERR_PTR (-EINVAL ); - -/* -* Shared signal handlers imply shared VM. By way of the above, -* thread groups also imply shared VM. Blocking this case allows -* for various simplifications in other code. -*/ -if ((clone_flags &CLONE_SIGHAND ) && !(clone_flags &CLONE_VM )) -return ERR_PTR (-EINVAL ); + retval =check_clone_flags (clone_flags); +if (retval) +return ERR_PTR (retval); retval =security_task_create (clone_flags);if (retval)
@@ -1371,47 +1387,12 @@ void __init proc_caches_init(void) SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); } - -/* -* Check constraints on flags passed to the unshare system call and -* force unsharing of additional process context as appropriate. -*/ -static inline void check_unshare_flags (unsigned long *flags_ptr) -{ -/* -* If unsharing a thread from a thread group, must also -* unshare vm. -*/ -if (*flags_ptr &CLONE_THREAD ) - *flags_ptr |=CLONE_VM ; - -/* -* If unsharing vm, must also unshare signal handlers. -*/ -if (*flags_ptr &CLONE_VM ) - *flags_ptr |=CLONE_SIGHAND ; - -/* -* If unsharing signal handlers and the task was created -* using CLONE_THREAD, then must unshare the thread -*/ -if ((*flags_ptr &CLONE_SIGHAND ) && - (atomic_read (¤t->signal->count) >1 )) - *flags_ptr |=CLONE_THREAD ; - -/* -* If unsharing namespace, must also unshare filesystem information. -*/ -if (*flags_ptr &CLONE_NEWNS ) - *flags_ptr |=CLONE_FS ; -} -/* * Unsharing of tasks created with CLONE_THREAD is not supported yet */ static int unshare_thread (unsigned long unshare_flags) { -if (unshare_flags &CLONE_THREAD ) +if (!(unshare_flags &CLONE_THREAD ) && !thread_group_empty (current))return -EINVAL ;return 0 ;
@@ -1424,7 +1405,7 @@ static int unshare_fs(unsigned long unsh {struct fs_struct *fs = current->fs; -if ((unshare_flags &CLONE_FS ) && +if (!(unshare_flags &CLONE_FS ) && (fs &&atomic_read (&fs->count) >1 )) { *new_fsp =__copy_fs_struct (current->fs);if (!*new_fsp)
@@ -1441,7 +1422,7 @@ static int unshare_namespace(unsigned lo {struct namespace *ns = current->namespace; -if ((unshare_flags &CLONE_NEWNS ) && +if (!(unshare_flags &CLONE_NEWNS ) && (ns &&atomic_read (&ns->count) >1 )) {if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
@@ -1462,7 +1443,7 @@ static int unshare_sighand(unsigned long {struct sighand_struct *sigh = current->sighand; -if ((unshare_flags &CLONE_SIGHAND ) && +if (!(unshare_flags &CLONE_SIGHAND ) && (sigh &&atomic_read (&sigh->count) >1 ))return -EINVAL ;else
@@ -1476,7 +1457,7 @@ static int unshare_vm(unsigned long unsh {struct mm_struct *mm = current->mm; -if ((unshare_flags &CLONE_VM ) && +if (!(unshare_flags &CLONE_VM ) && (mm &&atomic_read (&mm->mm_users) >1 )) { *new_mmp =dup_mm (current);if (!*new_mmp)
@@ -1494,7 +1475,7 @@ static int unshare_fd(unsigned long unshstruct files_struct *fd = current->files;int error =0 ; -if ((unshare_flags &CLONE_FILES ) && +if (!(unshare_flags &CLONE_FILES ) && (fd &&atomic_read (&fd->count) >1 )) { *new_fdp =dup_fd (fd, &error);if (!*new_fdp)
@@ -1510,7 +1491,9 @@ static int unshare_fd(unsigned long unsh*/ static int unshare_semundo (unsigned long unshare_flags,struct sem_undo_list **new_ulistp) { -if (unshare_flags &CLONE_SYSVSEM ) +struct sem_undo_list *undo_list = current->sysvsem.undo_list; +if (!(unshare_flags &CLONE_SYSVSEM ) && + undo_list && (atomic_read (&undo_list->refcnt) >1 ))return -EINVAL ;return 0 ;
@@ -1534,7 +1517,9 @@ asmlinkage long sys_unshare(unsigned lonstruct files_struct *fd, *new_fd =NULL ;struct sem_undo_list *new_ulist =NULL ; -check_unshare_flags (&unshare_flags); + err =check_clone_flags (unshare_flags); +if (err) + goto bad_unshare_out;/* Return -EINVAL for all unsupported flags */ err = -EINVAL ;
Quoted 29 lines · Eric W. Biederman
Quoted 12 lines · Linus Torvalds
Quoted 7 lines · Michael Kerrisk
Quoted 3 lines
- it's all the same issues that
clone()hasAt the moment, but possibly not in the future (if one day
usnhare()needs a flag that has no analogue inclone()).I don't believe that.
Quoted 9 lines
If we have something we might want to unshare, that implies by definition that it was something we wanted to conditionally share in the first place.
IOW, it ends up being something that would be a
clone()flag.So I really do believe that there is a fundamental 1:1 between the flags. They aren't just "similar". They are very fundamentally about the same thing, and giving two different names to the same thing is CONFUSING.
Linus
Was there ever a good reason why we decided to flip the sense of the bits?
Quoted 10 lines
I put a together a patch to see what the code would look like:
- We actually can reuse between clone and unshare.
- We don't need the confusing case of when to add additional resources to unshare.
- There is less total code.
- We don't confuse users and developers about the inverted values of the clone bits.
I guess confusion is subjective. With this patch if I want to unshare files and leave the rest as is, I would have to call
unshare(CLONE_VM | CLONE_FS | CLONE_SIGHAND | ...)
That is, to unshare one type of context, I have to remember and use flags corresponding to all other contexts. If I forget to include one of them, I might unwittingly unshare it. Unless I am reading the patch incorrectly, this to me is more confusing than the current scheme.
-Janak
Quoted 197 lines
kernel/fork.c| 105 ++++++++++++++++++++++++---------------------------------1 files changed, 45 insertions(+), 60 deletions(-)
28e4502c6d2ca48e0b4a08581123b2c3cf94454ekernel/fork.c +45
-61@@ -900,6 +900,36 @@ asmlinkage long sys_set_tid_address(int }/* +* Check constraints on flags passed to the clone or unshare system call. +*/ +static int check_clone_flags (unsigned long clone_flags) +{ +int err = -EINVAL ; +if ((clone_flags & (CLONE_NEWNS |CLONE_FS )) == (CLONE_NEWNS |CLONE_FS )) + goto out; + +/* +* Thread groups must share signals as well, and detached threads +* can only be started up within the thread group. +*/ +if ((clone_flags &CLONE_THREAD ) && !(clone_flags &CLONE_SIGHAND )) + goto out; + +/* +* Shared signal handlers imply shared VM. By way of the above, +* thread groups also imply shared VM. Blocking this case allows +* for various simplifications in other code. +*/ +if ((clone_flags &CLONE_SIGHAND ) && !(clone_flags &CLONE_VM )) + goto out; + +/* We made it here without problems */ + err =0 ; +out: +return err; +} + +/* * This creates a new process as a copy of the old one, * but does not actually start it yet. * @@ -918,23 +948,9 @@ static task_t *copy_process(unsigned lonint retval;struct task_struct *p =NULL ; -if ((clone_flags & (CLONE_NEWNS |CLONE_FS )) == (CLONE_NEWNS |CLONE_FS )) -return ERR_PTR (-EINVAL ); - -/* -* Thread groups must share signals as well, and detached threads -* can only be started up within the thread group. -*/ -if ((clone_flags &CLONE_THREAD ) && !(clone_flags &CLONE_SIGHAND )) -return ERR_PTR (-EINVAL ); - -/* -* Shared signal handlers imply shared VM. By way of the above, -* thread groups also imply shared VM. Blocking this case allows -* for various simplifications in other code. -*/ -if ((clone_flags &CLONE_SIGHAND ) && !(clone_flags &CLONE_VM )) -return ERR_PTR (-EINVAL ); + retval =check_clone_flags (clone_flags); +if (retval) +return ERR_PTR (retval); retval =security_task_create (clone_flags);if (retval)@@ -1371,47 +1387,12 @@ void __init proc_caches_init(void) SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); } - -/* -* Check constraints on flags passed to the unshare system call and -* force unsharing of additional process context as appropriate. -*/ -static inline void check_unshare_flags (unsigned long *flags_ptr) -{ -/* -* If unsharing a thread from a thread group, must also -* unshare vm. -*/ -if (*flags_ptr &CLONE_THREAD ) - *flags_ptr |=CLONE_VM ; - -/* -* If unsharing vm, must also unshare signal handlers. -*/ -if (*flags_ptr &CLONE_VM ) - *flags_ptr |=CLONE_SIGHAND ; - -/* -* If unsharing signal handlers and the task was created -* using CLONE_THREAD, then must unshare the thread -*/ -if ((*flags_ptr &CLONE_SIGHAND ) && - (atomic_read (¤t->signal->count) >1 )) - *flags_ptr |=CLONE_THREAD ; - -/* -* If unsharing namespace, must also unshare filesystem information. -*/ -if (*flags_ptr &CLONE_NEWNS ) - *flags_ptr |=CLONE_FS ; -} -/* * Unsharing of tasks created with CLONE_THREAD is not supported yet */ static int unshare_thread (unsigned long unshare_flags) { -if (unshare_flags &CLONE_THREAD ) +if (!(unshare_flags &CLONE_THREAD ) && !thread_group_empty (current))return -EINVAL ;return 0 ;@@ -1424,7 +1405,7 @@ static int unshare_fs(unsigned long unsh {struct fs_struct *fs = current->fs; -if ((unshare_flags &CLONE_FS ) && +if (!(unshare_flags &CLONE_FS ) && (fs &&atomic_read (&fs->count) >1 )) { *new_fsp =__copy_fs_struct (current->fs);if (!*new_fsp)@@ -1441,7 +1422,7 @@ static int unshare_namespace(unsigned lo {struct namespace *ns = current->namespace; -if ((unshare_flags &CLONE_NEWNS ) && +if (!(unshare_flags &CLONE_NEWNS ) && (ns &&atomic_read (&ns->count) >1 )) {if (!capable (CAP_SYS_ADMIN ))return -EPERM ;@@ -1462,7 +1443,7 @@ static int unshare_sighand(unsigned long {struct sighand_struct *sigh = current->sighand; -if ((unshare_flags &CLONE_SIGHAND ) && +if (!(unshare_flags &CLONE_SIGHAND ) && (sigh &&atomic_read (&sigh->count) >1 ))return -EINVAL ;else @@ -1476,7 +1457,7 @@ static int unshare_vm(unsigned long unsh {struct mm_struct *mm = current->mm; -if ((unshare_flags &CLONE_VM ) && +if (!(unshare_flags &CLONE_VM ) && (mm &&atomic_read (&mm->mm_users) >1 )) { *new_mmp =dup_mm (current);if (!*new_mmp)@@ -1494,7 +1475,7 @@ static int unshare_fd(unsigned long unshstruct files_struct *fd = current->files;int error =0 ; -if ((unshare_flags &CLONE_FILES ) && +if (!(unshare_flags &CLONE_FILES ) && (fd &&atomic_read (&fd->count) >1 )) { *new_fdp =dup_fd (fd, &error);if (!*new_fdp)@@ -1510,7 +1491,9 @@ static int unshare_fd(unsigned long unsh*/ static int unshare_semundo (unsigned long unshare_flags,struct sem_undo_list **new_ulistp) { -if (unshare_flags &CLONE_SYSVSEM ) +struct sem_undo_list *undo_list = current->sysvsem.undo_list; +if (!(unshare_flags &CLONE_SYSVSEM ) && + undo_list && (atomic_read (&undo_list->refcnt) >1 ))return -EINVAL ;return 0 ;@@ -1534,7 +1517,9 @@ asmlinkage long sys_unshare(unsigned lonstruct files_struct *fd, *new_fd =NULL ;struct sem_undo_list *new_ulist =NULL ; -check_unshare_flags (&unshare_flags); + err =check_clone_flags (unshare_flags); +if (err) + goto bad_unshare_out;/* Return -EINVAL for all unsupported flags */ err = -EINVAL ; -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 15 lines · Janak Desai
Quoted 13 lines · Eric W. Biederman
Was there ever a good reason why we decided to flip the sense of the bits?
I put a together a patch to see what the code would look like:
- We actually can reuse between clone and unshare.
- We don't need the confusing case of when to add additional resources to unshare.
- There is less total code.
- We don't confuse users and developers about the inverted values of the clone bits.
Quoted 4 lines
I guess confusion is subjective. With this patch if I want to unshare files and leave the rest as is, I would have to call
unshare(CLONE_VM | CLONE_FS | CLONE_SIGHAND | ...)
Yes. In my patch unshare(0) unshares all resources that a fork won't share.
Does anyone use unshare on threads?
My corresponding objection with the current interface is that it appears to be an implementation of "Do what I mean". Whenever you do more than is asked for you run into trouble.
Quoted 4 lines
That is, to unshare one type of context, I have to remember and use flags corresponding to all other contexts. If I forget to include one of them, I might unwittingly unshare it. Unless I am reading the patch incorrectly, this to me is more confusing than the current scheme.
Not exactly. unshare(CLONE_NEWNS) does not need any additional flags and I believe it is the primary case of interest.
Beyond that for any version of unshare to be predictable you need to know what you have shared and what you don't. Which means either another syscall or a /proc file that will give you that information.
Personally I think being unthreaded is easier to work with than the existing rule of everything necessary to unshare the specified resources. Especially since I can be explicit and tell it to leaves things the way they are.
With a query interface mine becomes unshare(get_shared() & ~CLONE_FILES). Which is the normal paradigm for modifying something expressed as flags.
With the current kernel implementation I can't see how calling unshare(CLONE_NEWNS) is any less surprising when called in a user space thread. Without a deep understanding of the kernel I don't see how you can predict that will unshare your current filesystem root and cwd pointers.
My rule that you stop being a thread I think is a little easier to remember if not understand. Who would suspect that in the current kernel unshare(CLONE_THREAD) does not completely unshare all of the resources that a thread shares?
Anyway I think unshare needs to carry a big fat:
WARNING dangerous when used with threads be very very careful!
Unfortunately that isn't something I can think of a general test for right now. Which makes using unshare in a library fairly dangerous.
Eric
Quoted 2 lines · Eric W. Biederman
- We don't confuse users and developers about the inverted values of the clone bits.
Given that the name starts with "un", I would *expect* unshare(CLONE_FOO) to mean that I no longer want to share FOO.
If you want the argument to have the same sense as in the clone system call, you will have to call it "share" rather than "unshare" (and then explain to confused developers why they can't use it to start sharing things that previously weren't shared :).
Paul.