Commit 82c6f5a5 authored by Imre Deak's avatar Imre Deak Committed by Russell King

ARM: 6051/1: VFP: preserve the HW context when calling signal handlers

From: Imre Deak <imre.deak@nokia.com>

Signal handlers can use floating point, so prevent them to corrupt
the main thread's VFP context. So far there were two signal stack
frame formats defined based on the VFP implementation, but the user
struct used for ptrace covers all posibilities, so use it for the
signal stack too.

Introduce also a new user struct for VFP exception registers. In
this too fields not relevant to the current VFP architecture are
ignored.

Support to save / restore the exception registers was added by
Will Deacon.
Signed-off-by: default avatarImre Deak <imre.deak@nokia.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 5c5cac63
...@@ -59,23 +59,22 @@ struct iwmmxt_sigframe { ...@@ -59,23 +59,22 @@ struct iwmmxt_sigframe {
#endif /* CONFIG_IWMMXT */ #endif /* CONFIG_IWMMXT */
#ifdef CONFIG_VFP #ifdef CONFIG_VFP
#if __LINUX_ARM_ARCH__ < 6
/* For ARM pre-v6, we use fstmiax and fldmiax. This adds one extra
* word after the registers, and a word of padding at the end for
* alignment. */
#define VFP_MAGIC 0x56465001 #define VFP_MAGIC 0x56465001
#define VFP_STORAGE_SIZE 152
#else
#define VFP_MAGIC 0x56465002
#define VFP_STORAGE_SIZE 144
#endif
struct vfp_sigframe struct vfp_sigframe
{ {
unsigned long magic; unsigned long magic;
unsigned long size; unsigned long size;
union vfp_state storage; struct user_vfp ufp;
}; struct user_vfp_exc ufp_exc;
} __attribute__((__aligned__(8)));
/*
* 8 byte for magic and size, 264 byte for ufp, 12 bytes for ufp_exc,
* 4 bytes padding.
*/
#define VFP_STORAGE_SIZE sizeof(struct vfp_sigframe)
#endif /* CONFIG_VFP */ #endif /* CONFIG_VFP */
/* /*
...@@ -91,7 +90,7 @@ struct aux_sigframe { ...@@ -91,7 +90,7 @@ struct aux_sigframe {
#ifdef CONFIG_IWMMXT #ifdef CONFIG_IWMMXT
struct iwmmxt_sigframe iwmmxt; struct iwmmxt_sigframe iwmmxt;
#endif #endif
#if 0 && defined CONFIG_VFP /* Not yet saved. */ #ifdef CONFIG_VFP
struct vfp_sigframe vfp; struct vfp_sigframe vfp;
#endif #endif
/* Something that isn't a valid magic number for any coprocessor. */ /* Something that isn't a valid magic number for any coprocessor. */
......
...@@ -83,11 +83,21 @@ struct user{ ...@@ -83,11 +83,21 @@ struct user{
/* /*
* User specific VFP registers. If only VFPv2 is present, registers 16 to 31 * User specific VFP registers. If only VFPv2 is present, registers 16 to 31
* are ignored by the ptrace system call. * are ignored by the ptrace system call and the signal handler.
*/ */
struct user_vfp { struct user_vfp {
unsigned long long fpregs[32]; unsigned long long fpregs[32];
unsigned long fpscr; unsigned long fpscr;
}; };
/*
* VFP exception registers exposed to user space during signal delivery.
* Fields not relavant to the current VFP architecture are ignored.
*/
struct user_vfp_exc {
unsigned long fpexc;
unsigned long fpinst;
unsigned long fpinst2;
};
#endif /* _ARM_USER_H */ #endif /* _ARM_USER_H */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/ucontext.h> #include <asm/ucontext.h>
#include <asm/unistd.h> #include <asm/unistd.h>
#include <asm/vfp.h>
#include "ptrace.h" #include "ptrace.h"
#include "signal.h" #include "signal.h"
...@@ -175,6 +176,90 @@ static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame) ...@@ -175,6 +176,90 @@ static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
#endif #endif
#ifdef CONFIG_VFP
static int preserve_vfp_context(struct vfp_sigframe __user *frame)
{
struct thread_info *thread = current_thread_info();
struct vfp_hard_struct *h = &thread->vfpstate.hard;
const unsigned long magic = VFP_MAGIC;
const unsigned long size = VFP_STORAGE_SIZE;
int err = 0;
vfp_sync_hwstate(thread);
__put_user_error(magic, &frame->magic, err);
__put_user_error(size, &frame->size, err);
/*
* Copy the floating point registers. There can be unused
* registers see asm/hwcap.h for details.
*/
err |= __copy_to_user(&frame->ufp.fpregs, &h->fpregs,
sizeof(h->fpregs));
/*
* Copy the status and control register.
*/
__put_user_error(h->fpscr, &frame->ufp.fpscr, err);
/*
* Copy the exception registers.
*/
__put_user_error(h->fpexc, &frame->ufp_exc.fpexc, err);
__put_user_error(h->fpinst, &frame->ufp_exc.fpinst, err);
__put_user_error(h->fpinst2, &frame->ufp_exc.fpinst2, err);
return err ? -EFAULT : 0;
}
static int restore_vfp_context(struct vfp_sigframe __user *frame)
{
struct thread_info *thread = current_thread_info();
struct vfp_hard_struct *h = &thread->vfpstate.hard;
unsigned long magic;
unsigned long size;
unsigned long fpexc;
int err = 0;
__get_user_error(magic, &frame->magic, err);
__get_user_error(size, &frame->size, err);
if (err)
return -EFAULT;
if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
return -EINVAL;
/*
* Copy the floating point registers. There can be unused
* registers see asm/hwcap.h for details.
*/
err |= __copy_from_user(&h->fpregs, &frame->ufp.fpregs,
sizeof(h->fpregs));
/*
* Copy the status and control register.
*/
__get_user_error(h->fpscr, &frame->ufp.fpscr, err);
/*
* Sanitise and restore the exception registers.
*/
__get_user_error(fpexc, &frame->ufp_exc.fpexc, err);
/* Ensure the VFP is enabled. */
fpexc |= FPEXC_EN;
/* Ensure FPINST2 is invalid and the exception flag is cleared. */
fpexc &= ~(FPEXC_EX | FPEXC_FP2V);
h->fpexc = fpexc;
__get_user_error(h->fpinst, &frame->ufp_exc.fpinst, err);
__get_user_error(h->fpinst2, &frame->ufp_exc.fpinst2, err);
if (!err)
vfp_flush_hwstate(thread);
return err ? -EFAULT : 0;
}
#endif
/* /*
* Do a signal return; undo the signal stack. These are aligned to 64-bit. * Do a signal return; undo the signal stack. These are aligned to 64-bit.
*/ */
...@@ -233,8 +318,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf) ...@@ -233,8 +318,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
err |= restore_iwmmxt_context(&aux->iwmmxt); err |= restore_iwmmxt_context(&aux->iwmmxt);
#endif #endif
#ifdef CONFIG_VFP #ifdef CONFIG_VFP
// if (err == 0) if (err == 0)
// err |= vfp_restore_state(&sf->aux.vfp); err |= restore_vfp_context(&aux->vfp);
#endif #endif
return err; return err;
...@@ -348,8 +433,8 @@ setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set) ...@@ -348,8 +433,8 @@ setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
err |= preserve_iwmmxt_context(&aux->iwmmxt); err |= preserve_iwmmxt_context(&aux->iwmmxt);
#endif #endif
#ifdef CONFIG_VFP #ifdef CONFIG_VFP
// if (err == 0) if (err == 0)
// err |= vfp_save_state(&sf->aux.vfp); err |= preserve_vfp_context(&aux->vfp);
#endif #endif
__put_user_error(0, &aux->end_magic, err); __put_user_error(0, &aux->end_magic, err);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment