Skip to content

Commit 0146337

Browse files
committed
Merge tag 'cpu-to-thread_info-v5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull thread_info update to move 'cpu' back from task_struct from Kees Cook: "Cross-architecture update to move task_struct::cpu back into thread_info on arm64, x86, s390, powerpc, and riscv. All Acked by arch maintainers. Quoting Ard Biesheuvel: 'Move task_struct::cpu back into thread_info Keeping CPU in task_struct is problematic for architectures that define raw_smp_processor_id() in terms of this field, as it requires linux/sched.h to be included, which causes a lot of pain in terms of circular dependencies (aka 'header soup') This series moves it back into thread_info (where it came from) for all architectures that enable THREAD_INFO_IN_TASK, addressing the header soup issue as well as some pointless differences in the implementations of task_cpu() and set_task_cpu()'" * tag 'cpu-to-thread_info-v5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: riscv: rely on core code to keep thread_info::cpu updated powerpc: smp: remove hack to obtain offset of task_struct::cpu sched: move CPU field back into thread_info if THREAD_INFO_IN_TASK=y powerpc: add CPU field to struct thread_info s390: add CPU field to struct thread_info x86: add CPU field to struct thread_info arm64: add CPU field to struct thread_info
2 parents 03feb7c + d9f2a53 commit 0146337

File tree

15 files changed

+14
-56
lines changed

15 files changed

+14
-56
lines changed

arch/arm64/include/asm/thread_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct thread_info {
4242
void *scs_base;
4343
void *scs_sp;
4444
#endif
45+
u32 cpu;
4546
};
4647

4748
#define thread_saved_pc(tsk) \

arch/arm64/kernel/asm-offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
int main(void)
2929
{
3030
DEFINE(TSK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
31-
DEFINE(TSK_CPU, offsetof(struct task_struct, cpu));
3231
BLANK();
32+
DEFINE(TSK_TI_CPU, offsetof(struct task_struct, thread_info.cpu));
3333
DEFINE(TSK_TI_FLAGS, offsetof(struct task_struct, thread_info.flags));
3434
DEFINE(TSK_TI_PREEMPT, offsetof(struct task_struct, thread_info.preempt_count));
3535
#ifdef CONFIG_ARM64_SW_TTBR0_PAN

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/Makefile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,6 @@ else
446446
endif
447447
endif
448448

449-
ifdef CONFIG_SMP
450-
ifdef CONFIG_PPC32
451-
prepare: task_cpu_prepare
452-
453-
PHONY += task_cpu_prepare
454-
task_cpu_prepare: prepare0
455-
$(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TASK_CPU") print $$3;}' include/generated/asm-offsets.h))
456-
457-
endif # CONFIG_PPC32
458-
endif # CONFIG_SMP
459-
460449
PHONY += checkbin
461450
# Check toolchain versions:
462451
# - gcc-4.6 is the minimum kernel-wide version so nothing required.

arch/powerpc/include/asm/smp.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,7 @@ int is_cpu_dead(unsigned int cpu);
8787
/* 32-bit */
8888
extern int smp_hw_index[];
8989

90-
/*
91-
* This is particularly ugly: it appears we can't actually get the definition
92-
* of task_struct here, but we need access to the CPU this task is running on.
93-
* Instead of using task_struct we're using _TASK_CPU which is extracted from
94-
* asm-offsets.h by kbuild to get the current processor ID.
95-
*
96-
* This also needs to be safeguarded when building asm-offsets.s because at
97-
* that time _TASK_CPU is not defined yet. It could have been guarded by
98-
* _TASK_CPU itself, but we want the build to fail if _TASK_CPU is missing
99-
* when building something else than asm-offsets.s
100-
*/
101-
#ifdef GENERATING_ASM_OFFSETS
102-
#define raw_smp_processor_id() (0)
103-
#else
104-
#define raw_smp_processor_id() (*(unsigned int *)((void *)current + _TASK_CPU))
105-
#endif
90+
#define raw_smp_processor_id() (current_thread_info()->cpu)
10691
#define hard_smp_processor_id() (smp_hw_index[smp_processor_id()])
10792

10893
static inline int get_hard_smp_processor_id(int cpu)

arch/powerpc/include/asm/thread_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
struct thread_info {
4848
int preempt_count; /* 0 => preemptable,
4949
<0 => BUG */
50+
#ifdef CONFIG_SMP
51+
unsigned int cpu;
52+
#endif
5053
unsigned long local_flags; /* private flags for thread */
5154
#ifdef CONFIG_LIVEPATCH
5255
unsigned long *livepatch_sp;

arch/powerpc/kernel/asm-offsets.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* #defines from the assembly-language output.
1010
*/
1111

12-
#define GENERATING_ASM_OFFSETS /* asm/smp.h */
13-
1412
#include <linux/compat.h>
1513
#include <linux/signal.h>
1614
#include <linux/sched.h>
@@ -93,7 +91,7 @@ int main(void)
9391
#endif /* CONFIG_PPC64 */
9492
OFFSET(TASK_STACK, task_struct, stack);
9593
#ifdef CONFIG_SMP
96-
OFFSET(TASK_CPU, task_struct, cpu);
94+
OFFSET(TASK_CPU, task_struct, thread_info.cpu);
9795
#endif
9896

9997
#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

arch/riscv/kernel/asm-offsets.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void asm_offsets(void)
3333
OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count);
3434
OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp);
3535
OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp);
36-
OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu);
3736

3837
OFFSET(TASK_THREAD_F0, task_struct, thread.fstate.f[0]);
3938
OFFSET(TASK_THREAD_F1, task_struct, thread.fstate.f[1]);

arch/riscv/kernel/entry.S

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,6 @@ ENTRY(__switch_to)
543543
REG_L s9, TASK_THREAD_S9_RA(a4)
544544
REG_L s10, TASK_THREAD_S10_RA(a4)
545545
REG_L s11, TASK_THREAD_S11_RA(a4)
546-
/* Swap the CPU entry around. */
547-
lw a3, TASK_TI_CPU(a0)
548-
lw a4, TASK_TI_CPU(a1)
549-
sw a3, TASK_TI_CPU(a1)
550-
sw a4, TASK_TI_CPU(a0)
551546
/* The offset of thread_info in task_struct is zero. */
552547
move tp, a1
553548
ret

0 commit comments

Comments
 (0)