Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3761596pxt; Tue, 10 Aug 2021 10:42:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+/MO3G29CmAIdVkKTvw8+lfXiQ1whlDUyIotDg2WX8oIde6iRs1LmowS+H/k6xZU0+Qiz X-Received: by 2002:a02:a196:: with SMTP id n22mr991147jah.24.1628617363541; Tue, 10 Aug 2021 10:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617363; cv=none; d=google.com; s=arc-20160816; b=e+m4Cbu/a3IqucM7YcmY0AnLCodz3Pib4oAIIOyo6IRavG3Csob8alkhoj+scccHrQ UXSHVg6+FA/lB6uoh49V1sZaZ/Qc0v3MpMoes5Cv2fOn8nOi+jU95+mI96+7kWrE9I/c Lb0KiZazBzOwRTGPzS1fJBpI92lqmEaoNj9fkyfPEx3IrHH/cZJt5yd90O7ldOW0+oGV /irgMLIiBAW1GYc4PcVVuootYG4it9gVSDDaMwTeoqITVw6B7oKtMwwT6fF91Humlesw jlRYWkd63lKX/GLJuqkk7/B+rB9j5EU2Co88Yy2gUvlyp1P0wvrYmDbLETvml5VjyrBc m/iA== 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=DiI5LCLfBr/J3t2YzFdNkaoJADvJwTo9guN6AtTcqrM=; b=HSPdwGIHudCGsDyhDkssqAPIXj0R6E6m8CR/KGLkufXaejtB8jz9C3yu8VTmTa+tK6 7ec/3MM/ITbMuBBJKqDCRfGM/9bBhQP8/ipfOJw/mPUNaXBDYckAH0yU77wS0PeAeCZQ 3lLTXvRl8YnYzgVxOxCMD1LLGHKP8ub4FKqxxcyaJHctO0ThOCqdK9Qb12xRg8Jlb7Qm uZxkXuslijqNdnGvK3888PeV/da6MvXY2lRq+/cswKEI4/ZMxDzh8hv1FCKgSmH4T1AT IN44a+MZJtMLIiTNQXGw+WbTfpdS/kQVQ4S+2GOXMI53idKUDPZzC7+l6GFxkKrSSjOg u5qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Ou/TInDv"; 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 r17si14189159jad.53.2021.08.10.10.42.08; Tue, 10 Aug 2021 10:42:43 -0700 (PDT) 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="Ou/TInDv"; 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 S229991AbhHJRlk (ORCPT + 99 others); Tue, 10 Aug 2021 13:41:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:42010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233409AbhHJRgl (ORCPT ); Tue, 10 Aug 2021 13:36:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B6D96610EA; Tue, 10 Aug 2021 17:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628616944; bh=xHgfxz9wQATRqOjex35VnVIrpDufuV1SvTgYhWBlqA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ou/TInDv+Rx0W2yVHFgKrMjFuhDsWgh6gHjY0XPUG2EzTDEX6HLJtBhvOF0pjFH7e ssFhe1DfQUWvq06oBYSaHQpVnypQj9Bq/ODnwzT7ylOh4I8sWMzWPDiO16UT1T08zq 2XCeDkXG28N5zMRvIDtZe2mfagmvNPZT2JzMmbAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhiyong Tao Subject: [PATCH 5.4 62/85] serial: 8250_mtk: fix uart corruption issue when rx power off Date: Tue, 10 Aug 2021 19:30:35 +0200 Message-Id: <20210810172950.339027962@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172948.192298392@linuxfoundation.org> References: <20210810172948.192298392@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: Zhiyong Tao commit 7c4a509d3815a260c423c0633bd73695250ac26d upstream. Fix uart corruption issue when rx power off. Add spin lock in mtk8250_dma_rx_complete function in APDMA mode. when uart is used as a communication port with external device(GPS). when external device(GPS) power off, the power of rx pin is also from 1.8v to 0v. Even if there is not any data in rx. But uart rx pin can capture the data "0". If uart don't receive any data in specified cycle, uart will generates BI(Break interrupt) interrupt. If external device(GPS) power off, we found that BI interrupt appeared continuously and very frequently. When uart interrupt type is BI, uart IRQ handler(8250 framwork API:serial8250_handle_irq) will push data to tty buffer. mtk8250_dma_rx_complete is a task of mtk_uart_apdma_rx_handler. mtk8250_dma_rx_complete priority is lower than uart irq handler(serial8250_handle_irq). if we are in process of mtk8250_dma_rx_complete, uart appear BI interrupt:1)serial8250_handle_irq will priority execution.2)it may cause write tty buffer conflict in mtk8250_dma_rx_complete. So the spin lock protect the rx receive data process is not break. Signed-off-by: Zhiyong Tao Cc: stable Link: https://lore.kernel.org/r/20210729084640.17613-2-zhiyong.tao@mediatek.com Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_mtk.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/tty/serial/8250/8250_mtk.c +++ b/drivers/tty/serial/8250/8250_mtk.c @@ -92,10 +92,13 @@ static void mtk8250_dma_rx_complete(void struct dma_tx_state state; int copied, total, cnt; unsigned char *ptr; + unsigned long flags; if (data->rx_status == DMA_RX_SHUTDOWN) return; + spin_lock_irqsave(&up->port.lock, flags); + dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); total = dma->rx_size - state.residue; cnt = total; @@ -119,6 +122,8 @@ static void mtk8250_dma_rx_complete(void tty_flip_buffer_push(tty_port); mtk8250_rx_dma(up); + + spin_unlock_irqrestore(&up->port.lock, flags); } static void mtk8250_rx_dma(struct uart_8250_port *up)