* FAILED: patch "[PATCH] memstick: ms_block: destroy io_queue workqueue on removal" failed to apply to 5.15-stable tree
@ 2026-09-22 9:36 gregkh
2026-09-22 16:48 ` [PATCH 5.15.y 1/3] block: move blk_drop_partitions to blk.h Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2026-09-22 9:36 UTC (permalink / raw)
To: gyf161023, ulfh; +Cc: stable
The 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 <stable@vger.kernel.org>.
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 '<stable@vger.kernel.org>' --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 <gyf161023@gmail.com>
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.
Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Yifei Gao <gyf161023@gmail.com>
Signed-off-by: Ulf Hansson <ulfh@kernel.org>
diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
index ce33907bfc24..65154e569a9e 100644
--- a/drivers/memstick/core/ms_block.c
+++ b/drivers/memstick/core/ms_block.c
@@ -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);
}
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 5.15.y 1/3] block: move blk_drop_partitions to blk.h 2026-09-22 9:36 FAILED: patch "[PATCH] memstick: ms_block: destroy io_queue workqueue on removal" failed to apply to 5.15-stable tree gregkh @ 2026-09-22 16:48 ` Sasha Levin 2026-09-22 16:48 ` [PATCH 5.15.y 2/3] block: add a ->free_disk method Sasha Levin 2026-09-22 16:48 ` [PATCH 5.15.y 3/3] memstick: ms_block: destroy io_queue workqueue on removal Sasha Levin 0 siblings, 2 replies; 4+ messages in thread From: Sasha Levin @ 2026-09-22 16:48 UTC (permalink / raw) To: stable Cc: Christoph Hellwig, Chaitanya Kulkarni, Martin K. Petersen, Jens Axboe, Sasha Levin From: Christoph Hellwig <hch@lst.de> [ Upstream commit e7243285c0fc87054990fcde630583586ff8ed5f ] No need to have this declaration in a public header. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Link: https://lore.kernel.org/r/20220124093913.742411-3-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk> Stable-dep-of: 90af7fde083e ("memstick: ms_block: destroy io_queue workqueue on removal") Signed-off-by: Sasha Levin <sashal@kernel.org> --- block/blk.h | 1 + include/linux/genhd.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk.h b/block/blk.h index 07f571e1ece0a..395aba99026e5 100644 --- a/block/blk.h +++ b/block/blk.h @@ -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, diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 3f49a3a30e9bc..ccad6b4b5d289 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -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); -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 5.15.y 2/3] block: add a ->free_disk method 2026-09-22 16:48 ` [PATCH 5.15.y 1/3] block: move blk_drop_partitions to blk.h Sasha Levin @ 2026-09-22 16:48 ` Sasha Levin 2026-09-22 16:48 ` [PATCH 5.15.y 3/3] memstick: ms_block: destroy io_queue workqueue on removal Sasha Levin 1 sibling, 0 replies; 4+ messages in thread From: Sasha Levin @ 2026-09-22 16:48 UTC (permalink / raw) To: stable; +Cc: Christoph Hellwig, Jens Axboe, Sasha Levin From: Christoph Hellwig <hch@lst.de> [ 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. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20220215094514.3828912-2-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk> 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") Signed-off-by: Sasha Levin <sashal@kernel.org> --- 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(-) diff --git a/block/genhd.c b/block/genhd.c index 717234acee49c..19cd50af5930c 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -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 */ } diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c index 7e02bb33577bd..0486bbb10e44d 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -1947,22 +1947,6 @@ static void msb_io_work(struct work_struct *work) static DEFINE_IDR(msb_disk_idr); /*set of used disk numbers */ static DEFINE_MUTEX(msb_disk_lock); /* protects against races in open/release */ -static int msb_bd_open(struct block_device *bdev, fmode_t mode) -{ - struct gendisk *disk = bdev->bd_disk; - struct msb_data *msb = disk->private_data; - - dbg_verbose("block device open"); - - mutex_lock(&msb_disk_lock); - - if (msb && msb->card) - msb->usage_count++; - - mutex_unlock(&msb_disk_lock); - return 0; -} - static void msb_data_clear(struct msb_data *msb) { kfree(msb->boot_page); @@ -1973,31 +1957,16 @@ static void msb_data_clear(struct msb_data *msb) msb->card = NULL; } -static int msb_disk_release(struct gendisk *disk) +static void msb_disk_release(struct gendisk *disk) { struct msb_data *msb = disk->private_data; dbg_verbose("block device release"); mutex_lock(&msb_disk_lock); - - if (msb) { - if (msb->usage_count) - msb->usage_count--; - - if (!msb->usage_count) { - disk->private_data = NULL; - idr_remove(&msb_disk_idr, msb->disk_id); - put_disk(disk); - kfree(msb); - } - } + idr_remove(&msb_disk_idr, msb->disk_id); mutex_unlock(&msb_disk_lock); - return 0; -} -static void msb_bd_release(struct gendisk *disk, fmode_t mode) -{ - msb_disk_release(disk); + kfree(msb); } static int msb_bd_getgeo(struct block_device *bdev, @@ -2101,10 +2070,9 @@ static void msb_start(struct memstick_dev *card) } static const struct block_device_operations msb_bdops = { - .open = msb_bd_open, - .release = msb_bd_release, - .getgeo = msb_bd_getgeo, - .owner = THIS_MODULE + .owner = THIS_MODULE, + .getgeo = msb_bd_getgeo, + .free_disk = msb_disk_release, }; static const struct blk_mq_ops msb_mq_ops = { @@ -2152,7 +2120,6 @@ static int msb_init_disk(struct memstick_dev *card) set_capacity(msb->disk, capacity); dbg("Set total disk size to %lu sectors", capacity); - msb->usage_count = 1; msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM); if (!msb->io_queue) { rc = -ENOMEM; @@ -2241,7 +2208,7 @@ static void msb_remove(struct memstick_dev *card) msb_data_clear(msb); mutex_unlock(&msb_disk_lock); - msb_disk_release(msb->disk); + put_disk(msb->disk); memstick_set_drvdata(card, NULL); } diff --git a/drivers/memstick/core/ms_block.h b/drivers/memstick/core/ms_block.h index 122e1a8a8bd5b..7058f9aefeb92 100644 --- a/drivers/memstick/core/ms_block.h +++ b/drivers/memstick/core/ms_block.h @@ -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; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 60e4d426fda87..a098e650c7d64 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -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, diff --git a/include/linux/genhd.h b/include/linux/genhd.h index ccad6b4b5d289..83b11fa71af8e 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -132,6 +132,7 @@ struct gendisk { #define GD_READ_ONLY 1 #define GD_DEAD 2 #define GD_NATIVE_CAPACITY 3 +#define GD_ADDED 4 struct mutex open_mutex; /* open/close mutex */ unsigned open_partitions; /* number of open partitions */ -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 5.15.y 3/3] memstick: ms_block: destroy io_queue workqueue on removal 2026-09-22 16:48 ` [PATCH 5.15.y 1/3] block: move blk_drop_partitions to blk.h Sasha Levin 2026-09-22 16:48 ` [PATCH 5.15.y 2/3] block: add a ->free_disk method Sasha Levin @ 2026-09-22 16:48 ` Sasha Levin 1 sibling, 0 replies; 4+ messages in thread From: Sasha Levin @ 2026-09-22 16:48 UTC (permalink / raw) To: stable; +Cc: Yifei Gao, Ulf Hansson, Sasha Levin From: Yifei Gao <gyf161023@gmail.com> [ 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. Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Yifei Gao <gyf161023@gmail.com> Signed-off-by: Ulf Hansson <ulfh@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> --- drivers/memstick/core/ms_block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c index 0486bbb10e44d..8f0e993403951 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -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); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-22 16:48 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-09-22 9:36 FAILED: patch "[PATCH] memstick: ms_block: destroy io_queue workqueue on removal" failed to apply to 5.15-stable tree gregkh 2026-09-22 16:48 ` [PATCH 5.15.y 1/3] block: move blk_drop_partitions to blk.h Sasha Levin 2026-09-22 16:48 ` [PATCH 5.15.y 2/3] block: add a ->free_disk method Sasha Levin 2026-09-22 16:48 ` [PATCH 5.15.y 3/3] memstick: ms_block: destroy io_queue workqueue on removal Sasha Levin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox