From patchwork Tue Mar 28 23:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13191667 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 B78ECC761A6 for ; Tue, 28 Mar 2023 23:52:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F04E6B0075; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A0536B0080; 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 64F606B0078; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 518DF6B0078 for ; Tue, 28 Mar 2023 19:52:28 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1199340B1A for ; Tue, 28 Mar 2023 23:52:28 +0000 (UTC) X-FDA: 80619958776.21.C27D491 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf25.hostedemail.com (Postfix) with ESMTP id 50C52A0002 for ; Tue, 28 Mar 2023 23:52:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=nOYZCYBZ; spf=pass (imf25.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:in-reply-to:references:references:dkim-signature; bh=S8OIOLUkRs5CBqJ2LYBXQxLSyKFNFEQS/E/TUK8EqMU=; b=l4gg236ba8BuZRYVLcQ/Oh/dVhqRKxdbzzez75tFdtlMBqAJE8SVvWeZ77j8J8/4yT/2Yd gJ8RQPs2lGAWVGWTyJ/3o3Ua3/cl6RdfPN2NAQPok4ZZkdHlZ1cxP7T+/0zLjOoloEBlrL hn38xE9S6b3tE5mGGICSXpEuQwOhC70= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=nOYZCYBZ; spf=pass (imf25.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=g3HU9M85/BWn5cEdCMO25kLGNKMe4WmbUB4GxEo9qXPOifk9GO274ZfCJg8qlSOA66/V5t EIdckjZZEmxntoohxvHQrcJ+sc4nGTx+dDMgXb1iuguLniQfk5M/9XHvDLvCOf/couvQyI nH6+tDOM+awlZGEVHH8LfqbItu4w5HI= Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 284C220FDAA8; Tue, 28 Mar 2023 16:52:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 284C220FDAA8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680047545; bh=S8OIOLUkRs5CBqJ2LYBXQxLSyKFNFEQS/E/TUK8EqMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nOYZCYBZnNL8mjXUQ7/DviplLsTB0V+Wfee3duOsmj42pfZJSfpTL3C/CWOFesECC OcarkvXVhOyaclMYZKL9aC8LkIsIGIKVZoMc6dS64oJ89B6sPg4/svycrBYyGUYQlC jm3KXGBFtgxgoaG+JAGtk3PRRUQcfQhKzIHCxecU= 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 02/12] tracing/user_events: Track fork/exec/exit for mm lifetime Date: Tue, 28 Mar 2023 16:52:09 -0700 Message-Id: <20230328235219.203-3-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230328235219.203-1-beaub@linux.microsoft.com> References: <20230328235219.203-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Stat-Signature: 7aqot7oqqcj74itqtdpngshf8t8ow5et X-Rspam-User: X-Rspamd-Queue-Id: 50C52A0002 X-Rspamd-Server: rspam06 X-HE-Tag: 1680047546-705644 X-HE-Meta: U2FsdGVkX19wChKEyjxGFgE5g/16sADfXtwyiYaj8RuZIMgzsbf7N4cb4X8azc+cy8BJmRA5IkK+3wjPzCgyWnAPOlXxqWHMqmcmlb/yoeGQX+HGmqIJAtdKSSXeZmTyg19zKo35KxYHnOUsl9j8gnpNzVs4qGpzW2HYO1OKzJF8C96DWIlDAhwAiL2uI5+MnSNRSEP2mmm/I8UQGvU/OeP7x64chN6O9eIvCRFWLMcUsFWI012sUGvHDjIsCFgYYXmZkJ5WzJfxaYH5iePkheu6HklAIpcKOFGk9Skxkv3WUkxjTvd8CfvztQAaMGnn7dkQ3+n1hGSG+iwXFbyfxGR9oG9N2b4/VWCv8vjFaFSa+OCsRSzF4/mB6KeaZDr26w8xfFFZ4qlqDw9+C+mI20/twXqTTjRzbx/D1oC5nA0RfamLkl1zSW9oygRqbFgNd+UbHNfLVTps5O6bm8JJyE3/Pe00sFCfEtb3pjHGXhH+YybO/kfbHONr3Y/xS9ry1WFa5OuhrZZe3eYIXO+PWsmvzVHlI+9YKwZHDLenk5mWuG+ZG+K9Dd7NROPFeutaAZnl0R0ZqbTuH/Cg24GopQ/+d75yv8Vs+Tv8+J8nCiaUpaC+YBwZH2Wmrgf87ej/nLDgpWtkQITpZE4/8IM4vq0EEY9BUp/jF1wHvoIK3hBvbSErLT6633kGUxDR0Z4gUuhxzEGS3GXQeorPXGbZSKnyf5rh9r6jDGLim2x+VnGsUlsP7ARMrgm/lON+s+aUxeXZDJhk+oD7rUw9bXDDAio30LG5r9J3JkDk7vAMo7VVxdhN9kACqSC5mzztZlGkzlVR5MI64yUa7OwhdRuFiymLG5eAR7tbivzOW4Q3fDV5WlxJoGiuN9c6q/WhyW0GA/FvS55pVMz4dU7gHc/FC7GBWun9b8CU123Intwlo5zy/t0dHWYPsl6Zde0/KvlXn9pMXvbSMlSzlWn9dV4 vk1YYM/u 1niVcXMqDfPVyzs+Ks7TL6jrx7kGSX61ZkdSxZxaJXkPFo95X8faf0PLdYbJW1BLT6mBEm94rIe5KPT3dlzMRvy25NxCPEOsyAYNnlv//zWAHvFBECEwVdrk1eREN/Zckdv1L6RILlmnsglaoR4nAfKEpOvs1uaVZlAYzVHUbWAeiosL4P7O3UKYjUDMIMI1Y0PDx7kyGSPCLTpetdFfub+TB5WWHiHbEx2qM1hmJxYrhO/RhqAdFie59Z0K3bmvF3dsTwh2MLDg8HUpaHksyJitS9ANfNRkqOnp0uoPzMZE/uCxOem6gJnCvqM0iv4Mi4BoC/mY3YgL1fPFlJPbaNfkZpp4JzOUKWwjFFeLr64c/Qd4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: During tracefs discussions it was decided instead of requiring a mapping within a user-process to track the lifetime of memory descriptors we should hook the appropriate calls. Do this by adding the minimal stubs required for task fork, exec, and exit. Currently this is just a NOP. Future patches will implement these calls fully. Suggested-by: Mathieu Desnoyers Signed-off-by: Beau Belgrave --- fs/exec.c | 2 ++ include/linux/sched.h | 5 +++++ include/linux/user_events.h | 18 ++++++++++++++++++ kernel/exit.c | 2 ++ kernel/fork.c | 2 ++ 5 files changed, 29 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index ab913243a367..d1c83e0dbae5 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include @@ -1856,6 +1857,7 @@ static int bprm_execve(struct linux_binprm *bprm, current->fs->in_exec = 0; current->in_execve = 0; rseq_execve(current); + user_events_execve(current); acct_update_integrals(current); task_numa_free(current, false); return retval; diff --git a/include/linux/sched.h b/include/linux/sched.h index 853d08f7562b..a8e683b4291c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -69,6 +69,7 @@ struct sighand_struct; struct signal_struct; struct task_delay_info; struct task_group; +struct user_event_mm; /* * Task state bitmask. NOTE! These bits are also @@ -1522,6 +1523,10 @@ struct task_struct { union rv_task_monitor rv[RV_PER_TASK_MONITORS]; #endif +#ifdef CONFIG_USER_EVENTS + struct user_event_mm *user_event_mm; +#endif + /* * New fields for task_struct should be added above here, so that * they are included in the randomized portion of task_struct. diff --git a/include/linux/user_events.h b/include/linux/user_events.h index 13689589d36e..3d747c45d2fa 100644 --- a/include/linux/user_events.h +++ b/include/linux/user_events.h @@ -11,4 +11,22 @@ #include +#ifdef CONFIG_USER_EVENTS +struct user_event_mm { +}; +#endif + +static inline void user_events_fork(struct task_struct *t, + unsigned long clone_flags) +{ +} + +static inline void user_events_execve(struct task_struct *t) +{ +} + +static inline void user_events_exit(struct task_struct *t) +{ +} + #endif /* _LINUX_USER_EVENTS_H */ diff --git a/kernel/exit.c b/kernel/exit.c index 15dc2ec80c46..e2aaaa81b281 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -816,6 +817,7 @@ void __noreturn do_exit(long code) coredump_task_exit(tsk); ptrace_event(PTRACE_EVENT_EXIT, code); + user_events_exit(tsk); validate_creds_for_do_exit(tsk); diff --git a/kernel/fork.c b/kernel/fork.c index 9f7fe3541897..180f6d86fbad 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -2502,6 +2503,7 @@ static __latent_entropy struct task_struct *copy_process( trace_task_newtask(p, clone_flags); uprobe_copy_process(p, clone_flags); + user_events_fork(p, clone_flags); copy_oom_score_adj(clone_flags, p);