From patchwork Tue Jul 28 07:56:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 6880051 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5F175C05AC for ; Tue, 28 Jul 2015 07:57:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D3697206BE for ; Tue, 28 Jul 2015 07:57:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 625BC20674 for ; Tue, 28 Jul 2015 07:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754843AbbG1H5Z (ORCPT ); Tue, 28 Jul 2015 03:57:25 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:59731 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754836AbbG1H5V (ORCPT ); Tue, 28 Jul 2015 03:57:21 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie1.idc.renesas.com with ESMTP; 28 Jul 2015 16:57:20 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 519AB4B947; Tue, 28 Jul 2015 16:57:20 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 3091C480A4; Tue, 28 Jul 2015 16:57:20 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 2B6CF480A3; Tue, 28 Jul 2015 16:57:20 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac4.idc.renesas.com with ESMTP id SAF06952; Tue, 28 Jul 2015 16:57:20 +0900 X-IronPort-AV: E=Sophos;i="5.15,561,1432566000"; d="scan'";a="191263114" Received: from mail-hk2apc01lp0207.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.207]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 28 Jul 2015 16:57:19 +0900 Authentication-Results: glider.be; dkim=none (message not signed) header.d=none; Received: from [10.166.13.234] (211.11.155.144) by SIXPR06MB0923.apcprd06.prod.outlook.com (10.162.173.158) with Microsoft SMTP Server (TLS) id 15.1.219.17; Tue, 28 Jul 2015 07:57:16 +0000 Message-ID: <55B735C2.2030905@renesas.com> Date: Tue, 28 Jul 2015 16:56:50 +0900 From: Yoshihiro Shimoda User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Geert Uytterhoeven CC: Magnus Damm , Laurent Pinchart , Nobuhiro Iwamatsu , Yoshihiro Kaneko , Kazuya Mizuguchi , Koji Matsuoka , Wolfram Sang , Guennadi Liakhovetski , Subject: Re: [PATCH/RFC v2 00/29] serial: sh-sci: Miscellaneous and DMA Improvements References: <1437070920-28069-1-git-send-email-geert+renesas@glider.be> In-Reply-To: <1437070920-28069-1-git-send-email-geert+renesas@glider.be> X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS1PR01CA0022.jpnprd01.prod.outlook.com (25.161.225.160) To SIXPR06MB0923.apcprd06.prod.outlook.com (25.162.173.158) X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0923; 2:jsyC460VVDuyKf9+5ovkDtxnYJuWfw/+EG9ct5aK9jzVf0fqjsF3Xa9z136ENzD+; 3:zG8DkZ6UtVH78I6hJDoIgQSwJ+D0gpAoxhl9LcPY3gp9iW/LINUl8cgoDLnzzI/xdTkoUW+2u7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a0vhXGIsnZ08KXhEluSpn7Bhq8vtYek/L0x5v6hLz8HSYy5cxCtkC91nLNuxlfLElewcfl1wcBOnzmfjJGQcdvHSyXuON8KXPglsx+QApisk6HlM2Mz3+OxryWJWW8EX4YC+v+fc4q5P9uSBW9TjPLYVAl9b95mPHkjt4a+BabGbjIO55p9FlL4yKdY= SIXPR06MB0923: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:SIXPR06MB0923; BCL:0; PCL:0; RULEID:; SRVR:SIXPR06MB0923; X-Forefront-PRVS: 06515DA04B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(6049001)(53754006)(479174004)(24454002)(51234002)(19580395003)(65806001)(110136002)(65816999)(4001350100001)(66066001)(92566002)(5001960100002)(80316001)(86362001)(575784001)(19580405001)(46102003)(77096005)(47776003)(64126003)(77156002)(2950100001)(23756003)(62966003)(59896002)(189998001)(36756003)(33656002)(40100003)(76176999)(122386002)(50986999)(42186005)(83506001)(50466002)(54356999)(7059030); DIR:OUT; SFP:1102; SCL:1; SRVR:SIXPR06MB0923; H:[10.166.13.234]; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1; SIXPR06MB0923; 23:biosQ9S0JPzG6Wr7Anqcek6Vguo8C9Lons5JpwE?= =?iso-8859-1?Q?z8N/juYhkRc1nGTLpZ8a6EbkU0bNkbgL4fRFRwQxKwnCKdSoCuF2csbbH9?= =?iso-8859-1?Q?2oFHKjHc8Pnq4eBf4YqYKXGHi95jn8uMErVfV7TE3PqI7QEjHng28ZJwhz?= =?iso-8859-1?Q?/EQ9qzrPni0EP50xu6ZEAu/cTYJoCjXVUJUlKo1fe+TQuSfzLDJ4zf8Ln3?= =?iso-8859-1?Q?yzRE7PKYhTARc2TuKu7VgmypmmGIOOtoHyDsUde+Nu/vrn46puy4ano65V?= =?iso-8859-1?Q?LKvrJWT+eJuXS5yZIqW0OXQxHEH8UqrAujlEJAQAVBL4mmNJ0OHsFniE3K?= =?iso-8859-1?Q?aEdUNcfynr1H+M2M139D+vBPucj0WXbtbiOizpuktdToxMhi3LtZBNveDI?= =?iso-8859-1?Q?B1yVd/JkfatdwYsOORWLOJCTwN1G7NM7dq4qK46ECQZLKWi1Dppe38jX4O?= =?iso-8859-1?Q?R1hiA3tKiLi9e/OwUc/F2zW/UaC5W1PWpmv8paQlvxajYeMoCd17vccpHV?= =?iso-8859-1?Q?HRzyUgMx/eYim3AX2Sy1qeSsdGJqhcNry1bLhEdwP56YnQfojBZhKbW3Hk?= =?iso-8859-1?Q?mdk2zqXnbNiHndaLBkonSCYtqfAozFQ5llQpiAa4jgqU4RWIVTQXFfTokV?= =?iso-8859-1?Q?6OILRa5eNSXIqbwDWgcGyAc7fqi/v2yILagAbXt9CKqOGSbLeE7IiuZcOr?= =?iso-8859-1?Q?s/Elys5qgvFTYewHM5+stoUwsphbrmQZMkAJmfh/8+QKFlWAANSpgI3PAF?= =?iso-8859-1?Q?VeAh994hBvfBQoFFkJ1bh+Z5MYOvQVXYfO9d4QJ9+3880t2+sft5KXM+VM?= =?iso-8859-1?Q?H9C3TIqmz9KxH1Ry7GbkZyl+WKwy0gzftInbbsBLsvl23NItf7JSFLDxzS?= =?iso-8859-1?Q?s7SlN5V4Xaxh98AhdS/MFSIqI/fIfHJhVPkD+gQdSkb+v/37LumvmFpbXG?= =?iso-8859-1?Q?fXat1vCmqNtcn3CWEvOmyZUR8Jlc10o2anTWVj3MtvYvNwfgdPt8NFI8SW?= =?iso-8859-1?Q?2r7rDLlMj1w6bmPpEcceOdgh/nfEv6vg9csJa9M1PuGUvDMaK4chtJgf2j?= =?iso-8859-1?Q?3D6G4NiYItmV7/8wH2ImA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; SIXPR06MB0923; 5:ieqXHFJB5yKONw5Qy7z916rNUwgPHYMu76ACaqkHtDC/N0BXbr193nHz8B7zI6BHFkfcGL8EQ4Kipj8yN8qGRZvf/sZ/ERilpwhUZGYBW8Rsm8TfTi0eNdVqeKuxj/B5hT3F/IVoq+Ne1zxYASCKkw==; 24:E6mPNhXSjTqmE3f0QffB8lAYFlcUG2kNZIgwcpzTIaUKS6OGern0ZQPDZap47JwnV4UpPIQvz9KowivZx7Iutc3KtKMbO+xFwaQdEii7gvU=; 20:+nrGan3NcbWZka8dLATPSdevpJBZCSiHOeracGOKxZBQdmPTjKFEvr5kg9cnaGlrzwuO7e5sC2wFpdd0/dKCcGX+BRRCIvWQKJSdOsCotOq1P8sATkMclVpwidbGd7kTZ44OcAUpJ1xAcokdOvhDl/SRNUzTUEFD8hiIEHxjeIM= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2015 07:57:16.1925 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SIXPR06MB0923 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Geert-san, Thank you for the patches! (2015/07/17 3:21), Geert Uytterhoeven wrote: > Hi all, > > This patch series contains various updates for the Renesas > (H)SCI(F{,A,B}) driver, incl. DMA support for SCIF on R-Car Gen2. > Some of these patches have been sent before. (Few) Changes are indicated > in the individual patches. > > This is definitely not a final series, that's why it's marked as RFC and > sent to a limited audience: > - There are still some race conditions between e.g. RX DMA > completion(s) and the worker function, > - Under high load RX DMA breaks, > - The patch to add DT DMA support should be last, after all DMA fixes, > to avoid regressions, > - Unlike the old shdmac DMA engine driver, the new rcar-dmac DMA > engine driver does not support resubmitting a DMA descriptor, so I > added a workaround to the sh-sci driver, > - This won't work with the old shdmac DMA engine driver anymore, due > to the lack of residue handling in shdmac (preliminary untested > patch sent, but it will need more work), > - There are issues with residual handling in general, > - ... > > However, DMA is now usable for the serial console on r8a7791/koelsch. > This also received light testing with scif3 and scifa5 on r8a7791/koelsch. > > For your convenience, I've also pushed this to > git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git#scif-dma-v2 > > Thanks for your comments! I tested this scif-dma-v2 branch using r8a7790/lager. If I enabled CONFIG_HIGHMEM, a WARNING and kernel panic happened. (I copyed the log at end of this email.) I investigated this issue and I could fix this issue using the following patch. The patch can be applied on the top of your scif-dma-v2. If possible, would you check the patch and merge your patch set to v3? --- Subject: [PATCH] serial: sh-sci: Fix NULL pointer dereference if HIGHMEM is enabled From: Yoshihiro Shimoda This patch fixes an issue that this driver causes a NULL pointer dereference if the following conditions: - CONFIG_HIGHMEM and CONFIG_SERIAL_SH_SCI_DMA are enabled - This driver runs on the sci_dma_rx_push() This issue was caused by virt_to_page(buf) in the sci_request_dma() because this driver didn't check if the "buf" was valid or not. So, this patch uses the "buf" from dma_alloc_coherent() as is, not page. This patch also relves a WARNING issue that this driver runs on the sci_rx_dma_release(). Signed-off-by: Yoshihiro Shimoda --- drivers/tty/serial/sh-sci.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 7e8fa37..e1ac4c3b 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -113,6 +113,8 @@ struct sci_port { struct scatterlist sg_tx; unsigned int sg_len_tx; struct scatterlist sg_rx[MAX_BUF_RX]; + void *rx_chunk; + u8 *rx_buf[MAX_BUF_RX]; unsigned int total_buf_len_rx; unsigned int nr_buf_rx; struct work_struct work_tx; @@ -1307,8 +1309,7 @@ static void sci_dma_tx_complete(void *arg) } /* Locking: called with port lock held */ -static int sci_dma_rx_push(struct sci_port *s, struct scatterlist *sg, - unsigned int count) +static int sci_dma_rx_push(struct sci_port *s, u8 *buf, unsigned int count) { struct uart_port *port = &s->port; struct tty_port *tport = &port->state->port; @@ -1323,7 +1324,7 @@ static int sci_dma_rx_push(struct sci_port *s, struct scatterlist *sg, return room; for (i = 0; i < room; i++) - tty_insert_flip_char(tport, ((u8 *)sg_virt(sg))[i], TTY_NORMAL); + tty_insert_flip_char(tport, buf[i], TTY_NORMAL); port->icount.rx += room; @@ -1357,7 +1358,7 @@ static void sci_dma_rx_complete(void *arg) active = sci_dma_rx_find_active(s); if (active >= 0) - count = sci_dma_rx_push(s, &s->sg_rx[active], + count = sci_dma_rx_push(s, s->rx_buf[active], sg_dma_len(&s->sg_rx[active])); mod_timer(&s->rx_timer, jiffies + s->rx_timeout); @@ -1385,8 +1386,7 @@ static void sci_rx_dma_release(struct sci_port *s, bool enable_pio) s->cookie_rx[i] = -EINVAL; if (sg_dma_address(&s->sg_rx[0])) { dma_free_coherent(chan->device->dev, s->total_buf_len_rx, - sg_virt(&s->sg_rx[0]), - sg_dma_address(&s->sg_rx[0])); + s->rx_chunk, sg_dma_address(&s->sg_rx[0])); sg_dma_address(&s->sg_rx[0]) = 0; } dma_release_channel(chan); @@ -1491,7 +1491,7 @@ static void work_fn_rx(struct work_struct *work) dev_dbg(port->dev, "Read %zu bytes with cookie %d\n", read, s->active_rx); - count = sci_dma_rx_push(s, &s->sg_rx[new], read); + count = sci_dma_rx_push(s, s->rx_buf[new], read); if (count) tty_flip_buffer_push(&port->state->port); @@ -1823,12 +1823,13 @@ static void sci_request_dma(struct uart_port *port) return; } + s->rx_chunk = buf; for (i = 0; i < s->nr_buf_rx; i++) { struct scatterlist *sg = &s->sg_rx[i]; sg_init_table(sg, 1); - sg_set_page(sg, virt_to_page(buf), buflen[i], - offset_in_page(buf)); + s->rx_buf[i] = buf; + sg->length = buflen[i]; sg_dma_address(sg) = dma; buf += buflen[i];