From patchwork Mon Dec 8 20:28:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: 'Timothy Arceri' via Patchwork Forward X-Patchwork-Id: 42021 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3637D202E0 for ; Mon, 8 Dec 2014 20:28:17 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf3170554wgh.5 for ; Mon, 08 Dec 2014 12:28:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:reply-to:to:cc:message-id :subject:mime-version:content-type:content-transfer-encoding :content-length:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=UfgtAE/pL9DjLB0BfZjjb1dHPEX5d7QMovMBMztTa4U=; b=UGVgYHSnzg+tqLUArE0MwP2ufEY3EeOdYeyV6EzkMwEt2HvAhN/vQ17Nvfrg4hUctz w9x+N2j1joLpPIlcGhzWd1lS9zIJ9Fl9pKrjKHIbT3v3otSzmvGVqbo+ysTkRi+tlepP irhWEgRWZekzpjn/TUlHTYrtG5ZLDbRmpsuSVKkP3wjRu+u3cV2tP3P2KRc8S93zurSr WYsnQam787YbqbpX4OPBUC6W5FLddwsWd9+zMh8FPYVHIQULi96ulEh2ixOvbsdcHBQc l0VY+ae9KfYPasC+t208tNUnDoNO6Rjwd1DvLdLVHSUEXCPVNm/YvOzhAbO9DDE6yLA5 k+7w== X-Gm-Message-State: ALoCoQlImJWAVo2a99/qlUsELkjg4RCaneIx1cqTZxoN5OtNDQZxAuFffuj/kC+p1se8WaxT193d X-Received: by 10.112.130.8 with SMTP id oa8mr674986lbb.11.1418070496521; Mon, 08 Dec 2014 12:28:16 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.227 with SMTP id u3ls689997laa.109.gmail; Mon, 08 Dec 2014 12:28:16 -0800 (PST) X-Received: by 10.152.30.100 with SMTP id r4mr18079815lah.58.1418070496341; Mon, 08 Dec 2014 12:28:16 -0800 (PST) Received: from mail-lb0-x235.google.com (mail-lb0-x235.google.com. [2a00:1450:4010:c04::235]) by mx.google.com with ESMTPS id ec6si16490227lbc.17.2014.12.08.12.28.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 12:28:16 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::235 as permitted sender) client-ip=2a00:1450:4010:c04::235; Received: by mail-lb0-f181.google.com with SMTP id l4so4475102lbv.12 for ; Mon, 08 Dec 2014 12:28:15 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr17946036lbo.32.1418070495923; Mon, 08 Dec 2014 12:28:15 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp666062lbc; Mon, 8 Dec 2014 12:28:14 -0800 (PST) X-Received: by 10.66.228.131 with SMTP id si3mr58132798pac.32.1418070493276; Mon, 08 Dec 2014 12:28:13 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id js5si61528279pbc.100.2014.12.08.12.28.12 for ; Mon, 08 Dec 2014 12:28:13 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754257AbaLHU2K (ORCPT + 27 others); Mon, 8 Dec 2014 15:28:10 -0500 Received: from nm43-vm7.bullet.mail.bf1.yahoo.com ([216.109.114.238]:37979 "EHLO nm43-vm7.bullet.mail.bf1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751119AbaLHU2I convert rfc822-to-8bit (ORCPT ); Mon, 8 Dec 2014 15:28:08 -0500 Received: from [98.139.212.149] by nm43.bullet.mail.bf1.yahoo.com with NNFMP; 08 Dec 2014 20:28:07 -0000 Received: from [98.139.212.243] by tm6.bullet.mail.bf1.yahoo.com with NNFMP; 08 Dec 2014 20:28:07 -0000 Received: from [127.0.0.1] by omp1052.mail.bf1.yahoo.com with NNFMP; 08 Dec 2014 20:28:07 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 646512.13460.bm@omp1052.mail.bf1.yahoo.com X-YMail-OSG: Cy2Y_ZcVM1mNrncXfl5oDxFLoHSfyDhrKVHoXMdXP2FlCJE2yx3zGg9.Gn1.IQR .i9qBfY3n7UUAnN_qBdCpAzcXXnvJFUx4vGhhmPJ8NOhXrc9DToWm9JUsYjFf_zYHCzKORDJBHfA dMhShyaTm1Fr4ovBWuDVMMdBSahzTJVge2E55V4m_hcUNyA2j5Dy8quFrmqvgBH0cP913uy86gwy JUWwF2M6.rvmzfCW79m0eRT49gT.q4rJGNLe7dsdNqbpciDG1KY9ONcxVL2RiuU_gOTRh9MU9wk3 ZhkvHURUjxQmFppE6P4604qsx_fLeBKi8jNE81PI6vNQ9cYWfG7naG751woahduBUYbMqyEnWRYV vgXhbMztghUIMwMTiLaDspRzTtlYOGRGM0bk1SX7eZX_i1Joca_SQXlI1cDnCxVFhKYgjLZPaaPb tyNalBBjb2_NOD68l.qr28Qkjpl_zhOB9.ddMh1wZwPawZV8gj9zg.R3HadKpp0H2FcOld7CzjC6 qgjwRgiEAuoyva0GZjBikhIM_CpX_T5BB7ur_CYd6WiZD Received: by 76.13.27.50; Mon, 08 Dec 2014 20:28:07 +0000 Date: Mon, 8 Dec 2014 20:28:00 +0000 (UTC) From: "'Denis Du' via Patchwork Forward" Reply-To: Denis Du To: "gregkh@linuxfoundation.org" , "jslaby@suse.cz" Cc: "linux-kernel@vger.kernel.org" Message-ID: <694700710.6880446.1418070480521.JavaMail.yahoo@jws10627.mail.bf1.yahoo.com> Subject: [PATCH] TTY: missing a lock to access the ldisk buffer MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: dudenis2000@yahoo.ca X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::235 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@; dmarc=fail (p=NONE dis=NONE) header.from=yahoo.ca Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , X-Original-From: Denis Du Hi, Guys: I found that the 3.12 kernel tty layer will lose or corrupt data when having a full-duplex communication, especcially in high baudrate, for example 230k for my OMAP5 uart. Eventually I found there is a lock missing between copy data to ldisc layer buffer and copy data from the same buffer to user space. I believe this issue have been existing since 3.8 kernel(since this kernel , it start to remove most of the spin-locks) and I didn't find any fix even through 3.17 kernel. This patch was tested to be works great with no any data loss again. I did try to use the existed lock atomic_read_lock, but it doesn’t work. Signed-off-by: Hui Du --- the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ --- drivers/tty/n_tty.c 2014-10-16 16:39:35.909350338 -0400 +++ drivers/tty/n_tty.c 2014-10-16 16:49:00.004930469 -0400 @@ -124,6 +124,7 @@ struct mutex atomic_read_lock; struct mutex output_lock; + struct mutex read_buf_lock; }; static inline size_t read_cnt(struct n_tty_data *ldata) @@ -1686,9 +1687,11 @@ char *fp, int count) { int room, n; + struct n_tty_data *ldata = tty->disc_data; down_read(&tty->termios_rwsem); + mutex_lock(&ldata->read_buf_lock); while (1) { room = receive_room(tty); n = min(count, room); @@ -1703,6 +1706,7 @@ tty->receive_room = room; n_tty_check_throttle(tty); + mutex_unlock(&ldata->read_buf_lock); up_read(&tty->termios_rwsem); } @@ -1713,7 +1717,7 @@ int room, n, rcvd = 0; down_read(&tty->termios_rwsem); - + mutex_lock(&ldata->read_buf_lock); while (1) { room = receive_room(tty); n = min(count, room); @@ -1732,6 +1736,7 @@ tty->receive_room = room; n_tty_check_throttle(tty); + mutex_unlock(&ldata->read_buf_lock); up_read(&tty->termios_rwsem); return rcvd; @@ -1880,6 +1885,7 @@ ldata->overrun_time = jiffies; mutex_init(&ldata->atomic_read_lock); mutex_init(&ldata->output_lock); + mutex_init(&ldata->read_buf_lock); tty->disc_data = ldata; reset_buffer_flags(tty->disc_data); @@ -1945,6 +1951,8 @@ size_t tail = ldata->read_tail & (N_TTY_BUF_SIZE - 1); retval = 0; + + mutex_lock(&ldata->read_buf_lock); n = min(read_cnt(ldata), N_TTY_BUF_SIZE - tail); n = min(*nr, n); if (n) { @@ -1960,6 +1968,7 @@ *b += n; *nr -= n; } + mutex_unlock(&ldata->read_buf_lock); return retval; } @@ -1990,6 +1999,8 @@ size_t tail; int ret, found = 0; bool eof_push = 0; + + mutex_lock(&ldata->read_buf_lock); /* N.B. avoid overrun if nr == 0 */ n = min(*nr, read_cnt(ldata)); @@ -2049,6 +2060,8 @@ ldata->line_start = ldata->read_tail; tty_audit_push(tty); } + + mutex_unlock(&ldata->read_buf_lock); return eof_push ? -EAGAIN : 0; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in