From patchwork Wed Mar 15 20:05:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9626571 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 E514B6048C for ; Wed, 15 Mar 2017 20:08:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3DE52856F for ; Wed, 15 Mar 2017 20:08:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C872828675; Wed, 15 Mar 2017 20:08:39 +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 841E128674 for ; Wed, 15 Mar 2017 20:08:38 +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 1coFBH-0008WL-Hr; Wed, 15 Mar 2017 20:05:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coFBG-0008Vt-Jg for xen-devel@lists.xenproject.org; Wed, 15 Mar 2017 20:05:58 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id C5/CA-19731-5AE99C85; Wed, 15 Mar 2017 20:05:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCIsWRWlGSWpSXmKPExsVyMbThiO7SeSc jDPY0CFh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmfNy9iKlgoXXHkp2oD42KxLkYuDiGBmYwS 85d8Yeti5ORgEXjJItH3NwwkISHQzyqxc+seRpCEhECMxM7585gg7CqJ3mePWUBsIQElidc7N zNB2HOYJKZcSASx2QQMJPa/e8IOYosA1dxbNZkJZCizwBlGic+LJoM1CAtESux72s0CsVlVYu 6JlcxdjBwcvAJOEu/nCkHskpO4ea6TGcTmFHCWePG0hRVil5PEtAUnmScwCixgZFjFqFGcWlS WWqRraK6XVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyXnJ+7iREYVgxAsIPx9saAQ4ySHExK orzXz52IEOJLyk+pzEgszogvKs1JLT7EKMPBoSTBW38bKCdYlJqeWpGWmQMMcJi0BAePkgjvJ 5A0b3FBYm5xZjpE6hSjMceDU7veMHF86j/8hkmIJS8/L1VKnPcZSKkASGlGaR7cIFjkXWKUlR LmZQQ6TYinILUoN7MEVf4VozgHo5Iw72eQKTyZeSVw+14BncIEdErizyMgp5QkIqSkGhhzGhs 6pv8y+6rx3FO+tqM+M5CzxXNSgIfQDff4OB1+kbOhafqJerOn8j/RUGNzUu40WsLxwmXF9rkG O23Ed137f0713/UTwqeqbEJm7onYLPZM5lvAVdcpL/s233x097Rtmnv/r6M/uZlKciqO/DUyY zmdy5T8hfdI5K4o/sUpjx4zO3X5/lBiKc5INNRiLipOBABTtUEptwIAAA== X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1489608357!68747236!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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51874 invoked from network); 15 Mar 2017 20:05:57 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-10.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 15 Mar 2017 20:05:57 -0000 Received: by mail-wr0-f196.google.com with SMTP id u108so3363928wrb.2 for ; Wed, 15 Mar 2017 13:05:57 -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=rcFfNmmGwJDfUJlIVBNXp8r91HwTC3NWRH8uaCfEIbU=; b=rG4xGrexjPvB6jQ+m2zXBVkS/bJ+S8DkcyOw1xJgEBjeI6Pemw9xxhLqm2zB4BLob+ F4BjywIRlzsELheqNbGDVsyzTFRaejnioCUSWFACBDE40gAEFRaPao0nLZLqw2sLlm5Z vZ3vVyfGIiYR9r7ddYcgmIGN5JLcXhGqOig3ZHC3MskHamG26XZmLYBMoWGV0E0FdcAK /+oV+wVr9oW4BwAVHybZh6XtJrLeG0OEwhtzVTmZbLSbMUevPJlqfdXinuQVPjcIVq/w MVB3SFUTR8hmC79rkDWOoRy/hpH95Y/iHSEX7iDt8GG+2NWJPX6KFCTCYo4cLtVb7ecD VIGg== 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=rcFfNmmGwJDfUJlIVBNXp8r91HwTC3NWRH8uaCfEIbU=; b=R8zRspCZnGVjyGF2AbTmnKDQg9dUB0L3mtYHenTaRPexzW5KzLIFWGk7YLTrSRpe5H mGuI4K+KqpXoYGGmFSYtIF3pEd+hlCkllrfUY0xT/ipIQFM5OI/m4Uxz3KXGVEZM0JKR v7Bh3iQwItVXevLO6AR1mxN67zYJlhst2xkxumHHxOpILiIdU3v6xC+eWZ2ICL+ATVYB XZhbqNua/9bQ5hLTOX4rcS8Uy3TPaKDYplT90B/vsv5Rr3v0c6ZaIq3Hi4HJ6JbFUeMG Al9sUwHe6MPgCbSM4i12lTgj5E0WBsDTVuTX0dYQR4meKjM1w8zjyJS94DlguRGhB8h4 /qSg== X-Gm-Message-State: AFeK/H3zIwXdPAYpSXK1Rw5QV1GTPf7PUzKs3xdeFeJzMVTJl+IywkfJbFIoHtZJ2sfrFw== X-Received: by 10.223.151.45 with SMTP id r42mr4578225wrb.185.1489608356912; Wed, 15 Mar 2017 13:05:56 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id b130sm1651516wma.17.2017.03.15.13.05.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Mar 2017 13:05:56 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Wed, 15 Mar 2017 22:05:26 +0200 Message-Id: <1489608329-7275-7-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489608329-7275-1-git-send-email-olekstysh@gmail.com> References: <1489608329-7275-1-git-send-email-olekstysh@gmail.com> Cc: sstabellini@kernel.org, vlad.babchuk@gmail.com, al1img@gmail.com, andrii.anisov@gmail.com, olekstysh@gmail.com, andr2000@gmail.com, julien.grall@arm.com, JBeulich@suse.com, joculator@gmail.com Subject: [Xen-devel] [RFC PATCH 6/9] iommu: Pass additional 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. 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 forced to false use_iommu flag for now, no functional change is intended. Basically, this patch is needed for unshared IOMMUs on ARM only since the unshared 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 applicable for both platforms. So, the patch target is to make ARM happy and not to brake x86. Confirmation from x86 guys is needed. Signed-off-by: Oleksandr Tyshchenko --- 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 bb327da..bab62ee 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -550,7 +550,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 479aee6..8ef4160 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -646,7 +646,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 115698f..6c17c59 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_t 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 0446ed3..ab68ae2 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_t 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);