powerpc: Switch to CONFIG_THREAD_INFO_IN_TASK
Subsystems (5)
v3 cover powerpc: Switch to CONFIG_THREAD_INFO_IN_TASK
The purpose of this serie is to activate CONFIG_THREAD_INFO_IN_TASK which moves the thread_info into task_struct.
Moving thread_info into task_struct has the following advantages:
- It protects thread_info from corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.
Changes since RFC v2:
- Removed the modification of names in asm-offsets
- Created a rule in arch/powerpc/Makefile to append the offset of current->cpu in CFLAGS
- Modified asm/smp.h to use the offset set in CFLAGS
- Squashed the renaming of THREAD_INFO to TASK_STACK in the preparation patch
- Moved the modification of current_pt_regs in the patch activating CONFIG_THREAD_INFO_IN_TASK
Changes since RFC v1:
- Removed the first patch which was modifying header inclusion order in timer
- Modified some names in asm-offsets to avoid conflicts when including asm-offsets in C files
- Modified asm/smp.h to avoid having to include linux/sched.h (using asm-offsets instead)
- Moved some changes from the activation patch to the preparation patch.
Christophe Leroy (7):
book3s/64: avoid circular header inclusion in mmu-hash.h
powerpc: Prepare for moving thread_info into task_struct
powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
powerpc: regain entire stack space
powerpc: 'current_set' is now a table of task_struct pointers powerpc/32: Remove CURRENT_THREAD_INFO and rename TI_CPU powerpc/64: Modify CURRENT_THREAD_INFO()
arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 6 +++ arch/powerpc/include/asm/asm-prototypes.h | 4 +- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 2 +- arch/powerpc/include/asm/exception-64s.h | 4 +- arch/powerpc/include/asm/irq.h | 14 +++--- arch/powerpc/include/asm/livepatch.h | 2 +- arch/powerpc/include/asm/processor.h | 39 ++------------- arch/powerpc/include/asm/ptrace.h | 2 +- arch/powerpc/include/asm/reg.h | 2 +- arch/powerpc/include/asm/smp.h | 8 +++- arch/powerpc/include/asm/task_size.h | 42 ++++++++++++++++ arch/powerpc/include/asm/thread_info.h | 17 +------ arch/powerpc/kernel/asm-offsets.c | 8 ++-- arch/powerpc/kernel/entry_32.S | 66 +++++++++----------------- arch/powerpc/kernel/entry_64.S | 12 ++--- arch/powerpc/kernel/epapr_hcalls.S | 5 +- arch/powerpc/kernel/exceptions-64e.S | 13 +---- arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/kernel/head_32.S | 14 +++--- arch/powerpc/kernel/head_40x.S | 4 +- arch/powerpc/kernel/head_44x.S | 8 ++-- arch/powerpc/kernel/head_64.S | 1 + arch/powerpc/kernel/head_8xx.S | 2 +- arch/powerpc/kernel/head_booke.h | 12 ++--- arch/powerpc/kernel/head_fsl_booke.S | 16 +++---- arch/powerpc/kernel/idle_6xx.S | 8 ++-- arch/powerpc/kernel/idle_book3e.S | 2 +- arch/powerpc/kernel/idle_e500.S | 8 ++-- arch/powerpc/kernel/idle_power4.S | 2 +- arch/powerpc/kernel/irq.c | 66 ++++---------------------- arch/powerpc/kernel/kgdb.c | 28 ----------- arch/powerpc/kernel/machine_kexec_64.c | 6 +-- arch/powerpc/kernel/misc_32.S | 17 +++---- arch/powerpc/kernel/process.c | 15 +++--- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/setup_32.c | 15 ++---- arch/powerpc/kernel/setup_64.c | 29 ++--------- arch/powerpc/kernel/smp.c | 16 +++---- arch/powerpc/kernel/trace/ftrace_64_mprofile.S | 6 +-- arch/powerpc/kvm/book3s_hv_hmi.c | 1 + arch/powerpc/mm/hash_low_32.S | 14 ++---- arch/powerpc/sysdev/6xx-suspend.S | 5 +- arch/powerpc/xmon/xmon.c | 2 +- 44 files changed, 203 insertions(+), 345 deletions(-) create mode 100644 arch/powerpc/include/asm/task_size.h
Signature · 1 line
2.13.3
RFC PATCH v3 1/7 book3s/64: avoid circular header inclusion in mmu-hash.h
When activating CONFIG_THREAD_INFO_IN_TASK, linux/sched.h includes asm/current.h. This generates a circular dependency. To avoid that, asm/processor.h shall not be included in mmu-hash.h
In order to do that, this patch moves into a new header called asm/task_size.h the information from asm/processor.h requires by mmu-hash.h
--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 2 +- arch/powerpc/include/asm/processor.h | 34 +--------------------- arch/powerpc/include/asm/task_size.h | 42 +++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_hmi.c | 1 + 4 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 arch/powerpc/include/asm/task_size.h
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -1
@@ -23,7 +23,7 @@*/ #include <asm/book3s/64/pgtable.h> #include <asm/bug.h> -#include <asm/processor.h> +#include <asm/task_size.h> #include <asm/cpu_has_feature.h> /*
arch/powerpc/include/asm/processor.h +1 -33
@@ -101,40 +101,8 @@ void release_thread(struct task_struct *);#endif #ifdef CONFIG_PPC64 -/* -* 64-bit user address space can have multiple limits -* For now supported values are: -*/ -#define TASK_SIZE_64TB (0x0000400000000000UL) -#define TASK_SIZE_128TB (0x0000800000000000UL) -#define TASK_SIZE_512TB (0x0002000000000000UL) -#define TASK_SIZE_1PB (0x0004000000000000UL) -#define TASK_SIZE_2PB (0x0008000000000000UL) -/* -* With 52 bits in the address we can support -* upto 4PB of range. -*/ -#define TASK_SIZE_4PB (0x0010000000000000UL) -/* -* For now 512TB is only supported with book3s and 64K linux page size. -*/ -#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_PPC_64K_PAGES ) -/* -* Max value currently used: -*/ -#define TASK_SIZE_USER64 TASK_SIZE_4PB -#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB -#define TASK_CONTEXT_SIZE TASK_SIZE_512TB -#else -#define TASK_SIZE_USER64 TASK_SIZE_64TB -#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB -/* -* We don't need to allocate extended context ids for 4K page size, because -* we limit the max effective address on this config to 64TB. -*/ -#define TASK_CONTEXT_SIZE TASK_SIZE_64TB -#endif +#include <asm/task_size.h> /* * 32-bit user address space is 4GB - 1 page
arch/powerpc/include/asm/task_size.h new file +42 -0
42 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_hmi.c +1 -0
@@ -24,6 +24,7 @@#include <linux/compiler.h> #include <asm/paca.h> #include <asm/hmi.h> +#include <asm/processor.h> void wait_for_subcore_guest_exit (void ) {
Signature · 1 line
2.13.3
Re: [RFC PATCH v3 1/7] book3s/64: avoid circular header inclusion in mmu-hash.h
Quoted 7 lines · On Mon, 1 Oct 2018 12:30:19 +0000 (UTC) Christophe Leroy…
When activating
CONFIG_THREAD_INFO_IN_TASK,linux/sched.hincludesasm/current.h. This generates a circular dependency. To avoid that,asm/processor.hshall not be included inmmu-hash.hIn order to do that, this patch moves into a new header called
asm/task_size.hthe information fromasm/processor.hrequires bymmu-hash.h
Doesn't look like you use this header in 32-bit code. Put task_size.h in asm/64/ maybe?
Quoted 132 lines
Signed-off-by Christophe Leroy <[email protected]>--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 2 +- arch/powerpc/include/asm/processor.h | 34 +--------------------- arch/powerpc/include/asm/task_size.h | 42 +++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_hmi.c | 1 + 4 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 arch/powerpc/include/asm/task_size.harch/powerpc/include/asm/book3s/64/mmu-hash.h +1
-1@@ -23,7 +23,7 @@*/ #include <asm/book3s/64/pgtable.h> #include <asm/bug.h> -#include <asm/processor.h> +#include <asm/task_size.h> #include <asm/cpu_has_feature.h> /* arch/powerpc/include/asm/processor.h +1
-33@@ -101,40 +101,8 @@ void release_thread(struct task_struct *);#endif #ifdef CONFIG_PPC64 -/* -* 64-bit user address space can have multiple limits -* For now supported values are: -*/ -#define TASK_SIZE_64TB (0x0000400000000000UL) -#define TASK_SIZE_128TB (0x0000800000000000UL) -#define TASK_SIZE_512TB (0x0002000000000000UL) -#define TASK_SIZE_1PB (0x0004000000000000UL) -#define TASK_SIZE_2PB (0x0008000000000000UL) -/* -* With 52 bits in the address we can support -* upto 4PB of range. -*/ -#define TASK_SIZE_4PB (0x0010000000000000UL) -/* -* For now 512TB is only supported with book3s and 64K linux page size. -*/ -#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_PPC_64K_PAGES ) -/* -* Max value currently used: -*/ -#define TASK_SIZE_USER64 TASK_SIZE_4PB -#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB -#define TASK_CONTEXT_SIZE TASK_SIZE_512TB -#else -#define TASK_SIZE_USER64 TASK_SIZE_64TB -#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB -/* -* We don't need to allocate extended context ids for 4K page size, because -* we limit the max effective address on this config to 64TB. -*/ -#define TASK_CONTEXT_SIZE TASK_SIZE_64TB -#endif +#include <asm/task_size.h> /* * 32-bit user address space is 4GB - 1 page arch/powerpc/include/asm/task_size.h new file +42
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_TASK_SIZE_H +#define _ASM_POWERPC_TASK_SIZE_H + +#ifdef CONFIG_PPC64 +/* +* 64-bit user address space can have multiple limits +* For now supported values are: +*/ +#define TASK_SIZE_64TB (0x0000400000000000UL) +#define TASK_SIZE_128TB (0x0000800000000000UL) +#define TASK_SIZE_512TB (0x0002000000000000UL) +#define TASK_SIZE_1PB (0x0004000000000000UL) +#define TASK_SIZE_2PB (0x0008000000000000UL) +/* +* With 52 bits in the address we can support +* upto 4PB of range. +*/ +#define TASK_SIZE_4PB (0x0010000000000000UL) + +/* +* For now 512TB is only supported with book3s and 64K linux page size. +*/ +#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_PPC_64K_PAGES ) +/* +* Max value currently used: +*/ +#define TASK_SIZE_USER64 TASK_SIZE_4PB +#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB +#define TASK_CONTEXT_SIZE TASK_SIZE_512TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB +/* +* We don't need to allocate extended context ids for 4K page size, because +* we limit the max effective address on this config to 64TB. +*/ +#define TASK_CONTEXT_SIZE TASK_SIZE_64TB +#endif + +#endif /* CONFIG_PPC64 */ +#endif /* _ASM_POWERPC_TASK_SIZE_H */ arch/powerpc/kvm/book3s_hv_hmi.c +1
-0@@ -24,6 +24,7 @@#include <linux/compiler.h> #include <asm/paca.h> #include <asm/hmi.h> +#include <asm/processor.h> void wait_for_subcore_guest_exit (void ) {Signature · 1 line
2.13.3
Re: [RFC PATCH v3 1/7] book3s/64: avoid circular header inclusion in mmu-hash.h
Le 03/10/2018 à 06:24, Nicholas Piggin a écrit :
Quoted 7 lines
Quoted 4 lines · On Mon, 1 Oct 2018 12:30:19 +0000 (UTC) Christophe Leroy…
When activating
CONFIG_THREAD_INFO_IN_TASK,linux/sched.hincludesasm/current.h. This generates a circular dependency. To avoid that,asm/processor.hshall not be included inmmu-hash.h
Quoted 6 lines
Quoted 3 lines
In order to do that, this patch moves into a new header called
asm/task_size.hthe information fromasm/processor.hrequires bymmu-hash.hDoesn't look like you use this header in 32-bit code. Put
task_size.hin asm/64/ maybe?
There is no asm/64/ dir at the time being, only book3s/64/ and nohash/64/
I'm thinking about leaving it in asm/ but renaming it task_size_user64.h
Christophe
Quoted 135 lines
Reviewed-by Nicholas Piggin <[email protected]>Quoted 132 lines
Signed-off-by Christophe Leroy <[email protected]>--- arch/powerpc/include/asm/book3s/64/mmu-hash.h | 2 +- arch/powerpc/include/asm/processor.h | 34 +--------------------- arch/powerpc/include/asm/task_size.h | 42 +++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_hmi.c | 1 + 4 files changed, 45 insertions(+), 34 deletions(-)create mode 100644
arch/powerpc/include/asm/task_size.harch/powerpc/include/asm/book3s/64/mmu-hash.h +1
-1@@ -23,7 +23,7 @@*/ #include <asm/book3s/64/pgtable.h> #include <asm/bug.h> -#include <asm/processor.h> +#include <asm/task_size.h> #include <asm/cpu_has_feature.h> /* arch/powerpc/include/asm/processor.h +1
-33@@ -101,40 +101,8 @@ void release_thread(struct task_struct *);#endif #ifdef CONFIG_PPC64 -/* -* 64-bit user address space can have multiple limits -* For now supported values are: -*/ -#define TASK_SIZE_64TB (0x0000400000000000UL) -#define TASK_SIZE_128TB (0x0000800000000000UL) -#define TASK_SIZE_512TB (0x0002000000000000UL) -#define TASK_SIZE_1PB (0x0004000000000000UL) -#define TASK_SIZE_2PB (0x0008000000000000UL) -/* -* With 52 bits in the address we can support -* upto 4PB of range. -*/ -#define TASK_SIZE_4PB (0x0010000000000000UL) -/* -* For now 512TB is only supported with book3s and 64K linux page size. -*/ -#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_PPC_64K_PAGES ) -/* -* Max value currently used: -*/ -#define TASK_SIZE_USER64 TASK_SIZE_4PB -#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB -#define TASK_CONTEXT_SIZE TASK_SIZE_512TB -#else -#define TASK_SIZE_USER64 TASK_SIZE_64TB -#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB -/* -* We don't need to allocate extended context ids for 4K page size, because -* we limit the max effective address on this config to 64TB. -*/ -#define TASK_CONTEXT_SIZE TASK_SIZE_64TB -#endif +#include <asm/task_size.h> /* * 32-bit user address space is 4GB - 1 page arch/powerpc/include/asm/task_size.h new file +42
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_TASK_SIZE_H +#define _ASM_POWERPC_TASK_SIZE_H + +#ifdef CONFIG_PPC64 +/* +* 64-bit user address space can have multiple limits +* For now supported values are: +*/ +#define TASK_SIZE_64TB (0x0000400000000000UL) +#define TASK_SIZE_128TB (0x0000800000000000UL) +#define TASK_SIZE_512TB (0x0002000000000000UL) +#define TASK_SIZE_1PB (0x0004000000000000UL) +#define TASK_SIZE_2PB (0x0008000000000000UL) +/* +* With 52 bits in the address we can support +* upto 4PB of range. +*/ +#define TASK_SIZE_4PB (0x0010000000000000UL) + +/* +* For now 512TB is only supported with book3s and 64K linux page size. +*/ +#if defined(CONFIG_PPC_BOOK3S_64 ) && defined(CONFIG_PPC_64K_PAGES ) +/* +* Max value currently used: +*/ +#define TASK_SIZE_USER64 TASK_SIZE_4PB +#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB +#define TASK_CONTEXT_SIZE TASK_SIZE_512TB +#else +#define TASK_SIZE_USER64 TASK_SIZE_64TB +#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB +/* +* We don't need to allocate extended context ids for 4K page size, because +* we limit the max effective address on this config to 64TB. +*/ +#define TASK_CONTEXT_SIZE TASK_SIZE_64TB +#endif + +#endif /* CONFIG_PPC64 */ +#endif /* _ASM_POWERPC_TASK_SIZE_H */ arch/powerpc/kvm/book3s_hv_hmi.c +1
-0@@ -24,6 +24,7 @@#include <linux/compiler.h> #include <asm/paca.h> #include <asm/hmi.h> +#include <asm/processor.h> void wait_for_subcore_guest_exit (void ) {Signature · 1 line
2.13.3
Re: [RFC PATCH v3 1/7] book3s/64: avoid circular header inclusion in mmu-hash.h
Quoted 14 lines · Christophe LEROY
Le 03/10/2018 à 06:24, Nicholas Piggin a écrit :
Quoted 11 lines
Quoted 7 lines · On Mon, 1 Oct 2018 12:30:19 +0000 (UTC) Christophe Leroy…
When activating
CONFIG_THREAD_INFO_IN_TASK,linux/sched.hincludesasm/current.h. This generates a circular dependency. To avoid that,asm/processor.hshall not be included inmmu-hash.hIn order to do that, this patch moves into a new header called
asm/task_size.hthe information fromasm/processor.hrequires bymmu-hash.h
Quoted 7 lines
Quoted 2 lines
Doesn't look like you use this header in 32-bit code. Put
task_size.hin asm/64/ maybe?There is no asm/64/ dir at the time being, only book3s/64/ and nohash/64/
I'm thinking about leaving it in asm/ but renaming it
task_size_user64.h
Quiet a lot of that is book3s 64 specifi because we have there.
#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_64K_PAGES) /*
* Max value currently used:
*/
-aneesh
Re: [RFC PATCH v3 1/7] book3s/64: avoid circular header inclusion in mmu-hash.h
Le 04/10/2018 à 10:23, Aneesh Kumar K.V a écrit :
Quoted 23 lines · Christophe LEROY
Quoted 14 lines
Le 03/10/2018 à 06:24, Nicholas Piggin a écrit :
Quoted 11 lines
Quoted 7 lines · On Mon, 1 Oct 2018 12:30:19 +0000 (UTC) Christophe Leroy…
When activating
CONFIG_THREAD_INFO_IN_TASK,linux/sched.hincludesasm/current.h. This generates a circular dependency. To avoid that,asm/processor.hshall not be included inmmu-hash.hIn order to do that, this patch moves into a new header called
asm/task_size.hthe information fromasm/processor.hrequires bymmu-hash.hQuoted 7 lines
Quoted 2 lines
Doesn't look like you use this header in 32-bit code. Put
task_size.hin asm/64/ maybe?There is no asm/64/ dir at the time being, only book3s/64/ and nohash/64/
I'm thinking about leaving it in asm/ but renaming it
task_size_user64.h
Quoted 6 lines
Quiet a lot of that is book3s 64 specifi because we have there.
#if
defined(CONFIG_PPC_BOOK3S_64)&&defined(CONFIG_PPC_64K_PAGES)/*
* Max value currently used:
*/
We have an #if / #else
#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_64K_PAGES) /*
* Max value currently used:
*/
#define TASK_SIZE_USER64 TASK_SIZE_4PB
#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_128TB
#define TASK_CONTEXT_SIZE TASK_SIZE_512TB
#else
#define TASK_SIZE_USER64 TASK_SIZE_64TB
#define DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB
/*
* We don't need to allocate extended context ids for 4K page size, because
* we limit the max effective address on this config to 64TB. */
#define TASK_CONTEXT_SIZE TASK_SIZE_64TB
#endif
And processor .h derives several other consts applying to both BOOK3S64 et BOOK3E64 from that.
And arch/powerpc/mm/pgtable-book3e.c has:
BUILD_BUG_ON(TASK_SIZE_USER64 > PGTABLE_RANGE);
Christophe
RFC PATCH v3 2/7 powerpc: Prepare for moving thread_info into task_struct
In reply to Christophe LeroyThis patch cleans the powerpc kernel before activating CONFIG_THREAD_INFO_IN_TASK:
- The purpose of the pointer given to call_do_softirq() and call_do_irq() is to point the new stack ==> change it to void*
- Don't use CURRENT_THREAD_INFO() to locate the stack.
- Fixed a few comments.
- TI_CPU is only used when CONFIG_SMP is set.
- Replace current_thread_info()->task by current
- Remove unnecessary casts to thread_info, as they'll become invalid once thread_info is not in stack anymore.
- Ensure task_struct 'cpu' fields is not used directly out of SMP code
- Rename THREAD_INFO to TASK_STASK: As it is in fact the offset of the pointer to the stack in task_struct, this pointer will not be impacted by the move of THREAD_INFO.
- Makes TASK_STACK available to PPC64 which will need it to the get stack pointer from current once the thread_info have been moved.
--- arch/powerpc/include/asm/irq.h | 4 ++-- arch/powerpc/include/asm/livepatch.h | 2 +- arch/powerpc/include/asm/processor.h | 4 ++-- arch/powerpc/include/asm/reg.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S | 2 +- arch/powerpc/kernel/entry_64.S | 2 +- arch/powerpc/kernel/head_32.S | 4 ++-- arch/powerpc/kernel/head_40x.S | 4 ++-- arch/powerpc/kernel/head_44x.S | 2 +- arch/powerpc/kernel/head_8xx.S | 2 +- arch/powerpc/kernel/head_booke.h | 4 ++-- arch/powerpc/kernel/head_fsl_booke.S | 6 ++++-- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/misc_32.S | 8 ++++++-- arch/powerpc/kernel/process.c | 6 +++--- arch/powerpc/kernel/setup_32.c | 15 +++++---------- arch/powerpc/kernel/smp.c | 4 +++- arch/powerpc/xmon/xmon.c | 2 +- 19 files changed, 40 insertions(+), 37 deletions(-)
arch/powerpc/include/asm/irq.h +2 -2
@@ -63,8 +63,8 @@ extern struct thread_info *hardirq_ctx[NR_CPUS];extern struct thread_info *softirq_ctx[NR_CPUS ];extern void irq_ctx_init (void ); -extern void call_do_softirq (struct thread_info *tp); -extern void call_do_irq (struct pt_regs *regs,struct thread_info *tp); +extern void call_do_softirq (void *tp); +extern void call_do_irq (struct pt_regs *regs,void *tp);extern void do_IRQ (struct pt_regs *regs);extern void __init init_IRQ (void );extern void __do_irq (struct pt_regs *regs);
arch/powerpc/include/asm/livepatch.h +1 -1
@@ -49,7 +49,7 @@ static inline void klp_init_thread_info(struct thread_info *ti) ti->livepatch_sp = (unsigned long *)(ti +1 ) +1 ; }#else -static void klp_init_thread_info (struct thread_info *ti) { } +static inline void klp_init_thread_info (struct thread_info *ti) { }#endif /* CONFIG_LIVEPATCH */ #endif /* _ASM_POWERPC_LIVEPATCH_H */
arch/powerpc/include/asm/processor.h +2 -2
@@ -40,7 +40,7 @@#ifndef __ASSEMBLY__#include <linux/types.h> -#include <asm/thread_info.h> +#include <linux/thread_info.h> #include <asm/ptrace.h> #include <asm/hw_breakpoint.h>
@@ -333,7 +333,7 @@ struct thread_struct {#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)#define INIT_SP_LIMIT \ - (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack) + (_ALIGN_UP(sizeof(struct thread_info), 16) + (unsigned long) &init_stack)#ifdef CONFIG_SPE #define SPEFSCR_INIT \
arch/powerpc/include/asm/reg.h +1 -1
@@ -1053,7 +1053,7 @@* - SPRG9 debug exception scratch * * All 32-bit: -* - SPRG3 current thread_info pointer +* - SPRG3 current thread_struct physical addr pointer * (virtual on BookE, physical on others) * * 32-bit classic:
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -85,10 +85,10 @@ int main(void)DEFINE (NMI_MASK ,NMI_MASK );OFFSET (TASKTHREADPPR , task_struct, thread.ppr);#else -OFFSET (THREAD_INFO , task_struct, stack);DEFINE (THREAD_INFO_GAP ,_ALIGN_UP (sizeof (struct thread_info ),16 ));OFFSET (KSP_LIMIT , thread_struct, ksp_limit);#endif /* CONFIG_PPC64 */ +OFFSET (TASK_STACK , task_struct, stack);#ifdef CONFIG_LIVEPATCH OFFSET (TI_livepatch_sp, thread_info, livepatch_sp);
arch/powerpc/kernel/entry_32.S +1 -1
@@ -1166,7 +1166,7 @@ ret_from_debug_exc: mfspr r9,SPRN_SPRG_THREAD lwz r10,SAVED_KSP_LIMIT(r1) stw r10,KSP_LIMIT(r9) - lwz r9,THREAD_INFO-THREAD(r9) + lwz r9,TASK_STACK-THREAD(r9) CURRENT_THREAD_INFO(r10, r1) lwz r10,TI_PREEMPT(r10) stw r10,TI_PREEMPT(r9)
arch/powerpc/kernel/entry_64.S +1 -1
@@ -680,7 +680,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) 2: #endif /* CONFIG_PPC_BOOK3S_64 */ - CURRENT_THREAD_INFO(r7, r8) /* base of new stack */ + clrrdi r7, r8, THREAD_SHIFT /* base of new stack */ /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE because we don't need to leave the 288-byte ABI gap at the top of the kernel stack. */
arch/powerpc/kernel/head_32.S +2 -2
@@ -261,7 +261,7 @@ __secondary_hold_acknowledge: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
@@ -841,7 +841,7 @@ __secondary_start: bl init_idle_6xx #endif /* CONFIG_6xx */ - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha tophys(r1,r1) lwz r1,secondary_ti@l(r1)
arch/powerpc/kernel/head_40x.S +2 -2
@@ -115,7 +115,7 @@ _ENTRY(saved_ksp_limit) andi. r11,r11,MSR_PR; \ beq 1f; \ mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\ + lwz r1,TASK_STACK-THREAD(r1); /* this thread's kernel stack */\ addi r1,r1,THREAD_SIZE; \ 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\ tophys(r11,r1); \
@@ -158,7 +158,7 @@ _ENTRY(saved_ksp_limit) beq 1f; \ /* COMING FROM USER MODE */ \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\ 1: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\ tophys(r11,r11); \ stw r10,_CCR(r11); /* save various registers */\
arch/powerpc/kernel/head_44x.S +1 -1
@@ -1020,7 +1020,7 @@ _GLOBAL(start_secondary_47x) /* Now we can get our task struct and real stack pointer */ - /* Get current_thread_info and current */ + /* Get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)
arch/powerpc/kernel/head_8xx.S +1 -1
@@ -124,7 +124,7 @@ turn_on_mmu: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
arch/powerpc/kernel/head_booke.h +2 -2
@@ -44,7 +44,7 @@mr r11, r1; \ beq 1f; \/* if from user, start at top of this thread's kernel stack */ \ - lwz r11, THREAD_INFO-THREAD(r10); \ + lwz r11, TASK_STACK-THREAD(r10); \ALLOC_STACK_FRAME (r11,THREAD_SIZE ); \ 1 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \stw r13,_CCR (r11 );/* save various registers */ \
@@ -130,7 +130,7 @@ DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ andi. r11,r11,MSR_PR ; \mfspr r11,SPRN_SPRG_THREAD ;/* if from user, start at top of */ \ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\addi r11,r11,EXC_LVL_FRAME_OVERHEAD ;/* allocate stack frame */ \ beq 1f; \/* COMING FROM USER MODE */ \
arch/powerpc/kernel/head_fsl_booke.S +4 -2
@@ -243,8 +243,10 @@ set_ivor: li r0,0 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) +#ifdef CONFIG_SMP CURRENT_THREAD_INFO(r22, r1) stw r24, TI_CPU(r22) +#endif bl early_init
@@ -702,7 +704,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r12, THREAD_INFO-THREAD(r12) + lwz r12, TASK_STACK-THREAD(r12) lwz r15, TI_CPU(r12) lis r14, __per_cpu_offset@h ori r14, r14, __per_cpu_offset@l
@@ -1074,7 +1076,7 @@ __secondary_start: mr r4,r24 /* Why? */ bl call_setup_cpu - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)
arch/powerpc/kernel/irq.c +1 -1
@@ -663,7 +663,7 @@ void do_IRQ(struct pt_regs *regs)struct thread_info *curtp, *irqtp, *sirqtp;/* Switch to the irq stack to handle this */ - curtp =current_thread_info (); + curtp = (void *)(current_stack_pointer () & ~(THREAD_SIZE -1 )); irqtp = hardirq_ctx[raw_smp_processor_id ()]; sirqtp = softirq_ctx[raw_smp_processor_id ()];
arch/powerpc/kernel/misc_32.S +6 -2
@@ -60,7 +60,7 @@ _GLOBAL(call_do_softirq) blr /* - * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp); + * void call_do_irq(struct pt_regs *regs, void *irqtp); */ _GLOBAL(call_do_irq) mflr r0
@@ -183,10 +183,14 @@ _GLOBAL(low_choose_750fx_pll) or r4,r4,r5 mtspr SPRN_HID1,r4 +#ifdef CONFIG_SMP /* Store new HID1 image */ CURRENT_THREAD_INFO(r6, r1) lwz r6,TI_CPU(r6) slwi r6,r6,2 +#else + li r6, 0 +#endif addis r6,r6,nap_save_hid1@ha stw r4,nap_save_hid1@l(r6)
@@ -599,7 +603,7 @@ EXPORT_SYMBOL(__bswapdi2) #ifdef CONFIG_SMP _GLOBAL(start_secondary_resume) /* Reset stack */ - CURRENT_THREAD_INFO(r1, r1) + rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD li r3,0 stw r3,0(r1) /* Zero the stack frame pointer */
arch/powerpc/kernel/process.c +3 -3
@@ -1240,8 +1240,8 @@ struct task_struct *__switch_to(struct task_struct *prev, batch->active =1 ; } -if (current_thread_info ()->task->thread.regs) { -restore_math (current_thread_info ()->task->thread.regs); +if (current->thread.regs) { +restore_math (current->thread.regs);/* * The copy-paste buffer can only store into foreign real
@@ -1251,7 +1251,7 @@ struct task_struct *__switch_to(struct task_struct *prev,* mappings, we must issue a cp_abort to clear any state and * prevent snooping, corruption or a covert channel. */ - if (current_thread_info()->task->thread.used_vas) + if (current->thread.used_vas) asm volatile(PPC_CP_ABORT); }#endif /* CONFIG_PPC_BOOK3S_64 */
arch/powerpc/kernel/setup_32.c +5 -10
@@ -205,10 +205,8 @@ void __init irqstack_early_init(void)/* interrupt stacks must be in lowmem, we get that for free on ppc32 * as the memblock is limited to lowmem by default */ for_each_possible_cpu (i) { - softirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - hardirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + softirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + hardirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); } }
@@ -226,13 +224,10 @@ void __init exc_lvl_early_init(void) hw_cpu =0 ;#endif - critirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + critirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#ifdef CONFIG_BOOKE - dbgirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - mcheckirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + dbgirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + mcheckirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#endif } }
arch/powerpc/kernel/smp.c +3 -1
@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/export.h> #include <linux/sched/mm.h> +#include <linux/sched/task_stack.h> #include <linux/sched/topology.h> #include <linux/smp.h> #include <linux/interrupt.h>
@@ -812,7 +813,8 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)#ifdef CONFIG_PPC64 paca_ptrs[cpu]->__current = idle; - paca_ptrs[cpu]->kstack = (unsigned long )ti +THREAD_SIZE -STACK_FRAME_OVERHEAD ; + paca_ptrs[cpu]->kstack = (unsigned long )task_stack_page (idle) + +THREAD_SIZE -STACK_FRAME_OVERHEAD ;#endif ti->cpu = cpu; secondary_ti = current_set[cpu] = ti;
arch/powerpc/xmon/xmon.c +1 -1
@@ -2988,7 +2988,7 @@ static void show_task(struct task_struct *tsk)printf ("%px %016lx %6d %6d %c %2d %s\n" , tsk, tsk->thread.ksp, tsk->pid, tsk->parent->pid, - state,task_thread_info (tsk)->cpu, + state,task_cpu (tsk), tsk->comm); }
Signature · 1 line
2.13.3
Re: [RFC PATCH v3 2/7] powerpc: Prepare for moving thread_info into task_struct
Quoted 45 lines · On Mon, 1 Oct 2018 12:30:21 +0000 (UTC) Christophe Leroy…
This patch cleans the powerpc kernel before activating
CONFIG_THREAD_INFO_IN_TASK:
- The purpose of the pointer given tocall_do_softirq()andcall_do_irq()is to point the new stack ==> change it to void*
- Don't useCURRENT_THREAD_INFO()to locate the stack.
- Fixed a few comments.
-TI_CPUis only used whenCONFIG_SMPis set.
- Replace current_thread_info()->task by current
- Remove unnecessary casts tothread_info, as they'll become invalid oncethread_infois not in stack anymore.
- Ensuretask_struct'cpu' fields is not used directly out of SMP code
- RenameTHREAD_INFOtoTASK_STASK: As it is in fact the offset of the pointer to the stack intask_struct, this pointer will not be impacted by the move ofTHREAD_INFO.
- MakesTASK_STACKavailable to PPC64 which will need it to the get stack pointer from current once thethread_infohave been moved.Signed-off-by Christophe Leroy <[email protected]>--- arch/powerpc/include/asm/irq.h | 4 ++-- arch/powerpc/include/asm/livepatch.h | 2 +- arch/powerpc/include/asm/processor.h | 4 ++-- arch/powerpc/include/asm/reg.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S | 2 +- arch/powerpc/kernel/entry_64.S | 2 +- arch/powerpc/kernel/head_32.S | 4 ++-- arch/powerpc/kernel/head_40x.S | 4 ++-- arch/powerpc/kernel/head_44x.S | 2 +- arch/powerpc/kernel/head_8xx.S | 2 +- arch/powerpc/kernel/head_booke.h | 4 ++-- arch/powerpc/kernel/head_fsl_booke.S | 6 ++++-- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/misc_32.S | 8 ++++++-- arch/powerpc/kernel/process.c | 6 +++--- arch/powerpc/kernel/setup_32.c | 15 +++++---------- arch/powerpc/kernel/smp.c | 4 +++- arch/powerpc/xmon/xmon.c | 2 +- 19 files changed, 40 insertions(+), 37 deletions(-)arch/powerpc/include/asm/irq.h +0
-0
arch/powerpc/include/asm/irq.h extern struct thread_info *hardirq_ctx[NR_CPUS]; · line 67
Quoted 7 lines
arch/powerpc/include/asm/irq.h +2
-2@@ -63,8 +63,8 @@ extern struct thread_info *hardirq_ctx[NR_CPUS];extern struct thread_info *softirq_ctx[NR_CPUS ];extern void irq_ctx_init (void ); -extern void call_do_softirq (struct thread_info *tp); -extern void call_do_irq (struct pt_regs *regs,struct thread_info *tp); +extern void call_do_softirq (void *tp); +extern void call_do_irq (struct pt_regs *regs,void *tp);
void *sp for these ?
This all seems okay to me except the 32-bit code which I don't know. Would it be any trouble for you to put the TI_CPU bits into their own patch?
Quoted 364 lines
arch/powerpc/include/asm/irq.h +0
-0extern void do_IRQ (struct pt_regs *regs);extern void __init init_IRQ (void );extern void __do_irq (struct pt_regs *regs);arch/powerpc/include/asm/livepatch.h +1
-1@@ -49,7 +49,7 @@ static inline void klp_init_thread_info(struct thread_info *ti) ti->livepatch_sp = (unsigned long *)(ti +1 ) +1 ; }#else -static void klp_init_thread_info (struct thread_info *ti) { } +static inline void klp_init_thread_info (struct thread_info *ti) { }#endif /* CONFIG_LIVEPATCH */ #endif /* _ASM_POWERPC_LIVEPATCH_H */ arch/powerpc/include/asm/processor.h +2
-2@@ -40,7 +40,7 @@#ifndef __ASSEMBLY__#include <linux/types.h> -#include <asm/thread_info.h> +#include <linux/thread_info.h> #include <asm/ptrace.h> #include <asm/hw_breakpoint.h> @@ -333,7 +333,7 @@ struct thread_struct {#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)#define INIT_SP_LIMIT \ - (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack) + (_ALIGN_UP(sizeof(struct thread_info), 16) + (unsigned long) &init_stack)#ifdef CONFIG_SPE #define SPEFSCR_INIT \arch/powerpc/include/asm/reg.h +1
-1@@ -1053,7 +1053,7 @@* - SPRG9 debug exception scratch * * All 32-bit: -* - SPRG3 current thread_info pointer +* - SPRG3 current thread_struct physical addr pointer * (virtual on BookE, physical on others) * * 32-bit classic: arch/powerpc/kernel/asm-offsets.c +1
-1@@ -85,10 +85,10 @@ int main(void)DEFINE (NMI_MASK ,NMI_MASK );OFFSET (TASKTHREADPPR , task_struct, thread.ppr);#else -OFFSET (THREAD_INFO , task_struct, stack);DEFINE (THREAD_INFO_GAP ,_ALIGN_UP (sizeof (struct thread_info ),16 ));OFFSET (KSP_LIMIT , thread_struct, ksp_limit);#endif /* CONFIG_PPC64 */ +OFFSET (TASK_STACK , task_struct, stack);#ifdef CONFIG_LIVEPATCH OFFSET (TI_livepatch_sp, thread_info, livepatch_sp);arch/powerpc/kernel/entry_32.S +1
-1@@ -1166,7 +1166,7 @@ ret_from_debug_exc: mfspr r9,SPRN_SPRG_THREAD lwz r10,SAVED_KSP_LIMIT(r1) stw r10,KSP_LIMIT(r9) - lwz r9,THREAD_INFO-THREAD(r9) + lwz r9,TASK_STACK-THREAD(r9) CURRENT_THREAD_INFO(r10, r1) lwz r10,TI_PREEMPT(r10) stw r10,TI_PREEMPT(r9)arch/powerpc/kernel/entry_64.S +1
-1@@ -680,7 +680,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) 2: #endif /* CONFIG_PPC_BOOK3S_64 */ - CURRENT_THREAD_INFO(r7, r8) /* base of new stack */ + clrrdi r7, r8, THREAD_SHIFT /* base of new stack */ /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE because we don't need to leave the 288-byte ABI gap at the top of the kernel stack. */arch/powerpc/kernel/head_32.S +2
-2@@ -261,7 +261,7 @@ __secondary_hold_acknowledge: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */@@ -841,7 +841,7 @@ __secondary_start: bl init_idle_6xx #endif /* CONFIG_6xx */ - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha tophys(r1,r1) lwz r1,secondary_ti@l(r1)arch/powerpc/kernel/head_40x.S +2
-2@@ -115,7 +115,7 @@ _ENTRY(saved_ksp_limit) andi. r11,r11,MSR_PR; \ beq 1f; \ mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\ + lwz r1,TASK_STACK-THREAD(r1); /* this thread's kernel stack */\ addi r1,r1,THREAD_SIZE; \ 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\ tophys(r11,r1); \@@ -158,7 +158,7 @@ _ENTRY(saved_ksp_limit) beq 1f; \ /* COMING FROM USER MODE */ \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\ 1: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\ tophys(r11,r11); \ stw r10,_CCR(r11); /* save various registers */\arch/powerpc/kernel/head_44x.S +1
-1@@ -1020,7 +1020,7 @@ _GLOBAL(start_secondary_47x) /* Now we can get our task struct and real stack pointer */ - /* Get current_thread_info and current */ + /* Get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)arch/powerpc/kernel/head_8xx.S +1
-1@@ -124,7 +124,7 @@ turn_on_mmu: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */arch/powerpc/kernel/head_booke.h +2
-2@@ -44,7 +44,7 @@mr r11, r1; \ beq 1f; \/* if from user, start at top of this thread's kernel stack */ \ - lwz r11, THREAD_INFO-THREAD(r10); \ + lwz r11, TASK_STACK-THREAD(r10); \ALLOC_STACK_FRAME (r11,THREAD_SIZE ); \ 1 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \stw r13,_CCR (r11 );/* save various registers */ \@@ -130,7 +130,7 @@ DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ andi. r11,r11,MSR_PR ; \mfspr r11,SPRN_SPRG_THREAD ;/* if from user, start at top of */ \ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\addi r11,r11,EXC_LVL_FRAME_OVERHEAD ;/* allocate stack frame */ \ beq 1f; \/* COMING FROM USER MODE */ \arch/powerpc/kernel/head_fsl_booke.S +4
-2@@ -243,8 +243,10 @@ set_ivor: li r0,0 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) +#ifdef CONFIG_SMP CURRENT_THREAD_INFO(r22, r1) stw r24, TI_CPU(r22) +#endif bl early_init@@ -702,7 +704,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r12, THREAD_INFO-THREAD(r12) + lwz r12, TASK_STACK-THREAD(r12) lwz r15, TI_CPU(r12) lis r14, __per_cpu_offset@h ori r14, r14, __per_cpu_offset@l@@ -1074,7 +1076,7 @@ __secondary_start: mr r4,r24 /* Why? */ bl call_setup_cpu - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)arch/powerpc/kernel/irq.c +1
-1@@ -663,7 +663,7 @@ void do_IRQ(struct pt_regs *regs)struct thread_info *curtp, *irqtp, *sirqtp;/* Switch to the irq stack to handle this */ - curtp =current_thread_info (); + curtp = (void *)(current_stack_pointer () & ~(THREAD_SIZE -1 )); irqtp = hardirq_ctx[raw_smp_processor_id ()]; sirqtp = softirq_ctx[raw_smp_processor_id ()];arch/powerpc/kernel/misc_32.S +6
-2@@ -60,7 +60,7 @@ _GLOBAL(call_do_softirq) blr /* - * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp); + * void call_do_irq(struct pt_regs *regs, void *irqtp); */ _GLOBAL(call_do_irq) mflr r0@@ -183,10 +183,14 @@ _GLOBAL(low_choose_750fx_pll) or r4,r4,r5 mtspr SPRN_HID1,r4 +#ifdef CONFIG_SMP /* Store new HID1 image */ CURRENT_THREAD_INFO(r6, r1) lwz r6,TI_CPU(r6) slwi r6,r6,2 +#else + li r6, 0 +#endif addis r6,r6,nap_save_hid1@ha stw r4,nap_save_hid1@l(r6)@@ -599,7 +603,7 @@ EXPORT_SYMBOL(__bswapdi2) #ifdef CONFIG_SMP _GLOBAL(start_secondary_resume) /* Reset stack */ - CURRENT_THREAD_INFO(r1, r1) + rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD li r3,0 stw r3,0(r1) /* Zero the stack frame pointer */arch/powerpc/kernel/process.c +3
-3@@ -1240,8 +1240,8 @@ struct task_struct *__switch_to(struct task_struct *prev, batch->active =1 ; } -if (current_thread_info ()->task->thread.regs) { -restore_math (current_thread_info ()->task->thread.regs); +if (current->thread.regs) { +restore_math (current->thread.regs);/* * The copy-paste buffer can only store into foreign real @@ -1251,7 +1251,7 @@ struct task_struct *__switch_to(struct task_struct *prev,* mappings, we must issue a cp_abort to clear any state and * prevent snooping, corruption or a covert channel. */ - if (current_thread_info()->task->thread.used_vas) + if (current->thread.used_vas) asm volatile(PPC_CP_ABORT); }#endif /* CONFIG_PPC_BOOK3S_64 */ arch/powerpc/kernel/setup_32.c +5
-10@@ -205,10 +205,8 @@ void __init irqstack_early_init(void)/* interrupt stacks must be in lowmem, we get that for free on ppc32 * as the memblock is limited to lowmem by default */ for_each_possible_cpu (i) { - softirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - hardirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + softirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + hardirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); } }@@ -226,13 +224,10 @@ void __init exc_lvl_early_init(void) hw_cpu =0 ;#endif - critirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + critirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#ifdef CONFIG_BOOKE - dbgirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - mcheckirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + dbgirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + mcheckirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#endif } }arch/powerpc/kernel/smp.c +3
-1@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/export.h> #include <linux/sched/mm.h> +#include <linux/sched/task_stack.h> #include <linux/sched/topology.h> #include <linux/smp.h> #include <linux/interrupt.h> @@ -812,7 +813,8 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)#ifdef CONFIG_PPC64 paca_ptrs[cpu]->__current = idle; - paca_ptrs[cpu]->kstack = (unsigned long )ti +THREAD_SIZE -STACK_FRAME_OVERHEAD ; + paca_ptrs[cpu]->kstack = (unsigned long )task_stack_page (idle) + +THREAD_SIZE -STACK_FRAME_OVERHEAD ;#endif ti->cpu = cpu; secondary_ti = current_set[cpu] = ti;arch/powerpc/xmon/xmon.c +1
-1@@ -2988,7 +2988,7 @@ static void show_task(struct task_struct *tsk)printf ("%px %016lx %6d %6d %c %2d %s\n" , tsk, tsk->thread.ksp, tsk->pid, tsk->parent->pid, - state,task_thread_info (tsk)->cpu, + state,task_cpu (tsk), tsk->comm); }Signature · 1 line
2.13.3
Re: [RFC PATCH v3 2/7] powerpc: Prepare for moving thread_info into task_struct
Le 03/10/2018 à 07:02, Nicholas Piggin a écrit :
Quoted 50 lines
Quoted 47 lines · On Mon, 1 Oct 2018 12:30:21 +0000 (UTC) Christophe Leroy…
This patch cleans the powerpc kernel before activating
CONFIG_THREAD_INFO_IN_TASK:
- The purpose of the pointer given tocall_do_softirq()andcall_do_irq()is to point the new stack ==> change it to void*
- Don't useCURRENT_THREAD_INFO()to locate the stack.
- Fixed a few comments.
-TI_CPUis only used whenCONFIG_SMPis set.
- Replace current_thread_info()->task by current
- Remove unnecessary casts tothread_info, as they'll become invalid oncethread_infois not in stack anymore.
- Ensuretask_struct'cpu' fields is not used directly out of SMP code
- RenameTHREAD_INFOtoTASK_STASK: As it is in fact the offset of the pointer to the stack intask_struct, this pointer will not be impacted by the move ofTHREAD_INFO.
- MakesTASK_STACKavailable to PPC64 which will need it to the get stack pointer from current once thethread_infohave been moved.Signed-off-by Christophe Leroy <[email protected]>--- arch/powerpc/include/asm/irq.h | 4 ++-- arch/powerpc/include/asm/livepatch.h | 2 +- arch/powerpc/include/asm/processor.h | 4 ++-- arch/powerpc/include/asm/reg.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S | 2 +- arch/powerpc/kernel/entry_64.S | 2 +- arch/powerpc/kernel/head_32.S | 4 ++-- arch/powerpc/kernel/head_40x.S | 4 ++-- arch/powerpc/kernel/head_44x.S | 2 +- arch/powerpc/kernel/head_8xx.S | 2 +- arch/powerpc/kernel/head_booke.h | 4 ++-- arch/powerpc/kernel/head_fsl_booke.S | 6 ++++-- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/misc_32.S | 8 ++++++-- arch/powerpc/kernel/process.c | 6 +++--- arch/powerpc/kernel/setup_32.c | 15 +++++---------- arch/powerpc/kernel/smp.c | 4 +++- arch/powerpc/xmon/xmon.c | 2 +- 19 files changed, 40 insertions(+), 37 deletions(-)arch/powerpc/include/asm/irq.h +0
-0@@ -63,8 +63,8 @@ extern struct thread_info *hardirq_ctx[NR_CPUS];extern struct thread_info *softirq_ctx[NR_CPUS ];
Quoted 7 lines
arch/powerpc/include/asm/irq.h extern struct thread_info *hardirq_ctx[NR_CPUS]; · line 67
Quoted 5 lines
arch/powerpc/include/asm/irq.h +2
-2extern void irq_ctx_init (void ); -extern void call_do_softirq (struct thread_info *tp); -extern void call_do_irq (struct pt_regs *regs,struct thread_info *tp); +extern void call_do_softirq (void *tp); +extern void call_do_irq (struct pt_regs *regs,void *tp);void *sp for these ?
Yes, why not but it means changing the code. I wanted to minimise the changes and avoid cosmetic. Or maybe should add a cosmetic patch at the end ?
Quoted 4 lines
This all seems okay to me except the 32-bit code which I don't know. Would it be any trouble for you to put the
TI_CPUbits into their own patch?
No problem, I can put the TI_CPU bits in a separate patch.
Quoted 3 lines
Reviewed-by Nicholas Piggin <[email protected]>
Thanks
Christophe
Quoted 365 lines
Quoted 365 lines
arch/powerpc/include/asm/irq.h +0
-0extern void do_IRQ (struct pt_regs *regs);extern void __init init_IRQ (void );extern void __do_irq (struct pt_regs *regs);arch/powerpc/include/asm/livepatch.h +1
-1@@ -49,7 +49,7 @@ static inline void klp_init_thread_info(struct thread_info *ti) ti->livepatch_sp = (unsigned long *)(ti +1 ) +1 ; }#else -static void klp_init_thread_info (struct thread_info *ti) { } +static inline void klp_init_thread_info (struct thread_info *ti) { }#endif /* CONFIG_LIVEPATCH */ #endif /* _ASM_POWERPC_LIVEPATCH_H */ arch/powerpc/include/asm/processor.h +2
-2@@ -40,7 +40,7 @@#ifndef __ASSEMBLY__#include <linux/types.h> -#include <asm/thread_info.h> +#include <linux/thread_info.h> #include <asm/ptrace.h> #include <asm/hw_breakpoint.h> @@ -333,7 +333,7 @@ struct thread_struct {#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)#define INIT_SP_LIMIT \ - (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack) + (_ALIGN_UP(sizeof(struct thread_info), 16) + (unsigned long) &init_stack)#ifdef CONFIG_SPE #define SPEFSCR_INIT \arch/powerpc/include/asm/reg.h +1
-1@@ -1053,7 +1053,7 @@* - SPRG9 debug exception scratch * * All 32-bit: -* - SPRG3 current thread_info pointer +* - SPRG3 current thread_struct physical addr pointer * (virtual on BookE, physical on others) * * 32-bit classic: arch/powerpc/kernel/asm-offsets.c +1
-1@@ -85,10 +85,10 @@ int main(void)DEFINE (NMI_MASK ,NMI_MASK );OFFSET (TASKTHREADPPR , task_struct, thread.ppr);#else -OFFSET (THREAD_INFO , task_struct, stack);DEFINE (THREAD_INFO_GAP ,_ALIGN_UP (sizeof (struct thread_info ),16 ));OFFSET (KSP_LIMIT , thread_struct, ksp_limit);#endif /* CONFIG_PPC64 */ +OFFSET (TASK_STACK , task_struct, stack);#ifdef CONFIG_LIVEPATCH OFFSET (TI_livepatch_sp, thread_info, livepatch_sp);arch/powerpc/kernel/entry_32.S +1
-1@@ -1166,7 +1166,7 @@ ret_from_debug_exc: mfspr r9,SPRN_SPRG_THREAD lwz r10,SAVED_KSP_LIMIT(r1) stw r10,KSP_LIMIT(r9) - lwz r9,THREAD_INFO-THREAD(r9) + lwz r9,TASK_STACK-THREAD(r9) CURRENT_THREAD_INFO(r10, r1) lwz r10,TI_PREEMPT(r10) stw r10,TI_PREEMPT(r9)arch/powerpc/kernel/entry_64.S +1
-1@@ -680,7 +680,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) 2: #endif /* CONFIG_PPC_BOOK3S_64 */ - CURRENT_THREAD_INFO(r7, r8) /* base of new stack */ + clrrdi r7, r8, THREAD_SHIFT /* base of new stack */ /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE because we don't need to leave the 288-byte ABI gap at the top of the kernel stack. */arch/powerpc/kernel/head_32.S +2
-2@@ -261,7 +261,7 @@ __secondary_hold_acknowledge: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */@@ -841,7 +841,7 @@ __secondary_start: bl init_idle_6xx #endif /* CONFIG_6xx */ - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha tophys(r1,r1) lwz r1,secondary_ti@l(r1)arch/powerpc/kernel/head_40x.S +2
-2@@ -115,7 +115,7 @@ _ENTRY(saved_ksp_limit) andi. r11,r11,MSR_PR; \ beq 1f; \ mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\ + lwz r1,TASK_STACK-THREAD(r1); /* this thread's kernel stack */\ addi r1,r1,THREAD_SIZE; \ 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\ tophys(r11,r1); \@@ -158,7 +158,7 @@ _ENTRY(saved_ksp_limit) beq 1f; \ /* COMING FROM USER MODE */ \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\ 1: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\ tophys(r11,r11); \ stw r10,_CCR(r11); /* save various registers */\arch/powerpc/kernel/head_44x.S +1
-1@@ -1020,7 +1020,7 @@ _GLOBAL(start_secondary_47x) /* Now we can get our task struct and real stack pointer */ - /* Get current_thread_info and current */ + /* Get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)arch/powerpc/kernel/head_8xx.S +1
-1@@ -124,7 +124,7 @@ turn_on_mmu: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */arch/powerpc/kernel/head_booke.h +2
-2@@ -44,7 +44,7 @@mr r11, r1; \ beq 1f; \/* if from user, start at top of this thread's kernel stack */ \ - lwz r11, THREAD_INFO-THREAD(r10); \ + lwz r11, TASK_STACK-THREAD(r10); \ALLOC_STACK_FRAME (r11,THREAD_SIZE ); \ 1 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \stw r13,_CCR (r11 );/* save various registers */ \@@ -130,7 +130,7 @@ DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ andi. r11,r11,MSR_PR ; \mfspr r11,SPRN_SPRG_THREAD ;/* if from user, start at top of */ \ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\addi r11,r11,EXC_LVL_FRAME_OVERHEAD ;/* allocate stack frame */ \ beq 1f; \/* COMING FROM USER MODE */ \arch/powerpc/kernel/head_fsl_booke.S +4
-2@@ -243,8 +243,10 @@ set_ivor: li r0,0 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) +#ifdef CONFIG_SMP CURRENT_THREAD_INFO(r22, r1) stw r24, TI_CPU(r22) +#endif bl early_init@@ -702,7 +704,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r12, THREAD_INFO-THREAD(r12) + lwz r12, TASK_STACK-THREAD(r12) lwz r15, TI_CPU(r12) lis r14, __per_cpu_offset@h ori r14, r14, __per_cpu_offset@l@@ -1074,7 +1076,7 @@ __secondary_start: mr r4,r24 /* Why? */ bl call_setup_cpu - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)arch/powerpc/kernel/irq.c +1
-1@@ -663,7 +663,7 @@ void do_IRQ(struct pt_regs *regs)struct thread_info *curtp, *irqtp, *sirqtp;/* Switch to the irq stack to handle this */ - curtp =current_thread_info (); + curtp = (void *)(current_stack_pointer () & ~(THREAD_SIZE -1 )); irqtp = hardirq_ctx[raw_smp_processor_id ()]; sirqtp = softirq_ctx[raw_smp_processor_id ()];arch/powerpc/kernel/misc_32.S +6
-2@@ -60,7 +60,7 @@ _GLOBAL(call_do_softirq) blr /* - * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp); + * void call_do_irq(struct pt_regs *regs, void *irqtp); */ _GLOBAL(call_do_irq) mflr r0@@ -183,10 +183,14 @@ _GLOBAL(low_choose_750fx_pll) or r4,r4,r5 mtspr SPRN_HID1,r4 +#ifdef CONFIG_SMP /* Store new HID1 image */ CURRENT_THREAD_INFO(r6, r1) lwz r6,TI_CPU(r6) slwi r6,r6,2 +#else + li r6, 0 +#endif addis r6,r6,nap_save_hid1@ha stw r4,nap_save_hid1@l(r6)@@ -599,7 +603,7 @@ EXPORT_SYMBOL(__bswapdi2) #ifdef CONFIG_SMP _GLOBAL(start_secondary_resume) /* Reset stack */ - CURRENT_THREAD_INFO(r1, r1) + rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD li r3,0 stw r3,0(r1) /* Zero the stack frame pointer */arch/powerpc/kernel/process.c +3
-3@@ -1240,8 +1240,8 @@ struct task_struct *__switch_to(struct task_struct *prev, batch->active =1 ; } -if (current_thread_info ()->task->thread.regs) { -restore_math (current_thread_info ()->task->thread.regs); +if (current->thread.regs) { +restore_math (current->thread.regs);/* * The copy-paste buffer can only store into foreign real @@ -1251,7 +1251,7 @@ struct task_struct *__switch_to(struct task_struct *prev,* mappings, we must issue a cp_abort to clear any state and * prevent snooping, corruption or a covert channel. */ - if (current_thread_info()->task->thread.used_vas) + if (current->thread.used_vas) asm volatile(PPC_CP_ABORT); }#endif /* CONFIG_PPC_BOOK3S_64 */ arch/powerpc/kernel/setup_32.c +5
-10@@ -205,10 +205,8 @@ void __init irqstack_early_init(void)/* interrupt stacks must be in lowmem, we get that for free on ppc32 * as the memblock is limited to lowmem by default */ for_each_possible_cpu (i) { - softirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - hardirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + softirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + hardirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); } }@@ -226,13 +224,10 @@ void __init exc_lvl_early_init(void) hw_cpu =0 ;#endif - critirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + critirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#ifdef CONFIG_BOOKE - dbgirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - mcheckirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + dbgirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + mcheckirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#endif } }arch/powerpc/kernel/smp.c +3
-1@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/export.h> #include <linux/sched/mm.h> +#include <linux/sched/task_stack.h> #include <linux/sched/topology.h> #include <linux/smp.h> #include <linux/interrupt.h> @@ -812,7 +813,8 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)#ifdef CONFIG_PPC64 paca_ptrs[cpu]->__current = idle; - paca_ptrs[cpu]->kstack = (unsigned long )ti +THREAD_SIZE -STACK_FRAME_OVERHEAD ; + paca_ptrs[cpu]->kstack = (unsigned long )task_stack_page (idle) + +THREAD_SIZE -STACK_FRAME_OVERHEAD ;#endif ti->cpu = cpu; secondary_ti = current_set[cpu] = ti;arch/powerpc/xmon/xmon.c +1
-1@@ -2988,7 +2988,7 @@ static void show_task(struct task_struct *tsk)printf ("%px %016lx %6d %6d %c %2d %s\n" , tsk, tsk->thread.ksp, tsk->pid, tsk->parent->pid, - state,task_thread_info (tsk)->cpu, + state,task_cpu (tsk), tsk->comm); }Signature · 1 line
2.13.3
Nicholas Piggin
reviewerRe: [RFC PATCH v3 2/7] powerpc: Prepare for moving thread_info into task_struct
Quoted 59 lines · On Wed, 3 Oct 2018 07:49:44 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:02, Nicholas Piggin a écrit :
Quoted 50 lines
Quoted 47 lines · On Mon, 1 Oct 2018 12:30:21 +0000 (UTC) Christophe Leroy…
This patch cleans the powerpc kernel before activating
CONFIG_THREAD_INFO_IN_TASK:
- The purpose of the pointer given tocall_do_softirq()andcall_do_irq()is to point the new stack ==> change it to void*
- Don't useCURRENT_THREAD_INFO()to locate the stack.
- Fixed a few comments.
-TI_CPUis only used whenCONFIG_SMPis set.
- Replace current_thread_info()->task by current
- Remove unnecessary casts tothread_info, as they'll become invalid oncethread_infois not in stack anymore.
- Ensuretask_struct'cpu' fields is not used directly out of SMP code
- RenameTHREAD_INFOtoTASK_STASK: As it is in fact the offset of the pointer to the stack intask_struct, this pointer will not be impacted by the move ofTHREAD_INFO.
- MakesTASK_STACKavailable to PPC64 which will need it to the get stack pointer from current once thethread_infohave been moved.Signed-off-by Christophe Leroy <[email protected]>--- arch/powerpc/include/asm/irq.h | 4 ++-- arch/powerpc/include/asm/livepatch.h | 2 +- arch/powerpc/include/asm/processor.h | 4 ++-- arch/powerpc/include/asm/reg.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S | 2 +- arch/powerpc/kernel/entry_64.S | 2 +- arch/powerpc/kernel/head_32.S | 4 ++-- arch/powerpc/kernel/head_40x.S | 4 ++-- arch/powerpc/kernel/head_44x.S | 2 +- arch/powerpc/kernel/head_8xx.S | 2 +- arch/powerpc/kernel/head_booke.h | 4 ++-- arch/powerpc/kernel/head_fsl_booke.S | 6 ++++-- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/misc_32.S | 8 ++++++-- arch/powerpc/kernel/process.c | 6 +++--- arch/powerpc/kernel/setup_32.c | 15 +++++---------- arch/powerpc/kernel/smp.c | 4 +++- arch/powerpc/xmon/xmon.c | 2 +- 19 files changed, 40 insertions(+), 37 deletions(-)arch/powerpc/include/asm/irq.h +0
-0@@ -63,8 +63,8 @@ extern struct thread_info *hardirq_ctx[NR_CPUS];extern struct thread_info *softirq_ctx[NR_CPUS ];Quoted 7 lines
arch/powerpc/include/asm/irq.h extern struct thread_info *hardirq_ctx[NR_CPUS]; · line 67
Quoted 5 lines
arch/powerpc/include/asm/irq.h +2
-2extern void irq_ctx_init (void ); -extern void call_do_softirq (struct thread_info *tp); -extern void call_do_irq (struct pt_regs *regs,struct thread_info *tp); +extern void call_do_softirq (void *tp); +extern void call_do_irq (struct pt_regs *regs,void *tp);void *sp for these ?
Quoted 2 lines
Yes, why not but it means changing the code. I wanted to minimise the changes and avoid cosmetic.
Fair enough.
Quoted 2 lines
Or maybe should add a cosmetic patch at the
end ?
Yeah that would be nice, I don't mind too much if it goes as part of the patches or as a cleanup afterward. There's a few other places that could use similar minor.
Quoted 5 lines
Quoted 3 lines
This all seems okay to me except the 32-bit code which I don't know. Would it be any trouble for you to put the
TI_CPUbits into their own patch?No problem, I can put the
TI_CPUbits in a separate patch.
Great thanks.
Thanks,
Nick
Quoted 373 lines
Quoted 4 lines
Reviewed-by Nicholas Piggin <[email protected]>Thanks
ChristopheQuoted 365 lines
Quoted 365 lines
arch/powerpc/include/asm/irq.h +0
-0extern void do_IRQ (struct pt_regs *regs);extern void __init init_IRQ (void );extern void __do_irq (struct pt_regs *regs);arch/powerpc/include/asm/livepatch.h +1
-1@@ -49,7 +49,7 @@ static inline void klp_init_thread_info(struct thread_info *ti) ti->livepatch_sp = (unsigned long *)(ti +1 ) +1 ; }#else -static void klp_init_thread_info (struct thread_info *ti) { } +static inline void klp_init_thread_info (struct thread_info *ti) { }#endif /* CONFIG_LIVEPATCH */ #endif /* _ASM_POWERPC_LIVEPATCH_H */ arch/powerpc/include/asm/processor.h +2
-2@@ -40,7 +40,7 @@#ifndef __ASSEMBLY__#include <linux/types.h> -#include <asm/thread_info.h> +#include <linux/thread_info.h> #include <asm/ptrace.h> #include <asm/hw_breakpoint.h> @@ -333,7 +333,7 @@ struct thread_struct {#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)#define INIT_SP_LIMIT \ - (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack) + (_ALIGN_UP(sizeof(struct thread_info), 16) + (unsigned long) &init_stack)#ifdef CONFIG_SPE #define SPEFSCR_INIT \arch/powerpc/include/asm/reg.h +1
-1@@ -1053,7 +1053,7 @@* - SPRG9 debug exception scratch * * All 32-bit: -* - SPRG3 current thread_info pointer +* - SPRG3 current thread_struct physical addr pointer * (virtual on BookE, physical on others) * * 32-bit classic: arch/powerpc/kernel/asm-offsets.c +1
-1@@ -85,10 +85,10 @@ int main(void)DEFINE (NMI_MASK ,NMI_MASK );OFFSET (TASKTHREADPPR , task_struct, thread.ppr);#else -OFFSET (THREAD_INFO , task_struct, stack);DEFINE (THREAD_INFO_GAP ,_ALIGN_UP (sizeof (struct thread_info ),16 ));OFFSET (KSP_LIMIT , thread_struct, ksp_limit);#endif /* CONFIG_PPC64 */ +OFFSET (TASK_STACK , task_struct, stack);#ifdef CONFIG_LIVEPATCH OFFSET (TI_livepatch_sp, thread_info, livepatch_sp);arch/powerpc/kernel/entry_32.S +1
-1@@ -1166,7 +1166,7 @@ ret_from_debug_exc: mfspr r9,SPRN_SPRG_THREAD lwz r10,SAVED_KSP_LIMIT(r1) stw r10,KSP_LIMIT(r9) - lwz r9,THREAD_INFO-THREAD(r9) + lwz r9,TASK_STACK-THREAD(r9) CURRENT_THREAD_INFO(r10, r1) lwz r10,TI_PREEMPT(r10) stw r10,TI_PREEMPT(r9)arch/powerpc/kernel/entry_64.S +1
-1@@ -680,7 +680,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) 2: #endif /* CONFIG_PPC_BOOK3S_64 */ - CURRENT_THREAD_INFO(r7, r8) /* base of new stack */ + clrrdi r7, r8, THREAD_SHIFT /* base of new stack */ /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE because we don't need to leave the 288-byte ABI gap at the top of the kernel stack. */arch/powerpc/kernel/head_32.S +2
-2@@ -261,7 +261,7 @@ __secondary_hold_acknowledge: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */@@ -841,7 +841,7 @@ __secondary_start: bl init_idle_6xx #endif /* CONFIG_6xx */ - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha tophys(r1,r1) lwz r1,secondary_ti@l(r1)arch/powerpc/kernel/head_40x.S +2
-2@@ -115,7 +115,7 @@ _ENTRY(saved_ksp_limit) andi. r11,r11,MSR_PR; \ beq 1f; \ mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\ + lwz r1,TASK_STACK-THREAD(r1); /* this thread's kernel stack */\ addi r1,r1,THREAD_SIZE; \ 1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\ tophys(r11,r1); \@@ -158,7 +158,7 @@ _ENTRY(saved_ksp_limit) beq 1f; \ /* COMING FROM USER MODE */ \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\ 1: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\ tophys(r11,r11); \ stw r10,_CCR(r11); /* save various registers */\arch/powerpc/kernel/head_44x.S +1
-1@@ -1020,7 +1020,7 @@ _GLOBAL(start_secondary_47x) /* Now we can get our task struct and real stack pointer */ - /* Get current_thread_info and current */ + /* Get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)arch/powerpc/kernel/head_8xx.S +1
-1@@ -124,7 +124,7 @@ turn_on_mmu: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \ 1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */arch/powerpc/kernel/head_booke.h +2
-2@@ -44,7 +44,7 @@mr r11, r1; \ beq 1f; \/* if from user, start at top of this thread's kernel stack */ \ - lwz r11, THREAD_INFO-THREAD(r10); \ + lwz r11, TASK_STACK-THREAD(r10); \ALLOC_STACK_FRAME (r11,THREAD_SIZE ); \ 1 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \stw r13,_CCR (r11 );/* save various registers */ \@@ -130,7 +130,7 @@ DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ andi. r11,r11,MSR_PR ; \mfspr r11,SPRN_SPRG_THREAD ;/* if from user, start at top of */ \ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\addi r11,r11,EXC_LVL_FRAME_OVERHEAD ;/* allocate stack frame */ \ beq 1f; \/* COMING FROM USER MODE */ \arch/powerpc/kernel/head_fsl_booke.S +4
-2@@ -243,8 +243,10 @@ set_ivor: li r0,0 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) +#ifdef CONFIG_SMP CURRENT_THREAD_INFO(r22, r1) stw r24, TI_CPU(r22) +#endif bl early_init@@ -702,7 +704,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r12, THREAD_INFO-THREAD(r12) + lwz r12, TASK_STACK-THREAD(r12) lwz r15, TI_CPU(r12) lis r14, __per_cpu_offset@h ori r14, r14, __per_cpu_offset@l@@ -1074,7 +1076,7 @@ __secondary_start: mr r4,r24 /* Why? */ bl call_setup_cpu - /* get current_thread_info and current */ + /* get current's stack and current */ lis r1,secondary_ti@ha lwz r1,secondary_ti@l(r1) lwz r2,TI_TASK(r1)arch/powerpc/kernel/irq.c +1
-1@@ -663,7 +663,7 @@ void do_IRQ(struct pt_regs *regs)struct thread_info *curtp, *irqtp, *sirqtp;/* Switch to the irq stack to handle this */ - curtp =current_thread_info (); + curtp = (void *)(current_stack_pointer () & ~(THREAD_SIZE -1 )); irqtp = hardirq_ctx[raw_smp_processor_id ()]; sirqtp = softirq_ctx[raw_smp_processor_id ()];arch/powerpc/kernel/misc_32.S +6
-2@@ -60,7 +60,7 @@ _GLOBAL(call_do_softirq) blr /* - * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp); + * void call_do_irq(struct pt_regs *regs, void *irqtp); */ _GLOBAL(call_do_irq) mflr r0@@ -183,10 +183,14 @@ _GLOBAL(low_choose_750fx_pll) or r4,r4,r5 mtspr SPRN_HID1,r4 +#ifdef CONFIG_SMP /* Store new HID1 image */ CURRENT_THREAD_INFO(r6, r1) lwz r6,TI_CPU(r6) slwi r6,r6,2 +#else + li r6, 0 +#endif addis r6,r6,nap_save_hid1@ha stw r4,nap_save_hid1@l(r6)@@ -599,7 +603,7 @@ EXPORT_SYMBOL(__bswapdi2) #ifdef CONFIG_SMP _GLOBAL(start_secondary_resume) /* Reset stack */ - CURRENT_THREAD_INFO(r1, r1) + rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFT addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD li r3,0 stw r3,0(r1) /* Zero the stack frame pointer */arch/powerpc/kernel/process.c +3
-3@@ -1240,8 +1240,8 @@ struct task_struct *__switch_to(struct task_struct *prev, batch->active =1 ; } -if (current_thread_info ()->task->thread.regs) { -restore_math (current_thread_info ()->task->thread.regs); +if (current->thread.regs) { +restore_math (current->thread.regs);/* * The copy-paste buffer can only store into foreign real @@ -1251,7 +1251,7 @@ struct task_struct *__switch_to(struct task_struct *prev,* mappings, we must issue a cp_abort to clear any state and * prevent snooping, corruption or a covert channel. */ - if (current_thread_info()->task->thread.used_vas) + if (current->thread.used_vas) asm volatile(PPC_CP_ABORT); }#endif /* CONFIG_PPC_BOOK3S_64 */ arch/powerpc/kernel/setup_32.c +5
-10@@ -205,10 +205,8 @@ void __init irqstack_early_init(void)/* interrupt stacks must be in lowmem, we get that for free on ppc32 * as the memblock is limited to lowmem by default */ for_each_possible_cpu (i) { - softirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - hardirq_ctx[i] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + softirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + hardirq_ctx[i] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); } }@@ -226,13 +224,10 @@ void __init exc_lvl_early_init(void) hw_cpu =0 ;#endif - critirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + critirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#ifdef CONFIG_BOOKE - dbgirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); - mcheckirq_ctx[hw_cpu] = (struct thread_info *) -__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + dbgirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE )); + mcheckirq_ctx[hw_cpu] =__va (memblock_alloc (THREAD_SIZE ,THREAD_SIZE ));#endif } }arch/powerpc/kernel/smp.c +3
-1@@ -20,6 +20,7 @@#include <linux/kernel.h> #include <linux/export.h> #include <linux/sched/mm.h> +#include <linux/sched/task_stack.h> #include <linux/sched/topology.h> #include <linux/smp.h> #include <linux/interrupt.h> @@ -812,7 +813,8 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)#ifdef CONFIG_PPC64 paca_ptrs[cpu]->__current = idle; - paca_ptrs[cpu]->kstack = (unsigned long )ti +THREAD_SIZE -STACK_FRAME_OVERHEAD ; + paca_ptrs[cpu]->kstack = (unsigned long )task_stack_page (idle) + +THREAD_SIZE -STACK_FRAME_OVERHEAD ;#endif ti->cpu = cpu; secondary_ti = current_set[cpu] = ti;arch/powerpc/xmon/xmon.c +1
-1@@ -2988,7 +2988,7 @@ static void show_task(struct task_struct *tsk)printf ("%px %016lx %6d %6d %c %2d %s\n" , tsk, tsk->thread.ksp, tsk->pid, tsk->parent->pid, - state,task_thread_info (tsk)->cpu, + state,task_cpu (tsk), tsk->comm); }Signature · 1 line
2.13.3
Re: [RFC PATCH v3 2/7] powerpc: Prepare for moving thread_info into task_struct
In reply to Christophe LEROYLe 03/10/2018 à 07:49, Christophe LEROY a écrit :
Quoted 60 lines
Le 03/10/2018 à 07:02, Nicholas Piggin a écrit :
Quoted 43 lines
Quoted 40 lines · On Mon, 1 Oct 2018 12:30:21 +0000 (UTC) Christophe Leroy…
This patch cleans the powerpc kernel before activating
CONFIG_THREAD_INFO_IN_TASK:
- The purpose of the pointer given tocall_do_softirq()andcall_do_irq()is to point the new stack ==> change it to void*
- Don't useCURRENT_THREAD_INFO()to locate the stack.
- Fixed a few comments.
-TI_CPUis only used whenCONFIG_SMPis set.
- Replace current_thread_info()->task by current
- Remove unnecessary casts tothread_info, as they'll become invalid oncethread_infois not in stack anymore.
- Ensuretask_struct'cpu' fields is not used directly out of SMP code
- RenameTHREAD_INFOtoTASK_STASK: As it is in fact the offset of the pointer to the stack intask_struct, this pointer will not be impacted by the move ofTHREAD_INFO.
- MakesTASK_STACKavailable to PPC64 which will need it to the get stack pointer from current once thethread_infohave been moved.Signed-off-by Christophe Leroy <[email protected]>---
arch/powerpc/include/asm/irq.h | 4 ++--
arch/powerpc/include/asm/livepatch.h| 2 +-
arch/powerpc/include/asm/processor.h| 4 ++--
arch/powerpc/include/asm/reg.h | 2 +-
arch/powerpc/kernel/asm-offsets.c | 2 +-
arch/powerpc/kernel/entry_32.S | 2 +-
arch/powerpc/kernel/entry_64.S | 2 +-
arch/powerpc/kernel/head_32.S | 4 ++--arch/powerpc/kernel/head_40x.S | 4 ++-- arch/powerpc/kernel/head_44x.S | 2 +- arch/powerpc/kernel/head_8xx.S | 2 +-arch/powerpc/kernel/head_booke.h | 4 ++--
arch/powerpc/kernel/head_fsl_booke.S| 6 ++++-- arch/powerpc/kernel/irq.c | 2 +- arch/powerpc/kernel/misc_32.S | 8 ++++++-- arch/powerpc/kernel/process.c | 6 +++--- arch/powerpc/kernel/setup_32.c | 15 +++++---------- arch/powerpc/kernel/smp.c | 4 +++- arch/powerpc/xmon/xmon.c | 2 +-19 files changed, 40 insertions(+), 37 deletions(-)Quoted 13 lines
arch/powerpc/include/asm/irq.h extern struct thread_info *hardirq_ctx[NR_CPUS]; · line 66
Quoted 11 lines
arch/powerpc/include/asm/irq.h +2
-2@@ -63,8 +63,8 @@ extern struct thread_info *hardirq_ctx[NR_CPUS]; extern struct thread_info *softirq_ctx[NR_CPUS]; extern void irq_ctx_init(void); -extern void call_do_softirq (struct thread_info *tp); -extern void call_do_irq (struct pt_regs *regs,struct thread_info *tp); +extern void call_do_softirq (void *tp); +extern void call_do_irq (struct pt_regs *regs,void *tp);void *sp for these ?
Quoted 1 line
Yes, why not but it means changing the code. I wanted to minimise the changes and avoid cosmetic. Or maybe should add a cosmetic patch at the end ?
In fact, I'll do it because the only additional impact is on a comment in misc_32.S
Christophe
Quoted 372 lines
Quoted 5 lines
This all seems okay to me except the 32-bit code which I don't know. Would it be any trouble for you to put the
TI_CPUbits into their own patch?No problem, I can put the
TI_CPUbits in a separate patch.Quoted 3 lines
Reviewed-by Nicholas Piggin <[email protected]>Thanks
ChristopheQuoted 357 lines
Quoted 357 lines
arch/powerpc/include/asm/irq.h +0
-0extern void do_IRQ(struct pt_regs *regs); extern void __init init_IRQ(void); extern void __do_irq(struct pt_regs *regs);arch/powerpc/include/asm/livepatch.h +1
-1@@ -49,7 +49,7 @@ static inline void klp_init_thread_info(struct thread_info *ti) ti->livepatch_sp = (unsigned long *)(ti + 1) + 1; } #else -static void klp_init_thread_info (struct thread_info *ti) { } +static inline void klp_init_thread_info (struct thread_info *ti) { } #endif /* CONFIG_LIVEPATCH */ #endif /* _ASM_POWERPC_LIVEPATCH_H */arch/powerpc/include/asm/processor.h +2
-2@@ -40,7 +40,7 @@ #ifndef __ASSEMBLY__ #include <linux/types.h> -#include <asm/thread_info.h> +#include <linux/thread_info.h> #include <asm/ptrace.h> #include <asm/hw_breakpoint.h>@@ -333,7 +333,7 @@ struct thread_struct { #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack) #define INIT_SP_LIMIT \ - (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack) + (_ALIGN_UP(sizeof(struct thread_info), 16) + (unsigned long) &init_stack) #ifdef CONFIG_SPE #define SPEFSCR_INIT \arch/powerpc/include/asm/reg.h +1
-1@@ -1053,7 +1053,7 @@ * - SPRG9 debug exception scratch * * All 32-bit: - * - SPRG3 current thread_info pointer + * - SPRG3 current thread_struct physical addr pointer * (virtual on BookE, physical on others) * * 32-bit classic:arch/powerpc/kernel/asm-offsets.c +1
-1@@ -85,10 +85,10 @@ int main(void) DEFINE(NMI_MASK, NMI_MASK); OFFSET(TASKTHREADPPR, task_struct, thread.ppr); #else - OFFSET(THREAD_INFO, task_struct, stack); DEFINE(THREAD_INFO_GAP, _ALIGN_UP(sizeof(struct thread_info), 16)); OFFSET(KSP_LIMIT, thread_struct, ksp_limit); #endif /* CONFIG_PPC64 */ + OFFSET(TASK_STACK, task_struct, stack); #ifdef CONFIG_LIVEPATCH OFFSET(TI_livepatch_sp, thread_info, livepatch_sp);arch/powerpc/kernel/entry_32.S +0
-0@@ -1166,7 +1166,7 @@ ret_from_debug_exc:mfspr r9,SPRN_SPRG_THREAD
lwz r10,SAVED_KSP_LIMIT(r1)
stw r10,KSP_LIMIT(r9)
- lwz r9,THREAD_INFO-THREAD(r9)
+ lwz r9,TASK_STACK-THREAD(r9)
CURRENT_THREAD_INFO(r10, r1)
lwz r10,TI_PREEMPT(r10)
stw r10,TI_PREEMPT(r9)arch/powerpc/kernel/entry_64.S +0
-0@@ -680,7 +680,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)2:
#endif /*CONFIG_PPC_BOOK3S_64*/
-CURRENT_THREAD_INFO(r7, r8)/* base of new stack */ + clrrdi r7, r8, THREAD_SHIFT /* base of new stack */ /* Note: this usesSWITCH_FRAME_SIZErather thanINT_FRAME_SIZEbecause we don't need to leave the 288-byte ABI gap at the top of the kernel stack. */arch/powerpc/kernel/head_32.S +1
-1@@ -261,7 +261,7 @@ __secondary_hold_acknowledge: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
arch/powerpc/kernel/head_32.S +0
-0@@ -841,7 +841,7 @@ __secondary_start:bl
init_idle_6xx
#endif /*CONFIG_6xx*/
- /* getcurrent_thread_infoand current */
+ /* get current's stack and current */
lis r1,secondary_ti@ha
tophys(r1,r1)
lwz r1,secondary_ti@l(r1)arch/powerpc/kernel/head_40x.S +1
-1@@ -115,7 +115,7 @@ _ENTRY(saved_ksp_limit) andi. r11,r11,MSR_PR; \ beq 1f; \ mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\ + lwz r1,TASK_STACK-THREAD(r1); /* this thread's kernel stack */\ addi r1,r1,THREAD_SIZE; \1: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\
tophys(r11,r1); \arch/powerpc/kernel/head_40x.S +1
-1@@ -158,7 +158,7 @@ _ENTRY(saved_ksp_limit) beq 1f; \ /* COMING FROM USER MODE */ \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack */\ 1: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\tophys(r11,r11); \
stw r10,_CCR(r11); /* save various registers */\arch/powerpc/kernel/head_44x.S +1
-1@@ -1020,7 +1020,7 @@ _GLOBAL(start_secondary_47x) /* Now we can get our task struct and real stack pointer */ - /* Get current_thread_info and current */ + /* Get current's stack and current */lis r1,secondary_ti@ha
lwz r1,secondary_ti@l(r1)
lwz r2,TI_TASK(r1)arch/powerpc/kernel/head_8xx.S +1
-1@@ -124,7 +124,7 @@ turn_on_mmu: tophys(r11,r1); /* use tophys(r1) if kernel */ \ beq 1f; \ mfspr r11,SPRN_SPRG_THREAD; \ - lwz r11,THREAD_INFO-THREAD(r11); \ + lwz r11,TASK_STACK-THREAD(r11); \ addi r11,r11,THREAD_SIZE; \ tophys(r11,r11); \1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
arch/powerpc/kernel/head_booke.h +2
-2@@ -44,7 +44,7 @@ mr r11, r1; \ beq 1f; \ /* if from user, start at top of this thread's kernel stack */ \ - lwz r11, THREAD_INFO-THREAD(r10); \ + lwz r11, TASK_STACK-THREAD(r10); \ ALLOC_STACK_FRAME(r11, THREAD_SIZE); \ 1 : subi r11, r11, INT_FRAME_SIZE; /* Allocate exception frame */ \ stw r13, _CCR(r11); /* save various registers */ \@@ -130,7 +130,7 @@DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ andi. r11,r11,MSR_PR; \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */ \ - lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ + lwz r11,TASK_STACK-THREAD(r11); /* this thread's kernel stack*/ \ addi r11,r11,EXC_LVL_FRAME_OVERHEAD; /* allocate stack frame */\beq 1f; \
/* COMING FROM USER MODE */ \arch/powerpc/kernel/head_fsl_booke.S +0
-0@@ -243,8 +243,10 @@ set_ivor:li r0,0
stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) +#ifdefCONFIG_SMP
CURRENT_THREAD_INFO(r22, r1)
stw r24,TI_CPU(r22)
+#endif
blearly_initarch/powerpc/kernel/head_fsl_booke.S +1
-1@@ -702,7 +704,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r12, THREAD_INFO-THREAD(r12) + lwz r12, TASK_STACK-THREAD(r12) lwz r15, TI_CPU(r12)lis r14, __per_cpu_offset@h
ori r14, r14, __per_cpu_offset@larch/powerpc/kernel/head_fsl_booke.S +0
-0@@ -1074,7 +1076,7 @@ __secondary_start:mr r4,r24 /* Why? */
blcall_setup_cpu
- /* getcurrent_thread_infoand current */
+ /* get current's stack and current */
lis r1,secondary_ti@ha
lwz r1,secondary_ti@l(r1)
lwz r2,TI_TASK(r1)arch/powerpc/kernel/irq.c +1
-1@@ -663,7 +663,7 @@ void do_IRQ(struct pt_regs *regs) struct thread_info *curtp, *irqtp, *sirqtp; /* Switch to the irq stack to handle this */ - curtp = current_thread_info(); + curtp = (void*)(current_stack_pointer() & ~(THREAD_SIZE - 1)); irqtp = hardirq_ctx[raw_smp_processor_id()]; sirqtp = softirq_ctx[raw_smp_processor_id()];arch/powerpc/kernel/misc_32.S +0
-0@@ -60,7 +60,7 @@ _GLOBAL(call_do_softirq)blr
/*
- * voidcall_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
+ * voidcall_do_irq(struct pt_regs *regs, void *irqtp);
*/
_GLOBAL(call_do_irq)
mflr r0arch/powerpc/kernel/misc_32.S +0
-0@@ -183,10 +183,14 @@ _GLOBAL(low_choose_750fx_pll)or r4,r4,r5
mtspr SPRN_HID1,r4
+#ifdefCONFIG_SMP
/* Store new HID1 image */
CURRENT_THREAD_INFO(r6, r1)
lwz r6,TI_CPU(r6)
slwi r6,r6,2arch/powerpc/kernel/misc_32.S +3
-0+#else + li r6, 0 +#endifaddis r6,r6,nap_save_hid1@ha
stw r4,nap_save_hid1@l(r6)arch/powerpc/kernel/misc_32.S +1
-1@@ -599,7 +603,7 @@ EXPORT_SYMBOL(__bswapdi2) #ifdef CONFIG_SMP _GLOBAL(start_secondary_resume) /* Reset stack */ - CURRENT_THREAD_INFO(r1, r1) + rlwinm r1, r1, 0, 0, 31 - THREAD_SHIFTaddi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
li r3,0
stw r3,0(r1) /* Zero the stack frame pointer */arch/powerpc/kernel/process.c +3
-3@@ -1240,8 +1240,8 @@ struct task_struct *__switch_to(structtask_struct *prev, batch->active = 1; } - if (current_thread_info()->task->thread.regs) { - restore_math(current_thread_info()->task->thread.regs); + if (current->thread.regs) { + restore_math(current->thread.regs); /** The copy-paste buffer can only store into foreign real @@ -1251,7 +1251,7 @@ struct task_struct *__switch_to(structtask_struct *prev, * mappings, we must issue a cp_abort to clear any state and * prevent snooping, corruption or a covert channel. */ - if (current_thread_info()->task->thread.used_vas) + if (current->thread.used_vas) asm volatile(PPC_CP_ABORT); }#endif /*
CONFIG_PPC_BOOK3S_64*/arch/powerpc/kernel/setup_32.c +2
-4@@ -205,10 +205,8 @@ void __init irqstack_early_init(void) /* interrupt stacks must be in lowmem, we get that for free on ppc32 * as the memblock is limited to lowmem by default */ for_each_possible_cpu(i) { - softirq_ctx[i] = (struct thread_info *) - __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); - hardirq_ctx[i] = (struct thread_info *) - __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); + softirq_ctx[i] = __va(memblock_alloc(THREAD_SIZE,THREAD_SIZE )); + hardirq_ctx[i] = __va(memblock_alloc(THREAD_SIZE,THREAD_SIZE )); }}
arch/powerpc/kernel/setup_32.c +3
-6@@ -226,13 +224,10 @@ void __init exc_lvl_early_init(void) hw_cpu = 0; #endif - critirq_ctx[hw_cpu] = (struct thread_info *) - __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); + critirq_ctx[hw_cpu] = __va(memblock_alloc(THREAD_SIZE,THREAD_SIZE )); #ifdef CONFIG_BOOKE - dbgirq_ctx[hw_cpu] = (struct thread_info *) - __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); - mcheckirq_ctx[hw_cpu] = (struct thread_info *) - __va(memblock_alloc(THREAD_SIZE, THREAD_SIZE)); + dbgirq_ctx[hw_cpu] = __va(memblock_alloc(THREAD_SIZE,THREAD_SIZE )); + mcheckirq_ctx[hw_cpu] = __va(memblock_alloc(THREAD_SIZE,THREAD_SIZE )); #endif}
}arch/powerpc/kernel/smp.c +3
-1@@ -20,6 +20,7 @@ #include <linux/kernel.h> #include <linux/export.h> #include <linux/sched/mm.h> +#include <linux/sched/task_stack.h> #include <linux/sched/topology.h> #include <linux/smp.h> #include <linux/interrupt.h>@@ -812,7 +813,8 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle) #ifdef CONFIG_PPC64 paca_ptrs[cpu]->__current = idle; - paca_ptrs[cpu]->kstack = (unsigned long)ti + THREAD_SIZE -STACK_FRAME_OVERHEAD ; + paca_ptrs[cpu]->kstack = (unsigned long)task_stack_page(idle) + + THREAD_SIZE - STACK_FRAME_OVERHEAD; #endif ti->cpu = cpu;
secondary_ti= current_set[cpu] = ti;arch/powerpc/xmon/xmon.c +1
-1@@ -2988,7 +2988,7 @@ static void show_task(struct task_struct *tsk) printf("%px %016lx %6d %6d %c %2d %s\n", tsk, tsk->thread.ksp, tsk->pid, tsk->parent->pid, - state, task_thread_info(tsk)->cpu, + state, task_cpu(tsk), tsk->comm); }Signature · 1 line
2.13.3
RFC PATCH v3 3/7 powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
In reply to Christophe LeroyThis patch activates CONFIG_THREAD_INFO_IN_TASK which moves the thread_info into task_struct.
Moving thread_info into task_struct has the following advantages:
- It protects thread_info from corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.
This has the following consequences:
- thread_info is now located at the top of task_struct.
- The 'cpu' field is now in task_struct, and only exists when CONFIG_SMP is active.
- thread_info doesn't have anymore the 'task' field.
This patch:
- Removes all recopy of thread_info struct when the stack changes.
- Changes the CURRENT_THREAD_INFO() macro to point to current.
- Selects CONFIG_THREAD_INFO_IN_TASK.
- Modifies raw_smp_processor_id() to get ->cpu from current without including linux/sched.h to avoid circular inclusion.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 6 +++++ arch/powerpc/include/asm/ptrace.h | 2 +- arch/powerpc/include/asm/smp.h | 8 +++++- arch/powerpc/include/asm/thread_info.h | 17 ++---------- arch/powerpc/kernel/asm-offsets.c | 5 ++-- arch/powerpc/kernel/entry_32.S | 9 +++---- arch/powerpc/kernel/exceptions-64e.S | 11 -------- arch/powerpc/kernel/head_32.S | 6 ++--- arch/powerpc/kernel/head_44x.S | 4 +-- arch/powerpc/kernel/head_64.S | 1 + arch/powerpc/kernel/head_booke.h | 8 +----- arch/powerpc/kernel/head_fsl_booke.S | 7 +++-- arch/powerpc/kernel/irq.c | 47 +--------------------------------- arch/powerpc/kernel/kgdb.c | 28 -------------------- arch/powerpc/kernel/machine_kexec_64.c | 6 ++--- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/setup_64.c | 21 --------------- arch/powerpc/kernel/smp.c | 2 +- 19 files changed, 39 insertions(+), 152 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -237,6 +237,7 @@ config PPC select RTC_LIB select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE + select THREAD_INFO_IN_TASK select VIRT_TO_BUS if !PPC64 # # Please keep this list sorted alphabetically.
arch/powerpc/Makefile +6 -0
@@ -422,3 +422,9 @@ checkbin: CLEAN_FILES += $(TOUT) +ifdef CONFIG_SMP +prepare: task_cpu_prepare + +task_cpu_prepare: prepare0 + $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TI_CPU") print $$3;}' include/generated/asm-offsets.h)) +endif
arch/powerpc/include/asm/ptrace.h +1 -1
@@ -120,7 +120,7 @@ extern int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data);#define current_pt_regs () \ - ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1) + ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)/* * We use the least-significant bit of the trap field to indicate * whether we have saved the full set of registers, or only a
arch/powerpc/include/asm/smp.h +7 -1
@@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);/* 32-bit */ extern int smp_hw_index[]; -#define raw_smp_processor_id () (current_thread_info()->cpu) +/* +* This is particularly ugly: it appears we can't actually get the definition +* of task_struct here, but we need access to the CPU this task is running on. +* Instead of using task_struct we're using _TASK_CPU which is extracted from +* asm-offsets.h by kbuild to get the current processor ID. +*/ +#define raw_smp_processor_id () (*(unsigned int*)((void*)current + _TASK_CPU))#define hard_smp_processor_id () (smp_hw_index[smp_processor_id()])static inline int get_hard_smp_processor_id (int cpu)
arch/powerpc/include/asm/thread_info.h +2 -15
@@ -18,9 +18,9 @@#define THREAD_SIZE (1 << THREAD_SHIFT)#ifdef CONFIG_PPC64 -#define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(clrrdi dest, sp, THREAD_SHIFT) +#define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(ld dest, PACACURRENT(r13))#else -#define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(rlwinm dest, sp, 0, 0, 31-THREAD_SHIFT) +#define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(mr dest, r2)#endif #ifndef __ASSEMBLY__
@@ -34,8 +34,6 @@* low level task data. */ struct thread_info { -struct task_struct *task;/* main task structure */ -int cpu;/* cpu we're on */ int preempt_count;/* 0 => preemptable, <0 => BUG */ unsigned long local_flags;/* private flags for thread */
@@ -58,8 +56,6 @@ struct thread_info {*/ #define INIT_THREAD_INFO (tsk) \ { \ - .task = &tsk, \ - .cpu = 0, \ .preempt_count = INIT_PREEMPT_COUNT, \ .flags = 0, \ }
@@ -67,15 +63,6 @@ struct thread_info {#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)/* how to get the thread information struct from C */ -static inline struct thread_info *current_thread_info (void ) -{ -unsigned long val; - - asm (CURRENT_THREAD_INFO(%0,1) : "=r" (val)); - -return (struct thread_info *)val; -} -extern int arch_dup_task_struct (struct task_struct *dst,struct task_struct *src);#ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/kernel/asm-offsets.c +3 -2
@@ -89,6 +89,9 @@ int main(void)OFFSET (KSP_LIMIT , thread_struct, ksp_limit);#endif /* CONFIG_PPC64 */ OFFSET (TASK_STACK , task_struct, stack); +#ifdef CONFIG_SMP +OFFSET (TI_CPU , task_struct, cpu); +#endif #ifdef CONFIG_LIVEPATCH OFFSET (TI_livepatch_sp, thread_info, livepatch_sp);
@@ -156,8 +159,6 @@ int main(void)OFFSET (TI_FLAGS , thread_info, flags);OFFSET (TI_LOCAL_FLAGS , thread_info, local_flags);OFFSET (TI_PREEMPT , thread_info, preempt_count); -OFFSET (TI_TASK , thread_info, task); -OFFSET (TI_CPU , thread_info, cpu);#ifdef CONFIG_PPC64 OFFSET (DCACHEL1BLOCKSIZE , ppc64_caches, l1d.block_size);
arch/powerpc/kernel/entry_32.S +4 -5
@@ -1166,10 +1166,6 @@ ret_from_debug_exc: mfspr r9,SPRN_SPRG_THREAD lwz r10,SAVED_KSP_LIMIT(r1) stw r10,KSP_LIMIT(r9) - lwz r9,TASK_STACK-THREAD(r9) - CURRENT_THREAD_INFO(r10, r1) - lwz r10,TI_PREEMPT(r10) - stw r10,TI_PREEMPT(r9) RESTORE_xSRR(SRR0,SRR1); RESTORE_xSRR(CSRR0,CSRR1); RESTORE_MMU_REGS;
@@ -1292,10 +1288,13 @@ BEGIN_FTR_SECTION END_FTR_SECTION_IFSET(CPU_FTR_601) lwz r3,_TRAP(r1) andi. r0,r3,1 - beq 4f + beq 5f SAVE_NVGPRS(r1) rlwinm r3,r3,0,0,30 stw r3,_TRAP(r1) +5: mfspr r2,SPRN_SPRG_THREAD + addi r2,r2,-THREAD + tovirt(r2,r2) /* set back r2 to current */ 4: addi r3,r1,STACK_FRAME_OVERHEAD bl nonrecoverable_exception /* shouldn't return */
arch/powerpc/kernel/exceptions-64e.S +0 -11
@@ -77,17 +77,6 @@ special_reg_save: andi. r3,r3,MSR_PR bnelr - /* Copy info into temporary exception thread info */ - ld r11,PACAKSAVE(r13) - CURRENT_THREAD_INFO(r11, r11) - CURRENT_THREAD_INFO(r12, r1) - ld r10,TI_FLAGS(r11) - std r10,TI_FLAGS(r12) - ld r10,TI_PREEMPT(r11) - std r10,TI_PREEMPT(r12) - ld r10,TI_TASK(r11) - std r10,TI_TASK(r12) - /* * Advance to the next TLB exception frame for handler * types that don't do it automatically.
arch/powerpc/kernel/head_32.S +3 -3
@@ -844,9 +844,9 @@ __secondary_start: /* get current's stack and current */ lis r1,secondary_ti@ha tophys(r1,r1) - lwz r1,secondary_ti@l(r1) - tophys(r2,r1) - lwz r2,TI_TASK(r2) + lwz r2,secondary_ti@l(r1) + tophys(r1,r2) + lwz r1,TASK_STACK(r1) /* stack */ addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
arch/powerpc/kernel/head_44x.S +2 -2
@@ -1022,8 +1022,8 @@ _GLOBAL(start_secondary_47x) /* Get current's stack and current */ lis r1,secondary_ti@ha - lwz r1,secondary_ti@l(r1) - lwz r2,TI_TASK(r1) + lwz r2,secondary_ti@l(r1) + lwz r1,TASK_STACK(r2) /* Current stack pointer */ addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
arch/powerpc/kernel/head_64.S +1 -0
@@ -805,6 +805,7 @@ __secondary_start: LOAD_REG_ADDR(r3, current_set) sldi r28,r24,3 /* get current_set[cpu#] */ ldx r14,r3,r28 + ld r14,TASK_STACK(r14) addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD std r14,PACAKSAVE(r13)
arch/powerpc/kernel/head_booke.h +1 -7
@@ -143,13 +143,7 @@stw r10,GPR11 (r11 ); \ b 2f; \/* COMING FROM PRIV MODE */ \ -1: lwz r9,TI_FLAGS-EXC_LVL_FRAME_OVERHEAD(r11); \ - lwz r10,TI_PREEMPT-EXC_LVL_FRAME_OVERHEAD(r11); \ - stw r9,TI_FLAGS-EXC_LVL_FRAME_OVERHEAD(r8); \ - stw r10,TI_PREEMPT-EXC_LVL_FRAME_OVERHEAD(r8); \ - lwz r9,TI_TASK-EXC_LVL_FRAME_OVERHEAD(r11); \ - stw r9,TI_TASK-EXC_LVL_FRAME_OVERHEAD(r8); \ -mr r11,r8; \ +1: mr r11,r8; \ 2: mfspr r8,SPRN_SPRG_RSCRATCH_##exc_level; \ stw r12,GPR12(r11); /* save various registers */\ mflr r10; \
arch/powerpc/kernel/head_fsl_booke.S +3 -4
@@ -704,8 +704,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r12, TASK_STACK-THREAD(r12) - lwz r15, TI_CPU(r12) + lwz r15, TI_CPU-THREAD(r12) lis r14, __per_cpu_offset@h ori r14, r14, __per_cpu_offset@l rlwinm r15, r15, 2, 0, 29
@@ -1078,8 +1077,8 @@ __secondary_start: /* get current's stack and current */ lis r1,secondary_ti@ha - lwz r1,secondary_ti@l(r1) - lwz r2,TI_TASK(r1) + lwz r2,secondary_ti@l(r1) + lwz r1,TASK_STACK(r2) /* stack */ addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
arch/powerpc/kernel/irq.c +1 -46
90 lines not on this page · raw message
arch/powerpc/kernel/kgdb.c +0 -28
@@ -151,41 +151,13 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)return 1 ; } -static DEFINE_PER_CPU(struct thread_info, kgdb_thread_info);static int kgdb_singlestep (struct pt_regs *regs) { -struct thread_info *thread_info, *exception_thread_info; -struct thread_info *backup_current_thread_info = -this_cpu_ptr (&kgdb_thread_info); -if (user_mode (regs))return 0 ; -/* -* On Book E and perhaps other processors, singlestep is handled on -* the critical exception stack. This causes current_thread_info() -* to fail, since it it locates the thread_info by masking off -* the low bits of the current stack pointer. We work around -* this issue by copying the thread_info from the kernel stack -* before calling kgdb_handle_exception, and copying it back -* afterwards. On most processors the copy is avoided since -* exception_thread_info == thread_info. -*/ - thread_info = (struct thread_info *)(regs->gpr[1 ] & ~(THREAD_SIZE -1 )); - exception_thread_info =current_thread_info (); - -if (thread_info != exception_thread_info) { -/* Save the original current_thread_info. */ -memcpy (backup_current_thread_info, exception_thread_info,sizeof *thread_info); -memcpy (exception_thread_info, thread_info,sizeof *thread_info); - } -kgdb_handle_exception (0 ,SIGTRAP ,0 , regs); -if (thread_info != exception_thread_info) -/* Restore current_thread_info lastly. */ -memcpy (exception_thread_info, backup_current_thread_info,sizeof *thread_info); -return 1 ; }
arch/powerpc/kernel/machine_kexec_64.c +2 -4
@@ -317,10 +317,8 @@ void default_machine_kexec(struct kimage *image)* We setup preempt_count to avoid using VMX in memcpy. * XXX: the task struct will likely be invalid once we do the copy! */ - kexec_stack.thread_info.task =current_thread_info ()->task; - kexec_stack.thread_info.flags =0 ; - kexec_stack.thread_info.preempt_count =HARDIRQ_OFFSET ; - kexec_stack.thread_info.cpu =current_thread_info ()->cpu; +current_thread_info ()->flags =0 ; +current_thread_info ()->preempt_count =HARDIRQ_OFFSET ;/* We need a static PACA, too; copy this CPU's PACA over and switch to * it. Also poison per_cpu_offset and NULL lppaca to catch anyone using
arch/powerpc/kernel/setup-common.c +1 -1
@@ -939,7 +939,7 @@ void __init setup_arch(char **cmdline_p)/* Reserve large chunks of memory for use by CMA for KVM. */ kvm_cma_reserve (); -klp_init_thread_info (&init_thread_info); +klp_init_thread_info (&init_task.thread_info); init_mm.start_code = (unsigned long )_stext; init_mm.end_code = (unsigned long ) _etext;
arch/powerpc/kernel/setup_64.c +0 -21
@@ -691,24 +691,6 @@ void __init exc_lvl_early_init(void)#endif /* -* Emergency stacks are used for a range of things, from asynchronous -* NMIs (system reset, machine check) to synchronous, process context. -* We set preempt_count to zero, even though that isn't necessarily correct. To -* get the right value we'd need to copy it from the previous thread_info, but -* doing that might fault causing more problems. -* TODO: what to do with accounting? -*/ -static void emerg_stack_init_thread_info (struct thread_info *ti,int cpu) -{ - ti->task =NULL ; - ti->cpu = cpu; - ti->preempt_count =0 ; - ti->local_flags =0 ; - ti->flags =0 ; -klp_init_thread_info (ti); -} - -/* * Stack space used when we detect a bad kernel stack pointer, and * early in SMP boots before relocation is enabled. Exclusive emergency * stack for machine checks.
@@ -739,20 +721,17 @@ void __init emergency_stack_init(void) ti =alloc_stack (limit, i);memset (ti,0 ,THREAD_SIZE ); -emerg_stack_init_thread_info (ti, i); paca_ptrs[i]->emergency_sp = (void *)ti +THREAD_SIZE ;#ifdef CONFIG_PPC_BOOK3S_64 /* emergency stack for NMI exception handling. */ ti =alloc_stack (limit, i);memset (ti,0 ,THREAD_SIZE ); -emerg_stack_init_thread_info (ti, i); paca_ptrs[i]->nmi_emergency_sp = (void *)ti +THREAD_SIZE ;/* emergency stack for machine check exception handling. */ ti =alloc_stack (limit, i);memset (ti,0 ,THREAD_SIZE ); -emerg_stack_init_thread_info (ti, i); paca_ptrs[i]->mc_emergency_sp = (void *)ti +THREAD_SIZE ;#endif }
arch/powerpc/kernel/smp.c +1 -1
@@ -816,7 +816,7 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle) paca_ptrs[cpu]->kstack = (unsigned long )task_stack_page (idle) +THREAD_SIZE -STACK_FRAME_OVERHEAD ;#endif - ti->cpu = cpu; + idle->cpu = cpu; secondary_ti = current_set[cpu] = ti; }
Signature · 1 line
2.13.3
Re: [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
Quoted 11 lines · On Mon, 1 Oct 2018 12:30:23 +0000 (UTC) Christophe Leroy…
This patch activates
CONFIG_THREAD_INFO_IN_TASKwhich moves thethread_infointotask_struct.Moving
thread_infointotask_structhas the following advantages:
- It protectsthread_infofrom corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.This has the following consequences:
-thread_infois now located at the top oftask_struct.
"top"... I got confused for a minute thinking high address and wondering how you can change CURRENT_THREAD_INFO just to point to current :)
Quoted 33 lines
arch/powerpc/Makefile +6
-0@@ -422,3 +422,9 @@ checkbin: CLEAN_FILES += $(TOUT) +ifdef CONFIG_SMP +prepare: task_cpu_prepare + +task_cpu_prepare: prepare0 + $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TI_CPU") print $$3;}' include/generated/asm-offsets.h)) +endifarch/powerpc/include/asm/ptrace.h +1
-1@@ -120,7 +120,7 @@ extern int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data);#define current_pt_regs () \ - ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1) + ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)/* * We use the least-significant bit of the trap field to indicate * whether we have saved the full set of registers, or only a arch/powerpc/include/asm/smp.h +0
-0@@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);/* 32-bit */
arch/powerpc/include/asm/smp.h int is_cpu_dead(unsigned int cpu); · line 92
Quoted 10 lines
arch/powerpc/include/asm/smp.h +7
-1extern int smp_hw_index[]; -#define raw_smp_processor_id () (current_thread_info()->cpu) +/* +* This is particularly ugly: it appears we can't actually get the definition +* of task_struct here, but we need access to the CPU this task is running on. +* Instead of using task_struct we're using _TASK_CPU which is extracted from +* asm-offsets.h by kbuild to get the current processor ID. +*/ +#define raw_smp_processor_id () (*(unsigned int*)((void*)current + _TASK_CPU))
This is clever but yes ugly. Can't you include asm-offsets.h? riscv seems to.
I'm not 100% sure on kgdb and kexec stuff but I think it seems okay. Looks like a pretty nice cleanup too aside from the features it brings, thanks for working on it.
Re: [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
Le 03/10/2018 à 07:30, Nicholas Piggin a écrit :
Quoted 12 lines
Quoted 9 lines · On Mon, 1 Oct 2018 12:30:23 +0000 (UTC) Christophe Leroy…
This patch activates
CONFIG_THREAD_INFO_IN_TASKwhich moves thethread_infointotask_struct.Moving
thread_infointotask_structhas the following advantages:
- It protectsthread_infofrom corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.
Quoted 6 lines
Quoted 2 lines
This has the following consequences:
-thread_infois now located at the top oftask_struct."top"... I got confused for a minute thinking high address and wondering how you can change
CURRENT_THREAD_INFOjust to point to current :)
Would 'beginning' be less confusing ?
Quoted 38 lines
Quoted 38 lines
arch/powerpc/Makefile +6
-0@@ -422,3 +422,9 @@ checkbin: CLEAN_FILES += $(TOUT) +ifdef CONFIG_SMP +prepare: task_cpu_prepare + +task_cpu_prepare: prepare0 + $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TI_CPU") print $$3;}' include/generated/asm-offsets.h)) +endifarch/powerpc/include/asm/ptrace.h +1
-1@@ -120,7 +120,7 @@ extern int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data);#define current_pt_regs () \ - ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1) + ((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)/* * We use the least-significant bit of the trap field to indicate * whether we have saved the full set of registers, or only a arch/powerpc/include/asm/smp.h +0
-0@@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);/* 32-bit */ extern int smp_hw_index[];
Quoted 11 lines
arch/powerpc/include/asm/smp.h int is_cpu_dead(unsigned int cpu); · line 92
Quoted 8 lines
arch/powerpc/include/asm/smp.h +7
-1-#define raw_smp_processor_id () (current_thread_info()->cpu) +/* +* This is particularly ugly: it appears we can't actually get the definition +* of task_struct here, but we need access to the CPU this task is running on. +* Instead of using task_struct we're using _TASK_CPU which is extracted from +* asm-offsets.h by kbuild to get the current processor ID. +*/ +#define raw_smp_processor_id () (*(unsigned int*)((void*)current + _TASK_CPU))This is clever but yes ugly. Can't you include
asm-offsets.h? riscv seems to.
riscv has a clean asm-offsets.h . Our's defines constant with the same name as those defined in other headers which are included in C files. So including asm-offsets in C files does create conflicts like:
./include/generated/asm-offsets.h:71:0: warning: "TASK_SIZE" redefined
#define TASK_SIZE -2147483648 /* TASK_SIZE */./arch/powerpc/include/asm/processor.h:95:0: note: this is the location of the previous definition
#define TASK_SIZE (CONFIG_TASK_SIZE)
./include/generated/asm-offsets.h:98:0: warning: "NSEC_PER_SEC" redefined
#define NSEC_PER_SEC 1000000000 /* NSEC_PER_SEC */./include/linux/time64.h:36:0: note: this is the location of the previous definition
#define NSEC_PER_SEC 1000000000L
./arch/powerpc/include/asm/nohash/32/pgtable.h:34:0: warning: "PGD_TABLE_SIZE" redefined
#define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)./include/generated/asm-offsets.h:101:0: note: this is the location of the previous definition
#define PGD_TABLE_SIZE 256 /* PGD_TABLE_SIZE */
...
In v2, I had a patch to fix those redundancies (https://patchwork.ozlabs.org/patch/974363/) but I found it unconvenient.
Quoted 4 lines
I'm not 100% sure on kgdb and kexec stuff but I think it seems okay. Looks like a pretty nice cleanup too aside from the features it brings, thanks for working on it.
Thanks for reviewing it.
Quoted 3 lines
Reviewed-by Nicholas Piggin <[email protected]>
Christophe
Nicholas Piggin
reviewerRe: [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
Quoted 13 lines · On Wed, 3 Oct 2018 07:47:05 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:30, Nicholas Piggin a écrit :
Quoted 12 lines
Quoted 9 lines · On Mon, 1 Oct 2018 12:30:23 +0000 (UTC) Christophe Leroy…
This patch activates
CONFIG_THREAD_INFO_IN_TASKwhich moves thethread_infointotask_struct.Moving
thread_infointotask_structhas the following advantages:
- It protectsthread_infofrom corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This has the following consequences:
-thread_infois now located at the top oftask_struct."top"... I got confused for a minute thinking high address and wondering how you can change
CURRENT_THREAD_INFOjust to point to current :)Would 'beginning' be less confusing ?
Yes, good idea.
Quoted 32 lines
Quoted 4 lines
Quoted 4 lines
arch/powerpc/include/asm/smp.h +0
-0@@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);/* 32-bit */ extern int smp_hw_index[];Quoted 11 lines
arch/powerpc/include/asm/smp.h int is_cpu_dead(unsigned int cpu); · line 92
Quoted 8 lines
arch/powerpc/include/asm/smp.h +7
-1-#define raw_smp_processor_id () (current_thread_info()->cpu) +/* +* This is particularly ugly: it appears we can't actually get the definition +* of task_struct here, but we need access to the CPU this task is running on. +* Instead of using task_struct we're using _TASK_CPU which is extracted from +* asm-offsets.h by kbuild to get the current processor ID. +*/ +#define raw_smp_processor_id () (*(unsigned int*)((void*)current + _TASK_CPU))This is clever but yes ugly. Can't you include
asm-offsets.h? riscv seems to.riscv has a clean
asm-offsets.h. Our's defines constant with the same name as those defined in other headers which are included in C files. So including asm-offsets in C files does create conflicts like:
./include/generated/asm-offsets.h:71:0: warning: "TASK_SIZE" redefined
#defineTASK_SIZE-2147483648 /*TASK_SIZE*/./arch/powerpc/include/asm/processor.h:95:0: note: this is the location of the previous definition
#defineTASK_SIZE(CONFIG_TASK_SIZE)
./include/generated/asm-offsets.h:98:0: warning: "NSEC_PER_SEC" redefined
#defineNSEC_PER_SEC1000000000 /*NSEC_PER_SEC*/./include/linux/time64.h:36:0: note: this is the location of the previous definition
#defineNSEC_PER_SEC1000000000L
Quoted 8 lines
./arch/powerpc/include/asm/nohash/32/pgtable.h:34:0: warning:
"PGD_TABLE_SIZE" redefined
#definePGD_TABLE_SIZE(sizeof(pgd_t)<<PGD_INDEX_SIZE)./include/generated/asm-offsets.h:101:0: note: this is the location of the previous definition
#definePGD_TABLE_SIZE256 /*PGD_TABLE_SIZE*/...
Okay.
Quoted 3 lines
In v2, I had a patch to fix those redundancies
(https://patchwork.ozlabs.org/patch/974363/) but I found it unconvenient.
Because of merge conflicts, or you did not like the new names?
Thanks,
Nick
Re: [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
Le 03/10/2018 à 07:52, Nicholas Piggin a écrit :
Quoted 68 lines
Quoted 13 lines · On Wed, 3 Oct 2018 07:47:05 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:30, Nicholas Piggin a écrit :
Quoted 12 lines
Quoted 9 lines · On Mon, 1 Oct 2018 12:30:23 +0000 (UTC) Christophe Leroy…
This patch activates
CONFIG_THREAD_INFO_IN_TASKwhich moves thethread_infointotask_struct.Moving
thread_infointotask_structhas the following advantages:
- It protectsthread_infofrom corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This has the following consequences:
-thread_infois now located at the top oftask_struct."top"... I got confused for a minute thinking high address and wondering how you can change
CURRENT_THREAD_INFOjust to point to current :)Would 'beginning' be less confusing ?
Yes, good idea.
Quoted 32 lines
Quoted 4 lines
Quoted 4 lines
arch/powerpc/include/asm/smp.h +0
-0@@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);/* 32-bit */ extern int smp_hw_index[];Quoted 11 lines
arch/powerpc/include/asm/smp.h int is_cpu_dead(unsigned int cpu); · line 92
Quoted 8 lines
arch/powerpc/include/asm/smp.h +7
-1-#define raw_smp_processor_id () (current_thread_info()->cpu) +/* +* This is particularly ugly: it appears we can't actually get the definition +* of task_struct here, but we need access to the CPU this task is running on. +* Instead of using task_struct we're using _TASK_CPU which is extracted from +* asm-offsets.h by kbuild to get the current processor ID. +*/ +#define raw_smp_processor_id () (*(unsigned int*)((void*)current + _TASK_CPU))This is clever but yes ugly. Can't you include
asm-offsets.h? riscv seems to.riscv has a clean
asm-offsets.h. Our's defines constant with the same name as those defined in other headers which are included in C files. So including asm-offsets in C files does create conflicts like:
./include/generated/asm-offsets.h:71:0: warning: "TASK_SIZE" redefined
#defineTASK_SIZE-2147483648 /*TASK_SIZE*/./arch/powerpc/include/asm/processor.h:95:0: note: this is the location of the previous definition
#defineTASK_SIZE(CONFIG_TASK_SIZE)
./include/generated/asm-offsets.h:98:0: warning: "NSEC_PER_SEC" redefined
#defineNSEC_PER_SEC1000000000 /*NSEC_PER_SEC*/./include/linux/time64.h:36:0: note: this is the location of the previous definition
#defineNSEC_PER_SEC1000000000LQuoted 8 lines
./arch/powerpc/include/asm/nohash/32/pgtable.h:34:0: warning:
"PGD_TABLE_SIZE" redefined
#definePGD_TABLE_SIZE(sizeof(pgd_t)<<PGD_INDEX_SIZE)./include/generated/asm-offsets.h:101:0: note: this is the location of the previous definition
#definePGD_TABLE_SIZE256 /*PGD_TABLE_SIZE*/...
Quoted 7 lines
Okay.
Quoted 3 lines
In v2, I had a patch to fix those redundancies
(https://patchwork.ozlabs.org/patch/974363/) but I found it unconvenient.Because of merge conflicts, or you did not like the new names?
Both, because of the amount of changes it implies, and also because of the new names. I find it quite convenient to be able to use same names both in C and ASM. And I didn't want my serie to imply big-bangs in unrelated or not directly related topics.
Christophe
Quoted 4 lines
Thanks,
Nick
Nicholas Piggin
reviewerRe: [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
Quoted 72 lines · On Wed, 3 Oct 2018 08:04:49 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:52, Nicholas Piggin a écrit :
Quoted 71 lines
Quoted 13 lines · On Wed, 3 Oct 2018 07:47:05 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:30, Nicholas Piggin a écrit :
Quoted 12 lines
Quoted 9 lines · On Mon, 1 Oct 2018 12:30:23 +0000 (UTC) Christophe Leroy…
This patch activates
CONFIG_THREAD_INFO_IN_TASKwhich moves thethread_infointotask_struct.Moving
thread_infointotask_structhas the following advantages:
- It protectsthread_infofrom corruption in the case of stack overflows.
- Its address is harder to determine if stack addresses are leaked, making a number of attacks more difficult.Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This has the following consequences:
-thread_infois now located at the top oftask_struct."top"... I got confused for a minute thinking high address and wondering how you can change
CURRENT_THREAD_INFOjust to point to current :)Would 'beginning' be less confusing ?
Yes, good idea.
Quoted 32 lines
Quoted 4 lines
Quoted 4 lines
arch/powerpc/include/asm/smp.h +0
-0@@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);/* 32-bit */ extern int smp_hw_index[];Quoted 11 lines
arch/powerpc/include/asm/smp.h int is_cpu_dead(unsigned int cpu); · line 92
Quoted 8 lines
arch/powerpc/include/asm/smp.h +7
-1-#define raw_smp_processor_id () (current_thread_info()->cpu) +/* +* This is particularly ugly: it appears we can't actually get the definition +* of task_struct here, but we need access to the CPU this task is running on. +* Instead of using task_struct we're using _TASK_CPU which is extracted from +* asm-offsets.h by kbuild to get the current processor ID. +*/ +#define raw_smp_processor_id () (*(unsigned int*)((void*)current + _TASK_CPU))This is clever but yes ugly. Can't you include
asm-offsets.h? riscv seems to.riscv has a clean
asm-offsets.h. Our's defines constant with the same name as those defined in other headers which are included in C files. So including asm-offsets in C files does create conflicts like:
./include/generated/asm-offsets.h:71:0: warning: "TASK_SIZE" redefined
#defineTASK_SIZE-2147483648 /*TASK_SIZE*/./arch/powerpc/include/asm/processor.h:95:0: note: this is the location of the previous definition
#defineTASK_SIZE(CONFIG_TASK_SIZE)
./include/generated/asm-offsets.h:98:0: warning: "NSEC_PER_SEC" redefined
#defineNSEC_PER_SEC1000000000 /*NSEC_PER_SEC*/./include/linux/time64.h:36:0: note: this is the location of the previous definition
#defineNSEC_PER_SEC1000000000LQuoted 8 lines
./arch/powerpc/include/asm/nohash/32/pgtable.h:34:0: warning:
"PGD_TABLE_SIZE" redefined
#definePGD_TABLE_SIZE(sizeof(pgd_t)<<PGD_INDEX_SIZE)./include/generated/asm-offsets.h:101:0: note: this is the location of the previous definition
#definePGD_TABLE_SIZE256 /*PGD_TABLE_SIZE*/...
Okay.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
In v2, I had a patch to fix those redundancies
(https://patchwork.ozlabs.org/patch/974363/) but I found it unconvenient.Because of merge conflicts, or you did not like the new names?
Both, because of the amount of changes it implies, and also because of the new names. I find it quite convenient to be able to use same names both in C and ASM.
Yeah that's true. I guess this is okay for a one-off hack.
Thanks,
Nick
RFC PATCH v3 4/7 powerpc: regain entire stack space
In reply to Christophe Leroythread_info is not anymore in the stack, so the entire stack can now be used.
In the meantime, all pointers to the stacks are not anymore pointers to thread_info so this patch changes them to void*
--- arch/powerpc/include/asm/irq.h | 10 +++++----- arch/powerpc/include/asm/processor.h | 3 +-- arch/powerpc/kernel/asm-offsets.c | 1 - arch/powerpc/kernel/entry_32.S | 14 ++++---------- arch/powerpc/kernel/irq.c | 19 +++++++++---------- arch/powerpc/kernel/misc_32.S | 6 ++---- arch/powerpc/kernel/process.c | 9 +++------ arch/powerpc/kernel/setup_64.c | 8 ++++---- 8 files changed, 28 insertions(+), 42 deletions(-)
arch/powerpc/include/asm/irq.h +5 -5
@@ -48,9 +48,9 @@ struct pt_regs;* Per-cpu stacks for handling critical, debug and machine check * level interrupts. */ -extern struct thread_info *critirq_ctx[NR_CPUS ]; -extern struct thread_info *dbgirq_ctx[NR_CPUS ]; -extern struct thread_info *mcheckirq_ctx[NR_CPUS ]; +extern void *critirq_ctx[NR_CPUS ]; +extern void *dbgirq_ctx[NR_CPUS ]; +extern void *mcheckirq_ctx[NR_CPUS ];extern void exc_lvl_ctx_init (void );#else #define exc_lvl_ctx_init ()
@@ -59,8 +59,8 @@ extern void exc_lvl_ctx_init(void);/* * Per-cpu stacks for handling hard and soft interrupts. */ -extern struct thread_info *hardirq_ctx[NR_CPUS ]; -extern struct thread_info *softirq_ctx[NR_CPUS ]; +extern void *hardirq_ctx[NR_CPUS ]; +extern void *softirq_ctx[NR_CPUS ];extern void irq_ctx_init (void );extern void call_do_softirq (void *tp);
arch/powerpc/include/asm/processor.h +1 -2
@@ -332,8 +332,7 @@ struct thread_struct {#define ARCH_MIN_TASKALIGN 16#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack) -#define INIT_SP_LIMIT \ - (_ALIGN_UP(sizeof(struct thread_info), 16) + (unsigned long) &init_stack) +#define INIT_SP_LIMIT ((unsigned long) &init_stack)#ifdef CONFIG_SPE #define SPEFSCR_INIT \
arch/powerpc/kernel/asm-offsets.c +0 -1
@@ -85,7 +85,6 @@ int main(void)DEFINE (NMI_MASK ,NMI_MASK );OFFSET (TASKTHREADPPR , task_struct, thread.ppr);#else -DEFINE (THREAD_INFO_GAP ,_ALIGN_UP (sizeof (struct thread_info ),16 ));OFFSET (KSP_LIMIT , thread_struct, ksp_limit);#endif /* CONFIG_PPC64 */ OFFSET (TASK_STACK , task_struct, stack);
arch/powerpc/kernel/entry_32.S +4 -10
@@ -97,14 +97,11 @@ crit_transfer_to_handler: mfspr r0,SPRN_SRR1 stw r0,_SRR1(r11) - /* set the stack limit to the current stack - * and set the limit to protect the thread_info - * struct - */ + /* set the stack limit to the current stack */ mfspr r8,SPRN_SPRG_THREAD lwz r0,KSP_LIMIT(r8) stw r0,SAVED_KSP_LIMIT(r11) - rlwimi r0,r1,0,0,(31-THREAD_SHIFT) + rlwinm r0,r1,0,0,(31 - THREAD_SHIFT) stw r0,KSP_LIMIT(r8) /* fall through */ #endif
@@ -121,14 +118,11 @@ crit_transfer_to_handler: mfspr r0,SPRN_SRR1 stw r0,crit_srr1@l(0) - /* set the stack limit to the current stack - * and set the limit to protect the thread_info - * struct - */ + /* set the stack limit to the current stack */ 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) + rlwinm r0,r1,0,0,(31 - THREAD_SHIFT) stw r0,KSP_LIMIT(r8) /* fall through */ #endif
arch/powerpc/kernel/irq.c +9 -10
@@ -618,9 +618,8 @@ static inline void check_stack_overflow(void) sp =current_stack_pointer () & (THREAD_SIZE -1 );/* check for stack overflow: is there less than 2KB free? */ -if (unlikely (sp < (sizeof (struct thread_info ) +2048 ))) { -pr_err ("do_IRQ: stack overflow: %ld\n" , - sp -sizeof (struct thread_info )); +if (unlikely (sp <2048 )) { +pr_err ("do_IRQ: stack overflow: %ld\n" , sp);dump_stack (); }#endif
@@ -660,7 +659,7 @@ void __do_irq(struct pt_regs *regs)void do_IRQ (struct pt_regs *regs) {struct pt_regs *old_regs =set_irq_regs (regs); -struct thread_info *curtp, *irqtp, *sirqtp; +void *curtp, *irqtp, *sirqtp;/* Switch to the irq stack to handle this */ curtp = (void *)(current_stack_pointer () & ~(THREAD_SIZE -1 ));
@@ -690,9 +689,9 @@ void __init init_IRQ(void) }#if defined(CONFIG_BOOKE ) || defined(CONFIG_40x) -struct thread_info *critirq_ctx[NR_CPUS ]__read_mostly ; -struct thread_info *dbgirq_ctx[NR_CPUS ]__read_mostly ; -struct thread_info *mcheckirq_ctx[NR_CPUS ]__read_mostly ; +void *critirq_ctx[NR_CPUS ]__read_mostly ; +void *dbgirq_ctx[NR_CPUS ]__read_mostly ; +void *mcheckirq_ctx[NR_CPUS ]__read_mostly ;void exc_lvl_ctx_init (void ) {
@@ -718,8 +717,8 @@ void exc_lvl_ctx_init(void) }#endif -struct thread_info *softirq_ctx[NR_CPUS ]__read_mostly ; -struct thread_info *hardirq_ctx[NR_CPUS ]__read_mostly ; +void *softirq_ctx[NR_CPUS ]__read_mostly ; +void *hardirq_ctx[NR_CPUS ]__read_mostly ;void irq_ctx_init (void ) {
@@ -733,7 +732,7 @@ void irq_ctx_init(void)void do_softirq_own_stack (void ) { -struct thread_info *irqtp; +void *irqtp; irqtp = softirq_ctx[smp_processor_id ()];call_do_softirq (irqtp);
arch/powerpc/kernel/misc_32.S +2 -4
@@ -46,11 +46,10 @@ _GLOBAL(call_do_softirq) mflr r0 stw r0,4(r1) lwz r10,THREAD+KSP_LIMIT(r2) - addi r11,r3,THREAD_INFO_GAP + stw r3, THREAD+KSP_LIMIT(r2) stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3) mr r1,r3 stw r10,8(r1) - stw r11,THREAD+KSP_LIMIT(r2) bl __do_softirq lwz r10,8(r1) lwz r1,0(r1)
@@ -66,11 +65,10 @@ _GLOBAL(call_do_irq) mflr r0 stw r0,4(r1) lwz r10,THREAD+KSP_LIMIT(r2) - addi r11,r4,THREAD_INFO_GAP + stw r4, THREAD+KSP_LIMIT(r2) stwu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r4) mr r1,r4 stw r10,8(r1) - stw r11,THREAD+KSP_LIMIT(r2) bl __do_irq lwz r10,8(r1) lwz r1,0(r1)
arch/powerpc/kernel/process.c +3 -6
@@ -1691,8 +1691,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, sp -=STACK_FRAME_OVERHEAD ; p->thread.ksp = sp;#ifdef CONFIG_PPC32 - p->thread.ksp_limit = (unsigned long )task_stack_page (p) + -_ALIGN_UP (sizeof (struct thread_info ),16 ); + p->thread.ksp_limit = (unsigned long )task_stack_page (p);#endif #ifdef CONFIG_HAVE_HW_BREAKPOINT p->thread.ptrace_bps[0 ] =NULL ;
@@ -2001,13 +2000,11 @@ static inline int valid_irq_stack(unsigned long sp, struct task_struct *p,*/ if (cpu <NR_CPUS &&cpu_possible (cpu)) { stack_page = (unsigned long ) hardirq_ctx[cpu]; -if (sp >= stack_page +sizeof (struct thread_struct ) - && sp <= stack_page +THREAD_SIZE - nbytes) +if (sp >= stack_page && sp <= stack_page +THREAD_SIZE - nbytes)return 1 ; stack_page = (unsigned long ) softirq_ctx[cpu]; -if (sp >= stack_page +sizeof (struct thread_struct ) - && sp <= stack_page +THREAD_SIZE - nbytes) +if (sp >= stack_page && sp <= stack_page +THREAD_SIZE - nbytes)return 1 ; }return 0 ;
arch/powerpc/kernel/setup_64.c +4 -4
@@ -717,22 +717,22 @@ void __init emergency_stack_init(void) limit =min (ppc64_bolted_size (), ppc64_rma_size);for_each_possible_cpu (i) { -struct thread_info *ti; +void *ti; ti =alloc_stack (limit, i);memset (ti,0 ,THREAD_SIZE ); - paca_ptrs[i]->emergency_sp = (void *)ti +THREAD_SIZE ; + paca_ptrs[i]->emergency_sp = ti +THREAD_SIZE ;#ifdef CONFIG_PPC_BOOK3S_64 /* emergency stack for NMI exception handling. */ ti =alloc_stack (limit, i);memset (ti,0 ,THREAD_SIZE ); - paca_ptrs[i]->nmi_emergency_sp = (void *)ti +THREAD_SIZE ; + paca_ptrs[i]->nmi_emergency_sp = ti +THREAD_SIZE ;/* emergency stack for machine check exception handling. */ ti =alloc_stack (limit, i);memset (ti,0 ,THREAD_SIZE ); - paca_ptrs[i]->mc_emergency_sp = (void *)ti +THREAD_SIZE ; + paca_ptrs[i]->mc_emergency_sp = ti +THREAD_SIZE ;#endif } }
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerRe: [RFC PATCH v3 4/7] powerpc: regain entire stack space
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:25 +0000 (UTC) Christophe Leroy…
thread_infois not anymore in the stack, so the entire stack can now be used.
Nice.
Quoted 3 lines
In the meantime, all pointers to the stacks are not anymore pointers to
thread_infoso this patch changes them to void*
Wasn't this previously effectively already the case with patch 3/7? You had thread_info sized space left there, but it was not used or initialized right? Does it make sense to move this part of it to the previous patch?
Thanks,
Nick
Re: [RFC PATCH v3 4/7] powerpc: regain entire stack space
Le 03/10/2018 à 07:34, Nicholas Piggin a écrit :
Quoted 9 lines
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:25 +0000 (UTC) Christophe Leroy…
thread_infois not anymore in the stack, so the entire stack can now be used.Nice.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
In the meantime, all pointers to the stacks are not anymore pointers to
thread_infoso this patch changes them to void*Wasn't this previously effectively already the case with patch 3/7? You had
thread_infosized space left there, but it was not used or initialized right? Does it make sense to move this part of it to the previous patch?
Not really.
In 3/7 I changed the prototypes of two functions that really used the pointer as a task pointer only.
Here it change things that before 4/7 were really used as both stack pointers and thread_info pointers.
Christophe
Quoted 4 lines
Thanks,
Nick
Nicholas Piggin
reviewerRe: [RFC PATCH v3 4/7] powerpc: regain entire stack space
Quoted 18 lines · On Wed, 3 Oct 2018 07:52:59 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:34, Nicholas Piggin a écrit :
Quoted 9 lines
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:25 +0000 (UTC) Christophe Leroy…
thread_infois not anymore in the stack, so the entire stack can now be used.Nice.
Quoted 1 line
Quoted 7 lines
Quoted 2 lines
In the meantime, all pointers to the stacks are not anymore pointers to
thread_infoso this patch changes them to void*Wasn't this previously effectively already the case with patch 3/7? You had
thread_infosized space left there, but it was not used or initialized right? Does it make sense to move this part of it to the previous patch?
Quoted 7 lines
Not really.
In 3/7 I changed the prototypes of two functions that really used the pointer as a task pointer only.
Here it change things that before 4/7 were really used as both stack pointers and
thread_infopointers.
What uses it as a thread_info pointer? It seems more like a stack with some amount of unused space in it but that's all.
That said I don't care to nitpick too much where things go exactly if you like it better here that's fine.
Thanks,
Nick
Re: [RFC PATCH v3 4/7] powerpc: regain entire stack space
Le 03/10/2018 à 08:30, Nicholas Piggin a écrit :
Quoted 21 lines
Quoted 18 lines · On Wed, 3 Oct 2018 07:52:59 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:34, Nicholas Piggin a écrit :
Quoted 16 lines
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:25 +0000 (UTC) Christophe Leroy…
thread_infois not anymore in the stack, so the entire stack can now be used.Nice.
Quoted 3 lines
In the meantime, all pointers to the stacks are not anymore pointers to
thread_infoso this patch changes them to void*Wasn't this previously effectively already the case with patch 3/7? You had
thread_infosized space left there, but it was not used or initialized right? Does it make sense to move this part of it to the previous patch?
Quoted 4 lines
Quoted 4 lines
Not really.
In 3/7 I changed the prototypes of two functions that really used the pointer as a task pointer only.
I meant 2/7 here sorry.
Quoted 3 lines
Quoted 3 lines
Here it change things that before 4/7 were really used as both stack pointers and
thread_infopointers.
And here I meant 3/7
Quoted 3 lines
What uses it as a
thread_infopointer? It seems more like a stack with some amount of unused space in it but that's all.
Before 3/7, we have
void do_softirq_own_stack(void)
{
struct thread_info *curtp, *irqtp;
curtp = current_thread_info();
irqtp = softirq_ctx[smp_processor_id()];
irqtp->task = curtp->task;
irqtp->flags = 0;
call_do_softirq(irqtp);
irqtp->task = NULL;
/* Set any flag that may have been set on the
* alternate stack
*/
if (irqtp->flags)
set_bits(irqtp->flags, &curtp->flags);
}After 3/7, we have
void do_softirq_own_stack(void)
{
struct thread_info *irqtp; irqtp = softirq_ctx[smp_processor_id()];
call_do_softirq(irqtp);
}
So now only we can change irqtp to void* can't we ?
Quoted 3 lines
That said I don't care to nitpick too much where things go exactly if you like it better here that's fine.
No worry, I may have missed something, your comments are always welcome.
Thanks
Christophe
Quoted 4 lines
Thanks,
Nick
Nicholas Piggin
reviewerRe: [RFC PATCH v3 4/7] powerpc: regain entire stack space
Quoted 65 lines · On Wed, 3 Oct 2018 08:45:25 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 08:30, Nicholas Piggin a écrit :
Quoted 21 lines
Quoted 18 lines · On Wed, 3 Oct 2018 07:52:59 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:34, Nicholas Piggin a écrit :
Quoted 16 lines
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:25 +0000 (UTC) Christophe Leroy…
thread_infois not anymore in the stack, so the entire stack can now be used.Nice.
Quoted 3 lines
In the meantime, all pointers to the stacks are not anymore pointers to
thread_infoso this patch changes them to void*Wasn't this previously effectively already the case with patch 3/7? You had
thread_infosized space left there, but it was not used or initialized right? Does it make sense to move this part of it to the previous patch?Quoted 4 lines
Quoted 4 lines
Not really.
In 3/7 I changed the prototypes of two functions that really used the pointer as a task pointer only.
I meant 2/7 here sorry.
Quoted 3 lines
Quoted 3 lines
Here it change things that before 4/7 were really used as both stack pointers and
thread_infopointers.And here I meant 3/7
Quoted 3 lines
What uses it as a
thread_infopointer? It seems more like a stack with some amount of unused space in it but that's all.Before 3/7, we have
void
do_softirq_own_stack(void){ struct thread_info *curtp, *irqtp; curtp = current_thread_info(); irqtp = softirq_ctx[smp_processor_id()]; irqtp->task = curtp->task; irqtp->flags = 0; call_do_softirq(irqtp); irqtp->task = NULL; /* Set any flag that may have been set on the * alternate stack */ if (irqtp->flags) set_bits(irqtp->flags, &curtp->flags); }After 3/7, we have
void
do_softirq_own_stack(void){ struct thread_info *irqtp;
Quoted 6 lines
irqtp = softirq_ctx[smp_processor_id()]; call_do_softirq(irqtp); }So now only we can change irqtp to void* can't we ?
In patch 3 we can, right? That's what I mean by moving from thread_info * to void * in patch 3 rather than 4.
But if you prefer not to, it's fine. Maybe it keeps patch 3 a little smaller.
Thanks,
Nick
Re: [RFC PATCH v3 4/7] powerpc: regain entire stack space
Le 03/10/2018 à 09:07, Nicholas Piggin a écrit :
Quoted 73 lines
Quoted 70 lines · On Wed, 3 Oct 2018 08:45:25 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 08:30, Nicholas Piggin a écrit :
Quoted 21 lines
Quoted 18 lines · On Wed, 3 Oct 2018 07:52:59 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:34, Nicholas Piggin a écrit :
Quoted 16 lines
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:25 +0000 (UTC) Christophe Leroy…
thread_infois not anymore in the stack, so the entire stack can now be used.Nice.
Quoted 3 lines
In the meantime, all pointers to the stacks are not anymore pointers to
thread_infoso this patch changes them to void*Wasn't this previously effectively already the case with patch 3/7? You had
thread_infosized space left there, but it was not used or initialized right? Does it make sense to move this part of it to the previous patch?Quoted 4 lines
Quoted 4 lines
Not really.
In 3/7 I changed the prototypes of two functions that really used the pointer as a task pointer only.
I meant 2/7 here sorry.
Quoted 3 lines
Quoted 3 lines
Here it change things that before 4/7 were really used as both stack pointers and
thread_infopointers.And here I meant 3/7
Quoted 3 lines
What uses it as a
thread_infopointer? It seems more like a stack with some amount of unused space in it but that's all.Before 3/7, we have
void
do_softirq_own_stack(void){ struct thread_info *curtp, *irqtp; curtp = current_thread_info(); irqtp = softirq_ctx[smp_processor_id()]; irqtp->task = curtp->task; irqtp->flags = 0; call_do_softirq(irqtp); irqtp->task = NULL; /* Set any flag that may have been set on the * alternate stack */ if (irqtp->flags) set_bits(irqtp->flags, &curtp->flags); }After 3/7, we have
void do_softirq_own_stack(void) { struct thread_info *irqtp; irqtp = softirq_ctx[smp_processor_id()]; call_do_softirq(irqtp); }
Quoted 4 lines
Quoted 1 line
So now only we can change irqtp to void* can't we ?
In patch 3 we can, right? That's what I mean by moving from
thread_info* to void * in patch 3 rather than 4.
Ah ok, that's what you meant. Sorry.
Quoted 3 lines
But if you prefer not to, it's fine. Maybe it keeps patch 3 a little smaller.
Yes indeed, that's the idea, keep patch 3 to the strict minimum and do cleanups afterwards.
Christophe
Quoted 4 lines
Thanks,
Nick
RFC PATCH v3 5/7 powerpc: 'current_set' is now a table of task_struct pointers
In reply to Christophe LeroyThe table of pointers 'current_set' has been used for retrieving the stack and current. They used to be thread_info pointers as they were pointing to the stack and current was taken from the 'task' field of the thread_info.
Now, the pointers of 'current_set' table are now both pointers to task_struct and pointers to thread_info.
As they are used to get current, and the stack pointer is retrieved from current's stack field, this patch changes their type to task_struct, and renames secondary_ti to secondary_current.
--- arch/powerpc/include/asm/asm-prototypes.h | 4 ++-- arch/powerpc/kernel/head_32.S | 6 +++--- arch/powerpc/kernel/head_44x.S | 4 ++-- arch/powerpc/kernel/head_fsl_booke.S | 4 ++-- arch/powerpc/kernel/smp.c | 10 ++++------ 5 files changed, 13 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/asm-prototypes.h +2 -2
@@ -23,8 +23,8 @@#include <uapi/asm/ucontext.h> /* SMP */ -extern struct thread_info *current_set[NR_CPUS ]; -extern struct thread_info *secondary_ti; +extern struct task_struct *current_set[NR_CPUS ]; +extern struct task_struct *secondary_current;void start_secondary (void *unused);/* kexec */
arch/powerpc/kernel/head_32.S +3 -3
@@ -842,9 +842,9 @@ __secondary_start: #endif /* CONFIG_6xx */ /* get current's stack and current */ - lis r1,secondary_ti@ha - tophys(r1,r1) - lwz r2,secondary_ti@l(r1) + lis r2,secondary_current@ha + tophys(r2,r2) + lwz r2,secondary_current@l(r2) tophys(r1,r2) lwz r1,TASK_STACK(r1)
arch/powerpc/kernel/head_44x.S +2 -2
@@ -1021,8 +1021,8 @@ _GLOBAL(start_secondary_47x) /* Now we can get our task struct and real stack pointer */ /* Get current's stack and current */ - lis r1,secondary_ti@ha - lwz r2,secondary_ti@l(r1) + lis r2,secondary_current@ha + lwz r2,secondary_current@l(r2) lwz r1,TASK_STACK(r2) /* Current stack pointer */
arch/powerpc/kernel/head_fsl_booke.S +2 -2
@@ -1076,8 +1076,8 @@ __secondary_start: bl call_setup_cpu /* get current's stack and current */ - lis r1,secondary_ti@ha - lwz r2,secondary_ti@l(r1) + lis r2,secondary_current@ha + lwz r2,secondary_current@l(r2) lwz r1,TASK_STACK(r2) /* stack */
arch/powerpc/kernel/smp.c +4 -6
@@ -74,7 +74,7 @@ static DEFINE_PER_CPU(int, cpu_state) = { 0 };#endif -struct thread_info *secondary_ti; +struct task_struct *secondary_current;DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map);DEFINE_PER_CPU (cpumask_var_t, cpu_l2_cache_map);
@@ -644,7 +644,7 @@ void smp_send_stop(void) }#endif /* CONFIG_NMI_IPI */ -struct thread_info *current_set[NR_CPUS ]; +struct task_struct *current_set[NR_CPUS ];static void smp_store_cpu_info (int id) {
@@ -724,7 +724,7 @@ void smp_prepare_boot_cpu(void) paca_ptrs[boot_cpuid]->__current = current;#endif set_numa_node (numa_cpu_lookup_table[boot_cpuid]); - current_set[boot_cpuid] =task_thread_info (current); + current_set[boot_cpuid] = current; }#ifdef CONFIG_HOTPLUG_CPU
@@ -809,15 +809,13 @@ static bool secondaries_inhibited(void)static void cpu_idle_thread_init (unsigned int cpu,struct task_struct *idle) { -struct thread_info *ti =task_thread_info (idle); -#ifdef CONFIG_PPC64 paca_ptrs[cpu]->__current = idle; paca_ptrs[cpu]->kstack = (unsigned long )task_stack_page (idle) +THREAD_SIZE -STACK_FRAME_OVERHEAD ;#endif idle->cpu = cpu; - secondary_ti = current_set[cpu] = ti; + secondary_current = current_set[cpu] = idle; }int __cpu_up (unsigned int cpu,struct task_struct *tidle)
Signature · 1 line
2.13.3
Re: [RFC PATCH v3 5/7] powerpc: 'current_set' is now a table of task_struct pointers
Quoted 5 lines · On Mon, 1 Oct 2018 12:30:27 +0000 (UTC) Christophe Leroy…
The table of pointers '
current_set' has been used for retrieving the stack and current. They used to bethread_infopointers as they were pointing to the stack and current was taken from the 'task' field of thethread_info.
Quoted 7 lines
Now, the pointers of '
current_set' table are now both pointers totask_structand pointers tothread_info.As they are used to get current, and the stack pointer is retrieved from current's stack field, this patch changes their type to
task_struct, and renamessecondary_titosecondary_current.
I'm not sure if current_set is actually needed is it? Because 64-bit already initializes paca->ksave / PACAKSAVE. That might be a cleanup to do after your series.
Re: [RFC PATCH v3 5/7] powerpc: 'current_set' is now a table of task_struct pointers
Le 03/10/2018 à 07:41, Nicholas Piggin a écrit :
Quoted 11 lines
Quoted 8 lines · On Mon, 1 Oct 2018 12:30:27 +0000 (UTC) Christophe Leroy…
The table of pointers '
current_set' has been used for retrieving the stack and current. They used to bethread_infopointers as they were pointing to the stack and current was taken from the 'task' field of thethread_info.Now, the pointers of '
current_set' table are now both pointers totask_structand pointers tothread_info.
Quoted 8 lines
Quoted 4 lines
As they are used to get current, and the stack pointer is retrieved from current's stack field, this patch changes their type to
task_struct, and renamessecondary_titosecondary_current.I'm not sure if
current_setis actually needed is it? Because 64-bit already initializespaca->ksave/ PACAKSAVE. That might be a cleanup to do after your series.
head_64.S contains:
__secondary_start:
/* Set thread priority to MEDIUM */ HMT_MEDIUM /* Initialize the kernel stack */ LOAD_REG_ADDR(r3, current_set) sldi r28,r24,3 /* get current_set[cpu#] */ ldx r14,r3,r28 addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD std r14,PACAKSAVE(r13)
32-bit doesn't seem to use it, it only uses secondary_ti it seems.
Quoted 3 lines
Reviewed-by Nicholas Piggin <[email protected]>
Christophe
Nicholas Piggin
reviewerRe: [RFC PATCH v3 5/7] powerpc: 'current_set' is now a table of task_struct pointers
Quoted 24 lines · On Wed, 3 Oct 2018 08:00:43 +0200 Christophe LEROY <[email protected]>…
Le 03/10/2018 à 07:41, Nicholas Piggin a écrit :
Quoted 11 lines
Quoted 8 lines · On Mon, 1 Oct 2018 12:30:27 +0000 (UTC) Christophe Leroy…
The table of pointers '
current_set' has been used for retrieving the stack and current. They used to bethread_infopointers as they were pointing to the stack and current was taken from the 'task' field of thethread_info.Now, the pointers of '
current_set' table are now both pointers totask_structand pointers tothread_info.Quoted 8 lines
Quoted 4 lines
As they are used to get current, and the stack pointer is retrieved from current's stack field, this patch changes their type to
task_struct, and renamessecondary_titosecondary_current.I'm not sure if
current_setis actually needed is it? Because 64-bit already initializespaca->ksave/ PACAKSAVE. That might be a cleanup to do after your series.
head_64.Scontains:
__secondary_start:
Quoted 9 lines
/* Set thread priority to MEDIUM */ HMT_MEDIUM /* Initialize the kernel stack */ LOAD_REG_ADDR(r3, current_set) sldi r28,r24,3 /* get current_set[cpu#] */ ldx r14,r3,r28 addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD std r14,PACAKSAVE(r13)
Right, I don't *think* that's needed because boot CPU should already have set PACAKSAVE before starting secondaries here. ld r14,PACAKSAVE should have the same result I think.
But never mind that for your series, just something I saw that could be cleaned up.
Thanks,
Nick
RFC PATCH v3 6/7 powerpc/32: Remove CURRENT_THREAD_INFO and rename TI_CPU
In reply to Christophe LeroyNow that thread_info is similar to task_struct, it's address is in r2 so CURRENT_THREAD_INFO() macro is useless. This patch removes it.
At the same time, as the 'cpu' field is not anymore in thread_info, this patch renames it to TASK_CPU.
--- arch/powerpc/Makefile | 2 +- arch/powerpc/include/asm/thread_info.h | 2 -- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/entry_32.S | 43 ++++++++++++---------------------- arch/powerpc/kernel/epapr_hcalls.S | 5 ++-- arch/powerpc/kernel/head_fsl_booke.S | 5 ++-- arch/powerpc/kernel/idle_6xx.S | 8 +++---- arch/powerpc/kernel/idle_e500.S | 8 +++---- arch/powerpc/kernel/misc_32.S | 3 +-- arch/powerpc/mm/hash_low_32.S | 14 ++++------- arch/powerpc/sysdev/6xx-suspend.S | 5 ++-- 11 files changed, 35 insertions(+), 62 deletions(-)
arch/powerpc/Makefile +1 -1
@@ -426,5 +426,5 @@ ifdef CONFIG_SMP prepare: task_cpu_prepare task_cpu_prepare: prepare0 - $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TI_CPU") print $$3;}' include/generated/asm-offsets.h)) + $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TASK_CPU") print $$3;}' include/generated/asm-offsets.h)) endif
arch/powerpc/include/asm/thread_info.h +0 -2
@@ -19,8 +19,6 @@#ifdef CONFIG_PPC64 #define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(ld dest, PACACURRENT(r13)) -#else -#define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(mr dest, r2)#endif #ifndef __ASSEMBLY__
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -89,7 +89,7 @@ int main(void)#endif /* CONFIG_PPC64 */ OFFSET (TASK_STACK , task_struct, stack);#ifdef CONFIG_SMP -OFFSET (TI_CPU , task_struct, cpu); +OFFSET (TASK_CPU , task_struct, cpu);#endif #ifdef CONFIG_LIVEPATCH
arch/powerpc/kernel/entry_32.S +15 -28
144 lines not on this page · raw message
arch/powerpc/kernel/epapr_hcalls.S +2 -3
@@ -21,10 +21,9 @@ #ifndef CONFIG_PPC64 /* epapr_ev_idle() was derived from e500_idle() */ _GLOBAL(epapr_ev_idle) - CURRENT_THREAD_INFO(r3, r1) - PPC_LL r4, TI_LOCAL_FLAGS(r3) /* set napping bit */ + PPC_LL r4, TI_LOCAL_FLAGS(r2) /* set napping bit */ ori r4, r4,_TLF_NAPPING /* so when we take an exception */ - PPC_STL r4, TI_LOCAL_FLAGS(r3) /* it will return to our caller */ + PPC_STL r4, TI_LOCAL_FLAGS(r2) /* it will return to our caller */ wrteei 1
arch/powerpc/kernel/head_fsl_booke.S +2 -3
@@ -244,8 +244,7 @@ set_ivor: stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) #ifdef CONFIG_SMP - CURRENT_THREAD_INFO(r22, r1) - stw r24, TI_CPU(r22) + stw r24, TASK_CPU(r2) #endif bl early_init
@@ -704,7 +703,7 @@ finish_tlb_load: /* Get the next_tlbcam_idx percpu var */ #ifdef CONFIG_SMP - lwz r15, TI_CPU-THREAD(r12) + lwz r15, TASK_CPU-THREAD(r12) lis r14, __per_cpu_offset@h ori r14, r14, __per_cpu_offset@l rlwinm r15, r15, 2, 0, 29
arch/powerpc/kernel/idle_6xx.S +3 -5
@@ -136,10 +136,9 @@ BEGIN_FTR_SECTION DSSALL sync END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) - CURRENT_THREAD_INFO(r9, r1) - lwz r8,TI_LOCAL_FLAGS(r9) /* set napping bit */ + lwz r8,TI_LOCAL_FLAGS(r2) /* set napping bit */ ori r8,r8,_TLF_NAPPING /* so when we take an exception */ - stw r8,TI_LOCAL_FLAGS(r9) /* it will return to our caller */ + stw r8,TI_LOCAL_FLAGS(r2) /* it will return to our caller */ mfmsr r7 ori r7,r7,MSR_EE oris r7,r7,MSR_POW@h
@@ -159,8 +158,7 @@ _GLOBAL(power_save_ppc32_restore) stw r9,_NIP(r11) /* make it do a blr */ #ifdef CONFIG_SMP - CURRENT_THREAD_INFO(r12, r11) - lwz r11,TI_CPU(r12) /* get cpu number * 4 */ + lwz r11,TASK_CPU(r2) /* get cpu number * 4 */ slwi r11,r11,2 #else li r11,0
arch/powerpc/kernel/idle_e500.S +3 -5
@@ -22,10 +22,9 @@ .text _GLOBAL(e500_idle) - CURRENT_THREAD_INFO(r3, r1) - lwz r4,TI_LOCAL_FLAGS(r3) /* set napping bit */ + lwz r4,TI_LOCAL_FLAGS(r2) /* set napping bit */ ori r4,r4,_TLF_NAPPING /* so when we take an exception */ - stw r4,TI_LOCAL_FLAGS(r3) /* it will return to our caller */ + stw r4,TI_LOCAL_FLAGS(r2) /* it will return to our caller */ #ifdef CONFIG_PPC_E500MC wrteei 1
@@ -88,8 +87,7 @@ _GLOBAL(power_save_ppc32_restore) stw r9,_NIP(r11) /* make it do a blr */ #ifdef CONFIG_SMP - CURRENT_THREAD_INFO(r12, r1) - lwz r11,TI_CPU(r12) /* get cpu number * 4 */ + lwz r11,TASK_CPU(r2) /* get cpu number * 4 */ slwi r11,r11,2 #else li r11,0
arch/powerpc/kernel/misc_32.S +1 -2
@@ -183,8 +183,7 @@ _GLOBAL(low_choose_750fx_pll) #ifdef CONFIG_SMP /* Store new HID1 image */ - CURRENT_THREAD_INFO(r6, r1) - lwz r6,TI_CPU(r6) + lwz r6,TASK_CPU(r2) slwi r6,r6,2 #else li r6, 0
arch/powerpc/mm/hash_low_32.S +5 -9
@@ -185,8 +185,7 @@ _GLOBAL(add_hash_page) add r3,r3,r0 /* note create_hpte trims to 24 bits */ #ifdef CONFIG_SMP - CURRENT_THREAD_INFO(r8, r1) /* use cpu number to make tag */ - lwz r8,TI_CPU(r8) /* to go in mmu_hash_lock */ + lwz r8,TASK_CPU(r2) /* to go in mmu_hash_lock */ oris r8,r8,12 #endif /* CONFIG_SMP */
@@ -546,9 +545,8 @@ _GLOBAL(flush_hash_pages) #ifdef CONFIG_SMP addis r9,r7,mmu_hash_lock@ha addi r9,r9,mmu_hash_lock@l - CURRENT_THREAD_INFO(r8, r1) - add r8,r8,r7 - lwz r8,TI_CPU(r8) + add r8,r2,r7 + lwz r8,TASK_CPU(r8) oris r8,r8,9 10: lwarx r0,0,r9 cmpi 0,r0,0
@@ -641,8 +639,7 @@ EXPORT_SYMBOL(flush_hash_pages) */ _GLOBAL(_tlbie) #ifdef CONFIG_SMP - CURRENT_THREAD_INFO(r8, r1) - lwz r8,TI_CPU(r8) + lwz r8,TASK_CPU(r2) oris r8,r8,11 mfmsr r10 SYNC
@@ -679,8 +676,7 @@ _GLOBAL(_tlbie) */ _GLOBAL(_tlbia) #if defined(CONFIG_SMP) - CURRENT_THREAD_INFO(r8, r1) - lwz r8,TI_CPU(r8) + lwz r8,TASK_CPU(r2) oris r8,r8,10 mfmsr r10 SYNC
arch/powerpc/sysdev/6xx-suspend.S +2 -3
@@ -29,10 +29,9 @@ _GLOBAL(mpc6xx_enter_standby) ori r5, r5, ret_from_standby@l mtlr r5 - CURRENT_THREAD_INFO(r5, r1) - lwz r6, TI_LOCAL_FLAGS(r5) + lwz r6, TI_LOCAL_FLAGS(r2) ori r6, r6, _TLF_SLEEPING - stw r6, TI_LOCAL_FLAGS(r5) + stw r6, TI_LOCAL_FLAGS(r2) mfmsr r5 ori r5, r5, MSR_EE
Signature · 1 line
2.13.3
RFC PATCH v3 7/7 powerpc/64: Modify CURRENT_THREAD_INFO()
In reply to Christophe LeroyCURRENT_THREAD_INFO() now uses the PACA to retrieve 'current' pointer, it doesn't use 'sp' anymore.
--- arch/powerpc/include/asm/exception-64s.h | 4 ++-- arch/powerpc/include/asm/thread_info.h | 2 +- arch/powerpc/kernel/entry_64.S | 10 +++++----- arch/powerpc/kernel/exceptions-64e.S | 2 +- arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/kernel/idle_book3e.S | 2 +- arch/powerpc/kernel/idle_power4.S | 2 +- arch/powerpc/kernel/trace/ftrace_64_mprofile.S | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/exception-64s.h +2 -2
@@ -672,7 +672,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)#define RUNLATCH_ON \ BEGIN_FTR_SECTION \ - CURRENT_THREAD_INFO(r3, r1); \ + CURRENT_THREAD_INFO(r3); \ ld r4,TI_LOCAL_FLAGS(r3); \ andi. r0,r4,_TLF_RUNLATCH; \ beql ppc64_runlatch_on_trampoline; \
@@ -722,7 +722,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_CTRL)#ifdef CONFIG_PPC_970_NAP #define FINISH_NAP \ BEGIN_FTR_SECTION \ - CURRENT_THREAD_INFO(r11, r1); \ + CURRENT_THREAD_INFO(r11); \ ld r9,TI_LOCAL_FLAGS(r11); \ andi. r10,r9,_TLF_NAPPING; \ bnel power4_fixup_nap; \
arch/powerpc/include/asm/thread_info.h +1 -1
@@ -18,7 +18,7 @@#define THREAD_SIZE (1 << THREAD_SHIFT)#ifdef CONFIG_PPC64 -#define CURRENT_THREAD_INFO (dest, sp) stringify_in_c(ld dest, PACACURRENT(r13)) +#define CURRENT_THREAD_INFO (dest) stringify_in_c(ld dest, PACACURRENT(r13))#endif #ifndef __ASSEMBLY__
arch/powerpc/kernel/entry_64.S +5 -5
@@ -158,7 +158,7 @@ system_call: /* label this so stack traces look sane */ li r10,IRQS_ENABLED std r10,SOFTE(r1) - CURRENT_THREAD_INFO(r11, r1) + CURRENT_THREAD_INFO(r11) ld r10,TI_FLAGS(r11) andi. r11,r10,_TIF_SYSCALL_DOTRACE bne .Lsyscall_dotrace /* does not return */
@@ -205,7 +205,7 @@ system_call: /* label this so stack traces look sane */ ld r3,RESULT(r1) #endif - CURRENT_THREAD_INFO(r12, r1) + CURRENT_THREAD_INFO(r12) ld r8,_MSR(r1) #ifdef CONFIG_PPC_BOOK3S
@@ -336,7 +336,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) /* Repopulate r9 and r10 for the syscall path */ addi r9,r1,STACK_FRAME_OVERHEAD - CURRENT_THREAD_INFO(r10, r1) + CURRENT_THREAD_INFO(r10) ld r10,TI_FLAGS(r10) cmpldi r0,NR_syscalls
@@ -731,7 +731,7 @@ _GLOBAL(ret_from_except_lite) mtmsrd r10,1 /* Update machine state */ #endif /* CONFIG_PPC_BOOK3E */ - CURRENT_THREAD_INFO(r9, r1) + CURRENT_THREAD_INFO(r9) ld r3,_MSR(r1) #ifdef CONFIG_PPC_BOOK3E ld r10,PACACURRENT(r13)
@@ -845,7 +845,7 @@ resume_kernel: 1: bl preempt_schedule_irq /* Re-test flags and eventually loop */ - CURRENT_THREAD_INFO(r9, r1) + CURRENT_THREAD_INFO(r9) ld r4,TI_FLAGS(r9) andi. r0,r4,_TIF_NEED_RESCHED bne 1b
arch/powerpc/kernel/exceptions-64e.S +1 -1
@@ -469,7 +469,7 @@ exc_##n##_bad_stack: \ * interrupts happen before the wait instruction. */ #define CHECK_NAPPING() \ - CURRENT_THREAD_INFO(r11, r1); \ + CURRENT_THREAD_INFO(r11); \ ld r10,TI_LOCAL_FLAGS(r11); \ andi. r9,r10,_TLF_NAPPING; \ beq+ 1f; \
arch/powerpc/kernel/exceptions-64s.S +1 -1
@@ -1620,7 +1620,7 @@ do_hash_page: ori r0,r0,DSISR_BAD_FAULT_64S@l and. r0,r4,r0 /* weird error? */ bne- handle_page_fault /* if not, try to insert a HPTE */ - CURRENT_THREAD_INFO(r11, r1) + CURRENT_THREAD_INFO(r11) lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */ andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */ bne 77f /* then don't call hash_page now */
arch/powerpc/kernel/idle_book3e.S +1 -1
@@ -63,7 +63,7 @@ _GLOBAL(\name) 1: /* Let's set the _TLF_NAPPING flag so interrupts make us return * to the right spot */ - CURRENT_THREAD_INFO(r11, r1) + CURRENT_THREAD_INFO(r11) ld r10,TI_LOCAL_FLAGS(r11) ori r10,r10,_TLF_NAPPING std r10,TI_LOCAL_FLAGS(r11)
arch/powerpc/kernel/idle_power4.S +1 -1
@@ -68,7 +68,7 @@ BEGIN_FTR_SECTION DSSALL sync END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) - CURRENT_THREAD_INFO(r9, r1) + CURRENT_THREAD_INFO(r9) ld r8,TI_LOCAL_FLAGS(r9) /* set napping bit */ ori r8,r8,_TLF_NAPPING /* so when we take an exception */ std r8,TI_LOCAL_FLAGS(r9) /* it will return to our caller */
arch/powerpc/kernel/trace/ftrace_64_mprofile.S +3 -3
@@ -229,7 +229,7 @@ ftrace_call: * - r0, r11 & r12 are free */ livepatch_handler: - CURRENT_THREAD_INFO(r12, r1) + CURRENT_THREAD_INFO(r12) /* Allocate 3 x 8 bytes */ ld r11, TI_livepatch_sp(r12)
@@ -256,7 +256,7 @@ livepatch_handler: * restore it. */ - CURRENT_THREAD_INFO(r12, r1) + CURRENT_THREAD_INFO(r12) ld r11, TI_livepatch_sp(r12)
@@ -273,7 +273,7 @@ livepatch_handler: ld r2, -24(r11) /* Pop livepatch stack frame */ - CURRENT_THREAD_INFO(r12, r1) + CURRENT_THREAD_INFO(r12) subi r11, r11, 24 std r11, TI_livepatch_sp(r12)
Signature · 1 line
2.13.3
Nicholas Piggin
reviewerRe: [RFC PATCH v3 7/7] powerpc/64: Modify CURRENT_THREAD_INFO()
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:31 +0000 (UTC) Christophe Leroy…
CURRENT_THREAD_INFO()now uses the PACA to retrieve 'current' pointer, it doesn't use 'sp' anymore.
Can you remove this too now? I think it will be clearer what's going on and easier to read once everyone remembers current is the same offset as current thread_info.
Overall nice series, thanks for doing this.
Thanks,
Nick
Re: [RFC PATCH v3 7/7] powerpc/64: Modify CURRENT_THREAD_INFO()
Le 03/10/2018 à 07:44, Nicholas Piggin a écrit :
Quoted 9 lines
Quoted 2 lines · On Mon, 1 Oct 2018 12:30:31 +0000 (UTC) Christophe Leroy…
CURRENT_THREAD_INFO()now uses the PACA to retrieve 'current' pointer, it doesn't use 'sp' anymore.Can you remove this too now? I think it will be clearer what's going on and easier to read once everyone remembers current is the same offset as current
thread_info.
Ok I will.
Christophe
Quoted 6 lines
Overall nice series, thanks for doing this.
Thanks,
Nick