From nobody Mon Feb 9 12:02:11 2026 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 EF316313E39 for ; Wed, 28 Jan 2026 04:43:52 +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=1769575434; cv=none; b=i5narwEe8SHqV/8aunUqvnZL2nEIYeTQW4uIUdezp705vzkP64JPcG2eB/h3eDP36DpvnC3v4SdfBUkR5/HOCHLPfOSMszMxJfO7yJapEHxIKimERH1QRPDrDhXUL0JY/fqB3676Z/ZMIOkKGY0rxk7gpx+oQeFCQ8OpvBo+Bvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769575434; c=relaxed/simple; bh=y3AG4ItZTE9YrI/yAlycILOMdlCMh4FiHB0Xw38NcNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fidvuDhdH4TI2nPJWWJ4agMNvzbNjQTZNuxIxhrP3zc28k0qSZEibE6Qzq7TmzrYrcoLHvsW6RnrJdVzdBL2tfnyhrNTxvqk22BikS0U7vxAXqf6nt4uhw/QXmk2cYTDmP9LAmuCq0MQ/LoJVgs+3X2jcDwH7gC86HRthbeuypE= 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=BuBAJPWF; 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="BuBAJPWF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769575432; 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=Z5s8pAN3XHJbPx9PP65YrQaQggkzkJ9pEpC05YMysnA=; b=BuBAJPWF/Lfg843FhCt1+tSMHQxzvnWRJf3BQGBdUFXPaKAsDRn8kUMlwEbMYnrDy6hXKV re2qDeIWK5FBSV29rgTBZWYcZcYouWpNK9flQr8m1O3qBdkD8IGn9YaYFvusY8GNAwBf1w uwEFeUdwFpFKp1h1hXKs4y/JKeDSJyQ= Received: from mx-prod-mc-06.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-684-Y8yRFISjPVaxi2pqybcVTg-1; Tue, 27 Jan 2026 23:43:46 -0500 X-MC-Unique: Y8yRFISjPVaxi2pqybcVTg-1 X-Mimecast-MFC-AGG-ID: Y8yRFISjPVaxi2pqybcVTg_1769575424 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 029BB1800365; Wed, 28 Jan 2026 04:43:43 +0000 (UTC) Received: from llong-thinkpadp16vgen1.westford.csb (unknown [10.22.80.3]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0A37C18002A6; Wed, 28 Jan 2026 04:43:39 +0000 (UTC) From: Waiman Long To: Chen Ridong , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=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, Waiman Long Subject: [PATCH/for-next 1/2] cgroup/cpuset: Defer housekeeping_update() call from CPU hotplug to task_work Date: Tue, 27 Jan 2026 23:42:50 -0500 Message-ID: <20260128044251.1229702-2-longman@redhat.com> In-Reply-To: <20260128044251.1229702-1-longman@redhat.com> References: <20260128044251.1229702-1-longman@redhat.com> 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.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" 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 cause deadlock. So we have to defer any call to housekeeping_update() after the CPU hotplug operation has finished. This can be done via the task_work_add(..., TWA_RESUME) API where the actual housekeeping_update() call, if needed, will happen right before existing back to userspace. Since the HK_TYPE_DOMAIN housekeeping cpumask should now track the changes in "cpuset.cpus.isolated", add a check in test_cpuset_prs.sh to confirm that the CPU hotplug deferral, if needed, is working as expected. Signed-off-by: Waiman Long --- kernel/cgroup/cpuset.c | 49 ++++++++++++++++++- .../selftests/cgroup/test_cpuset_prs.sh | 9 ++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 7b7d12ab1006..98c7cb732206 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -84,6 +84,10 @@ static cpumask_var_t isolated_cpus; */ static bool isolated_cpus_updating; =20 +/* Both cpuset_mutex and cpus_read_locked acquired */ +static bool cpuset_full_locked; +static bool isolation_task_work_queued; + /* * A flag to force sched domain rebuild at the end of an operation. * It can be set in @@ -285,10 +289,12 @@ void cpuset_full_lock(void) { cpus_read_lock(); mutex_lock(&cpuset_mutex); + cpuset_full_locked =3D true; } =20 void cpuset_full_unlock(void) { + cpuset_full_locked =3D false; mutex_unlock(&cpuset_mutex); cpus_read_unlock(); } @@ -1285,25 +1291,64 @@ static bool prstate_housekeeping_conflict(int prsta= te, struct cpumask *new_cpus) return false; } =20 +static void __update_isolation_cpumasks(bool twork); +static void isolation_task_work_fn(struct callback_head *cb) +{ + cpuset_full_lock(); + __update_isolation_cpumasks(true); + cpuset_full_lock(); +} + /* - * update_isolation_cpumasks - Update external isolation related CPU masks + * __update_isolation_cpumasks - Update external isolation related CPU mas= ks + * @twork - set if call from isolation_task_work_fn() * * The following external CPU masks will be updated if necessary: * - workqueue unbound cpumask */ -static void update_isolation_cpumasks(void) +static void __update_isolation_cpumasks(bool twork) { int ret; =20 + if (twork) + isolation_task_work_queued =3D false; + if (!isolated_cpus_updating) return; =20 + /* + * This function can be reached either directly from regular cpuset + * control file write (cpuset_full_locked) or via hotplug + * (cpus_write_lock && cpuset_mutex held). In the later case, we + * defer the housekeeping_update() call to a task_work to avoid + * the possibility of deadlock. The task_work will be run right + * before exiting back to userspace. + */ + if (!cpuset_full_locked) { + static struct callback_head twork_cb; + + if (!isolation_task_work_queued) { + init_task_work(&twork_cb, isolation_task_work_fn); + if (!task_work_add(current, &twork_cb, TWA_RESUME)) + isolation_task_work_queued =3D true; + else + /* Current task shouldn't be exiting */ + WARN_ON_ONCE(1); + } + return; + } + ret =3D housekeeping_update(isolated_cpus); WARN_ON_ONCE(ret < 0); =20 isolated_cpus_updating =3D false; } =20 +static inline void update_isolation_cpumasks(void) +{ + __update_isolation_cpumasks(false); +} + /** * rm_siblings_excl_cpus - Remove exclusive CPUs that are used by sibling = cpusets * @parent: Parent cpuset containing all siblings diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh b/tools/test= ing/selftests/cgroup/test_cpuset_prs.sh index 5dff3ad53867..af4a2532cb3e 100755 --- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh +++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh @@ -773,6 +773,7 @@ check_isolcpus() EXPECTED_ISOLCPUS=3D$1 ISCPUS=3D${CGROUP2}/cpuset.cpus.isolated ISOLCPUS=3D$(cat $ISCPUS) + HKICPUS=3D$(cat /sys/devices/system/cpu/isolated) LASTISOLCPU=3D SCHED_DOMAINS=3D/sys/kernel/debug/sched/domains if [[ $EXPECTED_ISOLCPUS =3D . ]] @@ -810,6 +811,14 @@ check_isolcpus() ISOLCPUS=3D EXPECTED_ISOLCPUS=3D$EXPECTED_SDOMAIN =20 + # + # The inverse of HK_TYPE_DOMAIN cpumask in $HKICPUS should match $ISOLCPUS + # + [[ "$ISOLCPUS" !=3D "$HKICPUS" ]] && { + echo "Housekeeping isolated CPUs mismatch - $HKICPUS" + return 1 + } + # # Use the sched domain in debugfs to check isolated CPUs, if available # --=20 2.52.0