Thread (161 messages) 161 messages, 8 authors, 2025-04-24

Re: [PATCH v4 30/39] unwind_user/deferred: Make unwind deferral requests NMI-safe

From: Peter Zijlstra <peterz@infradead.org>
Date: 2025-01-22 14:24:31
Also in: linux-perf-users, linux-toolchains, lkml

On Tue, Jan 21, 2025 at 06:31:22PM -0800, Josh Poimboeuf wrote:
+static int unwind_deferred_request_nmi(struct unwind_work *work, u64 *cookie)
+{
+	struct unwind_task_info *info = &current->unwind_info;
+	bool inited_cookie = false;
+	int ret;
+
+	*cookie = info->cookie;
+	if (!*cookie) {
+		/*
+		 * This is the first unwind request since the most recent entry
+		 * from user.  Initialize the task cookie.
+		 *
+		 * Don't write to info->cookie directly, otherwise it may get
+		 * cleared if the NMI occurred in the kernel during early entry
+		 * or late exit before the task work gets to run.  Instead, use
+		 * info->nmi_cookie which gets synced later by get_cookie().
+		 */
+		if (!info->nmi_cookie) {
+			u64 cpu = raw_smp_processor_id();
+			u64 ctx_ctr;
+
+			ctx_ctr = __this_cpu_inc_return(unwind_ctx_ctr);
__this_cpu_inc_return() is *NOT* NMI safe IIRC.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help