Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Nov 2007 10:26:28 -0800
From:      Marcel Moolenaar <xcllnt@mac.com>
To:        Julian Elischer <julian@elischer.org>
Cc:        Kostik Belousov <kostikbel@gmail.com>, Alexander Motin <mav@FreeBSD.org>, freebsd-arch@FreeBSD.org
Subject:   Re: Kernel thread stack usage
Message-ID:  <2FA48BC6-BCF3-4C16-B914-30A13C15B8AA@mac.com>
In-Reply-To: <4737D7E3.3090500@elischer.org>
References:  <1191187393.00807485.1191175801@10.7.7.3> <1191189248.00807488.1191177603@10.7.7.3> <4736D8AF.7010209@FreeBSD.org> <20071111163815.GJ37471@deviant.kiev.zoral.com.ua> <47373C5E.2080800@elischer.org> <0414590D-0C2A-4EBD-9617-7AC193ABD1E8@mac.com> <4737696A.7050605@FreeBSD.org> <06618562-A789-4B5E-94BF-0ED8AB51A1FF@mac.com> <4737D7E3.3090500@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Nov 11, 2007, at 8:34 PM, Julian Elischer wrote:

> Marcel Moolenaar wrote:
>> It's the register stack that grows faster in general and
>> yes, they grow towards each other so they can eventually
>> run into each other.
>
> so one could write something that detects tha tyou are getting close,
> but it would have to be machine dependent..

Yes. A good place would be cpu_switch in this case, because
the processor flushes the dirty stacked registers onto the
register stack only when it "feels" like it or when instructed
to do so. In practice this means that while the stacks may
have run into each other based on the pointers, the memory
corruption (sec) often happens in cpu_switch where we force
the processor to flush the dirty stacked registers.

In other words: a thread is expected in the common case to
encounter the corruption until the next switch-in, but could
in case of excessive use of either or both stacks encounter
it on function boundaries (function calls and/or returns).

As a side-note: The implementation of kernel stack guard pages
is just as meaningless for ia64. As a first improvement, you
want guard pages both at the top and at the bottom and not just
at the bottom. Secondly, you want to be able to protect each
stack running into each other. However, putting a guard page
somewhere in the middle may not be the right thing, because
different threads may require different ratios...

-- 
Marcel Moolenaar
xcllnt@mac.com





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2FA48BC6-BCF3-4C16-B914-30A13C15B8AA>