From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41PT4F3vWYzDrHZ for ; Tue, 10 Jul 2018 00:58:53 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w69Ermj5064307 for ; Mon, 9 Jul 2018 10:58:50 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k48jg5nvy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 09 Jul 2018 10:58:50 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Jul 2018 08:58:49 -0600 From: Michael Bringmann Subject: [PATCH v06 4/9] mobility/numa: Ensure numa update does not overlap Cc: Michael Bringmann , Nathan Fontenot , John Allen , Tyrel Datwyler , Thomas Falcon To: linuxppc-dev@lists.ozlabs.org In-Reply-To: <4e6b3582-0033-b232-3769-226ba6f68eac@linux.vnet.ibm.com> Date: Mon, 9 Jul 2018 09:58:43 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Message-Id: List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , mobility/numa: Ensure that numa_update_cpu_topology() can not be entered multiple times concurrently. It may be accessed through many different paths / concurrent work functions, and the lock ordering may be difficult to ensure otherwise. Signed-off-by: Michael Bringmann --- arch/powerpc/mm/numa.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index a789d57..b22e27a 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -1079,6 +1079,7 @@ struct topology_update_data { static int topology_timer_secs = 1; static int topology_inited; static int topology_update_needed; +static struct mutex topology_update_lock; /* * Change polling interval for associativity changes. @@ -1320,6 +1321,11 @@ int numa_update_cpu_topology(bool cpus_locked) if (!updates) return 0; + if (!mutex_trylock(&topology_update_lock)) { + kfree(updates); + return 0; + } + cpumask_clear(&updated_cpus); for_each_cpu(cpu, &cpu_associativity_changes_mask) { @@ -1424,6 +1430,7 @@ int numa_update_cpu_topology(bool cpus_locked) out: kfree(updates); topology_update_needed = 0; + mutex_unlock(&topology_update_lock); return changed; } @@ -1598,6 +1605,8 @@ static ssize_t topology_write(struct file *file, const char __user *buf, static int topology_update_init(void) { + mutex_init(&topology_update_lock); + /* Do not poll for changes if disabled at boot */ if (topology_updates_enabled) start_topology_update();