Skip to content

Commit

Permalink
block: remove retry loop in ioc_release_fn()
Browse files Browse the repository at this point in the history
The reverse-order double lock dance in ioc_release_fn() is using a
retry loop. This is a problem on PREEMPT_RT because it could preempt
the task that would release q->queue_lock and thus live lock in the
retry loop.

RCU is already managing the freeing of the request queue and icq. If
the trylock fails, use RCU to guarantee that the request queue and
icq are not freed and re-acquire the locks in the correct order,
allowing forward progress.

Signed-off-by: John Ogness <[email protected]>
Reviewed-by: Daniel Wagner <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
jogness authored and axboe committed Jul 16, 2020
1 parent a43f085 commit ab96bba
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions block/blk-ioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,23 @@ static void ioc_release_fn(struct work_struct *work)
ioc_destroy_icq(icq);
spin_unlock(&q->queue_lock);
} else {
spin_unlock_irq(&ioc->lock);
cpu_relax();
spin_lock_irq(&ioc->lock);
/* Make sure q and icq cannot be freed. */
rcu_read_lock();

/* Re-acquire the locks in the correct order. */
spin_unlock(&ioc->lock);
spin_lock(&q->queue_lock);
spin_lock(&ioc->lock);

/*
* The icq may have been destroyed when the ioc lock
* was released.
*/
if (!(icq->flags & ICQ_DESTROYED))
ioc_destroy_icq(icq);

spin_unlock(&q->queue_lock);
rcu_read_unlock();
}
}

Expand Down

0 comments on commit ab96bba

Please sign in to comment.