From nobody Fri Dec 19 20:59:50 2025 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B95BD230BC9 for ; Wed, 9 Jul 2025 21:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=158.69.130.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752096365; cv=none; b=nwODXVr06kygY5dYdZtJOUUGjKBnVv8s4i8Y6JyT7zzOfxhce6HU2NpaaRQA5n0djqwTU2NBMEUYPcXQG+npKflI4q3ZyOmCbea/P9LalWMrs8TTt/leaK/2Vcig9bioVRab0i0juojUv/hmAdE/8QUn+8PwO4YMoFcjXxhbODU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752096365; c=relaxed/simple; bh=iauZL9jmjufsByEqjLynOS/a/I/93HipMuGHw4CkAUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JZh3binjpqhUlOBoNDnQnWscr2iO/zQ2tqHqYLkC+t5k3aJGpSM/FeLDbvkvjjaxo9Vg9HvTCROA6JfgU7UxqjKDemWTcz4pwLautKTFZn+Y/ernZDccOcU/VALiy6wtBXX5wk/E7ZkVqtryFPgwsIGCRrpTH2F7EdVRN1Kt574= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=fKQgKrKb; arc=none smtp.client-ip=158.69.130.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="fKQgKrKb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1752096362; bh=iauZL9jmjufsByEqjLynOS/a/I/93HipMuGHw4CkAUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fKQgKrKbHnseUqsqLWBsQJMsXUQvKuXRe7UYe16qIO7Nq9lmpXwIEHBrc+pqUCB92 CwJ+oEGkRNC2vcfWS+JYsoXSc1kQRKBBoPRoqud0+XGeMQoD5410XhvUF6kdB1AMhk oFaPAmAa0RYJ6IjVi6ojH+qtnT3BtrC2QpSmWCxp9ooWeBjXfL3FctqeRp48Pa4ZiV KWphDqIT1nwUEixM6cQyMLjfL4+Icp4AUkMkDcORVSNO1Aowp/4qoKs7wTk9P8jM+b 9pLDOtWjXbc6ghAHJFTUdq5bUSaXpI3NV/AUvwkSjd6cvve6jl9nbnMPm5pLVkjW8N D9H41DxbioF+g== Received: from compudjdev.. (192-222-132-26.qc.cable.ebox.net [192.222.132.26]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4bcrcp4QsSzPN5; Wed, 9 Jul 2025 17:26:02 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Josh Poimboeuf , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Andrii Nakryiko , Indu Bhagat , "Jose E. Marchesi" , Beau Belgrave , Jens Remus , Linus Torvalds , Andrew Morton Subject: [RFC PATCH 3/5] unwind deferred: Introduce unwind_user_trace_cached Date: Wed, 9 Jul 2025 17:25:50 -0400 Message-ID: <20250709212556.32777-4-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250709212556.32777-1-mathieu.desnoyers@efficios.com> References: <20250709212556.32777-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce unwind_user_trace_cached which copies the stack trace if it was previously stored into the cache since the last reset of the cache. The expected use-case is sampling a stack trace from a faultable context at system call entry (coping it into the cache), and then copying the stack trace from the cache from non-faultable context to a ring buffer. Signed-off-by: Mathieu Desnoyers Cc: Steven Rostedt (Google) Cc: Josh Poimboeuf Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Jiri Olsa Cc: Namhyung Kim Cc: Thomas Gleixner Cc: Andrii Nakryiko Cc: Indu Bhagat Cc: "Jose E. Marchesi" Cc: Beau Belgrave Cc: Jens Remus Cc: Linus Torvalds Cc: Andrew Morton --- include/linux/unwind_deferred.h | 2 ++ kernel/unwind/deferred.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/linux/unwind_deferred.h b/include/linux/unwind_deferre= d.h index a9d5b100d6b2..ddc985ba982a 100644 --- a/include/linux/unwind_deferred.h +++ b/include/linux/unwind_deferred.h @@ -34,6 +34,7 @@ void unwind_task_init(struct task_struct *task); void unwind_task_free(struct task_struct *task); =20 int unwind_user_faultable(struct unwind_stacktrace *trace); +int unwind_user_trace_cached(struct unwind_stacktrace *trace); =20 int unwind_deferred_init(struct unwind_work *work, unwind_callback_t func); int unwind_deferred_request(struct unwind_work *work, u64 *cookie); @@ -67,6 +68,7 @@ static inline void unwind_task_init(struct task_struct *t= ask) {} static inline void unwind_task_free(struct task_struct *task) {} =20 static inline int unwind_user_faultable(struct unwind_stacktrace *trace) {= return -ENOSYS; } +static inline int unwind_user_trace_cached(struct unwind_stacktrace *trace= ) { return -ENOSYS; } static inline int unwind_deferred_init(struct unwind_work *work, unwind_ca= llback_t func) { return -ENOSYS; } static inline int unwind_deferred_request(struct unwind_work *work, u64 *t= imestamp) { return -ENOSYS; } static inline void unwind_deferred_cancel(struct unwind_work *work) {} diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c index 039e12700d49..02ab1d2afc21 100644 --- a/kernel/unwind/deferred.c +++ b/kernel/unwind/deferred.c @@ -145,6 +145,37 @@ int unwind_user_faultable(struct unwind_stacktrace *tr= ace) =20 return 0; } +EXPORT_SYMBOL_GPL(unwind_user_faultable); + +/** + * unwind_user_trace_cached - Copy user stack trace from cache + * @trace: The descriptor that will store the user stacktrace + * + * Copy user stack trace from cache if the cache was populated by + * unwind_user_faultable prior to this call. The returned trace + * entries are only valid until the cache is reset. + * + * Return: 0 on success and negative on error + * On success @trace will contain the user space stacktrace + */ +int unwind_user_trace_cached(struct unwind_stacktrace *trace) +{ + struct unwind_task_info *info =3D ¤t->unwind_info; + struct unwind_cache *cache; + + if (!current->mm) + return -EINVAL; + + cache =3D info->cache; + if (!cache || !cache->nr_entries) + return -ENOENT; + + trace->nr =3D cache->nr_entries; + trace->entries =3D cache->entries; + + return 0; +} +EXPORT_SYMBOL_GPL(unwind_user_trace_cached); =20 static void process_unwind_deferred(struct task_struct *task) { --=20 2.43.0