From patchwork Sun Aug 27 23:09:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Xiong Y" X-Patchwork-Id: 9924183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A8AF160329 for ; Mon, 28 Aug 2017 06:10:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A25B28673 for ; Mon, 28 Aug 2017 06:10:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EF5728682; Mon, 28 Aug 2017 06:10:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 358F42867B for ; Mon, 28 Aug 2017 06:10:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmDDg-0005XL-Nf; Mon, 28 Aug 2017 06:08:20 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmDDf-0005X9-Hx for xen-devel@lists.xenproject.org; Mon, 28 Aug 2017 06:08:19 +0000 Received: from [85.158.137.68] by server-14.bemta-3.messagelabs.com id A1/89-01862-253B3A95; Mon, 28 Aug 2017 06:08:18 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsXS1tbhqBu0eXG kwZ+b/Bbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8anzvdMBQfFK+ZPFGhg7BbsYuTiEBKYzijx 4dsPpi5GTg4JAV6JI8tmsELY/hLXFjeB2UICVRL/33awgNhsAtoSa/+eYgOxRQSUJO6tmgzWy ywQKXF1SheYLSwQLfHg7hWwehYBVYnLnyaDzeEVcJeY/rWBEWK+nMTNc53MIDangL3E7ruHmS F22UlcPd/GOoGRdwEjwypGjeLUorLUIl0jS72kosz0jJLcxMwcXUMDY73c1OLixPTUnMSkYr3 k/NxNjMBgqGdgYNzB2LTX7xCjJAeTkijvzorFkUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeBU3 AeUEi1LTUyvSMnOAYQmTluDgURLhXQuS5i0uSMwtzkyHSJ1iVJQS57UDSQiAJDJK8+DaYLFwi VFWSpiXkYGBQYinILUoN7MEVf4VozgHo5IwrxXIFJ7MvBK46a+AFjMBLVYUXAiyuCQRISXVwM h04vijkgc5rD4KbRZ2egEvn2rYnc36vXLHPl4Hq9s8qdLp/FHMrx+4/vm6Rcvi7DOBxPvJBQu uLD01J4vzcejZo2K3r694MOFpfvrmkhVf320T/PZgf9L0Q7/rtK4md0davVNo3dCb1RERNfFi 0M6Psm/2OSt3S31eN+N935PHzPEnnv76s85ZiaU4I9FQi7moOBEA9bjP44ACAAA= X-Env-Sender: xiong.y.zhang@intel.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1503900495!73324912!1 X-Originating-IP: [134.134.136.65] X-SpamReason: No, hits=0.8 required=7.0 tests=DATE_IN_PAST_06_12 X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45522 invoked from network); 28 Aug 2017 06:08:17 -0000 Received: from mga03.intel.com (HELO mga03.intel.com) (134.134.136.65) by server-6.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 28 Aug 2017 06:08:17 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2017 23:08:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,440,1498546800"; d="scan'208";a="305054811" Received: from test-kbl.bj.intel.com ([10.238.158.145]) by fmsmga004.fm.intel.com with ESMTP; 27 Aug 2017 23:08:12 -0700 From: Xiong Zhang To: xen-devel@lists.xenproject.org Date: Mon, 28 Aug 2017 07:09:26 +0800 Message-Id: <1503875366-14572-1-git-send-email-xiong.y.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <59A05A210200007800173DD6@prv-mh.provo.novell.com> References: <59A05A210200007800173DD6@prv-mh.provo.novell.com> Cc: Xiong Zhang , andrew.cooper3@citrix.com, JBeulich@suse.com Subject: [Xen-devel] [PATCH v2] tools/hvmloader: Use base instead of pci_mem_start for find_next_rmrr() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP find_next_rmrr(base) is used to find the lowest RMRR ending above base but below 4G. Current method couldn't cover the following situation: a. two rmrr exist, small gap between them b. pci_mem_start and mem_resource.base is below the first rmrr.base c. find_next_rmrr(pci_mem_start) will find the first rmrr d. After aligning mem_resource.base to bar size, first_rmrr.end < new_base < second_rmrr.base and new_base + bar_sz > second_rmrr.base. So the new bar will overlap with the second rmrr and doesn't overlap with the first rmrr. But the next_rmrr point to the first rmrr, then check_overlap() couldn't find the overlap. Finally assign a wrong address to bar. This patch using aligned new base to find the next rmrr, could fix the above case and find all the overlapped rmrr with new base. Signed-off-by: Xiong Zhang Reviewed-by: Jan Beulich --- Changes since v1: - Reduce the scope of next_rmrr to just this if() --- tools/firmware/hvmloader/pci.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c index f4288a3..1858d7f 100644 --- a/tools/firmware/hvmloader/pci.c +++ b/tools/firmware/hvmloader/pci.c @@ -84,7 +84,6 @@ void pci_setup(void) uint32_t vga_devfn = 256; uint16_t class, vendor_id, device_id; unsigned int bar, pin, link, isa_irq; - int next_rmrr; /* Resources assignable to PCI devices via BARs. */ struct resource { @@ -405,8 +404,6 @@ void pci_setup(void) io_resource.base = 0xc000; io_resource.max = 0x10000; - next_rmrr = find_next_rmrr(pci_mem_start); - /* Assign iomem and ioport resources in descending order of size. */ for ( i = 0; i < nr_bars; i++ ) { @@ -464,15 +461,21 @@ void pci_setup(void) base = (resource->base + bar_sz - 1) & ~(uint64_t)(bar_sz - 1); /* If we're using mem_resource, check for RMRR conflicts. */ - while ( resource == &mem_resource && - next_rmrr >= 0 && - check_overlap(base, bar_sz, - memory_map.map[next_rmrr].addr, - memory_map.map[next_rmrr].size) ) + if ( resource == &mem_resource) { - base = memory_map.map[next_rmrr].addr + memory_map.map[next_rmrr].size; - base = (base + bar_sz - 1) & ~(bar_sz - 1); + int next_rmrr; + next_rmrr = find_next_rmrr(base); + while ( next_rmrr >= 0 && + check_overlap(base, bar_sz, + memory_map.map[next_rmrr].addr, + memory_map.map[next_rmrr].size) ) + { + base = memory_map.map[next_rmrr].addr + + memory_map.map[next_rmrr].size; + base = (base + bar_sz - 1) & ~(bar_sz - 1); + next_rmrr = find_next_rmrr(base); + } } bar_data |= (uint32_t)base;