mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 22:19:30 +02:00
tracing/remotes: Account for ring buffer page header in size calculation
trace_buffer_desc_size() and trace_remote_alloc_buffer() undercount the
required pages because every ring buffer page contains a header
(BUF_PAGE_HDR_SIZE). Account for that header to ensure allocated remote
ring buffers aren't smaller than requested by the user.
The newly introduced helper __calc_nr_pages_ring_buffer_desc() can
return a value that overflows the descriptor nr_pages field (32 bits).
Link: https://patch.msgid.link/20260911193937.602202-2-vdonnefort@google.com
Fixes: 2e67fabd8b ("ring-buffer: Introduce ring-buffer remotes")
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
This commit is contained in:
committed by
Steven Rostedt
parent
bcfe2816e6
commit
442ffa742d
@@ -3,8 +3,9 @@
|
||||
#define _LINUX_RING_BUFFER_H
|
||||
|
||||
#include <linux/mm.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/poll.h>
|
||||
#include <linux/ring_buffer_types.h>
|
||||
#include <linux/seq_file.h>
|
||||
|
||||
#include <uapi/linux/trace_mmap.h>
|
||||
|
||||
@@ -279,9 +280,19 @@ static inline struct ring_buffer_desc *__first_ring_buffer_desc(struct trace_buf
|
||||
return (struct ring_buffer_desc *)(&desc->__data[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the number of pages for a ring_buffer_desc. The caller must ensure it
|
||||
* does not overflow ring_buffer_desc::nr_page_va.
|
||||
*/
|
||||
static inline unsigned long __calc_nr_pages_ring_buffer_desc(size_t size)
|
||||
{
|
||||
/* Takes into account the reader page */
|
||||
return max(DIV_ROUND_UP(size, PAGE_SIZE - BUF_PAGE_HDR_SIZE), 2UL) + 1;
|
||||
}
|
||||
|
||||
static inline size_t trace_buffer_desc_size(size_t buffer_size, unsigned int nr_cpus)
|
||||
{
|
||||
unsigned int nr_pages = max(DIV_ROUND_UP(buffer_size, PAGE_SIZE), 2UL) + 1;
|
||||
unsigned long nr_pages = __calc_nr_pages_ring_buffer_desc(buffer_size);
|
||||
struct ring_buffer_desc *rbdesc;
|
||||
|
||||
return size_add(offsetof(struct trace_buffer_desc, __data),
|
||||
|
||||
@@ -980,7 +980,7 @@ int trace_remote_alloc_buffer(struct trace_buffer_desc *desc, size_t desc_size,
|
||||
const struct cpumask *cpumask)
|
||||
{
|
||||
size_t min_desc_size = trace_buffer_desc_size(buffer_size, cpumask_weight(cpumask));
|
||||
unsigned int nr_pages = max(DIV_ROUND_UP(buffer_size, PAGE_SIZE), 2UL) + 1;
|
||||
unsigned int nr_pages = __calc_nr_pages_ring_buffer_desc(buffer_size);
|
||||
struct ring_buffer_desc *rb_desc;
|
||||
int cpu, ret = -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user