From nobody Mon Nov 25 09:55:06 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B0D71D88B1 for ; Mon, 28 Oct 2024 10:43:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730112226; cv=none; b=UKp+MJZVFFCEW3W2WQcrMqI1JDqU5EMJ2jmxMOEWqaEItlzL416k5XXMxpQFmT6JoV62/c7i84nW6K/7sl7f11mAE5gmQ6drswLb/O+N40fJEG90XBWjq1NxRiBqsvXJ1jreGz3AMx7lN5YESpBFCIotKUmTCdqi/TjkpAWWyro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730112226; c=relaxed/simple; bh=ipQrO0L1c/KaKus/S+ob2UFnyolNm0aZT1lrfgIVT7Q=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=hNXFeVyzYAq6cItuWLM0uWPrR08oIvL2ozr0C8m7/TxtBni+szX5VVqMfY1I3JkLq1n/vFCI3WMppcoFbSXnbH2jAy7lz+RpZs23AYEiUU6DsKOSIeAcrJpfdvkp+iFWo51GHWfY481PYglc/VI+4V3KtDtgCZBCAIkj7zuPF2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uFVucZTZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WwsBABA4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uFVucZTZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WwsBABA4" Message-ID: <20241028103142.359584747@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1730112222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=IygJzwRz1dGBlMSu6nhuCmf8n7Jtd/1+VfsTEUY9q7Y=; b=uFVucZTZR+4InRh4oIsyea3Tk+ZQCQtJRIejn13qgu8WIAjGxJ5tsgb9Pl+wkCFtnS/FJC 6wcJwicOImjb9K1ZKYvinzGfvdNRBg3F/NLLsHbhe1vTCu4Fw252X2QCF8pahNBJUD4ufI VXdatPkVARH+mncL7ND9+SJ+VQl4DPXW9IiZfilFSlSq2wvlM/4nRJhJjGjHhd5f0DKFEj YwPlLne7U65iVFGrFSDeVNur/ounaMXa4P7gtS/b67umrK0sqSuxleBr4K2bO9j72iw7Dg mvzgTe9OHMbVCvjIcKns+06qrDudS3uMrEFJzNTvvzHSv3X+ISuzKVM0qpDgkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1730112222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=IygJzwRz1dGBlMSu6nhuCmf8n7Jtd/1+VfsTEUY9q7Y=; b=WwsBABA4vKDg8E7/elp1uQpqZ2Q18/D1Du8Ds6GhCYLbgUMK3WIYu+otF4yqtbU5i1zdHU 49b1mrgIMoNm7+BA== From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Tejun Heo , David Vernet , Ingo Molnar Subject: [patch 1/2] sched: Initialize idle tasks only once References: <20241028103006.008053168@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Mon, 28 Oct 2024 11:43:42 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Idle tasks are initialized via __sched_fork() twice: fork_idle() copy_process() sched_fork() __sched_fork() init_idle() __sched_fork() =20 Instead of cleaning this up, sched_ext hacked around it. Even when analyis and solution were provided in a discussion, nobody cared to clean this up. init_idle() is also invoked from sched_init() to initialize the boot CPU's idle task, which requires the __sched_fork() invocation. But this can be trivially solved by invoking __sched_fork() before init_idle() in sched_init() and removing the __sched_fork() invocation from init_idle(). Do so and clean up the comments explaining this historical leftover. Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/8734p4ymqj.ffs@tglx Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider --- kernel/sched/core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4424,7 +4424,8 @@ int wake_up_state(struct task_struct *p, * Perform scheduler related setup for a newly forked process p. * p is forked by current. * - * __sched_fork() is basic setup used by init_idle() too: + * __sched_fork() is basic setup which is also used by sched_init() to + * initialize the boot CPU's idle task. */ static void __sched_fork(unsigned long clone_flags, struct task_struct *p) { @@ -7680,8 +7681,6 @@ void __init init_idle(struct task_struct struct rq *rq =3D cpu_rq(cpu); unsigned long flags; =20 - __sched_fork(0, idle); - raw_spin_lock_irqsave(&idle->pi_lock, flags); raw_spin_rq_lock(rq); =20 @@ -7696,10 +7695,8 @@ void __init init_idle(struct task_struct =20 #ifdef CONFIG_SMP /* - * It's possible that init_idle() gets called multiple times on a task, - * in that case do_set_cpus_allowed() will not do the right thing. - * - * And since this is boot we can forgo the serialization. + * No validation and serialization required at boot time and for + * setting up the idle tasks of not yet online CPUs. */ set_cpus_allowed_common(idle, &ac); #endif @@ -8543,6 +8540,7 @@ void __init sched_init(void) * but because we are the idle thread, we just pick up running again * when this runqueue becomes "idle". */ + __sched_fork(0, current); init_idle(current, smp_processor_id()); =20 calc_load_update =3D jiffies + LOAD_FREQ; From nobody Mon Nov 25 09:55:06 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70BD21D88AC for ; Mon, 28 Oct 2024 10:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730112227; cv=none; b=Y43v6bRAF0bQkMibRwM7IZ/nxKYIJd+CldrYwyvq/8E/pV7DjD5J3WnlH04OVqOQQeGwQG21G6uWvJEuDvE6iMtL2KRcEBfyorE5vNG9idFbNN4WtPDr8fz46SWSmXEeY1nDtlbv68hWI3tlAWGXTM28PV3yFLFoGL7CfNbOCkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730112227; c=relaxed/simple; bh=p87L0U/wfgeWAEMV0TRvnldY0DFh6yspZEZFR/aI/jI=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=cfHYdl5qH/vor4ruLqdx1RF7JmIMeSCUf6qPaKOyweFSrsm8YbRfIGQY37/6Rtkic17UFxjw1CmIV/vBN56zM8RYdD2cXCDsuQVE2NEvfqaJ03coJMZ1+2NdKY5fgcBVWgCIfG22Cg/igzh3p2LB1xpT0ZLMQ4LgMD17eJ6q8Q8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qLNLtPAF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RMcTOJSu; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qLNLtPAF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RMcTOJSu" Message-ID: <20241028103142.423153706@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1730112223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=8V9BMISLe+emg3tqf6WBDnIjWn20ZCDDb1a0hEN5uUQ=; b=qLNLtPAFOUQqVGi9YaQuXAvmlhkZXUc5MY2L3mUxrd0zQrBAwdSh3dFrfGnegyUoaDUNOL FcGqQvwf/SsjGVnNTzsHXIo5kesoeapMfMqoRxuWkygF0228NlGRUUulBoBuHIfUxeMDMS QM7MPW4SKUJLW3jU/1jSoIOJDn2saYfDpNvBI7t3EOBP3sUGcEVXwPWXzTGIL5MlQTBuCq MScWBZvt+cOQLTmexKDZjuYe2oQzAg8JMY5ErRkSpJAnVNUxkna0HrpObbcKvcTxAKwbiV BQvULmC7B1kBNqKmgokT0B8Ek58nopQNq9x2Sz9JwV9zCk7X/qP3e/oM9lDIYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1730112223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=8V9BMISLe+emg3tqf6WBDnIjWn20ZCDDb1a0hEN5uUQ=; b=RMcTOJSuPsXLBGtu+xnTbDBPjkc+ZnBCqYfj+5Na8Ao+PgNp3ENrq7JtFfkkK2djbXG0PI Ve1rODsJ454IqADQ== From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Tejun Heo , David Vernet , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Ingo Molnar Subject: [patch 2/2] sched/ext: Remove sched_fork() hack References: <20241028103006.008053168@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Mon, 28 Oct 2024 11:43:43 +0100 (CET) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of solving the underlying problem of the double invocation of __sched_fork() for idle tasks, sched-ext decided to hack around the issue by partially clearing out the entity struct to preserve the already enqueued node. A provided analysis and solution has been ignored for four months. Now that someone else has taken care of cleaning it up, remove the disgusting hack and clear out the full structure. Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class") Signed-off-by: Thomas Gleixner Cc: Tejun Heo Cc: David Vernet Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider --- kernel/sched/ext.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -3548,12 +3548,7 @@ static void scx_ops_exit_task(struct tas =20 void init_scx_entity(struct sched_ext_entity *scx) { - /* - * init_idle() calls this function again after fork sequence is - * complete. Don't touch ->tasks_node as it's already linked. - */ - memset(scx, 0, offsetof(struct sched_ext_entity, tasks_node)); - + memset(scx, 0, sizeof(*scx)); INIT_LIST_HEAD(&scx->dsq_list.node); RB_CLEAR_NODE(&scx->dsq_priq); scx->sticky_cpu =3D -1;