Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbeAENgc convert rfc822-to-8bit (ORCPT + 1 other); Fri, 5 Jan 2018 08:36:32 -0500 Received: from www.llwyncelyn.cymru ([82.70.14.225]:50738 "EHLO fuzix.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751422AbeAENga (ORCPT ); Fri, 5 Jan 2018 08:36:30 -0500 Date: Fri, 5 Jan 2018 13:36:09 +0000 From: Alan Cox To: "Kohli, Gaurav" Cc: jslaby@suse.com, gregkh@linuxfoundation.org, mikey@neuling.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] tty: fix data race in n_tty_receive_buf_common Message-ID: <20180105133609.636b2d1f@alans-desktop> In-Reply-To: <999c5499-05c7-4702-77a7-dfb56ba577d2@codeaurora.org> References: <1514987332-14122-1-git-send-email-gkohli@codeaurora.org> <20180103193807.465e054e@alans-desktop> <0a456419-c836-08cf-070b-a254fb702b75@codeaurora.org> <20180104110920.169a1fe5@alans-desktop> <0dbd1f05-4c94-d1cc-3858-7bd4d38b9212@codeaurora.org> <20180104143716.5b09b1c7@alans-desktop> <93a7bd73-1123-90a7-b22d-02964ba29fb0@codeaurora.org> <999c5499-05c7-4702-77a7-dfb56ba577d2@codeaurora.org> Organization: Intel Corporation X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Fri, 5 Jan 2018 13:15:45 +0530 "Kohli, Gaurav" wrote: > Hi Alan, > >>> > >>> Can you make that code available otherwise it's impossible to see > >>> what the problem might be. > > > > >  https://source.codeaurora.org/quic/la/kernel/msm-4.9/tree/drivers/tty/serial?h=msm-4.9 >  As discussed , there not seems a problem as we are getting print > request even when port seems to closed. > > > tty_ldisc_lock(tty, 5 * HZ); >  tty_ldisc_setup(tty); >  tty_ldisc_unlock(tty) > > But in above lock,  there is a chance when flush_to_ldisc will occur > first and acquired a lock in > tty_ldisc_ref itself. Which is fine. If the flush_to_ldisc gets there first then it will find there is a NULL ldisc and do nothing. When it finishes the tty_init_dev will run and will be protected from a further re-entry. If the init_dev gets there first it will complete the init before the flush_to_ldisc is permitted to proceed. In other words we restore the intended invariant that ldisc's do not get entered while their setup routine is running. Alan