Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9176635pxu; Mon, 28 Dec 2020 08:29:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrVSXWm3OIiGzRAmeYa9yYKrJ0ECxjI/l56tCTviyC/tfXhcyzZR0TW8DV4IyqRZ6yox1i X-Received: by 2002:a50:8163:: with SMTP id 90mr42134830edc.142.1609172953931; Mon, 28 Dec 2020 08:29:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172953; cv=none; d=google.com; s=arc-20160816; b=Xod2rpAkRCpxFPvjE+ODPc7i249RFOVwptnA70i3vsm/xsYNWZ2BABaszyNZxQxozc A9svO4KrCcxzbFcNFbERRH4gkZ8pXs+BC1+LqQUKqJ85pY39GxXRcfZMnoRVf6O6vkUm 2CWS9h8zMNAjL7k5bKbVMzc+JLyovg5E95EEv4x82U2J8FKzo41mu4Dv3ctxHTRgOhgG YlythVPYis5QTz3BgnzIzmduS8uyzjkKa2drSrHGxGNLMW98WZU3dkb6sbOFu4ZT1ac3 MVogleMnTeBXYPe74pk44OkzdprB1ipTnMkryEHxt4zhCcxb/MhtIJem6Y2LscLo0pKc ByRA== 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=fzS3r+BywZkQPmHCW2Xu15sk1r6p2pE7493Dyc/iivs=; b=u13V+PgJVRIBiHjaWOvc6r69hUc4pVdD47AH4FbIpRMl7X6t/B0MgspqkikQHMXCIY I5HCtSniR5NqoANTC/FSPO+kv22QEqVVeaLxmXfx2Xi6WRpj4DC8DAZMbV2zhmGfeliH HPzh25P7sYNXdbapakcn6RTzzLfY34Amto5TeFtOVzC+PiuazmxsqX5lc7rZnsMwQl6D 1nL8+FQjOGir7F6G8MH6Nwy/hTklxtBqN7eNGoc54UbXonCzMCAwbLKR9DQXoSjMarSS P7WQVj4LCT19VdfGhVZ7fyen9TY/OASSDs28x69ufddFB0ejUBIct/1iZp/qQ1VNFWnP Ggjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VZqQ97DB; 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 z23si19682182edr.334.2020.12.28.08.28.50; Mon, 28 Dec 2020 08:29:13 -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=VZqQ97DB; 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 S1731140AbgL1NJb (ORCPT + 99 others); Mon, 28 Dec 2020 08:09:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:36854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731098AbgL1NJR (ORCPT ); Mon, 28 Dec 2020 08:09:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E0A86207C9; Mon, 28 Dec 2020 13:09:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160941; bh=YlNmiCtb9qJKnSkPTpivwzAkIH8mQWS75TXzetaKuYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VZqQ97DBK8QYp/tyZsDyOwx80HZ6jS5Ppzo0DKRBnZ0dhG/Nz0KLOeN9KnjhWhEZ0 Mos+VzyhSpaNTCdazKJXsBB242bNWepDu0fdy5dHFyyp7PKK32mXt8z+U39S4G5Qjr Ru0r8/yt/mfPpIbiJGFw6DIJTvKHbHJBYoYtfuVg= 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.14 006/242] ARC: stack unwinding: dont assume non-current task is sleeping Date: Mon, 28 Dec 2020 13:46:51 +0100 Message-Id: <20201228124904.978294441@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 b007c06efbea9..35d418cde03b5 100644 --- a/arch/arc/kernel/stacktrace.c +++ b/arch/arc/kernel/stacktrace.c @@ -41,15 +41,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; @@ -68,11 +68,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); @@ -106,6 +110,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 @@ -119,7 +125,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