From patchwork Sat Apr 2 00:47:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jake Oshins X-Patchwork-Id: 605069 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3qcHFm3dcCz9ssP for ; Sat, 2 Apr 2016 10:11:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755317AbcDAXK1 (ORCPT ); Fri, 1 Apr 2016 19:10:27 -0400 Received: from p3plsmtps2ded03.prod.phx3.secureserver.net ([208.109.80.60]:58904 "EHLO p3plsmtps2ded03.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755178AbcDAXKZ (ORCPT ); Fri, 1 Apr 2016 19:10:25 -0400 Received: from linuxonhyperv.com ([72.167.245.219]) by : HOSTING RELAY : with SMTP id m89zab3mKetyNm89zanWov; Fri, 01 Apr 2016 16:07:24 -0700 x-originating-ip: 72.167.245.219 Received: by linuxonhyperv.com (Postfix, from userid 520) id C8D01190305; Fri, 1 Apr 2016 17:47:55 -0700 (PDT) From: Jake Oshins To: linux-pci@vger.kernel.org, gregkh@linuxfoundation.org, kys@microsoft.com, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, haiyangz@microsoft.com, haddenh@microsoft.com Cc: Jake Oshins Subject: [PATCH v4 1/7] drivers:hv: Lock access to hyperv_mmio resource tree Date: Fri, 1 Apr 2016 17:47:41 -0700 Message-Id: <1459558067-1725-2-git-send-email-jakeo@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1459558067-1725-1-git-send-email-jakeo@microsoft.com> References: <1459558067-1725-1-git-send-email-jakeo@microsoft.com> X-CMAE-Envelope: MS4wfHQaDXxynpTJtFu2ridER/nHwVkQvyMjbBglaFaEC2xWADE669xTPe3S0MAhtQdIR0nXArNZcOOLRGk3yO9j8YEJMWAcbATsYIRU7dL9OeDIzOu+jG5p iXpXvintN25Yf71Rmn7j/hrxSPWtNke7wDawCLgI0LI9GAWaYapFPnmJMKsgF/p01GgIG1p1E7/frZMnOvEmJLGq+YxMYykLCE3Q69Obfle5ZWFP/7dd+zPh ddrodxlWqouwL+Dt2sUcBZHPaSaoh1DkNvECiTvNEKLqGqJk2hkshDaw5PiAtlXldOM/n06LMFwVmv7moJE2ptHreUWTVCHOafAMGHen2+hLTTnxwrMyDlLe C70USFGjhb9r+UD1VFytqCDZIexMat6iwe/TQ6xYeDFjqkDUgVZowZzki5US3it9F1X58H4Q9ku2g6gAgF9ispOUAOyVgZ1c0J8YQLU5wcYvxRG40EerQxtR Md7FA/Zekpkp38M18MkNiLaU09rEee/A/YlpnPxrJwyMtntCQzlxgpvHIKw= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 --- drivers/hv/vmbus_drv.c | 16 ++++++++++++---- 1 file 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);