From patchwork Tue Nov 15 00:58:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 20113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2451146wru; Mon, 14 Nov 2022 17:04:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5F9biMQ9UGzg9w4eX760OLS2iuktTknmA00l1H4vbMA8RWs7pkR5QY5XAjRoSL1yAdljyA X-Received: by 2002:a17:90b:2302:b0:208:4bfa:51e1 with SMTP id mt2-20020a17090b230200b002084bfa51e1mr15653279pjb.228.1668474294820; Mon, 14 Nov 2022 17:04:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668474294; cv=none; d=google.com; s=arc-20160816; b=aRwIAVioSx9xmcQdRKxSSnVCDOsVOw3aRsXa9BUrSNMrYsbE1TCsAxSWd9i/CHQUwO MM6QRJblAOXnYjgWDqeMm4ExA/WZWLqXY0kQOJ2HWCmJdGO93JX4fSU+FQBfFMrVqjFi AEGx7KY8XHhdnUnxsGWAUPBbP8jrdIDwfLnwjH5cugKX4abEh7P5kEYVO/tA1uok+O61 pUMaq+ryImnzqbi0hwWr/ssNyHNu69D+ILRJWBf7ZV5RV9hwrwsRHP3B+5fEsYmgGF6h 46mHJLqG0fYZo4bjqt3+xN29P+tK5wGFcgsQEoTTjGhY9kLNj0bUI/pVcjT2qB1N7Q16 0nkw== 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=jaIIhLZttVFC7Yx8esBsWniUFcDQgLnfPHrKFv8TLp8=; b=JSaqsr1W8O7FcE/1gn+V3Nokt/DaaKjmpj+KzacimVTC+yFgCwOvvvHGfwy+xQpi+L KAQlF6nDGY7+qb3apaZFpeV+BPyyR7N6eN0aBTqEwqdX/jx6KWRZLJ2bjIO3z7TLMiNc gzbATJpkC8hWCgbvBXH92vCd5SBSNaInvr1ZsEB5kjOy7OMqM1KEqUP2g9/zu6b25+/v ZGFjIwJBEoHoEcje4vBWgC1KcX5Jp+fb2gzzyd2UKg3JAtDooznLsPC63ydgrsuuOIuk 7wCAqZMazMVXVu6PPL5pT8t8IyPqhpyQg/qA/ByGSnbUFyCXae3o93DXXfQO2+UFzKTl StSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="C/Ccg68A"; 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 u190-20020a6385c7000000b00462ed110adbsi10210794pgd.316.2022.11.14.17.04.41; Mon, 14 Nov 2022 17:04:54 -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="C/Ccg68A"; 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 S237808AbiKOA7U (ORCPT + 99 others); Mon, 14 Nov 2022 19:59:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237652AbiKOA7K (ORCPT ); Mon, 14 Nov 2022 19:59:10 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2CA89FAC6; Mon, 14 Nov 2022 16:59:08 -0800 (PST) Received: from W11-BEAU-MD.localdomain (unknown [76.135.50.127]) by linux.microsoft.com (Postfix) with ESMTPSA id C6E7720B83C2; Mon, 14 Nov 2022 16:59:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C6E7720B83C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1668473948; bh=jaIIhLZttVFC7Yx8esBsWniUFcDQgLnfPHrKFv8TLp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C/Ccg68At7kbLjSwvYepsoo1N5cBI8LhmldHjSZDOxGWaqAxxHnzZUPlxsQ/9mIod AFRKH1N1cJmoVnX5hSplGoKjif09iH8n1CkE/IvVSiZ+H0EOgLEsX7QvB7wf7u7gE8 n5HsS3ERBxYsfAUwKP9p6Kz1qbfvzlhOIcTsP4xI= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, dcook@linux.microsoft.com, alanau@linux.microsoft.com Cc: linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 2/7] tracing/user_events: Track fork/exec/exit for mm lifetime Date: Mon, 14 Nov 2022 16:58:57 -0800 Message-Id: <20221115005902.30458-3-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115005902.30458-1-beaub@linux.microsoft.com> References: <20221115005902.30458-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?1749522102383938591?= X-GMAIL-MSGID: =?utf-8?q?1749522102383938591?= 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 | 16 +++++++++++++++- kernel/exit.c | 2 ++ kernel/fork.c | 3 +++ 5 files changed, 27 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..2abf05224be1 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_flush_task(struct task_struct *t) +{ +} + #endif /* _LINUX_USER_EVENTS_H */ diff --git a/kernel/exit.c b/kernel/exit.c index 35e0a31a0315..f578ab3bf1c8 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -173,6 +174,7 @@ static void delayed_put_task_struct(struct rcu_head *rhp) kprobe_flush_task(tsk); rethook_flush_task(tsk); + user_events_flush_task(tsk); perf_event_delayed_put(tsk); trace_sched_process_free(tsk); put_task_struct(tsk); diff --git a/kernel/fork.c b/kernel/fork.c index 08969f5aa38d..8658e67d27b0 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -97,6 +97,7 @@ #include #include #include +#include #include #include @@ -2416,6 +2417,8 @@ static __latent_entropy struct task_struct *copy_process( rseq_fork(p, clone_flags); + user_events_fork(p, clone_flags); + /* Don't start children in a dying pid namespace */ if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) { retval = -ENOMEM;