From patchwork Tue Mar 28 23:52:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13191668 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 EEE36C77B60 for ; Tue, 28 Mar 2023 23:52:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 384AA6B0074; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 333C86B0075; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 222926B0078; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 12E496B0074 for ; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8DDA140B2D for ; Tue, 28 Mar 2023 23:52:27 +0000 (UTC) X-FDA: 80619958734.25.03D2317 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf27.hostedemail.com (Postfix) with ESMTP id D048C40002 for ; Tue, 28 Mar 2023 23:52:25 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b="g6TUG/nm"; spf=pass (imf27.hostedemail.com: domain of beaub@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=beaub@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680047546; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=0pwfcOP0BYjht0WfrCJ2bDXdNNrEgKRfwKmD9iPi+fk=; b=Nf7cy3ZURlVngybjx1EagfpSBWm6ibMZYNtmznS6kovY241Z9dv3hrmw34RLoCc/QM9xCT ILeq8s5g3yv2xU9xfaup6n1Gizz0TUJPhtZp4KE9PvWrzOmgV3+lyTdVbdAmyrCfN7aDKc 7yNYBZ6j3DKiQHLmZxXUStIqTcCp8/k= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b="g6TUG/nm"; spf=pass (imf27.hostedemail.com: domain of beaub@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=beaub@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680047546; a=rsa-sha256; cv=none; b=4t6ZSX/SzHk9yKQ8aRNt29u/u2UY9Nk1FZS4IvSsO55xgERjvPzARQPnEwcUgYVdIrNzuB bRG0oJMzRXNMUTD2bK3+71/m4tQ1RxudYYGoivzDY55+DOj7eoiJB0ZfsWq8Nq19CIabyc zmc6ESxzO0K7PxcAK4F0rdzTnO9uvDY= Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 631F120FDA98; Tue, 28 Mar 2023 16:52:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 631F120FDA98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680047544; bh=0pwfcOP0BYjht0WfrCJ2bDXdNNrEgKRfwKmD9iPi+fk=; h=From:To:Cc:Subject:Date:From; b=g6TUG/nmDiCWRUDvyK0XUTblKnu7x40ya09oCI0WRg7LHSlbM5REy978h6eknxh2j XBShQi3w7TJLWb3k7jiemicGH8AZtAo97r6jUo67CPG1Mtp3sGocVWNGh8Z2X1tc/9 IvQyAY8gvov62jeT4We42EJ6Tjo/ihC1TWByi9Rs= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dcook@linux.microsoft.com, alanau@linux.microsoft.com, brauner@kernel.org, akpm@linux-foundation.org, ebiederm@xmission.com, keescook@chromium.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH v10 00/12] tracing/user_events: Remote write ABI Date: Tue, 28 Mar 2023 16:52:07 -0700 Message-Id: <20230328235219.203-1-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: gn3wmsjpbhdp8bidkrx5rjf6wy6orxd4 X-Rspamd-Queue-Id: D048C40002 X-HE-Tag: 1680047545-521674 X-HE-Meta: U2FsdGVkX19TZ1DCkuzFNfyssFpmvhnxbjmAhPJwPFySPheEgGSpNJOW2P9ABJhRjD2LKwD8lQ/CdJRMxcWzhNySeJ+SisTqn35AOHAd1nUoRCR305gh9/DzhEQrA+E6tJo+pFfSHlsQ6lpxw+Qyx1UPrFFcE17fkFcCeKZN7rE9dN4YEghfkHvfY3PQNFBYozTOiYN0XNjtmppQShQuifXAaEyrp9iMKbNGGx+xtHx8roejycW/ggCYiizJj2k4wWg76I+nLIJw8rWIUlNdN82uqUsfJ6IokR9fSHxp4mrFosV65M1626kT9p0u5/mlVbnm7IpYPmpP1veW2VpQwUwnTgygP0jegXfuzx3LA0ug1Z2ZNUUFTRUHjPgAY4xS2Z7kv9BPGJZnP+oxTVDTCfLuAyVqkBkPmMLsW5GypzaqAvSKU1AA4c3GIIia3R7maAZvFC6cg0AqcEup4NJ75P2DEkBLkMu58Os6duUl3KwwnPRvEq7hDF+iVHhn9bIOUtPEnRnlZwuHjFS8OHM8r/XR4ME+kf/HmksPhdWqAJQfS4cvzNOaRxks7n9gMwveC3zTh6H0axDa3bKxK3pR6w//I5z6OeG2Ejdy6B2f631w739YIevaBKJC+6fJWPin/tXPXGCdMF3ldJqDZifWSxqkqgfXvf7wFe/qY07fqYofSTe/+iGx2hM8auQp7f0jEyBJSFOCotoDXFGRIT1xzqw+O/PexVSEjsv7oblalbpGqIDDxm3vFDVGAMp3L7ZIR4240BV1owpxJWqiISajEImSW9cU6Bjty6sb7P9CNrpEGSBLSNKkZojH5iS2NWA67u5jpc9CsXOo0+FXBeXMJN3RaO7FKstNPZ3Liuntu0x6kmu5/MBxlpYHrEFWU/QL2gA6SO0bwLnXnQzuS6S4pQK/x6jQid2U4fjIY1Ozsjvq3L4n0IcUjsQSy3d+j1q0iiYevBNz02U82XS+omK gqNgCdFv Hr6GdV81UERlICSkfNQXcoK3HThhEV81W47l42MMSFjS96WeYFwb4dRajQmaJtrqyqKElKISNVxug/Pnk9KbEi/8tbxEQhzKaC7Tjwr76tafz7eGtDnec7O/ztMeHWMrYzKe4qXKSgVyVGIaMJORWUqV/rW2LlXL0vHNbJagrcMKhGskhlBzEGCu7NaEJubqFlaf7+w+KiYj1KKxecAAzv1GqbMd0U1sF/udf9OXPw1O5hFR8Zi5BJJ/TEKiuQFLtj9CbyYCjpFvmc2dHecTo2k7+kA== 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: As part of the discussions for user_events aligned with user space tracers, it was determined that user programs should register a aligned value to set or clear a bit when an event becomes enabled. Currently a shared page is being used that requires mmap(). Remove the shared page implementation and move to a user registered address implementation. In this new model during the event registration from user programs 3 new values are specified. The first is the address to update when the event is either enabled or disabled. The second is the bit to set/clear to reflect the event being enabled. The third is the size of the value at the specified address. This allows for a local 32/64-bit value in user programs to support both kernel and user tracers. As an example, setting bit 31 for kernel tracers when the event becomes enabled allows for user tracers to use the other bits for ref counts or other flags. The kernel side updates the bit atomically, user programs need to also update these values atomically. User provided addresses must be aligned on a natural boundary, this allows for single page checking and prevents odd behaviors such as a enable value straddling 2 pages instead of a single page. When page faults are encountered they are done asyncly via a workqueue. If the page faults back in, the write update is attempted again. If the page cannot fault-in, then we log and wait until the next time the event is enabled/disabled. This is to prevent possible infinite loops resulting from bad user processes unmapping or changing protection values after registering the address. Change history V10: Ensure reserved values in unregister ioctl are set to 0. Tab out all structs for readability. V9: Updated documentation to include __packed attributed in example payload. Removed boot argument for max events, since sysctl can now be set via kernel boot parameters. V8: Rebase to 6.2-rc8. V7: Rebase to 6.2-rc4. Added flags to register ioctl, validates it's 0 for now. Future patches will enable other types of formats/options as needed. V6: Rebase to 6.2-rc2. Fixed small typos, code style. Changed from synchronize_rcu() to queue_rcu_work() to allow an rcu delay asyncly when mm is being removed and in an appropriate context for mmdrop(). V5: GFP_NOWAIT is still needed in user_event_enabler_dup(), due to rcu lock. V4: Rebase to 6.1-rc7. Moved user_events_fork() out of task signal lock and dropped use of GFP_NOWAIT. All allocations are now GFP_KERNEL or GFP_KERNEL_ACCOUNT. Added boot parameter user_events_max= to limit global events. Added sysctl value kernel.user_events_max to limit global events. Added cgroup tracking of memory allocated for events. V3: Rebase to 6.1-rc6. Removed RFC tag on series. Updated documentation to reflect ABI changes. Added self-test for ABI specific clone/fork cases. Moved user_event_mm removal into do_exit() to ensure RSS task accounting is done properly in async fault paths. Also lets us remove the delayed mmdrop(), saving memory in each user_event_mm struct. Fixed timing window where task exits, but write could be in-progress. During exit we now take mmap_write_lock to ensure we drain writes. V2: Rebase to 6.1-rc5. Added various comments based on feedback. Added enable_size to register struct, allows 32/64 bit addresses as long as the enable_bit fits and the address is naturally aligned. Changed user_event_enabler_write to accept a new flag indicating if a fault fixup should be done or not. This allows user_event_enabler_create to return back failures to the user ioctl reg call and retry to fault in data. Added tracking fork/exec/exit of tasks to have the user_event_mm lifetime tied more to the task than the file. This came with extra requirements around when you can lock, such as softirq cases, as well as a RCU pattern to ensure fork/exec/exit take minimal lock times. Changed enablers to use a single word-aligned value for saving the bit to set and any flags, such as faulting asyncly or being freed. This was required to ensure atomic bit set/test for fork cases where taking the event_mutex is not a good scalability decision. Added unregister IOCTL, since file lifetime no longer limits the enable time for any events (the mm does). Updated sample code to reflect the new remote write based ABI. Updated self-test code to reflect the new remote write based ABI. Beau Belgrave (12): tracing/user_events: Split header into uapi and kernel tracing/user_events: Track fork/exec/exit for mm lifetime tracing/user_events: Use remote writes for event enablement tracing/user_events: Fixup enable faults asyncly tracing/user_events: Add ioctl for disabling addresses tracing/user_events: Update self-tests to write ABI tracing/user_events: Add ABI self-test tracing/user_events: Use write ABI in example tracing/user_events: Update documentation for ABI tracing/user_events: Charge event allocs to cgroups tracing/user_events: Limit global user_event count tracing/user_events: Align structs with tabs for readability Documentation/trace/user_events.rst | 179 ++-- fs/exec.c | 2 + include/linux/sched.h | 5 + include/linux/user_events.h | 101 +- include/uapi/linux/user_events.h | 81 ++ kernel/exit.c | 2 + kernel/fork.c | 2 + kernel/trace/Kconfig | 5 +- kernel/trace/trace_events_user.c | 923 ++++++++++++++---- samples/user_events/example.c | 47 +- tools/testing/selftests/user_events/Makefile | 2 +- .../testing/selftests/user_events/abi_test.c | 226 +++++ .../testing/selftests/user_events/dyn_test.c | 2 +- .../selftests/user_events/ftrace_test.c | 162 +-- .../testing/selftests/user_events/perf_test.c | 39 +- 15 files changed, 1344 insertions(+), 434 deletions(-) create mode 100644 include/uapi/linux/user_events.h create mode 100644 tools/testing/selftests/user_events/abi_test.c base-commit: ceaa837f96adb69c0df0397937cd74991d5d821a