From nobody Mon Apr 6 21:25:59 2026 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 19DA82FDC2C for ; Wed, 18 Mar 2026 04:58:23 +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=1773809904; cv=none; b=q7F2CT5pEkovx/IdfTNtetptJtb88eQMA54H/2zQqk12XjwjGJsLQodZsjL03bMN73zvQX+m6eunXq0R63d8RWTZbAzUpnzaLgwJNGhoELaipqO0OK6IDHYI1Y7cQUt3CAa0ZIsQtzWroqzvI5awaIuFnt0P/KLaJ7pCwrVtFsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773809904; c=relaxed/simple; bh=7MJNZsJeS39n2ojWHSx8/JErYlkaOcC+j+Gs9faF9yc=; h=To:Cc:From:Message-Id:References:Content-Type:Subject:Date: In-Reply-To:Mime-Version; b=mizG2t91CAGmF0NVlLFvltWeoP/67yfUPg3DLsJYMmIrQXejeHMX2sHXXYWAZWIgXr/yHE+rqoHK+CqhgkRPFEKgEaHIK0M6ABp935aSIwkCGQ6lIIBS2o8ccaAVy+ywJ9Pu+pwckx9XN7vyat8wQDJgPLlNOZcn4XZ8uJtVKoQ= 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=dDfHeWfP; 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="dDfHeWfP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1773809899; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=I3Rm8ROr4+HRYuuyjAmvwWOTfT5mUF/s2Lnk6LUdYbg=; b=dDfHeWfPK+erY4zx3KTHpaEIT4g0ueD1k9qZ6rmDP25QFwNOLgfHc8nOhCtCfx9cDOjdJ7 CEHCMGjbvDEbkfSpuKmxMkpj43eW/YO4YMjmXnJT63Iug87D8Fyi81Z8pVbp0USIKaT0Tg aB/sXP7OfyBsUnnEl2NclFy4YqLTdSukl0kMoEr32D+vm842J7M8ErsUrWwiQWi0o76hAn EOhF5OQ6kIrbVIgWlheH+UiBAztwNWnJ2wgKmNeR1rGZ1jDpADlifQUY7v3YvW5fpytSEZ A7i3wVxpvufK4o17pHGtxaIL56LEfzo8XFlpsmKi/WSwZKrRiSTaJ2aSClEIUg== To: , , , , , , , , , , , Cc: , "Chuyi Zhou" From: "Chuyi Zhou" Message-Id: <20260318045638.1572777-5-zhouchuyi@bytedance.com> References: <20260318045638.1572777-1-zhouchuyi@bytedance.com> Content-Transfer-Encoding: quoted-printable Subject: [PATCH v3 04/12] smp: Use on-stack cpumask in smp_call_function_many_cond Date: Wed, 18 Mar 2026 12:56:30 +0800 In-Reply-To: <20260318045638.1572777-1-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: X-Original-From: Chuyi Zhou X-Mailer: git-send-email 2.20.1 Content-Type: text/plain; charset="utf-8" This patch use on-stack cpumask to replace percpu cfd cpumask in smp_call_function_many_cond(). Note that when both CONFIG_CPUMASK_OFFSTACK and PREEMPT_RT are enabled, allocation during preempt-disabled section would break RT. Therefore, only do this when CONFIG_CPUMASK_OFFSTACK=3Dn. This is a preparation for enabling preemption during csd_lock_wait() in smp_call_function_many_cond(). Signed-off-by: Chuyi Zhou Reviewed-by: Muchun Song --- kernel/smp.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/kernel/smp.c b/kernel/smp.c index 80daf9dd4a25..9728ba55944d 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -799,14 +799,25 @@ static void smp_call_function_many_cond(const struct = cpumask *mask, unsigned int scf_flags, smp_cond_func_t cond_func) { + bool preemptible_wait =3D !IS_ENABLED(CONFIG_CPUMASK_OFFSTACK); int cpu, last_cpu, this_cpu =3D smp_processor_id(); struct call_function_data *cfd; bool wait =3D scf_flags & SCF_WAIT; + cpumask_var_t cpumask_stack; + struct cpumask *cpumask; int nr_cpus =3D 0; bool run_remote =3D false; =20 lockdep_assert_preemption_disabled(); =20 + cfd =3D this_cpu_ptr(&cfd_data); + cpumask =3D cfd->cpumask; + + if (preemptible_wait) { + BUILD_BUG_ON(!alloc_cpumask_var(&cpumask_stack, GFP_ATOMIC)); + cpumask =3D cpumask_stack; + } + /* * Can deadlock when called with interrupts disabled. * We allow cpu's that are not yet online though, as no one else can @@ -827,16 +838,15 @@ static void smp_call_function_many_cond(const struct = cpumask *mask, =20 /* Check if we need remote execution, i.e., any CPU excluding this one. */ if (cpumask_any_and_but(mask, cpu_online_mask, this_cpu) < nr_cpu_ids) { - cfd =3D this_cpu_ptr(&cfd_data); - cpumask_and(cfd->cpumask, mask, cpu_online_mask); - __cpumask_clear_cpu(this_cpu, cfd->cpumask); + cpumask_and(cpumask, mask, cpu_online_mask); + __cpumask_clear_cpu(this_cpu, cpumask); =20 cpumask_clear(cfd->cpumask_ipi); - for_each_cpu(cpu, cfd->cpumask) { + for_each_cpu(cpu, cpumask) { call_single_data_t *csd =3D per_cpu_ptr(cfd->csd, cpu); =20 if (cond_func && !cond_func(cpu, info)) { - __cpumask_clear_cpu(cpu, cfd->cpumask); + __cpumask_clear_cpu(cpu, cpumask); continue; } =20 @@ -887,13 +897,16 @@ static void smp_call_function_many_cond(const struct = cpumask *mask, } =20 if (run_remote && wait) { - for_each_cpu(cpu, cfd->cpumask) { + for_each_cpu(cpu, cpumask) { call_single_data_t *csd; =20 csd =3D per_cpu_ptr(cfd->csd, cpu); csd_lock_wait(csd); } } + + if (preemptible_wait) + free_cpumask_var(cpumask_stack); } =20 /** --=20 2.20.1