Re: port bio(4) and bioctl(8) from openbsd ?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Manuel Bouyer
Date: Saturday, April 21, 2007 - 6:48 am

Here's my latest patch about this.
I've an issue with lock usage in bio(4):
there is a bio_lock, which is a kmutex_t to protect the internal structures
of bio(4). A disk driver (for example mfi(4)) will also have its own
lock to protect its structure; and will probably call bio_register()
and bio_unregister() with this lock held.
The callback from bio(4) to mfi(4) shall be called with bio_lock held, to
avoid having the entry removed from under its feets (it's not the
case right now, but as nothing calls bio_unregister() for now, it's
safe).
Now we could have this deadlock (theorically; because mfi doesn't have
a mfi_detach):
mfi_detach() takes the mfi mutex, and calls bio_unregister() which takes
  bio_lock.
bioioctl() takes bio_lock, and call backs in mfi(4) which will want to
  take the mfi mutex.

I'm not a multithread expert programmer. How is such case handled usually ?
I think mfi_detach() should take bio_lock itself, so it can take locks
in an order which can avoid the deadlock. Or the callback in mfi could
release bio_lock itself before trying to take the mfi mutex, but I can't
see how to avoid the race in which the mfi device could dissapear between
releasing bio_lock and taking the mfi mutex at this point. Any idea ?

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
port bio(4) and bioctl(8) from openbsd ?, Manuel Bouyer, (Sat Apr 7, 9:00 am)
Re: port bio(4) and bioctl(8) from openbsd ?, Thor Lancelot Simon, (Sat Apr 7, 11:51 am)
Re: port bio(4) and bioctl(8) from openbsd ?, Manuel Bouyer, (Sat Apr 7, 12:01 pm)
Re: port bio(4) and bioctl(8) from openbsd ?, Manuel Bouyer, (Sat Apr 21, 6:48 am)
Re: port bio(4) and bioctl(8) from openbsd ?, Bill Stouder-Studenmund, (Sat Apr 21, 11:17 pm)
Re: port bio(4) and bioctl(8) from openbsd ?, Manuel Bouyer, (Sun Apr 22, 2:01 pm)
Re: port bio(4) and bioctl(8) from openbsd ?, Manuel Bouyer, (Mon Apr 23, 4:16 pm)
Re: port bio(4) and bioctl(8) from openbsd ?, Manuel Bouyer, (Tue May 1, 11:11 am)