Skip to contentSkip to conversation

Documentation: x86: fix thread_info's position

PATCH In review Yang Mingzhe 2 participants 3 messages Nov 10, 2020 – Nov 11, 2020 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation: x86: fix thread_info's position

The bottom of the stack is where the first item was added to the stack, usually at the zero offset. Actually, the thread_info structure at the end of the stack.

Please see attached picture:
https://github.com/Mutated1994/kernel-beginner/blob/master/kernel-stack.md

See commits c65eacb ("sched/core: Allow putting thread_info into task_struct"), 15f4eae ("x86: Move thread_info into task_struct") and 883d50f ("scripts/gdb: fix get_thread_info").

---
 Documentation/x86/kernel-stacks.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/x86/kernel-stacks.rst +3 -1
index 6b0bcf0..b88b9e12 100644
@@ -15,7 +15,9 @@ Like all other architectures, x86_64 has a kernel stack for every
 active thread.  These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big.
 These stacks contain useful data as long as a thread is alive or a
 zombie. While the thread is in user space the kernel stack is empty
-except for the thread_info structure at the bottom.
+except for the thread_info structure at the end (since kernel 4.9, the
+thread_info has been moved into task_struct, no longer locates at the
+end of kernel stack).
 
 In addition to the per thread stacks, there are specialized stacks
 associated with each CPU.  These stacks are only used while the kernel
Signature · 1 line
1.8.3.1
#1 lore raw

From: Yang Mingzhe

Quoted 5 lines

Sent: 10 November 2020 14:21

The bottom of the stack is where the first item was added to the stack, usually at the zero offset. Actually, the thread_info structure at the end of the stack.

Nope, most stacks 'grow down'.
So the first item pushed is at address 8k (for 8k stacks).

Quoted 17 lines

Please see attached picture:
https://github.com/Mutated1994/kernel-beginner/blob/master/kernel-stack.md

See commits c65eacb ("sched/core: Allow putting thread_info into task_struct"), 15f4eae ("x86: Move thread_info into task_struct") and 883d50f ("scripts/gdb: fix get_thread_info").

---
 Documentation/x86/kernel-stacks.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/x86/kernel-stacks.rst +0 -0
index 6b0bcf0..b88b9e12 100644

Documentation/x86/kernel-stacks.rst Like all other architectures, x86_64 has a kernel stack for every · line 20

Quoted 7 lines
Documentation/x86/kernel-stacks.rst +3 -1
@@ -15,7 +15,9 @@ Like all other architectures, x86_64 has a kernel stack for every
 active thread.  These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big.
 These stacks contain useful data as long as a thread is alive or a
 zombie. While the thread is in user space the kernel stack is empty
-except for the thread_info structure at the bottom.
+except for the thread_info structure at the end (since kernel 4.9, the
+thread_info has been moved into task_struct, no longer locates at the
+end of kernel stack).

So 'bottom' - meaning address 0 is probably right.
Not sure what happens on the few architectures where pushing values onto the stack does increase the stack pointer.

The bit about the kernel 4.9 changes doesn't read well at all. I think the commas are just wrong.
You could say something like:

Prior to kernel 4.9 the thread_info structure was at the bottom of the kernel stack. kernel 4.9 moved it into the task_struct.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#2 lore raw

From: David Laight

Quoted 1 line

Sent: 10 November 2020 23:03

Thank you for your review!

Quoted 2 lines

Nope, most stacks 'grow down'.
So the first item pushed is at address 8k (for 8k stacks).

Yep, most stacks 'grow down'. But the zero offset of a stack is also at address 8k(for 8k stack).

Quoted 2 lines

The bit about the kernel 4.9 changes doesn't read well at all. I think the commas are just wrong.

I’m sorry for that, because my English is not very well.

Quoted 2 lines

You could say something like:
Prior to kernel 4.9 the thread_info structure was at the bottom of the kernel stack. kernel 4.9 moved it into the task_struct.

Gotcha!

Quoted 53 lines · David Laight

From: Yang Mingzhe

Quoted 5 lines

Sent: 10 November 2020 14:21

The bottom of the stack is where the first item was added to the stack, usually at the zero offset. Actually, the thread_info structure at the end of the stack.

Nope, most stacks 'grow down'.
So the first item pushed is at address 8k (for 8k stacks).

Quoted 17 lines

Please see attached picture:
https://github.com/Mutated1994/kernel-beginner/blob/master/kernel-stack.md

See commits c65eacb ("sched/core: Allow putting thread_info into task_struct"), 15f4eae ("x86: Move thread_info into task_struct") and 883d50f ("scripts/gdb: fix get_thread_info").

---
 Documentation/x86/kernel-stacks.rst | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/x86/kernel-stacks.rst +0 -0
index 6b0bcf0..b88b9e12 100644

Documentation/x86/kernel-stacks.rst Like all other architectures, x86_64 has a kernel stack for every · line 20

Quoted 7 lines
Documentation/x86/kernel-stacks.rst +3 -1
@@ -15,7 +15,9 @@ Like all other architectures, x86_64 has a kernel stack for every
 active thread.  These thread stacks are THREAD_SIZE (2*PAGE_SIZE) big.
 These stacks contain useful data as long as a thread is alive or a
 zombie. While the thread is in user space the kernel stack is empty
-except for the thread_info structure at the bottom.
+except for the thread_info structure at the end (since kernel 4.9, the
+thread_info has been moved into task_struct, no longer locates at the
+end of kernel stack).

So 'bottom' - meaning address 0 is probably right.
Not sure what happens on the few architectures where pushing values onto the stack does increase the stack pointer.

The bit about the kernel 4.9 changes doesn't read well at all. I think the commas are just wrong.
You could say something like:

Prior to kernel 4.9 the thread_info structure was at the bottom of the kernel stack. kernel 4.9 moved it into the task_struct.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)