From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796053775; b=BxxktQFXIQJKcvVI00AkZ1vnHC6tvhr4KpAnUf0wBxnV1BiIW0Lz/t/5yy3LuE4Z5Uqj NklkjPBgTnEDz51C8VRTPgV4feI7n+2Nxk5gTZJa0RQq/o6VAO3lRzmLTQx/4+VUsHwn9 RRk5y4pFTk3QeDULf5a3YepHOOxziy07MHdTR3pSP9GKTm22FbCKyNLC75YXKypjUyiQG zifoLQLo9yztygPwoUKjo0c8biDDea8fnlyOdKci3tibY5KXI4wlZFscOzIXGf8f02M7v IPzdU0mj+502/ai2JY8S0xxnSFVa5L2vzL7/Ht1e0vZAxR7dujcpAENqbS++eteSHdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053775; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=yOQ+Vq8qq4XaYw+BSQ2DLVpCp3Epv9YY1Fw1ZQRjFGE=; b=seVbKgYEjAl7G6yrZGnhbjsKBMrAqsASghfUqvLyWfzngMc/ZTIYZcXMOsravynAypmi +h0wQtrvWiiPVpERNgpRtK0II5SSDvQGt796Rg8uvwnF30DF51Z00AAPBgU9SYISEPyN/ hKDD2dM+zOILk+pfkUkEa86OkWPrcNhPfH5xw9DftYpz6XhryOcOFcfchMuH2XWUTp6yB VunBw6RnPe+U78NDamBOtIlE6lmipPdzpSJio5ZuH3acvFp0KelhUs1yxMxPzJzR5mSFH f4JWL6DPc5Jyd8Rkg+4BrfB6gNMP14UbSuXzSsw/JxjrOnZ05rCByUDxaKMb2EpIzYg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=o3DVqvRC; arc=none smtp.remote-ip=209.85.221.51 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 212AC606A325 for ; Mon, 30 Nov 2026 15:49:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 212AC606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=o3DVqvRC Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-4c4b8e58c9aso972825f8f.0 for ; Mon, 30 Nov 2026 07:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796053773; x=1796658573; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=yOQ+Vq8qq4XaYw+BSQ2DLVpCp3Epv9YY1Fw1ZQRjFGE=; b=o3DVqvRCUJZeuY2SYmrf/tep2xDvmhwZdW066Rb/Hi8zU/PD1uvsftBcJ0yIApV+iS ArbWbb/fJu9HciMglFZga6OGkQnDOsgUnotXFviJnY/6r8PrrlbUO98Uxurva+/0BTm4 MyJ3Up8utiI4ssIBTSFGm2dKlJcli2ZD9IIYkLf2XP8U4b2aobvzsFEuvZoHzB7zqEno 7ioX754cczR2vi7ZwjMsTXN6InJ6+FD+jdWMOyyJ4Z0oFUMv3V0A92aPMPehKhUuOHBu /4XXliaBGLclyjXUkMzZGrJLbeyfOEOZtAgmEzMPHLcjS9wgmSQz5dKKsZzuG04QbpHq 08Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796053773; x=1796658573; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yOQ+Vq8qq4XaYw+BSQ2DLVpCp3Epv9YY1Fw1ZQRjFGE=; b=Ht1wppXQFgviz37HfpgN3ZppBYuKo/SqKX2TqaPsSDQtcykB9qS5SozsfqwbgFBk67 2bsY0OZAeOfMOUG/IcyhMM0Swj/S5SYol9CcOkiD23jIjK0piL28zZ9zEoMrDC8uo8Zp MYeT8BolApRLrlIoZSDMqpw34RECv2YT2ThfEcz8AIZ8oPzdsM6xGk7WNYZQQptPXnks u69iYOtL7zLzqjx0TLLblFyzkxoE3dfE+4OqMtJTs9q6fIvM4Do1GZdl53HLd95DZw+v n6z0x+GP6oPjlM3/8Hy0bNlDPGnhNBHfsC4/1dWtcRwBcjveqxJZ1K4r29l+5VhvZcFC 8Nrw== X-Forwarded-Encrypted: i=1; AL+hErG1HXBJRyoENzaytSmFqPDNQn9/Ql4x0q43Cb35x9uVzuJWuBiaqtu0RD/REWnJlSdroRUqK8N3FknObb5Dh18uUkA=@vger.kernel.org X-Gm-Message-State: APuU4Z9cbIe/tGDOMpWT2/XaTR8hIU0RU+acBeA4vyP6Kup/+gRfMccV zJDb4vtvpcLCwFr8hedxTBT+t+ScUBXBt7/HM3RuPPd7y7jcE9vxEK7VntCeiGBq5g== X-Gm-Gg: AZFdTZdMDchAX2sBpW6Rv5pNxaGGiQvHhtov1qwP09yBwFEV8irbrvqI6RQ2mJdwrk8 ylLrx0n85Z/37oVWCjqbqNtSKW45p81pZW7Ec9aEL6+Mp2jZ8ZDjluztUpahF2ZaxyvfI6gcAOh flrS0iqOTVNpg5X2GPZIzzeZ9U4V7Pbo8Ug9ul+dRtG5aFHl30+ktW7Plsy3LMfCKtC0Y1fyzOj IUwO/z1OvaO51c1OCN7B8F/UJG4Ugp6ULgZb2DGD72zdmFQYcgyQAWCBbLAtcXL7Jp9XHW56bio DkI2CG9OfFcETxARG2VXynyBj+5hXOqa9T7P1vRREX63S6Iw0h5uakfePHkWk/hNIWGBI2kcIqf 6/1Jdw6i84wqx9Jva/pfBDmqRuRC5El5wvjFaLB6n6zVc9NoP3ugnt61suGbLqu5RLziAH5VAgD b++aEj0bDwehsYhO9K9JgmDV1UjYccM+iTE0D8j+VxvKVrsxxyOkDiXzRe1n71819boy+ZI7pDw M4WmDxta62ddte1eyd52JzdZbX44xZC1NAjxPHWteuNdPm95+ljdgD4sk2BnB+z+xXDwnMWLU9u tU2TG8CPYIOsW+4utHT8n/Ma/V1toc5F429c6GzACrjltNkMh8FmZRSIFywFJ4ie24QngFaALtO yzZCz+KfCN8TqHeEPWjCCbA== X-Received: by 2002:a05:6000:26d0:b0:4a6:8012:197 with SMTP id ffacd0b85a97d-4ad5d5f9320mr68304118f8f.2.1796053772925; Mon, 30 Nov 2026 07:49:32 -0800 (PST) Received: from google.com (0.182.34.34.bc.googleusercontent.com. [34.34.182.0]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110ba3sm54262445f8f.35.2026.11.30.07.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 07:49:32 -0800 (PST) Date: Mon, 30 Nov 2026 15:49:28 +0000 From: Vincent Donnefort To: Shuai Liu <847807867@qq.com> Cc: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+008851bf625629489e75@syzkaller.appspotmail.com, sashiko-bot@kernel.org Subject: Re: [PATCH v3] ring-buffer: Reset per-CPU buffer state in ring_buffer_subbuf_order_set() Message-ID: References: X-Mailing-List: linux-trace-kernel@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=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Nov 09, 2026 at 05:12:22PM +0800, Shuai Liu wrote: > ring_buffer_subbuf_order_set() replaces every page of a ring buffer > with newly allocated empty pages when the sub-buffer order changes. > However, it does not reset the per-CPU accounting of the discarded > pages. The stale counters (pages_read, pages_touched, pages_lost, > entries, ...) continue to describe pages that no longer exist. > > A full waiter (e.g. poll on per_cpu/*/trace_pipe_raw with > buffer_percent set) then causes ring_buffer_nr_dirty_pages() to read > the stale accounting, and the invariant pages_read <= pages_touched - > pages_lost + 1 can be violated, which trips the WARN_ON_ONCE() there: > > WARNING: kernel/trace/ring_buffer.c:866 at ring_buffer_nr_dirty_pages > > Since the old pages are gone, the buffer state after swapping in the > new pages is equivalent to a freshly allocated buffer. Replace the > manual head/tail/commit page assignment and the rb_head_page_activate() > call with rb_reset_cpu(), which performs the same page setup and also > resets all per-CPU accounting. > > Verified on QEMU (x86_64, v7.4-rc2): enable sched_switch events, > partially consume trace_pipe, set buffer_subbuf_size_kb to 32, then > poll trace_pipe_raw with buffer_percent=50 while writing events. The > unpatched kernel triggers the WARN above, while the patched kernel > does not, and the per-CPU stats report a clean buffer after the order > change. > > Fixes: 8e7b58c27b3c ("ring-buffer: Just update the subbuffers when changing their allocation order") > Reported-by: syzbot+008851bf625629489e75@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=008851bf625629489e75 > Link: https://lore.kernel.org/linux-trace-kernel/6af009ed.4dd4714a.f8d02.000d.GAE@google.com/ > Signed-off-by: Shuai Liu <847807867@qq.com> Reviewed-by: Vincent Donnefort > --- > Changes in v2: > - Fix the Fixes tag: the stale per-CPU accounting was introduced by > 8e7b58c27b3c, not 2808e31ec12e5 which only added the interface stub > (Sashiko) > > Changes in v3: > - Drop unnecessary comment above rb_reset_cpu() (Vincent Donnefort) > > kernel/trace/ring_buffer.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c > index 75cd8df23c1b9..4437b8b926c11 100644 > --- a/kernel/trace/ring_buffer.c > +++ b/kernel/trace/ring_buffer.c > @@ -7548,10 +7548,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order) > list_del_init(&cpu_buffer->new_pages); > cpu_buffer->cnt++; > > - cpu_buffer->head_page > - = list_entry(cpu_buffer->pages, struct buffer_page, list); > - cpu_buffer->tail_page = cpu_buffer->commit_page = cpu_buffer->head_page; > - > cpu_buffer->nr_pages = cpu_buffer->nr_pages_to_update; > cpu_buffer->nr_pages_to_update = 0; > > @@ -7560,7 +7556,7 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order) > cpu_buffer->free_page.data = NULL; > arch_spin_unlock(&cpu_buffer->lock); > > - rb_head_page_activate(cpu_buffer); > + rb_reset_cpu(cpu_buffer); > > raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags); > > -- > 2.43.0 >