Commit e16dad6b authored by Jake Oshins's avatar Jake Oshins Committed by Greg Kroah-Hartman

drivers:hv: Lock access to hyperv_mmio resource tree

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: default avatarJake Oshins <jakeo@microsoft.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ab028db4
...@@ -102,6 +102,7 @@ static struct notifier_block hyperv_panic_block = { ...@@ -102,6 +102,7 @@ static struct notifier_block hyperv_panic_block = {
}; };
struct resource *hyperv_mmio; struct resource *hyperv_mmio;
DEFINE_SEMAPHORE(hyperv_mmio_lock);
static int vmbus_exists(void) static int vmbus_exists(void)
{ {
...@@ -1132,7 +1133,10 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, ...@@ -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; resource_size_t range_min, range_max, start, local_min, local_max;
const char *dev_n = dev_name(&device_obj->device); const char *dev_n = dev_name(&device_obj->device);
u32 fb_end = screen_info.lfb_base + (screen_info.lfb_size << 1); 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) { for (iter = hyperv_mmio; iter; iter = iter->sibling) {
if ((iter->start >= max) || (iter->end <= min)) if ((iter->start >= max) || (iter->end <= min))
...@@ -1169,13 +1173,17 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, ...@@ -1169,13 +1173,17 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
for (; start + size - 1 <= local_max; start += align) { for (; start + size - 1 <= local_max; start += align) {
*new = request_mem_region_exclusive(start, size, *new = request_mem_region_exclusive(start, size,
dev_n); dev_n);
if (*new) if (*new) {
return 0; retval = 0;
goto exit;
}
} }
} }
} }
return -ENXIO; exit:
up(&hyperv_mmio_lock);
return retval;
} }
EXPORT_SYMBOL_GPL(vmbus_allocate_mmio); EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment