FAILED: patch "[PATCH] memstick: ms_block: destroy io_queue workqueue on removal" failed to apply to 5.15-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 90af7fde083e1b22c349c3a8b1626728e44e474c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092239-justify-dizzy-3fd4@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 90af7fde083e1b22c349c3a8b1626728e44e474c Mon Sep 17 00:00:00 2001
From: Yifei Gao <[email protected]>
Date: Tue, 4 Aug 2026 21:34:56 +0000
Subject: [PATCH] memstick: ms_block: destroy io_queue workqueue on removal
msb_init_disk() creates the per-card ordered workqueue msb->io_queue with alloc_ordered_workqueue(). It is torn down with destroy_workqueue() only on the init error path; msb_remove() never destroys it. msb_stop() merely flushes the queue, and neither msb_data_clear() nor put_disk() free it. As a result every card insert/remove cycle leaks the workqueue and its kworker, exhausting kernel memory over repeated cycles.
Destroy the workqueue in msb_remove() after the disk has been removed and the queue drained.
drivers/memstick/core/ms_block.c +2 -0
@@ -2204,6 +2204,8 @@ static void msb_remove(struct memstick_dev *card)msb_data_clear (msb);mutex_unlock (&msb_disk_lock); +destroy_workqueue (msb->io_queue); +put_disk (msb->disk);memstick_set_drvdata (card,NULL ); }
Sasha Levin
maintainerPATCH 1/3 block: move blk_drop_partitions to blk.h
From: Christoph Hellwig <[email protected]>
[ Upstream commit e7243285c0fc87054990fcde630583586ff8ed5f ]
No need to have this declaration in a public header.
Stable-dep-of: 90af7fde083e ("memstick: ms_block: destroy io_queue workqueue on removal")
--- block/blk.h | 1 + include/linux/genhd.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)
block/blk.h +1 -0
@@ -350,6 +350,7 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,int bdev_del_partition (struct gendisk *disk,int partno);int bdev_resize_partition (struct gendisk *disk,int partno,sector_t start,sector_t length); +void blk_drop_partitions (struct gendisk *disk); int bio_add_hw_page(struct request_queue *q, struct bio *bio, struct page *page, unsigned int len, unsigned int offset,
include/linux/genhd.h +0 -1
@@ -235,7 +235,6 @@ static inline sector_t get_capacity(struct gendisk *disk) }int bdev_disk_changed (struct gendisk *disk,bool invalidate); -void blk_drop_partitions (struct gendisk *disk);struct gendisk *__alloc_disk_node (struct request_queue *q,int node_id,struct lock_class_key *lkclass);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 block: add a ->free_disk method
From: Christoph Hellwig <[email protected]>
[ Upstream commit 76792055c4c8b2472ca1ae48e0ddaf8497529f08 ]
Add a method to notify the driver that the gendisk is about to be freed. This allows drivers to tie the lifetime of their private data to that of the gendisk and thus deal with device removal races without expensive synchronization and boilerplate code.
A new flag is added so that ->free_disk is only called after a successful call to add_disk, which significantly simplifies the error handling path during probing.
Backport notes for 5.15:
- Keep GD_ADDED alongside struct gendisk in include/linux/genhd.h; this tree has not merged genhd.h into blkdev.h.
- Fold in the ms_block lifetime conversion from e2efa0796607e so that target 90af7fde083e applies unchanged before put_disk() in msb_remove(). Reuse the existing msb_disk_release() as the free_disk callback instead of introducing a new function. Drop the old open/release callbacks and usage_count; the gendisk reference now protects msb_data until final release. Preserve the 5.15 request-queue cleanup and probe error paths.
Stable-dep-of: 90af7fde083e ("memstick: ms_block: destroy io_queue workqueue on removal")
--- block/genhd.c | 5 ++++ drivers/memstick/core/ms_block.c | 47 +++++--------------------------- drivers/memstick/core/ms_block.h | 1 - include/linux/blkdev.h | 1 + include/linux/genhd.h | 1 + 5 files changed, 14 insertions(+), 41 deletions(-)
block/genhd.c +5 -0
@@ -529,6 +529,7 @@ int device_add_disk(struct device *parent, struct gendisk *disk,disk_update_readahead (disk);disk_add_events (disk); +set_bit (GD_ADDED , &disk->state);return 0 ; out_unregister_bdi:
@@ -1136,6 +1137,10 @@ static void disk_release(struct device *dev)xa_destroy (&disk->part_tbl); disk->queue->disk =NULL ;blk_put_queue (disk->queue); + +if (test_bit (GD_ADDED , &disk->state) && disk->fops->free_disk) + disk->fops->free_disk (disk); +iput (disk->part0->bd_inode);/* frees the disk */ }
drivers/memstick/core/ms_block.c +7 -40
84 lines not on this page · raw message
drivers/memstick/core/ms_block.h +0 -1
@@ -143,7 +143,6 @@ struct ms_boot_page { } __packed;struct msb_data { -unsigned int usage_count;struct memstick_dev *card;struct gendisk *disk;struct request_queue *queue;
include/linux/blkdev.h +1 -0
@@ -1859,6 +1859,7 @@ struct block_device_operations {void (*unlock_native_capacity) (struct gendisk *);int (*getgeo)(struct block_device *,struct hd_geometry *);int (*set_read_only)(struct block_device *bdev,bool ro); +void (*free_disk)(struct gendisk *disk);/* this callback is with swap_lock and sometimes page table lock held */ void (*swap_slot_free_notify) (struct block_device *,unsigned long ); int (*report_zones)(struct gendisk *, sector_t sector,
include/linux/genhd.h +1 -0
@@ -132,6 +132,7 @@ struct gendisk {#define GD_READ_ONLY 1#define GD_DEAD 2#define GD_NATIVE_CAPACITY 3 +#define GD_ADDED 4struct mutex open_mutex;/* open/close mutex */ unsigned open_partitions;/* number of open partitions */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 memstick: ms_block: destroy io_queue workqueue on removal
In reply to Sasha LevinFrom: Yifei Gao <[email protected]>
[ Upstream commit 90af7fde083e1b22c349c3a8b1626728e44e474c ]
msb_init_disk() creates the per-card ordered workqueue msb->io_queue with alloc_ordered_workqueue(). It is torn down with destroy_workqueue() only on the init error path; msb_remove() never destroys it. msb_stop() merely flushes the queue, and neither msb_data_clear() nor put_disk() free it. As a result every card insert/remove cycle leaks the workqueue and its kworker, exhausting kernel memory over repeated cycles.
Destroy the workqueue in msb_remove() after the disk has been removed and the queue drained.
--- drivers/memstick/core/ms_block.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/memstick/core/ms_block.c +2 -0
@@ -2208,6 +2208,8 @@ static void msb_remove(struct memstick_dev *card)msb_data_clear (msb);mutex_unlock (&msb_disk_lock); +destroy_workqueue (msb->io_queue); +put_disk (msb->disk);memstick_set_drvdata (card,NULL ); }
Signature · 1 line
2.53.0