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 083303F483E for ; Tue, 9 Jun 2026 09:18:20 +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=1780996702; cv=none; b=iM30bojasZgFNQpKimgpiII7FCgoeD6O43m79s1ivqJ0q92dFjzRpVGkfEpnL3TtiUgHoUYMZLWJ0QQ+jYav8YjIUtCq7hQGsp9WJFN+c8MPWNg9zjrmmG6/h6lpnyA8z+oEW07SpsXz6yNnKEQJVoMgZloHKmS1L6aCisMChrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780996702; c=relaxed/simple; bh=1+/jf0lnbM/ox43aPM6n6bVNq3l3OoNlvzi1wsAOzMk=; h=In-Reply-To:References:Content-Type:To:Cc:Subject:From:Date: Mime-Version:Message-Id; b=FB6xeK65jA99diiVE2W7fwvOjcE5SX/WYR0V3AN6MhmstsSUXJz8zbk8jw6NJeiW3aTUq9mcJx1abBFM2J0uoMsqeFOjkkhGnk5LFHIjTbWJhrnfOy/tQe6E02sU6F/Qt4Gbj5KawPpS4hdNaQnzChdn+MDg0TxAaR1htMq65m8= 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=dk+XHy81; 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="dk+XHy81" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780996696; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=IQWvTs8KMqCd06PqYrP8SQSRn9LOACFGe0wZnkGdl2E=; b=dk+XHy81t+BdNvLl/yJdrPt1+LWgbmtKqDtv8yr+bnVttAyhj1k31tgD/HKkqhvThIihuS /xUuFnZLALsxxqfao/GckXD+uCwsCoO2A/AHmNN1q0fqirz3q9WAXTxHUufPhVTDu00kex jdAZN9tvcWSN3Fpbh7ZUPb6rIixEC0SpOFSN+EjqVOjTKL3/sO6GPvi6aQBAUsfTxlq7Bk fKcqWqoGTfguuSR6CnP8GYHylI37BD1xCEdfa2wzJHdCLYUgEVdgNLbrPrWZIToSV1xH62 7mXDX54c+DpcwPB+NG4EhN/e6S29rWyyG1o2CA8Ng6V5AoOiZ/Xwday8B2DTIQ== In-Reply-To: <20260609091710.404083-1-zhouchuyi@bytedance.com> References: <20260609091710.404083-1-zhouchuyi@bytedance.com> Content-Type: text/plain; charset=UTF-8 To: , , , , , , , , , , , , , Cc: , "Chuyi Zhou" Subject: [PATCH v7 02/14] smp: Enable preemption early in smp_call_function_single() From: "Chuyi Zhou" Date: Tue, 9 Jun 2026 17:16:58 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Message-Id: <20260609091710.404083-3-zhouchuyi@bytedance.com> X-Original-From: Chuyi Zhou X-Mailer: git-send-email 2.20.1 X-Lms-Return-Path: 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) Reviewed-by: Sebastian Andrzej Siewior Tested-by: Paul E. McKenney --- 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