Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp360161pxk; Thu, 3 Sep 2020 01:20:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY8t27dYospnSth3YoIYqj6+QbYNanly2JGgCpi0999b3gKNqlxXAJzcfVdZ+iJ25vP7RG X-Received: by 2002:a17:906:6b0b:: with SMTP id q11mr846401ejr.412.1599121211177; Thu, 03 Sep 2020 01:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599121211; cv=none; d=google.com; s=arc-20160816; b=uwwya8v51gs8NzjkKrsKeX6ayEmkFx5LBO2BiLXG/RQj1bxzmCozCWIeLIBnaRvwF8 vDZoRfCV42R/WzfBhc85rNi8pkcZi9zVydZHFEJnWNUETHoEXMOXQY05DSXyAei3snA8 9TFGXkNOn2y1SV7I53Us8s2sFeTjxl5ex/X1NdUMd5VnfsM6MozXUf/WwV+FRIrKppH6 pq5kL1S433aRvelC9tq/Jv3jrRb/d06WuynGU8Si9IHa39qBWHl4z+qmzd/6IOol3nPP TirTpQ0EcC/GdOZxV2DsoC2X0ba/wGp4l5+z9d7NgnNp6WP+zniUqcatvS5MA7P7nKI6 6aUQ== 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=heIsT8/SplQXU4w72h1M+LwpZvzUpp0QALjc6RNl7zw=; b=ex3doUCRNmdmLYRvN3iRglXtzZWF6Doqo6TagWXkvSpcfZ5WwhC/8lD/gaVt8hSKrW OIcA44wK0q4yDIfJdRt6w9QWRh61waweCneEKMwo5e+kKAt2LJyrPpWaJ+4de2QVuerz vBkBlggkqA0R8PHt0CoJoeklEbFrm52xGgeSV1PpLxmaEpFpwIu7UuYiAe8Rk/hD6N1S lbLkGQCuP9LH0lodrV5mvcHAIfSseZOqxLsdrIUHp1R90D+OfN0K3L6U+qk7Ina4g9zH 6/wr4B1pA7alrvTnre8mhT+fi5nS//GV2qRLeT3whTvZtvcSIH4Wi0dc6rdF2kr6POx4 AuIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=PJTestiP; 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 t17si1348934ejd.335.2020.09.03.01.19.47; Thu, 03 Sep 2020 01:20:11 -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=PJTestiP; 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 S1729015AbgICIRQ (ORCPT + 99 others); Thu, 3 Sep 2020 04:17:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbgICIBe (ORCPT ); Thu, 3 Sep 2020 04:01:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FA9EC061249; Thu, 3 Sep 2020 01:01:33 -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=heIsT8/SplQXU4w72h1M+LwpZvzUpp0QALjc6RNl7zw=; b=PJTestiPNaHQ4NuHebfydyrEWB nCiCAtdUz3eJLxq8KY9/S/xSlwUrEjqZK4eF4+fbUXvMMIC9DreUObnDmn4JhDMU9/5HAF8XBk5Gq madT5qC5ReZdHeg8qVcWB44DoSB5OUgt7zAX4QK4Ptsh9LPyChjoPIr2uwmTBVKGcl4JCpPQc4rZx huRcZeYK/88mJpcGFRGdXObvfs5YhZLg/cCBwDSTH/hmV1F9Eh2hOI/95cW5pdnMigN03LtlIjT5m gxeTTDqRzD4iSakHMKD9FHAwl1DT4Np18YNvLVn0C5yT+ncropdeV8EIl0QTwjOi+WiXiUKjP3SPv +9U7GLVg==; Received: from [2001:4bb8:184:af1:c70:4a89:bc61:2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDkBR-0006aU-RV; Thu, 03 Sep 2020 08:01:27 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Denis Efremov , "David S. Miller" , Song Liu , Al Viro , Finn Thain , Michael Schmitz , 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: Thu, 3 Sep 2020 10:01:04 +0200 Message-Id: <20200903080119.441674-5-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200903080119.441674-1-hch@lst.de> References: <20200903080119.441674-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 ec9b64207d9c2e..034e9089965a82 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) @@ -400,6 +400,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) @@ -412,11 +413,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 */ @@ -445,7 +446,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) { @@ -498,7 +499,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; } @@ -510,7 +511,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; @@ -520,7 +521,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); } @@ -671,7 +672,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) @@ -679,7 +680,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); @@ -690,7 +691,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) { @@ -703,7 +704,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); @@ -1039,7 +1040,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; @@ -1060,7 +1061,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); @@ -1068,7 +1069,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