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: 76315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp55331vqo; Tue, 28 Mar 2023 17:10:29 -0700 (PDT) X-Google-Smtp-Source: AK7set/9uFSrFkZlncawZJVdYkqzSqgpYjF7L7m7NfcXj+mDczoM1EHzlku32ctkD9WU/2uTxWrF X-Received: by 2002:a05:6a20:4b02:b0:db:10c8:4c95 with SMTP id fp2-20020a056a204b0200b000db10c84c95mr15162017pzb.17.1680048629456; Tue, 28 Mar 2023 17:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680048629; cv=none; d=google.com; s=arc-20160816; b=cN6XvDASGntLWi9uzHJNOAkYUi+RVL4IjvKRGpl2M6xMcYcc9XRUNUVUqUKSWvxVFQ zdCiqwkUb1N2iV/Ksek1rtcp3ujxOOp8qIOrTdEzzbBrAgJ80FlRv5RW7Cif0e8cq+xy UZqxo70qfofVdds1Tt6OMITTOJkLfd7TqTViCN9phb/wfpGivs6rT4gJc7Bod4nowo4E jbw6kIDQcB/2dYonZBKs5DVvb8gmU8/gQfK6LbjbEnLkDXJe3RW4RrBA+8/eCUhBAW92 9lNcWuwAobangFJ7iFsPc745U2KdCHMhpd/PC8Z1zdVKS92AU+df8ABM6+RvjzUJCUML XGKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=S8OIOLUkRs5CBqJ2LYBXQxLSyKFNFEQS/E/TUK8EqMU=; b=xnFtXX7UJWH6iZ0LNAR7Sj9iXXygi1xyVPCnitG0B52bzSm8KpDiOUbTS0BgpVLErb zuPoDqdjl2eWKzyxqf+ievKWOFazw78jOgCSADEreduy1cuViv9NndtalPs1wCy1IHz2 5bvYgrqvHczz2ZIJ58nEawaCIy5RygKJZ8PszrgJH16/8tq++PbJjL491JVPq13zk1q+ UId+DkGGjPV9n2S7tm2aVrmuRGEXgu3SQoXkW6X4b6eJ1foq+EDWkox0pC0utcuj4hN3 NHaHUF7DYMQRWZaGoU0VSMfaavBot3IWx8z4TR2xZOCTfBBJqkc+se8lbZc2iwG2YrNB oujQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=nOYZCYBZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r129-20020a632b87000000b0050fa328e128si19074496pgr.419.2023.03.28.17.10.17; Tue, 28 Mar 2023 17:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=nOYZCYBZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229484AbjC1Xwe (ORCPT + 99 others); Tue, 28 Mar 2023 19:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbjC1Xw1 (ORCPT ); Tue, 28 Mar 2023 19:52:27 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE52E2D53; Tue, 28 Mar 2023 16:52:25 -0700 (PDT) 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-Spam-Status: No, score=-17.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761658671607179970?= X-GMAIL-MSGID: =?utf-8?q?1761658671607179970?= 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);