From patchwork Fri Mar 17 15:11:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 740350 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vl82s0n0Gz9ryZ for ; Sat, 18 Mar 2017 02:12:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="W1rMY0OD"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bhHtcpQm"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:References:To:Subject:From:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n6pr9dzBfSwgq3IQVPON5W3Zr7PL0uGugFHCjfj5uvg=; b=W1rMY0ODXUDXJ8 uKQTsRHsVJCJrbuKnnHkvRV7MCBmfsW14lyh1U3EW7+yJkok0QxLkP85uK+dt0O0w4BTwC+V+J3zy 8jkKb9+n21fB9n08U3GhKeZESBUdVXeN6dIRwtiRdzfxA82EWT0ZzfT668mGZt04yNzLmyrmGhPkF etl8KBRXxEqjBgr4srknVAl7G43DuGHDSW4UVBaZHZPUWSWzN3NLchpgExGIbwru7edJZ5kI7eirv coaDpGLiNS4kDQNzdx8aZW5u418b7Tpsew7FIw2EMqsklPbPw7KI/LmEYp6tXk89COeRZueleiADi steY/TCyGPnlfs1CJy4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cotY8-0003oh-UX; Fri, 17 Mar 2017 15:12:16 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cotY5-0003e0-27 for linux-arm-kernel@lists.infradead.org; Fri, 17 Mar 2017 15:12:14 +0000 Received: by mail-wr0-x241.google.com with SMTP id l37so9902502wrc.3 for ; Fri, 17 Mar 2017 08:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=MM35Yp9WTBCB+PMFdtuJb5hGF0p0EaYMge9gXQRa/xo=; b=bhHtcpQmTWnDeHNUhbf4qHhTSmbG8y5on2QXzVP+X6LgI9wmvGO2ET4J7vzSmbGmVg L8re9NIj2MgVS0JwQBXhBFr8D05Dq5MCKDVeZjSuVguS9mAFAUrh/L+tAFV2l1YgFVpf QYfT/TUibr1rhR9p7v6LVX/TD5iYELW+UM1eJYtZ5Bo2JMBD7Ub0KViHNYtrNc8DgRwj rA8mqLIpGjqfP62GUfUjW/m3qbdJNde5QErPiKK3XpTHHqXbDPyTugIQkjbhWkCP2Mu7 K3xVdB1o4/QCPvSULlsiypn1qUWY+fLkVz2Vufcwn4OmKKHLNJPTh1yXPUhWxCZ0Wo62 uQUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=MM35Yp9WTBCB+PMFdtuJb5hGF0p0EaYMge9gXQRa/xo=; b=IFjo7uvHzUVzB16P8dEn1fUYqFvGDYqugeUwf/6ONt2j6v6TJ64PxLHHy5JHidOzQx O3pDU5S7Dq10xtx1F4lCOcHeh5U7DWIYq5V7+P+rO4YIrB9RR5A+6hT1IPAvSFs0nVxS tUV8skZzT9giYcLj85dUEsDqjzLeUldgqkaf5cHHRY+loH+kHT5FOZ3oiKp9nVEDjIAk OTY56c8i6/B90lAsVv87EZA2+O79xPN2d+dEzvxbH6KSuTj4cnZDL1uhKdLIk2qLzyiP Jkzy5O6hTzPhBR3I8/TdCYeNL3taILpQsrvHqOzoAvqbLOOWv6dfBxl7NJfGaoZoz1yC sW8g== X-Gm-Message-State: AFeK/H1LjjRlG02O7dugygFQXkS61rdpf+sh4qmHgE4m3CrdTf/jc8UfeQPpi0nEAh3Ifw== X-Received: by 10.223.136.253 with SMTP id g58mr15013331wrg.10.1489763510862; Fri, 17 Mar 2017 08:11:50 -0700 (PDT) Received: from [192.168.2.41] ([46.227.18.67]) by smtp.googlemail.com with ESMTPSA id 82sm6803869wmg.0.2017.03.17.08.11.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2017 08:11:50 -0700 (PDT) From: Richard Genoud Subject: Re: [RFC PATCH] tty/serial: atmel: fix TX path in atmel_console_write() To: Nicolas Ferre References: <20170315152948.10978-1-nicolas.ferre@microchip.com> <074d057e-4971-a325-e985-3f5046536225@gmail.com> Message-ID: <6fc2b136-3717-df85-92ec-55bb7b91971b@gmail.com> Date: Fri, 17 Mar 2017 16:11:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170317_081213_265145_CB5730CA X-CRM114-Status: GOOD ( 20.52 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (richard.genoud[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "stable # 4 . 4+" , "linux-arm-kernel@lists.infradead.org" , "linux-serial@vger.kernel.org" , "linux-kernel@vger.kernel.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org 2017-03-15 17:56 GMT+01:00 Nicolas Ferre : > Le 15/03/2017 à 17:19, Richard Genoud a écrit : >> On 15/03/2017 16:29, Nicolas Ferre wrote: >>> A side effect of 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA >>> from transmitting in stop_tx") is that the console can be called with >>> TX path disabled. Then the system would hang trying to push charecters >>> out in atmel_console_putchar(). >>> >>> Signed-off-by: Nicolas Ferre >>> Fixes: 89d8232411a8 ("tty/serial: atmel_serial: BUG: stop DMA from transmitting >>> in stop_tx") >>> Cc: stable # 4.4+ >>> --- >>> Hi Richard, >>> >>> I found this to fix the problem with system hang in my linux-4.4-at91 branch >>> (in the atmel_console_putchar() waiting loop actually). I'm open to more >>> insignt. >>> As we cannot figure out if this bit is set or not, I didn't preserve the >>> current status... >>> >>> Regards, >> >> So, I'm guessing that you may see some lines/characters printed twice on >> the screen, don't you ? > > Well, actually, I don't think so because the repetitions that I see are > probably due to open/close/open/close/re-open/... of the serial console > itself. > > Same with the line "random: udevd: uninitialized urandom read (16 bytes > read, 21 bits of entropy available)", they happen at different moment in > time => the printk log timestamping seem to indicate that they are > different. Hi Nicolas, It seems that the problem is between atmel_tx_dma() and its callback atmel_complete_tx_dma(). At some point, atmel_tx_dma() is called, does the job, and then, just before the callback is called, the xmit->head and xmit->tail pointers are set to zero (by uart_flush_buffer()) So, when atmel_complete_tx_dma() is called, it does: xmit->tail += atmel_port->tx_len; not knowing that the head and tail pointers have been reseted. => it's like there's (UART_XMIT_SIZE - atmel_port->tx_len) characters to transmit on the serial line. PS: I can trigger this bug by holding down the d key at login and then ctrl - basically, a ctrl-d just after sending text - with a rate success of about 1/5 :) Could you try this patch to see if it corrects also your system hang ? (The patch is small, but the bug hunt was a headache :)) [PATCH] tty/serial: atmel: fix race condition (TX+DMA) If uart_flush_buffer() is called between atmel_tx_dma() and atmel_complete_tx_dma(), the circular buffer has been cleared, but not atmel_port->tx_len. That leads to a circular buffer overflow (dumping (UART_XMIT_SIZE - atmel_port->tx_len) bytes). Signed-off-by: Richard Genoud Tested-by: Nicolas Ferre --- drivers/tty/serial/atmel_serial.c | 5 +++++ 1 file changed, 5 insertions(+) /* diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 833d3d80446f..89552157e334 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -1934,6 +1934,11 @@ static void atmel_flush_buffer(struct uart_port *port) atmel_uart_writel(port, ATMEL_PDC_TCR, 0); atmel_port->pdc_tx.ofs = 0; } + /* + * in uart_flush_buffer(), the xmit circular buffer has just + * been cleared, so we have to reset tx_len accordingly. + */ + atmel_port->tx_len = 0; }