From patchwork Tue Apr 22 07:07:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 4029111 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 5C8D19F387 for ; Tue, 22 Apr 2014 07:09:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F30E2020E for ; Tue, 22 Apr 2014 07:09:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D61920211 for ; Tue, 22 Apr 2014 07:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754143AbaDVHHZ (ORCPT ); Tue, 22 Apr 2014 03:07:25 -0400 Received: from mga09.intel.com ([134.134.136.24]:2506 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752125AbaDVHHT (ORCPT ); Tue, 22 Apr 2014 03:07:19 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 22 Apr 2014 00:01:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,902,1389772800"; d="scan'208";a="517082112" Received: from gerry-dev.bj.intel.com ([10.238.158.74]) by fmsmga001.fm.intel.com with ESMTP; 22 Apr 2014 00:06:46 -0700 From: Jiang Liu To: Joerg Roedel , David Woodhouse , Yinghai Lu , Bjorn Helgaas , Dan Williams , Vinod Koul , "Rafael J . Wysocki" Cc: Jiang Liu , Ashok Raj , Yijing Wang , Tony Luck , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org Subject: [Patch Part3 V1 18/22] iommu/vt-d: update proximity information when a new node with memory available Date: Tue, 22 Apr 2014 15:07:29 +0800 Message-Id: <1398150453-28141-19-git-send-email-jiang.liu@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398150453-28141-1-git-send-email-jiang.liu@linux.intel.com> References: <1398150453-28141-1-git-send-email-jiang.liu@linux.intel.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=-7.5 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 If node associated with a DMAR unit has no memory available, it uses -1 as default NUMA node id. So when memory hot-addition adds new memory to an empty NUMA node, we should update the NUMA node id associated with the DMAR unit. This will help to optomize memory allocation. Signed-off-by: Jiang Liu --- drivers/iommu/dmar.c | 50 ++++++++++++++++++++++++++++++++++++++++--- include/linux/intel-iommu.h | 1 + 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index 7a7383858c34..d607691a6a80 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -444,6 +445,7 @@ static int dmar_parse_one_rhsa(struct acpi_dmar_header *header, void *arg) if (!node_online(node)) node = -1; drhd->iommu->node = node; + drhd->iommu->proximity_domain = rhsa->proximity_domain; return 0; } } @@ -458,8 +460,48 @@ static int dmar_parse_one_rhsa(struct acpi_dmar_header *header, void *arg) return 0; } + +static int dmar_memory_notifier(struct notifier_block *nb, + unsigned long val, void *v) +{ + struct memory_notify *mhp = v; + struct dmar_drhd_unit *drhd; + struct intel_iommu *iommu; + int nid; + + if (val != MEM_ONLINE) + return NOTIFY_OK; + + if (mhp->status_change_nid < 0) + return NOTIFY_OK; + + down_read(&dmar_global_lock); + for_each_iommu(iommu, drhd) { + if (iommu->node != -1) + continue; + nid = acpi_map_pxm_to_node(iommu->proximity_domain); + if (nid == mhp->status_change_nid) + iommu->node = nid; + } + up_read(&dmar_global_lock); + + return NOTIFY_OK; +} + +static struct notifier_block dmar_memory_nb = { + .notifier_call = dmar_memory_notifier, +}; + +static void dmar_register_memory_notifier(void) +{ + register_memory_notifier(&dmar_memory_nb); +} #else #define dmar_parse_one_rhsa dmar_res_noop + +static void dmar_register_memory_notifier(void) +{ +} #endif static void __init @@ -1715,12 +1757,14 @@ static inline bool dmar_in_use(void) return irq_remapping_enabled || intel_iommu_enabled; } -static int __init dmar_free_unused_resources(void) +static int __init dmar_late_init(void) { struct dmar_drhd_unit *dmaru, *dmaru_n; - if (dmar_in_use()) + if (dmar_in_use()) { + dmar_register_memory_notifier(); return 0; + } if (dmar_dev_scope_status != 1 && !list_empty(&dmar_drhd_units)) bus_unregister_notifier(&pci_bus_type, &dmar_pci_bus_nb); @@ -1735,7 +1779,7 @@ static int __init dmar_free_unused_resources(void) return 0; } -late_initcall(dmar_free_unused_resources); +late_initcall(dmar_late_init); IOMMU_INIT_POST(detect_intel_iommu); /* diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 0a2da5188217..eea52ccdbd8e 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -337,6 +337,7 @@ struct intel_iommu { struct ir_table *ir_table; /* Interrupt remapping info */ #endif int node; + int proximity_domain; }; static inline void __iommu_flush_cache(