From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
Vincent Donnefort <vdonnefort@google.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Jann Horn <jannh@google.com>
Subject: [PATCH v3 0/5] ring-buffer: Allow persistent memory to be user space mmapped
Date: Tue, 01 Apr 2025 16:25:49 -0400 [thread overview]
Message-ID: <20250401202549.409271454@goodmis.org> (raw)
Now that I learned that the memory passed back from reserve_mem is part
of the memory allocator and just "reserved" and the memory is already
virtually mapped, it can simply use phys_to_virt() on the physical memory
that is returned to get the virtual mapping for that memory!
(Thanks Mike!)
That makes things much easier, especially since it means that the memory
returned by reserve_mem is no different than the memory retrieved by
page_alloc(). This allows that memory to be memory mapped to user space
no differently than it is mapped by the normal buffer.
This new series does the following:
- Enforce the memory mapping is page aligned (both the address and the
size). If not, it errors out.
- Use phys_to_virt() to get to the virtual memory from the reserve_mem
returned addresses. Also use free_reserved_area() to give it
back to the buddy allocator when it is freed.
- Treat the buffer allocated via memmap differently. It still needs to
be virtually mapped (cannot use phys_to_virt) and it must not be
freed nor memory mapped to user space. A new flag is added when a buffer
is created this way to prevent it from ever being memory mapped to user
space and the ref count is upped so that it can never be freed.
- Use vmap_page_range() instead of using kmalloc_array() to create an array
of struct pages for vmap().
- Use flush_kernel_vmap_range() instead of flush_dcache_folio()
- Allow the reserve_mem persistent ring buffer to be memory mapped.
There is no difference now with how the memory is mapped to user space,
only the accounting of what pages are mapped where is updated as
the meta data is different between the two.
Note, the first 4 patches makes the code a bit more correct. Especially
since the vunmap() does not give the buffer back to the buddy allocator.
I will be looking to get the first 4 patches into this merge window.
The last patch which enables he persistent memory mapping to user space can
wait till the 6.16.
Changes since v2: https://lore.kernel.org/all/20250331143426.947281958@goodmis.org/
- Basically a full rewrite once I found out that you can get the virtual
address of the memory returned by reserve_mem via phys_to_virt()!
Steven Rostedt (5):
tracing: Enforce the persistent ring buffer to be page aligned
tracing: Have reserve_mem use phys_to_virt() and separate from memmap buffer
tracing: Use vmap_page_range() to map memmap ring buffer
ring-buffer: Use flush_kernel_vmap_range() over flush_dcache_folio()
ring-buffer: Allow reserve_mem persistent ring buffers to be mmapped
----
Documentation/admin-guide/kernel-parameters.txt | 2 +
Documentation/trace/debugging.rst | 2 +
kernel/trace/ring_buffer.c | 54 ++++++++++++++++--
kernel/trace/trace.c | 75 ++++++++++++++++---------
kernel/trace/trace.h | 1 +
5 files changed, 102 insertions(+), 32 deletions(-)
next reply other threads:[~2025-04-01 20:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 20:25 Steven Rostedt [this message]
2025-04-01 20:25 ` [PATCH v3 1/5] tracing: Enforce the persistent ring buffer to be page aligned Steven Rostedt
2025-04-01 20:25 ` [PATCH v3 2/5] tracing: Have reserve_mem use phys_to_virt() and separate from memmap buffer Steven Rostedt
2025-04-01 20:25 ` [PATCH v3 3/5] tracing: Use vmap_page_range() to map memmap ring buffer Steven Rostedt
2025-04-01 21:41 ` Steven Rostedt
2025-04-01 20:25 ` [PATCH v3 4/5] ring-buffer: Use flush_kernel_vmap_range() over flush_dcache_folio() Steven Rostedt
2025-04-01 20:39 ` Steven Rostedt
2025-04-01 20:25 ` [PATCH v3 5/5] ring-buffer: Allow reserve_mem persistent ring buffers to be mmapped Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250401202549.409271454@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rppt@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
--cc=vdonnefort@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).