Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp50919ima; Thu, 14 Mar 2019 19:27:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl65bQ/hDSx2zauucKhV6r3uAVs8tALU+79MeQuJk3QaBWDH69vtabFeTF31KWoFHst66I X-Received: by 2002:a17:902:a5c6:: with SMTP id t6mr1547562plq.221.1552616830216; Thu, 14 Mar 2019 19:27:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552616830; cv=none; d=google.com; s=arc-20160816; b=Xpu0rYbP/TnxAtLe9ztbfen9a4xdx+uKsuGQ945nVDu/4Y5oXmJfUjw9v7fritKmMc a//94q5C5QEB5Lrgbha3iSNXcEmJuDiwSPLXn6Cuo4yrh03LZL0y2filfe5VG9mDGxbT b19KXtFwlOUdHULRzI17sqeg9nQ9RkppqkcZ5pGWi9SfMDj31g9XmowVXjDyFjohDokW w5l7YjIdBITQTiyMqH6eXmOaUlPU2HC7Dt5rFTI8NwYzeRsRrs8d5nkehzr68cwSnccO yPQU7X8ckBYuGt6Y60ykGdKVDzUcCGXDqsb3p/AuFf/P7ueEZqf3UQ3LqulaHClIvS81 e6+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:cc; bh=cDrU9s2mYvjRDKk8wHx3cKSKS4obL+Pn8uXyzwxdiUs=; b=ZImqlBEKku1TSmPdRlPylZdapBpDNJWgZDgWmUhf7pB2a/Sl5VkjD38HdvxtqXzJnh znK+X+4M9nRRSEG8erRNl2AmUX81fKTnjEEyNDTe0MbiO5ERbpEJC62xW5Elfov70h5S LZ4H8BDvcV3wZ4b6ualbi4/k/fa9xT9AjLrfALzLRQT6JnkKqtdS1ijZ8UJ4BTWyb32m BdaAbGUIpBDXVUKP/udThkRuMCqdRUnF+n3OHnVxiAiBHtCN6zEptls3Mu4YGIE3zZSN lAQS5cV0c+9/Tkunr/komKvIdg0g3ctvfru1zB6XOnxgbagSAjMxOkjJ80aF9mwp02kw VLkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si642743pgs.579.2019.03.14.19.26.55; Thu, 14 Mar 2019 19:27:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728250AbfCOCYd (ORCPT + 99 others); Thu, 14 Mar 2019 22:24:33 -0400 Received: from mga03.intel.com ([134.134.136.65]:59580 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728230AbfCOCYc (ORCPT ); Thu, 14 Mar 2019 22:24:32 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Mar 2019 19:24:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,480,1544515200"; d="scan'208";a="127108468" Received: from allen-box.sh.intel.com (HELO [10.239.159.136]) ([10.239.159.136]) by orsmga006.jf.intel.com with ESMTP; 14 Mar 2019 19:24:30 -0700 Cc: baolu.lu@linux.intel.com, Tom Murphy , Dmitry Safonov , Jacob Pan , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/7] iommu/vt-d: Expose ISA direct mapping region via iommu_get_resv_regions To: James Sewart , iommu@lists.linux-foundation.org References: <0F0C82BE-86E5-4BAC-938C-6F7629E18D27@arista.com> <83B82113-8AE5-4B0C-A079-F389520525BD@arista.com> From: Lu Baolu Message-ID: Date: Fri, 15 Mar 2019 10:19:05 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi James, On 3/14/19 7:58 PM, James Sewart wrote: > To support mapping ISA region via iommu_group_create_direct_mappings, > make sure its exposed by iommu_get_resv_regions. This allows > deduplication of reserved region mappings > > Signed-off-by: James Sewart > --- > drivers/iommu/intel-iommu.c | 42 +++++++++++++++++++++++++++++-------- > 1 file changed, 33 insertions(+), 9 deletions(-) > > diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c > index 8e0a4e2ff77f..2e00e8708f06 100644 > --- a/drivers/iommu/intel-iommu.c > +++ b/drivers/iommu/intel-iommu.c > @@ -337,6 +337,8 @@ static LIST_HEAD(dmar_rmrr_units); > #define for_each_rmrr_units(rmrr) \ > list_for_each_entry(rmrr, &dmar_rmrr_units, list) > > +static struct iommu_resv_region *isa_resv_region; > + > /* bitmap for indexing intel_iommus */ > static int g_num_of_iommus; > > @@ -2780,26 +2782,34 @@ static inline int iommu_prepare_rmrr_dev(struct dmar_rmrr_unit *rmrr, > rmrr->end_address); > } > > +static inline struct iommu_resv_region *iommu_get_isa_resv_region(void) > +{ > + if (!isa_resv_region) > + isa_resv_region = iommu_alloc_resv_region(0, > + 16*1024*1024, > + 0, IOMMU_RESV_DIRECT); > + > + return isa_resv_region; > +} > + > #ifdef CONFIG_INTEL_IOMMU_FLOPPY_WA > -static inline void iommu_prepare_isa(void) > +static inline void iommu_prepare_isa(struct pci_dev *pdev) > { > - struct pci_dev *pdev; > int ret; > + struct iommu_resv_region *reg = iommu_get_isa_resv_region(); > > - pdev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); > - if (!pdev) > + if (!reg) > return; > > pr_info("Prepare 0-16MiB unity mapping for LPC\n"); > - ret = iommu_prepare_identity_map(&pdev->dev, 0, 16*1024*1024 - 1); > + ret = iommu_prepare_identity_map(&pdev->dev, reg->start, > + reg->start + reg->length - 1); > > if (ret) > pr_err("Failed to create 0-16MiB identity map - floppy might not work\n"); > - > - pci_dev_put(pdev); > } > #else > -static inline void iommu_prepare_isa(void) > +static inline void iommu_prepare_isa(struct pci_dev *pdev) > { > return; > } > @@ -3289,6 +3299,7 @@ static int __init init_dmars(void) > struct dmar_rmrr_unit *rmrr; > bool copied_tables = false; > struct device *dev; > + struct pci_dev *pdev; > struct intel_iommu *iommu; > int i, ret; > > @@ -3469,7 +3480,11 @@ static int __init init_dmars(void) > } > } > > - iommu_prepare_isa(); > + pdev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); > + if (pdev) { > + iommu_prepare_isa(pdev); > + pci_dev_put(pdev); > + } > > domains_done: > > @@ -5266,6 +5281,7 @@ static void intel_iommu_get_resv_regions(struct device *device, > struct iommu_resv_region *reg; > struct dmar_rmrr_unit *rmrr; > struct device *i_dev; > + struct pci_dev *pdev; > int i; > > rcu_read_lock(); > @@ -5280,6 +5296,14 @@ static void intel_iommu_get_resv_regions(struct device *device, > } > rcu_read_unlock(); > > + if (dev_is_pci(device)) { > + pdev = to_pci_dev(device); > + if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) { > + reg = iommu_get_isa_resv_region(); > + list_add_tail(®->list, head); > + } > + } > + Just wondering why not just +#ifdef CONFIG_INTEL_IOMMU_FLOPPY_WA + if (dev_is_pci(device)) { + pdev = to_pci_dev(device); + if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_ISA) { + reg = iommu_alloc_resv_region(0, + 16*1024*1024, + 0, IOMMU_RESV_DIRECT); + if (reg) + list_add_tail(®->list, head); + } + } +#endif and, remove all other related code? Best regards, Lu Baolu