Re: [Industrypack-devel] [PATCH] ipoctal: protect only the real critical section

2014-07-03 Thread Samuel Iglesias Gonsálvez
On Thu, 2014-06-26 at 09:52 +0200, Samuel Iglesias Gonsálvez wrote:
> On Thu, 2014-06-26 at 09:46 +0200, Federico Vaga wrote:
> > In some conditions (echo or particular sequence of special
> > characters), on buffer push, the tty layer calls the write operation
> > while we are holding the spinlock. This means deadlock within the same
> > process on kernels version < 3.12. It seems not a problem on recent
> > kernel, but the patch still valid as locking optimization.
> > 
> > The protected variables by the spinlock are: xmit_buf, nb_bytes,
> > pointer_read and pointer_write. So, this patch reduces the locked area
> > in the IRQ handler only to these variables. Most of the code inside the
> > locked area in the IRQ handler is not protected elsewhere; it means
> > that it is not protected at all.
> > 
> > Signed-off-by: Federico Vaga 
> > ---
> >  drivers/ipack/devices/ipoctal.c |5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/ipack/devices/ipoctal.c 
> > b/drivers/ipack/devices/ipoctal.c
> > index 141094e..69687f1 100644
> > --- a/drivers/ipack/devices/ipoctal.c
> > +++ b/drivers/ipack/devices/ipoctal.c
> > @@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel 
> > *channel)
> > if (channel->nb_bytes == 0)
> > return;
> >  
> > +   spin_lock(>lock);
> > value = channel->tty_port.xmit_buf[*pointer_write];
> > iowrite8(value, >regs->w.thr);
> > channel->stats.tx++;
> > (*pointer_write)++;
> > *pointer_write = *pointer_write % PAGE_SIZE;
> > channel->nb_bytes--;
> > +   spin_unlock(>lock);
> >  }
> >  
> >  static void ipoctal_irq_channel(struct ipoctal_channel *channel)
> >  {
> > u8 isr, sr;
> >  
> > -   spin_lock(>lock);
> > /* The HW is organized in pair of channels.  See which register we need
> >  * to read from */
> > isr = ioread8(>block_regs->r.isr);
> > @@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel 
> > *channel)
> > /* TX of each character */
> > if ((isr & channel->isr_tx_rdy_mask) && (sr & SR_TX_READY))
> > ipoctal_irq_tx(channel);
> > -
> > -   spin_unlock(>lock);
> >  }
> >  
> >  static irqreturn_t ipoctal_irq_handler(void *arg)
> 
> Acked-by: Samuel Iglesias Gonsalvez 
> 
> Sam

Greg, Would you mind picking this patch through your driver-core tree?

Thanks,

Sam


signature.asc
Description: This is a digitally signed message part


Re: [Industrypack-devel] [PATCH] ipoctal: protect only the real critical section

2014-07-03 Thread Samuel Iglesias Gonsálvez
On Thu, 2014-06-26 at 09:52 +0200, Samuel Iglesias Gonsálvez wrote:
 On Thu, 2014-06-26 at 09:46 +0200, Federico Vaga wrote:
  In some conditions (echo or particular sequence of special
  characters), on buffer push, the tty layer calls the write operation
  while we are holding the spinlock. This means deadlock within the same
  process on kernels version  3.12. It seems not a problem on recent
  kernel, but the patch still valid as locking optimization.
  
  The protected variables by the spinlock are: xmit_buf, nb_bytes,
  pointer_read and pointer_write. So, this patch reduces the locked area
  in the IRQ handler only to these variables. Most of the code inside the
  locked area in the IRQ handler is not protected elsewhere; it means
  that it is not protected at all.
  
  Signed-off-by: Federico Vaga federico.v...@cern.ch
  ---
   drivers/ipack/devices/ipoctal.c |5 ++---
   1 file changed, 2 insertions(+), 3 deletions(-)
  
  diff --git a/drivers/ipack/devices/ipoctal.c 
  b/drivers/ipack/devices/ipoctal.c
  index 141094e..69687f1 100644
  --- a/drivers/ipack/devices/ipoctal.c
  +++ b/drivers/ipack/devices/ipoctal.c
  @@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel 
  *channel)
  if (channel-nb_bytes == 0)
  return;
   
  +   spin_lock(channel-lock);
  value = channel-tty_port.xmit_buf[*pointer_write];
  iowrite8(value, channel-regs-w.thr);
  channel-stats.tx++;
  (*pointer_write)++;
  *pointer_write = *pointer_write % PAGE_SIZE;
  channel-nb_bytes--;
  +   spin_unlock(channel-lock);
   }
   
   static void ipoctal_irq_channel(struct ipoctal_channel *channel)
   {
  u8 isr, sr;
   
  -   spin_lock(channel-lock);
  /* The HW is organized in pair of channels.  See which register we need
   * to read from */
  isr = ioread8(channel-block_regs-r.isr);
  @@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel 
  *channel)
  /* TX of each character */
  if ((isr  channel-isr_tx_rdy_mask)  (sr  SR_TX_READY))
  ipoctal_irq_tx(channel);
  -
  -   spin_unlock(channel-lock);
   }
   
   static irqreturn_t ipoctal_irq_handler(void *arg)
 
 Acked-by: Samuel Iglesias Gonsalvez sigles...@igalia.com
 
 Sam

Greg, Would you mind picking this patch through your driver-core tree?

Thanks,

Sam


signature.asc
Description: This is a digitally signed message part


Re: [PATCH] ipoctal: protect only the real critical section

2014-06-26 Thread Samuel Iglesias Gonsálvez
On Thu, 2014-06-26 at 09:46 +0200, Federico Vaga wrote:
> In some conditions (echo or particular sequence of special
> characters), on buffer push, the tty layer calls the write operation
> while we are holding the spinlock. This means deadlock within the same
> process on kernels version < 3.12. It seems not a problem on recent
> kernel, but the patch still valid as locking optimization.
> 
> The protected variables by the spinlock are: xmit_buf, nb_bytes,
> pointer_read and pointer_write. So, this patch reduces the locked area
> in the IRQ handler only to these variables. Most of the code inside the
> locked area in the IRQ handler is not protected elsewhere; it means
> that it is not protected at all.
> 
> Signed-off-by: Federico Vaga 
> ---
>  drivers/ipack/devices/ipoctal.c |5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
> index 141094e..69687f1 100644
> --- a/drivers/ipack/devices/ipoctal.c
> +++ b/drivers/ipack/devices/ipoctal.c
> @@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel 
> *channel)
>   if (channel->nb_bytes == 0)
>   return;
>  
> + spin_lock(>lock);
>   value = channel->tty_port.xmit_buf[*pointer_write];
>   iowrite8(value, >regs->w.thr);
>   channel->stats.tx++;
>   (*pointer_write)++;
>   *pointer_write = *pointer_write % PAGE_SIZE;
>   channel->nb_bytes--;
> + spin_unlock(>lock);
>  }
>  
>  static void ipoctal_irq_channel(struct ipoctal_channel *channel)
>  {
>   u8 isr, sr;
>  
> - spin_lock(>lock);
>   /* The HW is organized in pair of channels.  See which register we need
>* to read from */
>   isr = ioread8(>block_regs->r.isr);
> @@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel 
> *channel)
>   /* TX of each character */
>   if ((isr & channel->isr_tx_rdy_mask) && (sr & SR_TX_READY))
>   ipoctal_irq_tx(channel);
> -
> - spin_unlock(>lock);
>  }
>  
>  static irqreturn_t ipoctal_irq_handler(void *arg)

Acked-by: Samuel Iglesias Gonsalvez 

Sam


signature.asc
Description: This is a digitally signed message part


[PATCH] ipoctal: protect only the real critical section

2014-06-26 Thread Federico Vaga
In some conditions (echo or particular sequence of special
characters), on buffer push, the tty layer calls the write operation
while we are holding the spinlock. This means deadlock within the same
process on kernels version < 3.12. It seems not a problem on recent
kernel, but the patch still valid as locking optimization.

The protected variables by the spinlock are: xmit_buf, nb_bytes,
pointer_read and pointer_write. So, this patch reduces the locked area
in the IRQ handler only to these variables. Most of the code inside the
locked area in the IRQ handler is not protected elsewhere; it means
that it is not protected at all.

Signed-off-by: Federico Vaga 
---
 drivers/ipack/devices/ipoctal.c |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index 141094e..69687f1 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel 
*channel)
if (channel->nb_bytes == 0)
return;
 
+   spin_lock(>lock);
value = channel->tty_port.xmit_buf[*pointer_write];
iowrite8(value, >regs->w.thr);
channel->stats.tx++;
(*pointer_write)++;
*pointer_write = *pointer_write % PAGE_SIZE;
channel->nb_bytes--;
+   spin_unlock(>lock);
 }
 
 static void ipoctal_irq_channel(struct ipoctal_channel *channel)
 {
u8 isr, sr;
 
-   spin_lock(>lock);
/* The HW is organized in pair of channels.  See which register we need
 * to read from */
isr = ioread8(>block_regs->r.isr);
@@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel 
*channel)
/* TX of each character */
if ((isr & channel->isr_tx_rdy_mask) && (sr & SR_TX_READY))
ipoctal_irq_tx(channel);
-
-   spin_unlock(>lock);
 }
 
 static irqreturn_t ipoctal_irq_handler(void *arg)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] ipoctal: protect only the real critical section

2014-06-26 Thread Federico Vaga
In some conditions (echo or particular sequence of special
characters), on buffer push, the tty layer calls the write operation
while we are holding the spinlock. This means deadlock within the same
process on kernels version  3.12. It seems not a problem on recent
kernel, but the patch still valid as locking optimization.

The protected variables by the spinlock are: xmit_buf, nb_bytes,
pointer_read and pointer_write. So, this patch reduces the locked area
in the IRQ handler only to these variables. Most of the code inside the
locked area in the IRQ handler is not protected elsewhere; it means
that it is not protected at all.

Signed-off-by: Federico Vaga federico.v...@cern.ch
---
 drivers/ipack/devices/ipoctal.c |5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index 141094e..69687f1 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel 
*channel)
if (channel-nb_bytes == 0)
return;
 
+   spin_lock(channel-lock);
value = channel-tty_port.xmit_buf[*pointer_write];
iowrite8(value, channel-regs-w.thr);
channel-stats.tx++;
(*pointer_write)++;
*pointer_write = *pointer_write % PAGE_SIZE;
channel-nb_bytes--;
+   spin_unlock(channel-lock);
 }
 
 static void ipoctal_irq_channel(struct ipoctal_channel *channel)
 {
u8 isr, sr;
 
-   spin_lock(channel-lock);
/* The HW is organized in pair of channels.  See which register we need
 * to read from */
isr = ioread8(channel-block_regs-r.isr);
@@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel 
*channel)
/* TX of each character */
if ((isr  channel-isr_tx_rdy_mask)  (sr  SR_TX_READY))
ipoctal_irq_tx(channel);
-
-   spin_unlock(channel-lock);
 }
 
 static irqreturn_t ipoctal_irq_handler(void *arg)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] ipoctal: protect only the real critical section

2014-06-26 Thread Samuel Iglesias Gonsálvez
On Thu, 2014-06-26 at 09:46 +0200, Federico Vaga wrote:
 In some conditions (echo or particular sequence of special
 characters), on buffer push, the tty layer calls the write operation
 while we are holding the spinlock. This means deadlock within the same
 process on kernels version  3.12. It seems not a problem on recent
 kernel, but the patch still valid as locking optimization.
 
 The protected variables by the spinlock are: xmit_buf, nb_bytes,
 pointer_read and pointer_write. So, this patch reduces the locked area
 in the IRQ handler only to these variables. Most of the code inside the
 locked area in the IRQ handler is not protected elsewhere; it means
 that it is not protected at all.
 
 Signed-off-by: Federico Vaga federico.v...@cern.ch
 ---
  drivers/ipack/devices/ipoctal.c |5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
 index 141094e..69687f1 100644
 --- a/drivers/ipack/devices/ipoctal.c
 +++ b/drivers/ipack/devices/ipoctal.c
 @@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel 
 *channel)
   if (channel-nb_bytes == 0)
   return;
  
 + spin_lock(channel-lock);
   value = channel-tty_port.xmit_buf[*pointer_write];
   iowrite8(value, channel-regs-w.thr);
   channel-stats.tx++;
   (*pointer_write)++;
   *pointer_write = *pointer_write % PAGE_SIZE;
   channel-nb_bytes--;
 + spin_unlock(channel-lock);
  }
  
  static void ipoctal_irq_channel(struct ipoctal_channel *channel)
  {
   u8 isr, sr;
  
 - spin_lock(channel-lock);
   /* The HW is organized in pair of channels.  See which register we need
* to read from */
   isr = ioread8(channel-block_regs-r.isr);
 @@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel 
 *channel)
   /* TX of each character */
   if ((isr  channel-isr_tx_rdy_mask)  (sr  SR_TX_READY))
   ipoctal_irq_tx(channel);
 -
 - spin_unlock(channel-lock);
  }
  
  static irqreturn_t ipoctal_irq_handler(void *arg)

Acked-by: Samuel Iglesias Gonsalvez sigles...@igalia.com

Sam


signature.asc
Description: This is a digitally signed message part