On Mon, Feb 05, 2024 at 01:44:47PM -0500, Mathieu Desnoyers wrote: > On 2024-02-05 13:34, Vincent Donnefort wrote: > > On Mon, Feb 05, 2024 at 11:55:08AM -0500, Mathieu Desnoyers wrote: > [...] > > > > > > > How are the kernel linear mapping and the userspace mapping made coherent > > > on architectures with virtually aliasing data caches ? > > > > > > Ref. > > > https://lore.kernel.org/lkml/20240202210019.88022-1-mathieu.desnoy...@efficios.com/T/#t > > > > Hi Mathieu, > > > > Thanks for the pointer. > > > > We are in the exact same problem as DAX. We do modify the data through the > > kernel linear mapping while user-space can read it through its own. I should > > probably return an error when used with any of the arch ARM || SPARC || > > MIPS, > > until cpu_dcache_is_aliasing() introduces a fine-grain differentiation. > > You might want to use LTTng's ring buffer approach instead. See > > https://github.com/lttng/lttng-modules/blob/master/src/lib/ringbuffer/ring_buffer_frontend.c#L1202 > > lib_ring_buffer_flush_read_subbuf_dcache()
Thanks! > > Basically, whenever user-space grabs a sub-buffer for reading (through > lttng-modules's LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF ioctl), lttng > calls flush_dcache_page() on all pages of this subbuffer (I should > really change this for a call to flush_dcache_folio() which would be > more efficient). > > Note that doing this is not very efficient on architectures which have > coherent data caches and incoherent dcache vs icache: in that case, > we issue the flush_dcache_page uselessly. I plan on using the new > cpu_dcache_is_aliasing() check once/if it makes it way upstream to > remove those useless flushes on architectures which define > ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE, but do not virtually alias the > data cache. I believe the aim is to use the mapping by default in libtracefs and fallback to splice whenever not available... But for those arch, I guess that might be a mistake. Wonder if then it isn't just better to return ENOTSUPP? > > The equivalent of LTTng's "get subbuf" operation would be > the new TRACE_MMAP_IOCTL_GET_READER ioctl in ftrace AFAIU. That is correct! > > Thanks, > > Mathieu > > -- > Mathieu Desnoyers > EfficiOS Inc. > https://www.efficios.com >