Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9184741pxu; Mon, 28 Dec 2020 08:42:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaKYd1uo8s3cqDJoa81mK7swcjSpNQqywnMJ5ux5ASal5Nt5Jb9YPP0P7xS/BiG0IMI5Uo X-Received: by 2002:a17:906:6449:: with SMTP id l9mr37934003ejn.320.1609173725767; Mon, 28 Dec 2020 08:42:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173725; cv=none; d=google.com; s=arc-20160816; b=fR9y+yR5D0RsBPoWjtM4HLE81U8mxdcrsmoG4su73HuO3Zykxyj/VI1/4Dho1vgAbb WjU7Xw6DdIxry6yo+ffboFQCmEvSDMHNKWt8PXzUlRWry4xV6gs2ae5iariz6Z3gRGFT KaCwgjE3qQmteYtC+MAE5r81FB66om3xcdJf/3vBbICYLddZDktepgBbV08nMr6nEsb7 25m+ccDWJZ+AWSE2Jsgx8QQbjFAk7H3Xwr777ZnNcQVW5eiCLydjxa0SQHbOtHTzdt1S TiV4HfAZ4oU86ZOURlor2AqYT0pOhTF3q/aXVzSJHRsZTF/2mOFiVtMpe9NPS5JQKjAS GmyA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hqfqqbDKcV78h6pmxusyQF1Z7s/SuXbbPxgU5N+QAMU=; b=ONpjl3FJBsh5UbtWW6xBe5ozPRZqruXhSw+Jv+5ywfH7c/QPNJ0Xd7cb1syDhhIPtO +3Vy8FeSaTaMZRpKWBqCxOWAiOKqvqsXe9bnmfGBzXK02J4yYpV2HZiWXY1r7gASKnfB gH6pGDtzYA5pxdSzZ8Gj5dxXvLhq+ale8oMiMSBoSsQy4xWJ56bInBboi/oZmMSr1Cfx TzMUw2C4360e5dsMkWMZAAJBcK2LAVKUZ7ee5DxF4lGDIZC9ytSolfT/5AjohlJv5tHu BUeoDaUSkzPrz3guqlYgu6gis9kmnq1zw+0d9bAHa0NK9SS4T7y2tKuCoBCIM/VmeGKR g8wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x7kN5M8v; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si20116507eju.355.2020.12.28.08.41.40; Mon, 28 Dec 2020 08:42:05 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x7kN5M8v; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2441090AbgL1Qjw (ORCPT + 99 others); Mon, 28 Dec 2020 11:39:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:56074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729189AbgL1M7y (ORCPT ); Mon, 28 Dec 2020 07:59:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B677D22583; Mon, 28 Dec 2020 12:59:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160353; bh=4RVsrHt+swWkgwGUunNrBplzgzeOI/Zp42aT6hjTzQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x7kN5M8vm/ZWk20t3ZUehIJNL7HgnyLgYEAtFg/5GdjNM7Fb9Trj1UQBaDGdMqKyC hKwD8VahcbrR7viq19ofAzkVy3UGNSOePCrHmst0yEsPx73sZascJ1X/SJDGV0BL1i 6/LLMmJKRzSZo6//MftwQYZLi3jnFp6vardjBwiU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vineet Gupta , Sasha Levin Subject: [PATCH 4.9 005/175] ARC: stack unwinding: dont assume non-current task is sleeping Date: Mon, 28 Dec 2020 13:47:38 +0100 Message-Id: <20201228124853.506539508@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 165158735aa6b..3ee19b1e79be5 100644 --- a/arch/arc/kernel/stacktrace.c +++ b/arch/arc/kernel/stacktrace.c @@ -39,15 +39,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; @@ -66,11 +66,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); @@ -104,6 +108,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 @@ -117,7 +123,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