From patchwork Tue Jan 10 22:57:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 9509265 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 4C9D660710 for ; Wed, 11 Jan 2017 04:55:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E50628571 for ; Wed, 11 Jan 2017 04:55:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32F6528596; Wed, 11 Jan 2017 04:55:46 +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 9EF8A28571 for ; Wed, 11 Jan 2017 04:55:45 +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 1cRAuK-0008Eg-KM; Wed, 11 Jan 2017 04:53:08 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cR5NR-0007ji-Oy for xen-devel@lists.xen.org; Tue, 10 Jan 2017 22:58:49 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id 5F/65-09690-82765785; Tue, 10 Jan 2017 22:58:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXSO6nOVVc9vTT C4Ms+Y4slHxezODB6HN39mymAMYo1My8pvyKBNePF2aqCnRoVq67+Z21gnCfdxcjFISQwkUmi YeMcZgjnL6PE1TXPoZyNjBLfr09ghHA6GSUu7PgAlOHkYBMwkDh6uIcVxBYR8JXYe+ksC0gRs 8BMRokt7ZfYQBLCAq4S05/8BbI5OFgEVCX+7VUBCfMKeEj8OTqBCcSWEJCTuHmuE2wmp4CnxL +NE9lBbCGgmuYnLVA1hhKnH25jnMDIt4CRYRWjenFqUVlqka6hXlJRZnpGSW5iZo6uoYGxXm5 qcXFiempOYlKxXnJ+7iZGYKAwAMEOxuUfnQ4xSnIwKYnyWtmWRgjxJeWnVGYkFmfEF5XmpBYf YpTh4FCS4GVNA8oJFqWmp1akZeYAQxYmLcHBoyTCawCS5i0uSMwtzkyHSJ1iVJQS52UGSQiAJ DJK8+DaYHFyiVFWSpiXEegQIZ6C1KLczBJU+VeM4hyMSsK8tiBTeDLzSuCmvwJazAS0ONKuGG RxSSJCSqqBMVr+sPk+TVfBXPWlx7KfWrupJPH25brHHt5qxf//uzmH9m337NncIQfiTXz/Zk5 tmqVo9vnGffYJZmZZPKrC/Gl92hFHNmW7B5T/Pm3TtOXnv4PFHNOObm5rc2dUnbvWekZpyueU nPi31X1Rq0S2lNV/mmyXyadh6MmfNK/uXMvJvdn3d89VYinOSDTUYi4qTgQAesYAJ44CAAA= X-Env-Sender: venu.busireddy@oracle.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1484089126!49047091!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38060 invoked from network); 10 Jan 2017 22:58:47 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-11.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jan 2017 22:58:47 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v0AMwiss000361 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Jan 2017 22:58:44 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v0AMwhA0027676 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Jan 2017 22:58:44 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v0AMwh3M001812; Tue, 10 Jan 2017 22:58:43 GMT Received: from lenovo.localdomain (/24.55.20.143) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 10 Jan 2017 14:58:43 -0800 From: Venu Busireddy To: venu.busireddy@oracle.com, Konrad Rzeszutek Wilk Date: Tue, 10 Jan 2017 16:57:34 -0600 Message-Id: <1484089056-8762-2-git-send-email-venu.busireddy@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484089056-8762-1-git-send-email-venu.busireddy@oracle.com> References: <1484089056-8762-1-git-send-email-venu.busireddy@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] X-Mailman-Approved-At: Wed, 11 Jan 2017 04:53:07 +0000 Cc: Elena Ufimtseva , Kevin Tian , Feng Wu , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH v13 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 From: Elena Ufimtseva 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 --- xen/drivers/passthrough/vtd/dmar.c | 123 ++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 58 deletions(-) diff --git a/xen/drivers/passthrough/vtd/dmar.c b/xen/drivers/passthrough/vtd/dmar.c index 08c1d2d..84bf63d 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) ) + 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; }