linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 05/19] bcache: fix calling ida_simple_remove() with incorrect minor
@ 2017-07-01 19:25 Eric Wheeler
  0 siblings, 0 replies; 88+ messages in thread
From: Eric Wheeler @ 2017-07-01 19:25 UTC (permalink / raw)
  To: linux-block; +Cc: linux-bcache, hch, axboe, Tang Junhui, stable, Stefan Bader

From: Tang Junhui <tang.junhui@zte.com.cn>

bcache called ida_simple_remove() with minor which have multiplied by
BCACHE_MINORS, it would cause minor wrong release and leakage.

In addition, when adding partition support to bcache, the name assignment
was not updated, resulting in numbers jumping (bcache0, bcache16,
bcache32...). This has been fixed implicitly by the rework.

Signed-off-by: tang.junhui <tang.junhui@zte.com.cn>
Reviewed-by: Coly Li <colyli@suse.de>
Reviewed-by: Eric Wheeler <bcache@linux.ewheeler.net>
Cc: stable@vger.kernel.org # 4.10
Cc: Stefan Bader <stefan.bader@canonical.com>
Fixes: b8c0d91 (bcache: partition support: add 16 minors per bcacheN device)
BugLink: https://bugs.launchpad.net/bugs/1667078
---
 drivers/md/bcache/super.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 9a2c190..48b8c20 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -58,7 +58,10 @@ static wait_queue_head_t unregister_wait;
 struct workqueue_struct *bcache_wq;
 
 #define BTREE_MAX_PAGES		(256 * 1024 / PAGE_SIZE)
-#define BCACHE_MINORS		16 /* partition support */
+#define BCACHE_MINORS_BITS                4 /* bcache partition support */
+#define BCACHE_MINORS                     (1 << BCACHE_MINORS_BITS)
+#define BCACHE_TO_IDA_MINORS(first_minor) ((first_minor) >> BCACHE_MINORS_BITS)
+#define IDA_TO_BCACHE_MINORS(minor)       ((minor) << BCACHE_MINORS_BITS)
 
 /* Superblock */
 
@@ -734,7 +737,8 @@ static void bcache_device_free(struct bcache_device *d)
 	if (d->disk && d->disk->queue)
 		blk_cleanup_queue(d->disk->queue);
 	if (d->disk) {
-		ida_simple_remove(&bcache_minor, d->disk->first_minor);
+		ida_simple_remove(&bcache_minor,
+			BCACHE_TO_IDA_MINORS(d->disk->first_minor));
 		put_disk(d->disk);
 	}
 
@@ -776,11 +780,11 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 	if (!d->full_dirty_stripes)
 		return -ENOMEM;
 
-	minor = ida_simple_get(&bcache_minor, 0, MINORMASK + 1, GFP_KERNEL);
+	minor = ida_simple_get(&bcache_minor, 0,
+		BCACHE_TO_IDA_MINORS(MINORMASK) + 1, GFP_KERNEL);
 	if (minor < 0)
 		return minor;
 
-	minor *= BCACHE_MINORS;
 
 	if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio),
 					   BIOSET_NEED_BVECS |
@@ -794,7 +798,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 	snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", minor);
 
 	d->disk->major		= bcache_major;
-	d->disk->first_minor	= minor;
+	d->disk->first_minor	= IDA_TO_BCACHE_MINORS(minor);
 	d->disk->fops		= &bcache_ops;
 	d->disk->private_data	= d;
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 88+ messages in thread

end of thread, other threads:[~2017-10-28  8:58 UTC | newest]

Thread overview: 88+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <alpine.LRH.2.11.1705251853530.19359@mail.ewheeler.net>
2017-06-28 23:06 ` [PULL] bcache fixes and updates for-4.13 Eric Wheeler
2017-06-29 13:45   ` Christoph Hellwig
2016-10-11 19:04     ` [PATCH 07/19] bcache: introduce bcache sysfs entries for ioprio-based bypass/writeback hints Eric Wheeler
2016-10-11 19:04     ` Eric Wheeler
2016-10-11 19:08     ` [PATCH 08/19] bcache: documentation for sysfs entries describing bcache cache hinting Eric Wheeler
2016-10-11 19:08     ` Eric Wheeler
2016-10-20  0:36     ` [PATCH 09/19] bcache: update bio->bi_opf bypass/writeback REQ_ flag hints Eric Wheeler
2016-10-20  0:36     ` Eric Wheeler
2017-05-09 19:03     ` [PATCH 01/19] bcache: Fix leak of bdev reference Jan Kara
2017-05-09 19:03     ` Jan Kara
2017-05-09 19:05     ` [PATCH 02/19] bcache: fix sequential large write IO bypass Tang Junhui
2017-05-09 19:05     ` Tang Junhui
2017-05-09 19:07     ` [PATCH 03/19] bcache: do not subtract sectors_to_gc for bypassed IO Tang Junhui
2017-05-09 19:07     ` Tang Junhui
2017-05-09 19:14     ` [PATCH 05/19] bcache: fix calling ida_simple_remove() with incorrect minor Tang Junhui
2017-05-09 19:14     ` Tang Junhui
2017-06-01  8:48     ` [PATCH 10/19] bcache: initialize stripe_sectors_dirty correctly for thin flash device Tang Junhui
2017-06-01  8:48     ` Tang Junhui
2017-06-12 21:18     ` [PATCH 14/19] bcache: Correct return value for sysfs attach errors Tony Asleson
2017-06-12 21:18     ` Tony Asleson
2017-06-28  0:30     ` [PATCH 13/19] bcache: delete redundant calling set_gc_sectors() Tang Junhui
2017-06-28  0:30     ` Tang Junhui
2017-06-28  0:37     ` [PATCH 16/19] bcache: increase the number of open buckets Tang Junhui
2017-06-28  0:37     ` Tang Junhui
2017-06-28  0:41     ` [PATCH 17/19] bcache: fix for gc and write-back race Tang Junhui
2017-06-28  0:41     ` Tang Junhui
2017-06-28 11:47     ` [PATCH 18/19] bcache: silence static checker warning Dan Carpenter
2017-06-28 11:47     ` Dan Carpenter
2017-06-28 11:48     ` [PATCH 19/19] bcache: Update continue_at() documentation Dan Carpenter
2017-06-28 11:48     ` Dan Carpenter
2017-06-29 16:19     ` [PULL] bcache fixes and updates for-4.13 Coly Li
2017-06-29 22:12     ` Eric Wheeler
2017-06-29 22:25       ` Eric Wheeler
2017-06-29 23:28         ` Nick Alcock
2017-06-30 20:42     ` [PATCH 01/19] bcache: Fix leak of bdev reference bcache
2017-06-30 20:42       ` [PATCH 02/19] bcache: fix sequential large write IO bypass bcache
2017-07-05 18:25         ` Christoph Hellwig
2017-06-30 20:42       ` [PATCH 03/19] bcache: do not subtract sectors_to_gc for bypassed IO bcache
2017-07-01 17:26         ` Coly Li
2017-07-05 18:25         ` Christoph Hellwig
2017-06-30 20:42       ` [PATCH 05/19] bcache: fix calling ida_simple_remove() with incorrect minor bcache
2017-07-05 18:26         ` Christoph Hellwig
2017-07-06  6:21           ` tang.junhui
2017-06-30 20:42       ` [PATCH 06/19] bcache: explicitly destory mutex while exiting bcache
2017-07-01 18:43         ` Coly Li
2017-07-05 11:58           ` Liang Chen
2017-07-11  7:22             ` Coly Li
2017-07-05 18:27         ` Christoph Hellwig
2017-07-06  1:56           ` Liang Chen
2017-06-30 20:42       ` [PATCH 07/19] bcache: introduce bcache sysfs entries for ioprio-based bypass/writeback hints bcache
2017-07-05 18:47         ` Christoph Hellwig
2017-07-05 21:49           ` Eric Wheeler
2017-06-30 20:42       ` [PATCH 08/19] bcache: documentation for sysfs entries describing bcache cache hinting bcache
2017-07-05 18:27         ` Christoph Hellwig
2017-06-30 20:42       ` [PATCH 09/19] bcache: update bio->bi_opf bypass/writeback REQ_ flag hints bcache
2017-07-01 18:49         ` Coly Li
2017-07-01 19:39           ` Eric Wheeler
2017-07-02  6:51             ` Coly Li
2017-07-03 22:51               ` [PATCH 09/19 v2] " bcache
2017-07-04  4:08                 ` Coly Li
2017-07-05 18:48                 ` Christoph Hellwig
2017-07-06  7:35                   ` Coly Li
2017-07-06 15:24                     ` Christoph Hellwig
2017-07-11  3:48                       ` Coly Li
2017-07-12  9:18                         ` Coly Li
2017-06-30 20:42       ` [PATCH 10/19] bcache: initialize stripe_sectors_dirty correctly for thin flash device bcache
2017-07-01 18:52         ` Coly Li
2017-07-13  4:10           ` Eric Wheeler
2017-06-30 20:43       ` [PATCH 13/19] bcache: delete redundant calling set_gc_sectors() bcache
2017-07-13  3:41         ` Eric Wheeler
2017-06-30 20:43       ` [PATCH 14/19] bcache: Correct return value for sysfs attach errors bcache
2017-06-30 20:43       ` [PATCH 16/19] bcache: increase the number of open buckets bcache
2017-07-13  9:56         ` Coly Li
2017-06-30 20:43       ` [PATCH 17/19] bcache: fix for gc and write-back race bcache
2017-08-03 16:20         ` Coly Li
2017-06-30 20:43       ` [PATCH 18/19] bcache: silence static checker warning bcache
2017-07-13  9:44         ` Coly Li
2017-06-30 20:43       ` [PATCH 19/19] bcache: Update continue_at() documentation bcache
2017-07-05 18:48         ` Christoph Hellwig
2017-07-08 18:12         ` Coly Li
2017-07-01 16:55       ` [PATCH 01/19] bcache: Fix leak of bdev reference Coly Li
2017-07-05 18:24       ` Christoph Hellwig
2017-09-04 17:30         ` Coly Li
2017-09-05  6:43           ` Christoph Hellwig
2017-09-05  6:55             ` Coly Li
2017-09-06  5:25             ` Coly Li
     [not found]       ` <1498855388-16990-15-git-send-email-bcache@lists.ewheeler.net>
     [not found]         ` <a0e50d65-6e9d-23d0-d73c-8fb2b3dfcc51@coly.li>
     [not found]           ` <alpine.LRH.2.11.1710271906110.24585@mail.ewheeler.net>
     [not found]             ` <alpine.LRH.2.11.1710271908450.24585@mail.ewheeler.net>
2017-10-28  8:58               ` [PATCH 15/19] bcache: fix issue of writeback rate at minimum 1 key per second Coly Li
2017-07-01 19:25 [PATCH 05/19] bcache: fix calling ida_simple_remove() with incorrect minor Eric Wheeler

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).