From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796358825; b=R37m9iHY8XoaZw/M5WBc+gCjYAhFHMQaFGEZEYspsabxopvAautc893qZtS9ZDIN1q9G xG9J9c17swa71RNOdrJjBxDciyEnd0F5g/P/iEwcuZsu5Y4wM3nlbT7wj0Nl2ml1x43O0 WVoUQNy6NimstKx5QXXMeNpgfneaBVbByNBiA9dmor2AOa7kwIDsOSWZjHoL0tLmsVio5 +/9kpjV63CVwCyecy9AKEOybtq2O0wtRgkdfKTqlTixnjIYTOwqwuRo5B0/dUMJ4nHmsU 6nmYxqpIKaKdxJrG0I1+eVpUphSJvO8bECV46GAXFbVg9vsyhuAYiDQMPBED97oiEww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796358825; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=MOA14gyldLeEUhffRlluj8URhitey68uitfMoYqJaPI=; b=AKfRcvSrd7P8CjUMC209BPllWjfQzDxp0vSST8B77PPZDz13OrVUTphxDMz2zYaG82DG Z4eekkjuuQB91R2p1DRFjjFTbudfh8qATZv2Fka3e1u6fuThcp9x4hFh0ElKr81DfGUK0 8i0ufjh1H7LdiH7elymRtsq9mKvCIc8QDLcbneL4PEVhSLX3K+G9L9F5Tjv4blEqn9W4Z WvtJYUP8se0PBj1MChmd9fOrTEv9p8lWelC0WU4tymKId+29MEzl+jqphRIFIgAGe2+XB 04VKgdNbBWCgWDsgk+xiUSwVxdeDkHf8QKJqcKxulVQHaLow4RCwxZxE0TKXJaHRLng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QudTLQUi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBE98606A6BB for ; Fri, 4 Dec 2026 04:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QudTLQUi Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF48B1F00A0A; Fri, 4 Dec 2026 04:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796358825; bh=MOA14gyldLeEUhffRlluj8URhitey68uitfMoYqJaPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QudTLQUi6SxdvO8ejAo5EUkwQwKWrpA9vfoJLm27HIwL0ithAB4srKfMLuwvGFEvr gmQIgLiExk10d5PqEEWMo+JaLJGF8eQIq8kqjxKBkgEjUsKks/qWs7C8cziDIfinbq 5aquD+STj4xACYIRGIuSLAtwiepiCeHaaKDvYhgMkm1zT9J9L+/nL1/xrDUDBToSwB iYyEu2S2xyRHaJU5VeFWa9IHmIrphnWUoiULjTNiBk5nWlgc6Huo3kExNnzKEmSQs8 ng+FSCW5lEq9XM18JliRYFTEqn8MN9kVmKmcpYAouNfuWEE0jUZoxa7V9D0DQaq3ha eZfKD3UGG3qeA== From: Sasha Levin To: stable@vger.kernel.org Cc: Amit Machhiwal , =?UTF-8?q?Michal=20Such=C3=A1nek?= , Vincent Donnefort , Steven Rostedt , Sasha Levin Subject: [PATCH 6.6.y] ring-buffer: Do not check si_mem_available() before deferred init completes Date: Thu, 3 Dec 2026 23:33:43 -0500 Message-ID: <20261204043315.2627195-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120217-sierra-gamma-ce10@gregkh> References: <2026120217-sierra-gamma-ce10@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Amit Machhiwal [ Upstream commit abf7185109d3986c1f945641d2fb20e44527f7c6 ] With CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only about one memory section per node is initialized early in boot (16 MiB on powerpc). The rest is initialized on demand by deferred_grow_zone() when an allocation would otherwise fail, or later by page_alloc_init_late(). Until then NR_FREE_PAGES can be close to zero, because early allocations (SLUB, vmalloc, ftrace records) use up the first section. si_mem_available() is derived from NR_FREE_PAGES, so it under-reports. __rb_allocate_pages() returns -ENOMEM when si_mem_available() is below the requested size. This check wrongly fails the buffers allocated for the boot CPU in early_trace_init() and for secondary CPUs in smp_init(), both of which run before page_alloc_init_late(). The resulting boot log shows: ERROR: Failed to allocate trace buffer ERROR: tracer: failed to allocate ring buffer! Skip the check until SYSTEM_FREEING_INITMEM on CONFIG_DEFERRED_STRUCT_PAGE_INIT kernels. The allocation itself still fails if memory really is short. This is the second half of the fix for the early boot crash reported on ppc64le KVM guests. Commit b3b974008388 ("tracing: Do not initialize tracefs work if tracing is disabled") stopped the NULL pointer dereference in __find_event_file() that followed the failed allocation. This patch fixes the allocation failure itself. Cc: stable@vger.kernel.org Fixes: 2a872fa4e9c8 ("ring-buffer: Check if memory is available before allocation") Link: https://patch.msgid.link/20261118183235.63310-1-amachhiw@linux.ibm.com Reported-by: Michal Suchánek Closes: https://lore.kernel.org/all/arYskzbiaNzBR9MD@kunlun.suse.cz/ Reviewed-by: Vincent Donnefort Signed-off-by: Amit Machhiwal Signed-off-by: Steven Rostedt [ sashal: Adapted the hunk to an older __rb_allocate_pages() that compares si_mem_available() against nr_pages directly (no subbuf order shift), so the added check sits at a different indentation and context. ] Signed-off-by: Sasha Levin --- kernel/trace/ring_buffer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 28e23cd1341f0..046133424ab43 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -1636,8 +1636,17 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer, * memory. It may not be accurate. But we don't care, we just want * to prevent doing any allocation when it is obvious that it is * not going to succeed. + * + * With CONFIG_DEFERRED_STRUCT_PAGE_INIT, si_mem_available() + * will reflect the actual available memory only after + * SYSTEM_FREEING_INITMEM. */ - i = si_mem_available(); + if (IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT) && + unlikely(system_state < SYSTEM_FREEING_INITMEM)) + i = LONG_MAX; + else + i = si_mem_available(); + if (i < nr_pages) return -ENOMEM; -- 2.53.0