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=1796381195; b=WtDQEp2od9UpmsCJ5+OpJemXBY/HxLa0jBrPveonlIXzp8KUTI7SCClt2tgK3s93Aqrm 1ly5tX3XrkofjtlkIGRQ/ghn/wvhnBGD2chK+CZS87CbsFgqzncknTAtlEMbI7wqpO1Et QD8z/Jz3DdBgpsCz+zl7+GzF+u9pEq3XirrtF/GvGEBZmhIfN7b8jEpmAJcgp18Zlp8ai YHJw18emxXCXiaknGHYM5LBwQ9lHmNkXEzV4hY6XAwHeOBLQ6IMtkz8mYJQ3cXI7G5KH7 dSMprcRJXCC7TByWBN7BjnTDl4bJjhekbH1zGYllKG+Dicb6L5n7/GOKQ4NaNrwDJcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381195; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=QGluqYh6wGAnin7R5InWAVYu+ZQuufiI36c2F2OfXTs=; b=P6TdzgPJ7n2kwa2VBuno90HM4UzVexLxzrq5F58FG+QRjN2JkcgVuXsNVq/n1I9BjU1Y SyMlKXJ1PGIYcGzAfu52RtK27t1JlU4KpsPeUyQym9l29irHGSzM+sTQzeqHmJrF0q6IM 7rqnGdFFPIpuF9zjywOp42QxHY80CabrYpJUk2qad/3Sdiuo1Fo+Spek8IosGGi24cVb1 D79h/vXezEDbGD+nYNwW+14z0sO/DkVfMb7KK+LkPDvXCG7pmF2w1jXMYw1Vn8x5G8m+m hirvbMzbg+fww2ssN4LTYiFwNKtYM4otHlwnReKyyuVRvJ4Z4f5heotTEzaHuHao6hg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=P1VI7aDq; 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 950AC606A322; Fri, 4 Dec 2026 10:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=P1VI7aDq Received: by smtp.kernel.org (Postfix) with ESMTPSA id B536C1F000C2; Fri, 4 Dec 2026 10:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381195; bh=QGluqYh6wGAnin7R5InWAVYu+ZQuufiI36c2F2OfXTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P1VI7aDqoMNfLrLNApEiaRlZ5VSrjAXc5ZtHaqrgUGx+xA6mF/VPsCvKKVObRd226 NNPuVZ15dKZzObqchPuFkT69brI/UveAD0ZRVe3P2y9r/oOy6Tks4J5dqy9rOfElUP IJWYo6FfzYi2i1aT3mytqxSexM9Kh3qg8FTL/Oow= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Michal=20Such=C3=A1nek?= , Vincent Donnefort , Amit Machhiwal , Steven Rostedt Subject: [PATCH 7.3 573/742] ring-buffer: Do not check si_mem_available() before deferred init completes Date: Fri, 4 Dec 2026 19:07:17 +0900 Message-ID: <20261204100650.360194392@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev 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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amit Machhiwal commit abf7185109d3986c1f945641d2fb20e44527f7c6 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ring_buffer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -2463,8 +2463,17 @@ static int __rb_allocate_pages(struct ri * 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 << subbuf_order)) return -ENOMEM;