From patchwork Thu Mar 19 19:29:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46091 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EDF1121515 for ; Thu, 19 Mar 2015 19:32:05 +0000 (UTC) Received: by wghl18 with SMTP id l18sf14073017wgh.1 for ; Thu, 19 Mar 2015 12:32:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=lGCjLm1kbZk/CRogK2S51gfG60g4ixneZQPGBClN48k=; b=m8A3TGteF9JBje/wdroP/o2ovcRG/zpXharFI5cL9cXzsE2jz4uf6Ey2Jej/0T5Zbf mEMk4ArDOlA8SHoSf5rRHAx3gqVCA+bSUBz47H9zttRLFUES1ljwSyINJKj7jEBsQJOs NJBDwJ1ez3MQINS3NR3AoaMer1LCHS4nwh5A1d1LVAz2XS8dAphgm9nJra4eC1ShYFWU +w0AHsXG1KxRlL3MVcg8I7ZqJPZDblODuJ5dsSLKujarzLP6/BF5rrJpx6rYdhJHt7Bn 4d/VGO8ZNHfAYihAI3w1Tobzj/0huyCGfYciXfOA40i0ZbyzLEO0zCVe5Ht9+5B6cArV /FwQ== X-Gm-Message-State: ALoCoQmD42rx1NG1L7CzJkt6xR4WwvJ1wmJ6B/bDtlAcGGdI8MJFLD74GS+QHIbtdqBqBX0S3mnK X-Received: by 10.180.75.232 with SMTP id f8mr2075224wiw.0.1426793525280; Thu, 19 Mar 2015 12:32:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.4 with SMTP id f4ls287249lah.18.gmail; Thu, 19 Mar 2015 12:32:05 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr51233907lbc.36.1426793525116; Thu, 19 Mar 2015 12:32:05 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id g6si1666802lab.64.2015.03.19.12.32.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:32:04 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbnq5 with SMTP id q5so32326779lbn.0 for ; Thu, 19 Mar 2015 12:32:04 -0700 (PDT) X-Received: by 10.112.162.167 with SMTP id yb7mr68446721lbb.76.1426793524733; Thu, 19 Mar 2015 12:32:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp597387lbj; Thu, 19 Mar 2015 12:32:04 -0700 (PDT) X-Received: by 10.229.184.66 with SMTP id cj2mr97115346qcb.6.1426793520803; Thu, 19 Mar 2015 12:32:00 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id x143si2165022qkx.96.2015.03.19.12.32.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:00 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9x-0004uK-4R; Thu, 19 Mar 2015 19:31:13 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9v-0004oI-0k for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:31:11 +0000 Received: from [193.109.254.147] by server-15.bemta-14.messagelabs.com id FB/90-31237-EF32B055; Thu, 19 Mar 2015 19:31:10 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-3.tower-27.messagelabs.com!1426793469!14313814!1 X-Originating-IP: [74.125.82.51] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23733 invoked from network); 19 Mar 2015 19:31:09 -0000 Received: from mail-wg0-f51.google.com (HELO mail-wg0-f51.google.com) (74.125.82.51) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:31:09 -0000 Received: by wgdm6 with SMTP id m6so71312147wgd.2 for ; Thu, 19 Mar 2015 12:31:09 -0700 (PDT) X-Received: by 10.194.157.68 with SMTP id wk4mr36034075wjb.130.1426793469279; Thu, 19 Mar 2015 12:31:09 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.31.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:31:08 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:47 +0000 Message-Id: <1426793399-6283-22-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v4 21/33] xen/passthrough: Introduce iommu_construct X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: This new function will correctly initialize the IOMMU page table for the current domain. Also use it in iommu_assign_dt_device even though the current IOMMU implementation on ARM shares P2M with the processor. Signed-off-by: Julien Grall Cc: Jan Beulich --- Changes in v4: - Move memory_type_changed in iommu_construct. Added by commit 06ed8cc "x86: avoid needless EPT table ajustment and cache flush" - And an ASSERT and a comment in iommu_assign_dt_device to explain why the call is safe for DOM0 Changes in v3: - The ASSERT in iommu_construct was redundant with the if () - Remove d->need_iommu = 1 in assign_device has it's already done by iommu_construct. - Simplify the code in the caller of iommu_construct Changes in v2: - Add missing Signed-off-by - Rename iommu_buildup to iommu_construct --- xen/drivers/passthrough/arm/iommu.c | 6 ++++++ xen/drivers/passthrough/device_tree.c | 12 ++++++++++++ xen/drivers/passthrough/iommu.c | 26 ++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 22 ++++------------------ xen/include/xen/iommu.h | 2 ++ 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 3007b99..9234657 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -68,3 +68,9 @@ void arch_iommu_domain_destroy(struct domain *d) { iommu_dt_domain_destroy(d); } + +int arch_iommu_populate_page_table(struct domain *d) +{ + /* The IOMMU shares the p2m with the CPU */ + return -ENOSYS; +} diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 377d41d..4d82a09 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -41,6 +41,18 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) if ( !list_empty(&dev->domain_list) ) goto fail; + if ( need_iommu(d) <= 0 ) + { + /* + * The hwdom is forced to use IOMMU for protecting assigned + * device. Therefore the IOMMU data is already set up. + */ + ASSERT(!is_hardware_domain(d)); + rc = iommu_construct(d); + if ( rc ) + goto fail; + } + rc = hd->platform_ops->assign_device(d, 0, dt_to_dev(dev)); if ( rc ) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 92ea26f..faddd50 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -187,6 +187,32 @@ void iommu_teardown(struct domain *d) tasklet_schedule(&iommu_pt_cleanup_tasklet); } +int iommu_construct(struct domain *d) +{ + int rc = 0; + + if ( need_iommu(d) > 0 ) + return 0; + + if ( !iommu_use_hap_pt(d) ) + { + rc = arch_iommu_populate_page_table(d); + if ( rc ) + return rc; + } + + d->need_iommu = 1; + /* + * There may be dirty cache lines when a device is assigned + * and before need_iommu(d) becoming true, this will cause + * memory_type_changed lose effect if memory type changes. + * Call memory_type_changed here to amend this. + */ + memory_type_changed(d); + + return rc; +} + void iommu_domain_destroy(struct domain *d) { struct hvm_iommu *hd = domain_hvm_iommu(d); diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 4b83583..18b74f4 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1353,25 +1353,11 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) if ( !spin_trylock(&pcidevs_lock) ) return -ERESTART; - if ( need_iommu(d) <= 0 ) + rc = iommu_construct(d); + if ( rc ) { - if ( !iommu_use_hap_pt(d) ) - { - rc = arch_iommu_populate_page_table(d); - if ( rc ) - { - spin_unlock(&pcidevs_lock); - return rc; - } - } - d->need_iommu = 1; - /* - * There may be dirty cache lines when a device is assigned - * and before need_iommu(d) becoming true, this will cause - * memory_type_changed lose effect if memory type changes. - * Call memory_type_changed here to amend this. - */ - memory_type_changed(d); + spin_unlock(&pcidevs_lock); + return rc; } pdev = pci_get_pdev_by_domain(hardware_domain, seg, bus, devfn); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index bf4aff0..e9d2d5c 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -65,6 +65,8 @@ int arch_iommu_domain_init(struct domain *d); int arch_iommu_populate_page_table(struct domain *d); void arch_iommu_check_autotranslated_hwdom(struct domain *d); +int iommu_construct(struct domain *d); + /* Function used internally, use iommu_domain_destroy */ void iommu_teardown(struct domain *d);