1
0

062-03-MIPS-Only-change-28-to-thread_info-if-coming-from-us.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From: Matt Redfearn <matt.redfearn@imgtec.com>
  2. Date: Mon, 19 Dec 2016 14:20:58 +0000
  3. Subject: [PATCH] MIPS: Only change $28 to thread_info if coming from user
  4. mode
  5. The SAVE_SOME macro is used to save the execution context on all
  6. exceptions.
  7. If an exception occurs while executing user code, the stack is switched
  8. to the kernel's stack for the current task, and register $28 is switched
  9. to point to the current_thread_info, which is at the bottom of the stack
  10. region.
  11. If the exception occurs while executing kernel code, the stack is left,
  12. and this change ensures that register $28 is not updated. This is the
  13. correct behaviour when the kernel can be executing on the separate irq
  14. stack, because the thread_info will not be at the base of it.
  15. With this change, register $28 is only switched to it's kernel
  16. conventional usage of the currrent thread info pointer at the point at
  17. which execution enters kernel space. Doing it on every exception was
  18. redundant, but OK without an IRQ stack, but will be erroneous once that
  19. is introduced.
  20. Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
  21. Reviewed-by: Maciej W. Rozycki <macro@imgtec.com>
  22. ---
  23. --- a/arch/mips/include/asm/stackframe.h
  24. +++ b/arch/mips/include/asm/stackframe.h
  25. @@ -216,12 +216,19 @@
  26. LONG_S $25, PT_R25(sp)
  27. LONG_S $28, PT_R28(sp)
  28. LONG_S $31, PT_R31(sp)
  29. +
  30. + /* Set thread_info if we're coming from user mode */
  31. + mfc0 k0, CP0_STATUS
  32. + sll k0, 3 /* extract cu0 bit */
  33. + bltz k0, 9f
  34. +
  35. ori $28, sp, _THREAD_MASK
  36. xori $28, _THREAD_MASK
  37. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  38. .set mips64
  39. pref 0, 0($28) /* Prefetch the current pointer */
  40. #endif
  41. +9:
  42. .set pop
  43. .endm