From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796299555; b=BqD7tABt1X+cmBmrzJuTBvrUKv1VypVovVsx+/XWHweSn8qv0RvE5Tk3PjK9p3S1OCy5 fgCF74fTpGMBlXJk73gH3P6eSVoXSBjTcoUszKCxv/GgCWgD/VwWOQf5V8KFI0DqIHYz/ Pa6hqBbIkfmrBMcgv4jeWhmTyPX2CT2tM/eRzrR6Pk+km2v2Q7+Z3/jvvpfpAKHRD8F9s lcaRTMSMneb8gqEgPijKf6MurAoFTXeFx4aha3/px5hFAhgj680TreGRpL3zyW1jtbpEE NLV9ukgnkmvlOQ55PngUBhBK0o4BCtFJT0tvjkxNXFtiY0KvbHojf2sgHlj1VJfzIxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796299555; h=DMARC-Filter:Date:DKIM-Signature:DKIM-Signature:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=rSg03Eaxd0cSkHaA8qCFAkn8/bQHhBaFm5nzqIKkKXI=; b=m0erVsUCoIhFFV9UcwpFMXYFNg/rzBZ737+qs1rvarVwiEqjvN+XMEKyIf/2lkoBnbJg vsGfX5OPqQ6Kmejfk7Kn+CSOEHxetUJxP2OLvQYMzRobVLvmTPbyhwNE6fXtnfzfF5pPJ VVLvmOzHhD70m/nvvYafNd1ZadZPkOEj5CfULsR+DluZnftYcGhCdHaUbDLYnQ8veeS5o Zjpr/mdfz0QQGsZm8Xvi+myEY3W8N7FA09/1A/lupqcStL0HOpnZtBAEANHc8BsIUONHs 87+DLspB5abZPEQTmhTMH0rcOE52MS4QwbXWYB80VGjKNFot4MWiCLS/SVJKTEd7KrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=PJ8YQRlR; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=QQeY+qGL; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59ACD60A381F for ; Thu, 3 Dec 2026 12:05:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 59ACD60A381F 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.a=rsa-sha256 header.s=2020 header.b=PJ8YQRlR; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=QQeY+qGL Date: Thu, 3 Dec 2026 13:05:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1796299551; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rSg03Eaxd0cSkHaA8qCFAkn8/bQHhBaFm5nzqIKkKXI=; b=PJ8YQRlRk0OqUL1jW7lNppoNcfo0Qrv3uIF9lUl10gvnF8HtHh2TFJQgPgptFVwmKGQ9ou +tdMwp0kga1r9cnSgcHCzcdKONoKR3qwGUG9HSh5NUaodKHqhgGQqLIlqL9Kp/eLzKYsUN saW2qAJ9bUsfX0m4OytY6iwf7Hcsot8TRjPGHT8d3HOmt5FPFrG3gDedd+VXCLr81lBiW3 SApIGOKymzJdbCl7Q0TQE1ZE3AxXLBLb3AYoxKzy7qvbeD2PSE8pYFyvUG9GDQUEcyYLOa eh9MmFmHEGkZbTEgTkOJtVdk6ChFdciOQ/7kFmVOew+hnyloR1tUE9cOfMIpdQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1796299551; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rSg03Eaxd0cSkHaA8qCFAkn8/bQHhBaFm5nzqIKkKXI=; b=QQeY+qGLshnrCL3tRaixX+odFu/onPA8hmpxvCSMxAFCpx6Um0Tv882NDvF8om3RgNzVHS SDI33rQDr7tBRlCw== From: Sebastian Andrzej Siewior To: Zhen Wang Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, bristot@redhat.com, tglx@kernel.org, radu@rendec.net, syzbot+6835d5c11145e4f77057@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, Xuewen.Yan@unisoc.com, Hao_hao.Wang@unisoc.com, Ke.Wang@unisoc.com Subject: Re: [PATCH v3] sched: Reset cpumask if __migrate_task() failed for migration_cpu_stop() Message-ID: <20261203120548.B3Sd2Vns@linutronix.de> References: <20261120171658.Cf9qIU-Y@linutronix.de> <20261203112514.686980-1-zhen.wang1@unisoc.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20261203112514.686980-1-zhen.wang1@unisoc.com> On 2026-12-03 19:25:14 [+0800], Zhen Wang wrote: > On Thu, Nov 26, 2026 at 11:40:49AM +0100, Peter Zijlstra wrote: > > Fun though; if we did hit this condition then > > migrate_enable() would have silently failed. Also not a good thing. > > > > We should probably have ___migrate_enable() warn on this. >=20 > We hit exactly this condition in testing. The difference from the > syzbot trace: the CPU stays offline, so the task's cpus_mask contains > no online CPU at all, and we *do* take the -EINVAL exit even with the > migration_disabled() mitigation switching to cpu_online_mask. >=20 > Two extra consequences we see, beyond the silently ignored affinity: >=20 > - __migrate_enable() only calls ___migrate_enable() when > p->cpus_ptr !=3D &p->cpus_mask. With a stale cpus_ptr that branch is > taken on every enable: each later migrate_enable() re-enters > __set_cpus_allowed_ptr(), re-takes task_rq_lock() and fails again. > A healthy task returns early without taking any lock. Yeah. >=20 > - That breaks migrate_enable() in constrained contexts. We see it what is a constrained context? > from a BPF program attached to trace_sched_switch that calls > migrate_enable(): the call takes task_rq_lock() on the runqueue > __schedule() already holds and deadlocks. With an intact cpus_ptr > the enable takes no lock, so the same program is fine. So the migrate_enable() didn't succeed in restoring the mask and the balanced migrate_enable() with the scheduler does it again. And the BPF code does migrate_en/dis so=E2=80=A6 =E2=80=A6 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -3245,6 +3245,8 @@ static int __set_cpus_allowed_ptr_locked(struct tas= k_struct *p, > */ > dest_cpu =3D cpumask_any_and_distribute(cpu_valid_mask, ctx->new_= mask); > if (dest_cpu >=3D nr_cpu_ids) { > + if (ctx->flags & SCA_MIGRATE_ENABLE) > + p->cpus_ptr =3D ctx->new_mask; > ret =3D -EINVAL; > goto out; > } This does not make it right, it just avoids the problem on enabled. The mask still does not match the CPU it runs on. do_set_cpus_allowed() was not yet invoked yet so that is nice. Do you see the printk where select_fallback_rq() fixes the mask? Sebastian