From nobody Tue Dec 2 00:46:06 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 B2B1336D50C for ; Mon, 24 Nov 2025 03:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763955314; cv=none; b=KD/l0WSlmfluKMmaPHqpfKEg+e9pMhdat3TKm9jPpVuUBVlnsjyiPIwcmWzo/2wbINam3kwUpGPdBnfEWcDaVzKq4dBEh6PFz2JpVJ25lcVRBHjBgIPaUf4SFULxR5Z1mvnBT7c6KWk1d/ug2QX8CFvrJUCwRkJtAVPFdFY0Lgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763955314; c=relaxed/simple; bh=R61HooRzOl5iZLZ+6eP6z5HBdBtySBxQEeqSgIVV6YE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OPp7dz0Y6ChEM2j5tU5wncihIOJFuDwEBQUnJEjuFMAf7PSqcYIqzQZ0twtCiOGdm8fKy5fhxbP5Q6tB4qMvGuuktjpdR76Cj2oGSauY0Q2cWn4WcQVLdkDBjOdg2SxWYrWVEKMJG3wpH5B+Z98i/wiDlnk/QFivCL8gsMZRAFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MDUIp9HX; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MDUIp9HX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763955311; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T3XHEpgyFAambA4QUXpRraFGSX1hDedeGitjAG9I5fc=; b=MDUIp9HXeqj151l0XeKlWZzol9bDqLaMfSPkcEOdcxg+uuWkSMet0XrOHc1fjKsl7QsSRW 21OBsq1fBhqeHSRPtTTALl39RV8Qs0xMg+flETE3k32th+A/p3u3ynv3fEZDXREx1dB4zM nh9kAfgMTSynzqK8lL2wtPcHuGYU9uc= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-1pFamA8lMb2r8KR02bCvjg-1; Sun, 23 Nov 2025 22:34:34 -0500 X-MC-Unique: 1pFamA8lMb2r8KR02bCvjg-1 X-Mimecast-MFC-AGG-ID: 1pFamA8lMb2r8KR02bCvjg_1763955272 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 08DD01800447; Mon, 24 Nov 2025 03:34:32 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.35]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4D9A919560A7; Mon, 24 Nov 2025 03:34:22 +0000 (UTC) From: Pingfan Liu To: Tejun Heo , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Juri Lelli , Waiman Long , Chen Ridong , Peter Zijlstra , Pierre Gondois , Ingo Molnar , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Subject: [PATCH] sched/deadline: Fix potential race in dl_add_task_root_domain() Date: Mon, 24 Nov 2025 11:34:15 +0800 Message-ID: <20251124033415.10784-1-piliu@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" The access rule for local_cpu_mask_dl requires it to be called on the local CPU with preemption disabled. However, dl_add_task_root_domain() currently violates this rule. Without preemption disabled, the following race can occur: 1. ThreadA calls dl_add_task_root_domain() on CPU 0 2. Gets pointer to CPU 0's local_cpu_mask_dl 3. ThreadA is preempted and migrated to CPU 1 4. ThreadA continues using CPU 0's local_cpu_mask_dl 5. Meanwhile, the scheduler on CPU 0 calls find_later_rq() which also uses local_cpu_mask_dl (with preemption properly disabled) 6. Both contexts now corrupt the same per-CPU buffer concurrently Fix this by moving the local_cpu_mask_dl access to the preemption disabled section. Closes: https://lore.kernel.org/lkml/aSBjm3mN_uIy64nz@jlelli-thinkpadt14gen= 4.remote.csb Fixes: 318e18ed22e8 ("sched/deadline: Walk up cpuset hierarchy to decide ro= ot domain when hot-unplug") Reported-by: Juri Lelli Signed-off-by: Pingfan Liu To: Tejun Heo Cc: Waiman Long Cc: Chen Ridong Cc: Peter Zijlstra Cc: Juri Lelli Cc: Pierre Gondois Cc: Ingo Molnar Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider To: cgroups@vger.kernel.org To: linux-kernel@vger.kernel.org --- kernel/sched/deadline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 194a341e85864..e9153e86de0a7 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2944,7 +2944,7 @@ void dl_add_task_root_domain(struct task_struct *p) struct rq *rq; struct dl_bw *dl_b; unsigned int cpu; - struct cpumask *msk =3D this_cpu_cpumask_var_ptr(local_cpu_mask_dl); + struct cpumask *msk; =20 raw_spin_lock_irqsave(&p->pi_lock, rf.flags); if (!dl_task(p) || dl_entity_is_special(&p->dl)) { @@ -2952,6 +2952,7 @@ void dl_add_task_root_domain(struct task_struct *p) return; } =20 + msk =3D this_cpu_cpumask_var_ptr(local_cpu_mask_dl); /* * Get an active rq, whose rq->rd traces the correct root * domain. --=20 2.49.0