From patchwork Thu Jul 31 15:00:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 34668 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A71762188F for ; Thu, 31 Jul 2014 15:02:44 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id gl10sf1914623lab.2 for ; Thu, 31 Jul 2014 08:02:43 -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:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=BT/8jXRc3IZVk0SRWiJsd8iX/rVvOtA86NKwBS313nM=; b=X5NHfF5p0nEgCfPrS9p9VBc8ZlzBj67saKXxfYPwVXU77tkrzsqvAXaBcbrQY1JvT4 iirltBToX1tYRem2GMxpVKzBtAIOwkCAeyCyO08Z8C1fr5uxI772sGOkH7SNRPYOAorv sxJyuvKDK8abCybldey/aB/s9lyW84KinMrzbCBwSVn2bfLgpDtXP2uFa5FZxt0/92py yLIO3W9czteKEJOEcuYpdpw8Q1wnIxAZ1zjBEfhaF2zduLCjuRr/w+SjS7bTcTDDTq5A fhEQYcqGD7jzmUqTQ901wq4eg4hMQinaiPihEHJm+FM8Rq9+bhBIZg2INGdm9N4PAAWO NNVg== X-Gm-Message-State: ALoCoQkkxyAV3y4dVCX1tvmcN98EI+XZMphSvKBs/Hxi0qPTzUyyFPxTna3Hu75stEBXUt7TK6be X-Received: by 10.194.6.138 with SMTP id b10mr1191661wja.0.1406818962725; Thu, 31 Jul 2014 08:02:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.144 with SMTP id 16ls965975qgt.45.gmail; Thu, 31 Jul 2014 08:02:42 -0700 (PDT) X-Received: by 10.221.68.135 with SMTP id xy7mr11734829vcb.65.1406818962520; Thu, 31 Jul 2014 08:02:42 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id xw5si4632862vcb.11.2014.07.31.08.02.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so4339467vcb.26 for ; Thu, 31 Jul 2014 08:02:41 -0700 (PDT) X-Received: by 10.52.248.146 with SMTP id ym18mr15558308vdc.8.1406818961739; Thu, 31 Jul 2014 08:02:41 -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.221.37.5 with SMTP id tc5csp25100vcb; Thu, 31 Jul 2014 08:02:41 -0700 (PDT) X-Received: by 10.43.107.68 with SMTP id dx4mr16081192icc.34.1406818961191; Thu, 31 Jul 2014 08:02:41 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id f9si14900551igr.28.2014.07.31.08.02.40 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:41 -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 1XCrrA-0000mm-NB; Thu, 31 Jul 2014 15:01:24 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCrr9-0000jq-5H for xen-devel@lists.xenproject.org; Thu, 31 Jul 2014 15:01:23 +0000 Received: from [85.158.139.211:23958] by server-3.bemta-5.messagelabs.com id 2C/63-13873-24A5AD35; Thu, 31 Jul 2014 15:01:22 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-10.tower-206.messagelabs.com!1406818881!5848046!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.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28972 invoked from network); 31 Jul 2014 15:01:21 -0000 Received: from mail-wg0-f51.google.com (HELO mail-wg0-f51.google.com) (74.125.82.51) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 31 Jul 2014 15:01:21 -0000 Received: by mail-wg0-f51.google.com with SMTP id b13so2873446wgh.22 for ; Thu, 31 Jul 2014 08:01:20 -0700 (PDT) X-Received: by 10.194.200.3 with SMTP id jo3mr17957637wjc.110.1406818879875; Thu, 31 Jul 2014 08:01:19 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id r20sm67128337wik.0.2014.07.31.08.01.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jul 2014 08:01:19 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 31 Jul 2014 16:00:45 +0100 Message-Id: <1406818852-31856-15-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1406818852-31856-1-git-send-email-julien.grall@linaro.org> References: <1406818852-31856-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 v2 14/21] 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.220.181 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 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 | 7 +++++++ xen/drivers/passthrough/iommu.c | 25 +++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 12 ++++-------- xen/include/xen/iommu.h | 2 ++ 5 files changed, 44 insertions(+), 8 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 3e47df5..45d4a59 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -41,6 +41,13 @@ 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 ) + { + rc = iommu_construct(d); + if ( rc ) + goto fail; + } + rc = hd->platform_ops->assign_dt_device(d, dev); if ( rc ) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index cc12735..65479d6 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -187,6 +187,31 @@ void iommu_teardown(struct domain *d) tasklet_schedule(&iommu_pt_cleanup_tasklet); } +int iommu_construct(struct domain *d) +{ + int rc = 0; + + /* + * The caller should check we effectively need to set up the IOMMMU + * for this domain. + */ + ASSERT(need_iommu(d) <= 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; + + 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 1eba833..e711a2e 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1342,14 +1342,10 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) if ( need_iommu(d) <= 0 ) { - if ( !iommu_use_hap_pt(d) ) - { - rc = arch_iommu_populate_page_table(d); - if ( rc ) - { - spin_unlock(&pcidevs_lock); - return rc; - } + rc = iommu_construct(d); + if ( rc ) { + spin_unlock(&pcidevs_lock); + return rc; } d->need_iommu = 1; } diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 8eb764a..8dc7bd2 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -64,6 +64,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);