Received: by 10.213.65.68 with SMTP id h4csp2203729imn; Sun, 8 Apr 2018 22:25:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/+mu905kiG1AXP5o2yqQ7nmTKnc2yGT/bly5cpl58M7CbADUgs7veiSmqpPOK4P2ZWFxni X-Received: by 10.167.128.194 with SMTP id a2mr9953569pfn.130.1523251557265; Sun, 08 Apr 2018 22:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523251557; cv=none; d=google.com; s=arc-20160816; b=mWlw0NkgIEvAE9mZ8TEcFqTBYTWvogXVLPt5J0iSX7wFWflDUQ+UPtDALtEfM1q+OJ fu62mD550vgB5WQsp7KD2C6kvH7wPnW5yaVyBy+FnyvNSzbeor+wIYjY2TXkjuC7hUvw 5qPEf4kzw366MXwAe9wogSS5XW2WQ6b5tyGwJ7tYRGwmB3OaRqK/xlsAqgMyYkKA8OrR n+mL0x5Erxvd5gd20y8YxYsv+bzzJFC5z/qq7ymE8Nmne1uuq1HvO9K88jgOoLBFUNDf oaAdiVVJA9XNdLZ3ELZ+EK8AO5oali/dh+Ir67iHV6k835XutFWZEw1nJel2HUIB2gwn Qc2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=1DMHLlTLGSLhf4D4THjJeBHOd8yLAmNtT7WL8qlNw4E=; b=ze+s8KlvKgt/LLJ+T9JjDMz9K7ExVKjv6wL+CiGGwrknhl1zx3DifXYz/Rlp/OlblL u2VZbuAJDNPoQKxRGiQmMt6BjE6TPphzZQ7Kl+bM7VZzoCZz+7IRMMBudLI+qEwCerde S1WUznBFNMVwylHDpF2LbYlRgReQe2sKCfxZkw41KpSrVzdK/2Tb3Tseg4GIC4twu2nY X/odgedHlruSVv03dYT4t+GQmh5AZ3UR91e+zYQep8Y43sNiN5JqFrwnrb0VqUoFNHhu 7UnSLL8waa/4/IXSQfXdjWBsyBMhxLnYW6e+vTnSVylEAedFFM2012X+gEfjejd9w8to 0Ozg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=BBVnRcg2; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1-v6si13472448pld.529.2018.04.08.22.25.20; Sun, 08 Apr 2018 22:25:57 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=BBVnRcg2; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932080AbeDIAYg (ORCPT + 99 others); Sun, 8 Apr 2018 20:24:36 -0400 Received: from mail-by2nam03on0117.outbound.protection.outlook.com ([104.47.42.117]:63840 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754108AbeDIAYc (ORCPT ); Sun, 8 Apr 2018 20:24:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=1DMHLlTLGSLhf4D4THjJeBHOd8yLAmNtT7WL8qlNw4E=; b=BBVnRcg2wIppge8TbtcWraD5n4w/qLiEeuGONmgY2AmvgGa4a1yxkn63tLDKOPQUKvrUq2JsH35bfo/AGrmhr8AyuMVbA6+cnotgKIZJFSko7Z8FfppwieahEXDg3xYOJrJSbBvCZS2mYo3BRm5NYxkugErWxpZDyMFTHPmwptY= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0984.namprd21.prod.outlook.com (52.132.133.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:24:28 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:24:28 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Michael Bringmann , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 086/161] powerpc/numa: Ensure nodes initialized for hotplug Thread-Topic: [PATCH AUTOSEL for 4.14 086/161] powerpc/numa: Ensure nodes initialized for hotplug Thread-Index: AQHTz5igTDhf8gU1S0mWOxagIKe6kw== Date: Mon, 9 Apr 2018 00:20:56 +0000 Message-ID: <20180409001936.162706-86-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0984;7:zEYJyhH9FU/3AXdf/rQw6Dqxg0+TpCw4uUKuIyVpQquCBKAVz1uX9yuxrKQ2Jzd36ETAt7aSIJoONsnuI7tBbMJAtJtiKbXHM4RxeNPMo+BzcjaC0Cp1qFcEaYRl7sorX/OixOXHbgsb/psEUQgxnUugxmLzhRbYTqZY0eWR9npVfjhhaGntjwxiibRbv7WoUpgEQ4FchK7plQJvV0bBn6uJ7b5BwsSbXpzkTMOYeU7LkZZdv7mScmfh26qG2UxX;20:vg605lN7Gi7ycK6qZ6yVcIr4pHAp0Qqy1Y57ZhtXCB7e/HRurY/3ONjwRaQNSapggNKo3FxxqcjAOJhHLgUJFfN/nucimStViVzpbyc78QGfv/B99fLWEMiHksAIKHGb0Hyf3zddqyXi1qKgm5+x81ZeLD6OhVmoLlgMY3klQcU= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 176f872d-678b-417c-b80e-08d59db041e0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0984; x-ms-traffictypediagnostic: DM5PR2101MB0984: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(209352067349851)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0984;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0984; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(376002)(366004)(39860400002)(396003)(189003)(199004)(5250100002)(2501003)(110136005)(54906003)(6116002)(6436002)(11346002)(1076002)(486006)(25786009)(105586002)(2900100001)(102836004)(86612001)(3846002)(68736007)(107886003)(316002)(10290500003)(5660300001)(86362001)(2616005)(305945005)(4326008)(446003)(6486002)(22452003)(7736002)(476003)(8676002)(81156014)(81166006)(8936002)(6512007)(10090500001)(186003)(3280700002)(106356001)(76176011)(2906002)(99286004)(26005)(97736004)(59450400001)(14454004)(6666003)(478600001)(53936002)(6506007)(36756003)(72206003)(66066001)(3660700001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0984;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: jGa8XMPCYuTTvPSzz6LZkD6QrlN9ErToJaeGz1v2kRrtwCUliHqrohMgYa2EhQ7K7O6mvcgf6MTm+B1KJsAk9X4kdr734yKXqriCDL2KyxqjuibIoo2x6HlS4EBQLcxEtz4FvI/sJTtfkMY7OUjdONTOxBuXd/ObHJmrpKLAJ56bL/dUPMfOV2VJ/yS44zmwe/bGfefqk+jXC8BFcw5uPUY6O1EsfxarboICjPNE90bf48uWAtLn3bDW3hd7nvRjn0OSNcQ5uhHzb6GdFeFY9McVGE1dGcJp3aGONp0s1F0lDPPAwmiiubbZv+Jsr99EK+VdbDSMw7hWFvFmYNCHFtW/IsulWZj3fxp9/iuSA3DHpbwuoVJSGUd290V5sIw7GHWUM92UQgTc97FS2e60YqkqPI9TbgzEP2ONlSpmoAc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 176f872d-678b-417c-b80e-08d59db041e0 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:20:56.5815 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0984 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Bringmann [ Upstream commit ea05ba7c559c8e5a5946c3a94a2a266e9a6680a6 ] This patch fixes some problems encountered at runtime with configurations that support memory-less nodes, or that hot-add CPUs into nodes that are memoryless during system execution after boot. The problems of interest include: * Nodes known to powerpc to be memoryless at boot, but to have CPUs in them are allowed to be 'possible' and 'online'. Memory allocations for those nodes are taken from another node that does have memory until and if memory is hot-added to the node. * Nodes which have no resources assigned at boot, but which may still be referenced subsequently by affinity or associativity attributes, are kept in the list of 'possible' nodes for powerpc. Hot-add of memory or CPUs to the system can reference these nodes and bring them online instead of redirecting the references to one of the set of nodes known to have memory at boot. Note that this software operates under the context of CPU hotplug. We are not doing memory hotplug in this code, but rather updating the kernel's CPU topology (i.e. arch_update_cpu_topology / numa_update_cpu_topology). We are initializing a node that may be used by CPUs or memory before it can be referenced as invalid by a CPU hotplug operation. CPU hotplug operations are protected by a range of APIs including cpu_maps_update_begin/cpu_maps_update_done, cpus_read/write_lock / cpus_read/write_unlock, device locks, and more. Memory hotplug operations, including try_online_node, are protected by mem_hotplug_begin/mem_hotplug_done, device locks, and more. In the case of CPUs being hot-added to a previously memoryless node, the try_online_node operation occurs wholly within the CPU locks with no overlap. Using HMC hot-add/hot-remove operations, we have been able to add and remove CPUs to any possible node without failures. HMC operations involve a degree self-serialization, though. Signed-off-by: Michael Bringmann Reviewed-by: Nathan Fontenot Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/mm/numa.c | 47 +++++++++++++++++++++++++++++++++++++---------= - 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index 0356c6cceff7..9fead0796364 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -546,7 +546,7 @@ static int numa_setup_cpu(unsigned long lcpu) nid =3D of_node_to_nid_single(cpu); =20 out_present: - if (nid < 0 || !node_online(nid)) + if (nid < 0 || !node_possible(nid)) nid =3D first_online_node; =20 map_cpu_to_node(lcpu, nid); @@ -905,10 +905,8 @@ static void __init find_possible_nodes(void) goto out; =20 for (i =3D 0; i < numnodes; i++) { - if (!node_possible(i)) { - setup_node_data(i, 0, 0); + if (!node_possible(i)) node_set(i, node_possible_map); - } } =20 out: @@ -1277,6 +1275,40 @@ static long vphn_get_associativity(unsigned long cpu= , return rc; } =20 +static inline int find_and_online_cpu_nid(int cpu) +{ + __be32 associativity[VPHN_ASSOC_BUFSIZE] =3D {0}; + int new_nid; + + /* Use associativity from first thread for all siblings */ + vphn_get_associativity(cpu, associativity); + new_nid =3D associativity_to_nid(associativity); + if (new_nid < 0 || !node_possible(new_nid)) + new_nid =3D first_online_node; + + if (NODE_DATA(new_nid) =3D=3D NULL) { +#ifdef CONFIG_MEMORY_HOTPLUG + /* + * Need to ensure that NODE_DATA is initialized for a node from + * available memory (see memblock_alloc_try_nid). If unable to + * init the node, then default to nearest node that has memory + * installed. + */ + if (try_online_node(new_nid)) + new_nid =3D first_online_node; +#else + /* + * Default to using the nearest node that has memory installed. + * Otherwise, it would be necessary to patch the kernel MM code + * to deal with more memoryless-node error conditions. + */ + new_nid =3D first_online_node; +#endif + } + + return new_nid; +} + /* * Update the CPU maps and sysfs entries for a single CPU when its NUMA * characteristics change. This function doesn't perform any locking and i= s @@ -1344,7 +1376,6 @@ int numa_update_cpu_topology(bool cpus_locked) { unsigned int cpu, sibling, changed =3D 0; struct topology_update_data *updates, *ud; - __be32 associativity[VPHN_ASSOC_BUFSIZE] =3D {0}; cpumask_t updated_cpus; struct device *dev; int weight, new_nid, i =3D 0; @@ -1379,11 +1410,7 @@ int numa_update_cpu_topology(bool cpus_locked) continue; } =20 - /* Use associativity from first thread for all siblings */ - vphn_get_associativity(cpu, associativity); - new_nid =3D associativity_to_nid(associativity); - if (new_nid < 0 || !node_online(new_nid)) - new_nid =3D first_online_node; + new_nid =3D find_and_online_cpu_nid(cpu); =20 if (new_nid =3D=3D numa_cpu_lookup_table[cpu]) { cpumask_andnot(&cpu_associativity_changes_mask, --=20 2.15.1