Commit 968d04e8 authored by Federico Vaga's avatar Federico Vaga Committed by Greg Kroah-Hartman

ipoctal: protect only the real critical section

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: default avatarFederico Vaga <federico.vaga@cern.ch>
Acked-by: default avatarSamuel Iglesias Gonsalvez <siglesias@igalia.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b86e1926
...@@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel *channel) ...@@ -177,19 +177,20 @@ static void ipoctal_irq_tx(struct ipoctal_channel *channel)
if (channel->nb_bytes == 0) if (channel->nb_bytes == 0)
return; return;
spin_lock(&channel->lock);
value = channel->tty_port.xmit_buf[*pointer_write]; value = channel->tty_port.xmit_buf[*pointer_write];
iowrite8(value, &channel->regs->w.thr); iowrite8(value, &channel->regs->w.thr);
channel->stats.tx++; channel->stats.tx++;
(*pointer_write)++; (*pointer_write)++;
*pointer_write = *pointer_write % PAGE_SIZE; *pointer_write = *pointer_write % PAGE_SIZE;
channel->nb_bytes--; channel->nb_bytes--;
spin_unlock(&channel->lock);
} }
static void ipoctal_irq_channel(struct ipoctal_channel *channel) static void ipoctal_irq_channel(struct ipoctal_channel *channel)
{ {
u8 isr, sr; u8 isr, sr;
spin_lock(&channel->lock);
/* The HW is organized in pair of channels. See which register we need /* The HW is organized in pair of channels. See which register we need
* to read from */ * to read from */
isr = ioread8(&channel->block_regs->r.isr); isr = ioread8(&channel->block_regs->r.isr);
...@@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel *channel) ...@@ -213,8 +214,6 @@ static void ipoctal_irq_channel(struct ipoctal_channel *channel)
/* TX of each character */ /* TX of each character */
if ((isr & channel->isr_tx_rdy_mask) && (sr & SR_TX_READY)) if ((isr & channel->isr_tx_rdy_mask) && (sr & SR_TX_READY))
ipoctal_irq_tx(channel); ipoctal_irq_tx(channel);
spin_unlock(&channel->lock);
} }
static irqreturn_t ipoctal_irq_handler(void *arg) static irqreturn_t ipoctal_irq_handler(void *arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment