All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tty: remove recursive implementation of tty_ldisc_release
@ 2012-05-25 11:11 Alan Cox
  2012-05-25 11:13 ` Sasha Levin
  2012-05-26  2:45 ` Ming Lei
  0 siblings, 2 replies; 4+ messages in thread
From: Alan Cox @ 2012-05-25 11:11 UTC (permalink / raw)
  To: levinsasha928, linux-kernel

From: Alan Cox <alan@linux.intel.com>

We need to do this in one pass with the locking requirements we now
have.

Signed-off-by: Alan Cox <alan@linux.intel.com>
---

 drivers/tty/tty_ldisc.c |   40 +++++++++++++++++++++++-----------------
 1 files changed, 23 insertions(+), 17 deletions(-)


diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 833e851..ecfaef5 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -894,6 +894,23 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
 	tty_ldisc_enable(tty);
 	return 0;
 }
+
+static int tty_ldisc_kill(struct tty_struct *tty)
+{
+	mutex_lock(&tty->ldisc_mutex);
+	/*
+	 * Now kill off the ldisc
+	 */
+	tty_ldisc_close(tty, tty->ldisc);
+	tty_ldisc_put(tty->ldisc);
+	/* Force an oops if we mess this up */
+	tty->ldisc = NULL;
+
+	/* Ensure the next open requests the N_TTY ldisc */
+	tty_set_termios_ldisc(tty, N_TTY);
+	mutex_unlock(&tty->ldisc_mutex);
+}
+
 /**
  *	tty_ldisc_release		-	release line discipline
  *	@tty: tty being shut down
@@ -912,30 +929,19 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
 	 * race with the set_ldisc code path.
 	 */
 
-	/* We don't give a monkeys' about the o_tty lock here but we
-	   must do both to avoid lock inversions against another single
-	   locking case */
 	tty_unlock_pair(tty, o_tty);
 	tty_ldisc_halt(tty);
 	tty_ldisc_flush_works(tty);
+	if (o_tty) {
+		tty_ldisc_halt(o_tty);
+		tty_ldisc_flush_works(o_tty);
+	}
 	tty_lock_pair(tty, o_tty);
 
-	mutex_lock(&tty->ldisc_mutex);
-	/*
-	 * Now kill off the ldisc
-	 */
-	tty_ldisc_close(tty, tty->ldisc);
-	tty_ldisc_put(tty->ldisc);
-	/* Force an oops if we mess this up */
-	tty->ldisc = NULL;
-
-	/* Ensure the next open requests the N_TTY ldisc */
-	tty_set_termios_ldisc(tty, N_TTY);
-	mutex_unlock(&tty->ldisc_mutex);
 
-	/* This will need doing differently if we need to lock */
+	tty_ldisc_kill(tty);
 	if (o_tty)
-		tty_ldisc_release(o_tty, NULL);
+		tty_ldisc_kill(o_tty);
 
 	/* And the memory resources remaining (buffers, termios) will be
 	   disposed of when the kref hits zero */


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: remove recursive implementation of tty_ldisc_release
  2012-05-25 11:11 [PATCH] tty: remove recursive implementation of tty_ldisc_release Alan Cox
@ 2012-05-25 11:13 ` Sasha Levin
  2012-05-25 13:42   ` Alan Cox
  2012-05-26  2:45 ` Ming Lei
  1 sibling, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2012-05-25 11:13 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

On Fri, May 25, 2012 at 1:11 PM, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> From: Alan Cox <alan@linux.intel.com>
>
> We need to do this in one pass with the locking requirements we now
> have.
>
> Signed-off-by: Alan Cox <alan@linux.intel.com>
> ---

I don't see any lockdep warnings anymore with this patch applied on
top of all others.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: remove recursive implementation of tty_ldisc_release
  2012-05-25 11:13 ` Sasha Levin
@ 2012-05-25 13:42   ` Alan Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Cox @ 2012-05-25 13:42 UTC (permalink / raw)
  To: Sasha Levin; +Cc: linux-kernel

On Fri, 25 May 2012 13:13:15 +0200
Sasha Levin <levinsasha928@gmail.com> wrote:

> On Fri, May 25, 2012 at 1:11 PM, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > From: Alan Cox <alan@linux.intel.com>
> >
> > We need to do this in one pass with the locking requirements we now
> > have.
> >
> > Signed-off-by: Alan Cox <alan@linux.intel.com>
> > ---
> 
> I don't see any lockdep warnings anymore with this patch applied on
> top of all others.

Yay thanks for reporting/testing

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: remove recursive implementation of tty_ldisc_release
  2012-05-25 11:11 [PATCH] tty: remove recursive implementation of tty_ldisc_release Alan Cox
  2012-05-25 11:13 ` Sasha Levin
@ 2012-05-26  2:45 ` Ming Lei
  1 sibling, 0 replies; 4+ messages in thread
From: Ming Lei @ 2012-05-26  2:45 UTC (permalink / raw)
  To: Alan Cox; +Cc: levinsasha928, linux-kernel

On Fri, May 25, 2012 at 7:11 PM, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> From: Alan Cox <alan@linux.intel.com>
>
> We need to do this in one pass with the locking requirements we now
> have.
>
> Signed-off-by: Alan Cox <alan@linux.intel.com>
> ---
>
>  drivers/tty/tty_ldisc.c |   40 +++++++++++++++++++++++-----------------
>  1 files changed, 23 insertions(+), 17 deletions(-)
>
>
> diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
> index 833e851..ecfaef5 100644
> --- a/drivers/tty/tty_ldisc.c
> +++ b/drivers/tty/tty_ldisc.c
> @@ -894,6 +894,23 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
>        tty_ldisc_enable(tty);
>        return 0;
>  }
> +
> +static int tty_ldisc_kill(struct tty_struct *tty)

Maybe the return type should be defined as void to avoid compile warning.


After applying Alan's three patches for addressing tty locks and the patch
int the below link:

     http://marc.info/?l=linux-kernel&m=133775308420817&w=2

Looks no lockdep warnings are triggered any more when running
'exit' in shell of ssh session.

So I will send out the formal patch in the above link.

Thanks,
-- 
Ming Lei

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-26  2:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25 11:11 [PATCH] tty: remove recursive implementation of tty_ldisc_release Alan Cox
2012-05-25 11:13 ` Sasha Levin
2012-05-25 13:42   ` Alan Cox
2012-05-26  2:45 ` Ming Lei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.