From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6525AC4345F for ; Wed, 17 Apr 2024 04:56:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2F896B0089; Wed, 17 Apr 2024 00:56:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DF7E6B008A; Wed, 17 Apr 2024 00:56:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A8486B008C; Wed, 17 Apr 2024 00:56:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6C9F56B0089 for ; Wed, 17 Apr 2024 00:56:38 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1E52BA16AF for ; Wed, 17 Apr 2024 04:56:38 +0000 (UTC) X-FDA: 82017813276.26.B87565F Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 6FCE8100007 for ; Wed, 17 Apr 2024 04:56:36 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NkYMqRX4; spf=pass (imf05.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713329796; a=rsa-sha256; cv=none; b=a27bjowTSevJwBiWJe7YO6UaNEgiTLnRCy1b7kCI7eFIBHZEx2TOO8P3W7bzdopaK5fUeo gVlbd3YImh58HQsvsJHa+G/4fcWyIvI5jHq28SkQzFS1UGZmdVUMau/hhVGq1yykz8s/Sj hX2y9CVYa26BNvO3XjQ2k9BxoZobeg4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NkYMqRX4; spf=pass (imf05.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713329796; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DC7wT6VZgKj9Bt3TwrkJAAYa2Si3U7XmYqtvDVopd1s=; b=Pe2hBWjPsKEyVriuT74Q2ZmYfXSsJGZ6o8yTvCD9+TWNsmAKau6Lh3igOjNooDAGC8OM1o wdIqczqSdH1LlJqe8ILtNav5R5/SdOH3FMa9B1TzkZRXavz9KYqLdw7rF+emeTO2KG7Qwf v6QIzbbA6PWeDtjpthnT4GUGF3presM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 481EB61126; Wed, 17 Apr 2024 04:56:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB4E5C072AA; Wed, 17 Apr 2024 04:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713329794; bh=BuZ8P8XoiIAM75OqFsQnPajzoPmLzP8HTuZmoXwmL78=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NkYMqRX4lxFl4iWw0gcq2nChoo1XR/daM/2LKLMu4C1jUMDgQo8tyhr2G7YUjhKdS pLuanq23TlmLnRE6dzcC/2cCNh14Yqo7L88QkiEX1F9hv8l1pwStoZ+rouh/CzhNtI NNON0hzCsUKBJj9TI0Dk6NIKjn7PwvJU47ZEomLcLk+T5rJZqeK2QlZPGOo1IsNYoF oXqKT6dxgjhtUGLq8ChmriPA53H09h3zXaNuQx30NVQu1Tn3D3o2yWH5IR6AmQyLhE r6sb0+maeAgcgaWLW4w1wRMOEQsutwcvfjlnAa2eit0pUXHGrrLXdl9l4jy0eKigSK EzeMlT+16fzwA== Date: Wed, 17 Apr 2024 07:55:23 +0300 From: Mike Rapoport To: Steven Rostedt Cc: Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Vincent Donnefort , 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, linux-mm@kvack.org Subject: Re: [PATCH v20 0/5] Introducing trace buffer mapping by user-space Message-ID: References: <20240406173649.3210836-1-vdonnefort@google.com> <20240410135612.5dc362e3@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240410135612.5dc362e3@gandalf.local.home> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6FCE8100007 X-Stat-Signature: 6rr61griu6shubj9he73jtak8z556ikp X-Rspam-User: X-HE-Tag: 1713329796-127483 X-HE-Meta: U2FsdGVkX1+48lKKJ1T63aY+bn1+Gs59I2V2xEvhyTOQzVTGop1b10qXNMbxYtC73MdCy8awhWoGmFOL5jGYkbYM34S5cXhPlPe47r4RAvI+slbJYK4Ec48j6chhBiYibMGS9WRq9qiwuZkwKiNIFY++h9j1wPZfW46SM1jOtvSF+jaHj1jYN5Rg0h02GdSr7ejkr1mp2fTjeFHvQ3XcAa4AB2tyiMmpRJlfyFvQps+ODB6MhxDlds/ziCZIljUr+qD18h38KCWoNlU5HmbbsPq4dSaW6FJK0neswNnSf2QTace9VlVO0W49rmC4jlBqwF0ZjkyHcAwDCisUMGBLVaLmcpFO12yFyQ4zRcqkCwFbDEFYG1CnBdbJ3BUMcG62Ddwm3U22YaJSUpPqd+rWVjFutG+qk5/RZYodCV2rL7hhdYmmPril+Bgmps+jOmXk37d1zruh8ZukGL+62xTqL6wZpsFTUaOq34tY+rIRY8ACHZ78nfiUw6LRyYRNy7Ri7J5ORci7rntYyk2xwUXX6Acij66Q5MV3KhFNtCm4Y0xCPvrQhZ/9JDoCro7cU+1fyJa9YmOn0wRHVuei61IHlCqy7YA8ZntIBR4BR14y6rTamE6gukLYlMIAmsoArK/SzGdhGDILk+4PgHr1XvJ7bJsj1lO9LgEHKb5mzwBpAUImhid0gOVEIgOlYmD9N4oUu9mO31qLLjqCnpwGx2zxchNLo7VHDB2uOWhD0qrwteSiIApDMX/PaW477Qu3pWhfoG88QC2pX1WMqnty5OGx4UwU16SpPHRnbMXsLZqYjT4ZjnChtnDn6XKgvkAmxrh2CeglWtOTQ6YRbDqGjrCsUdbVoaNIYbYKYlvVpkztqIEIm0oN7x9ajhr2EnvSIY1XIadLEjgTjNjNkjXkx8F0xlGsDqgOSnG98hrj8ro2150nJv2rnubhPM6cqiZYF974nEtzcoA8xVCB3CxSr6E jxpS6eJj zrMmcyzJD4E2Yuqb4MlLNZCm6KL7TU8bd+KvUB4d03EvKeQJ5vpck+CKlUZNlw4XG9x4OZwtNLv9HxteBnkVmfPBbJnVlxPqQLAtNjnb9RIBk38o3drbYbfvBczrWnMYugjKUa3uO3e4sEmYpeaxGS0ImT7NqmQ1ZiFD+p9h9pba+PFLMq1qIqgRKN4L+PyhDeUnN0T6bVcrdIgs0B/14KXvJ0uH0DLBM9wtTVUGnsPePNkWgxfh+MVpC3susTw6ONrEBRfUkjF3vdHmGABeps9fZiE1imEwdiovA3h9mX3QBWxenBEbRoAYU2bMD74cL6DfDxshmjJiRIsT/S+bWhR7U/qzYxH2guISHYIHXDdxTGyM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: (added linux-mm) On Wed, Apr 10, 2024 at 01:56:12PM -0400, Steven Rostedt wrote: > > Hi Andrew, et.al. > > Linus said it's a hard requirement that this code gets an Acked-by (or > Reviewed-by) from the memory sub-maintainers before he will accept it. > He was upset that we faulted in pages one at a time instead of mapping it > in one go: > > https://lore.kernel.org/all/CAHk-=wh5wWeib7+kVHpBVtUn7kx7GGadWqb5mW5FYTdewEfL=w@mail.gmail.com/ > > Could you take a look at patches 1-3 to make sure they look sane from a > memory management point of view? > > I really want this applied in the next merge window. > > Thanks! > > -- Steve > > > On Sat, 6 Apr 2024 18:36:44 +0100 > Vincent Donnefort wrote: > > > The tracing ring-buffers can be stored on disk or sent to network > > without any copy via splice. However the later doesn't allow real time > > processing of the traces. A solution is to give userspace direct access > > to the ring-buffer pages via a mapping. An application can now become a > > consumer of the ring-buffer, in a similar fashion to what trace_pipe > > offers. > > > > Support for this new feature can already be found in libtracefs from > > version 1.8, when built with EXTRA_CFLAGS=-DFORCE_MMAP_ENABLE. > > > > Vincent > > > > v19 -> v20: > > * Fix typos in documentation. > > * Remove useless mmap open and fault callbacks. > > * add mm.h include for vm_insert_pages > > > > v18 -> v19: > > * Use VM_PFNMAP and vm_insert_pages > > * Allocate ring-buffer subbufs with __GFP_COMP > > * Pad the meta-page with the zero-page to align on the subbuf_order > > * Extend the ring-buffer test with mmap() dedicated suite > > > > v17 -> v18: > > * Fix lockdep_assert_held > > * Fix spin_lock_init typo > > * Fix CONFIG_TRACER_MAX_TRACE typo > > > > v16 -> v17: > > * Documentation and comments improvements. > > * Create get/put_snapshot_map() for clearer code. > > * Replace kzalloc with kcalloc. > > * Fix -ENOMEM handling in rb_alloc_meta_page(). > > * Move flush(cpu_buffer->reader_page) behind the reader lock. > > * Move all inc/dec of cpu_buffer->mapped behind reader lock and buffer > > mutex. (removes READ_ONCE/WRITE_ONCE accesses). > > > > v15 -> v16: > > * Add comment for the dcache flush. > > * Remove now unnecessary WRITE_ONCE for the meta-page. > > > > v14 -> v15: > > * Add meta-page and reader-page flush. Intends to fix the mapping > > for VIVT and aliasing-VIPT data caches. > > * -EPERM on VM_EXEC. > > * Fix build warning !CONFIG_TRACER_MAX_TRACE. > > > > v13 -> v14: > > * All cpu_buffer->mapped readers use READ_ONCE (except for swap_cpu) > > * on unmap, sync meta-page teardown with the reader_lock instead of > > the synchronize_rcu. > > * Add a dedicated spinlock for trace_array ->snapshot and ->mapped. > > (intends to fix a lockdep issue) > > * Add kerneldoc for flags and Reserved fields. > > * Add kselftest for snapshot/map mutual exclusion. > > > > v12 -> v13: > > * Swap subbufs_{touched,lost} for Reserved fields. > > * Add a flag field in the meta-page. > > * Fix CONFIG_TRACER_MAX_TRACE. > > * Rebase on top of trace/urgent. > > * Add a comment for try_unregister_trigger() > > > > v11 -> v12: > > * Fix code sample mmap bug. > > * Add logging in sample code. > > * Reset tracer in selftest. > > * Add a refcount for the snapshot users. > > * Prevent mapping when there are snapshot users and vice versa. > > * Refine the meta-page. > > * Fix types in the meta-page. > > * Collect Reviewed-by. > > > > v10 -> v11: > > * Add Documentation and code sample. > > * Add a selftest. > > * Move all the update to the meta-page into a single > > rb_update_meta_page(). > > * rb_update_meta_page() is now called from > > ring_buffer_map_get_reader() to fix NOBLOCK callers. > > * kerneldoc for struct trace_meta_page. > > * Add a patch to zero all the ring-buffer allocations. > > > > v9 -> v10: > > * Refactor rb_update_meta_page() > > * In-loop declaration for foreach_subbuf_page() > > * Check for cpu_buffer->mapped overflow > > > > v8 -> v9: > > * Fix the unlock path in ring_buffer_map() > > * Fix cpu_buffer cast with rb_work_rq->is_cpu_buffer > > * Rebase on linux-trace/for-next (3cb3091138ca0921c4569bcf7ffa062519639b6a) > > > > v7 -> v8: > > * Drop the subbufs renaming into bpages > > * Use subbuf as a name when relevant > > > > v6 -> v7: > > * Rebase onto lore.kernel.org/lkml/20231215175502.106587604@goodmis.org/ > > * Support for subbufs > > * Rename subbufs into bpages > > > > v5 -> v6: > > * Rebase on next-20230802. > > * (unsigned long) -> (void *) cast for virt_to_page(). > > * Add a wait for the GET_READER_PAGE ioctl. > > * Move writer fields update (overrun/pages_lost/entries/pages_touched) > > in the irq_work. > > * Rearrange id in struct buffer_page. > > * Rearrange the meta-page. > > * ring_buffer_meta_page -> trace_buffer_meta_page. > > * Add meta_struct_len into the meta-page. > > > > v4 -> v5: > > * Trivial rebase onto 6.5-rc3 (previously 6.4-rc3) > > > > v3 -> v4: > > * Add to the meta-page: > > - pages_lost / pages_read (allow to compute how full is the > > ring-buffer) > > - read (allow to compute how many entries can be read) > > - A reader_page struct. > > * Rename ring_buffer_meta_header -> ring_buffer_meta > > * Rename ring_buffer_get_reader_page -> ring_buffer_map_get_reader_page > > * Properly consume events on ring_buffer_map_get_reader_page() with > > rb_advance_reader(). > > > > v2 -> v3: > > * Remove data page list (for non-consuming read) > > ** Implies removing order > 0 meta-page > > * Add a new meta page field ->read > > * Rename ring_buffer_meta_page_header into ring_buffer_meta_header > > > > v1 -> v2: > > * Hide data_pages from the userspace struct > > * Fix META_PAGE_MAX_PAGES > > * Support for order > 0 meta-page > > * Add missing page->mapping. > > > > Vincent Donnefort (5): > > ring-buffer: allocate sub-buffers with __GFP_COMP > > ring-buffer: Introducing ring-buffer mapping functions > > tracing: Allow user-space mapping of the ring-buffer > > Documentation: tracing: Add ring-buffer mapping > > ring-buffer/selftest: Add ring-buffer mapping test > > > > Documentation/trace/index.rst | 1 + > > Documentation/trace/ring-buffer-map.rst | 106 +++++ > > include/linux/ring_buffer.h | 6 + > > include/uapi/linux/trace_mmap.h | 48 +++ > > kernel/trace/ring_buffer.c | 403 +++++++++++++++++- > > kernel/trace/trace.c | 113 ++++- > > kernel/trace/trace.h | 1 + > > tools/testing/selftests/ring-buffer/Makefile | 8 + > > tools/testing/selftests/ring-buffer/config | 2 + > > .../testing/selftests/ring-buffer/map_test.c | 302 +++++++++++++ > > 10 files changed, 979 insertions(+), 11 deletions(-) > > create mode 100644 Documentation/trace/ring-buffer-map.rst > > create mode 100644 include/uapi/linux/trace_mmap.h > > create mode 100644 tools/testing/selftests/ring-buffer/Makefile > > create mode 100644 tools/testing/selftests/ring-buffer/config > > create mode 100644 tools/testing/selftests/ring-buffer/map_test.c > > > > > > base-commit: 7604256cecef34a82333d9f78262d3180f4eb525 > -- Sincerely yours, Mike.