From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-112.ptr.blmpb.com (va-1-112.ptr.blmpb.com [209.127.230.112]) (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 C89CE43C057 for ; Tue, 16 Jun 2026 11:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781608392; cv=none; b=TJqqhkkomZi1y4j4ylAEVp5LGb1JGhAxl6wVHEXg+ouRWZVXsedctE9R73DzDwhES2GrgetPqTBmVx/kU6gl2Tsz8Rg1ZpRP1qncKDGZYdmUKQDc3yJ3WvotWNmMgM6qh2zz8AuBhltu637foKDACp3oaTlEd9mnVh+SAUAKPAc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781608392; c=relaxed/simple; bh=1+/jf0lnbM/ox43aPM6n6bVNq3l3OoNlvzi1wsAOzMk=; h=To:Subject:Message-Id:Content-Type:Cc:In-Reply-To:From: Mime-Version:Date:References; b=tvpqXN/W0M/fiTXfZPRn//5BjjLX3gyRNDX/GNcvt+xwO+hJjBOkNTJS9RSINXHNay2a/xiDKMJfaeHrIKnUGcwxgFTCC/h+VfwSW28FomVUl2SIKcvuzqVa3QU2oVSd1Kd29ciJ2MojRrnb1EpQqT0HYuK/dlqV+aF7zDk7U/c= 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=G8AFQK0I; arc=none smtp.client-ip=209.127.230.112 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="G8AFQK0I" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1781608369; 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=G8AFQK0IszFnn7Gt9tiAiD0ly6JjyoXb1taAYLxTchVfJMN1mbVAWwTtwSUc3JP0ScxomI G9IQX0MMM9+WFp67HQRWvcYueg4E/txBAIVO1GRW9vtSGyLyodgbj1pX2k+uoQHxDZqtt3 GQqr7O3b+zO6NS1JLI4kME8pjnzYlbvrQV/MYNCLkXgxC1IUesUlgwRd+iyOdtez9zAh5l FHVZfx3oHfOC4FHtAo0J5yUTI6FpD1TgVRKNPfTP8+D/7h5dLPMmxLtQOhMW1uNXrDsYqz N7i1E8GHjvBOCN5OwVvQKC6eY0Rf2GIGOKGbcAAViRP1snEKxNFcepNg4wUZkw== To: , , , , , , , , , , , , , Subject: [PATCH v8 02/14] smp: Enable preemption early in smp_call_function_single() Message-Id: <20260616111127.966468-3-zhouchuyi@bytedance.com> Content-Type: text/plain; charset=UTF-8 Cc: , "Chuyi Zhou" In-Reply-To: <20260616111127.966468-1-zhouchuyi@bytedance.com> From: "Chuyi Zhou" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Date: Tue, 16 Jun 2026 19:11:15 +0800 X-Lms-Return-Path: Content-Transfer-Encoding: 7bit X-Mailer: git-send-email 2.20.1 References: <20260616111127.966468-1-zhouchuyi@bytedance.com> X-Original-From: Chuyi Zhou 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