From patchwork Mon Feb 5 19:46:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 197019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1155615dyb; Mon, 5 Feb 2024 13:30:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYgOczuSwD7VB07whxjh0egcTOlF7FQN/+7lt4gsAXiJDTwJM4vjIGMPCjJdAEEph+9KFd X-Received: by 2002:a17:907:800e:b0:a37:1a8d:dfc1 with SMTP id ft14-20020a170907800e00b00a371a8ddfc1mr107214ejc.70.1707168604816; Mon, 05 Feb 2024 13:30:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707168604; cv=pass; d=google.com; s=arc-20160816; b=qQyUsitrGJqs3TG9ffOzBPHVgH2Nd2uSu8sqW3dOxK++ZxKcDqPFQNA4fFAwiLkmaA jL2bqav+lxgfo0HJAYXIlL5kKlFQOBBukCVLxK8kPU6GaMsmShvV4d7/1ijC9HPwqu2B dhGdkwkvQ1ktfF3FFQzVzIrmt7cZCRb4mLY5KcOpSwXzwzVc959uKtpQx3luGn+sWdzq B4aDY8U4vOdPnutg7seSUms/qUFBIef6TowUO9vphJKhfYLG/i3rno58bM5F9mssOzjd /Hx3HNM5w+ffjLnXBimpKebn66cinCpJlkrj328Kdf//ETu1rNihrR6NHso7gV1v+u8H 4P/w== 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=Tvk5P0YwhhGGdf9RGAqGeLDJl3BLaezVv7toWoOGyh0=; fh=iT+lcFfGbyckjy2FaSzGWDU4+vlwpEukFqQFx8tG8TQ=; b=IlrSOWO5AXhT+1obt45Sx25kHi8aCo1a4yuMcLAsh1yEIiYn3SW717N/V4oXz85FuK c3yKsvzVZsNh18nxz8qLE9HuyHfLj6GdNHbqk5vSXlMqveUPlcMSbHSmHtOsJa5BoMRf xishxhkwOhxKTbc/gsKG4XWjPcy8nUsqfqAGxGK2QTHLSiu3js1wW3Nziz3RATfJ0pY5 dzPqFTE/hr0CrIIugTucinUCDT+mDx+pgTbIFncMAFRHCnYiKcVMbHdnKiFSMG70S17g eqAZPcs4hcIn95yyu8RWfSsHVT8FVFqdgjnu9qSSiGL/Sj/W+fm1F0M+bZ9HmRfkDOMI SNXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UzUQ9UjJ; 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-53857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53857-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWBifaGJ2XMvb3dCFVydNpOMw3f/b6uCptk1u8niS9EVLyOZEwHQFDYufAJLkUlzcNmq3FClYmsWf4FDQ5kj7OTKN+8Yw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v21-20020a1709064e9500b00a37584ab2b4si265357eju.249.2024.02.05.13.30.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:30:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UzUQ9UjJ; 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-53857-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53857-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 616531F2A40E for ; Mon, 5 Feb 2024 21:30:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D315A7F49D; Mon, 5 Feb 2024 19:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UzUQ9UjJ" 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 5C4067CF18 for ; Mon, 5 Feb 2024 19:46:39 +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=1707162401; cv=none; b=dJKdlx72Q85YeRbKCT7xp/1xPzF+fbP/Zn1PAV9o0I/PInFra+7zmsMNMAHBB9bY+zB8sbSzlq3jAtx3Sp3M4EswjCVBR1BEiuGvEbYxoPYJ4nMeAN3JYchae834PMZT7O92KtLwmWJtOh6O56c0mBGlKrMEKbLXSFgqDjMGrXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707162401; c=relaxed/simple; bh=UBgB7wxdCAt+ad7SnQ4VhV8QrVhO4q6rF8Sg0R0cabs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CSnGwhaJ9OpFeUs5+R8/FCOYSzYD6QTLz+GL1xnFaWYD19kyQTWLpsSc9oL4N3WleW3IWzCt3cZQD3sEwChX7QrtGqKrYJUCz6hBATDAhUElIeNrn+9wgBtcZwdDdPIDCXqj17HiOSsNTpU6IBI43Vhkh7OTreb0AHLFV7XEswY= 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=UzUQ9UjJ; 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=1707162398; 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=Tvk5P0YwhhGGdf9RGAqGeLDJl3BLaezVv7toWoOGyh0=; b=UzUQ9UjJp/jRWZ1FFUih7Koif3FLob+rN6wAGXWblm1rU4JPbnt3HaKE11XEsk+PlfjdFO 1JMpQVFOUs68imuQfpyNeD8W0VZqwftDZ4kGYtk10SUyF7YtnUanlTQf3f0MbNteQDKjJG 4Ak9fFX4gK/XgH9FEVyAYBp5RXZwoKk= 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-653-gnYI3oETNTqqcyFngXnrCg-1; Mon, 05 Feb 2024 14:46:36 -0500 X-MC-Unique: gnYI3oETNTqqcyFngXnrCg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 7A5FA85A58C; Mon, 5 Feb 2024 19:46:36 +0000 (UTC) Received: from llong.com (unknown [10.22.17.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id 055931C060AF; Mon, 5 Feb 2024 19:46:35 +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 v3 2/4] workqueue: Thaw frozen pwq in workqueue_apply_unbound_cpumask() Date: Mon, 5 Feb 2024 14:46:00 -0500 Message-Id: <20240205194602.871505-3-longman@redhat.com> In-Reply-To: <20240205194602.871505-1-longman@redhat.com> References: <20240205194602.871505-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.7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790096027029278537 X-GMAIL-MSGID: 1790096027029278537 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 Tested-by: Juri Lelli --- kernel/workqueue.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 9b107e8a2c15..f453f339f74a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -6541,6 +6541,33 @@ 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) +{ + struct pool_workqueue *dfl_pwq = rcu_access_pointer(wq->dfl_pwq); + struct pool_workqueue *pwq; + int refs = 0; + + if (!READ_ONCE(dfl_pwq->frozen)) + return true; + mutex_lock(&wq->mutex); + for_each_pwq(pwq, wq) { + if (pwq == dfl_pwq) + continue; + refs += pwq->refcnt; + } + if (!refs) + thaw_pwq(dfl_pwq); + mutex_unlock(&wq->mutex); + return !refs; +} + static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask) { LIST_HEAD(ctxs); @@ -6566,12 +6593,12 @@ static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask) dfl_pwq = rcu_access_pointer(wq->dfl_pwq); if (!(wq->flags & __WQ_ORDERED_EXPLICIT)) { wq->flags &= ~__WQ_ORDERED; - } else if (dfl_pwq && dfl_pwq->frozen) { + } else if (dfl_pwq && !ordered_workqueue_ref_check(wq)) { int i; for (i = 0; i < 10; i++) { msleep(10); - if (!dfl_pwq->frozen) + if (ordered_workqueue_ref_check(wq)) break; } if (WARN_ON_ONCE(dfl_pwq->frozen))