Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp871871ybl; Wed, 11 Dec 2019 08:47:16 -0800 (PST) X-Google-Smtp-Source: APXvYqzm3uzOz77hxNjs4pWji/DzJKSo4mJ2E1mcEWywIeSplM1fLmRD56tOVsQJPuv/c/Ocvv7G X-Received: by 2002:a05:6830:2087:: with SMTP id y7mr2795790otq.96.1576082836694; Wed, 11 Dec 2019 08:47:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576082836; cv=none; d=google.com; s=arc-20160816; b=k3k7ZqUJ+0WcZnpK9RbfHEuEyy4Swvbx8xRMRUjCn5HE1brnpMJBF1dV8KrGtjtMH7 erVQwJkgF3dGa40VLPHIW1qUXqYet0Dgf6BBBQRr80NvBVnv+mG5sCyjuMLiqZ3WCh72 6pO0rPCdNbZSswKUq5errD7nUvDXQ8rdL4C8NAhUaTXLvg0BieYoQvsYFL8hJPKcpoOx TeAql8tlmF1c9OaS82fiPSVDwkec+X8M3zOrGKQTZjMolNQmlbMZhPf/X//wqTTcIjWG 4/BLOCUISfnUDSKJzw3ovrAgtPtHgKxLOK+TFH8Hv9uMXd/8G75HcesMTP60xnB/CgQV SGwQ== 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=gKPNpyEDHEzBkekBSG0hoZMUcDguhGN2UHXfIkab984=; b=EysEKcC6rRE0IhPJMpkDbtlkbP9kBoKBzc587Eh3EWMHq0hvMVqBfCWdfC4zV5pKTB DSPqmZEiz/zzxAnHYjiprcQ0qMlH0t+VJ1xY0ilAh3zGEiirjR9/kcsjaWCMsITP1J1S zzMc4MdQouBAwDrMVCzjC5e1datdU7Mw0HnY1Ke4HVxgup90SpMk0Ee4bALziDvHjzkP IF9hbqnHUWIv27CVjiXWYUlHjW65BTd+pdt7twl5p4DDHoHsCJj+txeM7p1/L3Fqh7ff d1oGv/n3M9rUZePfSFf+9nZ09cvBz+lnJnY5OWilYZ7ORl1Lns8pHaQcX12+F6hxsIWu d/eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rFEYRj8R; 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 u11si1356268oic.152.2019.12.11.08.46.59; Wed, 11 Dec 2019 08:47:16 -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=rFEYRj8R; 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 S2388202AbfLKQFC (ORCPT + 99 others); Wed, 11 Dec 2019 11:05:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:35564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730429AbfLKPM5 (ORCPT ); Wed, 11 Dec 2019 10:12:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 6D4692467D; Wed, 11 Dec 2019 15:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077176; bh=pQakcmBqFDRLENctK9bfXEUWLJiw418Ya1RuBaWljTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rFEYRj8RxbU1sKEEgPuDcs0/drDd/uO7o2nZh8flGXnoR09hukvZBlCyALN3z/ThW dH4lSfD3IfSpT8BRYitil0O1YPhi4fz5g757K/CdhviS1sFu6z8BgzpBMCgk89c0Cp uTY0NY3eKr5jbxToAwQfVK2wQpQKt0KYBk6Pnjms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Whitchurch Subject: [PATCH 5.3 010/105] serial: pl011: Fix DMA ->flush_buffer() Date: Wed, 11 Dec 2019 16:04:59 +0100 Message-Id: <20191211150223.556547365@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Vincent Whitchurch commit f6a196477184b99a31d16366a8e826558aa11f6d upstream. PL011's ->flush_buffer() implementation releases and reacquires the port lock. Due to a race condition here, data can end up being added to the circular buffer but neither being discarded nor being sent out. This leads to, for example, tcdrain(2) waiting indefinitely. Process A Process B uart_flush_buffer() - acquire lock - circ_clear - pl011_flush_buffer() -- release lock -- dmaengine_terminate_all() uart_write() - acquire lock - add chars to circ buffer - start_tx() -- start DMA - release lock -- acquire lock -- turn off DMA -- release lock // Data in circ buffer but DMA is off According to the comment in the code, the releasing of the lock around dmaengine_terminate_all() is to avoid a deadlock with the DMA engine callback. However, since the time this code was written, the DMA engine API documentation seems to have been clarified to say that dmaengine_terminate_all() (in the identically implemented but differently named dmaengine_terminate_async() variant) does not wait for any running complete callback to be completed and can even be called from a complete callback. So there is no possibility of deadlock if the DMA engine driver implements this API correctly. So we should be able to just remove this release and reacquire of the lock to prevent the aforementioned race condition. Signed-off-by: Vincent Whitchurch Cc: stable Link: https://lore.kernel.org/r/20191118092547.32135-1-vincent.whitchurch@axis.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/amba-pl011.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -813,10 +813,8 @@ __acquires(&uap->port.lock) if (!uap->using_tx_dma) return; - /* Avoid deadlock with the DMA engine callback */ - spin_unlock(&uap->port.lock); - dmaengine_terminate_all(uap->dmatx.chan); - spin_lock(&uap->port.lock); + dmaengine_terminate_async(uap->dmatx.chan); + if (uap->dmatx.queued) { dma_unmap_sg(uap->dmatx.chan->device->dev, &uap->dmatx.sg, 1, DMA_TO_DEVICE);