Skip to content

Commit bcf9033

Browse files
committed
sched: move CPU field back into thread_info if THREAD_INFO_IN_TASK=y
THREAD_INFO_IN_TASK moved the CPU field out of thread_info, but this causes some issues on architectures that define raw_smp_processor_id() in terms of this field, due to the fact that #include'ing linux/sched.h to get at struct task_struct is problematic in terms of circular dependencies. Given that thread_info and task_struct are the same data structure anyway when THREAD_INFO_IN_TASK=y, let's move it back so that having access to the type definition of struct thread_info is sufficient to reference the CPU number of the current task. Note that this requires THREAD_INFO_IN_TASK's definition of the task_thread_info() helper to be updated, as task_cpu() takes a pointer-to-const, whereas task_thread_info() (which is used to generate lvalues as well), needs a non-const pointer. So make it a macro instead. Signed-off-by: Ard Biesheuvel <[email protected]> Acked-by: Catalin Marinas <[email protected]> Acked-by: Mark Rutland <[email protected]> Acked-by: Michael Ellerman <[email protected]>
1 parent 227d735 commit bcf9033

File tree

6 files changed

+4
-20
lines changed

6 files changed

+4
-20
lines changed

arch/arm64/kernel/asm-offsets.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
int main(void)
2828
{
2929
DEFINE(TSK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
30-
DEFINE(TSK_CPU, offsetof(struct task_struct, cpu));
3130
BLANK();
3231
DEFINE(TSK_TI_CPU, offsetof(struct task_struct, thread_info.cpu));
3332
DEFINE(TSK_TI_FLAGS, offsetof(struct task_struct, thread_info.flags));

arch/arm64/kernel/head.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ SYM_FUNC_END(__create_page_tables)
412412
scs_load \tsk
413413

414414
adr_l \tmp1, __per_cpu_offset
415-
ldr w\tmp2, [\tsk, #TSK_CPU]
415+
ldr w\tmp2, [\tsk, #TSK_TI_CPU]
416416
ldr \tmp1, [\tmp1, \tmp2, lsl #3]
417417
set_this_cpu_offset \tmp1
418418
.endm

arch/powerpc/kernel/asm-offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int main(void)
9393
#endif /* CONFIG_PPC64 */
9494
OFFSET(TASK_STACK, task_struct, stack);
9595
#ifdef CONFIG_SMP
96-
OFFSET(TASK_CPU, task_struct, cpu);
96+
OFFSET(TASK_CPU, task_struct, thread_info.cpu);
9797
#endif
9898

9999
#ifdef CONFIG_LIVEPATCH

arch/powerpc/kernel/smp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
12231223
paca_ptrs[cpu]->kstack = (unsigned long)task_stack_page(idle) +
12241224
THREAD_SIZE - STACK_FRAME_OVERHEAD;
12251225
#endif
1226-
idle->cpu = cpu;
1226+
task_thread_info(idle)->cpu = cpu;
12271227
secondary_current = current_set[cpu] = idle;
12281228
}
12291229

include/linux/sched.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,6 @@ struct task_struct {
750750
#ifdef CONFIG_SMP
751751
int on_cpu;
752752
struct __call_single_node wake_entry;
753-
#ifdef CONFIG_THREAD_INFO_IN_TASK
754-
/* Current CPU: */
755-
unsigned int cpu;
756-
#endif
757753
unsigned int wakee_flips;
758754
unsigned long wakee_flip_decay_ts;
759755
struct task_struct *last_wakee;
@@ -1886,10 +1882,7 @@ extern struct thread_info init_thread_info;
18861882
extern unsigned long init_stack[THREAD_SIZE / sizeof(unsigned long)];
18871883

18881884
#ifdef CONFIG_THREAD_INFO_IN_TASK
1889-
static inline struct thread_info *task_thread_info(struct task_struct *task)
1890-
{
1891-
return &task->thread_info;
1892-
}
1885+
# define task_thread_info(task) (&(task)->thread_info)
18931886
#elif !defined(__HAVE_THREAD_FUNCTIONS)
18941887
# define task_thread_info(task) ((struct thread_info *)(task)->stack)
18951888
#endif
@@ -2114,11 +2107,7 @@ static __always_inline bool need_resched(void)
21142107

21152108
static inline unsigned int task_cpu(const struct task_struct *p)
21162109
{
2117-
#ifdef CONFIG_THREAD_INFO_IN_TASK
2118-
return READ_ONCE(p->cpu);
2119-
#else
21202110
return READ_ONCE(task_thread_info(p)->cpu);
2121-
#endif
21222111
}
21232112

21242113
extern void set_task_cpu(struct task_struct *p, unsigned int cpu);

kernel/sched/sched.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,11 +1926,7 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
19261926
* per-task data have been completed by this moment.
19271927
*/
19281928
smp_wmb();
1929-
#ifdef CONFIG_THREAD_INFO_IN_TASK
1930-
WRITE_ONCE(p->cpu, cpu);
1931-
#else
19321929
WRITE_ONCE(task_thread_info(p)->cpu, cpu);
1933-
#endif
19341930
p->wake_cpu = cpu;
19351931
#endif
19361932
}

0 commit comments

Comments
 (0)