Skip to content

Commit

Permalink
via-velocity: Fix races on shared interrupts
Browse files Browse the repository at this point in the history
This patch fixes two potential races in the velocity driver:

* Move the ACK and error handler to the interrupt handler. This fixes a
  potential race with shared interrupts when the other device interrupts
  before the NAPI poll handler has finished. As the velocity driver hasn't
  acked it's own interrupt, it will then steal the interrupt from the
  other device.

* Use spin_lock_irqsave in velocity_poll. In the current code, the
  interrupt handler will deadlock if e.g., the NAPI poll handler is
  executing when an interrupt (for another device) comes in since it
  tries to take the already held lock.

  Also unlock the spinlock only after enabling the interrupt in
  velocity_poll.

The error path is moved to the interrupt handler since this is where the
ISR is checked now.

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
Signed-off-by: Anders Grafstrom <anders.grafstrom@netinsight.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Simon Kagstrom authored and David S. Miller committed Feb 10, 2010
1 parent 39c2ff4 commit 3f2e8d9
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions drivers/net/via-velocity.c
Original file line number Diff line number Diff line change
Expand Up @@ -2148,16 +2148,9 @@ static int velocity_poll(struct napi_struct *napi, int budget)
struct velocity_info *vptr = container_of(napi,
struct velocity_info, napi);
unsigned int rx_done;
u32 isr_status;

spin_lock(&vptr->lock);
isr_status = mac_read_isr(vptr->mac_regs);

/* Ack the interrupt */
mac_write_isr(vptr->mac_regs, isr_status);
if (isr_status & (~(ISR_PRXI | ISR_PPRXI | ISR_PTXI | ISR_PPTXI)))
velocity_error(vptr, isr_status);
unsigned long flags;

spin_lock_irqsave(&vptr->lock, flags);
/*
* Do rx and tx twice for performance (taken from the VIA
* out-of-tree driver).
Expand All @@ -2167,13 +2160,12 @@ static int velocity_poll(struct napi_struct *napi, int budget)
rx_done += velocity_rx_srv(vptr, budget - rx_done);
velocity_tx_srv(vptr);

spin_unlock(&vptr->lock);

/* If budget not fully consumed, exit the polling mode */
if (rx_done < budget) {
napi_complete(napi);
mac_enable_int(vptr->mac_regs);
}
spin_unlock_irqrestore(&vptr->lock, flags);

return rx_done;
}
Expand Down Expand Up @@ -2203,10 +2195,17 @@ static irqreturn_t velocity_intr(int irq, void *dev_instance)
return IRQ_NONE;
}

/* Ack the interrupt */
mac_write_isr(vptr->mac_regs, isr_status);

if (likely(napi_schedule_prep(&vptr->napi))) {
mac_disable_int(vptr->mac_regs);
__napi_schedule(&vptr->napi);
}

if (isr_status & (~(ISR_PRXI | ISR_PPRXI | ISR_PTXI | ISR_PPTXI)))
velocity_error(vptr, isr_status);

spin_unlock(&vptr->lock);

return IRQ_HANDLED;
Expand Down

0 comments on commit 3f2e8d9

Please sign in to comment.