From nobody Fri Dec 19 10:57:20 2025 Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 991A0376E1 for ; Thu, 4 Jul 2024 03:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064796; cv=none; b=rkyGaoOtUETtonCcUcpfgXHAdrueF1L2qZ4m5+dGx2aRxzdC1RYcpJc4vP/Ge5KrVrW+27+dkygehFPYAUE3B2fYW8MI0bs7hrkMs/YnppvRYfK4PEjkkBKbjegMjHiYTP4+aKyr3E2YNu96BPpzhrDRAJxEnagU9sb1pzMyPNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064796; c=relaxed/simple; bh=vkihHeUPVc2ZjFVGWuUy6dhg/iIN8IgnkEmqLqIu4r4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SnwfQqApKDlejp+b1U1/wGBaxXuN3fIMDA8I9JW/cmpHI/cV+FSVMiuZfu6YRHw6uojNnU4nM7Jls6tyYevDnu59uuu8bXEJa/jBalVVM6/OvG31oWBvhWFa/lMpXA3xj2R0kxG7ePyCwD9x5kA+GzT8T+iNNl5NMS2yDBVwOZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZeDZqT5w; arc=none smtp.client-ip=209.85.166.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZeDZqT5w" Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-3815eaa136eso984715ab.0 for ; Wed, 03 Jul 2024 20:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720064793; x=1720669593; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kCyTuMbFoDwGev6RpdFwFdS1vydkz87hmYVqtPgiqyo=; b=ZeDZqT5wxSh11ypK/xk4jLh2L+kQ1qCkd46Ze99UEPRTneLOyVcuXL248uHeQVNshb EBYwHfFSA8ak5WZgCbMtcc0wgeYfoDNyr8hB1tjnYyFfzco8Ckeukznhj5x1rdmXWSZU HO8ED5SzRfqNEmRRqV59xU1Qax/yYyiJfK1ucHlP6TQ8QG4SGfAt7qc8vMY1OhCOEkgm gXcDlSDoXo+rplxevHbQ02gs3kTqtoEzNOweeDXK00bYT2KNQE2BtxGEYq0XRtuDd7Yy Q+gGqCRvzaHu8YYmw3Uh36pZEBgstfkw4zWJ+mXM1vFmNqLTUyhnTiL2daTZF1O6ry0W ffzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720064793; x=1720669593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kCyTuMbFoDwGev6RpdFwFdS1vydkz87hmYVqtPgiqyo=; b=c+afdkhf3YQV4YDPuebrf+BsJiOmxPRi1fhA9pULxHRCfEuClIjI3bKR4zeUO8nvqC QnGTMoMsq7rRYqIBTL8zzH+RZZa301GOEC058xzzYUjvrZEgwh0IoYMgK6R3j0fQRGz5 WglyrdK/1TJ/BWXbLHW7bNDm76Vi+OlUTx3UM8o6DvGaY+x30Frh8sXyjBEdytFK6RQ+ qEpaPwW1ZfXuOMxQt31R3AarMbfH1SlZHCUDE5BqxZCGWjgHIV3r/jZBiet7VjwiL7JW XXD9uYe/QGn4yUEMIB4RK999F7A+jHh6qlHLHzUqN5MWsr4YrwiE9kk7yHqqyg6kpxJC aSEg== X-Gm-Message-State: AOJu0YyBFHE7QdhLJlPdnIudZXktEfbGyhCl60o5HpqSpkdppm0PRJ13 UbwGlY1sCWgwOwRxIwa/wSNtk2yeW1NX2ptvp7Z2Z5zsfxKYqMHsD+SJqw== X-Google-Smtp-Source: AGHT+IHW8LWS/4C0uRRrfwyvzarWiQR6rYooB1Sa1/HYFmGrYkinBUPiKlgeARfACMOy5VYG8LxRdg== X-Received: by 2002:a05:6e02:1846:b0:383:206a:1b31 with SMTP id e9e14a558f8ab-3839b099794mr6425985ab.24.1720064793264; Wed, 03 Jul 2024 20:46:33 -0700 (PDT) Received: from localhost ([47.89.225.180]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6c7f761fsm8741479a12.62.2024.07.03.20.46.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 20:46:32 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Tejun Heo , Lai Jiangshan Subject: [PATCH V2 1/5] workqueue: Register sysfs after the whole creation of the new wq Date: Thu, 4 Jul 2024 11:49:10 +0800 Message-Id: <20240704034915.2164-2-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240704034915.2164-1-jiangshanlai@gmail.com> References: <20240704034915.2164-1-jiangshanlai@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan workqueue creation includes adding it to the workqueue list. Prepare for moving the whole workqueue initializing procedure into wq_pool_mutex and cpu hotplug locks. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index a38a67ac4e80..904a1a6808b7 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5693,9 +5693,6 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, if (wq_online && init_rescuer(wq) < 0) goto err_destroy; =20 - if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq)) - goto err_destroy; - /* * wq_pool_mutex protects global freeze state and workqueues list. * Grab it, adjust max_active and add the new @wq to workqueues @@ -5711,6 +5708,9 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, =20 mutex_unlock(&wq_pool_mutex); =20 + if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq)) + goto err_destroy; + return wq; =20 err_free_node_nr_active: --=20 2.19.1.6.gb485710b From nobody Fri Dec 19 10:57:20 2025 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDB563BBCC for ; Thu, 4 Jul 2024 03:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064801; cv=none; b=mfaq4FdBghkwaPSE/5VW4GfEfUAOkE3fWHRM/PuiDMM+HllTLm3UEdKh7QIpoq3bGg+HEmbQRUyNlUeUwtlB9BkRkDC7dQ+cjBDutBbgblOJ+RLuZEm1cTvldlgrDEeWF1ojC30qJeIhtF/0ystpsXPxmgITEEWLBNSsQrMHCVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064801; c=relaxed/simple; bh=z/XeS/S1Pa0LeS2I3yaJ8rhI4Ye1O/Fb37d7D4BP9Ds=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=skk3W0r8eRJcp/95dN43LqPr2VrB0go5Q2gkwjiJ+mNJj0CI/7io9aQUIvOaiWKcXrDxUimsiMB0rq0n75EYD68Ju7UIapb1hdmg/SLR8Sb4VDhqhXR2PG0LZI8xJeK8TCRIBxSj0bfD5fj0idGOdSa+qOyEzSE9Z/oA+g/9s2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BeWp3oRb; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BeWp3oRb" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-701fef57ac1so141619a34.0 for ; Wed, 03 Jul 2024 20:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720064798; x=1720669598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SWRDLhnXLKtkXkAKITd82oZMdwj+urGj9spLJB/oijM=; b=BeWp3oRbejMKUQ5gejRU3OLj6Y3OUex49+1o0kvcCRgWpt2vB1mpw/8Y++OIrs4DRD r7fpROLMD0RlK6poytDz+SuqFpf/6eU4ytKRWHEwBMaf/AUiRwRoiGvv7x/a3lBDFSEu EjrdDA5cooOZCOauTawX/+AsWcvrPvISfZAye9sd7d8uOX0y+pqbSxJ3N5zaiiV5rtIZ 7ATbqAS1iLInPpgT5U8cLbPVHWHxOHlaP/Npgho7Ib2EgYdvNb/pyCmCsZoVoB22s2Vw RL4RrfkAKWz0dfCjQoTqyvQo/kJqwy3Wcoyu8JV/AjLlHX4eq2BWOOaN70689Vgnw/oh eQyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720064798; x=1720669598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SWRDLhnXLKtkXkAKITd82oZMdwj+urGj9spLJB/oijM=; b=azm/bQ0/aajyE3XrO9WvC3lBkosPmHLdIg9D8aen7ZwsC5EySdVxy+lvfE9IgchXiK EgD8KVd8b6DtZoFlJVke6d4bDV2jnfxBmQUrmG8t8PAde6pU8UrKHyLCgBRJ/o/wRfwe YHz/d2gSZh0xWM+VNV0Vij+C3FFjNuctOnuLE8xQtkBPBuEC8RfpINrSa4tmui6Ge52G U/28fv5fgFoV9WAh+Ezk/ptwdEr7w/PniQAA3v4IqDYUHvUR34XDsxbAYSg/idFUDw4S Vi9gJna19B8zKGSwg5X5XYuEp9r7C85L9L62xRq05Z4Ateo5piG7pvDDcLexYQtR44JN O2oQ== X-Gm-Message-State: AOJu0Yx4bhj7SK1BMqIiBfbmTrdlbAJ9efUIaZ02wOi97mpZ8xyKZ1en XykeaPoqoi+/2mkUjGoJw28jlorTNOCzG3tIYWiGOGckCqGWk7KtmheZtg== X-Google-Smtp-Source: AGHT+IHsXhFhEH+jURVd8CA4C2NFMSDx3+IR1pXgHDrbueGhEu/4TcyvsTGUfJIdRU9blDalnxE9gQ== X-Received: by 2002:a9d:6b98:0:b0:700:cdcf:d3ae with SMTP id 46e09a7af769-7034a7e8385mr624690a34.29.1720064797560; Wed, 03 Jul 2024 20:46:37 -0700 (PDT) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a15acsm8817239a12.43.2024.07.03.20.46.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 20:46:37 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Juri Lelli , Waiman Long , Tejun Heo , Lai Jiangshan Subject: [PATCH V2 2/5] workqueue: Make rescuer initialization as the last step of the creation of a new wq Date: Thu, 4 Jul 2024 11:49:11 +0800 Message-Id: <20240704034915.2164-3-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240704034915.2164-1-jiangshanlai@gmail.com> References: <20240704034915.2164-1-jiangshanlai@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan For early wq allocation, rescuer initialization is the last step of the creation of a new wq. Make the behavior the same for all allocations. Prepare for initializing rescuer's affinities with the default pwq's affinities. Prepare for moving the whole workqueue initializing procedure into wq_pool_mutex and cpu hotplug locks. Cc: Juri Lelli Cc: Waiman Long Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 904a1a6808b7..0c5dc7c06b81 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5690,9 +5690,6 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, if (alloc_and_link_pwqs(wq) < 0) goto err_free_node_nr_active; =20 - if (wq_online && init_rescuer(wq) < 0) - goto err_destroy; - /* * wq_pool_mutex protects global freeze state and workqueues list. * Grab it, adjust max_active and add the new @wq to workqueues @@ -5708,6 +5705,9 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, =20 mutex_unlock(&wq_pool_mutex); =20 + if (wq_online && init_rescuer(wq) < 0) + goto err_destroy; + if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq)) goto err_destroy; =20 --=20 2.19.1.6.gb485710b From nobody Fri Dec 19 10:57:20 2025 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EA2B3F9CC for ; Thu, 4 Jul 2024 03:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064804; cv=none; b=SwQ5DTQOYfmmnSmo4MVu4Uf/0Jo9AR5B5JW50XfenybrUI3WOsbenUGXYUwg4OMLHO8QTu4mtBl7YgnyPHCeCVy2wpGkICYhDTHAFjPy7dFoTookqVPcteLuz/AB6vXDNqqVi05mu8BNK7Ljd4ldNtio9RjD720Ck6e1c+vpVjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064804; c=relaxed/simple; bh=2hz8w6CnLDWNAJ0UImaMdvulcV4dgoKmxYQT2AaAy0M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZrCzg+fjTGnmf9YTzyrvXtnI4pFPB9rycO3TrNmtXex3Gvp9uqcOCOMeGta6MgVQyXG1zLxFROtuKYed+jkj+0OCVLOQz9H94xktxAr5jNMKiqXwIuziECABC8vHPuwpVkYiGghCunscV0vp0QS1Tdjo3xGjUwNEqIDMfOqZz+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q9UkG8j6; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q9UkG8j6" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3c9cc66c649so103230b6e.1 for ; Wed, 03 Jul 2024 20:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720064802; x=1720669602; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nL/uAUjz0QFR5irOqrlwan8U0RfC4351qVASkU+SBbc=; b=Q9UkG8j6Xk2T5xAkU8KPV+FL2hD6lc6NXMBESR/3xNVaHMSSTMPv77cZ4fBolgp4c3 Xd84Bfj0jhUObmZtRaqcEHJeDVZPT/MftIPajfNIm0PYwCNUCWfjFkuJs1/q5tijlitU QpX5JdmapgWOVa5S5/koRmGe53UneG50h4yPjiY9gIajCwyFFX1UGi/tW6wZ1QJCOFZK 4XFdPI2X5LRKJCJz9/TOvJmwbqKUeLBE0FspK0RkCgl/POdQ31L2OFD85KKnKtgD1OsT wuILtFhhQrx+OahYCWVMNxKdSHhLhsLFFizx9/tTIhQrgljP6lc4KH9Lpdkv3e+h9y5a /QiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720064802; x=1720669602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nL/uAUjz0QFR5irOqrlwan8U0RfC4351qVASkU+SBbc=; b=EQQGieHbnpA+Czg5j90KM41KYFsNjvYF645hAhx0hQ0Zi//ldlrlf90e//XZ9ub/XG X3T29AHTwSuqHOcE5JJGY1IXMNsmKu4yPTyBgmzP2rMKPDfXXVIw4iJlhWq1CoBZlrmp fYTn521K7YO2J04xM63JAjvkGuYc3AmrDMYp5VtaDOc8rF+qIsXATKvJJEcRUe/N95ET f3FxySjirhtysKX4IIeZmJ1wwqUUCZA+ZiXEXw1HEAX8c0CPGOlmjbhDMcOGc7C9ru/F 6u0rWQpM8L2TJ0QZu+0Eloesmj7puiuNVTMFa9j3VumKHBnMd+4/3LSxYp0dTYwnIKkx /7VQ== X-Gm-Message-State: AOJu0Yx1P3PUhLEQNclijb4fy1+omtkflRZ1QGRrXYvz3WqoJIABIsX5 3jagXk9HNZEGtPs7MSrVYdS8K3NE1dpaXn/qK16yVtaFHCj5dmWMsG9orQ== X-Google-Smtp-Source: AGHT+IEvrcb/9RX2ZoQl9IDvDfhpTacvk2PTnkEGZleuOdxfiQ4sQcPRFFUjpZAFAj1/SFbB5DX0VA== X-Received: by 2002:a05:6808:21a4:b0:3d2:257b:2b5e with SMTP id 5614622812f47-3d914ea9b18mr522949b6e.50.1720064801866; Wed, 03 Jul 2024 20:46:41 -0700 (PDT) Received: from localhost ([47.254.32.37]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-708044ac419sm11243008b3a.164.2024.07.03.20.46.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 20:46:41 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Zqiang , Tejun Heo , Lai Jiangshan Subject: [PATCH V2 3/5] workqueue: Move kthread_flush_worker() out of alloc_and_link_pwqs() Date: Thu, 4 Jul 2024 11:49:12 +0800 Message-Id: <20240704034915.2164-4-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240704034915.2164-1-jiangshanlai@gmail.com> References: <20240704034915.2164-1-jiangshanlai@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan kthread_flush_worker() can't be called with wq_pool_mutex held. Prepare for moving wq_pool_mutex and cpu hotplug lock out of alloc_and_link_pwqs(). Cc: Zqiang Link: https://lore.kernel.org/lkml/20230920060704.24981-1-qiang.zhang1211@g= mail.com/ Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 0c5dc7c06b81..cb496facf654 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5476,12 +5476,6 @@ static int alloc_and_link_pwqs(struct workqueue_stru= ct *wq) } cpus_read_unlock(); =20 - /* for unbound pwq, flush the pwq_release_worker ensures that the - * pwq_release_workfn() completes before calling kfree(wq). - */ - if (ret) - kthread_flush_worker(pwq_release_worker); - return ret; =20 enomem: @@ -5714,8 +5708,15 @@ struct workqueue_struct *alloc_workqueue(const char = *fmt, return wq; =20 err_free_node_nr_active: - if (wq->flags & WQ_UNBOUND) + /* + * Failed alloc_and_link_pwqs() may leave pending pwq->release_work, + * flushing the pwq_release_worker ensures that the pwq_release_workfn() + * completes before calling kfree(wq). + */ + if (wq->flags & WQ_UNBOUND) { + kthread_flush_worker(pwq_release_worker); free_node_nr_active(wq->node_nr_active); + } err_unreg_lockdep: wq_unregister_lockdep(wq); wq_free_lockdep(wq); --=20 2.19.1.6.gb485710b From nobody Fri Dec 19 10:57:20 2025 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA54D225CB for ; Thu, 4 Jul 2024 03:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064808; cv=none; b=NFxBeYcUr0mmwpm4mNJxfS70vfbRVwAoRHPpXC4psVz9T6WV6UOL3CrQUQ6CHo4W8NSoakJgLzXEni4octvUGA7l4phIY3C6wmg5MwZjznON2e+CPD/72HvOx8xsUlcaukRaegW9Um+4UylDRyvhnDHst0s4toSWmx5gS6lifos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064808; c=relaxed/simple; bh=F7aCnF4Je6kbJtXhbTta6MUDOKYAmrnnYkqPPL+OdX8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YcveuSrmvAC9KgckbyiW3NV7IrXwRIvZ4CFzKXRe9EtcFYEHBMRAnrJ5ctbiWSlTpoG6L1QoXIixgUKIncBIuReLMHtGpWVef4F6fH5kpwi5XIlzuM8MSSfxPyReiB3py+F2Wk8QOuaRRPnIsHvWAGuSPjVhxc3J0sA64pwOjGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c1b+7Sn0; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c1b+7Sn0" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3d55ec570a7so141153b6e.1 for ; Wed, 03 Jul 2024 20:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720064805; x=1720669605; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CFc3F8iNdhbsXcR87CPEXGUW+F2Z0/vpYoMjfJU+nAc=; b=c1b+7Sn08iKQBxj3vygk2r/8dYDoaGyW1AnuOcFi8ICJZBK7IGr9aJmY/8qW89Ah/O 30Gxiq5CcyufSQFUzD/MwaamKavgMBjz6nM/LO5FYpYgvhE4Ax8DUA0BnIe5oqS9lvLR l1/fK7mf9VWfrnWDIrmZvq/wH6Byno57etzOj2g2laV17Hv0cHfnzsOxJXNRCjPueTe7 WBDBcDsYpCIMwZHgaCNguCVgbIz01oI1OSKhJG4UOL6+jCcdr+jXiuI1apjLemvS7wNU 8p08qOzZV/UGGBYHS5jFO0vzFmpuRpN0565l6UccqPPp6fr+ERz4py9gEenIWlZNdri2 H0ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720064805; x=1720669605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CFc3F8iNdhbsXcR87CPEXGUW+F2Z0/vpYoMjfJU+nAc=; b=wHoJGPPpiB5GVaUt68rBe5TtOVDGlIF1PGOL+DHjf3HIWasKAFmIuUURmgZx6QF8r3 8+CR42ABAmSW7SSviOLMcL7T9RrvvUIBpD1ZRaCrt/+R1nHA/CwXPt9r/jKQEdslbbgL fqLr0pachVIteLGyx39j69W5/ZdP7tSN4KHEQhUy538UzHAMpQLeyEyO+EM7dI0UEcn3 TdXFRDJVcZLM/xCoz+qvFIq90zYGZhK6teQayWdl1Bje9YTF+nixSNEv5M0EVMl9u+tg Y6RCbdZ0fsyt8tTCetigyt+24F5SV5hgvEBs5j18/dgVAo3mI97UAGESAQFXJ6SE5MXM PYCQ== X-Gm-Message-State: AOJu0Yw1uZUBxvrne2unrTSARDISO7EDFqnd4qpcT7L78CVsdfAhc7UV ofgzqZHortvVaKvPtoak+AqLkFyLL0YKfXul4URZ+yylrNawV2qYeVNdhA== X-Google-Smtp-Source: AGHT+IHr9kVQSQ0C/2Y1zxG7e5f08OcfVUYRLKIS4fRNxZ4bcWIzCIteoUkl+uki7QIswFN/hozTDA== X-Received: by 2002:a05:6871:24d4:b0:25b:5032:25c5 with SMTP id 586e51a60fabf-25e2bf885a3mr413520fac.49.1720064805268; Wed, 03 Jul 2024 20:46:45 -0700 (PDT) Received: from localhost ([47.254.32.37]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70804a8ed66sm11198550b3a.194.2024.07.03.20.46.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 20:46:44 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Tejun Heo , Lai Jiangshan Subject: [PATCH V2 4/5] workqueue: Put PWQ allocation and WQ enlistment in the same lock C.S. Date: Thu, 4 Jul 2024 11:49:13 +0800 Message-Id: <20240704034915.2164-5-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240704034915.2164-1-jiangshanlai@gmail.com> References: <20240704034915.2164-1-jiangshanlai@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan The PWQ allocation and WQ enlistment are not within the same lock-held critical section; therefore, their states can become out of sync when the user modifies the unbound mask or if CPU hotplug events occur in the interim since those operations only update the WQs that are already in the list. Make the PWQ allocation and WQ enlistment atomic. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 54 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index cb496facf654..5129934f274f 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5118,6 +5118,19 @@ static struct pool_workqueue *alloc_unbound_pwq(stru= ct workqueue_struct *wq, return pwq; } =20 +static void apply_wqattrs_lock(void) +{ + /* CPUs should stay stable across pwq creations and installations */ + cpus_read_lock(); + mutex_lock(&wq_pool_mutex); +} + +static void apply_wqattrs_unlock(void) +{ + mutex_unlock(&wq_pool_mutex); + cpus_read_unlock(); +} + /** * wq_calc_pod_cpumask - calculate a wq_attrs' cpumask for a pod * @attrs: the wq_attrs of the default pwq of the target workqueue @@ -5429,6 +5442,9 @@ static int alloc_and_link_pwqs(struct workqueue_struc= t *wq) bool highpri =3D wq->flags & WQ_HIGHPRI; int cpu, ret; =20 + lockdep_assert_cpus_held(); + lockdep_assert_held(&wq_pool_mutex); + wq->cpu_pwq =3D alloc_percpu(struct pool_workqueue *); if (!wq->cpu_pwq) goto enomem; @@ -5461,20 +5477,18 @@ static int alloc_and_link_pwqs(struct workqueue_str= uct *wq) return 0; } =20 - cpus_read_lock(); if (wq->flags & __WQ_ORDERED) { struct pool_workqueue *dfl_pwq; =20 - ret =3D apply_workqueue_attrs(wq, ordered_wq_attrs[highpri]); + ret =3D apply_workqueue_attrs_locked(wq, ordered_wq_attrs[highpri]); /* there should only be single pwq for ordering guarantee */ dfl_pwq =3D rcu_access_pointer(wq->dfl_pwq); WARN(!ret && (wq->pwqs.next !=3D &dfl_pwq->pwqs_node || wq->pwqs.prev !=3D &dfl_pwq->pwqs_node), "ordering guarantee broken for workqueue %s\n", wq->name); } else { - ret =3D apply_workqueue_attrs(wq, unbound_std_wq_attrs[highpri]); + ret =3D apply_workqueue_attrs_locked(wq, unbound_std_wq_attrs[highpri]); } - cpus_read_unlock(); =20 return ret; =20 @@ -5681,15 +5695,15 @@ struct workqueue_struct *alloc_workqueue(const char= *fmt, goto err_unreg_lockdep; } =20 - if (alloc_and_link_pwqs(wq) < 0) - goto err_free_node_nr_active; - /* - * wq_pool_mutex protects global freeze state and workqueues list. - * Grab it, adjust max_active and add the new @wq to workqueues - * list. + * wq_pool_mutex protects the workqueues list, allocations of PWQs, + * and the global freeze state. alloc_and_link_pwqs() also requires + * cpus_read_lock() for PWQs' affinities. */ - mutex_lock(&wq_pool_mutex); + apply_wqattrs_lock(); + + if (alloc_and_link_pwqs(wq) < 0) + goto err_unlock_free_node_nr_active; =20 mutex_lock(&wq->mutex); wq_adjust_max_active(wq); @@ -5697,7 +5711,7 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, =20 list_add_tail_rcu(&wq->list, &workqueues); =20 - mutex_unlock(&wq_pool_mutex); + apply_wqattrs_unlock(); =20 if (wq_online && init_rescuer(wq) < 0) goto err_destroy; @@ -5707,7 +5721,8 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, =20 return wq; =20 -err_free_node_nr_active: +err_unlock_free_node_nr_active: + apply_wqattrs_unlock(); /* * Failed alloc_and_link_pwqs() may leave pending pwq->release_work, * flushing the pwq_release_worker ensures that the pwq_release_workfn() @@ -6996,19 +7011,6 @@ static struct attribute *wq_sysfs_attrs[] =3D { }; ATTRIBUTE_GROUPS(wq_sysfs); =20 -static void apply_wqattrs_lock(void) -{ - /* CPUs should stay stable across pwq creations and installations */ - cpus_read_lock(); - mutex_lock(&wq_pool_mutex); -} - -static void apply_wqattrs_unlock(void) -{ - mutex_unlock(&wq_pool_mutex); - cpus_read_unlock(); -} - static ssize_t wq_nice_show(struct device *dev, struct device_attribute *a= ttr, char *buf) { --=20 2.19.1.6.gb485710b From nobody Fri Dec 19 10:57:20 2025 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B5B228689 for ; Thu, 4 Jul 2024 03:46:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064810; cv=none; b=n4VSqaG51Ix5+U0MHNYSlSWsCiRZ+Ins50qD107c0fuRdiUKFSjk8FhJRWVI8izEF62gkW9+ElT1awiDugpL6icjNbdOjg5C/D4YSXni1nf2Xz1QsoxWsAcNefnk2hDZZRMGXyF3x31m85BBLdLKS6bUeYZWQlpL2TniEuWxMwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720064810; c=relaxed/simple; bh=K4rtmrLNi14w4YzsqMgiSYpk3M98BPsm1zUFfbKCC8g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sXKvOxFYp1S2JIOLoZnYrODtj7JYsXk3e7DIUzSFpPWn0q9ec8RTa7DySeH+c0T+yfwqo/hHSjdGhCVzLVQZdgW9hpkK8Stf4IhLaGlz+/pkuL6ZIQT1VJ79LBOHssXSZp3uBHTinW5ppRy8/vQcj8WfYAqUHfMrQTMywYC0RN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aQglAF+U; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aQglAF+U" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1f65a3abd01so1056765ad.3 for ; Wed, 03 Jul 2024 20:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720064809; x=1720669609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YEZIajJ5x1uDp1oDsc7fJuYQkx1ZEDuNq4jcMhzNBkY=; b=aQglAF+UePSccC7knU+fO9OZIocXRQ4RyyGgkRPCWwq/veuvTGQYrIkeW+bkgPHrW1 y+vsmlCFaFqEDVDP89GaDT7bALUCN+iqiR47rOI3qLVqOSgwEbh2qEeRvOwedAChARWP pmBnwUPR9mA/ye69H6mdvm4MKNkxiKK6zZXgH8FIWEmU6Xf6r2jfVEMAwUsuP/X5o+cQ GJtha/ARRqEv2xH9b4UDdIa5cpf50wIjdPm8alXC50WS/ZCm5pxSebXTBWkDEA4hHpHn FYGXEJM77WZ6lYNP8PphxhsySM0Nrui4NKLYomX4LObMtrdy5ZcG/gTyWDkwlv8NexzK ANEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720064809; x=1720669609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YEZIajJ5x1uDp1oDsc7fJuYQkx1ZEDuNq4jcMhzNBkY=; b=QER5RPC/OSj+jNt2bWO+u2bELpo6tDZj1X4mL508WlQmfO+GPfupw5paU6cBxpVBxz DS1j4DAbr7CKCOWMhR7N94LPEEsrpGVDXvKQUl2PnWaVNcnF8G2H+Xu87x0P2AbejBSi q17+Tmym+na/Z7/gBRdwC5xZDb9zlc//bzmqXW+2jMMY+k2xJhmKW+OV3VIDuh3YVLWN lfEiR4Kiquz33HNZ1cDaOQ3SzvTCwq1ItokXQ+tcX+nEmTGYoB+VD+fK2Z2jcF5auOlr z6ExrRzUoqbuuBlGHlxpHz+2DJhdtICnKC5No5PM+Au5GmcjXblHcVgVCqj2xgMNC4ZC +pcQ== X-Gm-Message-State: AOJu0YxLnvfaiNTI37TNMydaEsBizJoRwhwF3iS61RUraxZxv/EbBFv5 on7YKREbEhZ3+OG55JaX6vOVpaZbQ8E8Ms4C0Xed9Q1cGVY5fI6K7cSFQw== X-Google-Smtp-Source: AGHT+IGJCmlV38zkfWrTZnePXV+rycLN0IYhkk8Uty0VL/OySveC3cSxL49MkXd8yDUOHWGMy++Uow== X-Received: by 2002:a17:902:6548:b0:1fb:32fd:8d61 with SMTP id d9443c01a7336-1fb33f29a00mr3415785ad.68.1720064808485; Wed, 03 Jul 2024 20:46:48 -0700 (PDT) Received: from localhost ([47.88.5.130]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb24fbd598sm13033655ad.199.2024.07.03.20.46.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2024 20:46:48 -0700 (PDT) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Juri Lelli , Waiman Long , Tejun Heo , Lai Jiangshan Subject: [PATCH V2 5/5] workqueue: Init rescuer's affinities as the wq's effective cpumask Date: Thu, 4 Jul 2024 11:49:14 +0800 Message-Id: <20240704034915.2164-6-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20240704034915.2164-1-jiangshanlai@gmail.com> References: <20240704034915.2164-1-jiangshanlai@gmail.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 Content-Type: text/plain; charset="utf-8" From: Lai Jiangshan Make it consistent with apply_wqattrs_commit(). Link: https://lore.kernel.org/lkml/20240203154334.791910-5-longman@redhat.c= om/ Cc: Juri Lelli Cc: Waiman Long Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 5129934f274f..8b2a0fe4a85e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5525,6 +5525,8 @@ static int init_rescuer(struct workqueue_struct *wq) struct worker *rescuer; int ret; =20 + lockdep_assert_held(&wq_pool_mutex); + if (!(wq->flags & WQ_MEM_RECLAIM)) return 0; =20 @@ -5547,7 +5549,7 @@ static int init_rescuer(struct workqueue_struct *wq) =20 wq->rescuer =3D rescuer; if (wq->flags & WQ_UNBOUND) - kthread_bind_mask(rescuer->task, wq_unbound_cpumask); + kthread_bind_mask(rescuer->task, unbound_effective_cpumask(wq)); else kthread_bind_mask(rescuer->task, cpu_possible_mask); wake_up_process(rescuer->task); @@ -5711,10 +5713,10 @@ struct workqueue_struct *alloc_workqueue(const char= *fmt, =20 list_add_tail_rcu(&wq->list, &workqueues); =20 - apply_wqattrs_unlock(); - if (wq_online && init_rescuer(wq) < 0) - goto err_destroy; + goto err_unlock_destroy; + + apply_wqattrs_unlock(); =20 if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq)) goto err_destroy; @@ -5739,6 +5741,8 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, free_workqueue_attrs(wq->unbound_attrs); kfree(wq); return NULL; +err_unlock_destroy: + apply_wqattrs_unlock(); err_destroy: destroy_workqueue(wq); return NULL; --=20 2.19.1.6.gb485710b