From patchwork Tue Feb 21 21:11:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 13148399 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 7B0D0C6FA9D for ; Tue, 21 Feb 2023 21:11:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A336A6B0074; Tue, 21 Feb 2023 16:11:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B5146B007B; Tue, 21 Feb 2023 16:11:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 855406B0075; Tue, 21 Feb 2023 16:11:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7504A6B0073 for ; Tue, 21 Feb 2023 16:11:52 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 42025C03D1 for ; Tue, 21 Feb 2023 21:11:52 +0000 (UTC) X-FDA: 80492546064.29.1C8A4F8 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 7B1AD120005 for ; Tue, 21 Feb 2023 21:11:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=VwLGet4O; spf=pass (imf29.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=1677013910; 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=tHu77fTu/Pc75Z3qVwi0VFcTFCyRQc+yM8ae91h5geojiwR90gxgioAhH+t8sIschW5Cez mUkwtgjYArBbNoH/fARRT6YzZjKk48stxncZqq9lr29guPYhHbBULm7YKsVxSm9xwqfLrx lydu4gTac88J01Kax6pGK/6ONzyJ/PU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=VwLGet4O; spf=pass (imf29.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=1677013910; a=rsa-sha256; cv=none; b=SCUMQVdGjdS1XIGk4W47C7o7T/6xh8Xs5vDi+6EYsx74T4QeuAOyryKQB3vGOXRp7R+pDg naqCGuazbUmqTLdXLI7KcgGYfih6OFUPyt7vwbzYoDz7mW7T/rt1xGeS170g0ybdsIqbu9 V0SGdjE3UdhAD9GBnrkRzMho3XQVlco= Received: from W11-BEAU-MD.localdomain (unknown [76.135.27.212]) by linux.microsoft.com (Postfix) with ESMTPSA id 0C401209A93C; Tue, 21 Feb 2023 13:11:49 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0C401209A93C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1677013909; bh=S8OIOLUkRs5CBqJ2LYBXQxLSyKFNFEQS/E/TUK8EqMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VwLGet4Ox6Jbrts9WykuV93sf2VYVaulOFjcl75VohmOtQSXPwHbypa6j/+9vjaJZ ITbYfc3DFAvcCF5GE9DM+R8SdZE5fBxZeeqvXqMOviyPY191C9t0v4ZeaPraxaO2jq 1MhjfMWFNCZmpaHtxIvjR/iFAaorf+9R+GiFQqSw= 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-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v8 02/11] tracing/user_events: Track fork/exec/exit for mm lifetime Date: Tue, 21 Feb 2023 13:11:34 -0800 Message-Id: <20230221211143.574-3-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230221211143.574-1-beaub@linux.microsoft.com> References: <20230221211143.574-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: fon7chqu3n7k5473mdjgzks14dk3zhqi X-Rspamd-Queue-Id: 7B1AD120005 X-HE-Tag: 1677013910-841080 X-HE-Meta: U2FsdGVkX19nlgyYUOHc5cAVnd786hvkV9QaFMQHTDYXH6welqYJWvzl33n/eMP00yrnroZy40Yi6p05Jh5heQq3yMHkbXrp/cHHzMmOPS8bmgaX1MXE4JX/SLoZkmmB1wzBMI/Div+mNeB9XfeEjivRlzc4bNWYgJO59PY88D2ji5Qd1Gogql4mpxbXhCab/hUpZ1dNfgaBt5qC2ZWGJ+eM7834iQdq4VQYwsAT5vOPre7LcUdYfy/nKhWnGgx8xgnhUsB3+OLEKsHIXczVOy0wKpiQxTl1ZTWgAZsTCcFNtk72VIBcj4T9CdtCTg5gsA2a4jKLdnD/AlmhddIAXz4sHDMYZ15H5X+eLswFubs0Km/hNgEyS+z1kqKOJ0IlyYS+o0MXdk6H65m10hEfbR/NdYuPxb56KywrS2YizY7IzGjUg0l0U75Bq2whWhdOci8CqSx+qDslb+6M4//XxGiiGSz5hLEYD60HUXVLPOVxgMd4oNwHBuJRGEAkSQMXzRbncIXXLwZKYZPAnbcxtLgBMTpnrzDnAqVa4PApwH3oFEkLQWTUu8AfwYBaIHfEGdAyzZrwplEeE7Hg32Ed3tCzqueePA2sTBIBMgk9b6p+dzcs3jvX+9e7LnjnbLmI87vzkJT+rlxYZZCRno0alBj3BKRzmyk3m0DtYdSDKT4z0OHTXzGNMe9Hyu66DgQENcRNGx7/RN2FSKvC2PT2AJrNoxIZgOHMm4fDtaKGj21YxfAXcf6r2mzpAqo5riWSEZK/BWJNgIZ0W/z/F6IAoyhXvdRoHShTuqfUTRJ6wV8pNzSyFbZ9dFEqOPT8HMM3XuE3vd/qRxZZhZ46MXKjc6psmpR7s/OAgslHn0iITx/ne5j6C0AtvpOyHPMsY9nI76/YCBvJLb+Y0PjuAWS6ClOaO8i0sxRXLccVBjTVwU6R0NhLS/Gon/fgSdi2LswFZs8kWpPkH9zAxN8HreD Chb4XAV8 BCG4Z31cpaeuEQacVMfVek3tl8NdlBc2kId5Q7ueBOGD8BbMw3wr9Rr6vVAcg/kG8h5hTES7E/fKGrk/zzj5jRJkzuXouMJft+5EbYHpEe7ndL3WkKlGcyqF4hk322Xcme7xc66HbUYuionYIAWG/0UjNO7z55EES2tSKiTPJIU+NEAcy562RLLf4+mdnFmP4y4LrGJ7tVYa92SQunLagARD0n/Hq+VmlE6s4O1FFEeNDbawCc91zvyGJCzypiRBs61RgV/EjGGCs0b19or5Bv+FKbFb0vo9DnJYuAqjlpC8qMU8zg49eq3T3twwjDUOoOIOBIWeKZOfkoMvbZhhlBJKYRdUPBP3iKbtjhrtc/+zYbX4= 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);