aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitalii Demianets <vitas@nppfactor.kiev.ua>2013-06-20 09:36:00 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-06-24 19:31:21 -0400
commit34cb27528398738bea94852b99ef8fb05944ec41 (patch)
tree88a9e99282138bd21af563b98ab65ccc8ab088be
parent077797117dfa209717e1f3f1416c1101c0e047f0 (diff)
UIO: Fix concurrency issue
In a SMP case there was a race condition issue between uio_pdrv_genirq_irqcontrol() running on one CPU and irq handler on another CPU. Fix it by spin_locking shared resources access inside irq handler. Also: - Change disable_irq to disable_irq_nosync to avoid deadlock, because disable_irq waits for the completion of the irq handler; - Change atomic bit-manipulation routines to their non-atomic counterparts as we already are guarding the code by spinlock. Signed-off-by: Vitalii Demianets <vitas@nppfactor.kiev.ua> Reviewed-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/uio/uio_pdrv_genirq.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c
index 97415492779e..bcd72f3a62c3 100644
--- a/drivers/uio/uio_pdrv_genirq.c
+++ b/drivers/uio/uio_pdrv_genirq.c
@@ -37,6 +37,11 @@ struct uio_pdrv_genirq_platdata {
37 struct platform_device *pdev; 37 struct platform_device *pdev;
38}; 38};
39 39
40/* Bits in uio_pdrv_genirq_platdata.flags */
41enum {
42 UIO_IRQ_DISABLED = 0,
43};
44
40static int uio_pdrv_genirq_open(struct uio_info *info, struct inode *inode) 45static int uio_pdrv_genirq_open(struct uio_info *info, struct inode *inode)
41{ 46{
42 struct uio_pdrv_genirq_platdata *priv = info->priv; 47 struct uio_pdrv_genirq_platdata *priv = info->priv;
@@ -63,8 +68,10 @@ static irqreturn_t uio_pdrv_genirq_handler(int irq, struct uio_info *dev_info)
63 * remember the state so we can allow user space to enable it later. 68 * remember the state so we can allow user space to enable it later.
64 */ 69 */
65 70
66 if (!test_and_set_bit(0, &priv->flags)) 71 spin_lock(&priv->lock);
72 if (!__test_and_set_bit(UIO_IRQ_DISABLED, &priv->flags))
67 disable_irq_nosync(irq); 73 disable_irq_nosync(irq);
74 spin_unlock(&priv->lock);
68 75
69 return IRQ_HANDLED; 76 return IRQ_HANDLED;
70} 77}
@@ -78,16 +85,17 @@ static int uio_pdrv_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
78 * in the interrupt controller, but keep track of the 85 * in the interrupt controller, but keep track of the
79 * state to prevent per-irq depth damage. 86 * state to prevent per-irq depth damage.
80 * 87 *
81 * Serialize this operation to support multiple tasks. 88 * Serialize this operation to support multiple tasks and concurrency
89 * with irq handler on SMP systems.
82 */ 90 */
83 91
84 spin_lock_irqsave(&priv->lock, flags); 92 spin_lock_irqsave(&priv->lock, flags);
85 if (irq_on) { 93 if (irq_on) {
86 if (test_and_clear_bit(0, &priv->flags)) 94 if (__test_and_clear_bit(UIO_IRQ_DISABLED, &priv->flags))
87 enable_irq(dev_info->irq); 95 enable_irq(dev_info->irq);
88 } else { 96 } else {
89 if (!test_and_set_bit(0, &priv->flags)) 97 if (!__test_and_set_bit(UIO_IRQ_DISABLED, &priv->flags))
90 disable_irq(dev_info->irq); 98 disable_irq_nosync(dev_info->irq);
91 } 99 }
92 spin_unlock_irqrestore(&priv->lock, flags); 100 spin_unlock_irqrestore(&priv->lock, flags);
93 101