linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: tixy@linaro.org (Jon Medhurst (Tixy))
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 2/2] ARM: vfp: clear fpscr length and stride bits on entry to sig handler
Date: Mon, 14 May 2012 15:33:55 +0100	[thread overview]
Message-ID: <1337006035.16954.21.camel@linaro1.home> (raw)
In-Reply-To: <1330009632-1235-2-git-send-email-will.deacon@arm.com>

Hi Will

I've bisected a screen corruption problem on vexpress down to this
commit, I've commented at the end of the patch at to what I see the
problem being...

On Thu, 2012-02-23 at 15:07 +0000, Will Deacon wrote:
> The ARM PCS mandates that the length and stride bits of the fpscr are
> cleared on entry to and return from a public interface. Although signal
> handlers run asynchronously with respect to the interrupted function,
> the handler itself expects to run as though it has been called like a
> normal function.
> 
> This patch updates the state mirroring the VFP hardware before entry to
> a signal handler so that it adheres to the PCS. Furthermore, we disable
> VFP to ensure that we trap on any floating point operation performed by
> the signal handler and synchronise the hardware appropriately. A check
> is inserted after the signal handler to avoid redundant flushing if VFP
> was not used.
> 
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
>  arch/arm/vfp/vfpmodule.c |   22 +++++++++++++++++++++-
>  1 files changed, 21 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
> index 1dfe7d8..269f40d 100644
> --- a/arch/arm/vfp/vfpmodule.c
> +++ b/arch/arm/vfp/vfpmodule.c
> @@ -562,6 +562,21 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
>  
>  	if (err)
>  		return -EFAULT;
> +
> +	/* Ensure that VFP is disabled. */
> +	vfp_flush_hwstate(thread);
> +
> +	/*
> +	 * As per the PCS, clear the length and stride bits for function
> +	 * entry.
> +	 */
> +	hwstate->fpscr &= ~(FPSCR_LENGTH_MASK | FPSCR_STRIDE_MASK);
> +
> +	/*
> +	 * Disable VFP in the hwstate so that we can detect if it gets
> +	 * used.
> +	 */
> +	hwstate->fpexc &= ~FPEXC_EN;
>  	return 0;
>  }
>  
> @@ -574,7 +589,12 @@ int vfp_restore_user_hwstate(struct user_vfp __user *ufp,
>  	unsigned long fpexc;
>  	int err = 0;
>  
> -	vfp_flush_hwstate(thread);
> +	/*
> +	 * If VFP has been used, then disable it to avoid corrupting
> +	 * the new thread state.
> +	 */
> +	if (hwstate->fpexc & FPEXC_EN)
> +		vfp_flush_hwstate(thread);
>  
>  	/*
>  	 * Copy the floating point registers. There can be unused

If the signal handler uses VFP, will it actually cause hwstate->fpexc &
FPEXC_EN to be set? Won't it instead just enable the VFP in the hardware
registers? (It looks to me that hwstate only gets updated by
vfp_flush_hwstate().)

This certainly seems to be the case in my screen corruption situation
where on entry to vfp_restore_user_hwstate() "fmrx(FPEXC) & FPEXC_EN"
is true and "hwstate->fpexc & FPEXC_EN" is false.

With the code as it stands this means that on return from a signal
handler the vfp hardware registers will be in whatever state the signal
handler left them in, not the thread's state at the point the signal
happened.

Assuming that I have understood things correctly, then I plan on posting
a patch that would make code changes like...

diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
index bc683b8..386a81a 100644
--- a/arch/arm/vfp/vfpmodule.c
+++ b/arch/arm/vfp/vfpmodule.c
@@ -574,11 +574,6 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp
__user *ufp,
         */
        hwstate->fpscr &= ~(FPSCR_LENGTH_MASK | FPSCR_STRIDE_MASK);
 
-       /*
-        * Disable VFP in the hwstate so that we can detect if it gets
-        * used.
-        */
-       hwstate->fpexc &= ~FPEXC_EN;
        return 0;
 }
 
@@ -591,12 +586,7 @@ int vfp_restore_user_hwstate(struct user_vfp __user
*ufp,
        unsigned long fpexc;
        int err = 0;
 
-       /*
-        * If VFP has been used, then disable it to avoid corrupting
-        * the new thread state.
-        */
-       if (hwstate->fpexc & FPEXC_EN)
-               vfp_flush_hwstate(thread);
+       vfp_flush_hwstate(thread);
 
        /*
         * Copy the floating point registers. There can be unused


-- 
Tixy 

  reply	other threads:[~2012-05-14 14:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23 15:07 [PATCH v4 1/2] ARM: vfp: move user vfp state save/restore code out of signal.c Will Deacon
2012-02-23 15:07 ` [PATCH v4 2/2] ARM: vfp: clear fpscr length and stride bits on entry to sig handler Will Deacon
2012-05-14 14:33   ` Jon Medhurst (Tixy) [this message]
2012-05-14 14:59     ` Will Deacon
2012-05-14 16:00       ` Will Deacon
2012-05-14 16:02       ` Jon Medhurst (Tixy)
2012-05-14 17:37         ` Will Deacon
2012-05-14 17:50           ` Jon Medhurst (Tixy)
2012-05-14 17:57             ` Will Deacon

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=1337006035.16954.21.camel@linaro1.home \
    --to=tixy@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).