Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1371738

[PATCH 1/7] drivers:hv: Lock access to hyperv_mmio resource tree

Path csiph.com!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!telefonica.de!news.panservice.it!bofh.it!news.nic.it!robomod
From "K. Y. Srinivasan" <kys@microsoft.com>
Newsgroups linux.kernel
Subject [PATCH 1/7] drivers:hv: Lock access to hyperv_mmio resource tree
Date Tue, 05 Apr 2016 17:50:02 +0200
Message-ID <rkBoR-66v-5@gated-at.bofh.it> (permalink)
References <rkBoR-66v-3@gated-at.bofh.it>
X-Originating-IP 72.167.245.219
X-Mailer git-send-email 1.7.4.1
X-Cmae-Envelope MS4wfD5/CM6DV/geoiso32z4ToYt/1UQ1Dkt5TKRyLy0rrgsALos24nubS/YeDSw5N0YTy58SfJZAUsN8hfLXoVoyaW+Cg7pLaZpSmtw7KA0J/Glo47yNL1l R6Uh8QzwinCU2oNEfXfiNX7AkCnK3V7f8sqK+N3ha6w2uWM7tiilan8wn17rQ2INTFZ0PfF+5J4pvSjs6lN0m3AGBFPsh1sFjqzoQ1uez2i1o6ucc5EiEdWh 0JAK7+vmN5l8VZGExpQ2u70j464o5D9yqkMoj813ZQ8nIJk/IaXS3D1Ju/QnSNvWF8JeXCP7Hqy84m1kOrGBZuwvqdXXEzxBqiGB0f4Es8cD3Ir6gBSLcrUA Qp5AIc4YhLJ9nR5o7teki5EWuVImuwh4f8CensaiCuogTL/DPxdViHJxcQSqgNYoTRUTDaAcZg41cc87+7id+D7YqreKlg==
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 64
Organization linux.* mail to news gateway
X-Original-Cc Jake Oshins <jakeo@microsoft.com>, "K. Y. Srinivasan" <kys@microsoft.com>
X-Original-Date Tue, 5 Apr 2016 10:22:50 -0700
X-Original-Message-ID <1459876976-15860-1-git-send-email-kys@microsoft.com>
X-Original-References <1459876777-15772-1-git-send-email-kys@microsoft.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1371738

Show key headers only | View raw


From: Jake Oshins <jakeo@microsoft.com>

In existing code, this tree of resources is created
in single-threaded code and never modified after it is
created, and thus needs no locking.  This patch introduces
a semaphore for tree access, as other patches in this
series introduce run-time modifications of this resource
tree which can happen on multiple threads.

Signed-off-by: Jake Oshins <jakeo@microsoft.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
Greg, please apply this to the 4.6 tree.

 drivers/hv/vmbus_drv.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 64713ff..799518b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -102,6 +102,7 @@ static struct notifier_block hyperv_panic_block = {
 };
 
 struct resource *hyperv_mmio;
+DEFINE_SEMAPHORE(hyperv_mmio_lock);
 
 static int vmbus_exists(void)
 {
@@ -1132,7 +1133,10 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
 	resource_size_t range_min, range_max, start, local_min, local_max;
 	const char *dev_n = dev_name(&device_obj->device);
 	u32 fb_end = screen_info.lfb_base + (screen_info.lfb_size << 1);
-	int i;
+	int i, retval;
+
+	retval = -ENXIO;
+	down(&hyperv_mmio_lock);
 
 	for (iter = hyperv_mmio; iter; iter = iter->sibling) {
 		if ((iter->start >= max) || (iter->end <= min))
@@ -1169,13 +1173,17 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
 			for (; start + size - 1 <= local_max; start += align) {
 				*new = request_mem_region_exclusive(start, size,
 								    dev_n);
-				if (*new)
-					return 0;
+				if (*new) {
+					retval = 0;
+					goto exit;
+				}
 			}
 		}
 	}
 
-	return -ENXIO;
+exit:
+	up(&hyperv_mmio_lock);
+	return retval;
 }
 EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
 
-- 
1.7.4.1

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/7] drivers:hv: Lock access to hyperv_mmio resource tree "K. Y. Srinivasan" <kys@microsoft.com> - 2016-04-05 17:50 +0200
  [PATCH 6/7] drivers:hv: Record MMIO range in use by frame buffer "K. Y. Srinivasan" <kys@microsoft.com> - 2016-04-05 17:50 +0200
  [PATCH 5/7] drivers:hv: Track allocations of children of hv_vmbus in private resource tree "K. Y. Srinivasan" <kys@microsoft.com> - 2016-04-05 17:50 +0200
  [PATCH 4/7] drivers:hv: Reverse order of resources in hyperv_mmio "K. Y. Srinivasan" <kys@microsoft.com> - 2016-04-05 17:50 +0200
  [PATCH 3/7] drivers:hv: Use new vmbus_mmio_free() from client drivers. "K. Y. Srinivasan" <kys@microsoft.com> - 2016-04-05 17:50 +0200

csiph-web