From patchwork Tue Apr 28 14:32:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 47676 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F04CF2121F for ; Tue, 28 Apr 2015 14:35:38 +0000 (UTC) Received: by lamp14 with SMTP id p14sf35042205lam.3 for ; Tue, 28 Apr 2015 07:35:37 -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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=mLk+PBO2PWuStPQbqoJWNo27MW19WX/V2JOrTETL/lU=; b=EOFuOIBNzY2N8BS71YjO/pJIIKRKLd/Lz3ygzC/fgojXnstIUugZrdm6y3F60mo1ir jBimSDqHV7Zs7mP7rTZf3v2QmXLp4lxC/7GiGoIdC+8F93lEA63VnwAZaceWXWWzHgGd GjKuk5mD4JaGt96YS8fY40rTlolCCtCqWX1qT6IRppyJN4DZIdNbj26RKsl/EBUZAxXw GGVM2V0E0MKT1uapaJUYoTMmUhzeFhbKKdXi8aBD1BsPOnozf6EzAZbVRneP/1h+lCpg g9XN4HudtPLCrGC7eDY6AzhF4c3JusWTNo1Ik63zJmMBSjWQN1uDO+eIY0tWmQbzmLCF PZJg== X-Gm-Message-State: ALoCoQk6dN2p8NiO/jUi/iRhBNlAefKSeVQxFSperGq6Tiv8VUK7EDTakW6jrHLDIkuYS/DoMT9f X-Received: by 10.112.28.111 with SMTP id a15mr10405650lbh.21.1430231737787; Tue, 28 Apr 2015 07:35:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.137 with SMTP id o9ls76441lal.16.gmail; Tue, 28 Apr 2015 07:35:37 -0700 (PDT) X-Received: by 10.152.4.72 with SMTP id i8mr3546266lai.32.1430231737676; Tue, 28 Apr 2015 07:35:37 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id uh8si3741559lac.136.2015.04.28.07.35.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 07:35:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by laat2 with SMTP id t2so105949134laa.1 for ; Tue, 28 Apr 2015 07:35:37 -0700 (PDT) X-Received: by 10.112.125.138 with SMTP id mq10mr15115152lbb.35.1430231737566; Tue, 28 Apr 2015 07:35:37 -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.67.65 with SMTP id l1csp1924518lbt; Tue, 28 Apr 2015 07:35:36 -0700 (PDT) X-Received: by 10.140.47.15 with SMTP id l15mr11978485qga.12.1430231730374; Tue, 28 Apr 2015 07:35:30 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id p86si18623049qkh.33.2015.04.28.07.35.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 28 Apr 2015 07:35:30 -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 1Yn6Zp-0007mY-Bf; Tue, 28 Apr 2015 14:33:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6Zn-0007ld-JX for xen-devel@lists.xenproject.org; Tue, 28 Apr 2015 14:33:31 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 96/2D-02119-A3A9F355; Tue, 28 Apr 2015 14:33:30 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1430231606!11240964!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.14; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13323 invoked from network); 28 Apr 2015 14:33:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 28 Apr 2015 14:33:28 -0000 X-IronPort-AV: E=Sophos;i="5.11,663,1422921600"; d="scan'208";a="257345545" From: Julien Grall To: Date: Tue, 28 Apr 2015 15:32:31 +0100 Message-ID: <1430231563-25648-8-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> References: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v6 07/19] 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: , 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: patch@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.215.44 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: From: Julien Grall 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 Acked-by: Jan Beulich Acked-by: Ian Campbell --- Changes in v5: - Limit the scope of rc - Add Jan's and Ian's ack 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..ae42aae 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) +{ + if ( need_iommu(d) > 0 ) + return 0; + + if ( !iommu_use_hap_pt(d) ) + { + int rc; + + 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 0; +} + 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 9f3413c..af26423 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1358,25 +1358,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);