linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: torvalds@linux-foundation.org, mpatocka@redhat.com
Cc: linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev,
	msnitzer@redhat.com, ignat@cloudflare.com, damien.lemoal@wdc.com,
	bob.liu@oracle.com, houtao1@huawei.com, peterz@infradead.org,
	mingo@kernel.org, netdev@vger.kernel.org, allen.lkml@gmail.com,
	kernel-team@meta.com, Tejun Heo <tj@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	linux-usb@vger.kernel.org
Subject: [PATCH 5/8] usb: core: hcd: Convert from tasklet to BH workqueue
Date: Mon, 29 Jan 2024 23:11:52 -1000	[thread overview]
Message-ID: <20240130091300.2968534-6-tj@kernel.org> (raw)
In-Reply-To: <20240130091300.2968534-1-tj@kernel.org>

The only generic interface to execute asynchronously in the BH context is
tasklet; however, it's marked deprecated and has some design flaws. To
replace tasklets, BH workqueue support was recently added. A BH workqueue
behaves similarly to regular workqueues except that the queued work items
are executed in the BH context.

This patch converts usb hcd from tasklet to BH workqueue.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/core/hcd.c  | 23 ++++++++++++-----------
 include/linux/usb/hcd.h |  2 +-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 12b6dfeaf658..edf74458474a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1664,9 +1664,10 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
 	usb_put_urb(urb);
 }
 
-static void usb_giveback_urb_bh(struct tasklet_struct *t)
+static void usb_giveback_urb_bh(struct work_struct *work)
 {
-	struct giveback_urb_bh *bh = from_tasklet(bh, t, bh);
+	struct giveback_urb_bh *bh =
+		container_of(work, struct giveback_urb_bh, bh);
 	struct list_head local_list;
 
 	spin_lock_irq(&bh->lock);
@@ -1691,9 +1692,9 @@ static void usb_giveback_urb_bh(struct tasklet_struct *t)
 	spin_lock_irq(&bh->lock);
 	if (!list_empty(&bh->head)) {
 		if (bh->high_prio)
-			tasklet_hi_schedule(&bh->bh);
+			queue_work(system_bh_highpri_wq, &bh->bh);
 		else
-			tasklet_schedule(&bh->bh);
+			queue_work(system_bh_wq, &bh->bh);
 	}
 	bh->running = false;
 	spin_unlock_irq(&bh->lock);
@@ -1706,7 +1707,7 @@ static void usb_giveback_urb_bh(struct tasklet_struct *t)
  * @status: completion status code for the URB.
  *
  * Context: atomic. The completion callback is invoked in caller's context.
- * For HCDs with HCD_BH flag set, the completion callback is invoked in tasklet
+ * For HCDs with HCD_BH flag set, the completion callback is invoked in BH
  * context (except for URBs submitted to the root hub which always complete in
  * caller's context).
  *
@@ -1725,7 +1726,7 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
 	struct giveback_urb_bh *bh;
 	bool running;
 
-	/* pass status to tasklet via unlinked */
+	/* pass status to BH via unlinked */
 	if (likely(!urb->unlinked))
 		urb->unlinked = status;
 
@@ -1747,9 +1748,9 @@ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
 	if (running)
 		;
 	else if (bh->high_prio)
-		tasklet_hi_schedule(&bh->bh);
+		queue_work(system_bh_highpri_wq, &bh->bh);
 	else
-		tasklet_schedule(&bh->bh);
+		queue_work(system_bh_wq, &bh->bh);
 }
 EXPORT_SYMBOL_GPL(usb_hcd_giveback_urb);
 
@@ -2540,7 +2541,7 @@ static void init_giveback_urb_bh(struct giveback_urb_bh *bh)
 
 	spin_lock_init(&bh->lock);
 	INIT_LIST_HEAD(&bh->head);
-	tasklet_setup(&bh->bh, usb_giveback_urb_bh);
+	INIT_WORK(&bh->bh, usb_giveback_urb_bh);
 }
 
 struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
@@ -2926,7 +2927,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
 			&& device_can_wakeup(&hcd->self.root_hub->dev))
 		dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
 
-	/* initialize tasklets */
+	/* initialize BHs */
 	init_giveback_urb_bh(&hcd->high_prio_bh);
 	hcd->high_prio_bh.high_prio = true;
 	init_giveback_urb_bh(&hcd->low_prio_bh);
@@ -3036,7 +3037,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
 	mutex_unlock(&usb_bus_idr_lock);
 
 	/*
-	 * tasklet_kill() isn't needed here because:
+	 * flush_work() isn't needed here because:
 	 * - driver's disconnect() called from usb_disconnect() should
 	 *   make sure its URBs are completed during the disconnect()
 	 *   callback
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 00724b4f6e12..f698aac71de3 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -55,7 +55,7 @@ struct giveback_urb_bh {
 	bool high_prio;
 	spinlock_t lock;
 	struct list_head  head;
-	struct tasklet_struct bh;
+	struct work_struct bh;
 	struct usb_host_endpoint *completing_ep;
 };
 
-- 
2.43.0


  parent reply	other threads:[~2024-01-30  9:13 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  9:11 [PATCHSET wq/for-6.9] workqueue: Implement BH workqueue and convert several tasklet users Tejun Heo
2024-01-30  9:11 ` [PATCH 1/8] workqueue: Update lock debugging code Tejun Heo
2024-01-30  9:11 ` [PATCH 2/8] workqueue: Factor out init_cpu_worker_pool() Tejun Heo
2024-01-30  9:11 ` [PATCH 3/8] workqueue: Implement BH workqueues to eventually replace tasklets Tejun Heo
2024-01-30 17:25   ` Linus Torvalds
2024-02-01 11:02   ` Lai Jiangshan
2024-02-01 21:47     ` Tejun Heo
2024-02-02  1:15   ` [PATCH v2 " Tejun Heo
2024-02-04  2:20     ` Lai Jiangshan
2024-02-04 21:29   ` [PATCH v3 " Tejun Heo
2024-02-05  4:48     ` Hillf Danton
2024-02-05 17:47       ` Tejun Heo
2024-02-26  2:00     ` Boqun Feng
2024-02-26 18:47       ` Tejun Heo
2024-02-27  1:38       ` [PATCH for-6.9] workqueue: Drain BH work items on hot-unplugged CPUs Tejun Heo
2024-02-29 20:37         ` Tejun Heo
2024-02-29 21:07           ` Boqun Feng
2024-01-30  9:11 ` [PATCH 4/8] backtracetest: Convert from tasklet to BH workqueue Tejun Heo
2024-01-30  9:11 ` Tejun Heo [this message]
2024-01-30 16:38   ` [PATCH 5/8] usb: core: hcd: " Greg Kroah-Hartman
2024-02-20 17:25   ` Davidlohr Bueso
2024-02-20 17:55     ` Linus Torvalds
2024-02-20 18:19       ` Tejun Heo
2024-02-20 19:36       ` Davidlohr Bueso
2024-01-30  9:11 ` [PATCH 6/8] net: tcp: tsq: " Tejun Heo
2024-02-16  5:31   ` Tejun Heo
2024-02-16  8:23     ` Eric Dumazet
2024-02-16 15:52       ` David Wei
2024-02-16 16:24       ` Tejun Heo
2024-01-30  9:11 ` [PATCH 7/8] dm-crypt: " Tejun Heo
2024-01-30 10:46   ` Sebastian Andrzej Siewior
2024-01-30 15:53     ` Tejun Heo
2024-01-31 21:23   ` Mikulas Patocka
2024-01-30  9:11 ` [PATCH 8/8] dm-verity: " Tejun Heo
2024-01-31 21:19   ` Mikulas Patocka
2024-01-31 21:32     ` Tejun Heo
2024-01-31 22:02       ` Mikulas Patocka
2024-01-31 23:19       ` Linus Torvalds
2024-02-01  0:04         ` Tejun Heo
2024-02-01  0:19           ` Mike Snitzer
2024-02-20 19:44             ` Mike Snitzer
2024-02-20 20:05               ` Tejun Heo
2024-02-22 21:24                 ` Mike Snitzer
2024-02-23 17:22                   ` Tejun Heo
2024-02-01  0:07         ` Mike Snitzer
2024-01-30  9:22 ` [PATCHSET wq/for-6.9] workqueue: Implement BH workqueue and convert several tasklet users Tejun Heo
2024-01-30 10:20 ` Sebastian Andrzej Siewior
2024-01-30 15:50   ` Tejun Heo
2024-01-30 23:37 ` Allen
2024-02-04 21:33 ` Tejun Heo
2024-02-05 20:50   ` Allen
2024-02-05 21:12     ` Tejun Heo
2024-02-05 21:31       ` Allen
2024-02-07 19:02         ` Allen
2024-02-08 16:56           ` Tejun Heo
2024-02-08 19:07             ` Allen

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=20240130091300.2968534-6-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=allen.lkml@gmail.com \
    --cc=bob.liu@oracle.com \
    --cc=damien.lemoal@wdc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=houtao1@huawei.com \
    --cc=ignat@cloudflare.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=msnitzer@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).