FAILED: patch "[PATCH] ring-buffer: Prevent resizing of persistent ring buffer" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 7c727dfce6be04dd009b29091a4a17d952dbfe03
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026081709-tank-childcare-2caa@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7c727dfce6be04dd009b29091a4a17d952dbfe03 Mon Sep 17 00:00:00 2001
From: Vincent Donnefort <[email protected]>
Date: Thu, 6 Aug 2026 22:13:01 +0100
Subject: [PATCH] ring-buffer: Prevent resizing of persistent ring buffer
Dynamically resizing a persistent ring buffer is not possible. Disable the feature.
kernel/trace/ring_buffer.c +2 -0
@@ -2528,6 +2528,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)if (cpu_buffer->ring_meta->head_buffer)rb_meta_buffer_update (cpu_buffer, bpage); bpage->range =1 ; + +atomic_inc (&cpu_buffer->resize_disabled); }else if (buffer->remote) {struct ring_buffer_desc *desc =ring_buffer_desc (buffer->remote->desc, cpu);
Sasha Levin
maintainerPATCH 1/3 ring-buffer: Simplify ring_buffer_read_page() with guard()
From: Steven Rostedt <[email protected]>
[ Upstream commit b2e7c6ed26e90fab1e5e626071e54e3b9ec9cb5a ]
The function ring_buffer_read_page() had two gotos. One was simply returning "ret" and the other was unlocking the reader_lock.
There's no reason to use goto to simply return the "ret" variable. Instead just return the value.
The jump to the unlocking of the reader_lock can be replaced by guard(raw_spinlock_irqsave)(&cpu_buffer->reader_lock).
With these two changes the "ret" variable is no longer used and can be removed. The return value on non-error is what was read and is stored in the "read" variable.
Stable-dep-of: 7c727dfce6be ("ring-buffer: Prevent resizing of persistent ring buffer")
--- kernel/trace/ring_buffer.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
kernel/trace/ring_buffer.c +11 -17
@@ -6483,38 +6483,37 @@ int ring_buffer_read_page(struct trace_buffer *buffer,struct buffer_data_page *bpage;struct buffer_page *reader;unsigned long missed_events; -unsigned long flags;unsigned int commit;unsigned int read;u64 save_timestamp; -int ret =-1 ;if (!cpumask_test_cpu (cpu, buffer->cpumask)) - goto out; +return -1 ;/* * If len is not big enough to hold the page header, then * we can not copy anything. */ if (len <=BUF_PAGE_HDR_SIZE ) - goto out; +return -1 ; len -=BUF_PAGE_HDR_SIZE ;if (!data_page || !data_page->data) - goto out; +return -1 ; +if (data_page->order != buffer->subbuf_order) - goto out; +return -1 ; bpage = data_page->data;if (!bpage) - goto out; +return -1 ; -raw_spin_lock_irqsave (&cpu_buffer->reader_lock, flags); +guard (raw_spinlock_irqsave)(&cpu_buffer->reader_lock); reader =rb_get_reader_page (cpu_buffer);if (!reader) - goto out_unlock; +return -1 ; event =rb_reader_event (cpu_buffer);
@@ -6548,7 +6547,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer,if (full && (!read || (len < (commit - read)) || cpu_buffer->reader_page == cpu_buffer->commit_page)) - goto out_unlock; +return -1 ;if (len > (commit - read)) len = (commit - read);
@@ -6557,7 +6556,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer, size =rb_event_ts_length (event);if (len < size) - goto out_unlock; +return -1 ;/* save the current timestamp, since the user will need it */ save_timestamp = cpu_buffer->read_stamp;
@@ -6615,7 +6614,6 @@ int ring_buffer_read_page(struct trace_buffer *buffer,if (reader->real_end)local_set (&bpage->commit, reader->real_end); } - ret = read; cpu_buffer->lost_events =0 ;
@@ -6642,11 +6640,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer,if (commit < buffer->subbuf_size)memset (&bpage->data[commit],0 , buffer->subbuf_size - commit); - out_unlock: -raw_spin_unlock_irqrestore (&cpu_buffer->reader_lock, flags); - - out: -return ret; +return read; }EXPORT_SYMBOL_GPL (ring_buffer_read_page);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 ring-buffer: Make ring_buffer_{un}map() simpler with guard(mutex)
From: Steven Rostedt <[email protected]>
[ Upstream commit 60bc720e10eac397b3adae975095df77bc368b88 ]
Convert the taking of the buffer->mutex and the cpu_buffer->mapping_lock over to guard(mutex) and simplify the ring_buffer_map() and ring_buffer_unmap() functions.
Stable-dep-of: 7c727dfce6be ("ring-buffer: Prevent resizing of persistent ring buffer")
--- kernel/trace/ring_buffer.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-)
kernel/trace/ring_buffer.c +11 -24
@@ -7105,36 +7105,34 @@ int ring_buffer_map(struct trace_buffer *buffer, int cpu, {struct ring_buffer_per_cpu *cpu_buffer;unsigned long flags, *subbuf_ids; -int err =0 ; +int err;if (!cpumask_test_cpu (cpu, buffer->cpumask))return -EINVAL ; cpu_buffer = buffer->buffers[cpu]; -mutex_lock (&cpu_buffer->mapping_lock); +guard (mutex)(&cpu_buffer->mapping_lock);if (cpu_buffer->user_mapped) { err =__rb_map_vma (cpu_buffer, vma);if (!err) err =__rb_inc_dec_mapped (cpu_buffer, true); -mutex_unlock (&cpu_buffer->mapping_lock);return err; }/* prevent another thread from changing buffer/sub-buffer sizes */ -mutex_lock (&buffer->mutex); +guard (mutex)(&buffer->mutex); err =rb_alloc_meta_page (cpu_buffer);if (err) - goto unlock; +return err;/* subbuf_ids include the reader while nr_pages does not */ subbuf_ids =kcalloc (cpu_buffer->nr_pages +1 ,sizeof (*subbuf_ids),GFP_KERNEL );if (!subbuf_ids) {rb_free_meta_page (cpu_buffer); - err = -ENOMEM ; - goto unlock; +return -ENOMEM ; }atomic_inc (&cpu_buffer->resize_disabled);
@@ -7162,11 +7160,7 @@ int ring_buffer_map(struct trace_buffer *buffer, int cpu,atomic_dec (&cpu_buffer->resize_disabled); } -unlock: -mutex_unlock (&buffer->mutex); -mutex_unlock (&cpu_buffer->mapping_lock); - -return err; +return 0 ; }/*
@@ -7194,24 +7188,22 @@ int ring_buffer_unmap(struct trace_buffer *buffer, int cpu) {struct ring_buffer_per_cpu *cpu_buffer;unsigned long flags; -int err =0 ;if (!cpumask_test_cpu (cpu, buffer->cpumask))return -EINVAL ; cpu_buffer = buffer->buffers[cpu]; -mutex_lock (&cpu_buffer->mapping_lock); +guard (mutex)(&cpu_buffer->mapping_lock);if (!cpu_buffer->user_mapped) { - err = -ENODEV ; - goto out; +return -ENODEV ; }else if (cpu_buffer->user_mapped >1 ) {__rb_inc_dec_mapped (cpu_buffer, false); - goto out; +return 0 ; } -mutex_lock (&buffer->mutex); +guard (mutex)(&buffer->mutex);raw_spin_lock_irqsave (&cpu_buffer->reader_lock, flags);/* This is the last user space mapping */
@@ -7226,12 +7218,7 @@ int ring_buffer_unmap(struct trace_buffer *buffer, int cpu)rb_free_meta_page (cpu_buffer);atomic_dec (&cpu_buffer->resize_disabled); -mutex_unlock (&buffer->mutex); - -out: -mutex_unlock (&cpu_buffer->mapping_lock); - -return err; +return 0 ; }int ring_buffer_map_get_reader (struct trace_buffer *buffer,int cpu)
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 ring-buffer: Prevent resizing of persistent ring buffer
In reply to Sasha LevinFrom: Vincent Donnefort <[email protected]>
[ Upstream commit 7c727dfce6be04dd009b29091a4a17d952dbfe03 ]
Dynamically resizing a persistent ring buffer is not possible. Disable the feature.
--- kernel/trace/ring_buffer.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/trace/ring_buffer.c +2 -0
@@ -2238,6 +2238,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)if (cpu_buffer->ring_meta->head_buffer)rb_meta_buffer_update (cpu_buffer, bpage); bpage->range =1 ; + +atomic_inc (&cpu_buffer->resize_disabled); }else { page = alloc_pages_node(cpu_to_node(cpu), GFP_KERNEL | __GFP_COMP | __GFP_ZERO,
Signature · 1 line
2.53.0