Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3768027pxt; Tue, 10 Aug 2021 10:52:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwy8RHG9N/6LO+ULKRlBjBJICaycGvYHbPMyhY/d5R4LNPqBjsKKKvMem64sOo8pUjl5Ekp X-Received: by 2002:a05:6402:270a:: with SMTP id y10mr6327445edd.385.1628617936087; Tue, 10 Aug 2021 10:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617936; cv=none; d=google.com; s=arc-20160816; b=0yqEkopQoOzdZTSEPRNcXwGiUiO4ecaq1rWF4bo1Tw1RdHMefIQ8LvxVj1Ltvcdy9X r/tqYCQ15CZpthcfyntCvr3k3dAZbb/Iu/gMjtNZbOG3z7fKbAafgiGTJgptt4RNs6Mk 6SDN8tLXc92yM3eFqm2qhLIEsYqExS4OJUev8oHwIYx8c2Z9yavd3HeYMeNOLC1E3rvb DYxTj8W34G45NL+kNuBM/XrF0sOE7u5PmfCQTjRnk1Tw9O94sB9ctPZS9WKY6d+rcQ9K DuwUNhoG+csiXa67VEHlrnTU5PwJFn0RxoD2NaRAPp6E7FVch9G+2ivE22DFrfA8HcHW Si4Q== 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=YbHHP4eJtFri5OPve2ett1Udcu059IGI10S6K4162UM=; b=JQ9oZVnWk8rLnIPg3OE2poGMp3JgHwuLO/We7blMybK2/WRJYg7q9SqU+QT+joMX+Z X/YbsUK3lm9AfLV2tH2njRafqDIJxTbayi6M32w0GrdCiPs3FPYaMfR64tznJ6mZ67EL jQvwJP+dgm9Y5LvFxc5b6dV/njkIDm0nhtOiWQwZBBFKmhhzkg5vNgIzltk7MCgF/14K M4MjMe5cxsdB7cMbqSD2uB0c6kJezRh7nJga5Fq5zHFpu14AFZGVMx4hUrjCAVm5qnM/ lkZStDqNroyTyxnJBo87R0zmtiYWXi+xOSzGufbQMF2agANDgPQIHW782mX98limWmbi nHKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hVQDRjTG; 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 g19si21446925edu.345.2021.08.10.10.51.52; Tue, 10 Aug 2021 10:52:16 -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=hVQDRjTG; 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 S231764AbhHJRsn (ORCPT + 99 others); Tue, 10 Aug 2021 13:48:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:55284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233281AbhHJRpl (ORCPT ); Tue, 10 Aug 2021 13:45:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7EAF261186; Tue, 10 Aug 2021 17:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617214; bh=/kwpo/cSIaEC2/+z2mB9+r8r9J8AzJ7XqK5n5Wv4JlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVQDRjTGH2/bTih4OH/Vuxuc1fD3ZH3Fkg8x95puhdd/M0TkjljGzy6mgJD5sDJUk tDaCPwQXq9nMRZvTwKV09qrWMgVhkzNWJpS2ag7pQNSf/kOZIG6x9dgoPtJKLABMIT VEZ2YTjru/O3QjcM7YBoi5/fVkOQUpUt57wAb9Ms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhiyong Tao Subject: [PATCH 5.10 095/135] serial: 8250_mtk: fix uart corruption issue when rx power off Date: Tue, 10 Aug 2021 19:30:29 +0200 Message-Id: <20210810172958.989866987@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@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 @@ -93,10 +93,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; @@ -120,6 +123,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)