From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-112.ptr.blmpb.com (va-1-112.ptr.blmpb.com [209.127.230.112]) (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 653F62D29B7 for ; Thu, 19 Mar 2026 07:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773906528; cv=none; b=U92j6josoVyaYAnkHi36KY2eGg7sFhmPCqLhLuZJT9YEj4t3NSXsl7FGRpLFR8p/EgGknkqythNOoxMPwrZrpsrgh8AfctOISAZPOmSdXUb8W/CIlzgGpDhdXv7sw0JEv2EiPUd1Oz9B+0vBfb/cywDCUIEQVViB2BOSSu/oQeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773906528; c=relaxed/simple; bh=I4ZtwVlLYmywPp/AbbvlHP0Ybf3o0zt8uv6LGslZzH0=; h=In-Reply-To:Subject:Message-Id:Mime-Version:References:From:Date: Content-Type:To:Cc; b=pIE2nO1seYToqEHt1X/iKk5lmJOT4VrXui1772jlVZBRS2YWaOZK/wJGRffjgzVXsZGG0f7gBjvXedw9gqH7R557duW271tmq9/8acGq3ATFxxqr8gVNHiuyqtrDX2LGotZBRGhIKcTbGmxxLYj4SdZOY5sAdFgXCKcT2G8qcBE= 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=oC6fhbvB; arc=none smtp.client-ip=209.127.230.112 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="oC6fhbvB" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1773906509; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=CnCLtwzy1fu+6+XIH9V3qbPEDGuAUGJlRxdOc4uIZcI=; b=oC6fhbvBfJ39/bSumXgvcgErEWbfUzdDnt7YhS2o6RKUNsQbo+Yl5c5H1ZwxgIvjh6V4qS SzP2BhVCZqgoAjUAuwWvPT9weifiO/VkUH+fEbpz9ozQalZjlsJNlNYsZTnG1ac8t6cnE0 3jlRP1BLYXn5QPYcAAeQ5r/V/gT0mx0wQHyHF+9jo/BsljXLsECB5RkyO5GQp0OYGoOidP Pm9fc9eFV9OqYeRrMPoGd0YYIanB5bszuFWiaIgNejY1dbGo+7O042O3ea58mrHLZNWwFk pKYCxpo7ZXM3Uvv9SHID7RRKSV8P7vdRTL2bd3sCyOULocBreTi/dicL3XDwsA== In-Reply-To: <20260318161928.jdoUolLo@linutronix.de> Subject: Re: [PATCH v3 05/12] smp: Free call_function_data via RCU in smpcfd_dead_cpu Message-Id: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260318045638.1572777-1-zhouchuyi@bytedance.com> <20260318045638.1572777-6-zhouchuyi@bytedance.com> <20260318161928.jdoUolLo@linutronix.de> User-Agent: Mozilla Thunderbird From: "Chuyi Zhou" X-Original-From: Chuyi Zhou Date: Thu, 19 Mar 2026 15:48:09 +0800 X-Lms-Return-Path: Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 To: "Sebastian Andrzej Siewior" Cc: , , , , , , , , , , , On 2026-03-19 12:19 a.m., Sebastian Andrzej Siewior wrote: > On 2026-03-18 12:56:31 [+0800], Chuyi Zhou wrote: >> Use rcu_read_lock() to protect csd in smp_call_function_many_cond() and >> wait for all read critical sections to exit before releasing percpu csd >> data. This is preparation for enabling preemption during csd_lock_wait() >> and can prevent accessing cfd->csd data that has already been freed in >> smpcfd_dead_cpu(). >> >> 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..32c293d8be0e 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 = &per_cpu(cfd_data, cpu); >> >> + synchronize_rcu(); >> free_cpumask_var(cfd->cpumask); >> free_cpumask_var(cfd->cpumask_ipi); >> free_percpu(cfd->csd); > > This seems to make sense. But it could delay CPU shutdown and then the > stress-cpu-hotplug.sh. And this one helped to find bugs. > > What is expectation of shutting down a CPU? Will it remain off for > _long_ at which point we care about this memory or is temporary and we > could skip to free the memory here because we allocate it only once on > the UP side? > Yes, we can allocate the csd only once during the first UP side. The advantage is that it avoids delaying the CPU offline process and keeps the code simpler. The tradeoff is a slight memory waste in scenarios where the CPU remains offline for a long time(or never online again). If we cannot tolerate the delay caused by synchronize_rcu() during the CPU offline process, we can switch to approach you suggested. Thanks. > Sebastian