Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3497321imu; Mon, 7 Jan 2019 04:35:17 -0800 (PST) X-Google-Smtp-Source: ALg8bN5mym9loHlyId79m8WEikUXGL1MPkBxn/IQHMMeVwEC+ctbK+qw1rlcWv60dS6xq7lA2w4v X-Received: by 2002:a17:902:6909:: with SMTP id j9mr59178212plk.196.1546864517352; Mon, 07 Jan 2019 04:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546864517; cv=none; d=google.com; s=arc-20160816; b=yLZyXk1+mroqhNCiNxIvD9wEESDn5exH29bBpqQylMf5fB9fRScSctks5OG6PHaGbj glrkDOdmXsH0HWDEfgUgH+YwPVohpEZrvcjweX7scmzscVOk1ApCFXyXoqzpSKbJf063 SR/ZuBTwmZMnCVYOdZaz2v6Q3CWag5A9kmOo6TG6Za/sGVzPLLw15dLl8e61KQSyaoTm ANT38KMHvUVYtRORCQLiSKbuTEbb59H/1UoKUFdIiMuSZ8ph32qcpusXQ0PYvxv37ggE WrdKERThDq6PyzpkqPVYti5Mo2daZIGih1V+V29ukLNXJp5e3Ud+O6m/bALX0K0YNrAc xTnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7rn9Ja/hHiNZo2ILwjhD6J05EJSyPm9OrgTc7EcPRX4=; b=KvoA7ik7MAeAWJtQ1cViJ6c89V2NsnExps1zx9PTbw7L19+OAAFhrWEXjaviJ0Gn5J fv5k/+4V7j2zKVpeXtQMZ2JvDhfMbvrinU3LWBbnXZvBJjQNhpqgjJJAzWAagyA/28I2 SVYbc2+PsHYY5G4qBwyfRTM9hKLkaY5IM0pCSF9nBZQswoJIkOSIXPIB+Y3FgvsnC0Ry PwnkGJYDM7Wd7kwcm7aeal8vJtOLvU7xvYL+ifZGpER5CDeh/KjhsqRsIGUu+bGpTakD Dlz9KBS/d4Ssbt/qk8IeXvN3Ze1UzGB+ZfLKQ5byE9ENusFur0YeUjvEuK0/rasdsg7k oHIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OBTr4PTI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s4si8860432pfb.190.2019.01.07.04.35.01; Mon, 07 Jan 2019 04:35:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OBTr4PTI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbfAGMdx (ORCPT + 99 others); Mon, 7 Jan 2019 07:33:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:45296 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbfAGMdx (ORCPT ); Mon, 7 Jan 2019 07:33:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 06BB92089F; Mon, 7 Jan 2019 12:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546864432; bh=4tsxEuB7ho1DPw+N7ceriqItLez2PsVII4+BlOrBoqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OBTr4PTIx7lYmBysMexf3XQjuCDknx8lAk1xRRpw/DVdUSVDPF1TRBJ6wWJYFey+C b/UnXiuyKg2hqMeD0D1IowVPS3rk7v736hS3TTIQE0sLMcxRwGiSJTn/jnD2qRIxBv T4m3Ez92vWs8b+VaRpBp7IGfN9v2evRFxfjXVm/c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steven Rostedt , Daniel Wang , Peter Zijlstra , Andrew Morton , Linus Torvalds , Alan Cox , Jiri Slaby , Peter Feiner , linux-serial@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky , Petr Mladek Subject: [PATCH 4.20 001/145] panic: avoid deadlocks in re-entrant console drivers Date: Mon, 7 Jan 2019 13:30:38 +0100 Message-Id: <20190107104437.506029025@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190107104437.308206189@linuxfoundation.org> References: <20190107104437.308206189@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sergey Senozhatsky commit c7c3f05e341a9a2bd1a92993d4f996cfd6e7348e upstream. >From printk()/serial console point of view panic() is special, because it may force CPU to re-enter printk() or/and serial console driver. Therefore, some of serial consoles drivers are re-entrant. E.g. 8250: serial8250_console_write() { if (port->sysrq) locked = 0; else if (oops_in_progress) locked = spin_trylock_irqsave(&port->lock, flags); else spin_lock_irqsave(&port->lock, flags); ... } panic() does set oops_in_progress via bust_spinlocks(1), so in theory we should be able to re-enter serial console driver from panic(): CPU0 uart_console_write() serial8250_console_write() // if (oops_in_progress) // spin_trylock_irqsave() call_console_drivers() console_unlock() console_flush_on_panic() bust_spinlocks(1) // oops_in_progress++ panic() spin_lock_irqsave(&port->lock, flags) // spin_lock_irqsave() serial8250_console_write() call_console_drivers() console_unlock() printk() ... However, this does not happen and we deadlock in serial console on port->lock spinlock. And the problem is that console_flush_on_panic() called after bust_spinlocks(0): void panic(const char *fmt, ...) { bust_spinlocks(1); ... bust_spinlocks(0); console_flush_on_panic(); ... } bust_spinlocks(0) decrements oops_in_progress, so oops_in_progress can go back to zero. Thus even re-entrant console drivers will simply spin on port->lock spinlock. Given that port->lock may already be locked either by a stopped CPU, or by the very same CPU we execute panic() on (for instance, NMI panic() on printing CPU) the system deadlocks and does not reboot. Fix this by removing bust_spinlocks(0), so oops_in_progress is always set in panic() now and, thus, re-entrant console drivers will trylock the port->lock instead of spinning on it forever, when we call them from console_flush_on_panic(). Link: http://lkml.kernel.org/r/20181025101036.6823-1-sergey.senozhatsky@gmail.com Cc: Steven Rostedt Cc: Daniel Wang Cc: Peter Zijlstra Cc: Andrew Morton Cc: Linus Torvalds Cc: Greg Kroah-Hartman Cc: Alan Cox Cc: Jiri Slaby Cc: Peter Feiner Cc: linux-serial@vger.kernel.org Cc: Sergey Senozhatsky Cc: stable@vger.kernel.org Signed-off-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Signed-off-by: Greg Kroah-Hartman --- kernel/panic.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/panic.c +++ b/kernel/panic.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -237,7 +238,10 @@ void panic(const char *fmt, ...) if (_crash_kexec_post_notifiers) __crash_kexec(NULL); - bust_spinlocks(0); +#ifdef CONFIG_VT + unblank_screen(); +#endif + console_unblank(); /* * We may have ended up stopping the CPU holding the lock (in