Re: [PATCH v4] PPC: use CURRENT_THREAD_INFO instead of open coded assembly

2012-07-12 Thread Paul Mackerras
On Thu, Jul 05, 2012 at 09:41:35AM -0500, Stuart Yoder wrote:

 diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
 index ba3aeb4..bad42e3 100644
 --- a/arch/powerpc/kernel/entry_32.S
 +++ b/arch/powerpc/kernel/entry_32.S
 @@ -92,7 +92,7 @@ crit_transfer_to_handler:
   mfspr   r8,SPRN_SPRG_THREAD
   lwz r0,KSP_LIMIT(r8)
   stw r0,SAVED_KSP_LIMIT(r11)
 - rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
 + CURRENT_THREAD_INFO(r0, r1)
   stw r0,KSP_LIMIT(r8)
   /* fall through */
  #endif
 @@ -112,7 +112,7 @@ crit_transfer_to_handler:
   mfspr   r8,SPRN_SPRG_THREAD
   lwz r0,KSP_LIMIT(r8)
   stw r0,saved_ksp_limit@l(0)
 - rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
 + CURRENT_THREAD_INFO(r0, r1)
   stw r0,KSP_LIMIT(r8)
   /* fall through */
  #endif

Do you really mean to replace a rlwimi with a rlwinm?  If so, is that
because the rlwinm is a bug fix, or is it because you know something
special about KSP_LIMIT(r8) which means that rlwinm and rlwimi are
equivalent here?

Paul.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v4] PPC: use CURRENT_THREAD_INFO instead of open coded assembly

2012-07-12 Thread Benjamin Herrenschmidt
On Fri, 2012-07-13 at 08:45 +1000, Paul Mackerras wrote:
 On Thu, Jul 05, 2012 at 09:41:35AM -0500, Stuart Yoder wrote:
 
  diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
  index ba3aeb4..bad42e3 100644
  --- a/arch/powerpc/kernel/entry_32.S
  +++ b/arch/powerpc/kernel/entry_32.S
  @@ -92,7 +92,7 @@ crit_transfer_to_handler:
  mfspr   r8,SPRN_SPRG_THREAD
  lwz r0,KSP_LIMIT(r8)
  stw r0,SAVED_KSP_LIMIT(r11)
  -   rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
  +   CURRENT_THREAD_INFO(r0, r1)
  stw r0,KSP_LIMIT(r8)
  /* fall through */
   #endif
  @@ -112,7 +112,7 @@ crit_transfer_to_handler:
  mfspr   r8,SPRN_SPRG_THREAD
  lwz r0,KSP_LIMIT(r8)
  stw r0,saved_ksp_limit@l(0)
  -   rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
  +   CURRENT_THREAD_INFO(r0, r1)
  stw r0,KSP_LIMIT(r8)
  /* fall through */
   #endif
 
 Do you really mean to replace a rlwimi with a rlwinm?  If so, is that
 because the rlwinm is a bug fix, or is it because you know something
 special about KSP_LIMIT(r8) which means that rlwinm and rlwimi are
 equivalent here?

Ah that's an interesting one I hadn't spotted when reviewing. Both
variants (rlwimi and rlwinm)  will effectively replace the top bits of
KSP_LIMIT, switching it to the current stack.

The difference is that the original one (rlwimi) will preserve the
bottom bits.

Now, do we want those bottom bits ? It looks like we do if we want to
make the thread_info at the bottom of the stack as out of bounds.

So the patch breaks that. It will not generally break a working kernel
but the stack overflow detection may not trigger if the overflow is just
enough to override the thread infos.

Stuart, I already applied v4 of the patch to powerpc-next and I'd rather
not rebase it, can you send a fixup patch please, one that will
effecticely revert those two hunks, we can leave that open coded. While
at it, please add a comment explaining what the code does to avoid
similar confusion in the future.

Cheers,
Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v4] PPC: use CURRENT_THREAD_INFO instead of open coded assembly

2012-07-10 Thread Alexander Graf

On 05.07.2012, at 16:41, Stuart Yoder wrote:

 From: Stuart Yoder stuart.yo...@freescale.com
 
 Signed-off-by: Stuart Yoder stuart.yo...@freescale.com

Ben, ping?


Alex

 ---
 -v4: fixed build issues in exception-64s.h and exceptions-64s.S
 
 arch/powerpc/include/asm/exception-64s.h |4 ++--
 arch/powerpc/include/asm/thread_info.h   |6 ++
 arch/powerpc/kernel/entry_32.S   |   24 
 arch/powerpc/kernel/entry_64.S   |   14 +++---
 arch/powerpc/kernel/exceptions-64e.S |2 +-
 arch/powerpc/kernel/exceptions-64s.S |2 +-
 arch/powerpc/kernel/head_fsl_booke.S |2 +-
 arch/powerpc/kernel/idle_6xx.S   |4 ++--
 arch/powerpc/kernel/idle_book3e.S|2 +-
 arch/powerpc/kernel/idle_e500.S  |4 ++--
 arch/powerpc/kernel/idle_power4.S|2 +-
 arch/powerpc/kernel/misc_32.S|4 ++--
 arch/powerpc/kvm/bookehv_interrupts.S|6 +-
 arch/powerpc/mm/hash_low_32.S|8 
 arch/powerpc/sysdev/6xx-suspend.S|2 +-
 15 files changed, 44 insertions(+), 42 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/exception-64s.h 
 b/arch/powerpc/include/asm/exception-64s.h
 index d58fc4e..a43c147 100644
 --- a/arch/powerpc/include/asm/exception-64s.h
 +++ b/arch/powerpc/include/asm/exception-64s.h
 @@ -293,7 +293,7 @@ label##_hv:   
 \
 
 #define RUNLATCH_ON   \
 BEGIN_FTR_SECTION \
 - clrrdi  r3,r1,THREAD_SHIFT; \
 + CURRENT_THREAD_INFO(r3, r1);\
   ld  r4,TI_LOCAL_FLAGS(r3);  \
   andi.   r0,r4,_TLF_RUNLATCH;\
   beqlppc64_runlatch_on_trampoline;   \
 @@ -332,7 +332,7 @@ label##_common:   
 \
 #ifdef CONFIG_PPC_970_NAP
 #define FINISH_NAP\
 BEGIN_FTR_SECTION \
 - clrrdi  r11,r1,THREAD_SHIFT;\
 + CURRENT_THREAD_INFO(r11, r1);   \
   ld  r9,TI_LOCAL_FLAGS(r11); \
   andi.   r10,r9,_TLF_NAPPING;\
   bnelpower4_fixup_nap;   \
 diff --git a/arch/powerpc/include/asm/thread_info.h 
 b/arch/powerpc/include/asm/thread_info.h
 index 68831e9..faf9352 100644
 --- a/arch/powerpc/include/asm/thread_info.h
 +++ b/arch/powerpc/include/asm/thread_info.h
 @@ -22,6 +22,12 @@
 
 #define THREAD_SIZE   (1  THREAD_SHIFT)
 
 +#ifdef CONFIG_PPC64
 +#define CURRENT_THREAD_INFO(dest, sp)clrrdi dest, sp, THREAD_SHIFT
 +#else
 +#define CURRENT_THREAD_INFO(dest, sp)rlwinm dest, sp, 0, 0, 
 31-THREAD_SHIFT
 +#endif
 +
 #ifndef __ASSEMBLY__
 #include linux/cache.h
 #include asm/processor.h
 diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
 index ba3aeb4..bad42e3 100644
 --- a/arch/powerpc/kernel/entry_32.S
 +++ b/arch/powerpc/kernel/entry_32.S
 @@ -92,7 +92,7 @@ crit_transfer_to_handler:
   mfspr   r8,SPRN_SPRG_THREAD
   lwz r0,KSP_LIMIT(r8)
   stw r0,SAVED_KSP_LIMIT(r11)
 - rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
 + CURRENT_THREAD_INFO(r0, r1)
   stw r0,KSP_LIMIT(r8)
   /* fall through */
 #endif
 @@ -112,7 +112,7 @@ crit_transfer_to_handler:
   mfspr   r8,SPRN_SPRG_THREAD
   lwz r0,KSP_LIMIT(r8)
   stw r0,saved_ksp_limit@l(0)
 - rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
 + CURRENT_THREAD_INFO(r0, r1)
   stw r0,KSP_LIMIT(r8)
   /* fall through */
 #endif
 @@ -158,7 +158,7 @@ transfer_to_handler:
   tophys(r11,r11)
   addir11,r11,global_dbcr0@l
 #ifdef CONFIG_SMP
 - rlwinm  r9,r1,0,0,(31-THREAD_SHIFT)
 + CURRENT_THREAD_INFO(r9, r1)
   lwz r9,TI_CPU(r9)
   slwir9,r9,3
   add r11,r11,r9
 @@ -179,7 +179,7 @@ transfer_to_handler:
   ble-stack_ovf   /* then the kernel stack overflowed */
 5:
 #if defined(CONFIG_6xx) || defined(CONFIG_E500)
 - rlwinm  r9,r1,0,0,31-THREAD_SHIFT
 + CURRENT_THREAD_INFO(r9, r1)
   tophys(r9,r9)   /* check local flags */
   lwz r12,TI_LOCAL_FLAGS(r9)
   mtcrf   0x01,r12
 @@ -333,7 +333,7 @@ _GLOBAL(DoSyscall)
   mtmsr   r11
 1:
 #endif /* CONFIG_TRACE_IRQFLAGS */
 - rlwinm  r10,r1,0,0,(31-THREAD_SHIFT)/* current_thread_info() */
 + CURRENT_THREAD_INFO(r10, r1)
   lwz r11,TI_FLAGS(r10)
   andi.   r11,r11,_TIF_SYSCALL_T_OR_A
   bne-syscall_dotrace
 @@ -354,7 +354,7 @@ ret_from_syscall:
   bl  do_show_syscall_exit
 #endif
   mr  r6,r3
 - rlwinm  r12,r1,0,0,(31-THREAD_SHIFT)/* current_thread_info() */
 + CURRENT_THREAD_INFO(r12, r1)
   /* disable interrupts so current_thread_info()-flags can't change */
   LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
   /* Note: We don't bother telling lockdep about 

[PATCH v4] PPC: use CURRENT_THREAD_INFO instead of open coded assembly

2012-07-05 Thread Stuart Yoder
From: Stuart Yoder stuart.yo...@freescale.com

Signed-off-by: Stuart Yoder stuart.yo...@freescale.com
---
-v4: fixed build issues in exception-64s.h and exceptions-64s.S

 arch/powerpc/include/asm/exception-64s.h |4 ++--
 arch/powerpc/include/asm/thread_info.h   |6 ++
 arch/powerpc/kernel/entry_32.S   |   24 
 arch/powerpc/kernel/entry_64.S   |   14 +++---
 arch/powerpc/kernel/exceptions-64e.S |2 +-
 arch/powerpc/kernel/exceptions-64s.S |2 +-
 arch/powerpc/kernel/head_fsl_booke.S |2 +-
 arch/powerpc/kernel/idle_6xx.S   |4 ++--
 arch/powerpc/kernel/idle_book3e.S|2 +-
 arch/powerpc/kernel/idle_e500.S  |4 ++--
 arch/powerpc/kernel/idle_power4.S|2 +-
 arch/powerpc/kernel/misc_32.S|4 ++--
 arch/powerpc/kvm/bookehv_interrupts.S|6 +-
 arch/powerpc/mm/hash_low_32.S|8 
 arch/powerpc/sysdev/6xx-suspend.S|2 +-
 15 files changed, 44 insertions(+), 42 deletions(-)

diff --git a/arch/powerpc/include/asm/exception-64s.h 
b/arch/powerpc/include/asm/exception-64s.h
index d58fc4e..a43c147 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -293,7 +293,7 @@ label##_hv: 
\
 
 #define RUNLATCH_ON\
 BEGIN_FTR_SECTION  \
-   clrrdi  r3,r1,THREAD_SHIFT; \
+   CURRENT_THREAD_INFO(r3, r1);\
ld  r4,TI_LOCAL_FLAGS(r3);  \
andi.   r0,r4,_TLF_RUNLATCH;\
beqlppc64_runlatch_on_trampoline;   \
@@ -332,7 +332,7 @@ label##_common: 
\
 #ifdef CONFIG_PPC_970_NAP
 #define FINISH_NAP \
 BEGIN_FTR_SECTION  \
-   clrrdi  r11,r1,THREAD_SHIFT;\
+   CURRENT_THREAD_INFO(r11, r1);   \
ld  r9,TI_LOCAL_FLAGS(r11); \
andi.   r10,r9,_TLF_NAPPING;\
bnelpower4_fixup_nap;   \
diff --git a/arch/powerpc/include/asm/thread_info.h 
b/arch/powerpc/include/asm/thread_info.h
index 68831e9..faf9352 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -22,6 +22,12 @@
 
 #define THREAD_SIZE(1  THREAD_SHIFT)
 
+#ifdef CONFIG_PPC64
+#define CURRENT_THREAD_INFO(dest, sp)  clrrdi dest, sp, THREAD_SHIFT
+#else
+#define CURRENT_THREAD_INFO(dest, sp)  rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT
+#endif
+
 #ifndef __ASSEMBLY__
 #include linux/cache.h
 #include asm/processor.h
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index ba3aeb4..bad42e3 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -92,7 +92,7 @@ crit_transfer_to_handler:
mfspr   r8,SPRN_SPRG_THREAD
lwz r0,KSP_LIMIT(r8)
stw r0,SAVED_KSP_LIMIT(r11)
-   rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
+   CURRENT_THREAD_INFO(r0, r1)
stw r0,KSP_LIMIT(r8)
/* fall through */
 #endif
@@ -112,7 +112,7 @@ crit_transfer_to_handler:
mfspr   r8,SPRN_SPRG_THREAD
lwz r0,KSP_LIMIT(r8)
stw r0,saved_ksp_limit@l(0)
-   rlwimi  r0,r1,0,0,(31-THREAD_SHIFT)
+   CURRENT_THREAD_INFO(r0, r1)
stw r0,KSP_LIMIT(r8)
/* fall through */
 #endif
@@ -158,7 +158,7 @@ transfer_to_handler:
tophys(r11,r11)
addir11,r11,global_dbcr0@l
 #ifdef CONFIG_SMP
-   rlwinm  r9,r1,0,0,(31-THREAD_SHIFT)
+   CURRENT_THREAD_INFO(r9, r1)
lwz r9,TI_CPU(r9)
slwir9,r9,3
add r11,r11,r9
@@ -179,7 +179,7 @@ transfer_to_handler:
ble-stack_ovf   /* then the kernel stack overflowed */
 5:
 #if defined(CONFIG_6xx) || defined(CONFIG_E500)
-   rlwinm  r9,r1,0,0,31-THREAD_SHIFT
+   CURRENT_THREAD_INFO(r9, r1)
tophys(r9,r9)   /* check local flags */
lwz r12,TI_LOCAL_FLAGS(r9)
mtcrf   0x01,r12
@@ -333,7 +333,7 @@ _GLOBAL(DoSyscall)
mtmsr   r11
 1:
 #endif /* CONFIG_TRACE_IRQFLAGS */
-   rlwinm  r10,r1,0,0,(31-THREAD_SHIFT)/* current_thread_info() */
+   CURRENT_THREAD_INFO(r10, r1)
lwz r11,TI_FLAGS(r10)
andi.   r11,r11,_TIF_SYSCALL_T_OR_A
bne-syscall_dotrace
@@ -354,7 +354,7 @@ ret_from_syscall:
bl  do_show_syscall_exit
 #endif
mr  r6,r3
-   rlwinm  r12,r1,0,0,(31-THREAD_SHIFT)/* current_thread_info() */
+   CURRENT_THREAD_INFO(r12, r1)
/* disable interrupts so current_thread_info()-flags can't change */
LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
/* Note: We don't bother telling lockdep about it */
@@ -815,7 +815,7 @@ ret_from_except:
 
 user_exc_return: