From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 13397256D for ; Mon, 24 Nov 2025 01:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763948731; cv=none; b=LLKWodGjSXTW8lpdwdlHwvpP2mPpBgJIUqdO5iREVe+VHZNp0+WVCIKK4/sPHGgC7JUOj17N2YpSfr3LPZdGwT7zk+V8DMwfDrRIgT4GPN8iVIDGNWVzzn9LerlvMAmDzgbszj/RBzYRF9y+Z8VpVo9huVIIXqXTtANkqwbusuM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763948731; c=relaxed/simple; bh=nT1uNKSpfXy1B7RKCyJBPQRWjd8wQIhgHpemmDJLO44=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=W/tcvhfnMdCDkrokmp5y8nUPRWl9jUF6R3auyZkdIC48iYTQas1qHNq/W7VfTpWwEEGfweb80iOzyeTGcT8ZC7XkccsnE9aLoT3AvWwqIctRDdNUx7S8KjqssZ6NHZgjEUu7YItFaYWGA9jXXo7WchUQOGzEvDNifNjfku9stoY= 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=ARBPqbbz; arc=none smtp.client-ip=170.10.129.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="ARBPqbbz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763948728; 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: in-reply-to:in-reply-to:references:references; bh=BKglrmo9LLgZO9XB05dhcvOykupJzgkwsqvGTFl1n1k=; b=ARBPqbbzV7txj99VFdVUz2H2h0KxzclOImC6swvToNaLsb4koPapLEGpA7NQSUcngpRa7W jaAgkti4C5j+XpqjyzsQyxUULgKyv/F0/apsN0Ry3TjL8sZ+ilkEhOln0iKKVm3/bqQLc9 mp2SG92l+lT+BpGezTClHFs8jL0qWGE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-483-K3Yeyr_XNACRhVyzJpKDiw-1; Sun, 23 Nov 2025 20:45:24 -0500 X-MC-Unique: K3Yeyr_XNACRhVyzJpKDiw-1 X-Mimecast-MFC-AGG-ID: K3Yeyr_XNACRhVyzJpKDiw_1763948722 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5A2751956096; Mon, 24 Nov 2025 01:45:21 +0000 (UTC) Received: from localhost (unknown [10.72.112.35]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1E19218002A6; Mon, 24 Nov 2025 01:45:18 +0000 (UTC) Date: Mon, 24 Nov 2025 09:45:16 +0800 From: Pingfan Liu To: Juri Lelli Cc: linux-kernel@vger.kernel.org, Waiman Long , Chen Ridong , Peter Zijlstra , Pierre Gondois , Ingo Molnar , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Tejun Heo , Johannes Weiner , mkoutny@suse.com Subject: Re: [PATCHv7 2/2] sched/deadline: Walk up cpuset hierarchy to decide root domain when hot-unplug Message-ID: References: <20251119095525.12019-1-piliu@redhat.com> <20251119095525.12019-3-piliu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 On Fri, Nov 21, 2025 at 02:05:31PM +0100, Juri Lelli wrote: > Hi! > > On 19/11/25 17:55, Pingfan Liu wrote: > > ... > > > +/* Access rule: must be called on local CPU with preemption disabled */ > > static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask_dl); > > ... > > > +/* The caller should hold cpuset_mutex */ > > Maybe we can add a lockdep explicit check? > Currently, all cpuset locks are encapsulated in kernel/cgroup/cpuset-internal.h. I'm not sure if it's appropriate to expose them. If exposing them is acceptable, cpuset_callback_lock_irq()/cpuset_callback_unlock_irq() would be preferable to cpuset_mutex assertion. @Waiman, @Ridong, could you kindly share your opinion? > > void dl_add_task_root_domain(struct task_struct *p) > > { > > struct rq_flags rf; > > struct rq *rq; > > struct dl_bw *dl_b; > > + unsigned int cpu; > > + struct cpumask *msk = this_cpu_cpumask_var_ptr(local_cpu_mask_dl); > > Can this corrupt local_cpu_mask_dl? > > Without preemption being disabled, the following race can occur: > > 1. Thread calls dl_add_task_root_domain() on CPU 0 > 2. Gets pointer to CPU 0's local_cpu_mask_dl > 3. Thread is preempted and migrated to CPU 1 > 4. Thread 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 > Oh, that is definitely an issue. Thanks for pointing it out. > > > > raw_spin_lock_irqsave(&p->pi_lock, rf.flags); > > It's safe to get the pointer after this point. > Yes. > > if (!dl_task(p) || dl_entity_is_special(&p->dl)) { > > @@ -2919,16 +2952,25 @@ void dl_add_task_root_domain(struct task_struct *p) > > return; > > } > > > > - rq = __task_rq_lock(p, &rf); > > - > > + /* > > + * Get an active rq, whose rq->rd traces the correct root > > + * domain. > > + * Ideally this would be under cpuset reader lock until rq->rd is > > + * fetched. However, sleepable locks cannot nest inside pi_lock, so we > > + * rely on the caller of dl_add_task_root_domain() holds 'cpuset_mutex' > > + * to guarantee the CPU stays in the cpuset. > > + */ > > + dl_get_task_effective_cpus(p, msk); > > + cpu = cpumask_first_and(cpu_active_mask, msk); > > + BUG_ON(cpu >= nr_cpu_ids); > > + rq = cpu_rq(cpu); > > dl_b = &rq->rd->dl_bw; > > - raw_spin_lock(&dl_b->lock); > > + /* End of fetching rd */ > > Not sure we need this comment above. :) > OK, I can remove them to keep the code neat. Thanks, Pingfan