Fix race in rwlock implementation which can occur when
your task is rescheduled to a different cpu after you've taken the lock but before calling RW_LOCK_HELD is called. We need the spinlock to ensure there is a wmb() there. git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@68 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
This commit is contained in:
parent
728b9dd800
commit
79f92663e3
|
@ -163,6 +163,8 @@ rw_tryenter(krwlock_t *rwlp, krw_t rw)
|
||||||
rwlp->rw_owner = current;
|
rwlp->rw_owner = current;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
BUG_ON(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -193,6 +195,8 @@ rw_enter(krwlock_t *rwlp, krw_t rw)
|
||||||
BUG_ON(rwlp->rw_owner != NULL);
|
BUG_ON(rwlp->rw_owner != NULL);
|
||||||
rwlp->rw_owner = current;
|
rwlp->rw_owner = current;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
BUG_ON(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,16 +29,21 @@ EXPORT_SYMBOL(__rw_write_held);
|
||||||
int
|
int
|
||||||
__rw_lock_held(krwlock_t *rwlp)
|
__rw_lock_held(krwlock_t *rwlp)
|
||||||
{
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
BUG_ON(rwlp->rw_magic != RW_MAGIC);
|
BUG_ON(rwlp->rw_magic != RW_MAGIC);
|
||||||
|
|
||||||
|
spin_lock_irq(&(rwlp->rw_sem.wait_lock));
|
||||||
#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
|
#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
|
||||||
if (rwlp->rw_sem.activity != 0) {
|
if (rwlp->rw_sem.activity != 0) {
|
||||||
#else
|
#else
|
||||||
if (rwlp->rw_sem.count != 0) {
|
if (rwlp->rw_sem.count != 0) {
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
rc = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
spin_unlock_irq(&(rwlp->rw_sem.wait_lock));
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__rw_lock_held);
|
EXPORT_SYMBOL(__rw_lock_held);
|
||||||
|
|
Loading…
Reference in New Issue