From patchwork Mon Jun 16 16:17:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 31997 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2346520E7A for ; Mon, 16 Jun 2014 16:20:47 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rp16sf19181742pbb.9 for ; Mon, 16 Jun 2014 09:20:46 -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=iY+/376+uwDnnYRSBrRodp1D+Diaj2m5oFfemNHm98k=; b=VEhzmTJceN4bfTN2duNpkjsag1nusvtUY9mmxTJiG1k9bKO6yrf2qfPE38mxW+K7L/ sQM2dS9llKHpRdxmSSL3t4e2Qi0SJVZ3L5WiZh1It8c03HrgeTTNws+oXFTdZA9+RDmT VGhNh1VbR2wudhOI/1zKoAYHQd6i0daeBes9RD06YxQxcjfwOkauJpqMOKHjDfljK8mr wrODCjvyibT8W1+4nvSeOxlixnbdUvT2LsZHxSUBqt+UsW0T8WzhPWbukHYN1ir2GBut ihwdlVyGnA2v8y5k978exeP0CEohtISh6s2OAGiW6b9jt+Pd+Ch2Xo5gW9oEKIsyFeQU E95w== X-Gm-Message-State: ALoCoQkUYNBV/dkG2i7EHFAQNxT5aeqRGA1DwgRwGIaUJCwkFrBfJ1gzls1jR0s6rZ24e3vq2NF3 X-Received: by 10.66.160.34 with SMTP id xh2mr1427740pab.6.1402935646450; Mon, 16 Jun 2014 09:20:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.72 with SMTP id k66ls4408505qgd.96.gmail; Mon, 16 Jun 2014 09:20:46 -0700 (PDT) X-Received: by 10.52.64.225 with SMTP id r1mr4660396vds.30.1402935646343; Mon, 16 Jun 2014 09:20:46 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id t7si4287345vef.53.2014.06.16.09.20.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so6467486veb.0 for ; Mon, 16 Jun 2014 09:20:46 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr17263911vcg.16.1402935646256; Mon, 16 Jun 2014 09:20:46 -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.54.6 with SMTP id vs6csp146228vcb; Mon, 16 Jun 2014 09:20:45 -0700 (PDT) X-Received: by 10.58.112.37 with SMTP id in5mr924004veb.51.1402935645928; Mon, 16 Jun 2014 09:20:45 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id mg9si4286541vcb.58.2014.06.16.09.20.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:45 -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 1WwZc7-0006md-Pc; Mon, 16 Jun 2014 16:18:31 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwZc6-0006lU-Gx for xen-devel@lists.xenproject.org; Mon, 16 Jun 2014 16:18:30 +0000 Received: from [85.158.137.68:62154] by server-13.bemta-3.messagelabs.com id 71/06-18692-5D81F935; Mon, 16 Jun 2014 16:18:29 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-11.tower-31.messagelabs.com!1402935509!10411400!1 X-Originating-IP: [74.125.82.182] 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 17426 invoked from network); 16 Jun 2014 16:18:29 -0000 Received: from mail-we0-f182.google.com (HELO mail-we0-f182.google.com) (74.125.82.182) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jun 2014 16:18:29 -0000 Received: by mail-we0-f182.google.com with SMTP id q59so6059530wes.27 for ; Mon, 16 Jun 2014 09:18:29 -0700 (PDT) X-Received: by 10.180.79.168 with SMTP id k8mr5751649wix.35.1402935508926; Mon, 16 Jun 2014 09:18:28 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id l45sm34836161eep.25.2014.06.16.09.18.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jun 2014 09:18:28 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jun 2014 17:17:57 +0100 Message-Id: <1402935486-29136-11-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> References: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [RFC 10/19] xen/passthrough: Introduce iommu_buildup 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.128.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. --- 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..de4ed64 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 share 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..afb4dfc 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_buildup(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..2e9b48d 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_buildup(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..e31dcfb 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_buildup(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..9b2af51 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_buildup(struct domain *d); + /* Function used internally, use iommu_domain_destroy */ void iommu_teardown(struct domain *d);