Received: by 10.213.65.68 with SMTP id h4csp2118068imn; Sun, 8 Apr 2018 20:09:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx48f8apWUpgPpEz+YORb1RSDXBJNOO91RIePQNzKN5eo4Uco5583TdTSk8IIjkXrngT1fEMo X-Received: by 10.101.64.139 with SMTP id t11mr24229905pgp.119.1523243357795; Sun, 08 Apr 2018 20:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243357; cv=none; d=google.com; s=arc-20160816; b=FYe+OylF/z0tRkojqi4ZyjBIEiAv5J1PyapXScRArBPfcFOv79yAwH1MRM+CLIapsg jM6XMhOHUiyG4YFh+tKQMjaP5sP1eCdH4QezwL3jILnT81bv/blHdN+FfuVt61TdLBRc s8Ck2kz48Y1OazzyabX8g8mdf81NJ3jMfiG7nbEJmB9EtSNJk0PHl/RoOG9txDR0IXu6 p57mtvB+L9lV1VmrTDkhSHWlPlG+uSVDOnVWrJAG/GU/w5i1tM36E/yqjsMB0V+cqgOt k75/FdUMrAIntHjuWOET+SlwnmLq1DaiQQbMFXywTlgswqmHqQjquHzYQ3sI8QR/RbhZ p6Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=68oLYEp+XeKVoRdb3x8QRtYhM2N5IRF9Roxa/S9Ny3k=; b=uA8c8y/a4RcLR2jFwDAAb10uImTu8H7AAQqzr6BnIsz9r8bnr8+eyrfbW1jdnzSn+C n3E6BcW4gaX27SjoXUo4ZuEEf1nRS9/paADw259sqTKAIpSpPH+YsPlVHeRMPykkwt2+ PnIppsN3Bh65xeUHS4VmBdIMyBBSZuxlZGEkm6ODg/T8Wfy6laACYYw9Z097COQEuYWp igJAYEJdZ/4o0ENQCep4GBrgxwxrjdJq8KxDcwKCVQOazLkObsPrJqxvngMl18y9uyaU wAqozxUrBlPzLQCc4PcMQO9szgzPX51o0EJXihZSKnGECjKP4Cu8x+lGyY/dQTBKF/Il 2qyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AYVwRDWN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v45si10655232pgn.379.2018.04.08.20.08.40; Sun, 08 Apr 2018 20:09:17 -0700 (PDT) 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=@microsoft.com header.s=selector1 header.b=AYVwRDWN; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757823AbeDICGS (ORCPT + 99 others); Sun, 8 Apr 2018 22:06:18 -0400 Received: from mail-cys01nam02on0107.outbound.protection.outlook.com ([104.47.37.107]:40886 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756297AbeDIAb3 (ORCPT ); Sun, 8 Apr 2018 20:31:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=68oLYEp+XeKVoRdb3x8QRtYhM2N5IRF9Roxa/S9Ny3k=; b=AYVwRDWNSQKMaep9sHrNRNMoG6SYBbsRtcrlCrLc2hBZBQ4EawJbcJw05u1pXAFZcthUis2oH7QvvfhKhAlxHPlNOLvWAO8sex0PRsiR56Ia2Jn///y9apbivm79dKpgZNgrQncHPvUHhqS2RP4IWCLo6HB9FSp2yjw/Fgq3P84= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1126.namprd21.prod.outlook.com (52.132.132.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:31:23 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:31:23 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Vignesh R , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 179/293] serial: 8250: 8250_omap: Fix race b/w dma completion and RX timeout Thread-Topic: [PATCH AUTOSEL for 4.9 179/293] serial: 8250: 8250_omap: Fix race b/w dma completion and RX timeout Thread-Index: AQHTz5k6LegX0UAFuECx3eTRdcWr6A== Date: Mon, 9 Apr 2018 00:25:14 +0000 Message-ID: <20180409002239.163177-179-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1126;7:Pe1JO/uCfaMdnn7/2WksNZi9zC0/zJzTo76j9cijO0+lxToBk0COv2AKAA6hndl1l3TJXMgX6Yb8nntwOteNAaV9jxbU0CQyANElz0BhaX1X8CMlhpqWDDwOfxFOn1OKuLs/JloCesQNumqQkAOh7wppWJyxFUMoePxbVD5e+9s1bAAzNgh2MLRxaboOiS6JXVg+dfY8Pn7zmfjeuQKU/P8R6f1tWMFZMwTWS0OXZUiYCFqA4LcqiW8YZSEBrdZx;20:bLqH3e80eRCKSScd3nUFAOeePYL10CXiFetvfd4l5766jwibkZMizYY6LBwrO58cdC3yr1zh3uO30d+/v1kqqEtlhydTxrbjal4SV+3ZxL/+JN3sVVTdH5BNsSOBWVh4NoHyiZ88sbf8Ohl5sYr1Vf+OzctEWXSJnw6jtJu6Ki8= X-MS-Office365-Filtering-Correlation-Id: a6359547-89ab-4b67-8f03-08d59db1390d x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1126; x-ms-traffictypediagnostic: DM5PR2101MB1126: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(31051911155226)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1126;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1126; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(39380400002)(396003)(39860400002)(346002)(376002)(189003)(199004)(2616005)(476003)(81156014)(8676002)(81166006)(3846002)(486006)(2900100001)(6436002)(186003)(478600001)(72206003)(110136005)(54906003)(2906002)(86612001)(6666003)(2501003)(26005)(10090500001)(102836004)(6512007)(6116002)(14454004)(5250100002)(10290500003)(1076002)(575784001)(446003)(3280700002)(3660700001)(11346002)(8936002)(25786009)(59450400001)(6506007)(106356001)(4326008)(107886003)(36756003)(105586002)(53936002)(86362001)(66066001)(6486002)(99286004)(5660300001)(316002)(22452003)(305945005)(76176011)(97736004)(68736007)(7736002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1126;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: qYrKe82pF6R5+5cPERH5MynJDtPivNLHZJQHaBcafBqPiSgwONMAWiHGO4Ra/Dlr1sTpDAn2AuRo+xMCkFCXEMJ6yeIrTKxQjwXByrGGM1ssr3cKlhjXPvtYxR/ipV1z4px6H2Ic3BtmJAE9rnWdhOaDtGCA/edFr1cxZHGA39bVRj2Izs5rop31aEqWge4tipHQSuLY3vKz8NRplmlFA19hMBLLfMtcGYVZd0rQP/41KS6UvzzL9Y5TBtA08OZzzhn0efhHqMPPdDUiN/xmzaUJ1bQlBT5MONzb6k3DsuaTgJbSTuXJ0vhMDU8erQ98aOyybtXQDGhMhY9cXw61NDNbnBkrfkkbwfVys93MeX/3GWg3rqKYYTkyKkckfCW7zrgNx6v1505g7sIvdppimdEMLOGIeby+5J2ZkiCTkdo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6359547-89ab-4b67-8f03-08d59db1390d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:25:14.7064 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1126 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vignesh R [ Upstream commit a1bfb6eb300d008decfbcdf13b0fda536d22dea9 ] DMA RX completion handler for UART is called from a tasklet and hence may be delayed depending on the system load. In meanwhile, there may be RX timeout interrupt which can get serviced first before DMA RX completion handler is executed for the completed transfer. omap_8250_rx_dma_flush() which is called on RX timeout interrupt makes sure that the DMA RX buffer is pushed and then the FIFO is drained and also queues a new DMA request. But, when DMA RX completion handler executes, it will erroneously flush the currently queued DMA transfer which sometimes results in data corruption and double queueing of DMA RX requests. Fix this by checking whether RX completion is for the currently queued transfer or not. And also hold port lock when in DMA completion to avoid race wrt RX timeout handler preempting it. Signed-off-by: Vignesh R Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_omap.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/= 8250_omap.c index da31159a03ec..d0a129aeae29 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -782,8 +782,27 @@ unlock: =20 static void __dma_rx_complete(void *param) { - __dma_rx_do_complete(param); - omap_8250_rx_dma(param); + struct uart_8250_port *p =3D param; + struct uart_8250_dma *dma =3D p->dma; + struct dma_tx_state state; + unsigned long flags; + + spin_lock_irqsave(&p->port.lock, flags); + + /* + * If the tx status is not DMA_COMPLETE, then this is a delayed + * completion callback. A previous RX timeout flush would have + * already pushed the data, so exit. + */ + if (dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state) !=3D + DMA_COMPLETE) { + spin_unlock_irqrestore(&p->port.lock, flags); + return; + } + __dma_rx_do_complete(p); + omap_8250_rx_dma(p); + + spin_unlock_irqrestore(&p->port.lock, flags); } =20 static void omap_8250_rx_dma_flush(struct uart_8250_port *p) --=20 2.15.1