From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sg-1-101.ptr.blmpb.com (sg-1-101.ptr.blmpb.com [118.26.132.101]) (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 66F0D212B0A for ; Mon, 2 Mar 2026 07:53:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772438028; cv=none; b=bfvOuVO3aQcuQJR66opgke3uE5n1ZZt/B7fFnwdlVp9KArURpMH8S30BqMD58cTn+UPvIRPlRiDPR1hSonUd7U8S9XezDrHfKMeUt9hRyfmyZppRFqvnPnEvp7TUkkUHw4v5pTOU5SBWbGCTPBKxpMBPLEKvzLDuwbg/tvvAlPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772438028; c=relaxed/simple; bh=EcfRwb2pEYQjsSKbm1m/19nTZG2B3csf+WGJ27Z1jEc=; h=To:Subject:References:Date:Mime-Version:In-Reply-To:Cc:From: Message-Id:Content-Type; b=cHTwLpXq3ookHdxlq2jdX+CiKLLVvLbpLFJk6NuMAHCde53jmIHqVnVkd6p3w3KH75ONOgEsxofjvTlMhaHJTbQ8YPF48EFu30AxW/WvD3uhMLc7tlTF7jQQnLdg4j2hq13ibRuD4+OJAXAPoNjE7j3jnyInus7fAQ/pJpsRCZ8= 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=p5lcHwls; arc=none smtp.client-ip=118.26.132.101 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="p5lcHwls" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1772438015; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=hq2wwmpbjv0StbGStx9tEznySPN2jyh4fTMfOnGCPAA=; b=p5lcHwlsENvbTGByPWvHI7huFCRpggcTs7YRGnpgWTcR7bM0It3emu/gvjV7ZiPkRb9rf1 yYiKWZk6MNbY6Du99ZNvS6mFFMsTkEIQG3Gnb7lz4BhAnGuRoCNjGnBkRZi+r68YRZzJSU 8JdPHd8RlKoR5u5nfzvA1mZs/YGCkj50w1OQvA68IEoJfFpC76xvab76EwIJyoB6o/GcaQ Tlka2mg7xjWDyOQ2xtMFCJEEBFYZCIM8fFhTFA2aw3SPdf36WEjF34s8J5zt79gDNp8jCL 1hitKLdDrGYkWLl5nT/ppjo5Af5tuJP/LWLZWhQHSi3ZV5a1FDcfEOlISKybZA== To: , , , , , , , , , , , Subject: [PATCH v2 04/12] smp: Use on-stack cpumask in smp_call_function_many_cond References: <20260302075216.2170675-1-zhouchuyi@bytedance.com> Content-Transfer-Encoding: 7bit X-Lms-Return-Path: Date: Mon, 2 Mar 2026 15:52:08 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1 X-Original-From: Chuyi Zhou In-Reply-To: <20260302075216.2170675-1-zhouchuyi@bytedance.com> Cc: , "Chuyi Zhou" From: "Chuyi Zhou" Message-Id: <20260302075216.2170675-5-zhouchuyi@bytedance.com> 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=n. This is a preparation for enabling preemption during csd_lock_wait() in smp_call_function_many_cond(). Signed-off-by: Chuyi Zhou --- 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 = !IS_ENABLED(CONFIG_CPUMASK_OFFSTACK); int cpu, last_cpu, this_cpu = smp_processor_id(); struct call_function_data *cfd; bool wait = scf_flags & SCF_WAIT; + cpumask_var_t cpumask_stack; + struct cpumask *cpumask; int nr_cpus = 0; bool run_remote = false; lockdep_assert_preemption_disabled(); + cfd = this_cpu_ptr(&cfd_data); + cpumask = cfd->cpumask; + + if (preemptible_wait) { + BUILD_BUG_ON(!alloc_cpumask_var(&cpumask_stack, GFP_ATOMIC)); + cpumask = 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, /* 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 = 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); cpumask_clear(cfd->cpumask_ipi); - for_each_cpu(cpu, cfd->cpumask) { + for_each_cpu(cpu, cpumask) { call_single_data_t *csd = per_cpu_ptr(cfd->csd, cpu); if (cond_func && !cond_func(cpu, info)) { - __cpumask_clear_cpu(cpu, cfd->cpumask); + __cpumask_clear_cpu(cpu, cpumask); continue; } @@ -887,13 +897,16 @@ static void smp_call_function_many_cond(const struct cpumask *mask, } if (run_remote && wait) { - for_each_cpu(cpu, cfd->cpumask) { + for_each_cpu(cpu, cpumask) { call_single_data_t *csd; csd = per_cpu_ptr(cfd->csd, cpu); csd_lock_wait(csd); } } + + if (preemptible_wait) + free_cpumask_var(cpumask_stack); } /** -- 2.20.1