From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5253C43334 for ; Tue, 14 Jun 2022 03:00:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355346AbiFNDAp (ORCPT ); Mon, 13 Jun 2022 23:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355530AbiFNC6x (ORCPT ); Mon, 13 Jun 2022 22:58:53 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3359110AB for ; Mon, 13 Jun 2022 19:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655175341; x=1686711341; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XkrY1IFtBFukO48gqiQ0AuYcbFkThuu4cQHVHVcOWwQ=; b=dC6NEzesiMnGlNzJiQhg71SBwi2JFXjgiyj47+OR3oVyGCBBXmhtkTYE bfCralLiAt/UfZexTChIAJ58H9+eJyG5potwGQoKeh59xDqDsPVfh3a09 kY7JwgEF5T9BkxEtB0yQYcVu+n/DAbwsgenqLcM6yCgJWaYsQAds9hN7h SlNlb8HQKmcAP8NMGu3BQA9khWhjr0kNWYSe97IQ8anpFJMZSDotTd5QB VAgYGzKdRMzP7/JvMGd/YJZTioIgvWKn2Ph3JcZo4VUEEtGVCKaVglH+5 qO8YJHwhG9O/AZylJLtk+/zhd7KSEwAWfgQUQ/agY7CNeNVzuvNIy/jLi w==; X-IronPort-AV: E=McAfee;i="6400,9594,10377"; a="258930291" X-IronPort-AV: E=Sophos;i="5.91,298,1647327600"; d="scan'208";a="258930291" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2022 19:55:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,298,1647327600"; d="scan'208";a="588166431" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga007.fm.intel.com with ESMTP; 13 Jun 2022 19:55:38 -0700 From: Lu Baolu To: Joerg Roedel , Kevin Tian , Ashok Raj , Christoph Hellwig , Jason Gunthorpe Cc: Will Deacon , Robin Murphy , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 02/12] iommu/vt-d: Remove for_each_device_domain() Date: Tue, 14 Jun 2022 10:51:27 +0800 Message-Id: <20220614025137.1632762-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220614025137.1632762-1-baolu.lu@linux.intel.com> References: <20220614025137.1632762-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The per-device device_domain_info data could be retrieved from the device itself. There's no need to search a global list. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.h | 2 -- drivers/iommu/intel/iommu.c | 25 ---------------------- drivers/iommu/intel/pasid.c | 41 +++++++++++-------------------------- 3 files changed, 12 insertions(+), 56 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 8a6d64d726c0..2f4a5b9509c0 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -727,8 +727,6 @@ extern int dmar_ir_support(void); void *alloc_pgtable_page(int node); void free_pgtable_page(void *vaddr); struct intel_iommu *domain_get_iommu(struct dmar_domain *domain); -int for_each_device_domain(int (*fn)(struct device_domain_info *info, - void *data), void *data); void iommu_flush_write_buffer(struct intel_iommu *iommu); int intel_iommu_enable_pasid(struct intel_iommu *iommu, struct device *dev); struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn); diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a39d72a9d1cf..ff6018f746e0 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -316,31 +316,6 @@ static int iommu_skip_te_disable; static DEFINE_SPINLOCK(device_domain_lock); static LIST_HEAD(device_domain_list); - -/* - * Iterate over elements in device_domain_list and call the specified - * callback @fn against each element. - */ -int for_each_device_domain(int (*fn)(struct device_domain_info *info, - void *data), void *data) -{ - int ret = 0; - unsigned long flags; - struct device_domain_info *info; - - spin_lock_irqsave(&device_domain_lock, flags); - list_for_each_entry(info, &device_domain_list, global) { - ret = fn(info, data); - if (ret) { - spin_unlock_irqrestore(&device_domain_lock, flags); - return ret; - } - } - spin_unlock_irqrestore(&device_domain_lock, flags); - - return 0; -} - const struct iommu_ops intel_iommu_ops; static bool translation_pre_enabled(struct intel_iommu *iommu) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index b2ac5869286f..641a4a6eb61e 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -103,36 +103,19 @@ device_detach_pasid_table(struct device_domain_info *info, } struct pasid_table_opaque { - struct pasid_table **pasid_table; - int segment; - int bus; - int devfn; + struct pasid_table *pasid_table; }; -static int search_pasid_table(struct device_domain_info *info, void *opaque) -{ - struct pasid_table_opaque *data = opaque; - - if (info->iommu->segment == data->segment && - info->bus == data->bus && - info->devfn == data->devfn && - info->pasid_table) { - *data->pasid_table = info->pasid_table; - return 1; - } - - return 0; -} - static int get_alias_pasid_table(struct pci_dev *pdev, u16 alias, void *opaque) { struct pasid_table_opaque *data = opaque; + struct device_domain_info *info; - data->segment = pci_domain_nr(pdev->bus); - data->bus = PCI_BUS_NUM(alias); - data->devfn = alias & 0xff; + info = dev_iommu_priv_get(&pdev->dev); + if (info && info->pasid_table) + data->pasid_table = info->pasid_table; - return for_each_device_domain(&search_pasid_table, data); + return data->pasid_table != NULL; } /* @@ -141,12 +124,12 @@ static int get_alias_pasid_table(struct pci_dev *pdev, u16 alias, void *opaque) */ int intel_pasid_alloc_table(struct device *dev) { + struct pasid_table_opaque data = { NULL }; struct device_domain_info *info; struct pasid_table *pasid_table; - struct pasid_table_opaque data; struct page *pages; u32 max_pasid = 0; - int ret, order; + int order; int size; might_sleep(); @@ -155,11 +138,11 @@ int intel_pasid_alloc_table(struct device *dev) return -EINVAL; /* DMA alias device already has a pasid table, use it: */ - data.pasid_table = &pasid_table; - ret = pci_for_each_dma_alias(to_pci_dev(dev), - &get_alias_pasid_table, &data); - if (ret) + if (pci_for_each_dma_alias(to_pci_dev(dev), + get_alias_pasid_table, &data)) { + pasid_table = data.pasid_table; goto attach_out; + } pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL); if (!pasid_table) -- 2.25.1