* [PATCH rc1-mm 2/3] coredump: shutdown current process first
@ 2006-04-09 0:11 Oleg Nesterov
2006-04-10 7:08 ` Roland McGrath
2006-06-09 17:24 ` [PATCH] 2.6.17-rc4 bugfix with initramfs Nickolay
0 siblings, 2 replies; 8+ messages in thread
From: Oleg Nesterov @ 2006-04-09 0:11 UTC (permalink / raw)
To: linux-kernel
Cc: Eric W. Biederman, Ingo Molnar, Paul E. McKenney, Roland McGrath,
Andrew Morton, Lee Revell
This patch optimize zap_threads() for the case when there are
no ->mm users except the current's thread group. In that case
we can avoid 'for_each_process()' loop.
It also adds a useful invariant: SIGNAL_GROUP_EXIT (if checked
under ->siglock) always implies that all threads (except may be
current) have pending SIGKILL.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- MM/fs/exec.c~2_optmz 2006-04-09 02:33:28.000000000 +0400
+++ MM/fs/exec.c 2006-04-09 03:06:43.000000000 +0400
@@ -1383,13 +1383,7 @@ static void format_corename(char *corena
static void zap_process(struct task_struct *start)
{
struct task_struct *t;
- unsigned long flags;
- /*
- * start->sighand can't disappear, but may be
- * changed by de_thread()
- */
- lock_task_sighand(start, &flags);
start->signal->flags = SIGNAL_GROUP_EXIT;
start->signal->group_stop_count = 0;
@@ -1401,40 +1395,51 @@ static void zap_process(struct task_stru
signal_wake_up(t, 1);
}
} while ((t = next_thread(t)) != start);
-
- unlock_task_sighand(start, &flags);
}
static inline int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
int exit_code)
{
struct task_struct *g, *p;
+ unsigned long flags;
int err = -EAGAIN;
spin_lock_irq(&tsk->sighand->siglock);
if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT)) {
- tsk->signal->flags = SIGNAL_GROUP_EXIT;
tsk->signal->group_exit_code = exit_code;
- tsk->signal->group_stop_count = 0;
+ zap_process(tsk);
err = 0;
}
spin_unlock_irq(&tsk->sighand->siglock);
if (err)
return err;
+ if (atomic_read(&mm->mm_users) == mm->core_waiters + 1)
+ goto done;
+
rcu_read_lock();
for_each_process(g) {
+ if (g == tsk->group_leader)
+ continue;
+
p = g;
do {
if (p->mm) {
- if (p->mm == mm)
+ if (p->mm == mm) {
+ /*
+ * p->sighand can't disappear, but
+ * may be changed by de_thread()
+ */
+ lock_task_sighand(p, &flags);
zap_process(p);
+ unlock_task_sighand(p, &flags);
+ }
break;
}
} while ((p = next_thread(p)) != g);
}
rcu_read_unlock();
-
+done:
return mm->core_waiters;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rc1-mm 2/3] coredump: shutdown current process first
2006-04-09 0:11 [PATCH rc1-mm 2/3] coredump: shutdown current process first Oleg Nesterov
@ 2006-04-10 7:08 ` Roland McGrath
2006-04-10 14:01 ` Oleg Nesterov
2006-06-09 17:24 ` [PATCH] 2.6.17-rc4 bugfix with initramfs Nickolay
1 sibling, 1 reply; 8+ messages in thread
From: Roland McGrath @ 2006-04-10 7:08 UTC (permalink / raw)
To: Oleg Nesterov
Cc: linux-kernel, Eric W. Biederman, Ingo Molnar, Paul E. McKenney,
Andrew Morton, Lee Revell
> This patch optimize zap_threads() for the case when there are
> no ->mm users except the current's thread group. In that case
> we can avoid 'for_each_process()' loop.
This is a very good optimization. Please don't use a goto here when a
simple if block and some reindenting works just fine.
I would be inclined to restructure the inner loop something like this:
p = g;
while (unlikely(p->mm == NULL)) {
p = next_thread(p);
if (p == g)
break;
}
if (p->mm == mm) {
/*
* p->sighand can't disappear, but
* may be changed by de_thread()
*/
lock_task_sighand(p, &flags);
zap_process(p);
unlock_task_sighand(p, &flags);
}
But that is just taste.
> It also adds a useful invariant: SIGNAL_GROUP_EXIT (if checked
> under ->siglock) always implies that all threads (except may be
> current) have pending SIGKILL.
I agree that's a sensible thing to be able to rely on (though I don't know
of a practical difference it makes atm). If this is merged with by
SIGNAL_GROUP_EXEC change, then the invariant is that SIGNAL_GROUP_EXIT
always means that all threads (including current) either have pending
SIGKILL or are already calling do_group_exit/do_exit.
Thanks,
Roland
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rc1-mm 2/3] coredump: shutdown current process first
2006-04-10 7:08 ` Roland McGrath
@ 2006-04-10 14:01 ` Oleg Nesterov
2006-04-14 8:04 ` Eric W. Biederman
0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2006-04-10 14:01 UTC (permalink / raw)
To: Roland McGrath
Cc: linux-kernel, Eric W. Biederman, Ingo Molnar, Paul E. McKenney,
Andrew Morton, Lee Revell
On 04/10, Roland McGrath wrote:
>
> I would be inclined to restructure the inner loop something like this:
>
> p = g;
> while (unlikely(p->mm == NULL)) {
> p = next_thread(p);
> if (p == g)
> break;
> }
> if (p->mm == mm) {
> /*
> * p->sighand can't disappear, but
> * may be changed by de_thread()
> */
> lock_task_sighand(p, &flags);
> zap_process(p);
> unlock_task_sighand(p, &flags);
> }
Yes, I agree, this is much more understandable.
Oleg.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rc1-mm 2/3] coredump: shutdown current process first
2006-04-10 14:01 ` Oleg Nesterov
@ 2006-04-14 8:04 ` Eric W. Biederman
2006-04-14 15:33 ` Oleg Nesterov
0 siblings, 1 reply; 8+ messages in thread
From: Eric W. Biederman @ 2006-04-14 8:04 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Roland McGrath, linux-kernel, Ingo Molnar, Paul E. McKenney,
Andrew Morton, Lee Revell
Oleg Nesterov <oleg@tv-sign.ru> writes:
> On 04/10, Roland McGrath wrote:
>>
>> I would be inclined to restructure the inner loop something like this:
>>
>> p = g;
>> while (unlikely(p->mm == NULL)) {
>> p = next_thread(p);
>> if (p == g)
>> break;
>> }
>> if (p->mm == mm) {
>> /*
>> * p->sighand can't disappear, but
>> * may be changed by de_thread()
>> */
>> lock_task_sighand(p, &flags);
>> zap_process(p);
>> unlock_task_sighand(p, &flags);
>> }
>
> Yes, I agree, this is much more understandable.
There is one piece of zap_threads that still makes me uncomfortable.
task_lock is used to protect p->mm.
Therefore killing a process based upon p->mm == mm is racy
with respect to sys_unshare I believe if we don't take
task_lock.
Eric
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rc1-mm 2/3] coredump: shutdown current process first
2006-04-14 8:04 ` Eric W. Biederman
@ 2006-04-14 15:33 ` Oleg Nesterov
2006-04-14 17:02 ` Eric W. Biederman
0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2006-04-14 15:33 UTC (permalink / raw)
To: Eric W. Biederman
Cc: Roland McGrath, linux-kernel, Ingo Molnar, Paul E. McKenney,
Andrew Morton, Lee Revell
On 04/14, Eric W. Biederman wrote:
>
> Oleg Nesterov <oleg@tv-sign.ru> writes:
>
> > On 04/10, Roland McGrath wrote:
> >>
> >> I would be inclined to restructure the inner loop something like this:
> >>
> >> p = g;
> >> while (unlikely(p->mm == NULL)) {
> >> p = next_thread(p);
> >> if (p == g)
> >> break;
> >> }
> >> if (p->mm == mm) {
> >> /*
> >> * p->sighand can't disappear, but
> >> * may be changed by de_thread()
> >> */
> >> lock_task_sighand(p, &flags);
> >> zap_process(p);
> >> unlock_task_sighand(p, &flags);
> >> }
> >
> > Yes, I agree, this is much more understandable.
>
> There is one piece of zap_threads that still makes me uncomfortable.
>
> task_lock is used to protect p->mm.
> Therefore killing a process based upon p->mm == mm is racy
> with respect to sys_unshare I believe if we don't take
> task_lock.
Well, unshare(CLONE_VM) is not yet supported. Currently (as I see
it) mm->mmap_sem is enough to protect against changing ->mm. Yes,
exit_mm/exec_mmap take task_lock too, so it can be used as well.
Please correct my understanding.
I think it is better to take ->mmap_sem in sys_unshare, this path
is rare.
Oleg.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH rc1-mm 2/3] coredump: shutdown current process first
2006-04-14 15:33 ` Oleg Nesterov
@ 2006-04-14 17:02 ` Eric W. Biederman
0 siblings, 0 replies; 8+ messages in thread
From: Eric W. Biederman @ 2006-04-14 17:02 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Roland McGrath, linux-kernel, Ingo Molnar, Paul E. McKenney,
Andrew Morton, Lee Revell
Oleg Nesterov <oleg@tv-sign.ru> writes:
> On 04/14, Eric W. Biederman wrote:
>>
>> Oleg Nesterov <oleg@tv-sign.ru> writes:
>>
>> > On 04/10, Roland McGrath wrote:
>> >>
>> >> I would be inclined to restructure the inner loop something like this:
>> >>
>> >> p = g;
>> >> while (unlikely(p->mm == NULL)) {
>> >> p = next_thread(p);
>> >> if (p == g)
>> >> break;
>> >> }
>> >> if (p->mm == mm) {
>> >> /*
>> >> * p->sighand can't disappear, but
>> >> * may be changed by de_thread()
>> >> */
>> >> lock_task_sighand(p, &flags);
>> >> zap_process(p);
>> >> unlock_task_sighand(p, &flags);
>> >> }
>> >
>> > Yes, I agree, this is much more understandable.
>>
>> There is one piece of zap_threads that still makes me uncomfortable.
>>
>> task_lock is used to protect p->mm.
>> Therefore killing a process based upon p->mm == mm is racy
>> with respect to sys_unshare I believe if we don't take
>> task_lock.
>
> Well, unshare(CLONE_VM) is not yet supported. Currently (as I see
> it) mm->mmap_sem is enough to protect against changing ->mm. Yes,
> exit_mm/exec_mmap take task_lock too, so it can be used as well.
> Please correct my understanding.
So what has me unsettled is that task_lock is used to
protect p->mm. The other place this could be a problem
is exit_mm. But it does appear that deliberately takes the mm_sem
to prevent this problem. So it looks like I was just missed
that trick.
> I think it is better to take ->mmap_sem in sys_unshare, this path
> is rare.
Agreed.
Eric
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] 2.6.17-rc4 bugfix with initramfs
2006-04-09 0:11 [PATCH rc1-mm 2/3] coredump: shutdown current process first Oleg Nesterov
2006-04-10 7:08 ` Roland McGrath
@ 2006-06-09 17:24 ` Nickolay
2006-06-10 7:07 ` Sam Ravnborg
1 sibling, 1 reply; 8+ messages in thread
From: Nickolay @ 2006-06-09 17:24 UTC (permalink / raw)
To: linux-kernel
This patch fix double inclusion of ramfs-input.
Signed-off-by: Nickolay Vinogradov <nickolay@protei.ru>
--- /linux-2.6.17-rc4.orig.old/usr/Makefile 2006-06-08
21:41:08.000000000 +0400
+++ linux-2.6.17/usr/Makefile 2006-06-09 21:16:53.000000000 +0400
@@ -21,8 +21,7 @@
$(CONFIG_INITRAMFS_SOURCE),-d)
ramfs-args := \
$(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
- $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
- $(ramfs-input)
+ $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID))
# .initramfs_data.cpio.gz.d is used to identify all files included
# in initramfs and to detect if any files are added/removed.
--
Nickolay Vinogradov
Russia, Saint Petersburg
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] 2.6.17-rc4 bugfix with initramfs
2006-06-09 17:24 ` [PATCH] 2.6.17-rc4 bugfix with initramfs Nickolay
@ 2006-06-10 7:07 ` Sam Ravnborg
0 siblings, 0 replies; 8+ messages in thread
From: Sam Ravnborg @ 2006-06-10 7:07 UTC (permalink / raw)
To: Nickolay; +Cc: linux-kernel
On Fri, Jun 09, 2006 at 09:24:14PM +0400, Nickolay wrote:
> This patch fix double inclusion of ramfs-input.
>
> Signed-off-by: Nickolay Vinogradov <nickolay@protei.ru>
Applied, thanks.
[Patch was malformed so applied by hand]
Sam
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-06-10 7:08 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-09 0:11 [PATCH rc1-mm 2/3] coredump: shutdown current process first Oleg Nesterov
2006-04-10 7:08 ` Roland McGrath
2006-04-10 14:01 ` Oleg Nesterov
2006-04-14 8:04 ` Eric W. Biederman
2006-04-14 15:33 ` Oleg Nesterov
2006-04-14 17:02 ` Eric W. Biederman
2006-06-09 17:24 ` [PATCH] 2.6.17-rc4 bugfix with initramfs Nickolay
2006-06-10 7:07 ` Sam Ravnborg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox