mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH char-misc-next] UIO: Fix concurrency issue
@ 2013-06-20 13:36 Vitalii Demianets
  2013-06-21 12:44 ` Pavel Machek
  0 siblings, 1 reply; 2+ messages in thread
From: Vitalii Demianets @ 2013-06-20 13:36 UTC (permalink / raw)
  To: linux-kernel, Greg Kroah-Hartman; +Cc: Hans J. Koch, Pavel Machek

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>
---
 drivers/uio/uio_pdrv_genirq.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c
index 9741549..bcd72f3 100644
--- a/drivers/uio/uio_pdrv_genirq.c
+++ b/drivers/uio/uio_pdrv_genirq.c
@@ -37,6 +37,11 @@ struct uio_pdrv_genirq_platdata {
 	struct platform_device *pdev;
 };
 
+/* Bits in uio_pdrv_genirq_platdata.flags */
+enum {
+	UIO_IRQ_DISABLED = 0,
+};
+
 static int uio_pdrv_genirq_open(struct uio_info *info, struct inode *inode)
 {
 	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)
 	 * remember the state so we can allow user space to enable it later.
 	 */
 
-	if (!test_and_set_bit(0, &priv->flags))
+	spin_lock(&priv->lock);
+	if (!__test_and_set_bit(UIO_IRQ_DISABLED, &priv->flags))
 		disable_irq_nosync(irq);
+	spin_unlock(&priv->lock);
 
 	return IRQ_HANDLED;
 }
@@ -78,16 +85,17 @@ static int uio_pdrv_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
 	 * in the interrupt controller, but keep track of the
 	 * state to prevent per-irq depth damage.
 	 *
-	 * Serialize this operation to support multiple tasks.
+	 * Serialize this operation to support multiple tasks and concurrency
+	 * with irq handler on SMP systems.
 	 */
 
 	spin_lock_irqsave(&priv->lock, flags);
 	if (irq_on) {
-		if (test_and_clear_bit(0, &priv->flags))
+		if (__test_and_clear_bit(UIO_IRQ_DISABLED, &priv->flags))
 			enable_irq(dev_info->irq);
 	} else {
-		if (!test_and_set_bit(0, &priv->flags))
-			disable_irq(dev_info->irq);
+		if (!__test_and_set_bit(UIO_IRQ_DISABLED, &priv->flags))
+			disable_irq_nosync(dev_info->irq);
 	}
 	spin_unlock_irqrestore(&priv->lock, flags);
 
-- 
1.7.12.4
-- 
With Best Regards,
Vitalii Demianets

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

* Re: [PATCH char-misc-next] UIO: Fix concurrency issue
  2013-06-20 13:36 [PATCH char-misc-next] UIO: Fix concurrency issue Vitalii Demianets
@ 2013-06-21 12:44 ` Pavel Machek
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Machek @ 2013-06-21 12:44 UTC (permalink / raw)
  To: Vitalii Demianets; +Cc: linux-kernel, Greg Kroah-Hartman, Hans J. Koch

On Thu 2013-06-20 16:36:00, Vitalii Demianets wrote:
> 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>

Sounds good.

Reviewed-by: Pavel Machek <pavel@ucw.cz>

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

end of thread, other threads:[~2013-06-21 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-20 13:36 [PATCH char-misc-next] UIO: Fix concurrency issue Vitalii Demianets
2013-06-21 12:44 ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®