Received: by 10.213.65.68 with SMTP id h4csp2147807imn; Sun, 8 Apr 2018 20:57:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx48dNZfUMCuWLNQV3/u6AHldbh37BcNfsLZ7yHEQlgHTKT+/AnvRp9KEpmVZEgnB1EVePg+/ X-Received: by 10.99.115.69 with SMTP id d5mr24004324pgn.289.1523246260398; Sun, 08 Apr 2018 20:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523246260; cv=none; d=google.com; s=arc-20160816; b=ln/mG3cWPjU5OMPKuatHxC0UywFxxQ4h4iOiUzLvdtb8R3Xlf5mKfVoVKY58cinXpb ufim70eDymUdCsUWZ0c0Y7IOkHgChxe21I8jeXXz4YDOogV8WdP7rf8Y575/vDOztgn2 1KkyrmzqQ5J/qdYz3vn2ztffwopFDkPvVrjPQfGjBghDuHir23YgoK3mcBR2VfGQyebM OWgsd5QlnlNipW9RnLSkoxNRO2KnwOWyC5kmBODOhE5z+TbbleaolmabPiHsEAZuuM79 Vx7sHwD30IgnZ3V/Fboz+jk84/9vl6tmclsWjBMdHQoTlOhtCK+nc7r1fuyl5/y9CzYM nkJg== 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=zoepvrFHhgxw0Fk0J2qGjhoGFrgotut+gGP7vt2SGmM=; b=VKVToN27SbGlb1Rfg1AjYNr6eTgRgUzqWdSw1I34K3gAfP6QTe7nMaDdbyZd6OsFeC Nk9SzWZN8a2jWzqYCh75xTtDq9//Jz6YnXoUQY+liuZ4pJoIhJSgfMOs6FeTHYGUtl9r A96qQl/aVzKd5UeOVNDAEyD9q0V2TT29B0xmFJt0uOqCColsPr5PqapkZ9vpQBNnLAEL PQwhsGLARgONm/RjLpqyxQpLAsWgF3dgwe3mSr3BCMoMqrbw1pANLlRuM+Wh+D2gVdmb n9MB8d6H4WYaQo5jLtdKwARXmLhBD9j44k6xmdBYl8ig5R+gHSgZHuKUCu7s4YgVMNRa zs3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=GPiNV0rS; 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 14-v6si15122595ple.450.2018.04.08.20.57.03; Sun, 08 Apr 2018 20:57:40 -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=GPiNV0rS; 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 S1754217AbeDIDvn (ORCPT + 99 others); Sun, 8 Apr 2018 23:51:43 -0400 Received: from mail-bn3nam01on0100.outbound.protection.outlook.com ([104.47.33.100]:20288 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754000AbeDIAT0 (ORCPT ); Sun, 8 Apr 2018 20:19:26 -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=zoepvrFHhgxw0Fk0J2qGjhoGFrgotut+gGP7vt2SGmM=; b=GPiNV0rSQFCNvgUHRQH7JisWnncAmqUTyfRWRqn7ttE3yybQKkIefZpAD0UHzDnDyQgaXQmWKAZxMPRXrU9yJi0mXQM4mN06kCXz5xuXRaZ81R6cE9l1XKbjlWrG5RC295KpFJFdyFCsVuD/xd7TozQDC/v9y+zmTsCTd6wHrb4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1063.namprd21.prod.outlook.com (52.132.128.39) 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:19:21 +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:19:21 +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.15 102/189] powerpc/numa: Ensure nodes initialized for hotplug Thread-Topic: [PATCH AUTOSEL for 4.15 102/189] powerpc/numa: Ensure nodes initialized for hotplug Thread-Index: AQHTz5g7hRlY1zUVaE+vKgyFoDNa5w== Date: Mon, 9 Apr 2018 00:18:06 +0000 Message-ID: <20180409001637.162453-102-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB1063;7:Fgo4Qxz5IQJypqsuosmAXdnrm9lG+V925ezBQcs0AdI1Pj68jA+Ki9Q0IoZzNCsnTtESyzRl0a+w5T+HkwUTVDbVwK7fnUxzdaYwX795JES8Xw7GQg+i+1WQMLAmXQyYDQINY9R2GgKYLz9i4j6sYzvB9vSZOLzW/CY8P68oJ0WJEeL1yscqt8KKQacMVUi2WkPTvpDiLVgxcxYBR+yMOSVF/XGggxz+YU5l8iWbRN1Res9Qhvnht9aOdU6s14XR;20:fMX/ZMa6o4OT8rtdRF4tQvy/ODhrmf6Nu0B3T0hqSozM7VfebDv5+6Cj10QmDYCw8sgtUOBklFmqajzJAx4FuDOFwOBPjMvbFhRvAJfnEWAc25De36cxPiJ404YJC9hM8Pb9Qh4ITWWZOyDMWdSVdRt06l8v1cML+edMUnUa3hs= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 17858cde-7a1f-4490-7a3f-08d59daf8a7d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1063; x-ms-traffictypediagnostic: DM5PR2101MB1063: 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)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1063;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1063; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(39860400002)(376002)(396003)(366004)(189003)(199004)(2900100001)(6436002)(7736002)(10090500001)(102836004)(3660700001)(6506007)(76176011)(305945005)(4326008)(5250100002)(97736004)(26005)(25786009)(6512007)(2906002)(81166006)(106356001)(107886003)(68736007)(14454004)(86612001)(66066001)(10290500003)(59450400001)(6666003)(5660300001)(81156014)(478600001)(476003)(486006)(6486002)(72206003)(3280700002)(99286004)(105586002)(36756003)(1076002)(2616005)(11346002)(53936002)(446003)(8676002)(186003)(3846002)(54906003)(6116002)(2501003)(8936002)(316002)(110136005)(86362001)(22452003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1063;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: ka3l7OYoCH3OxVvkmf7EJJbbyRu9bq8pBmwn4Mb6f+AbyV2If3hnQGcpsCx3TbpWRGTz89FPk+pwTBJnvSIUeGChivq2Sml3elqfwDlVio6uGS2L2y6rKqQqAl7n9EYWx1Xs024z60h5m79A7pLIzDlcvoqI9sOcrkMYlxBqo81FboBhZM2DOXSklnLSs6gGUhnmNLc4i8BEgQD39aHiLdzJnKFybi13ARneiO+yu5cDzwhvxsBa7Gtw5zBPTscmLJ6K1WxPEuKjAu5AitJ1NdGSXJpUolNUD4ptRF+nMMc6fR0bfpSHg+EUr7/KreHj+mlzHTKjrKNWkkjFteUUGpaXPznIBXlJ1yMQRVTHZrhE6fkN27w8pVEUShkcQ9I5n/eFWYbc3idTyjnh538NQHuaGqkItKECHlp6Nl7mtdQ= 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: 17858cde-7a1f-4490-7a3f-08d59daf8a7d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:06.6939 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1063 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 87323354b247..c6ec7ea312e8 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: @@ -1304,6 +1302,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 @@ -1371,7 +1403,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; @@ -1409,11 +1440,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