Skip to content

Commit

Permalink
locking/qrwlock: Fix write unlock bug on big endian systems
Browse files Browse the repository at this point in the history
This patch aims to get rid of endianness in queued_write_unlock(). We
want to set  __qrwlock->wmode to NULL, however the address is not
&lock->cnts in big endian machine. That causes queued_write_unlock()
write NULL to the wrong field of __qrwlock.

So implement __qrwlock_write_byte() which returns the correct
__qrwlock->wmode address.

Suggested-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Pan Xinhui <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
pan xinhui authored and Ingo Molnar committed Aug 10, 2016
1 parent a2071cd commit 2db34e8
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions include/asm-generic/qrwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@
#include <asm-generic/qrwlock_types.h>

/*
* Writer states & reader shift and bias
* Writer states & reader shift and bias.
*
* | +0 | +1 | +2 | +3 |
* ----+----+----+----+----+
* LE | 78 | 56 | 34 | 12 | 0x12345678
* ----+----+----+----+----+
* | wr | rd |
* +----+----+----+----+
*
* ----+----+----+----+----+
* BE | 12 | 34 | 56 | 78 | 0x12345678
* ----+----+----+----+----+
* | rd | wr |
* +----+----+----+----+
*/
#define _QW_WAITING 1 /* A writer is waiting */
#define _QW_LOCKED 0xff /* A writer holds the lock */
Expand Down Expand Up @@ -133,13 +146,23 @@ static inline void queued_read_unlock(struct qrwlock *lock)
(void)atomic_sub_return_release(_QR_BIAS, &lock->cnts);
}

/**
* __qrwlock_write_byte - retrieve the write byte address of a queue rwlock
* @lock : Pointer to queue rwlock structure
* Return: the write byte address of a queue rwlock
*/
static inline u8 *__qrwlock_write_byte(struct qrwlock *lock)
{
return (u8 *)lock + 3 * IS_BUILTIN(CONFIG_CPU_BIG_ENDIAN);
}

/**
* queued_write_unlock - release write lock of a queue rwlock
* @lock : Pointer to queue rwlock structure
*/
static inline void queued_write_unlock(struct qrwlock *lock)
{
smp_store_release((u8 *)&lock->cnts, 0);
smp_store_release(__qrwlock_write_byte(lock), 0);
}

/*
Expand Down

0 comments on commit 2db34e8

Please sign in to comment.