[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250331210245.585fff23@gandalf.local.home>
Date: Mon, 31 Mar 2025 21:02:45 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Jann Horn <jannh@...gle.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org, Masami
Hiramatsu <mhiramat@...nel.org>, Mark Rutland <mark.rutland@....com>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>, Andrew Morton
<akpm@...ux-foundation.org>, Vincent Donnefort <vdonnefort@...gle.com>,
Vlastimil Babka <vbabka@...e.cz>, Mike Rapoport <rppt@...nel.org>, Kees
Cook <kees@...nel.org>, Tony Luck <tony.luck@...el.com>, "Guilherme G.
Piccoli" <gpiccoli@...lia.com>, linux-hardening@...r.kernel.org, Matthew
Wilcox <willy@...radead.org>
Subject: Re: [PATCH v2 1/2] tracing: ring-buffer: Have the ring buffer code
do the vmap of physical memory
On Tue, 1 Apr 2025 02:09:10 +0200
Jann Horn <jannh@...gle.com> wrote:
> On Tue, Apr 1, 2025 at 1:41 AM Steven Rostedt <rostedt@...dmis.org> wrote:
> > On Mon, 31 Mar 2025 14:42:38 -0700
> > Linus Torvalds <torvalds@...ux-foundation.org> wrote:
> >
> > > .. and *after* you've given it back to the memory allocator, and it
> > > gets allocated using the page allocators, at that point ahead and use
> > > 'struct page' as much as you want.
> > >
> > > Before that, don't. Even if it might work. Because you didn't allocate
> > > it as a struct page, and for all you know it might be treated as a
> > > different hotplug memory zone or whatever when given back.
> >
> > Hmm, so if we need to map this memory to user space memory, then I can't
> > use the method from this patch series, if I have to avoid struct page.
> >
> > Should I then be using vm_iomap_memory() passing in the physical address?
>
> For mapping random physical memory ranges into userspace, we have
> helpers like remap_pfn_range() (the easy option, for use in an mmap
> handler, in case you want to want to map one contiguous physical
> region into userspace) and vmf_insert_pfn() (for use in a page fault
> handler, in case you want to map random physical pages into userspace
> on demand).
Note, I believe that Linus brought up the issue that because this physical
memory is not currently part of the memory allocator (it's not aware of it
yet), that the getting struct page or a "pfn" for it may not be reliable.
>
> > As for architectures that do not have user/kernel data cache coherency, how
> > does one flush the page when there's an update on the kernel side so that
> > the user side doesn't see stale data?
>
> flush_kernel_vmap_range() (and invalidate_kernel_vmap_range() for the
> other direction) might be what you want... I found those by going
> backwards from an arch-specific cache-flushing implementation.
>
> > As the code currently uses flush_dcache_folio(), I'm guessing there's an
> > easy way to create a folio that points to physical memory that's not part
> > of the memory allocator?
>
> Creating your own folio structs sounds like a bad idea; folio structs
> are supposed to be in specific kernel memory regions. For example,
> conversions from folio* to physical address can involve pointer
> arithmetic on the folio*, or they can involve reading members of the
> pointed-to folio.
Linus already mentioned flush_cache_range() which looks to be the thing to
use.
-- Steve
Powered by blists - more mailing lists