From patchwork Wed May 10 14:03:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9719913 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 D7FD96035D for ; Wed, 10 May 2017 14:06:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA17028608 for ; Wed, 10 May 2017 14:06:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEEBF28609; Wed, 10 May 2017 14:06:06 +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=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 4C97228602 for ; Wed, 10 May 2017 14:06:06 +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 1d8SDP-00079l-Nn; Wed, 10 May 2017 14:03:43 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8SDN-00078G-Uu for xen-devel@lists.xenproject.org; Wed, 10 May 2017 14:03:42 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id E2/BF-03920-DBD13195; Wed, 10 May 2017 14:03:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRWlGSWpSXmKPExsVyMbThiO4eWeF Ig9NP9Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyXa2ayFUyUqTg5hauB8ZtYFyMXh5DADEaJ qV+/sYE4LAIvWSTWLVjEAuJICPSzSlz5+Jq5i5ETyImTeLqtgwnCrpa4f+M9WFxIQEni9c7NT BCjZjFJLD52C6yITcBAYv+7J+wgtghQ0b1Vk8HizALlEj0zl7GB2MICIRIP/u5jBbFZBFQlbm +YBxbnFXCW2PBuOSPEMjmJm+c6wZZxCrhI7Hh9hwVisbPE/4/fWScwCixgZFjFqFGcWlSWWqR raKCXVJSZnlGSm5iZA+SZ6eWmFhcnpqfmJCYV6yXn525iBIYWAxDsYLy3LOAQoyQHk5Ior+4u oUghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErwXZIQjhQSLUtNTK9Iyc4BBDpOW4OBREuE9KgGU5 i0uSMwtzkyHSJ1iNOZ4cfn9eyaOJyt/vGcSYsnLz0uVEuftApkkAFKaUZoHNwgWfZcYZaWEeR mBThPiKUgtys0sQZV/xSjOwagkzHsRZApPZl4J3L5XQKcwAZ0SyCAAckpJIkJKqoExeUv+NZN sv806B0+8/WHbIfD2gdytk7FWD2afZSxwy/6U1H13X3jaCuWKiW+vJTE3yh7qPPltZccG2Y3O R4+3JXHdDVku9nXu8knv/E/qahlOaNM+Lf251sKy3SN5iYJyEt8M48SQCRLHbLbaT/mmZ5dzJ Xnysp87f3sc2nJ6j1/Cx8viNg9alViKMxINtZiLihMBgx5EA7kCAAA= X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1494425020!96762402!1 X-Originating-IP: [209.85.128.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 54770 invoked from network); 10 May 2017 14:03:40 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-7.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 May 2017 14:03:40 -0000 Received: by mail-wr0-f196.google.com with SMTP id v42so8709807wrc.3 for ; Wed, 10 May 2017 07:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nO7ddFBlNSlNhSIK+iOMtkKDdTWMOhViDpSvhjHclyM=; b=roK6A70CFPuAk7/XAoL4h7ABLOgFsdyS5MBggJ2JgXPckFN14oA+ZPo+honoLf/AZy ywyGBz/iTi9R+rLjkELrwMh0ILziuiTDBOK7OfUwvG/hRwJusKoH17m3dVJE0TN4HSbl Vl36DVE+XlRVJYD6RUKOYLxrQu7wMZKS7r7ai57pyf+PRAhS1uQVdPJ5jWh1BMg4Zd9A /OXOIu6hkj5Z3VmqM9vW4ktNaiM4g8mjAA+D9rZTQjDvM1GfiLV7C9IPI23qm8KpZ6Q1 /Hh7jO837I5qc2uE1EvgK3tD8cWtDHsvfXtkCcwtGACSxky2sY8/oSfAu1zN4VwM76mA /AqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nO7ddFBlNSlNhSIK+iOMtkKDdTWMOhViDpSvhjHclyM=; b=ZvaMnyvILrD4Ld2t9/LAq9hH30hQsig4ByYvEroGw1qed0oFAVCzwP7oZ8qnwCU9H+ YpgNYxpp6WOWcicN92aXdm4V2BThJwy0u9e4grlx1aUJ10f+eP+qA6TeBK426l8uB26u wqJryn+N+YzaM/Jpc5MTUvkSnt0ZkDKbSauu+2yJ/HjfiE3gxt56a+6QOjlYF7B7rvfy kC1LDh3W9ysRu3WIl7tCUqlnBq7i1kSENTZqz69kZVMCnDrB9x0EJj99qDpRZ/HJhhWc sVrBqTBj2JS1fuCyoUTUFfX7vJC0FEtWIi536anoctAzIVPLhzMQR0x5ZKIprfPjzAOb t7hQ== X-Gm-Message-State: AODbwcB3ZYR5q9Da5staUOsv+dr5IVpw0Ajo/3CE1bQh/HHQgHqt6+el 1WbjnKTvTFhAgQ== X-Received: by 10.223.169.230 with SMTP id b93mr4267381wrd.196.1494425020403; Wed, 10 May 2017 07:03:40 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-54.209.223.85.sovam.net.ua. [85.223.209.54]) by smtp.gmail.com with ESMTPSA id c34sm3378304wrc.7.2017.05.10.07.03.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 May 2017 07:03:39 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Wed, 10 May 2017 17:03:10 +0300 Message-Id: <1494424994-26232-7-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494424994-26232-1-git-send-email-olekstysh@gmail.com> References: <1494424994-26232-1-git-send-email-olekstysh@gmail.com> Cc: wei.liu2@citrix.com, julien.grall@arm.com, sstabellini@kernel.org, ian.jackson@eu.citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v1 06/10] iommu: Add extra use_iommu argument to iommu_domain_init() 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: Oleksandr Tyshchenko The presence of this flag lets us know that the guest has devices which will most likely be used for passthrough and as the result the use of IOMMU is expected for this domain. In that case we have to call iommu_construct(), actually what the real assign_device call usually does. As iommu_domain_init() is called with use_iommu flag being forced to false for now, no functional change is intended for both ARM and x86. Basically, this patch is needed for non-shared IOMMUs on ARM only since the non-shared IOMMUs on x86 are ok if iommu_construct() is called later. But, in order to be more generic and for possible future optimization make this change appliable for both platforms. Signed-off-by: Oleksandr Tyshchenko CC: Jan Beulich --- Changes in v1: - Clarify patch subject/description. - s/bool_t/bool/ --- xen/arch/arm/domain.c | 2 +- xen/arch/x86/domain.c | 2 +- xen/drivers/passthrough/iommu.c | 11 +++++++++-- xen/include/xen/iommu.h | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 76310ed..ec19310 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -569,7 +569,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, ASSERT(config != NULL); /* p2m_init relies on some value initialized by the IOMMU subsystem */ - if ( (rc = iommu_domain_init(d)) != 0 ) + if ( (rc = iommu_domain_init(d, false)) != 0 ) goto fail; if ( (rc = p2m_init(d)) != 0 ) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 90e2b1f..54037af 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -641,7 +641,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, if ( (rc = init_domain_irq_mapping(d)) != 0 ) goto fail; - if ( (rc = iommu_domain_init(d)) != 0 ) + if ( (rc = iommu_domain_init(d, false)) != 0 ) goto fail; } spin_lock_init(&d->arch.e820_lock); diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 3e9e4c3..c85f7b4 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -129,7 +129,7 @@ static void __init parse_iommu_param(char *s) } while ( ss ); } -int iommu_domain_init(struct domain *d) +int iommu_domain_init(struct domain *d, bool use_iommu) { struct domain_iommu *hd = dom_iommu(d); int ret = 0; @@ -142,7 +142,14 @@ int iommu_domain_init(struct domain *d) return 0; hd->platform_ops = iommu_get_ops(); - return hd->platform_ops->init(d); + ret = hd->platform_ops->init(d); + if ( ret ) + return ret; + + if ( use_iommu && !is_hardware_domain(d) ) + ret = iommu_construct(d); + + return ret; } static void __hwdom_init check_hwdom_reqs(struct domain *d) diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 3297998..3afbc3b 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -56,7 +56,7 @@ int iommu_setup(void); int iommu_add_device(struct pci_dev *pdev); int iommu_enable_device(struct pci_dev *pdev); int iommu_remove_device(struct pci_dev *pdev); -int iommu_domain_init(struct domain *d); +int iommu_domain_init(struct domain *d, bool use_iommu); void iommu_hwdom_init(struct domain *d); void iommu_domain_destroy(struct domain *d); int deassign_device(struct domain *d, u16 seg, u8 bus, u8 devfn);