Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2269154yba; Mon, 15 Apr 2019 08:17:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqymX49ZgXJRb6DV0jkyDkPWIqxpnmiTnR41mGA/2DKJJj+W2WSJu9tL5Myl8Ugws6If3gpu X-Received: by 2002:a63:8142:: with SMTP id t63mr67167821pgd.63.1555341430948; Mon, 15 Apr 2019 08:17:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555341430; cv=none; d=google.com; s=arc-20160816; b=hDShHyyOTug64OOSU4fmIOuPsJ5eeTMuXEsRf8Wl1F/eLYXjKBVcwpsJKx1bxfz2y8 8w+tmAzf5YEpThTsV+sydWmAHiJYkzFZKXJwYB6LaEn11CT235jcwm74BbXFStHdBzgi X+P8PaB6rir3MpD5kpU25Wu8rRnduuJrUa11MqHj8Giy7PhtBOWpKFCQYE0SGoVZLmj1 MR2qSx6saynxh/NcFSBTXWZtwdCk5ZjNS3vGB1joQTrxAg4kpSpP+zNKkclACRBz4KvP PmVOffnCMLx1vq1prnzPUbBwVk90cPWVlJUmHoGVY7DKRRrec6SEOawIPL5uq4AG6GxO VN8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ur6Byu3Rimd0aZkjVP49efczYHdI5+wCW7mi8aUocG0=; b=SLhz2hYtvjx4t69SieaSnrt7NLILvFYmlXGsuIigP0k0/XKoqRwZaYO8IUODpbqzsi 6nQzY/A/sWnpcgvVJOVJeLwbgw2zL2HLEl2wfn6TFp0akYWNBMBptQc3mA5pw7PDWt+O gacEVGZoydl3FO08qFjoiqk8GqKFgDiF9HLXDkR6zYZZXpaL/Uak/09osAJsdnjCVFQX Ux3AT6W1/7MbhblbQ9/2Q2eClJJrS8YKiMHRAfqqBZhQbFTYEBM7C3OSyjJ66Yc3wrL7 YFkpFlA6mDE/SKW/lbP2eY8G29yKgIu6UCDkRAXAooKHJkS2CzoFfveb8Ller+T0ipub qXPw== 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 l184si28999192pge.425.2019.04.15.08.16.51; Mon, 15 Apr 2019 08:17: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 S1727681AbfDOPPl (ORCPT + 99 others); Mon, 15 Apr 2019 11:15:41 -0400 Received: from mga04.intel.com ([192.55.52.120]:23729 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbfDOPPa (ORCPT ); Mon, 15 Apr 2019 11:15:30 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Apr 2019 08:15:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,354,1549958400"; d="scan'208";a="149585862" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by FMSMGA003.fm.intel.com with ESMTP; 15 Apr 2019 08:15:29 -0700 From: Keith Busch To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: Rafael Wysocki , Dave Hansen , Dan Williams , Brice Goglin , Keith Busch Subject: [PATCHv2 2/2] hmat: Register attributes for memory hot add Date: Mon, 15 Apr 2019 09:16:54 -0600 Message-Id: <20190415151654.15913-3-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190415151654.15913-1-keith.busch@intel.com> References: <20190415151654.15913-1-keith.busch@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some memory nodes described in HMAT may not be online at the time the we parse the subtables. Should the node be set to online later, as can happen when using PMEM as RAM after boot, the nodes will be missing their initiator links and performance attributes. Register a memory notifier callback and register the memory attributes the first time its node is brought online if it wasn't registered, ensuring a node's attributes may be registered only once. Reported-by: Brice Goglin Signed-off-by: Keith Busch --- drivers/acpi/hmat/hmat.c | 72 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/drivers/acpi/hmat/hmat.c b/drivers/acpi/hmat/hmat.c index bdb167c026ff..4fcfad6c2181 100644 --- a/drivers/acpi/hmat/hmat.c +++ b/drivers/acpi/hmat/hmat.c @@ -14,14 +14,18 @@ #include #include #include +#include +#include #include #include -static __initdata u8 hmat_revision; +static u8 hmat_revision; -static __initdata LIST_HEAD(targets); -static __initdata LIST_HEAD(initiators); -static __initdata LIST_HEAD(localities); +static LIST_HEAD(targets); +static LIST_HEAD(initiators); +static LIST_HEAD(localities); + +static DEFINE_MUTEX(target_lock); /* * The defined enum order is used to prioritize attributes to break ties when @@ -42,6 +46,7 @@ struct memory_target { unsigned int processor_pxm; struct node_hmem_attrs hmem_attrs; struct node_cache_attrs cache_attrs; + bool registered; }; struct memory_initiator { @@ -54,7 +59,7 @@ struct memory_locality { struct acpi_hmat_locality *hmat_loc; }; -static __init struct memory_initiator *find_mem_initiator(unsigned int cpu_pxm) +static struct memory_initiator *find_mem_initiator(unsigned int cpu_pxm) { struct memory_initiator *initiator; @@ -64,7 +69,7 @@ static __init struct memory_initiator *find_mem_initiator(unsigned int cpu_pxm) return NULL; } -static __init struct memory_target *find_mem_target(unsigned int mem_pxm) +static struct memory_target *find_mem_target(unsigned int mem_pxm) { struct memory_target *target; @@ -149,7 +154,7 @@ static __init const char *hmat_data_type_suffix(u8 type) } } -static __init u32 hmat_normalize(u16 entry, u64 base, u8 type) +static u32 hmat_normalize(u16 entry, u64 base, u8 type) { u32 value; @@ -184,7 +189,7 @@ static __init u32 hmat_normalize(u16 entry, u64 base, u8 type) return value; } -static __init void hmat_update_target_access(struct memory_target *target, +static void hmat_update_target_access(struct memory_target *target, u8 type, u32 value) { switch (type) { @@ -439,7 +444,7 @@ static __init int srat_parse_mem_affinity(union acpi_subtable_headers *header, return 0; } -static __init u32 hmat_initiator_perf(struct memory_target *target, +static u32 hmat_initiator_perf(struct memory_target *target, struct memory_initiator *initiator, struct acpi_hmat_locality *hmat_loc) { @@ -477,7 +482,7 @@ static __init u32 hmat_initiator_perf(struct memory_target *target, hmat_loc->data_type); } -static __init bool hmat_update_best(u8 type, u32 value, u32 *best) +static bool hmat_update_best(u8 type, u32 value, u32 *best) { bool updated = false; @@ -521,7 +526,7 @@ static int initiator_cmp(void *priv, struct list_head *a, struct list_head *b) return ia->processor_pxm - ib->processor_pxm; } -static __init void hmat_register_target_initiators(struct memory_target *target) +static void hmat_register_target_initiators(struct memory_target *target) { static DECLARE_BITMAP(p_nodes, MAX_NUMNODES); struct memory_initiator *initiator; @@ -581,13 +586,13 @@ static __init void hmat_register_target_initiators(struct memory_target *target) } } -static __init void hmat_register_target_cache(struct memory_target *target) +static void hmat_register_target_cache(struct memory_target *target) { unsigned mem_nid = pxm_to_node(target->memory_pxm); node_add_cache(mem_nid, &target->cache_attrs); } -static __init void hmat_register_target_perf(struct memory_target *target) +static void hmat_register_target_perf(struct memory_target *target) { unsigned mem_nid = pxm_to_node(target->memory_pxm); node_set_perf_attrs(mem_nid, &target->hmem_attrs, 0); @@ -598,12 +603,17 @@ static __init void hmat_register_target(struct memory_target *target) if (!node_online(pxm_to_node(target->memory_pxm))) return; - hmat_register_target_initiators(target); - hmat_register_target_cache(target); - hmat_register_target_perf(target); + mutex_lock(&target_lock); + if (!target->registered) { + hmat_register_target_initiators(target); + hmat_register_target_cache(target); + hmat_register_target_perf(target); + target->registered = true; + } + mutex_unlock(&target_lock); } -static __init void hmat_register_targets(void) +static void hmat_register_targets(void) { struct memory_target *target; @@ -611,6 +621,30 @@ static __init void hmat_register_targets(void) hmat_register_target(target); } +static int hmat_callback(struct notifier_block *self, + unsigned long action, void *arg) +{ + struct memory_target *target; + struct memory_notify *mnb = arg; + int pxm, nid = mnb->status_change_nid; + + if (nid == NUMA_NO_NODE || action != MEM_ONLINE) + return NOTIFY_OK; + + pxm = node_to_pxm(nid); + target = find_mem_target(pxm); + if (!target) + return NOTIFY_OK; + + hmat_register_target(target); + return NOTIFY_OK; +} + +static struct notifier_block hmat_callback_nb = { + .notifier_call = hmat_callback, + .priority = 2, +}; + static __init void hmat_free_structures(void) { struct memory_target *target, *tnext; @@ -676,6 +710,10 @@ static __init int hmat_init(void) } } hmat_register_targets(); + + /* Keep the table and structures if the notifier may use them */ + if (!register_hotmemory_notifier(&hmat_callback_nb)) + return 0; out_put: hmat_free_structures(); acpi_put_table(tbl); -- 2.14.4