From: David Hildenbrand <david@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Vincent Donnefort <vdonnefort@google.com>
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
mathieu.desnoyers@efficios.com, kernel-team@android.com,
rdunlap@infradead.org, rppt@kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v22 2/5] ring-buffer: Introducing ring-buffer mapping functions
Date: Fri, 10 May 2024 11:19:21 +0200 [thread overview]
Message-ID: <cc719813-ba73-461f-8b45-4728f926c151@redhat.com> (raw)
In-Reply-To: <20240507223402.206d6ddc@rorschach.local.home>
On 08.05.24 04:34, Steven Rostedt wrote:
> On Tue, 30 Apr 2024 12:13:51 +0100
> Vincent Donnefort <vdonnefort@google.com> wrote:
>
>> +#ifdef CONFIG_MMU
>> +static int __rb_map_vma(struct ring_buffer_per_cpu *cpu_buffer,
>> + struct vm_area_struct *vma)
>> +{
>> + unsigned long nr_subbufs, nr_pages, vma_pages, pgoff = vma->vm_pgoff;
>> + unsigned int subbuf_pages, subbuf_order;
>> + struct page **pages;
>> + int p = 0, s = 0;
>> + int err;
>> +
>> + /* Refuse MP_PRIVATE or writable mappings */
>> + if (vma->vm_flags & VM_WRITE || vma->vm_flags & VM_EXEC ||
>> + !(vma->vm_flags & VM_MAYSHARE))
>> + return -EPERM;
>> +
>> + /*
>> + * Make sure the mapping cannot become writable later. Also tell the VM
>> + * to not touch these pages (VM_DONTCOPY | VM_DONTEXPAND). Finally,
>> + * prevent migration, GUP and dump (VM_IO).
>> + */
>> + vm_flags_mod(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_IO, VM_MAYWRITE);
>
> Do we really need the VM_IO?
>
> When testing this in gdb, I would get:
>
> (gdb) p tmap->map->subbuf_size
> Cannot access memory at address 0x7ffff7fc2008
>
> It appears that you can't ptrace IO memory. When I removed that flag,
> gdb has no problem reading that memory.
>
> I think we should drop that flag.
>
> Can you send a v23 with that removed, Shuah's update, and also the
> change below:
>
>> +
>> + lockdep_assert_held(&cpu_buffer->mapping_lock);
>> +
>> + subbuf_order = cpu_buffer->buffer->subbuf_order;
>> + subbuf_pages = 1 << subbuf_order;
>> +
>> + nr_subbufs = cpu_buffer->nr_pages + 1; /* + reader-subbuf */
>> + nr_pages = ((nr_subbufs) << subbuf_order) - pgoff + 1; /* + meta-page */
>> +
>> + vma_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
>> + if (!vma_pages || vma_pages > nr_pages)
>> + return -EINVAL;
>> +
>> + nr_pages = vma_pages;
>> +
>> + pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
>> + if (!pages)
>> + return -ENOMEM;
>> +
>> + if (!pgoff) {
>> + pages[p++] = virt_to_page(cpu_buffer->meta_page);
>> +
>> + /*
>> + * TODO: Align sub-buffers on their size, once
>> + * vm_insert_pages() supports the zero-page.
>> + */
>> + } else {
>> + /* Skip the meta-page */
>> + pgoff--;
>> +
>> + if (pgoff % subbuf_pages) {
>> + err = -EINVAL;
>> + goto out;
>> + }
>> +
>> + s += pgoff / subbuf_pages;
>> + }
>> +
>> + while (s < nr_subbufs && p < nr_pages) {
>> + struct page *page = virt_to_page(cpu_buffer->subbuf_ids[s]);
>> + int off = 0;
>> +
>> + for (; off < (1 << (subbuf_order)); off++, page++) {
>> + if (p >= nr_pages)
>> + break;
>> +
>> + pages[p++] = page;
>> + }
>> + s++;
>> + }
>
> The above can be made to:
>
> while (p < nr_pages) {
> struct page *page;
> int off = 0;
>
> if (WARN_ON_ONCE(s >= nr_subbufs))
> break;
I'm not particularly happy about us calling vm_insert_pages with NULL
pointers stored in pages.
Should we instead do
if (WARN_ON_ONCE(s >= nr_subbufs)) {
err = -EINVAL;
goto out;
}
?
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2024-05-10 9:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 11:13 [PATCH v22 0/5] Introducing trace buffer mapping by user-space Vincent Donnefort
2024-04-30 11:13 ` [PATCH v22 1/5] ring-buffer: Allocate sub-buffers with __GFP_COMP Vincent Donnefort
2024-05-02 13:18 ` David Hildenbrand
2024-04-30 11:13 ` [PATCH v22 2/5] ring-buffer: Introducing ring-buffer mapping functions Vincent Donnefort
2024-05-02 13:30 ` David Hildenbrand
2024-05-02 13:38 ` Vincent Donnefort
2024-05-02 13:46 ` Steven Rostedt
2024-05-08 2:34 ` Steven Rostedt
2024-05-09 11:05 ` Vincent Donnefort
2024-05-10 9:15 ` David Hildenbrand
2024-05-10 10:57 ` Vincent Donnefort
2024-05-10 9:19 ` David Hildenbrand [this message]
2024-05-10 11:03 ` Vincent Donnefort
2024-05-10 18:42 ` Steven Rostedt
2024-04-30 11:13 ` [PATCH v22 3/5] tracing: Allow user-space mapping of the ring-buffer Vincent Donnefort
2024-04-30 11:13 ` [PATCH v22 4/5] Documentation: tracing: Add ring-buffer mapping Vincent Donnefort
2024-04-30 11:13 ` [PATCH v22 5/5] ring-buffer/selftest: Add ring-buffer mapping test Vincent Donnefort
2024-05-03 19:12 ` Shuah Khan
2024-05-07 23:35 ` Steven Rostedt
2024-05-10 11:04 ` Vincent Donnefort
2024-05-10 18:44 ` Steven Rostedt
2024-05-10 18:50 ` 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=cc719813-ba73-461f-8b45-4728f926c151@redhat.com \
--to=david@redhat.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--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).