From nobody Mon Apr 6 21:28:01 2026 Received: from va-1-111.ptr.blmpb.com (va-1-111.ptr.blmpb.com [209.127.230.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B32E82FD1A1 for ; Wed, 18 Mar 2026 04:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773809893; cv=none; b=c2SMw3db8zmw7+oI2RIHWD+VQavHwx0Rc8S+QPPP4LtI0VzE2d6rOvpm8EUlDcEGmjJh+ntLbktxKaLyDkmPpDzuBneeaG7T6uVaEWUZrncIwYuwM0Y4A0Xw5cWGCEPJp/7qDQeVI9cAvPAFqC/9z8jVUcmXTqsvpX7KI6Eq6CE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773809893; c=relaxed/simple; bh=TCy2KX9qDbiHGy1QuZHj0y6OOg+oyJE4Ks74Pqah68A=; h=References:Cc:From:Date:In-Reply-To:Content-Type:Subject: Message-Id:Mime-Version:To; b=JCSnDz4XWD7FCUy95S+5nus7dl/uvJphTRNspVJHlgmoiWmxjI0RLpimcHevEmqccCVppzpYV024ZOtVeUc/BDMpWvqosZGW58XdjDkWzFxbWpTEwi0Td+f17Z8jza+3ynn2C/gUsVN24RTwvVSgMXrRjfqlVunsF35q6wm5rB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=LaPvzZpT; arc=none smtp.client-ip=209.127.230.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="LaPvzZpT" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1773809887; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=KHQMxt7OqXLP0XEy9NJ/DuIMZST6z1kq98CQ96mzrVY=; b=LaPvzZpTtMUP4M1VYO9O/7yeOIZWcOy47aKB8heL1glDtggQeE8B4Xza3Njztn4vhhM/cq IAAavfaF09pSsY2WYCe3F0LJ70yS+UB4DrDHEwNAW8XHzy7vvHfLEm8kNtzptVLMrcR6F5 76fcPqdDuOufTozktRDQj3VX/9IMtLtq521O/5k3NF39q0B/9H1yJDIUuf3PFMzoi10yUd gv0WxYMC0oq/Ti3zPx9WDYGaLqOZtn/4ul/5r0ohwIDNRUkn0vk0j3pczWXV+Tcz/HL00+ JEi4fHlpp38UWGOBkUIOqJuNJFabfJ9ftgCrNwL5zXb0CJ2nMyHa97kB15gDZA== Content-Transfer-Encoding: quoted-printable References: <20260318045638.1572777-1-zhouchuyi@bytedance.com> Cc: , "Chuyi Zhou" From: "Chuyi Zhou" Date: Wed, 18 Mar 2026 12:56:29 +0800 In-Reply-To: <20260318045638.1572777-1-zhouchuyi@bytedance.com> Subject: [PATCH v3 03/12] smp: Remove get_cpu from smp_call_function_any Message-Id: <20260318045638.1572777-4-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 To: , , , , , , , , , , , X-Original-From: Chuyi Zhou X-Lms-Return-Path: X-Mailer: git-send-email 2.20.1 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Muchun Song --- kernel/smp.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/smp.c b/kernel/smp.c index b603d4229f95..80daf9dd4a25 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -761,16 +761,26 @@ EXPORT_SYMBOL_GPL(smp_call_function_single_async); int smp_call_function_any(const struct cpumask *mask, smp_call_func_t func, void *info, int wait) { + bool local =3D true; unsigned int cpu; int ret; =20 - /* Try for same CPU (cheapest) */ + /* + * Prevent migration to another CPU after selecting the current CPU + * as the target. + */ cpu =3D get_cpu(); - if (!cpumask_test_cpu(cpu, mask)) + + /* Try for same CPU (cheapest) */ + if (!cpumask_test_cpu(cpu, mask)) { cpu =3D sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)); + local =3D false; + put_cpu(); + } =20 ret =3D smp_call_function_single(cpu, func, info, wait); - put_cpu(); + if (local) + put_cpu(); return ret; } EXPORT_SYMBOL_GPL(smp_call_function_any); --=20 2.20.1