mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Marco Crivellari <marco.crivellari@suse.com>,
	 linux-kernel@vger.kernel.org
Cc: Andy Whitcroft <apw@canonical.com>,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	 Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Tejun Heo <tj@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	 Michal Hocko <mhocko@suse.com>, Breno Leitao <leitao@debian.org>
Subject: Re: [PATCH] checkpatch: Check WQ_PERCPU or WQ_UNBOUND presence in alloc_workqueue() users
Date: Wed, 03 Jun 2026 22:08:43 -0700	[thread overview]
Message-ID: <8add4f780ec4861fba4e6bd77d50b384d32a642b.camel@perches.com> (raw)
In-Reply-To: <20260603140941.320063-1-marco.crivellari@suse.com>

On Wed, 2026-06-03 at 16:09 +0200, Marco Crivellari wrote:
> The workqueue API introduced a new flag, WQ_PERCPU, that has to be used when
> WQ_UNBOUND is not present. One of these flags must be present, but not
> both of them.
> 
> To limit usage mistakes, emit an ERROR if one of the below condition is met:
> - alloc_workqueue() is called without WQ_PERCPU nor WQ_UNBOUND
> - alloc_workqueue() is called with both WQ_PERCPU and WQ_UNBOUND
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7804,6 +7804,22 @@ sub process {
>  			ERROR("UNINITIALIZED_PTR_WITH_FREE",
>  			      "pointer '$1' with __free attribute should be initialized\n" . $herecurr);
>  		}
> +
> +# check alloc_workqueue() flags parameter (2nd argument) for WQ_PERCPU, WQ_UNBOUND presence
> +		if ($line =~ /\balloc_workqueue\s*\(/ &&
> +			$stat =~ /\balloc_workqueue\s*\(\s*[^,]+\s*,\s*([^,]+)/s) {
> +			my $flags = $1;
> +			my $has_percpu = $flags =~ /\bWQ_PERCPU\b/;
> +			my $has_unbound = $flags =~ /\bWQ_UNBOUND\b/;
> +
> +			if ($has_percpu && $has_unbound) {
> +				ERROR("ALLOC_WORKQUEUE_FLAGS",
> +				      "alloc_workqueue() second parameter should not contain both WQ_PERCPU and WQ_UNBOUND\n" . $herecurr);
> +			} elsif (!$has_percpu && !$has_unbound) {
> +				ERROR("ALLOC_WORKQUEUE_FLAGS",
> +				      "alloc_workqueue() second parameter should specify either WQ_PERCPU or WQ_UNBOUND\n" . $herecurr);
> +			}
> +		}
>  	}

OK but a couple comments:

Add devm_alloc_workqueue as well?

Avoid using $line here as $stat isn't populated on multi-line uses
of alloc_workqueue.  Just test $stat

Using the patch below gives a few matches treewide with a few
false positives as the flags are stored in a variable in
drivers/nvme/host/... and fs/btrfs/...

-----------------
block/blk-zoned.c
-----------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#1926: FILE: block/blk-zoned.c:1926:
+	disk->zone_wplugs_wq =
+		alloc_workqueue("%s_zwplugs", WQ_MEM_RECLAIM | WQ_HIGHPRI,
+				pool_size, disk->disk_name);

-----------------------------------------
drivers/gpu/drm/bridge/analogix/anx7625.c
-----------------------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#2851: FILE: drivers/gpu/drm/bridge/analogix/anx7625.c:2851:
+		platform->workqueue = alloc_workqueue("anx7625_work",
+						      WQ_FREEZABLE | WQ_MEM_RECLAIM, 1);

-------------------------------------
drivers/gpu/drm/nouveau/nouveau_drm.c
-------------------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#635: FILE: drivers/gpu/drm/nouveau/nouveau_drm.c:635:
+	drm->sched_wq = alloc_workqueue("nouveau_sched_wq_shared", 0,
+					WQ_MAX_ACTIVE);

---------------------------------------
drivers/gpu/drm/nouveau/nouveau_sched.c
---------------------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#417: FILE: drivers/gpu/drm/nouveau/nouveau_sched.c:417:
+		wq = alloc_workqueue("nouveau_sched_wq_%d", 0, WQ_MAX_ACTIVE,
+				     current->pid);

------------------------------------------
drivers/media/pci/ddbridge/ddbridge-core.c
------------------------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#3433: FILE: drivers/media/pci/ddbridge/ddbridge-core.c:3433:
+	ddb_wq = alloc_workqueue("ddbridge", 0, 0);

-------------------------------------
drivers/net/wireless/ath/ath6kl/usb.c
-------------------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#639: FILE: drivers/net/wireless/ath/ath6kl/usb.c:639:
+	ar_usb->wq = alloc_workqueue("ath6kl_wq", 0, 0);

------------------------
drivers/nvme/host/core.c
------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#5410: FILE: drivers/nvme/host/core.c:5410:
+	nvme_wq = alloc_workqueue("nvme-wq", wq_flags, 0);

ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#5414: FILE: drivers/nvme/host/core.c:5414:
+	nvme_reset_wq = alloc_workqueue("nvme-reset-wq", wq_flags, 0);

ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#5418: FILE: drivers/nvme/host/core.c:5418:
+	nvme_delete_wq = alloc_workqueue("nvme-delete-wq", wq_flags, 0);

---------------------
drivers/rapidio/rio.c
---------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#1997: FILE: drivers/rapidio/rio.c:1997:
+	rio_wq = alloc_workqueue("riodisc", 0, 0);

------------------------------
drivers/thermal/thermal_core.c
------------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#1892: FILE: drivers/thermal/thermal_core.c:1892:
+	thermal_wq = alloc_workqueue("thermal_events", WQ_POWER_EFFICIENT, 0);

-------------------------
drivers/virt/acrn/irqfd.c
-------------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#209: FILE: drivers/virt/acrn/irqfd.c:209:
+	vm->irqfd_wq = alloc_workqueue("acrn_irqfd-%u", 0, 0, vm->vmid);

------------------
fs/btrfs/disk-io.c
------------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#1950: FILE: fs/btrfs/disk-io.c:1950:
+	fs_info->endio_workers =
+		alloc_workqueue("btrfs-endio", flags, max_active);

ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#1952: FILE: fs/btrfs/disk-io.c:1952:
+	fs_info->endio_meta_workers =
+		alloc_workqueue("btrfs-endio-meta", flags, max_active);

ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#1954: FILE: fs/btrfs/disk-io.c:1954:
+	fs_info->rmw_workers = alloc_workqueue("btrfs-rmw", flags, max_active);

----------------
fs/btrfs/scrub.c
----------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#3050: FILE: fs/btrfs/scrub.c:3050:
+	scrub_workers = alloc_workqueue("btrfs-scrub", flags, max_active);

---------------
fs/ntfs/super.c
---------------
ERROR: alloc_workqueue() must specify either WQ_PERCPU or WQ_UNBOUND
#2652: FILE: fs/ntfs/super.c:2652:
+	ntfs_wq = alloc_workqueue("ntfs-bg-io", 0, 0);

---
 scripts/checkpatch.pl | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0492d6afc9a1..aed83ce4b552 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7804,6 +7804,31 @@ sub process {
 			ERROR("UNINITIALIZED_PTR_WITH_FREE",
 			      "pointer '$1' with __free attribute should be initialized\n" . $herecurr);
 		}
+
+# check alloc_workqueue() and devm_alloc_workqueue parameters for
+# WQ_PERCPU and WQ_UNBOUND uses
+		if (defined($stat) &&
+		    $stat =~ /^[ \+]\s*(?:$Lval\s*=\s*)?((?:devm_)?alloc_workqueue)\s*($balanced_parens)/) {
+			my $func = $1;
+			my $args = $2;
+			my $has_percpu = $args =~ /\bWQ_PERCPU\b/;
+			my $has_unbound = $args =~ /\bWQ_UNBOUND\b/;
+			my $error_msg;
+
+			if ($has_percpu && $has_unbound) {
+				$error_msg = "$func() should not contain both WQ_PERCPU and WQ_UNBOUND\n";
+			} elsif (!$has_percpu && !$has_unbound) {
+				$error_msg = "$func() must specify either WQ_PERCPU or WQ_UNBOUND\n";
+			}
+
+			if (defined($error_msg)) {
+				my $stmt_cnt = statement_rawlines($stat);
+				my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
+				ERROR("ALLOC_WORKQUEUE_FLAGS",
+				      $error_msg . $herectx);
+			}
+
+		}
 	}
 
 	# If we have no input at all, then there is nothing to report on

  reply	other threads:[~2026-06-04  5:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 14:09 Marco Crivellari
2026-06-04  5:08 ` Joe Perches [this message]
2026-06-04  9:31   ` Marco Crivellari
2026-06-04 14:09     ` Joe Perches
2026-06-04 14:18       ` Marco Crivellari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8add4f780ec4861fba4e6bd77d50b384d32a642b.camel@perches.com \
    --to=joe@perches.com \
    --cc=apw@canonical.com \
    --cc=dwaipayanray1@gmail.com \
    --cc=frederic@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=marco.crivellari@suse.com \
    --cc=mhocko@suse.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®