From patchwork Mon Jan 23 18:20:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 9533315 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 4F02660434 for ; Mon, 23 Jan 2017 18:23:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 402DD28365 for ; Mon, 23 Jan 2017 18:23:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32F9028442; Mon, 23 Jan 2017 18:23:29 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY 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 A8FAA28365 for ; Mon, 23 Jan 2017 18:23:28 +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 1cVjF6-0007Cc-Mh; Mon, 23 Jan 2017 18:21:24 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVjF6-0007CQ-8h for xen-devel@lists.xen.org; Mon, 23 Jan 2017 18:21:24 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 18/B4-15802-3A946885; Mon, 23 Jan 2017 18:21:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsUyZ7p8oO4iz7Y Ig9OfjS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxt3TkFdzUq5h+fz9jAuE26i5GLQ0hgIpPE 5L1fWLsYOYGcv4wSTzZKQSQ2MEr0r+9mhnA6GSUOz2piBqliEzCQOHq4B6xDRMBMYmrbPhaQI maBm4wSva8PsoMkhAVcJWZPWsMCYrMIqEq8vHqQEcTmFfCQ6P1yig3ElhCQk7h5rhNoKAcHp4 CnxLQWRYgrPCS2LznDBFFiKPF541LmCYx8CxgZVjFqFKcWlaUW6Rpa6CUVZaZnlOQmZuboGhq Y6uWmFhcnpqfmJCYV6yXn525iBAYKAxDsYGza7nmIUZKDSUmU90Z8S4QQX1J+SmVGYnFGfFFp TmrxIUYZDg4lCd52j7YIIcGi1PTUirTMHGDIwqQlOHiURHitQNK8xQWJucWZ6RCpU4yKUuK8b iAJAZBERmkeXBssTi4xykoJ8zICHSLEU5BalJtZgir/ilGcg1FJmFcaZApPZl4J3PRXQIuZgB bLSjSDLC5JREhJNTDuVj+qpiZ4lnui9ISWT3M2VHx5ovTR6Kv5jKaHwnw/KtdM7tgtesevQ2N 7wsRptc9Ofn+xYb/cW+bAb41Hd23ad3NStfH+RfMZvM+/eBn75TxD8FOPTT+mbN0xv/aHyXE2 g+2qz5VCRK6fiOrMPbpr+1tLlu1poXfjP7zkOTP1XcVNXUaFEwr51kosxRmJhlrMRcWJAJwCC AKOAgAA X-Env-Sender: venu.busireddy@oracle.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1485195680!81467548!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31819 invoked from network); 23 Jan 2017 18:21:22 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Jan 2017 18:21:22 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0NILJ9a031083 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jan 2017 18:21:19 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v0NILIKs021028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Jan 2017 18:21:18 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v0NILIRR018327; Mon, 23 Jan 2017 18:21:18 GMT Received: from lenovo.localdomain (/24.55.20.143) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 23 Jan 2017 10:21:17 -0800 From: Venu Busireddy To: venu.busireddy@oracle.com, xen-devel@lists.xen.org Date: Mon, 23 Jan 2017 12:20:37 -0600 Message-Id: <1485195639-1996-2-git-send-email-venu.busireddy@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485195639-1996-1-git-send-email-venu.busireddy@oracle.com> References: <1485195639-1996-1-git-send-email-venu.busireddy@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: Elena Ufimtseva , Kevin Tian , Feng Wu , Jan Beulich Subject: [Xen-devel] [PATCH v14 1/3] iommu VT-d: separate rmrr addition function. 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 In preparation for auxiliary RMRR data provided on Xen command line, make RMRR adding a separate function. Also free memery for rmrr device scope in error path. Signed-off-by: Elena Ufimtseva Signed-off-by: Venu Busireddy Acked-by: Kevin Tian Reviewed-by: Jan Beulich Acked-by: Kevin Tian --- xen/drivers/passthrough/vtd/dmar.c | 123 ++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 58 deletions(-) Changes in v14: - Capture the return value from register_one_rmrr() and use it. diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c index 08c1d2d..3c7c9b2 100644 --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -579,6 +579,68 @@ out: return ret; } +static int register_one_rmrr(struct acpi_rmrr_unit *rmrru) +{ + bool ignore = false; + unsigned int i = 0; + int ret = 0; + + /* Skip checking if segment is not accessible yet. */ + if ( !pci_known_segment(rmrru->segment) ) + i = UINT_MAX; + + for ( ; i < rmrru->scope.devices_cnt; i++ ) + { + u8 b = PCI_BUS(rmrru->scope.devices[i]); + u8 d = PCI_SLOT(rmrru->scope.devices[i]); + u8 f = PCI_FUNC(rmrru->scope.devices[i]); + + if ( pci_device_detect(rmrru->segment, b, d, f) == 0 ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Non-existent device (%04x:%02x:%02x.%u) is reported" + " in RMRR (%"PRIx64", %"PRIx64")'s scope!\n", + rmrru->segment, b, d, f, + rmrru->base_address, rmrru->end_address); + ignore = true; + } + else + { + ignore = false; + break; + } + } + + if ( ignore ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " Ignore the RMRR (%"PRIx64", %"PRIx64") due to " + "devices under its scope are not PCI discoverable!\n", + rmrru->base_address, rmrru->end_address); + scope_devices_free(&rmrru->scope); + xfree(rmrru); + } + else if ( rmrru->base_address > rmrru->end_address ) + { + dprintk(XENLOG_WARNING VTDPREFIX, + " The RMRR (%"PRIx64", %"PRIx64") is incorrect!\n", + rmrru->base_address, rmrru->end_address); + scope_devices_free(&rmrru->scope); + xfree(rmrru); + ret = -EFAULT; + } + else + { + if ( iommu_verbose ) + dprintk(VTDPREFIX, + " RMRR region: base_addr %"PRIx64" end_addr %"PRIx64"\n", + rmrru->base_address, rmrru->end_address); + acpi_register_rmrr_unit(rmrru); + } + + return ret; +} + static int __init acpi_parse_one_rmrr(struct acpi_dmar_header *header) { @@ -628,65 +690,10 @@ acpi_parse_one_rmrr(struct acpi_dmar_header *header) ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end, &rmrru->scope, RMRR_TYPE, rmrr->segment); - if ( ret || (rmrru->scope.devices_cnt == 0) ) - xfree(rmrru); + if ( !ret && (rmrru->scope.devices_cnt != 0) ) + ret = register_one_rmrr(rmrru); else - { - u8 b, d, f; - bool_t ignore = 0; - unsigned int i = 0; - - /* Skip checking if segment is not accessible yet. */ - if ( !pci_known_segment(rmrr->segment) ) - i = UINT_MAX; - - for ( ; i < rmrru->scope.devices_cnt; i++ ) - { - b = PCI_BUS(rmrru->scope.devices[i]); - d = PCI_SLOT(rmrru->scope.devices[i]); - f = PCI_FUNC(rmrru->scope.devices[i]); - - if ( !pci_device_detect(rmrr->segment, b, d, f) ) - { - printk(XENLOG_WARNING VTDPREFIX - " Non-existent device (%04x:%02x:%02x.%u) reported in RMRR (%"PRIx64", %"PRIx64")'s scope!\n", - rmrr->segment, b, d, f, - rmrru->base_address, rmrru->end_address); - ignore = 1; - } - else - { - ignore = 0; - break; - } - } - - if ( ignore ) - { - printk(XENLOG_WARNING VTDPREFIX - " Ignore RMRR (%"PRIx64", %"PRIx64") (some devices in its scope are not PCI discoverable)\n", - rmrru->base_address, rmrru->end_address); - scope_devices_free(&rmrru->scope); - xfree(rmrru); - } - else if ( base_addr > end_addr ) - { - printk(XENLOG_WARNING VTDPREFIX - " RMRR (%"PRIx64", %"PRIx64") is incorrect\n", - rmrru->base_address, rmrru->end_address); - scope_devices_free(&rmrru->scope); - xfree(rmrru); - ret = -EFAULT; - } - else - { - if ( iommu_verbose ) - printk(VTDPREFIX - " RMRR region: base_addr %"PRIx64" end_address %"PRIx64"\n", - rmrru->base_address, rmrru->end_address); - acpi_register_rmrr_unit(rmrru); - } - } + xfree(rmrru); return ret; }