Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9192618pxu; Mon, 28 Dec 2020 08:55:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSWAyuUS5DX3gAGorXysAB9DX03c5dJlCzMmQzG+rKxcmWgcUUHn4nq4iKp5nTO7uJLgJJ X-Received: by 2002:a50:fb1a:: with SMTP id d26mr42896139edq.101.1609174524003; Mon, 28 Dec 2020 08:55:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609174523; cv=none; d=google.com; s=arc-20160816; b=uRICgf8oe5BBdOZBgiZys6TVx/lGsksKn2rHAkeFKuJm4Wz0wEDIgDbicnE1VZbMNX 21vUFTaWY4Cygnc/J48pk5VBEtQqwhdQY6MCbAXMdRcE6dhhuCT9dlug5edQl/GMA16Q DLtpVzNBNdFNe5jRgWf1mkrED0DMkn8DYpjhaL3sB4XRnr464dmE+PrnBznjLxHpZg7Q BTu4cS9AejtujpAIs1hDz3Ty7qbH9k6gFjWmBOxQRP68q6+4JJu2kXm9qCCqMFSjWg37 oK16BXVkUUbAV8Jggv+tNkVPE/e0Q/U5OTasAuJiwyfReqb3qeBQYe+Ssts5aqxnTDHq bvNg== 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=scDtyRFISbaRby+PijExK1K5+SfHlhFnEBf8hrv5oEY=; b=poeKBf9jczTZwrANYpIZkrCJ69BtlEagPlYJbqW/P8JPEsyX6Bg57ml3HslMm5P0X/ 0s1tQvtpzD2G2BsozqORW7ebAe095c1JxuYJctPghsEevrb6FMmEhVRIulG9yvxFjBLj aZAiZY9hVXMyEKFzdIpXuTOMvjY9UtSkBF2r5SaE5jQsRZwxMgUnGu8+UGkCGQZmipHe MES8PUfH78ZmbexGhDvdgvFO7z2/bBHYZCZOEgyn/7wRGS3WhXqAycR9DUxU0wX1wcu8 irXXiqN/QGGkKTOaKcA78kw8LbDple2ImRIQ9Lp+F0r27ZG9E7oKbBLXPR+XR0czRtmt 1WAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AAU6NljG; 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 a12si21524273edk.285.2020.12.28.08.54.59; Mon, 28 Dec 2020 08:55:23 -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=AAU6NljG; 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 S1728022AbgL1Mw7 (ORCPT + 99 others); Mon, 28 Dec 2020 07:52:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:49864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728014AbgL1Mw6 (ORCPT ); Mon, 28 Dec 2020 07:52:58 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C1D522AAD; Mon, 28 Dec 2020 12:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609159924; bh=7s45JohUG30iwJDbdBJWmStd19JLp6VNjraO8w+7aTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AAU6NljGRHDV8uE0ceH7FQaXybIXpc2Q7uPO2eCQFrmW9VYC6RS4L2/Nx91W3u4ZR WEbAUoSG4QLuRa+PzTg6+l4YL5OLWqfGUxIcW5z+4km48NkcyvBHsppGUhy0/LiyVK kGXGjHV3MMIE17n2KesriaHtOyJDFwhTZXN3YBtY= 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.4 003/132] ARC: stack unwinding: dont assume non-current task is sleeping Date: Mon, 28 Dec 2020 13:48:07 +0100 Message-Id: <20201228124846.593368255@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124846.409999325@linuxfoundation.org> References: <20201228124846.409999325@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 5401e2bab3da2..054511f571dfd 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