xtensa: fix warning '"CONFIG_OF" is not defined'

The warning only shows up when building MMUv3 configuration with OF
support disabled.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: export ccount_freq

Now that ccount_freq is used in udelay and ndelay it needs to be
exported in order to be available to modules.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: introduce spill_registers_kernel macro

Most in-kernel users want registers spilled on the kernel stack and
don't require PS.EXCM to be set. That means that they don't need fixup
routine and could reuse regular window overflow mechanism for that,
which makes spill routine very simple.

Cc: stable@vger.kernel.org
Suggested-by: Chris Zankel <chris@zankel.net>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: save current register frame in fast_syscall_spill_registers_fixup

We need it saved because it contains a3 where we track which register
windows we still need to spill, and fixup handler may call C exception
handlers. Also fix comments.

Cc: stable@vger.kernel.org
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: fix fast_syscall_spill_registers

The original implementation could clobber registers under certain conditions.

The Xtensa processor architecture uses windowed registers and the original
implementation was using a4 as a temporary register, which under certain
conditions could be register a0 of the oldest window frame, and didn't always
restore the content correctly.

By moving the _spill_registers routine inside the fast system call, it frees
up one more register (the return address is not required anymore) for the
spill routine.

Signed-off-by: Chris Zankel <chris@zankel.net>
xtensa: fix fast_syscall_spill_registers

The original implementation could clobber registers under certain conditions.

The Xtensa processor architecture uses windowed registers and the original
implementation was using a4 as a temporary register, which under certain
conditions could be register a0 of the oldest window frame, and didn't always
restore the content correctly.

By moving the _spill_registers routine inside the fast system call, it frees
up one more register (the return address is not required anymore) for the
spill routine.

Signed-off-by: Chris Zankel <chris@zankel.net>
xtensa: return correct pt_regs even when in double exception

Double exception handler may (and by default does) run in a nested (2nd
level) stack frame, but task_pt_regs always returns the topmost stack frame.
When a signal is raised from the double exception for a ptraced
application the register values that ptracing application sees may be
incorrect.

Expand struct thread_info by adding a new field, double_frame, that points
to a double exception stack frame. task_pt_regs returns double_frame
when it is non-NULL, or the topmost stack frame otherwise.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: deliver signal raised in double exception handler

This fixes infinite loop caused by an exception in a fast exception
handler, e.g. on userspace access to unaligned address in unmapped memory
region, or spill_registers syscall when user stack pointer is corrupted.

In such situations the handler of the nested exception sends a signal that
is either handled by the task or that kills the task avoiding infinite
retry of the faulty operation.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: restart fast_unaligned handler on double exception

Add fast_unaligned_fixup that restores user registers, runs double
exception handler in the topmost stack frame and restarts fast_unaligned
afterwards. This makes sure that when a double exception handler raises
a signal, task registers visible through ptrace are correct in the signal
handler.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
WIP: broken: xtensa: restart fast_unaligned from the fault point

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>