linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] PREEMPT_RT: USB serial gadget: Fix locking issue
@ 2014-05-22  9:58 Jean-Jacques Hiblot
  2014-05-22 14:09 ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Jacques Hiblot @ 2014-05-22  9:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, tglx, gregkh, balbi, Jean-Jacques Hiblot

With CONFIG_PREEMPT_RT_FULL the tty_flip_buffer_push(..) actions are executed
immeditely (same behaviour as if low_latency flag was set). We thus have to
release port_lock before callng tty_flip_buffer_push().

This issue resultst of commits:
44a0c019: USB: g_serial: don't set low_latency flag
dc0cbd1b: serial: 8250: Call flush_to_ldisc when the irq is threaded

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
---

changes since v1:
 - fix compilation problem: use port.tty instead of port->port_tty

 drivers/usb/gadget/u_serial.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index b369292..3d4246d 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -549,12 +549,25 @@ static void gs_rx_push(unsigned long _port)
 		port->read_started--;
 	}

-	/* Push from tty to ldisc; without low_latency set this is handled by
-	 * a workqueue, so we won't get callbacks and can hold port_lock
-	 */
-	if (do_push)
+	/* Push from tty to ldisc */
+	if (do_push) {
+#ifndef CONFIG_PREEMPT_RT_FULL
+		/* without low_latency set this is handled by a workqueue, so
+		 * we won't get callbacks and can hold port_lock
+		*/
 		tty_flip_buffer_push(&port->port);
-
+#else
+		/* CONFIG_PREEMPT_RT_FULL makes this a synchronous action. and
+		 * it may trigger synchronous callbacks to this driver. We need
+		 * to release the lock.
+		*/
+		spin_unlock_irq(&port->port_lock);
+		tty_flip_buffer_push(&port->port);
+		spin_lock_irq(&port->port_lock);
+		/* tty may have been closed */
+		tty = port->port.tty;
+#endif
+	}

 	/* We want our data queue to become empty ASAP, keeping data
 	 * in the tty and ldisc (not here).  If we couldn't push any
--
1.9.2


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

* Re: [PATCH v2] PREEMPT_RT: USB serial gadget: Fix locking issue
  2014-05-22  9:58 [PATCH v2] PREEMPT_RT: USB serial gadget: Fix locking issue Jean-Jacques Hiblot
@ 2014-05-22 14:09 ` Felipe Balbi
  2014-05-22 14:57   ` [PATCH v2 RESEND] " Jean-Jacques Hiblot
  0 siblings, 1 reply; 4+ messages in thread
From: Felipe Balbi @ 2014-05-22 14:09 UTC (permalink / raw)
  To: Jean-Jacques Hiblot; +Cc: linux-kernel, mingo, tglx, gregkh, balbi

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

Hi,

On Thu, May 22, 2014 at 11:58:48AM +0200, Jean-Jacques Hiblot wrote:
> With CONFIG_PREEMPT_RT_FULL the tty_flip_buffer_push(..) actions are executed
> immeditely (same behaviour as if low_latency flag was set). We thus have to
> release port_lock before callng tty_flip_buffer_push().
> 
> This issue resultst of commits:
> 44a0c019: USB: g_serial: don't set low_latency flag
> dc0cbd1b: serial: 8250: Call flush_to_ldisc when the irq is threaded
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>

can you please resend with linux-usb in copy ?

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* [PATCH v2 RESEND] PREEMPT_RT: USB serial gadget: Fix locking issue
  2014-05-22 14:09 ` Felipe Balbi
@ 2014-05-22 14:57   ` Jean-Jacques Hiblot
  2014-06-19 15:10     ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Jacques Hiblot @ 2014-05-22 14:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-usb, mingo, tglx, gregkh, balbi, Jean-Jacques Hiblot

With CONFIG_PREEMPT_RT_FULL the tty_flip_buffer_push(..) actions are executed
immeditely (same behaviour as if low_latency flag was set). We thus have to
release port_lock before callng tty_flip_buffer_push().

This issue resultst of commits:
44a0c019: USB: g_serial: don't set low_latency flag
dc0cbd1b: serial: 8250: Call flush_to_ldisc when the irq is threaded

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
---
changes since v1:
 - fix compilation problem: use port.tty instead of port->port_tty

 drivers/usb/gadget/u_serial.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index b369292..3d4246d 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -549,12 +549,25 @@ static void gs_rx_push(unsigned long _port)
 		port->read_started--;
 	}

-	/* Push from tty to ldisc; without low_latency set this is handled by
-	 * a workqueue, so we won't get callbacks and can hold port_lock
-	 */
-	if (do_push)
+	/* Push from tty to ldisc */
+	if (do_push) {
+#ifndef CONFIG_PREEMPT_RT_FULL
+		/* without low_latency set this is handled by a workqueue, so
+		 * we won't get callbacks and can hold port_lock
+		*/
 		tty_flip_buffer_push(&port->port);
-
+#else
+		/* CONFIG_PREEMPT_RT_FULL makes this a synchronous action. and
+		 * it may trigger synchronous callbacks to this driver. We need
+		 * to release the lock.
+		*/
+		spin_unlock_irq(&port->port_lock);
+		tty_flip_buffer_push(&port->port);
+		spin_lock_irq(&port->port_lock);
+		/* tty may have been closed */
+		tty = port->port.tty;
+#endif
+	}

 	/* We want our data queue to become empty ASAP, keeping data
 	 * in the tty and ldisc (not here).  If we couldn't push any
--
1.9.2


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

* Re: [PATCH v2 RESEND] PREEMPT_RT: USB serial gadget: Fix locking issue
  2014-05-22 14:57   ` [PATCH v2 RESEND] " Jean-Jacques Hiblot
@ 2014-06-19 15:10     ` Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2014-06-19 15:10 UTC (permalink / raw)
  To: Jean-Jacques Hiblot; +Cc: linux-kernel, linux-usb, mingo, tglx, gregkh, balbi

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

On Thu, May 22, 2014 at 04:57:31PM +0200, Jean-Jacques Hiblot wrote:
> With CONFIG_PREEMPT_RT_FULL the tty_flip_buffer_push(..) actions are executed
> immeditely (same behaviour as if low_latency flag was set). We thus have to
> release port_lock before callng tty_flip_buffer_push().
> 
> This issue resultst of commits:
> 44a0c019: USB: g_serial: don't set low_latency flag
> dc0cbd1b: serial: 8250: Call flush_to_ldisc when the irq is threaded
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@traphandler.com>
> ---
> changes since v1:
>  - fix compilation problem: use port.tty instead of port->port_tty
> 
>  drivers/usb/gadget/u_serial.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
> index b369292..3d4246d 100644
> --- a/drivers/usb/gadget/u_serial.c
> +++ b/drivers/usb/gadget/u_serial.c
> @@ -549,12 +549,25 @@ static void gs_rx_push(unsigned long _port)
>  		port->read_started--;
>  	}
> 
> -	/* Push from tty to ldisc; without low_latency set this is handled by
> -	 * a workqueue, so we won't get callbacks and can hold port_lock
> -	 */
> -	if (do_push)
> +	/* Push from tty to ldisc */
> +	if (do_push) {
> +#ifndef CONFIG_PREEMPT_RT_FULL

can we drop the ifdef somehow ? Are there no better options here ?

> +		/* without low_latency set this is handled by a workqueue, so
> +		 * we won't get callbacks and can hold port_lock
> +		*/
>  		tty_flip_buffer_push(&port->port);
> -
> +#else
> +		/* CONFIG_PREEMPT_RT_FULL makes this a synchronous action. and
> +		 * it may trigger synchronous callbacks to this driver. We need
> +		 * to release the lock.
> +		*/
> +		spin_unlock_irq(&port->port_lock);
> +		tty_flip_buffer_push(&port->port);
> +		spin_lock_irq(&port->port_lock);
> +		/* tty may have been closed */
> +		tty = port->port.tty;
> +#endif
> +	}
> 
>  	/* We want our data queue to become empty ASAP, keeping data
>  	 * in the tty and ldisc (not here).  If we couldn't push any
> --
> 1.9.2
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2014-06-19 15:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-22  9:58 [PATCH v2] PREEMPT_RT: USB serial gadget: Fix locking issue Jean-Jacques Hiblot
2014-05-22 14:09 ` Felipe Balbi
2014-05-22 14:57   ` [PATCH v2 RESEND] " Jean-Jacques Hiblot
2014-06-19 15:10     ` Felipe Balbi

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).