Fix a serious SMP bug. The RWLOCK support used by dev/raid/aac,
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 20 Jun 2005 07:31:05 +0000 (07:31 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 20 Jun 2005 07:31:05 +0000 (07:31 +0000)
commit0c4539500d9a2004d1a87218aac6cff35711e373
tree9cd01599e8f5c65781299213bdc72ba934933419
parentb2a7de38b6de78c49f7c8968e35913d3e40a2731
Fix a serious SMP bug.  The RWLOCK support used by dev/raid/aac,
ACPI, and dev/drm improperly tries to use a token in lwkt_schedule().
Because lwkt_schedule() can be called from an IPI in the context of
the current thread it cannot safely manipulate the current thread,
much less the td_toks field.

To fix this problem the RW lock functions in lwkt_rwlock.c have to be
covered by a critical section as well as the token, and lwkt_schedule()
then simply checks to see if the token is owned by the current cpu.  RWLocks
may require some rethinking.

The token code is designed to operate mostly without having to use a
critical section, but in order for this to work it depends on the td_toks
list not being ripped out from under it.  The nested trytoken/release
call in lwkt_schedule() should not have caused mainline token code to
fail as it restored td_toks to the same state it was in on entry, but
we can't take that chance.
sys/kern/lwkt_rwlock.c
sys/kern/lwkt_thread.c