From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756353Ab0EJTxt (ORCPT ); Mon, 10 May 2010 15:53:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47557 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754469Ab0EJTxr (ORCPT ); Mon, 10 May 2010 15:53:47 -0400 Date: Mon, 10 May 2010 21:50:38 +0200 From: Oleg Nesterov To: Andrew Morton Cc: Cedric Le Goater , Dave Hansen , Eric Biederman , Herbert Poetzl , Ingo Molnar , Mathias Krause , Roland McGrath , Serge Hallyn , Sukadev Bhattiprolu , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] pids: fix fork_idle() to setup ->pids correctly Message-ID: <20100510195038.GD5249@redhat.com> References: <4BE01C86.3050908@secunet.com> <20100509184510.GA15219@redhat.com> <4BE7B3BD.70901@secunet.com> <20100510194917.GA5249@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100510194917.GA5249@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org copy_process(pid => &init_struct_pid) doesn't do attach_pid/etc. It shouldn't, but this means that the idle threads run with the wrong pids copied from the caller's task_struct. In x86 case the caller is either kernel_init() thread or keventd. In particular, this means that after the series of cpu_up/cpu_down an idle thread (which never exits) can run with .pid pointing to nowhere. Change fork_idle() to initialize idle->pids[] correctly. We only set .pid = &init_struct_pid but do not add .node to list, INIT_TASK() does the same for the boot-cpu idle thread (swapper). Signed-off-by: Oleg Nesterov --- kernel/fork.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- 34-rc1/kernel/fork.c~3_FORK_IDLE_SET_PIDS 2010-03-24 18:07:03.000000000 +0100 +++ 34-rc1/kernel/fork.c 2010-05-10 20:45:33.000000000 +0200 @@ -1339,6 +1339,16 @@ noinline struct pt_regs * __cpuinit __at return regs; } +static inline void init_idle_pids(struct pid_link *links) +{ + enum pid_type type; + + for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type) { + INIT_HLIST_NODE(&links[type].node); /* not really needed */ + links[type].pid = &init_struct_pid; + } +} + struct task_struct * __cpuinit fork_idle(int cpu) { struct task_struct *task; @@ -1346,8 +1356,10 @@ struct task_struct * __cpuinit fork_idle task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, &init_struct_pid, 0); - if (!IS_ERR(task)) + if (!IS_ERR(task)) { + init_idle_pids(task->pids); init_idle(task, cpu); + } return task; }