From patchwork Mon Dec 5 21:00:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 29934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2470468wrr; Mon, 5 Dec 2022 13:01:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf6163P7pooJSYtE/Iuyyo3nvf+dZZ+QPBg30KR3hobk2jcPnbVRdoAXRNDWhg6+r7DlNy+F X-Received: by 2002:aa7:da48:0:b0:46b:25b9:3941 with SMTP id w8-20020aa7da48000000b0046b25b93941mr33842113eds.28.1670274097779; Mon, 05 Dec 2022 13:01:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670274097; cv=none; d=google.com; s=arc-20160816; b=q+MAu+A4ZKSElhcNO34SoI68fOTk/IOGaY50biJhPpTV28MtVvLGYmsNlAsCaVeo1j NqxwZ36ZCTEe3CfPiKoKafwR6JgkNpGlCg1ILy80UIUpaoeDmgUkrfhc/TgX2lb64RAm CHi/YX7nwdwCePeggWbojCnCeaHignnQxm/w+gK38DAoGhYw3tuaUJw1ihQOEfD99wUe 8vDwzaiLI4UwInkxgxWp5j92momGfRM+eoKEVe4264J3tJu7zf+SrVMM7NXcr9oNVkVs 90bEZje0OCIBjeEEx5W/GamPFykdhgY0CP16iLVqQsTcbLhAmmDb+rTaFKjwGaV8tCSm UdFQ== 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=uParTVU9Z9xqfA98lJokNpjIwc9u+HZsqpYzGti/vmY=; b=v0e7My6nQyv+jYPUHEyY2V66/LKXnxEqiiiSqT2ZH/vwuBoDGNAD/osRT81kA/sbPy vI+iwTh9gJpqIYCTOEb+nG1i69/iS/qdNLSNgmgtlNSDz6YtmMwIPR0yWgYzJF05QqLd OHz6Tho0c3+QPYrAMuLp+Xu3EST6ddhz8u7sqSDPLcAkxsM0lO9tqKsEFWtM2C0dQ7wP DvWULJDShCQ00tJi0/BAMeMkeStLxOX9IUcMQzmdoKkYPVKUVRxjYnGP+8p7fwuiB3AV xZfEyc9HyBsKw2Y75mpKntjWA1ViOp/SVKEY17GyqJ7zSziHGQf87Zrd8gJNn4fRk4Pt zA5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=iMJDXP8Q; 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 wz13-20020a170906fe4d00b007813b1924ccsi12566301ejb.934.2022.12.05.13.01.13; Mon, 05 Dec 2022 13:01:37 -0800 (PST) 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=iMJDXP8Q; 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 S233674AbiLEVAd (ORCPT + 99 others); Mon, 5 Dec 2022 16:00:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbiLEVAY (ORCPT ); Mon, 5 Dec 2022 16:00:24 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DB16125E92; Mon, 5 Dec 2022 13:00:23 -0800 (PST) Received: from W11-BEAU-MD.localdomain (unknown [76.135.50.127]) by linux.microsoft.com (Postfix) with ESMTPSA id 7A19420B83DC; Mon, 5 Dec 2022 13:00:23 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7A19420B83DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1670274023; bh=uParTVU9Z9xqfA98lJokNpjIwc9u+HZsqpYzGti/vmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iMJDXP8Q5fT1haWV3G14W4tzih6QY47J8fXaYMvfsLe18yT12SuxO2g94oNrgxAtn hqffpLzkQRBKe42aBOgM9z30NjI+oaYluLrYRVj8ur/hM5vXRoKU5IamaDBRE4rAyx 4Pvdk5uOD0ombKPG6wnNcfyyiRCfj/zoP4sbcOJ0= 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 Cc: linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/11] tracing/user_events: Track fork/exec/exit for mm lifetime Date: Mon, 5 Dec 2022 13:00:08 -0800 Message-Id: <20221205210017.23440-3-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205210017.23440-1-beaub@linux.microsoft.com> References: <20221205210017.23440-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,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=ham 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?1751409332695674365?= X-GMAIL-MSGID: =?utf-8?q?1751409332695674365?= 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 Reviewed-by: Mathieu Desnoyers --- fs/exec.c | 2 ++ include/linux/sched.h | 5 +++++ include/linux/user_events.h | 16 +++++++++++++++- kernel/exit.c | 2 ++ kernel/fork.c | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index a0b1f0337a62..75ca6fbd195c 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -1842,6 +1843,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 ffb6eb55cd13..61ed2f9deb26 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 @@ -1528,6 +1529,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 036b360f3d97..3d747c45d2fa 100644 --- a/include/linux/user_events.h +++ b/include/linux/user_events.h @@ -12,7 +12,21 @@ #include #ifdef CONFIG_USER_EVENTS -#else +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 35e0a31a0315..0bfadc26d278 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -769,6 +770,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 08969f5aa38d..a4be76276ccb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -2487,6 +2488,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);