mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
powerpc: Fix write-after-destroy in lock elision [BZ #20822]
The update of *adapt_count after the release of the lock causes a race condition when thread A unlocks, thread B continues and destroys the mutex, and thread A writes to *adapt_count.
This commit is contained in:
@ -28,13 +28,16 @@ __lll_unlock_elision (int *lock, short *adapt_count, int pshared)
|
||||
__libc_tend (0);
|
||||
else
|
||||
{
|
||||
lll_unlock ((*lock), pshared);
|
||||
/* Update adapt_count in the critical section to prevent a
|
||||
write-after-destroy error as mentioned in BZ 20822. The
|
||||
following update of adapt_count has to be contained within
|
||||
the critical region of the fall-back lock in order to not violate
|
||||
the mutex destruction requirements. */
|
||||
short __tmp = atomic_load_relaxed (adapt_count);
|
||||
if (__tmp > 0)
|
||||
atomic_store_relaxed (adapt_count, __tmp--);
|
||||
|
||||
/* Update the adapt count AFTER completing the critical section.
|
||||
Doing this here prevents unneeded stalling when entering
|
||||
a critical section. Saving about 8% runtime on P8. */
|
||||
if (*adapt_count > 0)
|
||||
(*adapt_count)--;
|
||||
lll_unlock ((*lock), pshared);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user