Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1411985yba; Tue, 2 Apr 2019 08:23:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwd8K1q/ZyldGnqIEempSYVfNzN7osjq8wKLtWHoKzT7FrOL7z2V5BCfh1JBwz30aExVWuj X-Received: by 2002:a62:4852:: with SMTP id v79mr69005883pfa.72.1554218614866; Tue, 02 Apr 2019 08:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554218614; cv=none; d=google.com; s=arc-20160816; b=H6VWQnIdoynjQcteMYztck+sXwjSwPTJuSReJ8cIYf0Lw1IKttg3izfBMs/uVHAaF5 3D8D4rrvj06trxKejQa9hqwHZutKFHTyRFi8JSyRw4mCpqZU4PyoP0CWS9gfTwia1G7Q 1vvtGJ3PsmH8/fPlZjd1gDSQf8QnV9xPPnbl+ne1Jw75GhXIKAuza4W4ERPkKduuuIW0 qAkdv1NNOmvjakFxBRxO6hmHWsHjdVutdctN5R4uQl60tk4zaqjSwJTGOypuQgKn/wui 7kWAfkCz1oPhoHjlSYWeQs3yU7jvyHxVygTDxljidxn5z+tbcDVxM9vXDi7Y1e50lAD4 lwdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=+k+TBxRyHgPNJIXMh3OE57Y1EPTyfqOcAkTpKVw+/CQ=; b=jWXbOzOmtEeh3kvcL21QKnZdAD4HZvgu1gmrK7ndGnP3PY1efXWcJRRhDH3CWEr/0J YcdlWpE7rD9MTzNhwxocZTVimxaYJyIW/p3g90goF8IKxyz42SxIAi/lxRh7VbGmh/oi lWxkGQ/a0FyS7RF2eigorcPbuNgQdKqUfrkpp99WaDQB8Z9SSoa6+5IKe24/IvMPtWME xnRZIcut/3tk3kygLqhLOsYL1bLdepRE5tSeZYhErPHqAsOi70BZo4guQHzSmdLliDbU xagcpto1+bhnFWyuwyUZk/BxoSXFJYa3vwhcvZPbfgLPM9nsjX9Y39iDpls8erw2xo+q /cOQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t9si11255079plo.98.2019.04.02.08.23.19; Tue, 02 Apr 2019 08:23:34 -0700 (PDT) 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; 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 S1731786AbfDBNkv (ORCPT + 99 others); Tue, 2 Apr 2019 09:40:51 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43930 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731309AbfDBNkR (ORCPT ); Tue, 2 Apr 2019 09:40:17 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJdu-0002mk-WB; Tue, 02 Apr 2019 14:39:59 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdu-0004rZ-2J; Tue, 02 Apr 2019 14:39:58 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Sergey Senozhatsky" , "Greg Kroah-Hartman" , "Daniel Wang" , "Jiri Slaby" , "Petr Mladek" , "Sergey Senozhatsky" , "Peter Feiner" , "Alan Cox" , linux-serial@vger.kernel.org, "Linus Torvalds" , "Peter Zijlstra" , "Steven Rostedt" Date: Tue, 02 Apr 2019 14:38:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 14/99] panic: avoid deadlocks in re-entrant console drivers In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.65-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Sergey Senozhatsky commit c7c3f05e341a9a2bd1a92993d4f996cfd6e7348e upstream. =46romprintk()/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 Signed-off-by: Sergey Senozhatsky Signed-off-by: Petr Mladek Signed-off-by: Ben Hutchings --- kernel/panic.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/panic.c +++ b/kernel/panic.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -178,7 +179,10 @@ void panic(const char *fmt, ...) */ 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