From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 04D8B1E51E1; Tue, 26 Aug 2025 13:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756215538; cv=none; b=A4xXIL8lFPRfLezRe/cuWZ7H8deiL8Gv0mv0oWFbUxIHSBi5Q7yvd2vmktf+Dz1XGQKMUh9PHJJ8qULrRCxMhAhO9Hi7VeGCjyKf1ybhwAU2TN81Gkpr53N2t6NARE2P/cGTuDcEYw2ertP2bNjtSmP8qzGCOQ/y2WFA5B4BMcc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756215538; c=relaxed/simple; bh=Wl85erfLeSqaiTQeqrdHGaLSE5B02xaIORkLoi/Zsxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fV8pZNKMpBujz+CFhih8ZgLCL4u3fsHf2nJ1IVsZrafuq4GovnwdAz9L3Z9sjHVYuxbSaM49LG4JnuuKp95amd7iOjuQDcIlIfivusHl09TglYq7bI+Gqlqa5o5GtgeSYqyL/zReFcUqRUOdBwYkkOFkDq7/rIaSQGxPuK69oj0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dnsVavBs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dnsVavBs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C1CEC4CEF1; Tue, 26 Aug 2025 13:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756215537; bh=Wl85erfLeSqaiTQeqrdHGaLSE5B02xaIORkLoi/Zsxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dnsVavBsifuuCc4TZ4bPZ4bADT6QAAlmAi/4lGzVS8T0zqR8Py+k86JOjFSyb8svA KzBy0qWjm8ZUkgUOZexFBf5zvRArHteR1GVJP+hVe/AbQVup7DjMWqs146xNboPaJx 6ixsCufDuiVO/ne0gZIBzYXWHVfsp4nD7Bo8Gg64= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qi Zheng , Kees Cook , "Peter Zijlstra (Intel)" , Siddhi Katage Subject: [PATCH 5.15 072/644] x86: Fix get_wchan() to support the ORC unwinder Date: Tue, 26 Aug 2025 13:02:43 +0200 Message-ID: <20250826110948.281970176@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110946.507083938@linuxfoundation.org> References: <20250826110946.507083938@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qi Zheng commit bc9bbb81730ea667c31c5b284f95ee312bab466f upstream. Currently, the kernel CONFIG_UNWINDER_ORC option is enabled by default on x86, but the implementation of get_wchan() is still based on the frame pointer unwinder, so the /proc//wchan usually returned 0 regardless of whether the task is running. Reimplement get_wchan() by calling stack_trace_save_tsk(), which is adapted to the ORC and frame pointer unwinders. Fixes: ee9f8fce9964 ("x86/unwind: Add the ORC unwinder") Signed-off-by: Qi Zheng Signed-off-by: Kees Cook Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20211008111626.271115116@infradead.org Signed-off-by: Siddhi Katage Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/process.c | 51 ++-------------------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -971,58 +971,13 @@ unsigned long arch_randomize_brk(struct */ unsigned long get_wchan(struct task_struct *p) { - unsigned long start, bottom, top, sp, fp, ip, ret = 0; - int count = 0; + unsigned long entry = 0; if (p == current || task_is_running(p)) return 0; - if (!try_get_task_stack(p)) - return 0; - - start = (unsigned long)task_stack_page(p); - if (!start) - goto out; - - /* - * Layout of the stack page: - * - * ----------- topmax = start + THREAD_SIZE - sizeof(unsigned long) - * PADDING - * ----------- top = topmax - TOP_OF_KERNEL_STACK_PADDING - * stack - * ----------- bottom = start - * - * The tasks stack pointer points at the location where the - * framepointer is stored. The data on the stack is: - * ... IP FP ... IP FP - * - * We need to read FP and IP, so we need to adjust the upper - * bound by another unsigned long. - */ - top = start + THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING; - top -= 2 * sizeof(unsigned long); - bottom = start; - - sp = READ_ONCE(p->thread.sp); - if (sp < bottom || sp > top) - goto out; - - fp = READ_ONCE_NOCHECK(((struct inactive_task_frame *)sp)->bp); - do { - if (fp < bottom || fp > top) - goto out; - ip = READ_ONCE_NOCHECK(*(unsigned long *)(fp + sizeof(unsigned long))); - if (!in_sched_functions(ip)) { - ret = ip; - goto out; - } - fp = READ_ONCE_NOCHECK(*(unsigned long *)fp); - } while (count++ < 16 && !task_is_running(p)); - -out: - put_task_stack(p); - return ret; + stack_trace_save_tsk(p, &entry, 1, 0); + return entry; } long do_arch_prctl_common(struct task_struct *task, int option,