From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8C4703F4DC0 for ; Fri, 26 Jun 2026 14:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782484356; cv=none; b=UwxINmefImCrFSexOcLx1t6QZ/fFMGyscxEwj+8rdeTyMw0wTlor2vVnBCcIT6PyyQ7IVzHDTjlNY2KwdhhsCq7zNrOr0eymcJwGokj8kHn8saZMJm28ig2ZUjKiO9L3EJ3OtClEWDYpuFt++u+L+MCUfJacL3XHPd/2cb/afkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782484356; c=relaxed/simple; bh=Em25qRWpNLxIfkEhuQ/LtwQt4IMuLu6IUqNJ0Seknfk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=BsR2eKGGIO3FEHemkEVv/0hCPLHQZvXV53C0VdXGWvAtpaSlLj7php0KKqsP7OwG/q3rktIeUttMcr1h2UMH1iMr9AIy46iTTWM0gGmIGoEELfwfGH7yZxhh6wx+KyvaAh0RzFgXKEZB6gfIa5KH35JRe/16OwDCnOWzWNqnbRo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GdHmsxmI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GdHmsxmI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B31791F000E9; Fri, 26 Jun 2026 14:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1782484355; bh=F3hm0zeAG5Qa8NG39wgl2nC4iu1aJyJvU/jWL98beCw=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=GdHmsxmIAMBlwg9JlGCDNWz2OuhKbz8HmThc22AQXznvjUk0v6zh7PYvkcwMB6c8V uvqPU3eonDbXlmgQEW3GnY4TBmemmq7mwukeTkVfQ+HKokszDs+jNTtnLP0sNcVUC8 3qAf9/jPYjiKtNtVoeRWcEE0AGXai6phsekciv4Wcyd8bxlf+xcv1lU6GHsVElHLUx n1W4dELId28K07eaYNEnseWisaNpbwQbkJ/oIVgKCyavqo3HPFpAmR+ZKK2z0X9cyC ygClcvJZTmMPLqPkdlfoXkNw7ANi6xWPEm0kGBGWcf7q/K06ocnkiLXaEB0RPutkVb 9UMCxfisvhDNA== From: Thomas Gleixner To: Chuyi Zhou , mingo@redhat.com, luto@kernel.org, peterz@infradead.org, paulmck@kernel.org, muchun.song@linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, pbonzini@redhat.com, bigeasy@linutronix.de, clrkwllms@kernel.org, rostedt@goodmis.org, nadav.amit@gmail.com, vkuznets@redhat.com Cc: linux-kernel@vger.kernel.org, Chuyi Zhou Subject: Re: [PATCH v8 05/14] smp: Alloc percpu csd data in smpcfd_prepare_cpu() only once In-Reply-To: <20260616111127.966468-6-zhouchuyi@bytedance.com> References: <20260616111127.966468-1-zhouchuyi@bytedance.com> <20260616111127.966468-6-zhouchuyi@bytedance.com> Date: Fri, 26 Jun 2026 16:32:32 +0200 Message-ID: <87y0g1id8f.ffs@fw13> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Tue, Jun 16 2026 at 19:11, Chuyi Zhou wrote: > Later patch would enable preemption during csd_lock_wait() in > smp_call_function_many_cond(), which may cause access cfd->csd data that > has already been freed in smpcfd_dead_cpu(). > > One way to fix the above issue is to use the RCU mechanism to protect the > csd data and wait for all read critical sections to exit before freeing > the memory in smpcfd_dead_cpu(), but this could delay CPU shutdown. This > patch chooses a simpler approach: allocate the percpu csd on the UP side > only once and skip freeing the csd memory in smpcfd_dead_cpu(). See earlier comments about change logs. > - cfd->csd = alloc_percpu(call_single_data_t); > + > + /* > + * The percpu csd is allocated only once and never freed. > + * This ensures that smp_call_function_many_cond() can safely > + * access the csd of an offlined CPU if it gets preempted > + * during csd_lock_wait(). I know what you are trying to say, but that sentence does not parse. Allocate the per CPU csd at the first time a CPU comes up. It's not freed when the CPU is offlined. That ensures that the per CPU CSD can be accessed from csd_lock_wait() even when the CPU was offlined after preemption was reenabled before invoking it. Or something like that.