From patchwork Fri Jan 3 00:08:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 3428461 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EED7DC02DC for ; Fri, 3 Jan 2014 00:13:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B8DE2017D for ; Fri, 3 Jan 2014 00:13:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E778520145 for ; Fri, 3 Jan 2014 00:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753337AbaACANT (ORCPT ); Thu, 2 Jan 2014 19:13:19 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:23713 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753990AbaACAHq (ORCPT ); Thu, 2 Jan 2014 19:07:46 -0500 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id s0307df0031337 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jan 2014 00:07:39 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0307cSb025604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 3 Jan 2014 00:07:38 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s0307cGu021963; Fri, 3 Jan 2014 00:07:38 GMT Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jan 2014 16:07:38 -0800 From: Yinghai Lu To: "H. Peter Anvin" , Tony Luck , Bjorn Helgaas , "Rafael J. Wysocki" , x86 Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Yinghai Lu , Joerg Roedel , Donald Dutile Subject: [PATCH v2 04/10] IOMMU: iommu_unique_seq_id() Date: Thu, 2 Jan 2014 16:08:11 -0800 Message-Id: <1388707697-16800-5-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1388707697-16800-1-git-send-email-yinghai@kernel.org> References: <1388707697-16800-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 So for hot-remove/hot-add will reuse seq_id. Signed-off-by: Yinghai Lu Cc: Joerg Roedel Cc: Donald Dutile --- drivers/iommu/dmar.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index a14867c..f5e0718 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c @@ -785,11 +785,22 @@ out: return err; } +static DECLARE_BITMAP(iommu_allocated, 1024); + +static int iommu_unique_seq_id(void) +{ + int id; + + id = find_first_zero_bit(iommu_allocated, 1024); + __set_bit(id, iommu_allocated); + + return id; +} + int alloc_iommu(struct dmar_drhd_unit *drhd) { struct intel_iommu *iommu; u32 ver, sts; - static int iommu_allocated = 0; int agaw = 0; int msagaw = 0; int err; @@ -803,7 +814,7 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) if (!iommu) return -ENOMEM; - iommu->seq_id = iommu_allocated++; + iommu->seq_id = iommu_unique_seq_id(); sprintf (iommu->name, "dmar%d", iommu->seq_id); err = map_iommu(iommu, drhd->reg_base_addr); @@ -855,6 +866,7 @@ int alloc_iommu(struct dmar_drhd_unit *drhd) err_unmap: unmap_iommu(iommu); error: + __clear_bit(iommu->seq_id, iommu_allocated); kfree(iommu); return err; } @@ -869,6 +881,8 @@ void free_iommu(struct intel_iommu *iommu) if (iommu->reg) unmap_iommu(iommu); + __clear_bit(iommu->seq_id, iommu_allocated); + kfree(iommu); }