From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756897AbcHXX04 (ORCPT ); Wed, 24 Aug 2016 19:26:56 -0400 Received: from mga07.intel.com ([134.134.136.100]:63706 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754176AbcHXX0z (ORCPT ); Wed, 24 Aug 2016 19:26:55 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,573,1464678000"; d="scan'208";a="1046779233" Date: Wed, 24 Aug 2016 16:26:49 -0700 From: Tim Chen To: Andrew Morton , Ingo Molnar , "H. Peter Anvin" , Peter Zijlstra Cc: Tim Chen , "Huang, Ying" , Andi Kleen , Dave Hansen , Dan Williams , linux-kernel@vger.kernel.org Subject: [PATCH] x86, cpu: Fix node state for whether it contains CPU Message-ID: <20160824232647.GA21759@linux.intel.com> Reply-To: tim.c.chen@linux.intel.com MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.6.2 (2016-07-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In current kernel code, we only call node_set_state(cpu_to_node(cpu), N_CPU) when a cpu is hot plugged. But we do not set the node state for N_CPU when the cpus are brought online during boot. So this could lead to failure when we check to see if a node contains cpu with node_state(node_id, N_CPU). One use case is in the node_reclaime function: /* * Only run node reclaim on the local node or on nodes that do * not * have associated processors. This will favor the local * processor * over remote processors and spread off node memory allocations * as wide as possible. */ if (node_state(pgdat->node_id, N_CPU) && pgdat->node_id != numa_node_id()) return NODE_RECLAIM_NOSCAN; I instrumented the kernel to call this function after boot and it always returns 0 on a x86 desktop machine until I apply the attached patch. static int num_cpu_node(void) { int i, nr_cpu_nodes = 0; for_each_node(i) { if (node_state(i, N_CPU)) ++ nr_cpu_nodes; } return nr_cpu_nodes; } I have not tested other architectues but they are likely to have similar issue. Signed-off-by: Tim Chen --- arch/x86/kernel/smpboot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index d8f7d01..04c0574 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -259,6 +259,7 @@ static void notrace start_secondary(void *unused) lock_vector_lock(); setup_vector_irq(smp_processor_id()); set_cpu_online(smp_processor_id(), true); + node_set_state(cpu_to_node(smp_processor_id()), N_CPU); unlock_vector_lock(); cpu_set_state_online(smp_processor_id()); x86_platform.nmi_init(); -- 2.5.5