From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FE0D3A0EA0 for ; Thu, 5 Feb 2026 09:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770284562; cv=none; b=lwFIvyjz3oIy69Fu2XMHqyKzBbqvO1bCtEA2aIsDzDdM32+Iepduvs8wNXewYfiKQ/ULl+zgeUxVDgs32Z9fb4lvMRQxkHBpr+KryyhxgmWrLrqvgcU/BOzb4osStPjtwSpXQCBjY8bjvadIBeU5i/acg4AhYrt29L1IkGEElSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770284562; c=relaxed/simple; bh=DVzVBX9+NaxZkP4ezT84pfDT+ZJi0KJ2yFnWvzo1NAc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jqkAmbCHrV0ojDUfCVvACa5LBIsnnx0rOfAG5LyGxR/0KgMy3sCkwKTPJRA2pqzT7LMT2soS5a+a7w0qDD0AJIw0GyKragCyaMJLP8GWZ6EKaZfT9UEu69wtd+YGb66X1+zmtkWHsM5lfeaj+LU648xG2CYZrI7la1COs1uv3aU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=HQHL/9DA; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="HQHL/9DA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ooSX94uNTTpDve1MG7r9WrOth3eQ7C6Q0hzZ+TOJOy8=; b=HQHL/9DADKwPv+IaGSiSOgASJ6 QCdbaKJhkFgGCzQnsT7stht1+z1IY93GDDAMslt2JezMh/uxESQ/b5vMySfkWz8rUDIqdaVdD1XAx VoYXXguIvjXTnA3mQpz8PVH2kSr+vbQNcEIgWAdkPuhEBPgd+1QHc+QUj+OGlZE54u3UZj73DZT2X MUacKeJhio/qr8Ky4EFiiusXKjlICaD8yUKrAVpR8YEMXRCmjDaDiu2Sf9uCOI+bFu57tQYzdgr8B 8KlVVLQw/tFPAB2riqgUcPuwffKqp+rCdtIc+VX6ARtd6/pKkOfAeQ5lz7qgSQmKqtca2xEUz5x19 5bj2w0Vg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vnvsZ-00000001uY5-3FVR; Thu, 05 Feb 2026 09:42:27 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 06CD8300BD2; Thu, 05 Feb 2026 10:42:27 +0100 (CET) Date: Thu, 5 Feb 2026 10:42:26 +0100 From: Peter Zijlstra To: Chuyi Zhou Cc: tglx@linutronix.de, mingo@redhat.com, luto@kernel.org, paulmck@kernel.org, muchun.song@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/11] smp: Remove get_cpu from smp_call_function_any Message-ID: <20260205094226.GF232055@noisy.programming.kicks-ass.net> References: <20260203112401.3889029-1-zhouchuyi@bytedance.com> <20260203112401.3889029-4-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260203112401.3889029-4-zhouchuyi@bytedance.com> On Tue, Feb 03, 2026 at 07:23:53PM +0800, Chuyi Zhou wrote: > Now smp_call_function_single() would enable preemption before > csd_lock_wait() to reduce the critical section. To allow callers of > smp_call_function_any() to also benefit from this optimization, remove > get_cpu()/put_cpu() from smp_call_function_any(). > > Signed-off-by: Chuyi Zhou > --- > kernel/smp.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/kernel/smp.c b/kernel/smp.c > index 0858553f3666..f572716c3c7d 100644 > --- a/kernel/smp.c > +++ b/kernel/smp.c > @@ -772,13 +772,18 @@ int smp_call_function_any(const struct cpumask *mask, > unsigned int cpu; > int ret; > > + /* > + * Prevent migration to another CPU after selecting the current CPU > + * as the target. > + */ > + guard(migrate)(); > + > /* Try for same CPU (cheapest) */ > - cpu = get_cpu(); > + cpu = smp_processor_id(); > if (!cpumask_test_cpu(cpu, mask)) > cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)); > > ret = smp_call_function_single(cpu, func, info, wait); > - put_cpu(); > return ret; Urgh, that's horrible. Basically what you want is something like so: bool enable = true; unsigned int cpu; int ret; preempt_disable(); cpu = smp_processor_id(); if (!cpumask_test_cpu(cpu, mask)) { cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)) enable = false; preempt_enable(); } ret = smp_call_function_single(cpu, func, info, wait); if (enable) preempt_enable(); return ret;