Subject: kernel stack overflow
To: der Mouse <mouse@Holo.Rodents.Montreal.QC.CA>
From: Eduardo E. Horvath <eeh@one-o.com>
List: port-sparc
Date: 01/30/1997 14:53:00
Although I should let this thread die (note the more accurate subject
line) I cannot resist making at least one small clarification.

On Wed, 29 Jan 1997, der Mouse wrote:

> > Correct me if I'm wrong, but does the sparc processor really have a
> > stack in hardware?  I thought that it saves all the machine state at
> > the time of the trap in onchip registers and restarts at some known
> > location.  OK, it might get a "double" trap when it cannot access the
> > trap handling code, but I don't think that it can get one when
> > accessing something on the (software implemented) stack.
> 
> It almost can.
> 
> When the CPU takes a trap, it may shift into an otherwise invalid
> register window (the "trap window"); it's true this is all the CPU
> really does.
> 
> A double error halt ("Watchdog reset!" on machines with older ROMs) is
> what happens when the machine takes a trap while traps are disabled.
> When a trap is taken, traps are automatically disabled; if another trap
> occurs before the trap handler re-enables traps, this is what happens.
> (If the kernel stack is invalid, this is probably what will happen; the
> machine will take an MMU-provoked trap while trying to spill register
> windows to the stack.  It might be avoidable, but it's not at all clear
> to me how.)

Since this problem needs to be handled for user window traps where the
destination address is not mapped in or swapped out, the sparc v8- port
should be perfectly able to deal with this condition with a small tweek to
the window trap handlers.

I beleive what the current handler checks to see if the location the stack
pointer points to is mapped in before attempting to save the registers.
If not, then it saves the window in the u-structure and issues a data
fault.  All we need to do to handle a kernel stack redzone is if the
window fault was to a kernel address and the CPU was in kernel mode,
switch to an emergency backup kernel stack, then panic.

=========================================================================
Eduardo Horvath				eeh@btr.com
"Cliffs are for climbing.  That's why God invented grappling hooks."
					- Benton Frasier