From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89FFF260588 for ; Thu, 5 Feb 2026 09:51:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770285086; cv=none; b=RvLnTUuN42oY83Dd9q2QnfltjoTvMkD+nBj0AIRnK0aaJjBswRwVP/MsucpYTvxu2Jx1juUwJpRQHdt/vavBu8WrlZHMgJxxoigs5wlFgiQazUdDen1KpQDN4y5LopNmugCgbqBPe0XlYrb687yhe/bVHZNBBx+Z7pL0gLg4k10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770285086; c=relaxed/simple; bh=0qSxLvv4yactwg1HL3RNHlDuJ751eidNHxBa8im/ANc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b+ZrPV0DdqyH9DlcFOl/HJs737df+B/IizSJBOdmnaQjOMA93N2RPvxxEheFbrVPgZRsDtg5gB0Gh3mVUg8lqMbghWcQN+JqdBTzJe+gAkM739E4+FQ/soEPCI6a4gMQM5nfktf7QazwUH/PZJVSvqPXkV4EzRUo4wFo1sL2RnQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=X7tjGuGN; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="X7tjGuGN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lFddVFns+OlN02fHXA4rmM+4zGG8keRTwtH33byn6zo=; b=X7tjGuGNsChB16kAgI1N8Zcli4 nXVwuyXesmdgmYh9mBemqfFiojb8alqWq/CFwuI4E9AlqALNtLDnW9sHqIodMok4KwUE9sC9DBZEk 5JsCstv4b595OEYN08UK9le8iEd3CapSDz3XPx7nPfcpO6tWH1I6IxHQo45KDzJSuWdNeO8IP0Yja vKA++Oin0GELznrv1T8J9PmNTSuzoL6KAhsDtui+r7JxcQ1+kqaAE44xMgo86bY/mD3HCPAJTKwQM MPVHj60t0EjVn4h4Y3FKMoV9WJ7ZI6ImngsMvPAcFESdEtJ4KaGO7YWonjqPN8KVkA42t8ZMzF2sw bMxft4tA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vnw18-00000003RCy-0Umz; Thu, 05 Feb 2026 09:51:18 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 96166300BD2; Thu, 05 Feb 2026 10:51:17 +0100 (CET) Date: Thu, 5 Feb 2026 10:51:17 +0100 From: Peter Zijlstra To: Chuyi Zhou Cc: tglx@linutronix.de, mingo@redhat.com, luto@kernel.org, paulmck@kernel.org, muchun.song@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 04/11] smp: Use on-stack cpumask in smp_call_function_many_cond Message-ID: <20260205095117.GH232055@noisy.programming.kicks-ass.net> References: <20260203112401.3889029-1-zhouchuyi@bytedance.com> <20260203112401.3889029-5-zhouchuyi@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260203112401.3889029-5-zhouchuyi@bytedance.com> On Tue, Feb 03, 2026 at 07:23:54PM +0800, Chuyi Zhou wrote: > This patch use on-stack cpumask to replace percpu cfd cpumask in > smp_call_function_many_cond(). alloc_cpumask_var() may fail when > CONFIG_CPUMASK_OFFSTACK is enabled. In such extreme case, fall back to > cfd->cpumask. This is a preparation for the next patch. > > Signed-off-by: Chuyi Zhou > --- > kernel/smp.c | 22 +++++++++++++++++----- > 1 file changed, 17 insertions(+), 5 deletions(-) > > diff --git a/kernel/smp.c b/kernel/smp.c > index f572716c3c7d..35948afced2e 100644 > --- a/kernel/smp.c > +++ b/kernel/smp.c > @@ -805,11 +805,17 @@ static void smp_call_function_many_cond(const struct cpumask *mask, > int cpu, last_cpu, this_cpu = smp_processor_id(); > struct call_function_data *cfd; > bool wait = scf_flags & SCF_WAIT; > + bool preemptible_wait = true; > + cpumask_var_t cpumask_stack; > + struct cpumask *cpumask; > int nr_cpus = 0; > bool run_remote = false; > > lockdep_assert_preemption_disabled(); > > + if (!alloc_cpumask_var(&cpumask_stack, GFP_ATOMIC)) > + preemptible_wait = false; > + > /* > * Can deadlock when called with interrupts disabled. > * We allow cpu's that are not yet online though, as no one else can > @@ -831,15 +837,18 @@ 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 = preemptible_wait ? cpumask_stack : 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; > } > > @@ -890,13 +899,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); > } *sigh*, even if you don't break RT, this is quite terrible, what is wrong with something like so? --- --- a/kernel/smp.c +++ b/kernel/smp.c @@ -802,19 +802,18 @@ static void smp_call_function_many_cond( unsigned int scf_flags, smp_cond_func_t cond_func) { + struct call_function_data *cfd = this_cpu_ptr(&cfd_data); int cpu, last_cpu, this_cpu = smp_processor_id(); - struct call_function_data *cfd; + struct cpumask *cpumask = cfd->cpumask; bool wait = scf_flags & SCF_WAIT; - bool preemptible_wait = true; cpumask_var_t cpumask_stack; - struct cpumask *cpumask; int nr_cpus = 0; bool run_remote = false; lockdep_assert_preemption_disabled(); if (!alloc_cpumask_var(&cpumask_stack, GFP_ATOMIC)) - preemptible_wait = false; + cpumask = cpumask_stack; /* * Can deadlock when called with interrupts disabled. @@ -836,10 +835,6 @@ static void smp_call_function_many_cond( /* 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 = preemptible_wait ? cpumask_stack : cfd->cpumask; - cpumask_and(cpumask, mask, cpu_online_mask); __cpumask_clear_cpu(this_cpu, cpumask); @@ -907,8 +902,7 @@ static void smp_call_function_many_cond( } } - if (preemptible_wait) - free_cpumask_var(cpumask_stack); + free_cpumask_var(cpumask_stack); } /**