From patchwork Mon Dec 15 09:52:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Zhen-Hua" X-Patchwork-Id: 5491841 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DA0539F30B for ; Mon, 15 Dec 2014 09:57:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 143FF20A01 for ; Mon, 15 Dec 2014 09:57:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1C031209E3 for ; Mon, 15 Dec 2014 09:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751934AbaLOJyM (ORCPT ); Mon, 15 Dec 2014 04:54:12 -0500 Received: from g2t1383g.austin.hp.com ([15.217.136.92]:41823 "EHLO g2t1383g.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbaLOJyK (ORCPT ); Mon, 15 Dec 2014 04:54:10 -0500 Received: from g2t2353.austin.hp.com (g2t2353.austin.hp.com [15.217.128.52]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by g2t1383g.austin.hp.com (Postfix) with ESMTPS id 0C0AF3C5A; Mon, 15 Dec 2014 09:54:10 +0000 (UTC) Received: from g2t2360.austin.hp.com (g2t2360.austin.hp.com [16.197.8.247]) by g2t2353.austin.hp.com (Postfix) with ESMTP id 22AB0C0; Mon, 15 Dec 2014 09:54:08 +0000 (UTC) Received: from piepie.asiapacific.hpqcorp.net (piepie.asiapacific.hpqcorp.net [16.187.246.131]) by g2t2360.austin.hp.com (Postfix) with ESMTP id F112664; Mon, 15 Dec 2014 09:54:03 +0000 (UTC) From: "Li, Zhen-Hua" To: , , , , , , , Cc: , , , , , , , , , , , , Subject: [PATCH 01/10] iommu/vt-d: Update iommu_attach_domain() and its callers Date: Mon, 15 Dec 2014 17:52:57 +0800 Message-Id: <1418637186-9988-2-git-send-email-zhen-hual@hp.com> X-Mailer: git-send-email 2.0.0-rc0 In-Reply-To: <1418637186-9988-1-git-send-email-zhen-hual@hp.com> References: <1418637186-9988-1-git-send-email-zhen-hual@hp.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow specification of the domain-id for the new domain. This patch only adds the 'did' parameter to iommu_attach_domain() and modifies all of its callers to specify the default value of -1 which says "no did specified, allocate a new one". This is no functional change from current behaviour -- just enables a functional change to be made in a later patch. Bill Sumner: Original version. Li, Zhenhua: Minor change, add change to function __iommu_attach_domain. Signed-off-by: Bill Sumner Signed-off-by: Li, Zhen-Hua --- drivers/iommu/intel-iommu.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 1232336..2dc6250 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -1534,31 +1534,36 @@ static struct dmar_domain *alloc_domain(int flags) } static int __iommu_attach_domain(struct dmar_domain *domain, - struct intel_iommu *iommu) + struct intel_iommu *iommu, + int domain_number) { int num; unsigned long ndomains; ndomains = cap_ndoms(iommu->cap); - num = find_first_zero_bit(iommu->domain_ids, ndomains); - if (num < ndomains) { - set_bit(num, iommu->domain_ids); - iommu->domains[num] = domain; - } else { - num = -ENOSPC; - } + if (domain_number < 0) { + num = find_first_zero_bit(iommu->domain_ids, ndomains); + if (num < ndomains) { + set_bit(num, iommu->domain_ids); + iommu->domains[num] = domain; + } else { + num = -ENOSPC; + } + } else + num = domain_number; return num; } static int iommu_attach_domain(struct dmar_domain *domain, - struct intel_iommu *iommu) + struct intel_iommu *iommu, + int domain_number) { int num; unsigned long flags; spin_lock_irqsave(&iommu->lock, flags); - num = __iommu_attach_domain(domain, iommu); + num = __iommu_attach_domain(domain, iommu, domain_number); spin_unlock_irqrestore(&iommu->lock, flags); if (num < 0) pr_err("IOMMU: no free domain ids\n"); @@ -1577,7 +1582,7 @@ static int iommu_attach_vm_domain(struct dmar_domain *domain, if (iommu->domains[num] == domain) return num; - return __iommu_attach_domain(domain, iommu); + return __iommu_attach_domain(domain, iommu, -1); } static void iommu_detach_domain(struct dmar_domain *domain, @@ -2231,6 +2236,7 @@ static struct dmar_domain *get_domain_for_dev(struct device *dev, int gaw) u16 dma_alias; unsigned long flags; u8 bus, devfn; + int did = -1; /* Default to "no domain_id supplied" */ domain = find_domain(dev); if (domain) @@ -2264,7 +2270,7 @@ static struct dmar_domain *get_domain_for_dev(struct device *dev, int gaw) domain = alloc_domain(0); if (!domain) return NULL; - domain->id = iommu_attach_domain(domain, iommu); + domain->id = iommu_attach_domain(domain, iommu, did); if (domain->id < 0) { free_domain_mem(domain); return NULL; @@ -2442,7 +2448,7 @@ static int __init si_domain_init(int hw) return -EFAULT; for_each_active_iommu(iommu, drhd) { - ret = iommu_attach_domain(si_domain, iommu); + ret = iommu_attach_domain(si_domain, iommu, -1); if (ret < 0) { domain_exit(si_domain); return -EFAULT; @@ -3866,7 +3872,7 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru) iommu_enable_translation(iommu); if (si_domain) { - ret = iommu_attach_domain(si_domain, iommu); + ret = iommu_attach_domain(si_domain, iommu, -1); if (ret < 0 || si_domain->id != ret) goto disable_iommu; domain_attach_iommu(si_domain, iommu);