mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Kohli, Gaurav" <gkohli@codeaurora.org>
To: Alan Cox <gnomes@lxorguk.ukuu.org.uk>
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
Date: Fri, 5 Jan 2018 13:04:19 +0530	[thread overview]
Message-ID: <93a7bd73-1123-90a7-b22d-02964ba29fb0@codeaurora.org> (raw)
In-Reply-To: <20180104143716.5b09b1c7@alans-desktop>

[-- Attachment #1: Type: text/plain, Size: 3291 bytes --]



>

>> 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.
>>>     
>>> Ok no what I need to see is a trace of what each CPU is doing at the
>>> point you detect the problem. That way we can see what the path that
>>> races is.
>> Below is stack trace running by init in our case on one core
>> -006|n_tty_open(
>>       |    tty = 0xFFFFFFFF477AC880 -> (
>>       |      disc_data = 0xFFFFFF80197AD000,
>>
>>       |      port = 0xFFFFFFFFEDE40000))
>>       |  ldata = 0xFFFFFF80197AD000
>>
>>       |  trace_printk_fmt = 0xFFFFFF9F275125F8
>> -007|tty_ldisc_open.isra.3(
>>       |    tty = 0xFFFFFFFF477AC880)
>> -008|tty_ldisc_setup(
>>
>> -009|tty_init_dev(
>>       |    driver = 0xFFFFFFFFEDE2A480,
>>       |    idx = 0)
>>
>> -010|tty_open_by_driver(inline)
>> -010|tty_open(
> So core 1 is opening the tty from user space and that's a normal looking
> trace for an open of a port that was closed
>
>> Core 2:
>> -000|n_tty_receive_buf_common(
>>       |    tty = 0xFFFFFFFF477AC880,
>>
>>       |  ?)
>>       |  ldata_=_0x0
>>       |  __func__ = (110, 95, 116, 116, 121, 95, 114, 101, 99, 101, 105,
>> 118, 101, 95, 98, 117, 102, 95, 99, 111, 109, 109, 111, 110, 0)
>>       |  __u = (__val = 7079195495121566464, __c = (0))
>>       |  c = 127
>>       |  ldata = 0xFFFFFFFFF40DF97C
>>
>>       |  c = 0
>>       |  ldata = 0xFFFFFF9F26F46000
>>
>> -001|n_tty_receive_buf2(
>>       |    tty = 0xFFFFFFFF477AC880,
>>
>> -002|tty_ldisc_receive_buf(inline)
>> -002|receive_buf(inline)
>> -002|flush_to_ldisc(
> This is probably the important bit. As you say we are doing a flush to
> ldisc for a port even though it is not open.
>
> That's starting to make more sense. Becausee your driver is the console
> tty_port_shutdown doesn't stop everything (so console printk still
> works), and that means you can receive data and we have a window on
> reopening a tty that is only in use as a console where port->tty is valid
> but ldisc is not.
>
> I wonder what Jiri thinks but my first thougt is that tty_init_dev in
> fact needs to do
>
> 	tty_ldisc_lock(tty, 5 * HZ);
> 	tty_ldisc_setup(tty);
> 	tty_ldisc_unlock(tty)
>
> with the relevant error handling so that the flush_to_ldisc waits and
> either hits 'no ldisc' or 'ldisc valid'
>

But in above lock there is a chance, when flush_to_ldisc will occur 
first and acquired a lock in
tty_ldisc_ref

So this may fail, I am not much sure here, Please correct me if here i 
am missing something.

tty_ldisc_lock(tty, 5 * HZ);
	tty_ldisc_setup(tty);
	tty_ldisc_unlock(tty)


So can not we simply return from flush_to_ldisc ,when we know disc_data 
is not valid like
we are doing for tty and ldisc already?

if (tty->disc_data == NULL) {
                 tty_ldisc_deref(disc);
                 return;
         }

Regards
Gaurav


-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.


[-- Attachment #2: Type: text/html, Size: 5972 bytes --]

  reply	other threads:[~2018-01-05  7:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 13:48 Gaurav Kohli
2018-01-03 19:38 ` Alan Cox
2018-01-04  5:47   ` Kohli, Gaurav
2018-01-04 11:09     ` Alan Cox
2018-01-04 13:46       ` Kohli, Gaurav
2018-01-04 14:37         ` Alan Cox
2018-01-05  7:34           ` Kohli, Gaurav [this message]
2018-01-05  7:45             ` Kohli, Gaurav
2018-01-05 13:36               ` Alan Cox
2018-01-05 13:56                 ` Kohli, Gaurav
2018-01-05 14:15                   ` Alan Cox
2018-01-05 20:14                     ` Kohli, Gaurav
2018-01-05 20:24                       ` Kohli, Gaurav
2018-01-05 21:05                         ` Alan Cox
2018-01-06  7:50                           ` Kohli, Gaurav
2018-01-17 13:25                             ` Kohli, Gaurav
2018-01-20 18:49                               ` Alan Cox
2018-01-05 20:28                       ` Kohli, Gaurav

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=93a7bd73-1123-90a7-b22d-02964ba29fb0@codeaurora.org \
    --to=gkohli@codeaurora.org \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikey@neuling.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®