Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp828415pxu; Mon, 23 Nov 2020 05:21:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJzFOjEOyYt2al+niMwHceVa0PQoIt2ix0zxcQYqVThDRMx6bWtcNaCaU+EjMo7Dv1IBFZZd X-Received: by 2002:a17:906:4057:: with SMTP id y23mr41177481ejj.299.1606137682766; Mon, 23 Nov 2020 05:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606137682; cv=none; d=google.com; s=arc-20160816; b=S/Vtt+USMLwxDOUh+YRPPhPYPLFQ3LagGEz9XaH075Nuk+c2nB7OscQRhbzM0rsSJL 4iJCGftftkfgP1dBzzHYqL1dhIZi7MGOXJ0PCAUepJgEXOJ6aLIhYEFe4QAdFv98mwYA Su0KOarUiq7ONl+wlN+617f3tNYpXPwLWiKgeg3dCmS1e+E2DtauOF4SPa/XEhmbzJJA dRCSp5SrQG1s80l0dPhX7xLb3ATFPbwfInwBFbQZr9mH28bPzyMTEXptUo+aHka4j/+Y 7UQfD4rNwjMl7fBQmxysn/bdbNK5xNyx/8VdBOjvCzoixZr/9QE97gMTSLCJ3AgMWaAg ooIQ== 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=Gau8L7FwwGqDaupc5BJLgf9AjdFC3vtY/z3MBZ54X2o=; b=XFiinXtznmFlNgE7rab8Qjlrwgs3DI97imVkq+xOU6OR9QxTKsF6/U/wGaV7mD9bRa BcvhKfKiOGtzF45Qhrlt/8/6/XoFFpWo4uB3Rko5CRv5zUKdlAvsjRFYtz/L9nqDQp7F 5jWvBILayCUD4ibw2bV8/vZL3y1rN/a4EUx88D7xpHugGtzYiiJR5ADUIKmQ4stsxTX2 E0nX92xSMQ0Jn09Bx+cR8yY6ue3F+qnAwah3lm1/vSssg0GrDTMZwnceZcqUlPsums+W uRIw42hfFtM/1IE2Il1Cw72hmfwBYPyZ1WE1MWVmfgCkAfppkNuoxVTmMyEiEXK2vgx2 jNIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=odHFKuzJ; 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 h6si6285163ejq.48.2020.11.23.05.20.59; Mon, 23 Nov 2020 05:21:22 -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=odHFKuzJ; 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 S1732516AbgKWMkf (ORCPT + 99 others); Mon, 23 Nov 2020 07:40:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:53464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732506AbgKWMke (ORCPT ); Mon, 23 Nov 2020 07:40:34 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 211CE2065E; Mon, 23 Nov 2020 12:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135233; bh=kgtcLmtm9wHjRma6lXp+oE0OFan3yDGUTvzn8LDgpPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=odHFKuzJrDXFUdsKjMg5N0BOY4yzX0dzqLMgZOCp60nrFf88inUJHeN7gHH7Hyy/U HLiqu1rCr6qk0IN6Da9DX6pgsN3P1s//xNSv2rdisW82gdu89LOKJZUol8+YcJ6EuO YJYFO30rWP6EZFUEOofgaCfo16wB0+B+e43rLxZI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Sam Nobs Subject: [PATCH 5.4 123/158] tty: serial: imx: fix potential deadlock Date: Mon, 23 Nov 2020 13:22:31 +0100 Message-Id: <20201123121825.867390771@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@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: Sam Nobs commit 33f16855dcb973f745c51882d0e286601ff3be2b upstream. Enabling the lock dependency validator has revealed that the way spinlocks are used in the IMX serial port could result in a deadlock. Specifically, imx_uart_int() acquires a spinlock without disabling the interrupts, meaning that another interrupt could come along and try to acquire the same spinlock, potentially causing the two to wait for each other indefinitely. Use spin_lock_irqsave() instead to disable interrupts upon acquisition of the spinlock. Fixes: c974991d2620 ("tty:serial:imx: use spin_lock instead of spin_lock_irqsave in isr") Reviewed-by: Uwe Kleine-König Signed-off-by: Sam Nobs Link: https://lore.kernel.org/r/1604955006-9363-1-git-send-email-samuel.nobs@taitradio.com Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/imx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -877,8 +877,14 @@ static irqreturn_t imx_uart_int(int irq, struct imx_port *sport = dev_id; unsigned int usr1, usr2, ucr1, ucr2, ucr3, ucr4; irqreturn_t ret = IRQ_NONE; + unsigned long flags = 0; - spin_lock(&sport->port.lock); + /* + * IRQs might not be disabled upon entering this interrupt handler, + * e.g. when interrupt handlers are forced to be threaded. To support + * this scenario as well, disable IRQs when acquiring the spinlock. + */ + spin_lock_irqsave(&sport->port.lock, flags); usr1 = imx_uart_readl(sport, USR1); usr2 = imx_uart_readl(sport, USR2); @@ -946,7 +952,7 @@ static irqreturn_t imx_uart_int(int irq, ret = IRQ_HANDLED; } - spin_unlock(&sport->port.lock); + spin_unlock_irqrestore(&sport->port.lock, flags); return ret; }