Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934025AbdC3OIM (ORCPT ); Thu, 30 Mar 2017 10:08:12 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:33456 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933714AbdC3OIJ (ORCPT ); Thu, 30 Mar 2017 10:08:09 -0400 From: Denis Kirjanov To: gregkh@linuxfoundation.org, jslaby@suse.com Cc: linuxppc-dev@ozlabs.org, linux-kernel@vger.kernel.org, benh@kernel.crashing.org, Denis Kirjanov Subject: [PATCH] tty/hvc_console: fix console lock ordering with spinlock Date: Thu, 30 Mar 2017 10:06:19 -0400 Message-Id: <1490882779-16066-1-git-send-email-kda@linux-powerpc.org> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1032 Lines: 35 hvc_remove() takes a spin lock first then acquires the console semaphore. This situation can easily lead to a deadlock scenario where we call scheduler with spin lock held. Signed-off-by: Denis Kirjanov --- drivers/tty/hvc/hvc_console.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index b19ae36..a8d3991 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -920,17 +920,17 @@ int hvc_remove(struct hvc_struct *hp) tty = tty_port_tty_get(&hp->port); + console_lock(); spin_lock_irqsave(&hp->lock, flags); if (hp->index < MAX_NR_HVC_CONSOLES) { - console_lock(); vtermnos[hp->index] = -1; cons_ops[hp->index] = NULL; - console_unlock(); } /* Don't whack hp->irq because tty_hangup() will need to free the irq. */ spin_unlock_irqrestore(&hp->lock, flags); + console_unlock(); /* * We 'put' the instance that was grabbed when the kref instance -- 1.8.3.1