kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
To: ", Samuel" <samuel@csie.io>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: process descriptor address in kernel stack
Date: Thu, 19 Mar 2020 05:22:32 -0400	[thread overview]
Message-ID: <22784.1584609752@turing-police> (raw)
In-Reply-To: <CAEw=bybknPF5jK-ha3agXbxryH=7=-6XHnw_XMUiAXuGgenGVg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1250 bytes --]

On Thu, 19 Mar 2020 16:53:32 +0800, ", Samuel" said:

>  movl $0xffffe000,%ecx or 0xfffff000 for 4KB stacks
>  andl %esp,%ecx
>  movl %ecx,p
>
> Why is *"stack pointer(esp) & 0xffffe000"* equal to the process descriptor
> base address?
>
> That means the base address of process descriptor is always *0xXYZ...000*,
> right? It is weird.

It's not at all weird if the kernel, when allocating the stack space to begin with,
asked for 1 (or 2 contiguous) 4K chunks of memory, at a page-aligned address....

For example, see kernel/fork.c:

    238         /*
    239          * Allocated stacks are cached and later reused by new threads,
    240          * so memcg accounting is performed manually on assigning/releasing
    241          * stacks to tasks. Drop __GFP_ACCOUNT.
    242          */
    243         stack = __vmalloc_node_range(THREAD_SIZE, THREAD_ALIGN,
    244                                      VMALLOC_START, VMALLOC_END,
    245                                      THREADINFO_GFP & ~__GFP_ACCOUNT,
    246                                      PAGE_KERNEL,
    247                                      0, node, __builtin_return_address(0));

I'll leave figuring out what THREAD_ALIGN is set to, as an exercise for the student. :)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

      reply	other threads:[~2020-03-19  9:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19  8:53 process descriptor address in kernel stack , Samuel
2020-03-19  9:22 ` Valdis Klētnieks [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22784.1584609752@turing-police \
    --to=valdis.kletnieks@vt.edu \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=samuel@csie.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).