From patchwork Sat Jul 1 19:25:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Wheeler X-Patchwork-Id: 9820941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51457602CC for ; Sat, 1 Jul 2017 19:25:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39BA228474 for ; Sat, 1 Jul 2017 19:25:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CCFC28521; Sat, 1 Jul 2017 19:25:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E7D328474 for ; Sat, 1 Jul 2017 19:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752124AbdGATZk (ORCPT ); Sat, 1 Jul 2017 15:25:40 -0400 Received: from mx.ewheeler.net ([66.155.3.69]:55490 "EHLO mail.ewheeler.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751911AbdGATZj (ORCPT ); Sat, 1 Jul 2017 15:25:39 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.ewheeler.net (Postfix) with ESMTP id F21B6A047B; Sat, 1 Jul 2017 19:25:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at ewheeler.net Received: from mail.ewheeler.net ([127.0.0.1]) by localhost (mail.ewheeler.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id m1YCDANdZzSp; Sat, 1 Jul 2017 19:25:38 +0000 (UTC) Received: from mx.ewheeler.net (mx.ewheeler.net [66.155.3.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.ewheeler.net (Postfix) with ESMTPSA id 1BEBFA029F; Sat, 1 Jul 2017 19:25:38 +0000 (UTC) Date: Sat, 1 Jul 2017 19:25:38 +0000 (UTC) From: Eric Wheeler X-X-Sender: lists@mail.ewheeler.net To: linux-block@vger.kernel.org cc: linux-bcache@vger.kernel.org, hch@infradead.org, axboe@kernel.dk, Tang Junhui , stable@vger.kernel.org, Stefan Bader Subject: [PATCH 05/19] bcache: fix calling ida_simple_remove() with incorrect minor Message-ID: User-Agent: Alpine 2.11 (LRH 23 2013-08-11) MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tang Junhui 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 Reviewed-by: Coly Li Reviewed-by: Eric Wheeler Cc: stable@vger.kernel.org # 4.10 Cc: Stefan Bader 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;