linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] locking/qrwlock: Fix write unlock issue in big endian
@ 2016-07-18  9:47 Pan Xinhui
  2016-07-21 16:17 ` Will Deacon
  2016-08-10 18:05 ` [tip:locking/core] locking/qrwlock: Fix write unlock bug on big endian systems tip-bot for pan xinhui
  0 siblings, 2 replies; 3+ messages in thread
From: Pan Xinhui @ 2016-07-18  9:47 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: peterz, arnd, Waiman.Long, mingo, will.deacon, boqun.feng, pan xinhui

From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>

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) <peterz@infradead.org>
Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
---
change from v3:
	rewrite totally. :)
change from v2:
	change macro's name, add comments.
change from v1:
	A typo fix which is really bad...
	thanks Will for the carefull review.
---
 include/asm-generic/qrwlock.h | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/qrwlock.h b/include/asm-generic/qrwlock.h
index 54a8e65..7d026bf 100644
--- a/include/asm-generic/qrwlock.h
+++ b/include/asm-generic/qrwlock.h
@@ -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 */
@@ -134,12 +147,22 @@ static inline void queued_read_unlock(struct qrwlock *lock)
 }
 
 /**
+ * __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);
 }
 
 /*
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] locking/qrwlock: Fix write unlock issue in big endian
  2016-07-18  9:47 [PATCH v4] locking/qrwlock: Fix write unlock issue in big endian Pan Xinhui
@ 2016-07-21 16:17 ` Will Deacon
  2016-08-10 18:05 ` [tip:locking/core] locking/qrwlock: Fix write unlock bug on big endian systems tip-bot for pan xinhui
  1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2016-07-21 16:17 UTC (permalink / raw)
  To: Pan Xinhui
  Cc: linux-kernel, linux-arch, peterz, arnd, Waiman.Long, mingo, boqun.feng

On Mon, Jul 18, 2016 at 05:47:39PM +0800, Pan Xinhui wrote:
> From: pan xinhui <xinhui.pan@linux.vnet.ibm.com>
> 
> 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) <peterz@infradead.org>
> Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
> ---
> change from v3:
> 	rewrite totally. :)
> change from v2:
> 	change macro's name, add comments.
> change from v1:
> 	A typo fix which is really bad...
> 	thanks Will for the carefull review.
> ---
>  include/asm-generic/qrwlock.h | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/include/asm-generic/qrwlock.h b/include/asm-generic/qrwlock.h
> index 54a8e65..7d026bf 100644
> --- a/include/asm-generic/qrwlock.h
> +++ b/include/asm-generic/qrwlock.h
> @@ -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 */
> @@ -134,12 +147,22 @@ static inline void queued_read_unlock(struct qrwlock *lock)
>  }
>  
>  /**
> + * __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);
> +}

Might be worth a comment here, saying that IS_BUILTIN expands to 1 or 0.

Either way, the patch looks correct to me:

Acked-by: Will Deacon <will.deacon@arm.com>

Will

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:locking/core] locking/qrwlock: Fix write unlock bug on big endian systems
  2016-07-18  9:47 [PATCH v4] locking/qrwlock: Fix write unlock issue in big endian Pan Xinhui
  2016-07-21 16:17 ` Will Deacon
@ 2016-08-10 18:05 ` tip-bot for pan xinhui
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for pan xinhui @ 2016-08-10 18:05 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, mingo, peterz, torvalds, xinhui.pan, akpm, paulmck,
	linux-kernel, hpa

Commit-ID:  2db34e8bf9a22f4e38b29deccee57457bc0e7d74
Gitweb:     http://git.kernel.org/tip/2db34e8bf9a22f4e38b29deccee57457bc0e7d74
Author:     pan xinhui <xinhui.pan@linux.vnet.ibm.com>
AuthorDate: Mon, 18 Jul 2016 17:47:39 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 10 Aug 2016 14:13:27 +0200

locking/qrwlock: Fix write unlock bug on big endian systems

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) <peterz@infradead.org>
Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman.Long@hpe.com
Cc: arnd@arndb.de
Cc: boqun.feng@gmail.com
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1468835259-4486-1-git-send-email-xinhui.pan@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/asm-generic/qrwlock.h | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/include/asm-generic/qrwlock.h b/include/asm-generic/qrwlock.h
index 54a8e65..7d026bf 100644
--- a/include/asm-generic/qrwlock.h
+++ b/include/asm-generic/qrwlock.h
@@ -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 */
@@ -134,12 +147,22 @@ static inline void queued_read_unlock(struct qrwlock *lock)
 }
 
 /**
+ * __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);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-10 18:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-18  9:47 [PATCH v4] locking/qrwlock: Fix write unlock issue in big endian Pan Xinhui
2016-07-21 16:17 ` Will Deacon
2016-08-10 18:05 ` [tip:locking/core] locking/qrwlock: Fix write unlock bug on big endian systems tip-bot for pan xinhui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).