From patchwork Wed Mar 15 20:05:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 9626575 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 C852D604A9 for ; Wed, 15 Mar 2017 20:09:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B619B2856F for ; Wed, 15 Mar 2017 20:09:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAB0828675; Wed, 15 Mar 2017 20:09: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 0C0942856F for ; Wed, 15 Mar 2017 20:09: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 1coFBL-00009R-Dr; Wed, 15 Mar 2017 20:06:03 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coFBK-000083-Ay for xen-devel@lists.xenproject.org; Wed, 15 Mar 2017 20:06:02 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id F7/58-13095-9AE99C85; Wed, 15 Mar 2017 20:06:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrEIsWRWlGSWpSXmKPExsXiVRvkrLty3sk Ig9NnWCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owd12YxFzzWqli2aztrA2OTUhcjF4eQwHRG iX+t75hBHBaBlywSD7ecYgNxJAT6WSUm9M4CynACOTESU2+tYYewKyRuTTzOBGILCShJvN65m Qli1BwmicZri1lBEmwCBhL73z0BaxABKrq3ajJYEbPAGUaJz4smg3ULC7hL3Hh2D8xmEVCVmD p5NVgzr4CzxOZ3DWwQ2+Qkbp7rBLuCEyj+4mkLK8RmJ4lpC04yT2AUWMDIsIpRozi1qCy1SNf YQC+pKDM9oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTIzC8GIBgB+PftYGHGCU5mJREeT/P PRghxJeUn1KZkVicEV9UmpNafIhRhoNDSYKX7zRQTrAoNT21Ii0zBxjoMGkJDh4lEd6dp4DSv MUFibnFmekQqVOMuhwf+g+/YRJiycvPS5US570DUiQAUpRRmgc3AhZ1lxhlpYR5GYGOEuIpSC 3KzSxBlX/FKM7BqCTM+x1kCk9mXgncpldARzABHTGND+yIkkSElFQDY7TTLe+nhzLmVUtlzDB p1Lv0fMv0jT9tp33TVBd7cthXZ+3+HXXdv8We26x+Ju0dVsr1uKw4re59ZFynhpqaX77gs312 fQkNDv3Vl1auUJprY7XdhNtArvSM0/5nIf82lbO/ikt/8a840qwvOMXw54F7Owq0zbaq72xeM mXNSs8t+aGv9E4IKbEUZyQaajEXFScCAHcWH1q1AgAA X-Env-Sender: olekstysh@gmail.com X-Msg-Ref: server-16.tower-21.messagelabs.com!1489608360!58016552!1 X-Originating-IP: [74.125.82.67] 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 24660 invoked from network); 15 Mar 2017 20:06:01 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-16.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 15 Mar 2017 20:06:01 -0000 Received: by mail-wm0-f67.google.com with SMTP id n11so6465399wma.0 for ; Wed, 15 Mar 2017 13:06:01 -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=CuCzaue3dMh7XTTVAV1dm+rovm5g9lPIArfTRoHPSE8=; b=lUPDGrE8Tw0Ze+z48awE/LMpcxfszeTB4ytkIs3VI73wUZq+vvn/KezSfKzLiYbN9b CC2nu1taRj9Y3PO8pZ+JfgPR+sXXHezB52li9b0aEtCn/nvDpq1zCyMbhlefLkRNgH6N P+HonZ0yLoRt0ktcpbvUg8qOl0B+qckuOlh6865iUXclMM+1bnFhub8p/8mzvY+byTrA PVjZAJMzIw0txCj5Gs+4YWkMkTakqqFmX/l8JExw/6CApXRrTNjAxGx3K6d8NOvwaWiK MOlw+qdWHHWiNf1cSA7U3tDFQdCgIjPv9zb433gLxcOEEDc53IbEh4myuRHuruZ8n/lk 3A7Q== 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=CuCzaue3dMh7XTTVAV1dm+rovm5g9lPIArfTRoHPSE8=; b=Y6zgtkYQh7ko74R37qgh1S3676odpXUpqgSv27kD0aBzasVVmJYhxK/R97HWAz/DVV 8Y+e1mgrQIMA+qYXZxqQON8ftp08ZC2ODBdTizLDGSko30vC4RRfNKNtA+6DsAItz/h0 KLLRZvvzJoqLTIF3pKW0qoh0SgDIAIbXV30V/m54fSfZcqexivB97JvdPzHrAd9M/Sys cH2U022C1fTGBFsPDMZgId+B1O4ycdvyKTP5NaJ3lyKE3pYKXeDHql5M6MW4yQuUvqA4 waUVpf8BIjE90pjpItfivj5sADSOAs7WFfDET5ssRpJy8BjcbDIkUsQorXxtMvEtmhRz PDtQ== X-Gm-Message-State: AFeK/H3Wj1P93Yf8euHcU8jSQ1c6n9kN6ihU2XVi67ZfuXEYB4f3E2ygpzXOpsnCb5xExg== X-Received: by 10.28.21.210 with SMTP id 201mr3954952wmv.94.1489608360646; Wed, 15 Mar 2017 13:06:00 -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.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Mar 2017 13:06:00 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Wed, 15 Mar 2017 22:05:29 +0200 Message-Id: <1489608329-7275-10-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 9/9] xen: Add use_iommu flag to createdomain domctl 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 This flag is intended to let Xen know that the guest has devices which will most likely be used for passthrough. The primary aim of this knowledge is to help the IOMMUs that don't share page tables with the CPU be ready before P2M code starts updating IOMMU mapping. So, if this flag is set the unshared IOMMUs will populate their page tables at the domain creation time and thereby will be able to handle IOMMU mapping updates from *the very beginning*. Signed-off-by: Oleksandr Tyshchenko --- tools/libxl/libxl_create.c | 5 +++++ xen/arch/arm/domain.c | 4 +++- xen/arch/x86/domain.c | 4 +++- xen/common/domctl.c | 5 ++++- xen/include/public/domctl.h | 3 +++ xen/include/xen/sched.h | 3 +++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index e741b9a..4393fa2 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -546,6 +546,11 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config, flags |= XEN_DOMCTL_CDF_hap; } + /* TODO Are these assumptions enough to make decision about using IOMMU? */ + if ((d_config->num_dtdevs && d_config->dtdevs) || + (d_config->num_pcidevs && d_config->pcidevs)) + flags |= XEN_DOMCTL_CDF_use_iommu; + /* Ultimately, handle is an array of 16 uint8_t, same as uuid */ libxl_uuid_copy(ctx, (libxl_uuid *)handle, &info->uuid); diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index bab62ee..940bb98 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -539,6 +539,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, struct xen_arch_domainconfig *config) { int rc, count = 0; + bool_t use_iommu; BUILD_BUG_ON(GUEST_MAX_VCPUS < MAX_VIRT_CPUS); d->arch.relmem = RELMEM_not_started; @@ -550,7 +551,8 @@ 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, false)) != 0 ) + use_iommu = !!(domcr_flags & DOMCRF_use_iommu); + if ( (rc = iommu_domain_init(d, use_iommu)) != 0 ) goto fail; if ( (rc = p2m_init(d)) != 0 ) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 8ef4160..7d634ff 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -525,6 +525,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, { bool paging_initialised = false; int rc = -ENOMEM; + bool_t use_iommu; if ( config == NULL && !is_idle_domain(d) ) return -EINVAL; @@ -646,7 +647,8 @@ 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, false)) != 0 ) + use_iommu = !!(domcr_flags & DOMCRF_use_iommu); + if ( (rc = iommu_domain_init(d, use_iommu)) != 0 ) goto fail; } spin_lock_init(&d->arch.e820_lock); diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 93e3029..56c4d38 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -505,7 +505,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) | XEN_DOMCTL_CDF_hap | XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off - | XEN_DOMCTL_CDF_xs_domain)) ) + | XEN_DOMCTL_CDF_xs_domain + | XEN_DOMCTL_CDF_use_iommu)) ) break; dom = op->domain; @@ -549,6 +550,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) domcr_flags |= DOMCRF_oos_off; if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_xs_domain ) domcr_flags |= DOMCRF_xs_domain; + if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_use_iommu ) + domcr_flags |= DOMCRF_use_iommu; d = domain_create(dom, domcr_flags, op->u.createdomain.ssidref, &op->u.createdomain.config); diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 85cbb7c..a37a566 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -66,6 +66,9 @@ struct xen_domctl_createdomain { /* Is this a xenstore domain? */ #define _XEN_DOMCTL_CDF_xs_domain 5 #define XEN_DOMCTL_CDF_xs_domain (1U<<_XEN_DOMCTL_CDF_xs_domain) + /* Should IOMMU page tables be populated at the domain creation time? */ +#define _XEN_DOMCTL_CDF_use_iommu 6 +#define XEN_DOMCTL_CDF_use_iommu (1U<<_XEN_DOMCTL_CDF_use_iommu) uint32_t flags; struct xen_arch_domainconfig config; }; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 0929c0b..80e6fdc 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -561,6 +561,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags, /* DOMCRF_xs_domain: xenstore domain */ #define _DOMCRF_xs_domain 6 #define DOMCRF_xs_domain (1U<<_DOMCRF_xs_domain) + /* DOMCRF_use_iommu: Populate IOMMU page tables at the domain creation time */ +#define _DOMCRF_use_iommu 7 +#define DOMCRF_use_iommu (1U<<_DOMCRF_use_iommu) /* * rcu_lock_domain_by_id() is more efficient than get_domain_by_id().