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 D4B5234DB48 for ; Wed, 4 Feb 2026 04:51:42 +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=1770180703; cv=none; b=gCUO5TZNgJsizib5BhyhxHGp5x8f/ns6pJnuFHEeed5DUsOo1nbLJesI0y2YyJns0F3qKhgyx2w/vGWkDE+5R0W+L35tU3muRZc4o9YoSmlAABYEvHzgNVBj1BEe/6gdeen4JYzMxly7d/t7sYyYvog7YMo9jaK0gbCuMnePkEk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770180703; c=relaxed/simple; bh=D8rFsDusdghX9Cf6V/kCkMURMbR/46pNYwM4R/WsxV0=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=VN0zg1trEPPbuPKFWpN4a5Jh31s6UbgAjNgs9dKjJhRLz4bEO283R82AKo1zPkzo77UPhBnPsCnYKLVDhy3AclzXAQa5ONJMgx+J224D6Io656n1lwn4pfZy+XSKe+zCWktJYFS6lV6hbK0ZZ/gTtbJYAb0/qAdZKGHJcz+DAgo= 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=epOOaSKl; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=dmp2Obzf; 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="epOOaSKl"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="dmp2Obzf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770180702; 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=pqp85rJLzs+OcPVvimtwEtdfYFvEbLOSgnCsPP9SUU0=; b=epOOaSKl1PIyWppDInQ99pYpXaqBFAyH+FCF/Q17WCblpLp+qWm6wymFSz1ny6lRm6SU6N s7zDj++vgt4Hu3ygY1n0AI0goKZQXJ8kvZvKa+fkq2QkW/Fq1pH4YA8migHI+EWnmRDoWZ ISyGv4kDjy0X0YjkcZ+TRGJYhAkp2ro= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-O1vZfldnPqmVxTPjXn_D2A-1; Tue, 03 Feb 2026 23:51:40 -0500 X-MC-Unique: O1vZfldnPqmVxTPjXn_D2A-1 X-Mimecast-MFC-AGG-ID: O1vZfldnPqmVxTPjXn_D2A_1770180700 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8c71655aa11so2109731985a.3 for ; Tue, 03 Feb 2026 20:51:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1770180700; x=1770785500; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:from:to :cc:subject:date:message-id:reply-to; bh=pqp85rJLzs+OcPVvimtwEtdfYFvEbLOSgnCsPP9SUU0=; b=dmp2Obzfnm+vQfInWFPGTm/QAEgIGOKlzuh9JlpIl5M8cQRu/N8zrQKbxIU9/lG60X v9RHKN/kFlmP+ywGK1s2R3b7goQ4vZRqLpzP9WKpqXbBOMwQN8tkkFDFYhKSKSasrq/c HZ21/TUV8aqT+gFZtqXBMFeG5PVlMxuOKSDncKxaFWXVpzhOGztbBFEhBTViGxijunhn mR84djYu/RvrPoQBNyg3OIqu54uYvC/R9esUqdQMlTqRAkkYvDIfuuwbhIBCnAU5PsTl k3l3KQbXvGOh5KyMfnWy8GuXFOjYKN05GqaK8ldIEZQ/zrZ9dvV1fZsus2TUipbspUnE zWvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770180700; x=1770785500; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pqp85rJLzs+OcPVvimtwEtdfYFvEbLOSgnCsPP9SUU0=; b=OYj5JXb7GAMkKy0xCS/Mg1rgXWjhqV2MvtJuX+XViPoifspDUWzDP02VxKJJyja3B1 5sgLTr/7aAlZvGch+RudXGTqo9QLNGBGoykqmAsTPEcGEzG3qZAIPAgE1oCeYsm/78+K cz6aHoCbQVkn1c3qZoUof+WJpTs4N23knzUNnh0CqPTy/MWNsZulGyaKEU8n6WLGYqCu dD7sTPVhVqKzstLGAGJl0HIj6udPdtvvj51KFWZQg3i+duMxPkPp0iZwdKbR304xLyMJ ejYJMyzTjYkQFUNaUYPOqIFHuF5idO9ULatCMeTu3VHR+Zj2iCxi//Hecq15/wqzEg7l iBjA== X-Forwarded-Encrypted: i=1; AJvYcCXbItNjZC6L9cMRzhOpP8Sh/0EmNm0YNPMuIxMkjvfWzfL/vDKPzW39kJmTvDetRUuSZAF+j/Xykrdrv2c=@vger.kernel.org X-Gm-Message-State: AOJu0YzGzNIlEqhsLW3/0TsOsLwvPgHNEGmgTp0xSWm/BJHOSfs9Ds+8 EMo2QOog0NYUfwCNxj8qazRkY4sd25xwx7NKvdjEJKHP+uwE9d5PeKgwG9k2SaZfnBSAtoJlu3G 6HOXKm0GY+L/2MZ8fPE9r8zF+2CAfrKaipvHaZtZvaX7DLxQShIWA7M0xndXk7n2Czw== X-Gm-Gg: AZuq6aIPoDL9fejw1D2yfYuqTr1mlKJy0A3Y5a530FVIE3mfreKM1lHVP+/DvHey+qt 76kBYUGcU6jFQhscxQWXWj+OmCwmvXgqYxgZJNA8IvjkIuxLIkhha+Xero3a8S2OhEnyEPDEDO+ TXahM4ejs4RKtBa7WWCQq75SzWy81BpoDoRZBgry++h3gJposjSbj9pc1J2aq0RWTuvHBM8o+DC yonc6Uwl1LkpzA19gbPmwV+ME1YBJPf8Svhx2TpNRQRtQkvVn2CrKjY5jZskKc4o+Xkr4wg2IFF P/pr6Yz/WQKheEvUggjqj90tDh++2U19ISaYF0GqbbNqJTzTWVI+UC5ubOlXB0bEob7miOWQKLg lLMrHj4qWqhpLbQPEpO5eimRBQmrYGoV89HRt1JVMv17RmWVxAXSFjH6l X-Received: by 2002:a05:620a:410e:b0:8c6:e0c5:7bbc with SMTP id af79cd13be357-8ca2f9fdd41mr205363385a.76.1770180700323; Tue, 03 Feb 2026 20:51:40 -0800 (PST) X-Received: by 2002:a05:620a:410e:b0:8c6:e0c5:7bbc with SMTP id af79cd13be357-8ca2f9fdd41mr205362285a.76.1770180699876; Tue, 03 Feb 2026 20:51:39 -0800 (PST) Received: from ?IPV6:2601:188:c102:b180:1f8b:71d0:77b1:1f6e? ([2601:188:c102:b180:1f8b:71d0:77b1:1f6e]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89521bfeac0sm12038286d6.9.2026.02.03.20.51.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Feb 2026 20:51:39 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: <617f19e4-cac0-4dab-801c-f1a31f0233a8@redhat.com> Date: Tue, 3 Feb 2026 23:51:38 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH/for-next v3 2/3] cgroup/cpuset: Defer housekeeping_update() calls from CPU hotplug to workqueue To: Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Shuah Khan Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20260202201144.1669260-1-longman@redhat.com> <20260202201144.1669260-3-longman@redhat.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/3/26 10:27 PM, Chen Ridong wrote: > > On 2026/2/3 4:11, Waiman Long wrote: >> The update_isolation_cpumasks() function can be called either directly >> from regular cpuset control file write with cpuset_full_lock() called >> or via the CPU hotplug path with cpus_write_lock and cpuset_mutex held. >> >> As we are going to enable dynamic update to the nozh_full housekeeping >> cpumask (HK_TYPE_KERNEL_NOISE) soon with the help of CPU hotplug, >> allowing the CPU hotplug path to call into housekeeping_update() directly >> from update_isolation_cpumasks() will likely cause deadlock. So we >> have to defer any call to housekeeping_update() after the CPU hotplug >> operation has finished. This is now done via the workqueue where >> the actual housekeeping_update() call, if needed, will happen after >> cpus_write_lock is released. >> >> We can't use the synchronous task_work API as call from CPU hotplug >> path happen in the per-cpu kthread of the CPU that is being shut down >> or brought up. Because of the asynchronous nature of workqueue, the >> HK_TYPE_DOMAIN housekeeping cpumask will be updated a bit later than the >> "cpuset.cpus.isolated" control file in this case. >> >> Also add a check in test_cpuset_prs.sh and modify some existing >> test cases to confirm that "cpuset.cpus.isolated" and HK_TYPE_DOMAIN >> housekeeping cpumask will both be updated. >> >> Signed-off-by: Waiman Long >> --- >> kernel/cgroup/cpuset.c | 37 +++++++++++++++++-- >> .../selftests/cgroup/test_cpuset_prs.sh | 13 +++++-- >> 2 files changed, 44 insertions(+), 6 deletions(-) >> >> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c >> index d705c5ba64a7..e98a2e953392 100644 >> --- a/kernel/cgroup/cpuset.c >> +++ b/kernel/cgroup/cpuset.c >> @@ -1302,6 +1302,17 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) >> return false; >> } >> >> +static void isolcpus_workfn(struct work_struct *work) >> +{ >> + cpuset_full_lock(); >> + if (isolated_cpus_updating) { >> + isolated_cpus_updating = false; >> + WARN_ON_ONCE(housekeeping_update(isolated_cpus) < 0); >> + rebuild_sched_domains_locked(); >> + } >> + cpuset_full_unlock(); >> +} >> + >> /* >> * update_isolation_cpumasks - Update external isolation related CPU masks >> * >> @@ -1310,14 +1321,34 @@ static bool prstate_housekeeping_conflict(int prstate, struct cpumask *new_cpus) >> */ >> static void update_isolation_cpumasks(void) >> { >> - int ret; >> + static DECLARE_WORK(isolcpus_work, isolcpus_workfn); >> >> if (!isolated_cpus_updating) >> return; >> >> - ret = housekeeping_update(isolated_cpus); >> - WARN_ON_ONCE(ret < 0); >> + /* >> + * This function can be reached either directly from regular cpuset >> + * control file write or via CPU hotplug. In the latter case, it is >> + * the per-cpu kthread that calls cpuset_handle_hotplug() on behalf >> + * of the task that initiates CPU shutdown or bringup. >> + * >> + * To have better flexibility and prevent the possibility of deadlock >> + * when calling from CPU hotplug, we defer the housekeeping_update() >> + * call to after the current cpuset critical section has finished. >> + * This is done via workqueue. >> + */ >> + if (current->flags & PF_KTHREAD) { >> + /* >> + * We rely on WORK_STRUCT_PENDING_BIT to not requeue a work >> + * item that is still pending. >> + */ >> + queue_work(system_unbound_wq, &isolcpus_work); >> + /* Also defer sched domains regeneration to the work function */ >> + force_sd_rebuild = false; > Eh, looking at the call path: > > cpuset_hotplug_update_tasks > update_parent_effective_cpumask > update_isolation_cpumasks > force_sd_rebuild = false; > cpuset_force_rebuild(); > > Setting force_sd_rebuild to false here might be redundant, given that > cpuset_force_rebuild() is called immediately afterward. Thank for spotting that. I will try to address this. Thanks, Longman