From patchwork Sat Feb 3 15:43:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 196328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1078845dyc; Sat, 3 Feb 2024 07:45:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRECfKu+YnywnhsqGI6bBbjie8l1Y1Ga++jYocKBYPQeGpzcbXV7heXwXXaOmyGjYvOkoC X-Received: by 2002:a05:6a00:22c6:b0:6db:b094:8524 with SMTP id f6-20020a056a0022c600b006dbb0948524mr8850519pfj.28.1706975132033; Sat, 03 Feb 2024 07:45:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706975131; cv=pass; d=google.com; s=arc-20160816; b=JLMZ704roFxGrnO3xnRaKmc4R0aX4/K+CMr1Vukqf2T8M4pe5jAvPHlZFaRnxw2gvM SU+K/mjHZIdk/Xi2STskl8TJE/Ep64M1B+awyM7OZeIKT6cBs/W7vYp/7OQ9KOfJOmVW RTKztd0IUiy2ato7nZHjXX9AKkNVHtMeUPvc+CkCEMQI853tbI9FQYI430wOkoQXSkJd vtzrYyc+/QXHtJi2eqqgA/aHbV607sx+S6ZY/buNEE8QpkTfO0wi/xfKVowYdE6cpRNa j111p8JJ6xxRQmNitPyc/RetrvVlxhJ9eWtyXOIUHUGZXbAIvJxgeRmv8B5JoTeGlXZ1 8+xQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=z37S38Ac+FZG32K3ttyGhIlDZkrUn25fgqCMfEdj2WY=; fh=QbawulODGreSzsFbMlRrloBg1fkqj9L2TlDZatQbj78=; b=fMuCsT6nHkiC3Tvgk0DdHMEhU437Sh5IMEunQbkWM18eVhh5AgnhJQCZhgIQNAfZ3b yMyolR+1vYt6CwujodyE1EKZR5XHQU8ecHWL04KAWSV9f8vKppzRS8gvE2C6rRKJhgBW OA0olVLuKoPxnrpavjDBPS7IjaLtrV1xPe+lB9Y0ltqX24tkfwjLUmnmNWBJW6rOL6xs gb0qz7nEM/YOaog16MzQFtiJPOYW2iFCkCwUnQ5CjWDS+CW1PdY08v9BxXsPQzVav/pm GGyFEawmXOcLubIayDBxil1v2jWoQb00BGW+ynf9czdKERV9sWxfNoFlHnH6r75HU55J BrzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aBhH4ipD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-51160-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51160-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCVFvMHGP+fKA6kfgOzwI+VfMytwqUtgbfWS5KAnbeY1WVckZAiEYLKLpQ1b7mN8qyE9eQNY7FJWUHfAyydDrvSpfuqUyQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s10-20020a056a00194a00b006dd81e6e926si3405007pfk.264.2024.02.03.07.45.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 07:45:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51160-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aBhH4ipD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-51160-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51160-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BF09C284DE6 for ; Sat, 3 Feb 2024 15:45:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 706EB5FEEA; Sat, 3 Feb 2024 15:44:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aBhH4ipD" 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 6D7E85F579 for ; Sat, 3 Feb 2024 15:44:06 +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=1706975048; cv=none; b=HJGCmgRph4acVTXAwgtwYsvYVTiZLofZmg+iQTC0sCVCtDTlFOL7dfPTssuRz0HJYgcrvYL3VF8zth7PXlXRYUB50XY0YnZpvUrc6kaorUW5UDUL1/0EhN9CGMXrOsiQcPW61f8EUf9ivM2w3WJUujUHjmePeVsk6VOgXTAynfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706975048; c=relaxed/simple; bh=1jnXP20A8FTVhBfK5XMoOFBXtkTqsoRl3cBJhPND+Tg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bR/2f25UTt7qPHKoL/J+aq2Wx/rQhbrjtbXmvELpV2tBLE4F24V4hgynW8IeoapKS41ss1TVujBP+RJsmj5lRD7VBD6WeRQ/pdVW58iA8qPGLKmWhmRxqFTN9R0m5xk7b8kuaW5xel2NoKHrG6qU9cyG3TQNih8thhwKd1KIOpE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=aBhH4ipD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706975045; 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=z37S38Ac+FZG32K3ttyGhIlDZkrUn25fgqCMfEdj2WY=; b=aBhH4ipDEgoo8UXOSW7WmbWhPq9zVUBr1RB1JReM0I2qHV25bosFShNDkM++oHn+LNqiLO b3egrFqb1OMWR4oeWq18EgYNa42rGuuURj5vddWafBBPgCEwIU8smI9Y7AA7AKF88HdkyK X758m2z5hPhBi+/wM5dmaGOf4vjkvBc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-571-KRPLBrgKMu6TrTKsDj8DEA-1; Sat, 03 Feb 2024 10:44:00 -0500 X-MC-Unique: KRPLBrgKMu6TrTKsDj8DEA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 537488432A0; Sat, 3 Feb 2024 15:44:00 +0000 (UTC) Received: from llong.com (unknown [10.22.32.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id D413D492BC6; Sat, 3 Feb 2024 15:43:59 +0000 (UTC) From: Waiman Long To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Juri Lelli , Cestmir Kalina , Alex Gladkov , Phil Auld , Costa Shulyupin , Waiman Long Subject: [PATCH-wq v2 3/5] workqueue: Thaw frozen pwq in workqueue_apply_unbound_cpumask() Date: Sat, 3 Feb 2024 10:43:32 -0500 Message-Id: <20240203154334.791910-4-longman@redhat.com> In-Reply-To: <20240203154334.791910-1-longman@redhat.com> References: <20240203154334.791910-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789893155845327347 X-GMAIL-MSGID: 1789893155845327347 workqueue_apply_unbound_cpumask() cannot proceed with an ordered workqueue if its dfl_pwq is still frozen. Just do a sleep wait for it to be thawed may not work in some cases if pwq_release_workfn() is somehow prevented from being called due to resources (e.g. wq_pool_mutex) that are held by its caller. To break the logjam, we have to actively check if the frozen dfl_pwq is ready to be thawed and call thaw_pwq() directly if so. Signed-off-by: Waiman Long --- kernel/workqueue.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index f089e532758a..ee934c2c6ea8 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -6354,6 +6354,32 @@ void thaw_workqueues(void) } #endif /* CONFIG_FREEZER */ +/* + * Check the given ordered workqueue to see if its non-default pwq's have + * zero reference count and if so thaw the frozen default pwq. + * + * Return: + * %true if dfl_pwq has been thawed or %false otherwise. + */ +static bool ordered_workqueue_ref_check(struct workqueue_struct *wq) +{ + int refs = 0; + struct pool_workqueue *pwq; + + if (!READ_ONCE(wq->dfl_pwq->frozen)) + return true; + mutex_lock(&wq->mutex); + for_each_pwq(pwq, wq) { + if (pwq == wq->dfl_pwq) + continue; + refs += pwq->refcnt; + } + if (!refs) + thaw_pwq(wq->dfl_pwq); + mutex_unlock(&wq->mutex); + return !refs; +} + static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask) { LIST_HEAD(ctxs); @@ -6378,12 +6404,12 @@ static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask) if (!(wq->flags & __WQ_ORDERED_EXPLICIT)) { wq->flags &= ~__WQ_ORDERED; - } else if (pwq && pwq->frozen) { + } else if (pwq && !ordered_workqueue_ref_check(wq)) { int i; for (i = 0; i < 10; i++) { msleep(10); - if (!pwq->frozen) + if (ordered_workqueue_ref_check(wq)) break; } if (WARN_ON_ONCE(pwq->frozen))