From patchwork Tue Jul 25 17:26:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9862575 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 08A6B603FA for ; Tue, 25 Jul 2017 17:30:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF3A8286F3 for ; Tue, 25 Jul 2017 17:30:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDED0286F8; Tue, 25 Jul 2017 17:30:08 +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 F2592286E3 for ; Tue, 25 Jul 2017 17:30:04 +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 1da3c7-0008V1-Im; Tue, 25 Jul 2017 17:27:19 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1da3c5-0008TO-Sy for xen-devel@lists.xenproject.org; Tue, 25 Jul 2017 17:27:17 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 36/31-02962-57F77795; Tue, 25 Jul 2017 17:27:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrHIsWRWlGSWpSXmKPExsVyMfS6k25JfXm kwfcuSYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPz3k+sBU2GFUd+zWNuYFyl0cXIxSEkMINR 4tSJUywgDovASxaJqx/vMoE4EgL9rBKPvj5h72LkBHLiJNauXs8EYVdJfNv4nwXEFhJQkni9c zMTxKjZTBKzX09hBUmwCRhI7H8H0SwCVHRv1WSwImaBbUwSh99PAusWFgiRuLvnMFgDi4CqxN Kzz8BsXgFniZc9/awQ2+Qkbp7rZAaxOQVcJLZ+2ga12Vli/bEDzBMYBRYwMqxi1ChOLSpLLdI 1NtBLKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZLzs/dxAgMLwYg2MH4d23gIUZJDiYlUd5v uuWRQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4DeuAcoJFqempFWmZOcBAh0lLcPAoifC+qgVK8 xYXJOYWZ6ZDpE4xWnJcubLuCxPHlAPbgeSrCf+/MQmx5OXnpUqJ834EaRAAacgozYMbB4vGS4 yyUsK8jEAHCvEUpBblZpagyr9iFOdgVBLmfQ0yhSczrwRu6yugg5iADpozoxTkoJJEhJRUA2P J3PSl6VcdT//2UrPP+cJjZOm5h2VuXmCEIvfmlplC9qdtnx87byW15Lzgq5nM15wM9/8T2P7K aMO5Y5V758kw7C27Wc+0+9SXx9+bOPjLN2ZMXMbccHgCr+iO7vvnxaYcqfJb1SG9jXnBS/4mE 943v2KuOkn2zDVmSJR7VXFb8n+Bfe3dro9KLMUZiYZazEXFiQA2ClVnwQIAAA== X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1501003635!60968766!1 X-Originating-IP: [209.85.215.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17016 invoked from network); 25 Jul 2017 17:27:16 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-2.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 25 Jul 2017 17:27:16 -0000 Received: by mail-lf0-f66.google.com with SMTP id t128so5040339lff.3 for ; Tue, 25 Jul 2017 10:27:16 -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=mR+eHUBrC4/HslTCLBXhDJ5AUg2tOvXkY4JmBkFBTrM=; b=RkeRaG2ioapUWZ9QIe26q02sCLBMHi3QFplwOQdxoHiR2zWNK0aZCygKqOS3n5NY3q kpX+JSAtprErNwtqZQcCzFGV1qiFDFXc3Bm+a0w2QmHZE2w977OuRNyqFRK+GDPZj5TN xt9sT+yEGFPOwO4+/CCUn/SXqoFvrmZxbDNelt1T5fLJP2tCi6HB/iXROQFuFuCzEz6p qHXhlSH1l+59zUagDLc6T/rcN/cORg8dakAO1wrnIwfKLgICw1puAHInlHPL6IMe8kd/ KegxI5x0eYISMTqXHbj37nHuYNI6ZvUS4uTcVvm8bn29Cxww7dyw4ITJnEOUndc4XRCu gnvw== 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=mR+eHUBrC4/HslTCLBXhDJ5AUg2tOvXkY4JmBkFBTrM=; b=miQHZSHl167upIPxR64HxOhlnh4f7OQQKmJG9FMPNdLQnDIp5cnAUbj24veQ6pAwT0 cCFT8Qz2FSf+TWyxdTEdJ2nia9zMM4UYZCn5rAb3twvCjuzIs6k3Qs33lcL3/cTPkDli UGvrfKUHU6XJ0NMVcE2ETglGIjoIg29RhfDZRo/EBr6nDz5ZFBCK+JbMEsDYvbrYhhf2 IqQ2K6KCQK77rW/HzKgf64HLJIbO/cpC0HJy+Z85WnUQ4WuKpuTdg80xUnSkc9UccUvc F0Bp99rlybk7ZFyzZjtKnJixJsZMOrzXzlMbANBf/H5vMZYYU88atbKSrpX99zU1u3GG yKYQ== X-Gm-Message-State: AIVw112rXZzlgtnjsfGjdTwN8ayAHPqntE/dq8pH2le9CSVnkmkZsOY6 JrgZkif3cNCldhTr X-Received: by 10.25.228.156 with SMTP id x28mr6956836lfi.175.1501003635292; Tue, 25 Jul 2017 10:27:15 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-59.209.223.85.sovam.net.ua. [85.223.209.59]) by smtp.gmail.com with ESMTPSA id v145sm411748lfa.21.2017.07.25.10.27.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Jul 2017 10:27:14 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 25 Jul 2017 20:26:48 +0300 Message-Id: <1501003615-15274-7-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501003615-15274-1-git-send-email-olekstysh@gmail.com> References: <1501003615-15274-1-git-send-email-olekstysh@gmail.com> Cc: Kevin Tian , Stefano Stabellini , Suravee Suthikulpanit , Andrew Cooper , Oleksandr Tyshchenko , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v2 06/13] 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 domain has statically assigned devices which will most likely be used for passthrough and as the result the IOMMU is expected to be used for this domain. Taking into the account this hint when dealing with non-shared IOMMUs we can populate IOMMU page tables before hand avoid going through the list of pages at the first assigned device. As this flag doesn't cover hotplug case, we will continue to populate IOMMU page tables on the fly. Extend corresponding platform callback with extra argument as well and pass thought incoming flag to the IOMMU drivers followed by updating "d->need_iommu" flag for any domains. But, it must be an additional logic before updating this flag for hardware domains which the next patch is introducing. 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. Signed-off-by: Oleksandr Tyshchenko CC: Jan Beulich CC: Julien Grall CC: Stefano Stabellini CC: Andrew Cooper CC: Kevin Tian CC: Suravee Suthikulpanit --- Changes in v1: - Clarify patch subject/description. - s/bool_t/bool/ Changes in v2: - Extend "init" callback with extra argument too. - Clarify patch description. - Add maintainers in CC --- xen/arch/arm/domain.c | 2 +- xen/arch/x86/domain.c | 2 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 2 +- xen/drivers/passthrough/arm/smmu.c | 2 +- xen/drivers/passthrough/iommu.c | 10 ++++++++-- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/xen/iommu.h | 4 ++-- 7 files changed, 15 insertions(+), 9 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 d7e6992..1ffe76c 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/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index fe744d2..2491e8c 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -261,7 +261,7 @@ static int get_paging_mode(unsigned long entries) return level; } -static int amd_iommu_domain_init(struct domain *d) +static int amd_iommu_domain_init(struct domain *d, bool use_iommu) { struct domain_iommu *hd = dom_iommu(d); diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index e828308..652b58c 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -2705,7 +2705,7 @@ static int arm_smmu_reassign_dev(struct domain *s, struct domain *t, return 0; } -static int arm_smmu_iommu_domain_init(struct domain *d) +static int arm_smmu_iommu_domain_init(struct domain *d, bool use_iommu) { struct arm_smmu_xen_domain *xen_domain; diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 3e9e4c3..19c87d1 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,13 @@ 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, use_iommu); + if ( ret ) + return ret; + + d->need_iommu = use_iommu; + + return 0; } static void __hwdom_init check_hwdom_reqs(struct domain *d) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index b4e8c89..45d1f36 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -1277,7 +1277,7 @@ void __init iommu_free(struct acpi_drhd_unit *drhd) agaw = 64; \ agaw; }) -static int intel_iommu_domain_init(struct domain *d) +static int intel_iommu_domain_init(struct domain *d, bool use_iommu) { dom_iommu(d)->arch.agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 3297998..f4d489e 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); @@ -155,7 +155,7 @@ struct page_info; typedef int iommu_grdm_t(xen_pfn_t start, xen_ulong_t nr, u32 id, void *ctxt); struct iommu_ops { - int (*init)(struct domain *d); + int (*init)(struct domain *d, bool use_iommu); void (*hwdom_init)(struct domain *d); int (*add_device)(u8 devfn, device_t *dev); int (*enable_device)(device_t *dev);