From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-2-112.ptr.blmpb.com (va-2-112.ptr.blmpb.com [209.127.231.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 9F3273C5546 for ; Thu, 9 Jul 2026 12:30:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.231.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783600255; cv=none; b=gZ+oULokk5nDj9I4a50eqH80lOpcImGtuSIRR3xVzzgJwY2EQNTitDpiwZxoaeppKmDYZ+pOKEh0OhBEjrXclrbvJWflp15Zq6IPtQRa0O3qb1j3i2Mwd7HRsaOGK14lNz0JYFTNXmE3vCNmthIG/uyrM6Xxw3HGmwW8oplh6D4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783600255; c=relaxed/simple; bh=XKP8JYf8Z2wYHNaLfHxvJWRj1U1bt5XLc5pXrpSoBK0=; h=In-Reply-To:References:Cc:Date:Message-Id:Mime-Version:To:From: Subject:Content-Type; b=gCnofEqy6GyR5soGVOrXwzfzLWhVA2IYZQniThGj/e8RWT2sA2RYGZ5bnrqJ79auCV+2F9xA/i0hbAV9UbB3yidRM9EJ2jZGDyy8RHzuMKx8KDi4QZ63bHXhrfKgRXRUI7NgDF8bcPKjSHdXxgfY8+qG6xdYEG6UH7koQ3I/8N8= 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=pVf0Oz95; arc=none smtp.client-ip=209.127.231.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="pVf0Oz95" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1783600248; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=e7Yxv6JQTj1GPtG9bpXo1c9chLOxpdLWlb5AGeLtS2s=; b=pVf0Oz95c2RDFYF+EtBcLV2Ds6TcdQEjYOOxyCmUoiwKvvLu/nIdMc+M6pjc1bYKm+Wvci VKkeu8VmQdL+SkdlAv5msKJS1SaYfnOGU5UBJxASRhmOp/qVHa1UpjoOxZKn6ybWifIpgh Mseo9VeYVB/3DpVdmNP/7tzqw4kVmrNmEkNjlYPCBghx17XXZrhpjJg9N0WLe5lRFvLO3q AqQqDKpePKLatDbYw9Adq27i4ALQc10/7wNvO/8JciRj8FdehDDHmq5WQhRjzQQtfxGYoH pJW2oAwIIggVQoT+frdvYZxv26qUf8hadaEyKMFvsUMAaMjepvd0XXHCNyMU1Q== In-Reply-To: <20260709122933.4021501-1-zhouchuyi@bytedance.com> References: <20260709122933.4021501-1-zhouchuyi@bytedance.com> Content-Transfer-Encoding: 7bit Cc: , "Chuyi Zhou" Date: Thu, 9 Jul 2026 20:29:21 +0800 Message-Id: <20260709122933.4021501-3-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Lms-Return-Path: To: , , , , , , , , , , , , , From: "Chuyi Zhou" Subject: [PATCH v10 02/14] smp: Enable preemption early in smp_call_function_single() Content-Type: text/plain; charset=UTF-8 X-Original-From: Chuyi Zhou X-Mailer: git-send-email 2.20.1 smp_call_function_single() disables preemption while it validates the target CPU, prepares the call single data, queues the callback and sends the IPI. For the !wait case, preemption protects the per-CPU csd_data from concurrent modification by another task on the same CPU. For the wait case, the CSD is stack allocated and no other task can reuse it. CPU pinning is still required until the callback has been queued and the IPI has been sent, to ensure that the target CPU cannot be offlined after the online check but before dispatch. After generic_exec_single() has queued the callback, the synchronous csd_lock_wait() invocation at the end of the execution does not require the caller to remain pinned to the current CPU. Enable preemption before csd_lock_wait() to shorten the preemption-disabled section. Signed-off-by: Chuyi Zhou Tested-by: Paul E. McKenney Reviewed-by: Muchun Song Reviewed-by: Steven Rostedt (Google) Reviewed-by: Sebastian Andrzej Siewior --- 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