From patchwork Wed Apr 6 01:18:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jake Oshins X-Patchwork-Id: 8756691 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E63579F36E for ; Tue, 5 Apr 2016 23:42:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 283E9200E5 for ; Tue, 5 Apr 2016 23:42:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 463822021F for ; Tue, 5 Apr 2016 23:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760371AbcDEXkx (ORCPT ); Tue, 5 Apr 2016 19:40:53 -0400 Received: from p3plsmtps2ded02.prod.phx3.secureserver.net ([208.109.80.59]:52011 "EHLO p3plsmtps2ded02.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760347AbcDEXkv (ORCPT ); Tue, 5 Apr 2016 19:40:51 -0400 Received: from linuxonhyperv.com ([72.167.245.219]) by : HOSTING RELAY : with SMTP id naXcaa8jtzRgvnaXcaGoK3; Tue, 05 Apr 2016 16:37:49 -0700 x-originating-ip: 72.167.245.219 Received: by linuxonhyperv.com (Postfix, from userid 520) id 258BC190331; Tue, 5 Apr 2016 18:18:36 -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, helgaas@kernel.org Cc: Jake Oshins Subject: [PATCH v5 1/6] drivers:hv: Lock access to hyperv_mmio resource tree Date: Tue, 5 Apr 2016 18:18:17 -0700 Message-Id: <1459905502-20798-2-git-send-email-jakeo@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1459905502-20798-1-git-send-email-jakeo@microsoft.com> References: <1459905502-20798-1-git-send-email-jakeo@microsoft.com> X-CMAE-Envelope: MS4wfI9F+Sh/hpPIdDrVebDfPokFa3MTzeiDKzhWDfzQcqKIMfMDJbPB48ZQk4CX+YmNU/5qTWJVmYUkpHplFNHzanSFUVKZOUSq7Yo2BR+MndpTC78wguKT 9FiPOLuwaQTE0mo+gBy4E58kyyT+dbJLW/Qh709jK/xGmME3FfyIR8RolgbY51FuLeu6bKuI117WGpLUkdND1KXd/RUASYIQXrkD0JS1RCgU9WzbLj37eYpZ ELsEOy5E9X0U3zQC+JgWKU+XvUAyHYU4luX/GitjTiSowpLwW72ddn0RzTjdekrzINg/5759hpT6kv+i0jvEdNuUs/OYVhQZtpj+KXDcqRB+BaHCFZdjXVeB PZPaC4A2+3szBqEGfVZbWz0eCjJIl7bZAOxYFBH9toYfdJWDqeHMNsuEw68jzLXKEAmQh8SBFkmNJW8TehDFwDiCIAhM45p8bEXqf+p44LDxh+/4e9sjZ8rJ RpfBYNSkkxcVIzuyTywcohWWH+7csxrV/ZDmJ7dftaf++uuZNXBFSKUdtE7uGl/wnSFiswtQE05tEYTx Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);