Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp491293pxu; Thu, 3 Dec 2020 05:40:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPcIAp8+flvGO+e9ViYFBevOWIj5bd86MdItklGp5NETMA+1MbTdDL/fu8Gxs8TjQUq9Gz X-Received: by 2002:a17:906:a946:: with SMTP id hh6mr2531979ejb.456.1607002807682; Thu, 03 Dec 2020 05:40:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607002807; cv=none; d=google.com; s=arc-20160816; b=Bo8RQhDW9ViudkaA0ELvOQqeH+6nz+cdnnrRlsfuSd3uv4TkqrKMZXIx8GLnuuq1PC LfoF+8guWne9wcTxCxukb0uYVKbA8YT0r0HnPwFS/obl4bk64gV6CnD1QwjvaRGh+EoY yklLClHllMYxRy5UH6ymw+2J8pXrF+VjFfSM0RIfpSP6LLT0UkHPvVrxw/NPz/y+zqx1 sJxVzDMg0uHPp8beSIdaboqC2LfNqD9FztFSMSImm9hRC565AtX2OJfYxjnCxD0KSow2 yVRMROEz6QOarMXKMW5UiYFUwLVo8vE+flDUGunX0jQV4KH3Da1PQ/2LnMW1bLu08b8v aYQQ== 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; bh=yVSdZ8u+A6VK2jmaA3KyjVeHjT3MaSSBm8VZWqV06HU=; b=PuFBX0K9462npjX8lcBDzjCEbD9TB/OO8CXdhefzoezn2PYiu1gdPZvJokQJfmZs2e XD+iO4PscJnJgEfCK68esqMSCWuW9yq+gjnZeqfsaKIbKx96lq4lWpTMeKJvL/BEj8uL big0o1uXS5AjPGa7wKrqh3MS9z7sMzkycqIsZrCXucZ1Xq/raocdyTIOcDClFxz9t96s NQO93Fgy8qn8Kug0Lt0Ynm4dFVtl/BDYol1vh25mwJtP4db0ynBbWpkiBBEnf3/k4w9V LA3/04ioaw/KCJ7AYxa6+c7YMVYMh+egLKnw8O1X92iZX5BClPTkHWxBhZIKz1uUauXB /Afw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb6si930878edb.497.2020.12.03.05.39.39; Thu, 03 Dec 2020 05:40:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437084AbgLCNiB (ORCPT + 99 others); Thu, 3 Dec 2020 08:38:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:47922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436462AbgLCNaB (ORCPT ); Thu, 3 Dec 2020 08:30:01 -0500 From: Sasha Levin Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vineet Gupta , Sasha Levin , linux-snps-arc@lists.infradead.org Subject: [PATCH AUTOSEL 5.9 11/39] ARC: stack unwinding: don't assume non-current task is sleeping Date: Thu, 3 Dec 2020 08:28:05 -0500 Message-Id: <20201203132834.930999-11-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201203132834.930999-1-sashal@kernel.org> References: <20201203132834.930999-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineet Gupta [ Upstream commit e42404fa10fd11fe72d0a0e149a321d10e577715 ] To start stack unwinding (SP, PC and BLINK) are needed. When the explicit execution context (pt_regs etc) is not available, unwinder assumes the task is sleeping (in __switch_to()) and fetches SP and BLINK from kernel mode stack. But this assumption is not true, specially in a SMP system, when top runs on 1 core, there may be active running processes on all cores. So when unwinding non courrent tasks, ensure they are NOT running. And while at it, handle the self unwinding case explicitly. This came out of investigation of a customer reported hang with rcutorture+top Link: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/31 Signed-off-by: Vineet Gupta Signed-off-by: Sasha Levin --- arch/arc/kernel/stacktrace.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/arc/kernel/stacktrace.c b/arch/arc/kernel/stacktrace.c index b23986f984509..b2557f581ea8c 100644 --- a/arch/arc/kernel/stacktrace.c +++ b/arch/arc/kernel/stacktrace.c @@ -38,15 +38,15 @@ #ifdef CONFIG_ARC_DW2_UNWIND -static void seed_unwind_frame_info(struct task_struct *tsk, - struct pt_regs *regs, - struct unwind_frame_info *frame_info) +static int +seed_unwind_frame_info(struct task_struct *tsk, struct pt_regs *regs, + struct unwind_frame_info *frame_info) { /* * synchronous unwinding (e.g. dump_stack) * - uses current values of SP and friends */ - if (tsk == NULL && regs == NULL) { + if (regs == NULL && (tsk == NULL || tsk == current)) { unsigned long fp, sp, blink, ret; frame_info->task = current; @@ -65,11 +65,15 @@ static void seed_unwind_frame_info(struct task_struct *tsk, frame_info->call_frame = 0; } else if (regs == NULL) { /* - * Asynchronous unwinding of sleeping task - * - Gets SP etc from task's pt_regs (saved bottom of kernel - * mode stack of task) + * Asynchronous unwinding of a likely sleeping task + * - first ensure it is actually sleeping + * - if so, it will be in __switch_to, kernel mode SP of task + * is safe-kept and BLINK at a well known location in there */ + if (tsk->state == TASK_RUNNING) + return -1; + frame_info->task = tsk; frame_info->regs.r27 = TSK_K_FP(tsk); @@ -103,6 +107,8 @@ static void seed_unwind_frame_info(struct task_struct *tsk, frame_info->regs.r63 = regs->ret; frame_info->call_frame = 0; } + + return 0; } #endif @@ -116,7 +122,8 @@ arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs, unsigned int address; struct unwind_frame_info frame_info; - seed_unwind_frame_info(tsk, regs, &frame_info); + if (seed_unwind_frame_info(tsk, regs, &frame_info)) + return 0; while (1) { address = UNW_PC(&frame_info); -- 2.27.0