RE: Kernel stack

From: Thekkedath, Gopakumar (Gopakumar.Thekkedath_at_fci.com)
Date: 10/12/04

  • Next message: Hirokazu Takata: "[PATCH 2.6.9-rc4] [m32r] Fix sys_tas system call for m32r"
    To: "'suthambhara nagaraj'" <suthambhara@gmail.com>, "Dhiman, Gaurav" <gaurav.dhiman@ca.com>
    Date:	Tue, 12 Oct 2004 13:21:29 +0530
    
    

    -----Original Message-----
    From: suthambhara nagaraj [mailto:suthambhara@gmail.com]
    Sent: Tuesday, October 12, 2004 12:22 PM
    To: Dhiman, Gaurav
    Cc: main kernel; kernel
    Subject: Re: Kernel stack

    >in another structure( struct thread_struct ).A kernel stack of size 8k
    >(By default)
    >is actully shared by processes running on a processor.
            Each process has its own kernel mode stack, in fact it starts from
    the process's task_struct start address + 8K (atleast in 2.4). (This also
    helps in the implementation of 'current')

    >A Process does not have an SS entry in its thread_struct but only an
    >esp (and esp0) entry. This made me believe that the stack base is the
    >same.Correct me

            Again, in linux implementaton, for each process, SS is the same ,
    but ESP differs and hence the stack

    On Tue, 12 Oct 2004 11:55:24 +0530, Dhiman, Gaurav <gaurav.dhiman@ca.com>
    wrote:
    >
    > > I have not understood how the common kernel stack in the
    > > init_thread_union(2.6 ,init_task_union in case of 2.4) works for all
    > > the processes which run on the same processor
    >
    > As far as I know, Kernel do not have any common stack for all the
    > processes running over it. Whenever we enter the kernel mode thru system
    > calls, we go thru system gate or descriptor (0x80 entry) in IDT. This
    > entry contains the index of the descriptor in GDT (normally it points to
    > Kernel CS Segment Descriptor in GDT) and the offset (pointer) to the
    > code to be executed in kernel mode (which is system_call() function in
    > Kernel).
    >
    > Now the descriptor entry in GDT pointed out by the system gate entry in
    > IDT, contains 2 bit field known as DPL (Desired Privelege Level). If
    > this DPL is less than the CPL (Current Prevelege Level) of CPU then CPU
    > switches to the process specific kernel stack segement by refferring the
    > TSS of current running process. This stack switch is automatic by CPUand
    > there is no assembly intruction required for it.
    >
    > This stack switch is done at the time when we enter from user space to
    > the kernel space, this is done because we can not trust and share the
    > user process stack (stack used by user process in user mode). That is
    > why every process has atleast two and can even have four stacks. In each
    > process, stack for every CPU level (ring level) is defined. So whenever
    > the process runs in user mode (ring 3), its user mode stack is used, but
    > when it enters the kernel mode (ring 0) its stack is switched to the
    > kernel stack of that process. All the stacks of a process for different
    > levels of CPU are tracked thru TSS defined for that process.
    >
    > To read more on IDT, GDT, TSS and System Calls invocation, refer to the
    > Intels System Programmer's Guide. Her is the Link:
    > ftp://download.intel.com/design/PentiumII/manuals/24319202.pdf
    >
    > Correct me if I am wrong somewhere.
    >
    > Cheers !!
    > Gaurav
    >
    >
    >
    >
    > -----Original Message-----
    > From: kernelnewbies-bounce@nl.linux.org
    > [mailto:kernelnewbies-bounce@nl.linux.org] On Behalf Of suthambhara
    > nagaraj
    > Sent: Tuesday, October 12, 2004 10:31 AM
    > To: kernel
    > Subject: Kernel stack
    >
    > Hi all,
    >
    > I have not understood how the common kernel stack in the
    > init_thread_union(2.6 ,init_task_union in case of 2.4) works for all
    > the processes which run on the same processor. The scheduling is round
    > robin and yet the things on the stack (saved during SAVE_ALL) have to
    > be maintained after a switch without them getting erased. I am
    > familiar with only the i386 arch implementation.
    >
    > Please help
    >
    > regards,
    > Suthambhara
    >
    > --
    > Kernelnewbies: Help each other learn about the Linux kernel.
    > Archive: http://mail.nl.linux.org/kernelnewbies/
    > FAQ: http://kernelnewbies.org/faq/
    >
    >

    --
    Kernelnewbies: Help each other learn about the Linux kernel.
    Archive:       http://mail.nl.linux.org/kernelnewbies/
    FAQ:           http://kernelnewbies.org/faq/
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at  http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at  http://www.tux.org/lkml/
    

  • Next message: Hirokazu Takata: "[PATCH 2.6.9-rc4] [m32r] Fix sys_tas system call for m32r"

    Relevant Pages

    • [Full-disclosure] PHRACK 64: ATTACKING THE CORE
      ... - The Slab Allocator ... - Slab overflow exploiting: ... - Forcing a kernel path to sleep ... - Stack Frame Flow Recovery ...
      (Full-Disclosure)
    • Re: Interrupt context...
      ... > gone through most of the posts on interrupt in usenet. ... > kernel stack and ISR is executed. ... More may be saved depending on the architecture. ... Here the kernel have assembler code to save all general ...
      (comp.os.linux.development.system)
    • Re: Why is GForth-ITC fast?
      ... The kernel and the application code (so-called "userland") do not run ... That jump entails a "stack switch", ... the only thing is I guess if you want to do syscalls ...
      (comp.lang.forth)
    • Re: Kernel stack
      ... The problem is each process does not have a TSS of its own.Only one ... in another structure.A kernel stack of size 8k ... esp entry. ... This made me believe that the stack base is the ...
      (Linux-Kernel)
    • Re: The well-factored 386
      ... That would have to be a kernel for very special use. ... means any user process can take over the cpu as if ... processes running. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)