From: Greg KH <greg@kroah.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
linux-next@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
Peter Hurley <peter@hurleysoftware.com>,
Michael Neuling <mikey@neuling.org>
Subject: Re: linux-next: manual merge of the tty tree with the tty.current tree
Date: Wed, 29 Mar 2017 07:51:52 +0200 [thread overview]
Message-ID: <20170329055152.GE4137@kroah.com> (raw)
In-Reply-To: <CACT4Y+YvkT0dVhM3fG_cnaMA_guNAt28dvzhbgyXtowDD7oBaw@mail.gmail.com>
On Mon, Mar 20, 2017 at 10:26:43AM +0100, Dmitry Vyukov wrote:
> On Mon, Mar 20, 2017 at 10:21 AM, Dmitry Vyukov <dvyukov@google.com> wrote:
> > On Mon, Mar 20, 2017 at 3:28 AM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> >> Hi Greg,
> >>
> >> Today's linux-next merge of the tty tree got a conflict in:
> >>
> >> drivers/tty/tty_ldisc.c
> >>
> >> between commit:
> >>
> >> 5362544bebe8 ("tty: don't panic on OOM in tty_set_ldisc()")
> >>
> >> from the tty.current tree and commit:
> >>
> >> 71472fa9c52b ("tty: Fix ldisc crash on reopened tty")
> >>
> >> from the tty tree.
> >>
> >> I fixed it up (see below) and can carry the fix as necessary. This
> >> is now fixed as far as linux-next is concerned, but any non trivial
> >> conflicts should be mentioned to your upstream maintainer when your tree
> >> is submitted for merging. You may also want to consider cooperating
> >> with the maintainer of the conflicting tree to minimise any particularly
> >> complex conflicts.
> >>
> >> --
> >> Cheers,
> >> Stephen Rothwell
> >>
> >> diff --cc drivers/tty/tty_ldisc.c
> >> index b0500a0a87b8,4ee7742dced3..000000000000
> >> --- a/drivers/tty/tty_ldisc.c
> >> +++ b/drivers/tty/tty_ldisc.c
> >> @@@ -621,14 -669,17 +621,15 @@@ int tty_ldisc_reinit(struct tty_struct
> >> tty_ldisc_put(tty->ldisc);
> >> }
> >>
> >> - /* switch the line discipline */
> >> - tty->ldisc = ld;
> >> tty_set_termios_ldisc(tty, disc);
> >> - retval = tty_ldisc_open(tty, tty->ldisc);
> >> + retval = tty_ldisc_open(tty, ld);
> >> if (retval) {
> >> - tty_ldisc_put(tty->ldisc);
> >> - tty->ldisc = NULL;
> >> - if (!WARN_ON(disc == N_TTY)) {
> >> - tty_ldisc_put(ld);
> >> - ld = NULL;
> >> - }
> >> ++ tty_ldisc_put(ld);
> >> ++ ld = NULL;
> >> }
> >> +
> >> + /* switch the line discipline */
> >> + smp_store_release(&tty->ldisc, ld);
> >> return retval;
> >> }
> >>
> >
> >
> > Peter,
> >
> > Looking at your patch "tty: Fix ldisc crash on reopened tty", I think
> > there is a missed barrier in tty_ldisc_ref. A single barrier does not
> > have any effect, they always need to be in pairs. So I think we also
> > need at least:
> >
> > @@ -295,7 +295,8 @@ struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
> > struct tty_ldisc *ld = NULL;
> >
> > if (ldsem_down_read_trylock(&tty->ldisc_sem)) {
> > - ld = tty->ldisc;
> > + ld = READ_ONCE(tty->ldisc);
> > + read_barrier_depends();
> > if (!ld)
> > ldsem_up_read(&tty->ldisc_sem);
> > }
> >
> >
> > Or simply:
> >
> > @@ -295,7 +295,8 @@ struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
> > struct tty_ldisc *ld = NULL;
> >
> > if (ldsem_down_read_trylock(&tty->ldisc_sem)) {
> > - ld = tty->ldisc;
> > + /* pairs with smp_store_release in tty_ldisc_reinit */
> > + ld = smp_load_acquire(&tty->ldisc);
> > if (!ld)
> > ldsem_up_read(&tty->ldisc_sem);
> > }
>
>
>
>
> I am also surprised that callers of tty_ldisc_reinit don't hold
> ldisc_sem. I thought that ldisc_sem is what's supposed to protect
> changes to ldisc. That would also auto fix the crash without any
> tricky barriers as flush_to_ldisc uses tty_ldisc_ref.
Ok, I'm reverting this patch. Michael and Peter, please rework it and
resubmit.
thanks,
greg k-h
next prev parent reply other threads:[~2017-03-29 5:52 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 2:28 linux-next: manual merge of the tty tree with the tty.current tree Stephen Rothwell
2017-03-20 9:21 ` Dmitry Vyukov
2017-03-20 9:26 ` Dmitry Vyukov
2017-03-29 5:51 ` Greg KH [this message]
2017-03-30 3:46 ` Michael Neuling
2017-03-30 12:17 ` Dmitry Vyukov
-- strict thread matches above, loose matches on Subject: below --
2024-04-19 4:19 Stephen Rothwell
2024-04-19 6:09 ` Greg KH
2024-04-23 11:24 ` Greg KH
2024-04-11 3:57 Stephen Rothwell
2024-04-11 4:17 ` Stephen Rothwell
2024-04-11 4:38 ` Greg KH
2024-04-11 10:40 ` Andy Shevchenko
2023-10-04 1:55 Stephen Rothwell
2023-10-04 2:14 ` Stephen Rothwell
2023-10-04 6:38 ` Greg KH
2023-10-16 8:20 ` Greg KH
2020-09-17 6:09 Stephen Rothwell
2020-09-17 6:34 ` Greg KH
2019-12-18 0:49 Stephen Rothwell
2019-12-18 7:05 ` Greg KH
2017-08-02 4:26 Stephen Rothwell
2017-08-04 1:02 ` Greg KH
2017-08-14 22:17 ` Greg KH
2016-02-08 2:16 Stephen Rothwell
2016-02-08 2:21 ` Greg KH
2016-02-08 2:53 ` Peter Hurley
2016-04-01 0:23 ` Peter Hurley
2016-04-01 3:49 ` Greg KH
2015-05-25 8:19 Stephen Rothwell
2015-05-25 16:28 ` Greg KH
2015-05-26 11:08 ` Dave Martin
2014-11-26 7:12 Stephen Rothwell
2014-11-26 19:51 ` Greg KH
2014-11-10 4:49 Stephen Rothwell
2014-11-10 5:08 ` Greg KH
2013-01-17 2:07 Stephen Rothwell
2013-01-18 1:27 ` Greg KH
2012-04-19 4:59 Stephen Rothwell
2012-04-19 20:07 ` Greg KH
2012-04-23 16:40 ` Greg KH
2011-11-18 3:30 Stephen Rothwell
2011-11-18 8:41 ` Jiri Slaby
2011-11-18 16:18 ` Greg KH
2011-11-27 4:08 ` Greg KH
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=20170329055152.GE4137@kroah.com \
--to=greg@kroah.com \
--cc=dvyukov@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mikey@neuling.org \
--cc=peter@hurleysoftware.com \
--cc=sfr@canb.auug.org.au \
/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;
as well as URLs for NNTP newsgroup(s).