From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-114.ptr.blmpb.com (va-1-114.ptr.blmpb.com [209.127.230.114]) (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 1F230289E13 for ; Wed, 13 May 2026 12:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.114 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778676389; cv=none; b=ZxH6pb8HIQZNCEtvg1Ilc801fyZJRQAE++nyR6cymnovu4iWm2fe1bvUAiXNJMenTfh3ZxTqoRsRRX9+WD3SlisF258w0hT4r+thNFaIbVTFPNjoGNUn+C7fxoEim33Dgn/b8AQSaAjnSKBo7sqFi+3BMm/5gZMDIVXNHoNPN/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778676389; c=relaxed/simple; bh=vE5jQFy5pFyzEGryo9XJ36yYIHZDePx/ABJ6N57nt/A=; h=Cc:References:Content-Type:To:Mime-Version:In-Reply-To:From: Subject:Date:Message-Id; b=A4pVnTRIiDd/Go7VLn3O5RuH57/jfNhpqyyw3QLtEdZUaXoLGbls5IzehF7JJWsnFPnXc4tS084V+GQ8rXEvWOJ9zCuz5ILUv7s+bZODzSN5g150x5k+gncBmt0TESoPFVLA1dgcozg4omHvWM+rmpibVVtytQbAoE4/3XQ7xHg= 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=W7+I9Ou/; arc=none smtp.client-ip=209.127.230.114 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="W7+I9Ou/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1778676377; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=L2M7ctaod3d46KXdrMlsb/SZhOyJC5OxK8ymMPI71u4=; b=W7+I9Ou/nI3c20NqQiT0nV0mYLI1aFnULdYoqXjYButIjG5AaNiRSCC/OPBoseWAVY929M jbVTayt2SDuxVx86f7tyw24e09DEFPDFBCMyaAptFfX18izkSvNCLS2Q3neXX04AXgVctl s5SF3TSSVZf1uM77t5vZ8rF7g7XeFiHp7N/o1qhDXirMvzQHipCYw/4vpbDSwK2d287g+m XMvr3uR+AXHF/oVzBN8hcP4UkM4G0tkyjwPkdWMmIkmiL+tYa58w95vBWaWgo759E+z6CC UMbJi1NNMS2hAuAPmsQWkrDVWYfPisXWiak77l0cjjNv2oJ49TY7dsivK2mPKQ== Cc: , "Chuyi Zhou" References: <20260513124524.2569867-1-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 X-Lms-Return-Path: Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 To: , , , , , , , , , , , , Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 In-Reply-To: <20260513124524.2569867-1-zhouchuyi@bytedance.com> X-Original-From: Chuyi Zhou From: "Chuyi Zhou" Subject: [RESEND PATCH v5 02/12] smp: Enable preemption early in smp_call_function_single Date: Wed, 13 May 2026 20:45:14 +0800 Message-Id: <20260513124524.2569867-3-zhouchuyi@bytedance.com> Now smp_call_function_single() disables preemption mainly for the following reasons: - To protect the per-cpu csd_data from concurrent modification by other tasks on the current CPU in the !wait case. For the wait case, synchronization is not a concern as on-stack csd is used. - To prevent the remote online CPU from being offlined. Specifically, we want to ensure that no new IPIs are queued after smpcfd_dying_cpu() has finished. Disabling preemption for the entire execution is unnecessary, especially csd_lock_wait() part does not require preemption protection. This patch enables preemption before csd_lock_wait() to reduce the preemption-disabled critical section. Signed-off-by: Chuyi Zhou Reviewed-by: Muchun Song Reviewed-by: Steven Rostedt (Google) --- kernel/smp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/smp.c b/kernel/smp.c index b58975480e11..292eefadddbc 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -700,11 +700,16 @@ int smp_call_function_single(int cpu, smp_call_func_t func, void *info, err = generic_exec_single(cpu, csd); + /* + * @csd is stack-allocated when @wait is true. No concurrent access + * except from the IPI completion path, so we can re-enable preemption + * early to reduce latency. + */ + put_cpu(); + if (wait) csd_lock_wait(csd); - put_cpu(); - return err; } EXPORT_SYMBOL(smp_call_function_single); -- 2.20.1