Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b235beea authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Clarify naming of thread info/stack allocators



We've had the thread info allocated together with the thread stack for
most architectures for a long time (since the thread_info was split off
from the task struct), but that is about to change.

But the patches that move the thread info to be off-stack (and a part of
the task struct instead) made it clear how confused the allocator and
freeing functions are.

Because the common case was that we share an allocation with the thread
stack and the thread_info, the two pointers were identical.  That
identity then meant that we would have things like

	ti = alloc_thread_info_node(tsk, node);
	...
	tsk->stack = ti;

which certainly _worked_ (since stack and thread_info have the same
value), but is rather confusing: why are we assigning a thread_info to
the stack? And if we move the thread_info away, the "confusing" code
just gets to be entirely bogus.

So remove all this confusion, and make it clear that we are doing the
stack allocation by renaming and clarifying the function names to be
about the stack.  The fact that the thread_info then shares the
allocation is an implementation detail, and not really about the
allocation itself.

This is a pure renaming and type fix: we pass in the same pointer, it's
just that we clarify what the pointer means.

The ia64 code that actually only has one single allocation (for all of
task_struct, thread_info and kernel thread stack) now looks a bit odd,
but since "tsk->stack" is actually not even used there, that oddity
doesn't matter.  It would be a separate thing to clean that up, I
intentionally left the ia64 changes as a pure brute-force renaming and
type change.

Acked-by: default avatarAndy Lutomirski <luto@amacapital.net>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 63c04ee7
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -226,8 +226,8 @@ config ARCH_INIT_TASK
config ARCH_TASK_STRUCT_ALLOCATOR
config ARCH_TASK_STRUCT_ALLOCATOR
	bool
	bool


# Select if arch has its private alloc_thread_info() function
# Select if arch has its private alloc_thread_stack() function
config ARCH_THREAD_INFO_ALLOCATOR
config ARCH_THREAD_STACK_ALLOCATOR
	bool
	bool


# Select if arch wants to size task_struct dynamically via arch_task_struct_size:
# Select if arch wants to size task_struct dynamically via arch_task_struct_size:
+1 −1
Original line number Original line Diff line number Diff line
@@ -45,7 +45,7 @@ config IA64
	select GENERIC_SMP_IDLE_THREAD
	select GENERIC_SMP_IDLE_THREAD
	select ARCH_INIT_TASK
	select ARCH_INIT_TASK
	select ARCH_TASK_STRUCT_ALLOCATOR
	select ARCH_TASK_STRUCT_ALLOCATOR
	select ARCH_THREAD_INFO_ALLOCATOR
	select ARCH_THREAD_STACK_ALLOCATOR
	select ARCH_CLOCKSOURCE_DATA
	select ARCH_CLOCKSOURCE_DATA
	select GENERIC_TIME_VSYSCALL_OLD
	select GENERIC_TIME_VSYSCALL_OLD
	select SYSCTL_ARCH_UNALIGN_NO_WARN
	select SYSCTL_ARCH_UNALIGN_NO_WARN
+4 −4
Original line number Original line Diff line number Diff line
@@ -48,15 +48,15 @@ struct thread_info {
#ifndef ASM_OFFSETS_C
#ifndef ASM_OFFSETS_C
/* how to get the thread information struct from C */
/* how to get the thread information struct from C */
#define current_thread_info()	((struct thread_info *) ((char *) current + IA64_TASK_SIZE))
#define current_thread_info()	((struct thread_info *) ((char *) current + IA64_TASK_SIZE))
#define alloc_thread_info_node(tsk, node)	\
#define alloc_thread_stack_node(tsk, node)	\
		((struct thread_info *) ((char *) (tsk) + IA64_TASK_SIZE))
		((unsigned long *) ((char *) (tsk) + IA64_TASK_SIZE))
#define task_thread_info(tsk)	((struct thread_info *) ((char *) (tsk) + IA64_TASK_SIZE))
#define task_thread_info(tsk)	((struct thread_info *) ((char *) (tsk) + IA64_TASK_SIZE))
#else
#else
#define current_thread_info()	((struct thread_info *) 0)
#define current_thread_info()	((struct thread_info *) 0)
#define alloc_thread_info_node(tsk, node)	((struct thread_info *) 0)
#define alloc_thread_stack_node(tsk, node)	((unsigned long *) 0)
#define task_thread_info(tsk)	((struct thread_info *) 0)
#define task_thread_info(tsk)	((struct thread_info *) 0)
#endif
#endif
#define free_thread_info(ti)	/* nothing */
#define free_thread_stack(ti)	/* nothing */
#define task_stack_page(tsk)	((void *)(tsk))
#define task_stack_page(tsk)	((void *)(tsk))


#define __HAVE_THREAD_FUNCTIONS
#define __HAVE_THREAD_FUNCTIONS
+1 −1
Original line number Original line Diff line number Diff line
@@ -115,7 +115,7 @@ static inline unsigned long current_stack_pointer(void)
}
}


#ifndef CONFIG_KGDB
#ifndef CONFIG_KGDB
void arch_release_thread_info(struct thread_info *ti);
void arch_release_thread_stack(unsigned long *stack);
#endif
#endif
#define get_thread_info(ti)	get_task_struct((ti)->task)
#define get_thread_info(ti)	get_task_struct((ti)->task)
#define put_thread_info(ti)	put_task_struct((ti)->task)
#define put_thread_info(ti)	put_task_struct((ti)->task)
+2 −1
Original line number Original line Diff line number Diff line
@@ -397,8 +397,9 @@ static bool kgdb_arch_undo_singlestep(struct pt_regs *regs)
 * single-step state is cleared.  At this point the breakpoints should have
 * single-step state is cleared.  At this point the breakpoints should have
 * been removed by __switch_to().
 * been removed by __switch_to().
 */
 */
void arch_release_thread_info(struct thread_info *ti)
void arch_release_thread_stack(unsigned long *stack)
{
{
	struct thread_info *ti = (void *)stack;
	if (kgdb_sstep_thread == ti) {
	if (kgdb_sstep_thread == ti) {
		kgdb_sstep_thread = NULL;
		kgdb_sstep_thread = NULL;


Loading