From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sg-1-102.ptr.blmpb.com (sg-1-102.ptr.blmpb.com [118.26.132.102]) (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 A40C9212B0A for ; Mon, 2 Mar 2026 07:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.102 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772437998; cv=none; b=btbdWrsq5LKyv5O8114RGazuExi1SCE/vaVB5OustIXlWaOx1lulc7TR6btRDjgIfUjUvO1/k2OiCcXGQnsiWcVvKC991R7c5uOMRaxsAa0qHH6lj1K3qJtlhH4lEHUP712aGyGlAl+Aa1AL/CC+zzZDxxXofMN557YaX+ow06g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772437998; c=relaxed/simple; bh=BUQMpQd8u4yUUj234WDO6+aggVbiGFe/pxhvaD81hJA=; h=Cc:Mime-Version:References:Content-Type:Subject:Date:In-Reply-To: To:From:Message-Id; b=Ay4KRnks+qBKdDIg1UKqCwCMBw/yV1ZwD/uszmTH/kT0z01F5wnXdLvVyyJYE7cULKxDO6c15pIUgc/i275TbgSGnv6/MVm5KIrjB++bdLGnvhOysyn7zIAV/mPOoEDtMyeEXWUC2AnYG3+go/XJuvPhBoAAiNwFfo75rf8X2bU= 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=UiKFCKpi; arc=none smtp.client-ip=118.26.132.102 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="UiKFCKpi" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1772437990; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=3XTAwPdhGZK2OUqdl9lebTQ6K/gQ43T09kCwqsH/4Gg=; b=UiKFCKpiCgl5Yb6HP1ZW9GkJI/lLyexP3/yuZrYz1x4JqBZCfLGTjReJnkKlWBA76k8yC+ aGqZdASEA5il6YHKPFLVDwsGSmivC0/RQgr4ZwQSCbM+2gG65Xjfi+jwSyD1Pg5AC5Dz/c mzmHWwts19DM1Fqwa2WbfrCI2pOMi5MmDQwnF4X+GQ03g/nrJJugMGx5hcvURXSARmC3P/ RjivLf9BjCkq+1LE/5Y1CN2idJiPmf853YSP2iG+67lRJs9ZFquJoXdSF3O78eD3bccZ5d 2MJkPYwcAF53SUz88VQPDd2NuoUyuRiMakVIooSgSm95rjqPVZ9KGT+YZT/GHg== Cc: , "Chuyi Zhou" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260302075216.2170675-1-zhouchuyi@bytedance.com> X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 Subject: [PATCH v2 02/12] smp: Enable preemption early in smp_call_function_single Date: Mon, 2 Mar 2026 15:52:06 +0800 In-Reply-To: <20260302075216.2170675-1-zhouchuyi@bytedance.com> Content-Transfer-Encoding: 7bit X-Original-From: Chuyi Zhou To: , , , , , , , , , , , From: "Chuyi Zhou" Message-Id: <20260302075216.2170675-3-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 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 --- kernel/smp.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/smp.c b/kernel/smp.c index fc1f7a964616..b603d4229f95 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -685,11 +685,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