From patchwork Wed Mar 30 23:48:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jake Oshins X-Patchwork-Id: 8705391 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7BF59C0553 for ; Wed, 30 Mar 2016 22:13:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9930C2037E for ; Wed, 30 Mar 2016 22:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB24A20253 for ; Wed, 30 Mar 2016 22:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753462AbcC3WMA (ORCPT ); Wed, 30 Mar 2016 18:12:00 -0400 Received: from p3plsmtps2ded03.prod.phx3.secureserver.net ([208.109.80.60]:56353 "EHLO p3plsmtps2ded03.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753420AbcC3WL6 (ORCPT ); Wed, 30 Mar 2016 18:11:58 -0400 Received: from linuxonhyperv.com ([72.167.245.219]) by : HOSTING RELAY : with SMTP id lOILauczBetyNlOILadEqk; Wed, 30 Mar 2016 15:08:57 -0700 x-originating-ip: 72.167.245.219 Received: by linuxonhyperv.com (Postfix, from userid 520) id 7B0C8190304; Wed, 30 Mar 2016 16:49:21 -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 v2 5/7] drivers:hv: Track allocations of children of hv_vmbus in private resource tree Date: Wed, 30 Mar 2016 16:48:45 -0700 Message-Id: <1459381727-25039-6-git-send-email-jakeo@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1459381727-25039-1-git-send-email-jakeo@microsoft.com> References: <1459381727-25039-1-git-send-email-jakeo@microsoft.com> X-CMAE-Envelope: MS4wfI2aRo4MV0Smch/iBfIsgAtxUNwFiOB9NgaIk8Q0f6UsdEmBCsjY81a7JMjEFZf4SupHQR1IGKp8gufcHo3igthejvUIsJfXsU8jgcGI4dPDvuOs6rUC HoAN7BNK0PqQ2inmdGC7FQAZjfsGtE0DvE7vs9Iy0690k1ZeRFUf7VHzTmQJlNYP1ubh8cWXytgMWbIqrbTh1VlFGMkARYsoT76YB8TaZR4EhknnoLAuH17v 7c1V46FU2Bp6LhXyLV/Rr+xQWQrN1P2vvo3AzE4xY1Ily/Dr8XdgB84Fd7S58Fgmb9Kqz8aIFFwQj9TmzaS7u1OunwKeZlx6ZaFzqCJpSTrHCkLEz2KO1h9R /76e6rHIT+YWXFVEtq9pdYBTNlW14tLKymzf+CeU6bKoPY/FzAFlmiOT+BuzvPD1YRW4Bo4hngfYz8HlTdLDJwVwVg/9gIivffbYcgi88Km0rYBJrD89DgW7 UgkiWpA2TAuMUhPlCSKIFLMNpRWR7Gu7X9DhV/vh+0bFuNfp/cM/cXXIdSU= 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 This patch changes vmbus_allocate_mmio() and vmbus_free_mmio() so that when child paravirtual devices allocate memory-mapped I/O space, they allocate it privately from a resource tree pointed at by hyperv_mmio and also by the public resource tree iomem_resource. This allows the region to be marked as "busy" in the private tree, but a "bridge window" in the public tree, guaranteeing that no two bridge windows will overlap each other but while also allowing the PCI device children of the bridge windows to overlap that window. One might conclude that this belongs in the pnp layer, rather than in this driver. Rafael Wysocki, the maintainter of the pnp layer, has previously asked that we not modify the pnp layer as it is considered deprecated. This patch is thus essentially a workaround. Signed-off-by: Jake Oshins --- drivers/hv/vmbus_drv.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 1ce47d0..dfc6149 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1128,7 +1128,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, resource_size_t size, resource_size_t align, bool fb_overlap_ok) { - struct resource *iter; + struct resource *iter, *shadow; 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); @@ -1170,12 +1170,22 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, start = (local_min + align - 1) & ~(align - 1); for (; start + size - 1 <= local_max; start += align) { + shadow = __request_region(iter, start, + size, + NULL, + IORESOURCE_BUSY); + if (!shadow) + continue; + *new = request_mem_region_exclusive(start, size, dev_n); if (*new) { + shadow->name = (char *)*new; retval = 0; goto exit; } + + __release_region(iter, start, size); } } } @@ -1196,7 +1206,17 @@ EXPORT_SYMBOL_GPL(vmbus_allocate_mmio); */ void vmbus_free_mmio(resource_size_t start, resource_size_t size) { + struct resource *iter; + + down(&hyperv_mmio_lock); + for (iter = hyperv_mmio; iter; iter = iter->sibling) { + if ((iter->start >= start + size) || (iter->end <= start)) + continue; + + __release_region(iter, start, size); + } release_mem_region(start, size); + up(&hyperv_mmio_lock); } EXPORT_SYMBOL_GPL(vmbus_free_mmio);