Skip to contentSkip to conversation

locking/rwsem/x86: Add stack frame dependency for some inline asm

PATCH Superseded Miguel Bernal Marin 4 participants 27 messages Sep 6, 2017 – Sep 25, 2017 x86

lore
Share & tools
lore
#0 lore raw

cover locking/rwsem/x86: Add stack frame dependency for some inline asm

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Miguel Bernal Marin (3):
locking/rwsem/x86: Add stack frame dependency for __up_read() locking/rwsem/x86: Add stack frame dependency for __up_write() locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

 arch/x86/include/asm/rwsem.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/3 locking/rwsem/x86: Add stack frame dependency for __up_read()

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_read() inline asm (and its call instruction) before the frame pointer setup in up_read(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index a34e0d4b957d..762167afaec0 100644
@@ -166,14 +166,16 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
 static inline void __up_read(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_read\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 1, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n"
 		     "# ending __up_read\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/3 locking/rwsem/x86: Add stack frame dependency for __up_write()

In reply to Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_write() inline asm (and its call instruction) before the frame pointer setup in up_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index 762167afaec0..d26b6916b935 100644
@@ -186,14 +186,16 @@ static inline void __up_read(struct rw_semaphore *sem)
 static inline void __up_write(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_write\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 0xffff0001, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n\t"
 		     "# ending __up_write\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_WRITE_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/3 locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

In reply to Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __downgrade_write() inline asm (and its call instruction) before the frame pointer setup in downgrade_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index d26b6916b935..a749dc6a3103 100644
@@ -205,8 +205,10 @@ static inline void __up_write(struct rw_semaphore *sem)
  */
 static inline void __downgrade_write(struct rw_semaphore *sem)
 {
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%2,(%2)\n\t"
 		     /*
 		      * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
 		      *     0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -215,7 +217,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 		     "  call call_rwsem_downgrade_wake\n"
 		     "1:\n\t"
 		     "# ending __downgrade_write\n"
-		     : "+m" (sem->count)
+		     : "+m" (sem->count), "+r" (__sp)
 		     : "a" (sem), "er" (-RWSEM_WAITING_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#4 lore raw

Re: [PATCH 3/3] locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

Quoted 20 lines · Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __downgrade_write() inline asm (and its call instruction) before the frame pointer setup in downgrade_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +0 -0
index d26b6916b935..a749dc6a3103 100644

arch/x86/include/asm/rwsem.h static inline void __up_write(struct rw_semaphore *sem) · line 211

Quoted 8 lines
arch/x86/include/asm/rwsem.h +3 -1
@@ -205,8 +205,10 @@ static inline void __up_write(struct rw_semaphore *sem)
  */
 static inline void __downgrade_write(struct rw_semaphore *sem)
 {
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%2,(%2)\n\t"

The '%2' should be changed to '%3'

		     LOCK_PREFIX _ASM_ADD "%3,(%2)\n\t"

because both inputs' indices are shifted by the new output constraint.

Quoted 11 lines
arch/x86/include/asm/rwsem.h +1 -1
 		     /*
 		      * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
 		      *     0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -215,7 +217,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 		     "  call call_rwsem_downgrade_wake\n"
 		     "1:\n\t"
 		     "# ending __downgrade_write\n"
-		     : "+m" (sem->count)
+		     : "+m" (sem->count), "+r" (__sp)
 		     : "a" (sem), "er" (-RWSEM_WAITING_BIAS)
 		     : "memory", "cc");
Signature · 1 line
Josh
#5 lore raw

Re: [PATCH 3/3] locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

Quoted 32 lines · Josh Poimboeuf
Quoted 20 lines · Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __downgrade_write() inline asm (and its call instruction) before the frame pointer setup in downgrade_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +0 -0
index d26b6916b935..a749dc6a3103 100644

arch/x86/include/asm/rwsem.h static inline void __up_write(struct rw_semaphore *sem) · line 211

Quoted 8 lines
arch/x86/include/asm/rwsem.h +3 -1
@@ -205,8 +205,10 @@ static inline void __up_write(struct rw_semaphore *sem)
  */
 static inline void __downgrade_write(struct rw_semaphore *sem)
 {
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%2,(%2)\n\t"

The '%2' should be changed to '%3'

Quoted 4 lines
		     LOCK_PREFIX _ASM_ADD "%3,(%2)\n\t"

because both inputs' indices are shifted by the new output constraint.

Thanks, I will send the V2.

Quoted 14 lines
Quoted 11 lines
arch/x86/include/asm/rwsem.h +1 -1
 		     /*
 		      * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
 		      *     0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -215,7 +217,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 		     "  call call_rwsem_downgrade_wake\n"
 		     "1:\n\t"
 		     "# ending __downgrade_write\n"
-		     : "+m" (sem->count)
+		     : "+m" (sem->count), "+r" (__sp)
 		     : "a" (sem), "er" (-RWSEM_WAITING_BIAS)
 		     : "memory", "cc");
Signature · 1 line
Josh
Signature · 4 lines
Regards,

Miguel Bernal Marin                     Open Source Technology Center
https://clearlinux.org                              Intel Corporation
#6 lore raw

Re: [PATCH 3/3] locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

In reply to Josh Poimboeuf
Quoted 32 lines · Josh Poimboeuf
Quoted 20 lines · Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __downgrade_write() inline asm (and its call instruction) before the frame pointer setup in downgrade_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +0 -0
index d26b6916b935..a749dc6a3103 100644

arch/x86/include/asm/rwsem.h static inline void __up_write(struct rw_semaphore *sem) · line 211

Quoted 8 lines
arch/x86/include/asm/rwsem.h +3 -1
@@ -205,8 +205,10 @@ static inline void __up_write(struct rw_semaphore *sem)
  */
 static inline void __downgrade_write(struct rw_semaphore *sem)
 {
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%2,(%2)\n\t"

The '%2' should be changed to '%3'

Quoted 3 lines
		     LOCK_PREFIX _ASM_ADD "%3,(%2)\n\t"

because both inputs' indices are shifted by the new output constraint.

Even better would be to used named operands.

#7 lore raw

v2 cover locking/rwsem/x86: Add stack frame dependency for some inline asm

In reply to Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Changes in v2:
- Update first parameter from _ASM_ADD to '%3' at __downgrade_write()

Miguel Bernal Marin (3):
locking/rwsem/x86: Add stack frame dependency for __up_read() locking/rwsem/x86: Add stack frame dependency for __up_write() locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

 arch/x86/include/asm/rwsem.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
Signature · 1 line
2.14.1
#8 lore raw

PATCH v2 1/3 locking/rwsem/x86: Add stack frame dependency for __up_read()

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_read() inline asm (and its call instruction) before the frame pointer setup in up_read(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index a34e0d4b957d..762167afaec0 100644
@@ -166,14 +166,16 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
 static inline void __up_read(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_read\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 1, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n"
 		     "# ending __up_read\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#9 lore raw

Re: [PATCH v2 1/3] locking/rwsem/x86: Add stack frame dependency for __up_read()

Quoted 27 lines · Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_read() inline asm (and its call instruction) before the frame pointer setup in up_read(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +2 -1
index a34e0d4b957d..762167afaec0 100644
@@ -166,14 +166,16 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
 static inline void __up_read(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_read\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"

arch/x86/include/asm/rwsem.h static inline bool __down_write_trylock(struct rw_semaphore *sem) · line 180

Quoted 10 lines
arch/x86/include/asm/rwsem.h +2 -1
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 1, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n"
 		     "# ending __up_read\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
 		     : "memory", "cc");

Please also convert it to named operands (in separate patches!) - this apparently BASIC inspired labeling syntax of GCC is utterly confusing, counterproductive and somewhat embarrasing as well, considering that we write 2017.

Thanks,

Ingo

#10 lore raw

Re: [PATCH v2 1/3] locking/rwsem/x86: Add stack frame dependency for __up_read()

Quoted 36 lines · Ingo Molnar
Quoted 33 lines · Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_read() inline asm (and its call instruction) before the frame pointer setup in up_read(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +3 -1
index a34e0d4b957d..762167afaec0 100644
@@ -166,14 +166,16 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
 static inline void __up_read(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_read\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 1, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n"
 		     "# ending __up_read\n"
Quoted 8 lines

arch/x86/include/asm/rwsem.h static inline bool __down_write_trylock(struct rw_semaphore *sem) · line 180

Quoted 4 lines
arch/x86/include/asm/rwsem.h +1 -1
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
 		     : "memory", "cc");

Please also convert it to named operands (in separate patches!) - this apparently BASIC inspired labeling syntax of GCC is utterly confusing, counterproductive and somewhat embarrasing as well, considering that we write 2017.

Sorry for delay response,
So I will add the named operands on the v3

Quoted 4 lines

Thanks,

Ingo

Signature · 4 lines
Regards,

Miguel Bernal Marin                     Open Source Technology Center
https://clearlinux.org                              Intel Corporation
#11 lore raw

PATCH v2 2/3 locking/rwsem/x86: Add stack frame dependency for __up_write()

In reply to Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_write() inline asm (and its call instruction) before the frame pointer setup in up_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index 762167afaec0..d26b6916b935 100644
@@ -186,14 +186,16 @@ static inline void __up_read(struct rw_semaphore *sem)
 static inline void __up_write(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_write\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 0xffff0001, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n\t"
 		     "# ending __up_write\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_WRITE_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#12 lore raw

PATCH v2 3/3 locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

In reply to Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __downgrade_write() inline asm (and its call instruction) before the frame pointer setup in downgrade_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index d26b6916b935..a749dc6a3103 100644
@@ -205,8 +205,10 @@ static inline void __up_write(struct rw_semaphore *sem)
  */
 static inline void __downgrade_write(struct rw_semaphore *sem)
 {
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%3,(%2)\n\t"
 		     /*
 		      * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
 		      *     0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -215,7 +217,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 		     "  call call_rwsem_downgrade_wake\n"
 		     "1:\n\t"
 		     "# ending __downgrade_write\n"
-		     : "+m" (sem->count)
+		     : "+m" (sem->count), "+r" (__sp)
 		     : "a" (sem), "er" (-RWSEM_WAITING_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
Reviewed-by on the v2 series
#13 lore raw
In reply to Miguel Bernal Marin
Quoted 15 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Changes in v2:
- Update first parameter from _ASM_ADD to '%3' at __downgrade_write()

Quoted 7 lines

Miguel Bernal Marin (3):
locking/rwsem/x86: Add stack frame dependency for __up_read() locking/rwsem/x86: Add stack frame dependency for __up_write() locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

 arch/x86/include/asm/rwsem.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

For the series:

Signature · 1 line
Josh
#14 lore raw

v3 cover locking/rwsem/x86: Add stack frame dependency for some inline asm

In reply to Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

Changes in v3:
- Convert to named operands

Changes in v2:
- Update first parameter from _ASM_ADD to '%3' at __downgrade_write()

Miguel Bernal Marin (6):
locking/rwsem/x86: Add stack frame dependency for __up_read() locking/rwsem/x86: Add stack frame dependency for __up_write() locking/rwsem/x86: Add stack frame dependency for __downgrade_write() x86, asm/rwsem: Use named operands in __up_read()
x86, asm/rwsem: Use named operands in __up_write()
x86, asm/rwsem: Use named operands in __downgrade_write()

 arch/x86/include/asm/rwsem.h | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
Signature · 1 line
2.14.1
#15 lore raw

PATCH v3 1/6 locking/rwsem/x86: Add stack frame dependency for __up_read()

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_read() inline asm (and its call instruction) before the frame pointer setup in up_read(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index a34e0d4b957d..762167afaec0 100644
@@ -166,14 +166,16 @@ static inline bool __down_write_trylock(struct rw_semaphore *sem)
 static inline void __up_read(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_read\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 1, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n"
 		     "# ending __up_read\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#16 lore raw

PATCH v3 2/6 locking/rwsem/x86: Add stack frame dependency for __up_write()

In reply to Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __up_write() inline asm (and its call instruction) before the frame pointer setup in up_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index 762167afaec0..d26b6916b935 100644
@@ -186,14 +186,16 @@ static inline void __up_read(struct rw_semaphore *sem)
 static inline void __up_write(struct rw_semaphore *sem)
 {
 	long tmp;
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __up_write\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%2)\n\t"
+		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
 		     /* subtracts 0xffff0001, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n\t"
 		     "# ending __up_write\n"
-		     : "+m" (sem->count), "=d" (tmp)
+		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
 		     : "a" (sem), "1" (-RWSEM_ACTIVE_WRITE_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#17 lore raw

PATCH v3 3/6 locking/rwsem/x86: Add stack frame dependency for __downgrade_write()

In reply to Miguel Bernal Marin

kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

The warning means gcc 7.2.0 placed the __downgrade_write() inline asm (and its call instruction) before the frame pointer setup in downgrade_write(), which breaks frame pointer convention and can result in incorrect stack traces.

Force a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

---
 arch/x86/include/asm/rwsem.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +4 -2
index d26b6916b935..8400ad3e17dc 100644
@@ -205,8 +205,10 @@ static inline void __up_write(struct rw_semaphore *sem)
  */
 static inline void __downgrade_write(struct rw_semaphore *sem)
 {
+	register void *__sp asm(_ASM_SP);
+
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%3,(%2)\n\t"
 		     /*
 		      * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
 		      *     0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -215,7 +217,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 		     "  call call_rwsem_downgrade_wake\n"
 		     "1:\n\t"
 		     "# ending __downgrade_write\n"
-		     : "+m" (sem->count)
+		     : "+m" (sem->count), "+r" (__sp)
 		     : "a" (sem), "er" (-RWSEM_WAITING_BIAS)
 		     : "memory", "cc");
 }
Signature · 1 line
2.14.1
#18 lore raw

PATCH v3 4/6 x86, asm/rwsem: Use named operands in __up_read()

In reply to Miguel Bernal Marin

Since GCC version 3.1, it is possible to specify input and output operands using symbolic names which can be referenced within the assembler code.

Convert to named operands makes easy to understand and maintain for future changes.

---
 arch/x86/include/asm/rwsem.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/rwsem.h +3 -3
index 8400ad3e17dc..2b3fb6d316f5 100644
@@ -169,14 +169,14 @@ static inline void __up_read(struct rw_semaphore *sem)
 	register void *__sp asm(_ASM_SP);
 
 	asm volatile("# beginning __up_read\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
+		     LOCK_PREFIX "  xadd      %[tmp],(%[sem])\n\t"
 		     /* subtracts 1, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n"
 		     "# ending __up_read\n"
-		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
-		     : "a" (sem), "1" (-RWSEM_ACTIVE_READ_BIAS)
+		     : "+m" (sem->count), [tmp] "=d" (tmp), "+r" (__sp)
+		     : [sem] "a" (sem), "[tmp]" (-RWSEM_ACTIVE_READ_BIAS)
 		     : "memory", "cc");
 }
 
Signature · 1 line
2.14.1
#19 lore raw

PATCH v3 5/6 x86, asm/rwsem: Use named operands in __up_write()

In reply to Miguel Bernal Marin

Since GCC version 3.1, it is possible to specify input and output operands using symbolic names which can be referenced within the assembler code.

Convert to named operands makes easy to understand and maintain for future changes.

---
 arch/x86/include/asm/rwsem.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/rwsem.h +3 -3
index 2b3fb6d316f5..3245902e961f 100644
@@ -189,14 +189,14 @@ static inline void __up_write(struct rw_semaphore *sem)
 	register void *__sp asm(_ASM_SP);
 
 	asm volatile("# beginning __up_write\n\t"
-		     LOCK_PREFIX "  xadd      %1,(%3)\n\t"
+		     LOCK_PREFIX "  xadd      %[tmp],(%[sem])\n\t"
 		     /* subtracts 0xffff0001, returns the old value */
 		     "  jns        1f\n\t"
 		     "  call call_rwsem_wake\n" /* expects old value in %edx */
 		     "1:\n\t"
 		     "# ending __up_write\n"
-		     : "+m" (sem->count), "=d" (tmp), "+r" (__sp)
-		     : "a" (sem), "1" (-RWSEM_ACTIVE_WRITE_BIAS)
+		     : "+m" (sem->count), [tmp] "=d" (tmp), "+r" (__sp)
+		     : [sem] "a" (sem), "[tmp]" (-RWSEM_ACTIVE_WRITE_BIAS)
 		     : "memory", "cc");
 }
 
Signature · 1 line
2.14.1
#20 lore raw

PATCH v3 6/6 x86, asm/rwsem: Use named operands in __downgrade_write()

In reply to Miguel Bernal Marin

Since GCC version 3.1, it is possible to specify input and output operands using symbolic names which can be referenced within the assembler code.

Convert to named operands makes easy to understand and maintain for future changes.

---
 arch/x86/include/asm/rwsem.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/rwsem.h +2 -2
index 3245902e961f..1f5d083599ba 100644
@@ -208,7 +208,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 	register void *__sp asm(_ASM_SP);
 
 	asm volatile("# beginning __downgrade_write\n\t"
-		     LOCK_PREFIX _ASM_ADD "%3,(%2)\n\t"
+		     LOCK_PREFIX _ASM_ADD "%[inc],(%[sem])\n\t"
 		     /*
 		      * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
 		      *     0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
@@ -218,7 +218,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
 		     "1:\n\t"
 		     "# ending __downgrade_write\n"
 		     : "+m" (sem->count), "+r" (__sp)
-		     : "a" (sem), "er" (-RWSEM_WAITING_BIAS)
+		     : [sem] "a" (sem), [inc] "er" (-RWSEM_WAITING_BIAS)
 		     : "memory", "cc");
 }
 
Signature · 1 line
2.14.1
#21 lore raw
In reply to Miguel Bernal Marin
Quoted 6 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

Quoted 8 lines

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

I've got a patch going around which will change the way we do this, so you'll probably need to do a v3 after my patch gets merged. I'll add you to cc for the next revision.

Signature · 1 line
Josh
#22 lore raw
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Quoted 7 lines
Quoted 2 lines

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

I've got a patch going around which will change the way we do this, so you'll probably need to do a v3 after my patch gets merged. I'll add you to cc for the next revision.

Ok, I will wait to see your changes merged.

Thanks.

Quoted 2 lines
Signature · 1 line
Josh
Signature · 4 lines
Regards,

Miguel Bernal Marin                     Open Source Technology Center
https://clearlinux.org                              Intel Corporation
#23 lore raw
In reply to Josh Poimboeuf
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Quoted 7 lines
Quoted 2 lines

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

I've got a patch going around which will change the way we do this, so you'll probably need to do a v3 after my patch gets merged. I'll add you to cc for the next revision.

With your new patches (at v4.14.-rc2) the warning is not seen any more, so I will send only the named operand patches (in separate thread), as this fix is not more needed.

Quoted 2 lines
Signature · 1 line
Josh
Signature · 4 lines
Regards,

Miguel Bernal Marin                     Open Source Technology Center
https://clearlinux.org                              Intel Corporation
#24 lore raw
Quoted 17 lines · Miguel Bernal Marin
Quoted 16 lines · Josh Poimboeuf
Quoted 14 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

Quoted 8 lines
Quoted 4 lines

I've got a patch going around which will change the way we do this, so you'll probably need to do a v3 after my patch gets merged. I'll add you to cc for the next revision.

With your new patches (at v4.14.-rc2) the warning is not seen any more, so I will send only the named operand patches (in separate thread), as this fix is not more needed.

Any chance you tested with GCC 7? With GCC 6 and older you might still see the warnings.

Signature · 1 line
Josh
#25 lore raw
Quoted 23 lines · Josh Poimboeuf
Quoted 22 lines · Miguel Bernal Marin
Quoted 20 lines · Josh Poimboeuf
Quoted 6 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

Quoted 8 lines

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

I've got a patch going around which will change the way we do this, so you'll probably need to do a v3 after my patch gets merged. I'll add you to cc for the next revision.

Quoted 6 lines
Quoted 3 lines

With your new patches (at v4.14.-rc2) the warning is not seen any more, so I will send only the named operand patches (in separate thread), as this fix is not more needed.

Any chance you tested with GCC 7? With GCC 6 and older you might still see the warnings.

Sorry, reading again it looks like your warnings only started showing up in GCC 7.2.0? If so, then it does make sense that your fix isn't needed any more, because my patch fixed this issue for *all* inline asm for GCC 7+.

Signature · 1 line
Josh
#26 lore raw
Quoted 28 lines · Josh Poimboeuf
Quoted 27 lines · Josh Poimboeuf
Quoted 25 lines · Miguel Bernal Marin
Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Miguel Bernal Marin

Some warning were showed by objtool using gcc 7.2.0

kernel/locking/rwsem.o: warning: objtool: up_read()+0x11: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: up_write()+0x17: call without frame pointer save/setup kernel/locking/rwsem.o: warning: objtool: downgrade_write()+0x22: call without frame pointer save/setup

which means gcc placed an inline asm function and its call instruction before the frame pointer setup.

This series forces a stack frame to be created before the call instruction by listing the stack pointer as an output operand in the inline asm statement.

Quoted 7 lines
Quoted 2 lines

Also to be easy to maintain and understand the operands from the extended assembler instructions were converted to named operands.

I've got a patch going around which will change the way we do this, so you'll probably need to do a v3 after my patch gets merged. I'll add you to cc for the next revision.

With your new patches (at v4.14.-rc2) the warning is not seen any more, so I will send only the named operand patches (in separate thread), as this fix is not more needed.

Quoted 8 lines
Quoted 2 lines

Any chance you tested with GCC 7? With GCC 6 and older you might still see the warnings.

Sorry, reading again it looks like your warnings only started showing up in GCC 7.2.0? If so, then it does make sense that your fix isn't needed any more, because my patch fixed this issue for *all* inline asm for GCC 7+.

Yes it was with GCC 7.2.0

Quoted 2 lines
Signature · 1 line
Josh
Signature · 4 lines
Regards,

Miguel Bernal Marin                     Open Source Technology Center
https://clearlinux.org                              Intel Corporation