From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sg-1-103.ptr.blmpb.com (sg-1-103.ptr.blmpb.com [118.26.132.103]) (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 583E0218845 for ; Thu, 5 Feb 2026 14:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.103 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770301835; cv=none; b=uKYInLv2250pcLggjS5+O6MyoCV54/FruOeOSxxBhm8NJv1nt+JkRufwYoYEJ1B2RPwWtRjtpS+hFV9gtXz9sX3V+rjPXzre4DO+G4BJNDuOZyITXS75OuY9O/sf28gtDsj5pJmWkPx+ISL+iF0J5INMWbydsh8E8zhUYDLSeis= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770301835; c=relaxed/simple; bh=VDiWI2xE3v1r61oqPZFKcB//lC6oMXTby6pE5aLAjT8=; h=From:In-Reply-To:To:Message-Id:Date:Mime-Version:Content-Type:Cc: References:Subject; b=WgtQM7Xu/Es6B34a9UeLmAYNSo9xKyH63cYwL2+fp5PINYMazpIwDGbdsURhHPjGolAqr2gICqwlgYo2QafKdyiglFdTo+iwNjHu96PCXEcuWf44Q33KhUclZe7QOiHcLj81NA+hqP2xRQtpM4B+4LxSrYXWj/QUTEC8fxhqJxA= 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=Mqk3FJL7; arc=none smtp.client-ip=118.26.132.103 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="Mqk3FJL7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1770301822; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=8PacRRVV5w5WAE6QgWvzEIlrcby/5yCJO/dYlMY9Bz0=; b=Mqk3FJL7fIe02IJTQ6LeeMskhepnAUzWmSbm+/OeezQjMIRIHxVA5TX6VUKid+MChJWuy5 VchivNkhGzNgtp0F5OOB3EQjcoOOQZgg7JpbiZb+twHx0dNIEa/rIj2oFZsDxq6uIz2ls7 Hg9lKir6MesHJZAwn86N/aHztrvp5k67PORrffoFvtfXd3diXgUdGArOsBHcnBuNtu5VsJ vc+sIIW0OUeqPzaPCIhkqCN3tWjzjhf9JzUjkyUh9KqNN+ya0DhNKeeD3eJ6njPshKr5Eu 2l4s8oS9DH3I/wsb4RMh1y4t0JDPN0a+c1qEjidRF44aIsYM8HF8U1SzAsDcWA== From: "Chuyi Zhou" In-Reply-To: <20260205105704.GA245049@noisy.programming.kicks-ass.net> X-Lms-Return-Path: Content-Transfer-Encoding: quoted-printable To: "Peter Zijlstra" Message-Id: <261ae19f-e3d1-4017-be1e-90b5c6d91dc7@bytedance.com> User-Agent: Mozilla Thunderbird Date: Thu, 5 Feb 2026 22:29:51 +0800 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=UTF-8 Cc: , , , , , , , References: <20260203112401.3889029-1-zhouchuyi@bytedance.com> <20260203112401.3889029-6-zhouchuyi@bytedance.com> <20260205095236.GI232055@noisy.programming.kicks-ass.net> <20260205105704.GA245049@noisy.programming.kicks-ass.net> X-Original-From: Chuyi Zhou Subject: Re: [PATCH 05/11] smp: Enable preemption early in smp_call_function_many_cond Hi Peter, =E5=9C=A8 2026/2/5 18:57, Peter Zijlstra =E5=86=99=E9=81=93: > On Thu, Feb 05, 2026 at 10:52:36AM +0100, Peter Zijlstra wrote: >> On Tue, Feb 03, 2026 at 07:23:55PM +0800, Chuyi Zhou wrote: >> >>> + /* >>> + * Prevent the current CPU from going offline. >>> + * Being migrated to another CPU and calling csd_lock_wait() may caus= e >>> + * UAF due to smpcfd_dead_cpu() during the current CPU offline proces= s. >>> + */ >>> + migrate_disable(); >> >> This is horrible crap. migrate_disable() is *NOT* supposed to be used to >> serialize cpu hotplug. >=20 > This was too complicated or something? >=20 Now most callers of smp_call*() explicitly use preempt_disable(). IIUC,=20 if we want to use cpus_read_lock(), we first need to clean up all these=20 preempt_disable() calls. Maybe a stupid question: Why can't migrate_disable prevent CPU removal? Before takedown_cpu(), all tasks need to be migrated to other CPUs, and=20 all kthreads on that CPU must be parked, except the stopper thread and=20 the hotplug thread. > --- a/kernel/smp.c > +++ b/kernel/smp.c > @@ -802,19 +802,20 @@ static void smp_call_function_many_cond( > unsigned int scf_flags, > smp_cond_func_t cond_func) > { > - int cpu, last_cpu, this_cpu =3D smp_processor_id(); > - struct call_function_data *cfd; > + struct call_function_data *cfd =3D this_cpu_ptr(&cfd_data); > + struct cpumask *cpumask =3D cfd->cpumask; > bool wait =3D scf_flags & SCF_WAIT; > - bool preemptible_wait =3D true; > cpumask_var_t cpumask_stack; > - struct cpumask *cpumask; > + int cpu, last_cpu, this_cpu; > int nr_cpus =3D 0; > bool run_remote =3D false; > =20 > - lockdep_assert_preemption_disabled(); > + if (wait && !alloc_cpumask_var(&cpumask_stack, GFP_ATOMIC)) > + cpumask =3D cpumask_stack; > =20 > - if (!alloc_cpumask_var(&cpumask_stack, GFP_ATOMIC)) > - preemptible_wait =3D false; > + cpus_read_lock(); > + preempt_disable(); > + this_cpu =3D smp_processor_id(); > =20 > /* > * Can deadlock when called with interrupts disabled. > @@ -836,10 +837,6 @@ static void smp_call_function_many_cond( > =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 =3D preemptible_wait ? cpumask_stack : cfd->cpumask; > - > cpumask_and(cpumask, mask, cpu_online_mask); > __cpumask_clear_cpu(this_cpu, cpumask); > =20 > @@ -897,6 +894,7 @@ static void smp_call_function_many_cond( > csd_do_func(func, info, NULL); > local_irq_restore(flags); > } > + preempt_enable(); > =20 > if (run_remote && wait) { > for_each_cpu(cpu, cpumask) { > @@ -907,8 +905,8 @@ static void smp_call_function_many_cond( > } > } > =20 > - if (preemptible_wait) > - free_cpumask_var(cpumask_stack); > + cpus_read_unlock(); > + free_cpumask_var(cpumask_stack); > } > =20 > /**