Skip to contentSkip to conversation

bad: scheduling while atomic! (Part Deux)

DISCUSSION Russell King 2 participants 2 messages Jun 15, 2003

lore
Share & tools
lore
#0 lore raw

Sigh. Another MTD deadlock, and cause of scheduling badness on UP preempt.

David, I think MTD needs an audit to ensure that no further cases exist.

static void cfi_intelext_sync (struct mtd_info *mtd)

{
        for (i=0; !ret && i<cfi->numchips; i++) {
                chip = &cfi->chips[i];

                spin_lock(chip->mutex);
                ret = get_chip(map, chip, chip->start, FL_SYNCING);
...
        }

        /* Unlock the chips again */

        for (i--; i >=0; i--) {
                chip = &cfi->chips[i];

                spin_lock(chip->mutex);
...
                spin_unlock(chip->mutex);
        }
}
Signature · 2 lines
Russell King ([email protected])                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html
#1 lore raw
Quoted 4 lines · Russell King

Sigh. Another MTD deadlock, and cause of scheduling badness on UP preempt.

David, I think MTD needs an audit to ensure that no further cases exist.

Could this be done with smatch plus some perl? Being a lazy bastard, I like the idea of letting the machines do the boring repetetive job.

Quoted 12 lines

static void cfi_intelext_sync (struct mtd_info *mtd)

{
        for (i=0; !ret && i<cfi->numchips; i++) {
                chip = &cfi->chips[i];

                spin_lock(chip->mutex);
                ret = get_chip(map, chip, chip->start, FL_SYNCING);
...
        }

        /* Unlock the chips again */
Quoted 8 lines
        for (i--; i >=0; i--) {
                chip = &cfi->chips[i];

                spin_lock(chip->mutex);
...
                spin_unlock(chip->mutex);
        }
}

Mindless guess of a fix part 1 & 2 below.

As an anecdote, the stupid copy of cmdset_0001, cmdset_0020, did it right. Interesting.

Jörn

Signature · 40 lines
Courage is not the absence of fear, but rather the judgement that
something else is more important than fear.
-- Ambrose Redmoon

--- linux-2.5.71/drivers/mtd/mtd_blkdevs.c~mtd_spinlocks	2003-06-15 16:05:05.000000000 +0200
+++ linux-2.5.71/drivers/mtd/mtd_blkdevs.c	2003-06-15 16:19:43.000000000 +0200
@@ -93,14 +93,13 @@
 	recalc_sigpending();
 	spin_unlock_irq(&current->sighand->siglock);
 
+	spin_lock_irq(rq->queue_lock);
 	while (!tr->blkcore_priv->exiting) {
 		struct request *req;
 		struct mtd_blktrans_dev *dev;
 		int res = 0;
 		DECLARE_WAITQUEUE(wait, current);
 
-		spin_lock_irq(rq->queue_lock);
-
 		req = elv_next_request(rq);
 
 		if (!req) {
@@ -112,6 +111,7 @@
 			schedule();
 			remove_wait_queue(&tr->blkcore_priv->thread_wq, &wait);
 
+			spin_lock_irq(rq->queue_lock);
 			continue;
 		}
 
--- linux-2.5.71/drivers/mtd/chips/cfi_cmdset_0001.c~mtd_spinlocks	2003-06-15 16:05:03.000000000 +0200
+++ linux-2.5.71/drivers/mtd/chips/cfi_cmdset_0001.c	2003-06-15 17:33:43.000000000 +0200
@@ -1423,6 +1423,7 @@
 			 * with the chip now anyway.
 			 */
 		}
+		spin_unlock(chip->mutex);
 	}
 
 	/* Unlock the chips again */