From patchwork Sat Feb 3 15:43:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 196330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1080097dyc; Sat, 3 Feb 2024 07:48:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfp/eNx3PWWSi9uWFU8zdHn1HQLlCZ8JDwSTajkhu6AUxMJNVEcJWjb3WqtDymEF32c3hQ X-Received: by 2002:a17:90a:6b47:b0:290:28f8:f5a7 with SMTP id x7-20020a17090a6b4700b0029028f8f5a7mr2350777pjl.12.1706975316950; Sat, 03 Feb 2024 07:48:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706975316; cv=pass; d=google.com; s=arc-20160816; b=NVO9r19UdKimyw4nlIwkmGhK78PszceJbhmDgJ0ajMCfV9KAScpp5EEslivtOAm6jP TbxyuxkLurIUsAAPTtHXzBdZBPaoUPXTDM402E1drhnSzFOmxpEm5eNgLhnpWb0tcrxK OFYiH2jjOcZPiq2ZdyCO3AAVB4U8MXRVOwEZN6/puNuUL3Fwpme8A2+mtqQWP5aYGzxh T2IFUs7YakUykTC574eMq7KJrErHCg+OJqC1b6RlvJgX2DAYW/mNMnlNXzWCZmw5i0py t4Wgp7qxIg5sqwsmV8Q0926K76bA62ELs++CtGxMVIx2Q2mPzahOqfAqe9GjH3lBZghM NUMg== 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=Qd3lbhuW8fX+DsS5188RrMwd7iN3OLF290p+wTUe/dc=; fh=c7zAGiTr3EddLHefKkk6vbXRbv2YklXim+VHcQ5b5Gg=; b=HIku0ZNY3lWtX+NxlXWFRUqDXIADBvq9/6mUgHm7AJHg8In+/0D9h7tq6C1C5wtjnH K5hzw4ld+VJWzbiPPGdae96GXV34Qhcc6pAoIQ99wQyo4ZR8QvbWeuqtlp7JDXzh619v gSTYrSQDsOON5ncNZOqiy/CMxqybYHDJn2UT0m3qI3Ml95f1PKBhDyDBEBFUgcWg8/uV zSdd9pbWYXmv2BhAG3HuAZpC3Lijkh3ttbUteDg5L8M/h6u/jQnaJGL4wPIx06uOj4gn PagsooPt+XRwH+QuZ3zY0FgncSEWWATFIc5kqZxcwBPAwi2bl9nPp/v/fnKG5a+fP81w xH6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UN3lK1be; 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-51156-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51156-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWk/co/YxdzUBcp9wscQr/o8MbXVuvQ0al3iiQn3hGopQ65G30EjsR720+aq3SYLz4h8A3q4K/sc1SDcYiZ0jISUPQa3Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 21-20020a170902e9d500b001d781dc0f70si3350333plk.591.2024.02.03.07.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 07:48:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51156-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UN3lK1be; 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-51156-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51156-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8A4E0B22C59 for ; Sat, 3 Feb 2024 15:44:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE0035F87A; Sat, 3 Feb 2024 15:44:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UN3lK1be" 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 7D9F75F557 for ; Sat, 3 Feb 2024 15:44:04 +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=1706975046; cv=none; b=VRgUPQIJG5Mzfn7V1l8PpdfzTdPMrXtRgtcdu5H06zRSPnb+7N3PTVg7mk6TroMQUPlLo29ZBqiychHb3En/EbVi2EoDwGM6vaoctPnpD0xJOqbbovZjoqy40rao/Qw+ITdwUnO7NVmCiJicW6LpzovOi/230Lwo+knqu/6Sbq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706975046; c=relaxed/simple; bh=N0NFN9G6d8VckDtQzeRTKSXMqsIlgHOkxLBCqDdAB+Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=il4Sa6mfIUTG/EW+ZGY8hJ+QA+5a5gYJJpwLOSE6kqdVYK5lu80p2GQXt43zQKXu6AEKbRXLsXEudfssY/9ClEYGPwEbWwxGxxFAOMtCDDIMzWjJHCmJ9fPdzuhri14wPVHkFALMiOCl1lpxmCQ61jg7sZK7OPNvDVutskLSq8o= 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=UN3lK1be; arc=none smtp.client-ip=170.10.133.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=1706975043; 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=Qd3lbhuW8fX+DsS5188RrMwd7iN3OLF290p+wTUe/dc=; b=UN3lK1beGPMzr4dsr0b9cKs1uKH4G8ZD4wM/6pq5boXAdvfSSB9ecrL9+gYDoiyWojaTF3 iibRtWmVBWp1TxO/Dy+8o6zt8nXsVt86g4EY9QNtODUIcx8W//QiaB+R2bU0OflAioNEkH EnxD8VlM8ve11EB+dtVP3xgDatRq5oI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-XtEwpxLtMrWxLbKcxe-wAw-1; Sat, 03 Feb 2024 10:43:59 -0500 X-MC-Unique: XtEwpxLtMrWxLbKcxe-wAw-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 39BB73C0C136; Sat, 3 Feb 2024 15:43:59 +0000 (UTC) Received: from llong.com (unknown [10.22.32.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8BA5492BC6; Sat, 3 Feb 2024 15:43:58 +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 1/5] workqueue: Skip __WQ_DESTROYING workqueues when updating global unbound cpumask Date: Sat, 3 Feb 2024 10:43:30 -0500 Message-Id: <20240203154334.791910-2-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: 1789893349894194699 X-GMAIL-MSGID: 1789893349894194699 Skip updating workqueues with __WQ_DESTROYING bit set when updating global unbound cpumask to avoid unnecessary work and other complications. Signed-off-by: Waiman Long --- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ffb625db9771..7ef393f4012e 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -6313,7 +6313,7 @@ static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask) lockdep_assert_held(&wq_pool_mutex); list_for_each_entry(wq, &workqueues, list) { - if (!(wq->flags & WQ_UNBOUND)) + if (!(wq->flags & WQ_UNBOUND) || (wq->flags & __WQ_DESTROYING)) continue; /* creating multiple pwqs breaks ordering guarantee */ From patchwork Sat Feb 3 15:43:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 196331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1080244dyc; Sat, 3 Feb 2024 07:49:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbaejeGRxo3phkzGTrgXLG4sI9FN9uybHXi16hmrqUhnhZEljVgAC56Au7KZeOoM13zWZG X-Received: by 2002:a17:903:484:b0:1d9:7729:2a6f with SMTP id jj4-20020a170903048400b001d977292a6fmr3944007plb.61.1706975347603; Sat, 03 Feb 2024 07:49:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706975347; cv=pass; d=google.com; s=arc-20160816; b=XOEW+UA4xzFLwoLE9DZwVlxjQZqqScaCY++N29ugz8uIloiHwLDoSZgdoFlmQV4NaH EuTdwDKUebrtUFtdlU+fcnnJohJcvKmtsYlaigKXiFJa7zURfBCQAmEXi1bLRMp7HcYN sGOB7PmtlooOCEFMe0LymnSVb+XQIjV7NpaqTypPtxP/Vhn6HDE4BEdn+AwwX0trN9vs UaT5Zhjp7vO5BSuNUQK0HyWa44r4VUsQA2TnmBiUwF47oun93QTZruKGtMOfs1e9qu+m VgFtci2PtWfomQ9tFaptnzEo55DB3uKdVOYtbUHjX+E48Dw+bxrxLhSaAwzinUGESwY4 +oRQ== 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=xqI95iFKnrWkwe8wbz452OkEw/9Fkjl9mFJelsPsD1I=; fh=AHHn5AclAEYDGG1RjYqEr7SZ0UGK/ebqc60usFFT+8w=; b=J15X17/qb8Ds8VqZCHa533Itb9pTYwLp30RPsOx+ELr2vXQ1xTVHlH5spNYoBYSY8H bqY+opDuqisuy4SSeJ4/YUa16ULUMNptOczDMaFn4L9acPcoIPIGHL5i3SHAGV+U6kVa fNFiTD2UIRL+eTMMWlJN57qAL4H+EmudGh0MSUiCywPyfs6F+jjGHzmZVG+ocj0UJs4B vG2R30DG2PPVgvdfJgxOMltDGD8m36GpeiyRqXG+zuSxpLpRMAIMxONLTeqpW/gf38xU zJLDaVJCXkHDSktC6QYU3iHtU0x4vsVg1tcYk6ICXxwUpGo5zI1eG6qqGKYMskoDPANa e+DQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TQUXn5fm; 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-51157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51157-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCU+Xq6jjwULwf5sZcsdt8dx5NG0CAL45WOmaDwX6Dw2E6x4pX0TNqfAmEPRau/ywk22sb/uANPtlLyes/msRnOlhxCQdA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id jg1-20020a17090326c100b001d6f7875f69si3393288plb.380.2024.02.03.07.49.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 07:49:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TQUXn5fm; 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-51157-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51157-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 55CD5B25747 for ; Sat, 3 Feb 2024 15:45:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE6BD5FBBA; Sat, 3 Feb 2024 15:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TQUXn5fm" 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 B002A5F549 for ; Sat, 3 Feb 2024 15:44:04 +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=1706975046; cv=none; b=tCWziBbzkfYvwIuTht4sJxbzDeD+Y6g0OERN8uHty7oq5T0y8iTo25xM3OBxpm9k0cMSAnuQJhzb6o210p97eFJGDRVZ2yBriDRmDppR1qtUkhucz4LfUGGtq4Y5btDkA4uQysjyqn2mYrDWkx9ITKhQhuAc66y1UJjfYuBThJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706975046; c=relaxed/simple; bh=P0fDczSqjm+4VoEPMcjEIqr0fOERQ7HRV0xJuzSw7Sw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=apeEqKu66IDlxeMuio3AsxscXrv+LZGsrQohiP5PfUpzFcOTLAg4JOcyVmcIB3iVj3KJ7whMtlrQx8bv8wgpSsrt+0hUE66CW0xlyNYGS91EYTqHZ+YK4tB0AD/9K3990lZ2V7Sa5UYN03aM7tTPHmQ0CD5KxfxV9setd2rvwtk= 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=TQUXn5fm; arc=none smtp.client-ip=170.10.133.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=1706975043; 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=xqI95iFKnrWkwe8wbz452OkEw/9Fkjl9mFJelsPsD1I=; b=TQUXn5fmTUy20KWzZKT077IM+kL4649wFqBTa1kFro1Ns0i7bAUyeuE+75x5lMHcMYBLFD rpkC2icXiFk6yF4/CePTZcJuKhWModAKQo2RgvUOFuzcbWA2f5H5GZa6um7LtB1NaeSEHG FOsWi23RKpuuddD4cg5Ci/QnI2s3cDE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-134-yHwX9ymmOlquW_3aGoaEYQ-1; Sat, 03 Feb 2024 10:44:00 -0500 X-MC-Unique: yHwX9ymmOlquW_3aGoaEYQ-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 C2467383DBE0; Sat, 3 Feb 2024 15:43:59 +0000 (UTC) Received: from llong.com (unknown [10.22.32.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 496A6492BC6; 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 2/5] workqueue: Enable unbound cpumask update on ordered workqueues Date: Sat, 3 Feb 2024 10:43:31 -0500 Message-Id: <20240203154334.791910-3-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: 1789893315001443703 X-GMAIL-MSGID: 1789893382199844932 Ordered workqueues does not currently follow changes made to the global unbound cpumask because per-pool workqueue changes may break the ordering guarantee. IOW, a work function in an ordered workqueue may run on an isolated CPU. This patch enables ordered workqueues to follow changes made to the global unbound cpumask by temporaily freeze the newly allocated pool_workqueue by using the new frozen flag to freeze execution of newly queued work items until the old pwq has been properly flushed. This enables ordered workqueues to follow the unbound cpumask changes like other unbound workqueues at the expense of some delay in execution of work functions during the transition period. Signed-off-by: Waiman Long --- kernel/workqueue.c | 93 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 13 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7ef393f4012e..f089e532758a 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -242,6 +242,7 @@ struct pool_workqueue { int refcnt; /* L: reference count */ int nr_in_flight[WORK_NR_COLORS]; /* L: nr of in_flight works */ + int frozen; /* L: temporarily frozen */ /* * nr_active management and WORK_STRUCT_INACTIVE: @@ -1667,6 +1668,9 @@ static bool pwq_tryinc_nr_active(struct pool_workqueue *pwq, bool fill) lockdep_assert_held(&pool->lock); + if (pwq->frozen) + return false; + if (!nna) { /* per-cpu workqueue, pwq->nr_active is sufficient */ obtained = pwq->nr_active < READ_ONCE(wq->max_active); @@ -1747,6 +1751,21 @@ static bool pwq_activate_first_inactive(struct pool_workqueue *pwq, bool fill) } } +/** + * thaw_pwq - thaw a frozen pool_workqueue + * @pwq: pool_workqueue to be thawed + */ +static void thaw_pwq(struct pool_workqueue *pwq) +{ + unsigned long flags; + + raw_spin_lock_irqsave(&pwq->pool->lock, flags); + pwq->frozen = false; + if (pwq_activate_first_inactive(pwq, true)) + kick_pool(pwq->pool); + raw_spin_unlock_irqrestore(&pwq->pool->lock, flags); +} + /** * node_activate_pending_pwq - Activate a pending pwq on a wq_node_nr_active * @nna: wq_node_nr_active to activate a pending pwq for @@ -4595,6 +4614,14 @@ static void pwq_release_workfn(struct kthread_work *work) mutex_lock(&wq->mutex); list_del_rcu(&pwq->pwqs_node); is_last = list_empty(&wq->pwqs); + + /* + * For ordered workqueue with a frozen dfl_pwq, thaw it now. + */ + if (!is_last && (wq->flags & __WQ_ORDERED_EXPLICIT) && + wq->dfl_pwq->frozen) + thaw_pwq(wq->dfl_pwq); + mutex_unlock(&wq->mutex); } @@ -4758,10 +4785,30 @@ static void apply_wqattrs_cleanup(struct apply_wqattrs_ctx *ctx) { if (ctx) { int cpu; + bool refcheck = false; for_each_possible_cpu(cpu) put_pwq_unlocked(ctx->pwq_tbl[cpu]); + + /* + * For ordered workqueue with a frozen dfl_pwq and a reference + * count of 1 in ctx->dfl_pwq, it is highly likely that the + * refcnt will become 0 after the final put_pwq(). Acquire + * wq->mutex to ensure that the pwq won't be freed by + * pwq_release_workfn() when we check pwq later. + */ + if ((ctx->wq->flags & __WQ_ORDERED_EXPLICIT) && + ctx->wq->dfl_pwq->frozen && + (ctx->dfl_pwq->refcnt == 1)) { + mutex_lock(&ctx->wq->mutex); + refcheck = true; + } put_pwq_unlocked(ctx->dfl_pwq); + if (refcheck) { + if (!ctx->dfl_pwq->refcnt) + thaw_pwq(ctx->wq->dfl_pwq); + mutex_unlock(&ctx->wq->mutex); + } free_workqueue_attrs(ctx->attrs); @@ -4821,6 +4868,15 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, cpumask_copy(new_attrs->__pod_cpumask, new_attrs->cpumask); ctx->attrs = new_attrs; + /* + * For initialized ordered workqueues, there is only one pwq (dfl_pwq). + * Temporarily the frozen flag of ctx->dfl_pwq to freeze the execution + * of newly queued work items until execution of older work items in + * the old pwq has completed. + */ + if (!list_empty(&wq->pwqs) && (wq->flags & __WQ_ORDERED_EXPLICIT)) + ctx->dfl_pwq->frozen = true; + ctx->wq = wq; return ctx; @@ -4861,13 +4917,8 @@ static int apply_workqueue_attrs_locked(struct workqueue_struct *wq, if (WARN_ON(!(wq->flags & WQ_UNBOUND))) return -EINVAL; - /* creating multiple pwqs breaks ordering guarantee */ - if (!list_empty(&wq->pwqs)) { - if (WARN_ON(wq->flags & __WQ_ORDERED_EXPLICIT)) - return -EINVAL; - + if (!list_empty(&wq->pwqs) && !(wq->flags & __WQ_ORDERED_EXPLICIT)) wq->flags &= ~__WQ_ORDERED; - } ctx = apply_wqattrs_prepare(wq, attrs, wq_unbound_cpumask); if (IS_ERR(ctx)) @@ -6316,11 +6367,28 @@ static int workqueue_apply_unbound_cpumask(const cpumask_var_t unbound_cpumask) if (!(wq->flags & WQ_UNBOUND) || (wq->flags & __WQ_DESTROYING)) continue; - /* creating multiple pwqs breaks ordering guarantee */ + /* + * We does not support changing cpumask of an ordered workqueue + * again before the previous cpumask change is completed. + * Sleep up to 100ms in 10ms interval to allow previous + * operation to complete and skip it if not done by then. + */ if (!list_empty(&wq->pwqs)) { - if (wq->flags & __WQ_ORDERED_EXPLICIT) - continue; - wq->flags &= ~__WQ_ORDERED; + struct pool_workqueue *pwq = wq->dfl_pwq; + + if (!(wq->flags & __WQ_ORDERED_EXPLICIT)) { + wq->flags &= ~__WQ_ORDERED; + } else if (pwq && pwq->frozen) { + int i; + + for (i = 0; i < 10; i++) { + msleep(10); + if (!pwq->frozen) + break; + } + if (WARN_ON_ONCE(pwq->frozen)) + continue; + } } ctx = apply_wqattrs_prepare(wq, wq->unbound_attrs, unbound_cpumask); @@ -6836,9 +6904,8 @@ int workqueue_sysfs_register(struct workqueue_struct *wq) int ret; /* - * Adjusting max_active or creating new pwqs by applying - * attributes breaks ordering guarantee. Disallow exposing ordered - * workqueues. + * Adjusting max_active breaks ordering guarantee. Disallow exposing + * ordered workqueues. */ if (WARN_ON(wq->flags & __WQ_ORDERED_EXPLICIT)) return -EINVAL; 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)) From patchwork Sat Feb 3 15:43:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 196329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1078847dyc; Sat, 3 Feb 2024 07:45:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbyxp35EbLYgI5LREdLRhgB4U+I8MnoJWtBC/6AazQ5A7ESwvLnhvWdsl2EtfYmsY9vXSN X-Received: by 2002:a05:6214:5192:b0:68c:6b44:1f25 with SMTP id kl18-20020a056214519200b0068c6b441f25mr1598296qvb.52.1706975132080; Sat, 03 Feb 2024 07:45:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706975132; cv=pass; d=google.com; s=arc-20160816; b=LC7xYqKY0M2RwfeKQh2CEZb9d44/aDh+QxR14qtd0/k1na3wLvUhHrnSwzY4bviqGO /G7sHNvzSgLGP2Qt03RSy0yquVrhvwjOrFCRfmmcppSScj3xfgcMnGmf2nLU1SeRYyQO mMjgHSLYwpMkxrsR42FrjTEvcfdj016eF83j84ahTz5lwlGUoAqMACGV8NKncvPanUkC CRPE4xiIyoDeiW5wYJUJzsFk2WgTUjbGlh7Bfh6b94J1P71XRGXe5gl/JT9AOzT4PNdX ozlnTYRweHeK21Xax4IK/u6A81Cjc1v1r2oULznn1pP2f67v19lPzu4naqg7YPxUWPpB WTVQ== 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=X2395hdNLA+e2lfzBFwx2gFoDSFHPhjOE9LGsAepU2M=; fh=O+wAIWxw/3tRiArgHolQY1Yj974mwZKEDn4H3a8Y8cg=; b=0PaiPJrnGmn/C+R7pZk9639C48ASlUlE9weYT395i6+zI7L05b7LHB7R1qstBXkDrp 0INDZ57EC0G7CQIpc1VoIkWQ3uURwz0S0NciyamSakIH22mcI8EqZSgB/P/ODeNfeoj7 3l0D6VGzt6jHxs22A8D2geNCVRrduF9f+7mGVsOfk+Pr060VLiBsssStO1Osfh3XluU7 DfSz9f3jcYBf4eVSf1/thdzt05VBJtLMecqv1LeUTivyKuYn/H1pBHy4+l+43HPhn+Ks 01Ixd0AI6SygsLG5CT3EFNTSHuruppt9xvkVytqdQak3LnSqCAwLY1PRFDBOvcNKJjLV fgAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WjzxMAgk; 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-51158-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51158-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCUO9GGczBVBy5G61Hj+CqRksUYWJr2vT4nQzLdh0N8BIhdjhuSzkGvwuwApnQ0pXKmiZYYOlOXo31/NoXxSUVYrvLIn6g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n7-20020a0cfbc7000000b0068c45be246bsi4514586qvp.76.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:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51158-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WjzxMAgk; 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-51158-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51158-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B03D81C231F2 for ; Sat, 3 Feb 2024 15:45:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D0735FDBD; Sat, 3 Feb 2024 15:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WjzxMAgk" 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 6D7BD5F55E 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=dIWxxy10rmkNKE6BnZhuXTsoaXcrK5IXvfe3YHkD1PLH2DnJl3vxoLLjUBF0V2KRSDC7VOVBU99UpFcK8qGpukEPlGfm4pZzPgqqsMybot9UpESJpm8IKuChDNaU1W8lDGybBNqti4rM+e79Nmddl/EfxPjlJmxwdSJShp9Ffmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706975048; c=relaxed/simple; bh=h5QmlYtfNPJkR43xmQK8MmClp8+0FgNrfjWDooIF2m0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hI6Z0gZLxAieT32sIs6vOW6QMeYZKBAf/2/822iMShMCtTuvv1sJTNaC8PwTOkPL9S0YYbbIZBLaO83wmglGgzEQb0DJbW295MJHL6Icq6gVLaA4IyDINRcLunF38W93jlDCbhuilykEAxKnRHnP1KufvBaQQGnuXWs7jzITRG4= 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=WjzxMAgk; 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=X2395hdNLA+e2lfzBFwx2gFoDSFHPhjOE9LGsAepU2M=; b=WjzxMAgkj36pZ35fZ6xBRi93t2HvO53jHTZVM6VOjM+EAtUwjRCKhiyB6IVNpn3pIpgZ5w pQs1pVx8nJoU3rfC/fwWD8U4q6DifCDJ//hrVme7ZEeT3ps4KWTcBpnsmrI4WQd6Auevly 6b+aSadqgxXqOcnIAzwT5t3ka5bvgBo= 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-573-LSgab-vdNNS5dJajugvDTA-1; Sat, 03 Feb 2024 10:44:01 -0500 X-MC-Unique: LSgab-vdNNS5dJajugvDTA-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 DC44E10651AF; 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 64ECB492BC6; Sat, 3 Feb 2024 15:44:00 +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 4/5] kernel/workqueue: Let rescuers follow unbound wq cpumask changes Date: Sat, 3 Feb 2024 10:43:33 -0500 Message-Id: <20240203154334.791910-5-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: 1789893156122053754 X-GMAIL-MSGID: 1789893156122053754 From: Juri Lelli When workqueue cpumask changes are committed the associated rescuer (if one exists) affinity is not touched and this might be a problem down the line for isolated setups. Make sure rescuers affinity is updated every time a workqueue cpumask changes, so that rescuers can't break isolation. [longman: set_cpus_allowed_ptr() will block until the designated task is enqueued on an allowed CPU, no wake_up_process() needed. Also use the unbound_effective_cpumask() helper as suggested by Tejun.] Signed-off-by: Juri Lelli Signed-off-by: Waiman Long --- kernel/workqueue.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ee934c2c6ea8..172f7299aa71 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4905,6 +4905,11 @@ static void apply_wqattrs_commit(struct apply_wqattrs_ctx *ctx) /* update node_nr_active->max */ wq_update_node_max_active(ctx->wq, -1); + /* rescuer needs to respect wq cpumask changes */ + if (ctx->wq->rescuer) + set_cpus_allowed_ptr(ctx->wq->rescuer->task, + unbound_effective_cpumask(ctx->wq)); + mutex_unlock(&ctx->wq->mutex); } From patchwork Sat Feb 3 15:43:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 196327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1078822dyc; Sat, 3 Feb 2024 07:45:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHxPMKBACFlbPwRwMptvO04q6R5vhP3cfgwf3tNZCmzc0O6Echbof1wv4hDTVuJLFbfCFdr X-Received: by 2002:aa7:ccd6:0:b0:55f:cb7a:c9fb with SMTP id y22-20020aa7ccd6000000b0055fcb7ac9fbmr1994627edt.3.1706975129128; Sat, 03 Feb 2024 07:45:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706975129; cv=pass; d=google.com; s=arc-20160816; b=mk5nK15hN6m0Tv8cTuA3N2jPs1vAWR/YU7uFl4SzRXV2D0BuiSMQdxIDGOBrcDDsel 28uBJeDhK/Dp8LnNJfQOFlHDcRsbQSFgbpBqGnZSart3Y474xSaUVNwNqFUXQTxhQ3Hk LPHN5/QeZj4azbipAIhjIiXMWgaHxTa3bCjTMtYxUHQJ7+/M8FtlmxmZ1pqtKR8tyfuv qfFK90QJnlVg8gW1/XX3JGRwJSUFuDajmkLSaaTvpyjWnJDS+r6Cq++SjzfU+/C2lzya pX9TO2rIi27Euq8oxDSbjQMIFJuA2J2ZjaOvM6YhcbMGQE997lTjuQqPQM40kMZL0sZi HLTw== 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=ZE5SuTiC1eU6caXAnwVyMAj7DO/jK06d00aD2gGGC9Y=; fh=GjFTa+UfQ0HZH64ol4pbJXnwOWrBQpazNOg0Q8iYPI0=; b=jIjLyTWAm126dujQRXKKUk9S+kkTADvHMDwJDaMEp9Oid922bwnt1L6J+aB38SRa3G mxybPFm+FRxEMDECZFjp3I7Ljdfr7fwJHIhKYzqc2e6+kFQZRtjLP/wSIC0rszmVtFuO l320jBtnwePMorWmCaNU0o+pjmhxL/vZ3bzLz1UqqO7mwvcjhVzt1b9elkyL6GvV4WUJ OIrUCAmeiHusmRocz8VHvZPZVQ2G70MROmseKSNayFXhBzCNMKsD3qH/rlG+lKui8ULk MNwxsQFP7D9Y4AQr3fbe54NDHATh6kka/pLizz6Y/LJM0MS/o8XJzux6nhX6pDjEwX1x 1lQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="X7LUy/uz"; 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-51159-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51159-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCX07PDcukw7CjensOI7J//PVVeYOJGmKb2G7CJtoiZFS3JqPt3CESydHAG75adpEeGLBKQoFOOUlRd7aIecEdd6VEKTKg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h10-20020a50cdca000000b0055f46b6c9bfsi1936098edj.162.2024.02.03.07.45.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 07:45:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51159-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="X7LUy/uz"; 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-51159-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51159-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 AB8A21F2265E for ; Sat, 3 Feb 2024 15:45:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A5B45FDD8; 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="X7LUy/uz" 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 C8D4B5F844 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=Ai7Tqx5SSkJ2WN03IoaYN9XSzLpk3658wE3WYNyxXjxh064O/OExTS+04IZQpBSBPOVwyhEYEDS4e+2HIVNTVuIITMcD0HtKHMj52S6ysDddI9hifg2CI8+U/H5D+kzKYDuM/Tx1H1iX3QE1mMr0/oSPlrgLKC+5ybjbBKIaxFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706975048; c=relaxed/simple; bh=i6TPdcvT1TQK+CKu+xNdsdflEhMuYXP1v6ppPXqzfUY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NCoSI1LTkJ9Ij7HiX8XBlnghvFl47onquJbOSgcDmNh6DoN4/MwINVE9C7s/+pp2ysx2P6x+X2vY6uhg2UE9rrUUsKyJHBDpR5cS9OJDPwXFknea3igj+ku67sTN6K3YXPIFxWmqWaFUrsiWYpuu0pPEAGhPHsuzCLlDE+kB7N8= 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=X7LUy/uz; 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=ZE5SuTiC1eU6caXAnwVyMAj7DO/jK06d00aD2gGGC9Y=; b=X7LUy/uzVH5EXH2n/t6My/QPxHBhhzeFjPesyb1BeDWyZYucG8QvuZbXhkanu9NxnO2ITA R6Js1uhp6Cw+e8iw4hTp3SDnZ+cexYHPcDXJvsi7bjUcqGwJeK9AjvX9FmIgwGb6J/obev VTJRJg1DBcXNS5Gmk0goxFKqbe0UuKw= 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-583-kpxT-kJSPYyD4ihjCqYHlA-1; Sat, 03 Feb 2024 10:44:01 -0500 X-MC-Unique: kpxT-kJSPYyD4ihjCqYHlA-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 69864185A781; Sat, 3 Feb 2024 15:44:01 +0000 (UTC) Received: from llong.com (unknown [10.22.32.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB934492BC6; Sat, 3 Feb 2024 15:44:00 +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 5/5] workqueue: Bind unbound workqueue rescuer to wq_unbound_cpumask Date: Sat, 3 Feb 2024 10:43:34 -0500 Message-Id: <20240203154334.791910-6-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: 1789893153106961922 X-GMAIL-MSGID: 1789893153106961922 Commit 85f0ab43f9de ("kernel/workqueue: Bind rescuer to unbound cpumask for WQ_UNBOUND") modified init_rescuer() to bind rescuer of an unbound workqueue to the cpumask in wq->unbound_attrs. However unbound_attrs->cpumask's of all workqueues are initialized to cpu_possible_mask and will only be changed if it has the WQ_SYSFS flag to expose a cpumask sysfs file to be written by users. So this patch doesn't achieve what it is intended to do. If an unbound workqueue is created after wq_unbound_cpumask is modified and there is no more unbound cpumask update after that, the unbound rescuer will be bound to all CPUs unless the workqueue is created with the WQ_SYSFS flag and an user explicitly modified its cpumask sysfs file. Fix this problem by binding directly to wq_unbound_cpumask in init_rescuer(). Fixes: 85f0ab43f9de ("kernel/workqueue: Bind rescuer to unbound cpumask for WQ_UNBOUND") Signed-off-by: Waiman Long --- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 172f7299aa71..1e022899c13c 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5149,7 +5149,7 @@ static int init_rescuer(struct workqueue_struct *wq) wq->rescuer = rescuer; if (wq->flags & WQ_UNBOUND) - kthread_bind_mask(rescuer->task, wq->unbound_attrs->cpumask); + kthread_bind_mask(rescuer->task, wq_unbound_cpumask); else kthread_bind_mask(rescuer->task, cpu_possible_mask); wake_up_process(rescuer->task);