Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[IA64] Fix bug in ia64 specific down() function

Chen, Kenneth W wrote:
> The memory order semantics for include/asm-ia64/semaphore.h:down()
> doesn't look right. It is using atomic_dec_return, which eventually
> translate into ia64_fetch_and_add() that uses release semantics.
> Shouldn't it use acquire semantics?

Use ia64_fetchadd() instead of atomic_dec_return()

Acked-by: Ken Chen <kenneth.w.chen@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>

authored by

Zoltan Menyhart and committed by
Tony Luck
4b16bfbf 8d08aed8

+4 -4
+4 -4
include/asm-ia64/semaphore.h
··· 61 61 down (struct semaphore *sem) 62 62 { 63 63 might_sleep(); 64 - if (atomic_dec_return(&sem->count) < 0) 64 + if (ia64_fetchadd(-1, &sem->count.counter, acq) < 1) 65 65 __down(sem); 66 66 } 67 67 ··· 75 75 int ret = 0; 76 76 77 77 might_sleep(); 78 - if (atomic_dec_return(&sem->count) < 0) 78 + if (ia64_fetchadd(-1, &sem->count.counter, acq) < 1) 79 79 ret = __down_interruptible(sem); 80 80 return ret; 81 81 } ··· 85 85 { 86 86 int ret = 0; 87 87 88 - if (atomic_dec_return(&sem->count) < 0) 88 + if (ia64_fetchadd(-1, &sem->count.counter, acq) < 1) 89 89 ret = __down_trylock(sem); 90 90 return ret; 91 91 } ··· 93 93 static inline void 94 94 up (struct semaphore * sem) 95 95 { 96 - if (atomic_inc_return(&sem->count) <= 0) 96 + if (ia64_fetchadd(1, &sem->count.counter, rel) <= -1) 97 97 __up(sem); 98 98 } 99 99