From patchwork Fri Jan 12 23:36:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 13518767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97147C4707C for ; Fri, 12 Jan 2024 23:37:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 077206B008C; Fri, 12 Jan 2024 18:37:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F19816B0092; Fri, 12 Jan 2024 18:37:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D46776B0093; Fri, 12 Jan 2024 18:37:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BAD1B6B008C for ; Fri, 12 Jan 2024 18:37:15 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 93782A01B6 for ; Fri, 12 Jan 2024 23:37:15 +0000 (UTC) X-FDA: 81672272430.11.7D61D85 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) by imf25.hostedemail.com (Postfix) with ESMTP id D44E1A000B for ; Fri, 12 Jan 2024 23:37:13 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf25.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.167.170 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705102633; a=rsa-sha256; cv=none; b=nvqxkzdBPVz6PcXl4ub15LqDvaqFtPQH7cbFM+BE48O+YNLvWgmbB9MRrF2azMlcbs4pMy cNF06t0A9NSGkZuOR+SKrh2B+u+aANrSFN8quT3en5w5vaBMmAw0LLOmq089BlX2QOKDwl q8ahSwdi/ngSHYlcM+w9dERA4DBPSEc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf25.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.167.170 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705102633; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YnmSD5dxnU1WwAaH5fLVr5yJ8rSNa8AOKTOrmDoJ578=; b=vKFmDvrfiMf/p2l6R1LuM2amXY82wGaUKJk+UUbJwTsb9JYfjo4fCmFQu5sD5RgZp5ftqw qfwL9p+q1o8W6pvAWrwbKOFiJDbuIVj8HmSmZeijUBvdqzZqNKbWgFdtE/AvcxTFYczl0b ldSMr8EK95kfrKdHHl9syKCol2Xy9gE= Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3bbc7746812so6466470b6e.2 for ; Fri, 12 Jan 2024 15:37:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705102633; x=1705707433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YnmSD5dxnU1WwAaH5fLVr5yJ8rSNa8AOKTOrmDoJ578=; b=aKhBWrOmMEHklCi5zS1keo+MABQsPmopuLGL05YijZLaFGpiABuYElJaVu5jGdK/Ho NIykrFtwq7SV1oIF0Kw+qAO+K79hhgyTju9jlnVBzaDykxa0QsDLB7kXEsc+DxQ3m7H6 /WxeebPIBrkRr8G6QA78DLf5Y9SbF/5Cz0rOJV1CT6Zog6TOeAA5euZJ0naMighybTs9 GAbcrg3yqZRiFxmLDOVUIqBGaIUrOBNUy8CE0qKgZ0AfBNrG4ZRTFEJx8SItWvhpcxUY 0UeNetdQGrgE1vxAejTikvmVR91ikK4kNmN9tc5iCXc5gG52K621ejg3KEik5VLgdnC+ 4XLA== X-Gm-Message-State: AOJu0YxwQoDb5XWDrv6Q2eT+5HuyvXeR/wA8WvzBNrNU0q2v0x7FWtfD v6glxylRZm3ysaaymQnNFbQ= X-Google-Smtp-Source: AGHT+IHPXgqSez2R+qOMrb7s54Bb8t+LL2MpfluYLQirkr16IsXNbTUrTocH36DT/iGKlbKL5BO7KQ== X-Received: by 2002:a05:6808:1306:b0:3bb:cd5d:41b0 with SMTP id y6-20020a056808130600b003bbcd5d41b0mr2106600oiv.73.1705102632870; Fri, 12 Jan 2024 15:37:12 -0800 (PST) Received: from snowbird.lan ([136.25.84.107]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b006d9b4171b20sm3676811pff.112.2024.01.12.15.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 15:37:12 -0800 (PST) From: Dennis Zhou To: Tejun Heo , Christoph Lameter , Thomas Gleixner Cc: Peter Zijlstra , Valentin Schneider , Dave Chinner , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Ye Bin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 1/3] lib/percpu_counter: Fix CPU hotplug handling Date: Fri, 12 Jan 2024 15:36:46 -0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D44E1A000B X-Stat-Signature: d3443w1duoru7p9yppa175etb67tqhe6 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IDJcs/3Crbq2PXuwPKnp9rpV1mygk3YGZ226XNKuLOqBfvYb4z7z664zeFGOmenxs2Bj0kDN14PueIEPJqVYlQfMWhOsFZ8YgcDqvJtfJqD6A9zBQ63mhZpKobpVz9MVm18tc/ESUt8plYIsr00w0zXy7pmDl2zqLiMKkK1jIJpd89Lys4H+4TuIF0s4602GbWv5fudn/cqRB5g+6xrocFnlK/H438xPh6UU/gcaiuDx5qZZo4Ann2pSpDYFu3eqv1wQeKo2YWA6pIeh6TTNaC1ldU6QKs6QLyUQr6miNHdoLC8ryWX9KHdEC9lzGhSbcbxNxtAapSrYtqrXL5T7yCTScWPt2Gz737XwQUZFXRG7R2TkvhHa7ZwLYTeLSxI2+Pn7+wLeCGI6qWpjquXXoeJyzruN5u8jAGwY6lO2BoucnK9+YiT4Mv4DeMDVZKs6hNKSxKU23+d2CdIJu62pktBZDljo+XAJr7PCptykBr6StKibcDrMyKvdleWg6tT2Gkfbb51T7wTT7YzlPItuviBiF22jtvl/JlLzPqvnORmpAAQAOBPIKQSLt1saEZae9ZyndgBE/m5jXwuh//PJ3dxYqNMdR9E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Commit 8b57b11cca88 ("pcpcntrs: fix dying cpu summation race") tried to address a race condition between percpu_counter_sum() and a concurrent CPU hotplug operation. The race window is between the point where an un-plugged CPU removed itself from the online_cpu_mask and the hotplug state callback which folds the per CPU counters of the now dead CPU into the global count. percpu_counter_sum() used for_each_online_cpu() to accumulate the per CPU local counts, so during the race window it missed to account for the not yet folded back local count of the offlined CPU. The attempt to address this used the admittedly undocumented and pointlessly public cpu_dying_mask by changing the loop iterator to take both the cpu_online_mask and the cpu_dying_mask into account. That works to some extent, but it is incorrect. The cpu_dying_mask bits are sticky even after cpu_up()/cpu_down() completes. That means that all offlined CPUs are always taken into account. In the case of disabling SMT at boottime or runtime this results in evaluating _all_ offlined SMT siblings counters forever. Depending on system size, that's a massive amount of cache-lines to be touched forever. It might be argued, that the cpu_dying_mask bit could be cleared when cpu_down() completes, but that's not possible under all circumstances. Especially with partial hotplug the bit must be sticky in order to keep the initial user, i.e. the scheduler correct. Partial hotplug which allows explicit state transitions also can create a situation where the race window gets recreated: cpu_down(target = CPUHP_PERCPU_CNT_DEAD + 1) brings a CPU down to one state before the per CPU counter folding callback. As this did not reach CPUHP_OFFLINE state the bit would stay set. Now the next partial operation: cpu_up(target = CPUHP_PERCPU_CNT_DEAD + 2) has to clear the bit and the race window is open again. There are two ways to solve this: 1) Maintain a local CPU mask in the per CPU counter code which gets the bit set when a CPU comes online and removed in the the CPUHP_PERCPU_CNT_DEAD state after folding. This adds more code and complexity. 2) Move the folding hotplug state into the DYING callback section, which runs on the outgoing CPU immediatedly after it cleared its online bit. There is no concurrency vs. percpu_counter_sum() on another CPU because all still online CPUs are waiting in stop_machine() for the outgoing CPU to complete its shutdown. The raw spinlock held around the CPU mask iteration prevents that an online CPU reaches the stop machine thread while iterating, which implicitely prevents the outgoing CPU from clearing its online bit. This is way simpler than #1 and makes the hotplug calls symmetric for the price of a slightly longer wait time in stop_machine(), which is not the end of the world as CPU un-plug is already slow. The overall time for a cpu_down() operation stays exactly the same. Implement #2 and plug the race completely. percpu_counter_sum() is still inherently racy against a concurrent percpu_counter_add_batch() fastpath unless externally serialized. That's completely independent of CPU hotplug though. Fixes: 8b57b11cca88 ("pcpcntrs: fix dying cpu summation race") Signed-off-by: Thomas Gleixner [Dennis: Ported to v6.7-rc4. Updated percpu_counter.c for batch percpu_counter creation and _percpu_counter_limited_add().] Signed-off-by: Dennis Zhou --- include/linux/cpuhotplug.h | 2 +- lib/percpu_counter.c | 65 ++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index efc0c0b07efb..1e11f3193398 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -90,7 +90,6 @@ enum cpuhp_state { CPUHP_FS_BUFF_DEAD, CPUHP_PRINTK_DEAD, CPUHP_MM_MEMCQ_DEAD, - CPUHP_PERCPU_CNT_DEAD, CPUHP_RADIX_DEAD, CPUHP_PAGE_ALLOC, CPUHP_NET_DEV_DEAD, @@ -198,6 +197,7 @@ enum cpuhp_state { CPUHP_AP_HRTIMERS_DYING, CPUHP_AP_X86_TBOOT_DYING, CPUHP_AP_ARM_CACHE_B15_RAC_DYING, + CPUHP_AP_PERCPU_COUNTER_STARTING, CPUHP_AP_ONLINE, CPUHP_TEARDOWN_CPU, diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c index 44dd133594d4..6a1354661378 100644 --- a/lib/percpu_counter.c +++ b/lib/percpu_counter.c @@ -12,7 +12,7 @@ #ifdef CONFIG_HOTPLUG_CPU static LIST_HEAD(percpu_counters); -static DEFINE_SPINLOCK(percpu_counters_lock); +static DEFINE_RAW_SPINLOCK(percpu_counters_lock); #endif #ifdef CONFIG_DEBUG_OBJECTS_PERCPU_COUNTER @@ -126,13 +126,8 @@ EXPORT_SYMBOL(percpu_counter_sync); * Add up all the per-cpu counts, return the result. This is a more accurate * but much slower version of percpu_counter_read_positive(). * - * We use the cpu mask of (cpu_online_mask | cpu_dying_mask) to capture sums - * from CPUs that are in the process of being taken offline. Dying cpus have - * been removed from the online mask, but may not have had the hotplug dead - * notifier called to fold the percpu count back into the global counter sum. - * By including dying CPUs in the iteration mask, we avoid this race condition - * so __percpu_counter_sum() just does the right thing when CPUs are being taken - * offline. + * Note: This function is inherently racy against the lockless fastpath of + * percpu_counter_add_batch() unless externaly serialized. */ s64 __percpu_counter_sum(struct percpu_counter *fbc) { @@ -142,10 +137,8 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc) raw_spin_lock_irqsave(&fbc->lock, flags); ret = fbc->count; - for_each_cpu_or(cpu, cpu_online_mask, cpu_dying_mask) { - s32 *pcount = per_cpu_ptr(fbc->counters, cpu); - ret += *pcount; - } + for_each_online_cpu(cpu) + ret += *per_cpu_ptr(fbc->counters, cpu); raw_spin_unlock_irqrestore(&fbc->lock, flags); return ret; } @@ -181,10 +174,10 @@ int __percpu_counter_init_many(struct percpu_counter *fbc, s64 amount, } #ifdef CONFIG_HOTPLUG_CPU - spin_lock_irqsave(&percpu_counters_lock, flags); + raw_spin_lock_irqsave(&percpu_counters_lock, flags); for (i = 0; i < nr_counters; i++) list_add(&fbc[i].list, &percpu_counters); - spin_unlock_irqrestore(&percpu_counters_lock, flags); + raw_spin_unlock_irqrestore(&percpu_counters_lock, flags); #endif return 0; } @@ -205,10 +198,10 @@ void percpu_counter_destroy_many(struct percpu_counter *fbc, u32 nr_counters) debug_percpu_counter_deactivate(&fbc[i]); #ifdef CONFIG_HOTPLUG_CPU - spin_lock_irqsave(&percpu_counters_lock, flags); + raw_spin_lock_irqsave(&percpu_counters_lock, flags); for (i = 0; i < nr_counters; i++) list_del(&fbc[i].list); - spin_unlock_irqrestore(&percpu_counters_lock, flags); + raw_spin_unlock_irqrestore(&percpu_counters_lock, flags); #endif free_percpu(fbc[0].counters); @@ -221,22 +214,29 @@ EXPORT_SYMBOL(percpu_counter_destroy_many); int percpu_counter_batch __read_mostly = 32; EXPORT_SYMBOL(percpu_counter_batch); -static int compute_batch_value(unsigned int cpu) +static void compute_batch_value(int offs) { - int nr = num_online_cpus(); + int nr = num_online_cpus() + offs; - percpu_counter_batch = max(32, nr*2); + percpu_counter_batch = max(32, nr * 2); +} + +static int percpu_counter_cpu_starting(unsigned int cpu) +{ + /* If invoked during hotplug @cpu is not yet marked online. */ + compute_batch_value(cpu_online(cpu) ? 0 : 1); return 0; } -static int percpu_counter_cpu_dead(unsigned int cpu) +static int percpu_counter_cpu_dying(unsigned int cpu) { #ifdef CONFIG_HOTPLUG_CPU struct percpu_counter *fbc; + unsigned long flags; - compute_batch_value(cpu); + compute_batch_value(0); - spin_lock_irq(&percpu_counters_lock); + raw_spin_lock_irqsave(&percpu_counters_lock, flags); list_for_each_entry(fbc, &percpu_counters, list) { s32 *pcount; @@ -246,7 +246,7 @@ static int percpu_counter_cpu_dead(unsigned int cpu) *pcount = 0; raw_spin_unlock(&fbc->lock); } - spin_unlock_irq(&percpu_counters_lock); + raw_spin_unlock_irqrestore(&percpu_counters_lock, flags); #endif return 0; } @@ -331,13 +331,11 @@ bool __percpu_counter_limited_add(struct percpu_counter *fbc, } if (!good) { - s32 *pcount; int cpu; - for_each_cpu_or(cpu, cpu_online_mask, cpu_dying_mask) { - pcount = per_cpu_ptr(fbc->counters, cpu); - count += *pcount; - } + for_each_online_cpu(cpu) + count += *per_cpu_ptr(fbc->counters, cpu); + if (amount > 0) { if (count > limit) goto out; @@ -359,15 +357,8 @@ bool __percpu_counter_limited_add(struct percpu_counter *fbc, static int __init percpu_counter_startup(void) { - int ret; - - ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "lib/percpu_cnt:online", - compute_batch_value, NULL); - WARN_ON(ret < 0); - ret = cpuhp_setup_state_nocalls(CPUHP_PERCPU_CNT_DEAD, - "lib/percpu_cnt:dead", NULL, - percpu_counter_cpu_dead); - WARN_ON(ret < 0); + WARN_ON(cpuhp_setup_state(CPUHP_AP_PERCPU_COUNTER_STARTING, "lib/percpu_counter:starting", + percpu_counter_cpu_starting, percpu_counter_cpu_dying)); return 0; } module_init(percpu_counter_startup); From patchwork Fri Jan 12 23:36:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 13518768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78AB3C4706C for ; Fri, 12 Jan 2024 23:37:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83CF46B0092; Fri, 12 Jan 2024 18:37:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C6F06B0093; Fri, 12 Jan 2024 18:37:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A89B6B0095; Fri, 12 Jan 2024 18:37:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 429656B0092 for ; Fri, 12 Jan 2024 18:37:17 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 128CDC06CB for ; Fri, 12 Jan 2024 23:37:17 +0000 (UTC) X-FDA: 81672272514.04.728CD06 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) by imf23.hostedemail.com (Postfix) with ESMTP id 4D8D314000E for ; Fri, 12 Jan 2024 23:37:15 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf23.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.210.48 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705102635; a=rsa-sha256; cv=none; b=GM37ysm0RtfugoeDq2b5LA2kyoZdf/ravQcCwmOmXBQgI8NOr9Vs3E/MRGTuLrmgbmixuv 2ZoGj77Xxi4Oq1BXXM6QeEgOMm4b1wJ2SwAgNuo51ZzNQT6HJZDOxAhSVIGBMwEcmX6gQl Rn5N89zJNzTjNFi/dciqcj+9GaLYYaA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf23.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.210.48 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705102635; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DXiBs0Dsv9lw08RA+psp/orErqrti+c5fonsf5dUFRo=; b=zgxJjRnKyrWvqR1vUUTZpTjo4on+vaisNY8VXEtynGU8cm2gJU4ZtnN8Uj6nlrXFuDInjj 82d8VtNitr1aptqtjStdHJc6LvW3No9EYmnujlpjEKjAey9V6A4eKjTlO95ylnrGDA7M2E uvXi6Stm3GMmf7vtlRYigob6M22LaKE= Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6ddf05b1922so2085577a34.2 for ; Fri, 12 Jan 2024 15:37:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705102634; x=1705707434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DXiBs0Dsv9lw08RA+psp/orErqrti+c5fonsf5dUFRo=; b=NGnnL8nVXGRH/wqih4vzUjsvVPnwoU/1+Zq87DN7LbCqs4TIQal8mJT1ao4LbtUJzn A4mzHV8CzHuZa3ZGAtV6YYemuTjUHGtbUb2jVfCxwtA/0mZo0bPTKQtB3ZTXGlAVyFkd 5h+lyl8fctghNIGSWEXWlkJhC1suwGBqBFaJg9xVxZV+GLgBOtr4H1QnKr+AeWCqOoEJ CybHk231/kHfzfmEvt/k5xGEeMFWBUALw5vs+PY31OUQLCylNo9GARmUKUwM6fQqYPx+ SZ/XgQdyOAks5VIZdd6EHDMib5eKftVQkCXN5kdcsNeI+4AFdt3BOjUGlq/RP0Wfd8kc Eq2A== X-Gm-Message-State: AOJu0YzG7XsCjNzl47cpsbXIUv2jKYKscsz5ZikJDpuRFXxx+XbR2JuG E/W592hhi9YScd9Hvp+zalc= X-Google-Smtp-Source: AGHT+IEdNIM2lremxB3JZhNXf4OuMUXyIV4MCDVGmUw8k5Ivx9Us2Hv3XZbGLovn7MBYk8JmFX6PxA== X-Received: by 2002:a05:6830:12d6:b0:6dd:eebd:cd5f with SMTP id a22-20020a05683012d600b006ddeebdcd5fmr2415192otq.48.1705102634455; Fri, 12 Jan 2024 15:37:14 -0800 (PST) Received: from snowbird.lan ([136.25.84.107]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b006d9b4171b20sm3676811pff.112.2024.01.12.15.37.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 15:37:14 -0800 (PST) From: Dennis Zhou To: Tejun Heo , Christoph Lameter , Thomas Gleixner Cc: Peter Zijlstra , Valentin Schneider , Dave Chinner , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Ye Bin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 2/3] cpu/hotplug: Remove export of cpu_active_mask and cpu_dying_mask Date: Fri, 12 Jan 2024 15:36:47 -0800 Message-Id: <1d719106061cc0177eb16d6d5ac914c0485772b2.1705101789.git.dennis@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4D8D314000E X-Stat-Signature: ee878ooe57poqkjxtmws7dh3jgc99tch X-Rspam-User: X-HE-Tag: 1705102635-434353 X-HE-Meta: U2FsdGVkX1/1AMZmfpulvb4MChUAu6jnzOOwWpJBkdBALzj6Yts3PlfzxRjd/gSO9wqHrQ8vFZd02XWW+p4mG5i+bo09et6DrD4yXEgt701YChWiDYxyrFv45ngBYoJivLeo7wY291UkiCjfilpYhwq6Q3uZKmfpUClguyQZUkueu6ydn/K2lKPjdvQY+4isANygJxN+tAzKcO6ZvVou6n/V0O3jsALUf8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4G6ZFUmc5B8JeIQyay4/iv1G+8fqlkmMMRFyM5M6aECdGw1cSPyEpN14cTAUg/xRCbjTCbyZ/u0N8NYX7h4rNLvNuhjhsWQRGlMSuEc2Mzfe1d/ptU2FdT1ZwC/+xQY0ZDZdAe28UOlGMBpqGmmfN/YuVDuDeFgjLH3a8gbxly0/bi8xaW0XypbyhDAT/YPqXtIneEOSTBY16su2ELtxy1N8hCtL2rxlc94SItPOwFldeALCPbdJ7oreSms+O7Rje8Yf6XEo8JAiya31Iz0/f23GXd2jrdeWvH2fgAJe7I0LsSaPd4fDnZnSIF8Rtf341vhc4tnPm06LmIWntJzzD8gspPIzFCD2KGU X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Thomas Gleixner No module users and no module should ever care. Signed-off-by: Thomas Gleixner Reviewed-by: Valentin Schneider [Dennis: applied cleanly] Signed-off-by: Dennis Zhou --- kernel/cpu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index a86972a91991..c4929e9cd9be 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -3126,10 +3126,8 @@ struct cpumask __cpu_present_mask __read_mostly; EXPORT_SYMBOL(__cpu_present_mask); struct cpumask __cpu_active_mask __read_mostly; -EXPORT_SYMBOL(__cpu_active_mask); struct cpumask __cpu_dying_mask __read_mostly; -EXPORT_SYMBOL(__cpu_dying_mask); atomic_t __num_online_cpus __read_mostly; EXPORT_SYMBOL(__num_online_cpus); From patchwork Fri Jan 12 23:36:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dennis Zhou X-Patchwork-Id: 13518769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25FA2C4707C for ; Fri, 12 Jan 2024 23:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9017E8D0001; Fri, 12 Jan 2024 18:37:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88A3E6B0095; Fri, 12 Jan 2024 18:37:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DC648D0001; Fri, 12 Jan 2024 18:37:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4DBC06B0093 for ; Fri, 12 Jan 2024 18:37:19 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 209D5A0AF9 for ; Fri, 12 Jan 2024 23:37:19 +0000 (UTC) X-FDA: 81672272598.20.B0586EC Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf29.hostedemail.com (Postfix) with ESMTP id 570D712000A for ; Fri, 12 Jan 2024 23:37:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf29.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705102637; a=rsa-sha256; cv=none; b=xdqqaHqKvHSGfjFuzzJoupIl2uW4WSNQOQPyvQeT9yooaTmV4jTQsRdtYPPUdA9mxdLbfK YD8vi2Qy0sqYBCxqN3wazzeEs+P36KAi+23S8tE6VcB5Mo66RfssWydfrW/8whSKIlJ0pl TXSNK0bQvF3egSrLqIzc2m9KirdgXK4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none); spf=pass (imf29.hostedemail.com: domain of dennisszhou@gmail.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=dennisszhou@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705102637; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ifDoLpiNdOYTSQ47Pl1LromjALktxWcq8aIySdxMVro=; b=fRbH6QrNdXmJAdaRaWYC7eQ2IM2m20rnnRFnVUbyUtaoHqsc3fqjbLRaVsB+S24NrrbEpN Yg3SyD3sbpVrHLeT6UeWGxeQO5Lugzu311iY0yGRkmIiYR3f5FVqjNhJ8DVYXbTBgxZcvq Kp4NTdMSeM++YpgdmhhuumIEP/YKcJI= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6d9344f30caso4792812b3a.1 for ; Fri, 12 Jan 2024 15:37:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705102636; x=1705707436; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ifDoLpiNdOYTSQ47Pl1LromjALktxWcq8aIySdxMVro=; b=wnSFUERrQDPXAG1oVJJP66HBePW4L8rbmMaNlmX6uN4ZZqa5sIXXkL7t6b3665rFGf ovm4QRa5oEA6LepbfMLq0sVp6MZnwns8dWhybcgv9ngp0jCAw9NDgV9fc4YMqymDbVbW 7Y/gGuAZHWJA+G3IBUZEJ5FnQ709r8ocGym+mZew5jxbIUVAbZW+qoV//pV0lhIXpGKo MAQdFNpn5nJeYDGvs+z8bhuoEmfocD7XaXUe6jwDYHcY+lMDB1M8sluQNIVhjs/v7NI0 vtr3z6uKs4f6YhzmVa3yI6lviXE8WGXQatTipWWWYGYXU/EAxMWpz2JEambqSgUl8Zxu AZUg== X-Gm-Message-State: AOJu0Yw3MxUgQY/Kz7kYs23ByI6pYZOrfH9R8ThZ6Lcrb59jxO6Uypep k8kZPV2EgLJVDkIGZHxTuSODbY6tz1k82A== X-Google-Smtp-Source: AGHT+IETOzry7t2QrGyMY0qVE9zN8YF+Pj/G2WT9Tg51W3pV2fUxP0YtB8ryO5YxL+RNGUaJMSnd/Q== X-Received: by 2002:a05:6a00:1822:b0:6da:56c:1019 with SMTP id y34-20020a056a00182200b006da056c1019mr2564523pfa.3.1705102636149; Fri, 12 Jan 2024 15:37:16 -0800 (PST) Received: from snowbird.lan ([136.25.84.107]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b006d9b4171b20sm3676811pff.112.2024.01.12.15.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 15:37:15 -0800 (PST) From: Dennis Zhou To: Tejun Heo , Christoph Lameter , Thomas Gleixner Cc: Peter Zijlstra , Valentin Schneider , Dave Chinner , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Ye Bin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 3/3] cpu/hotplug: Get rid of cpu_dying_mask Date: Fri, 12 Jan 2024 15:36:48 -0800 Message-Id: <4aeddaa133df7c0b7795b7774d2222efedc3aa12.1705101789.git.dennis@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 570D712000A X-Stat-Signature: 7xgegczxckm9krwqw5kx1d9wpwoetngr X-Rspam-User: X-HE-Tag: 1705102637-363646 X-HE-Meta: U2FsdGVkX185xsw+2/+9RyBT4y2rJsf4rjIwVjWSqAyHn3thCRHgwMlQ+I/G78yIK3DwAu9lXNh84fTPFwLQo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Sem4Goae23LLo9J2NCP+P1EalrniP+CONCiJbZLWgjNOTPgw4YtsXSwEfrhFTwzrHVTPcTzCraYfKAWYC2Jm0gSLXpR3gKNWYkVgsVyXXU7wx5yiaot/XuMfud8Qxi9Hf+9TUN86NDGZjoQGgFICMXBNXFjBqVSPpd54rhUMdZY7V98tBV9f/gTrzcv/SYtmKG/u3Ckno1omhp8ufIMH2jYnpEWN8LGQtS0iqftW7+eRNpwniX9lzKMap6dkmHundLjrEJhUzGysUug0tUF1IHoNLyfoU8nEi3gQ/H+VxrdBgTqry6ItsKJ2PLxYvTVrYqyEIZP/QxZTKYVnAnGUo+fas8zDPA5m/OPhWzO4IoETIN6e1aYyMmGAfWC8S5VfD1/s7omw/gItNTxpY2WAcCn3UZUgRWt4u0jg6QkqweLcZf+eajaiIntf9zlp77AyZBih+eqf74bHZAztGiuda6AT8CWlJOVWsTjvpEeEC7xU2too= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The cpu_dying_mask is not only undocumented but also to some extent a misnomer. It's purpose is to capture the last direction of a cpu_up() or cpu_down() operation taking eventual rollback operations into account. The name and the lack of documentation lured already someone to use it in the wrong way. The initial user is the scheduler code which needs to keep the decision correct whether to schedule tasks on a CPU, which is between the CPUHP_ONLINE and the CPUHP_ACTIVE state and has the balance_push() hook installed. cpu_dying mask is not really useful for general consumption. The cpu_dying_mask bits are sticky even after cpu_up() or cpu_down() completes. It might be argued, that the cpu_dying_mask bit could be cleared when cpu_down() completes, but that's not possible under all circumstances. Especially not with partial hotplug operations. In that case the bit must be sticky in order to keep the initial user, i.e. the scheduler correct. Replace the cpumask completely by: - recording the direction internally in the CPU hotplug core state - exposing that state via a documented function to the scheduler After that cpu_dying_mask is not longer in use and removed before the next user trips over it. Signed-off-by: Thomas Gleixner [Dennis: ported to v6.7-rc4, delete in cpumask.h didn't apply cleanly] Signed-off-by: Dennis Zhou --- include/linux/cpumask.h | 21 -------------------- kernel/cpu.c | 43 +++++++++++++++++++++++++++++++++++------ kernel/sched/core.c | 4 ++-- kernel/smpboot.h | 2 ++ 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index cfb545841a2c..b19b6fd29a0d 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -126,12 +126,10 @@ extern struct cpumask __cpu_possible_mask; extern struct cpumask __cpu_online_mask; extern struct cpumask __cpu_present_mask; extern struct cpumask __cpu_active_mask; -extern struct cpumask __cpu_dying_mask; #define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask) #define cpu_online_mask ((const struct cpumask *)&__cpu_online_mask) #define cpu_present_mask ((const struct cpumask *)&__cpu_present_mask) #define cpu_active_mask ((const struct cpumask *)&__cpu_active_mask) -#define cpu_dying_mask ((const struct cpumask *)&__cpu_dying_mask) extern atomic_t __num_online_cpus; @@ -1035,15 +1033,6 @@ set_cpu_active(unsigned int cpu, bool active) cpumask_clear_cpu(cpu, &__cpu_active_mask); } -static inline void -set_cpu_dying(unsigned int cpu, bool dying) -{ - if (dying) - cpumask_set_cpu(cpu, &__cpu_dying_mask); - else - cpumask_clear_cpu(cpu, &__cpu_dying_mask); -} - /** * to_cpumask - convert a NR_CPUS bitmap to a struct cpumask * * @bitmap: the bitmap @@ -1119,11 +1108,6 @@ static inline bool cpu_active(unsigned int cpu) return cpumask_test_cpu(cpu, cpu_active_mask); } -static inline bool cpu_dying(unsigned int cpu) -{ - return cpumask_test_cpu(cpu, cpu_dying_mask); -} - #else #define num_online_cpus() 1U @@ -1151,11 +1135,6 @@ static inline bool cpu_active(unsigned int cpu) return cpu == 0; } -static inline bool cpu_dying(unsigned int cpu) -{ - return false; -} - #endif /* NR_CPUS > 1 */ #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) diff --git a/kernel/cpu.c b/kernel/cpu.c index c4929e9cd9be..ce78757b7535 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -54,6 +54,9 @@ * @rollback: Perform a rollback * @single: Single callback invocation * @bringup: Single callback bringup or teardown selector + * @goes_down: Indicator for direction of cpu_up()/cpu_down() operations + * including eventual rollbacks. Not affected by state or + * instance add/remove operations. See cpuhp_cpu_goes_down(). * @cpu: CPU number * @node: Remote CPU node; for multi-instance, do a * single entry callback for install/remove @@ -74,6 +77,7 @@ struct cpuhp_cpu_state { bool rollback; bool single; bool bringup; + bool goes_down; struct hlist_node *node; struct hlist_node *last; enum cpuhp_state cb_state; @@ -474,6 +478,37 @@ void cpu_maps_update_done(void) mutex_unlock(&cpu_add_remove_lock); } +/** + * cpuhp_cpu_goes_down - Query the current/last CPU hotplug direction of a CPU + * @cpu: The CPU to query + * + * The direction indicator is modified by the hotplug core on + * cpu_up()/cpu_down() operations including eventual rollback operations. + * The indicator is not affected by state or instance install/remove + * operations. + * + * The indicator is sticky after the hotplug operation completes, whether + * the operation was a full up/down or just a partial bringup/teardown. + * + * goes_down + * cpu_up(target) enter -> False + * rollback on fail -> True + * cpu_up(target) exit Last state + * + * cpu_down(target) enter -> True + * rollback on fail -> False + * cpu_down(target) exit Last state + * + * The return value is a racy snapshot and not protected against concurrent + * CPU hotplug operations which modify the indicator. + * + * Returns: True if cached direction is down, false otherwise + */ +bool cpuhp_cpu_goes_down(unsigned int cpu) +{ + return data_race(per_cpu(cpuhp_state.goes_down, cpu)); +} + /* * If set, cpu_up and cpu_down will return -EBUSY and do nothing. * Should always be manipulated under cpu_add_remove_lock @@ -708,8 +743,7 @@ cpuhp_set_state(int cpu, struct cpuhp_cpu_state *st, enum cpuhp_state target) st->target = target; st->single = false; st->bringup = bringup; - if (cpu_dying(cpu) != !bringup) - set_cpu_dying(cpu, !bringup); + st->goes_down = !bringup; return prev_state; } @@ -743,8 +777,7 @@ cpuhp_reset_state(int cpu, struct cpuhp_cpu_state *st, } st->bringup = bringup; - if (cpu_dying(cpu) != !bringup) - set_cpu_dying(cpu, !bringup); + st->goes_down = !bringup; } /* Regular hotplug invocation of the AP hotplug thread */ @@ -3127,8 +3160,6 @@ EXPORT_SYMBOL(__cpu_present_mask); struct cpumask __cpu_active_mask __read_mostly; -struct cpumask __cpu_dying_mask __read_mostly; - atomic_t __num_online_cpus __read_mostly; EXPORT_SYMBOL(__num_online_cpus); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index a708d225c28e..6d4f0cdad446 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2468,7 +2468,7 @@ static inline bool is_cpu_allowed(struct task_struct *p, int cpu) return cpu_online(cpu); /* Regular kernel threads don't get to stay during offline. */ - if (cpu_dying(cpu)) + if (cpuhp_cpu_goes_down(cpu)) return false; /* But are allowed during online. */ @@ -9434,7 +9434,7 @@ static void balance_push(struct rq *rq) * Only active while going offline and when invoked on the outgoing * CPU. */ - if (!cpu_dying(rq->cpu) || rq != this_rq()) + if (!cpuhp_cpu_goes_down(rq->cpu) || rq != this_rq()) return; /* diff --git a/kernel/smpboot.h b/kernel/smpboot.h index 34dd3d7ba40b..9d3b4d554411 100644 --- a/kernel/smpboot.h +++ b/kernel/smpboot.h @@ -20,4 +20,6 @@ int smpboot_unpark_threads(unsigned int cpu); void __init cpuhp_threads_init(void); +bool cpuhp_cpu_goes_down(unsigned int cpu); + #endif