Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3438859pxa; Tue, 25 Aug 2020 23:38:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUd5QhBrDU5ycyrOqFxcSLzehNCyg5fLBWAcoRCTR6Lq9ItcUgl70wT3o2Z922//wUZQ7S X-Received: by 2002:a05:6402:b04:: with SMTP id bm4mr13409377edb.173.1598423896424; Tue, 25 Aug 2020 23:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598423896; cv=none; d=google.com; s=arc-20160816; b=NyuG5iYVcwuRsaneiCCBrmuKSWzmUIIaVAh+rkjBYihfdoONCX33mjMAN7Aokg5vgJ YCoAw70q+n3C/dLFOBsBPyN2CYFj+YBTeCNObvB2rP09lnVhmscYokkcitISDolQfjjo 79StRBLpq+qyJy9fIJrr/1fzMpNc5xMnUHIlI7kXNm8LNCvgHYc5Y6xxaDj3R62A546L P3xv9Z46tg2H6WbpnOrbKl0Y1qFEdJLcXBiY18XT7wR4AgCYI4XBwN0rLJvP+3K1z85j Mr0L6STsuZkxUG9vXTbTJUe13YEg/6hYP6uw/eQmq+EHFbuwWKZf3UksmHaB4bqrcu4T VOzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+cMW5JtsVeNS2FjWWdcDP87J0ElpYqiX0+V9AmGsl5g=; b=cI0BdYMBdDVu9GGVI4JIAPEJfnlhF/wZUoVuepIWT0gWM4qArIRtL81FpZa0tH5ukT 1sNHa9ndhtN2DK33Ebrf9bDlWkETY+nASKIQ3LDNVZALcFcF9qa1gAn7oKhZjFco1wTE XfrHZI13wIn2TtSHrA/bFBZS11c9jhtRbvSIPG4LcWNS0Li/tDd4/xX6c3fs6wNnqnQj cc4DpV4ndjPQ8514Dg2SaMFROpxw6tkaa9mt92VXiytPVcZ7wVBYoBFLqGYad83NqOVX caMrGeHXKWZihQEdwK2AfO0NQOCmQfgAa5KnqybbNX2TTE3amBaTjOUbGJA04mqQBIo3 9iRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=vdQOiVSF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si907080ejb.289.2020.08.25.23.37.53; Tue, 25 Aug 2020 23:38:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=vdQOiVSF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727073AbgHZGgl (ORCPT + 99 others); Wed, 26 Aug 2020 02:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbgHZGfs (ORCPT ); Wed, 26 Aug 2020 02:35:48 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27F56C061574; Tue, 25 Aug 2020 23:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=+cMW5JtsVeNS2FjWWdcDP87J0ElpYqiX0+V9AmGsl5g=; b=vdQOiVSF6fBxenY6vigpPDDsWy LAzWjpyJ7o18k22xyQbjOpHTJyPJKLXoVeaa04ofyq6Z3VaTrUPwWJWMnKJPSYMKjUp7k/OPQ/xgz EcSojjFOvAu3EU8v3YnCxPkEqa9JaBNOWNs3cgRmGwXIIaoBM3lNgEnKi7HERU+C7bybJl53Z7kSM ELarZ2DolwN5nr4Gk1JZ3lOujCRX15fsGCop2mJ8/MbvWoatnsQWOZLHwWAKwKJauKmHBhZ/jtLMZ 4L7Qa37j+tybKLQU/LrLDM1/f4zYDYgxg5mF5VImsBfThswFUUAIef3p5ARCVVEu+lZyyumP9yXHx lnBE7AnA==; Received: from 213-225-6-196.nat.highway.a1.net ([213.225.6.196] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAp25-0001NT-RV; Wed, 26 Aug 2020 06:35:42 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Denis Efremov , "David S. Miller" , Song Liu , Al Viro , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org, linux-m68k@lists.linux-m68k.org Subject: [PATCH 04/19] block: split block_class_lock Date: Wed, 26 Aug 2020 08:24:31 +0200 Message-Id: <20200826062446.31860-5-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200826062446.31860-1-hch@lst.de> References: <20200826062446.31860-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split the block_class_lock mutex into one each to protect bdev_map and major_names. Signed-off-by: Christoph Hellwig --- block/genhd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index df6485223a2c3d..0ae6210e141ee5 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -25,7 +25,6 @@ #include "blk.h" -static DEFINE_MUTEX(block_class_lock); static struct kobject *block_depr; struct bdev_map { @@ -37,6 +36,7 @@ struct bdev_map { int (*lock)(dev_t, void *); void *data; } *bdev_map[255]; +static DEFINE_MUTEX(bdev_map_lock); /* for extended dynamic devt allocation, currently only one major is used */ #define NR_EXT_DEVT (1 << MINORBITS) @@ -403,6 +403,7 @@ static struct blk_major_name { int major; char name[16]; } *major_names[BLKDEV_MAJOR_HASH_SIZE]; +static DEFINE_MUTEX(major_names_lock); /* index in the above - for now: assume no multimajor ranges */ static inline int major_to_index(unsigned major) @@ -415,11 +416,11 @@ void blkdev_show(struct seq_file *seqf, off_t offset) { struct blk_major_name *dp; - mutex_lock(&block_class_lock); + mutex_lock(&major_names_lock); for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next) if (dp->major == offset) seq_printf(seqf, "%3d %s\n", dp->major, dp->name); - mutex_unlock(&block_class_lock); + mutex_unlock(&major_names_lock); } #endif /* CONFIG_PROC_FS */ @@ -448,7 +449,7 @@ int register_blkdev(unsigned int major, const char *name) struct blk_major_name **n, *p; int index, ret = 0; - mutex_lock(&block_class_lock); + mutex_lock(&major_names_lock); /* temporary */ if (major == 0) { @@ -501,7 +502,7 @@ int register_blkdev(unsigned int major, const char *name) kfree(p); } out: - mutex_unlock(&block_class_lock); + mutex_unlock(&major_names_lock); return ret; } @@ -513,7 +514,7 @@ void unregister_blkdev(unsigned int major, const char *name) struct blk_major_name *p = NULL; int index = major_to_index(major); - mutex_lock(&block_class_lock); + mutex_lock(&major_names_lock); for (n = &major_names[index]; *n; n = &(*n)->next) if ((*n)->major == major) break; @@ -523,7 +524,7 @@ void unregister_blkdev(unsigned int major, const char *name) p = *n; *n = p->next; } - mutex_unlock(&block_class_lock); + mutex_unlock(&major_names_lock); kfree(p); } @@ -674,7 +675,7 @@ void blk_register_region(dev_t devt, unsigned long range, struct module *module, p->data = data; } - mutex_lock(&block_class_lock); + mutex_lock(&bdev_map_lock); for (i = 0, p -= n; i < n; i++, p++, index++) { struct bdev_map **s = &bdev_map[index % 255]; while (*s && (*s)->range < range) @@ -682,7 +683,7 @@ void blk_register_region(dev_t devt, unsigned long range, struct module *module, p->next = *s; *s = p; } - mutex_unlock(&block_class_lock); + mutex_unlock(&bdev_map_lock); } EXPORT_SYMBOL(blk_register_region); @@ -693,7 +694,7 @@ void blk_unregister_region(dev_t devt, unsigned long range) unsigned i; struct bdev_map *found = NULL; - mutex_lock(&block_class_lock); + mutex_lock(&bdev_map_lock); for (i = 0; i < min(n, 255u); i++, index++) { struct bdev_map **s; for (s = &bdev_map[index % 255]; *s; s = &(*s)->next) { @@ -706,7 +707,7 @@ void blk_unregister_region(dev_t devt, unsigned long range) } } } - mutex_unlock(&block_class_lock); + mutex_unlock(&bdev_map_lock); kfree(found); } EXPORT_SYMBOL(blk_unregister_region); @@ -1041,7 +1042,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno) unsigned long best = ~0UL; retry: - mutex_lock(&block_class_lock); + mutex_lock(&bdev_map_lock); for (p = bdev_map[MAJOR(dev) % 255]; p; p = p->next) { struct kobject *(*probe)(dev_t, int *, void *); struct module *owner; @@ -1062,7 +1063,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno) module_put(owner); continue; } - mutex_unlock(&block_class_lock); + mutex_unlock(&bdev_map_lock); kobj = probe(dev, partno, data); /* Currently ->owner protects _only_ ->probe() itself. */ module_put(owner); @@ -1070,7 +1071,7 @@ static struct gendisk *lookup_gendisk(dev_t dev, int *partno) return dev_to_disk(kobj_to_dev(kobj)); goto retry; } - mutex_unlock(&block_class_lock); + mutex_unlock(&bdev_map_lock); return NULL; } -- 2.28.0