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 2222E264A97 for ; Tue, 10 Mar 2026 07:27:25 +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=1773127649; cv=none; b=n2OPLgbjfCqr2McncQqjkZ4Bzte+9zU/5Uz6pMWP8EXL4ZMI0QZPXldr5MDjE8+QfJkqsmaoH2QNszfMntF5V/TQCwTKzOQ3oFdi39dbmSKeK3QRxw8YhD7hjspuQCeLXk5Y5vQyeczmHqTHzlDa3ywuXwuvDA3tzwHBmj1fxx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773127649; c=relaxed/simple; bh=I/jK0j8dF2Ri2FYaaPCnFye75mJjA+7o+wpdcxHmAJ8=; h=In-Reply-To:To:Cc:Content-Type:From:Subject:References:Date: Message-Id:Mime-Version; b=aAsSlfUH9p+GdVl+AlebYQNtZaiNdtLY55P1jdX+3JicyLqAcR+ZcD/5jbA7YH6iN5HAFyO3a7C21JKrIQ1FhH4J4niR/izlka6ZUixxMKwmZNJpnSDBL2jMJo5YUWXOyT4bV2BMHsWtEcJxixKu1kOSN4XpIXqg9knNCX0wRH0= 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=nYj8nZlG; 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="nYj8nZlG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1773127602; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=Lq4nEIRbi5JwEblHalmo0rVLtQQFYsdBpaYuvPQJGZU=; b=nYj8nZlGTsdUuNJlatDfCaWHTnVCLjVC/FckeUnBF/9j5TKkwrO0ETcUYLGntZlsbR+CgX FdVkwNUM2Wum2x++rHapQrxhnZz63bCy2qOJtNiwF/ZLVDjSgxL9Ig4jzKdloY+lWTCOUq LLwK8jWPGKbehseb/C1fVcka+uzNxc9icz/OyOgdqrdAdAM00C42/TEPcR3uoLqZKltSCF DRfAMh0I9Dtyyrf52QNrsYY55a/ruFrPUO3nLmiDZqMI+GP6R/hc1DNU8zGcF27O1NlbyA QpAu8JY0X5OFgm7W0vzIZ1eT9AgOjqv7rUeySX67yQJfNPoSZbsgn3GZLsgzEw== In-Reply-To: <2A193780-53DC-469A-B770-8AA5B97C7D7E@linux.dev> To: "Muchun Song" Cc: , , , , , , , , , , , User-Agent: Mozilla Thunderbird Content-Type: text/plain; charset=UTF-8 X-Original-From: Chuyi Zhou From: "Chuyi Zhou" Subject: Re: [PATCH v2 05/12] smp: Free call_function_data via RCU in smpcfd_dead_cpu References: <20260302075216.2170675-1-zhouchuyi@bytedance.com> <20260302075216.2170675-6-zhouchuyi@bytedance.com> <2A193780-53DC-469A-B770-8AA5B97C7D7E@linux.dev> Content-Transfer-Encoding: quoted-printable Date: Tue, 10 Mar 2026 15:26:23 +0800 X-Lms-Return-Path: Message-Id: <1f7a8944-18c8-49f4-9ca8-3322b3db5d25@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Hi Muchun, =E5=9C=A8 2026/3/10 15:05, Muchun Song =E5=86=99=E9=81=93: >=20 >=20 >> On Mar 2, 2026, at 15:52, Chuyi Zhou wrote: >> >> Use rcu_read_lock to protect the hole scope of smp_call_function_many_co= nd > ^ > whole >=20 > BTW, The protection we often refer to actually pertains to data, not code= . > Therefore, the rcu_read_lock() here is actually preventing smp_call_funct= ion_many_cond() > from accessing percpu csd data that has already been freed (which is > what smpcfd_dead_cpu() does). >=20 OK. >> and wait for all read critical sections to exit before releasing percpu = csd >> data. This is a preparation for enabling preemption during csd_lock_wait= (). >> >> Signed-off-by: Chuyi Zhou >> --- >> kernel/smp.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/kernel/smp.c b/kernel/smp.c >> index 9728ba55944d..ad6073b71bbd 100644 >> --- a/kernel/smp.c >> +++ b/kernel/smp.c >> @@ -77,6 +77,7 @@ int smpcfd_dead_cpu(unsigned int cpu) >> { >> struct call_function_data *cfd =3D &per_cpu(cfd_data, cpu); >> >> + synchronize_rcu(); >> free_cpumask_var(cfd->cpumask); >> free_cpumask_var(cfd->cpumask_ipi); >> free_percpu(cfd->csd); >> @@ -810,6 +811,7 @@ static void smp_call_function_many_cond(const struct= cpumask *mask, >> >> lockdep_assert_preemption_disabled(); >> >> + rcu_read_lock(); >> cfd =3D this_cpu_ptr(&cfd_data); >> cpumask =3D cfd->cpumask; >> >> @@ -907,6 +909,7 @@ static void smp_call_function_many_cond(const struct= cpumask *mask, >> >> if (preemptible_wait) >> free_cpumask_var(cpumask_stack); >> + rcu_read_unlock(); >=20 > We could call rcu_read_unlock() before free_cpumask_var() above. I will update in the next version. Thanks. >=20 >> } >> >> /** >> --=20 >> 2.20.1 >