Skip to content

Commit 3aa2df6

Browse files
Julien ThierryRussell King
authored andcommitted
ARM: 8791/1: vfp: use __copy_to_user() when saving VFP state
Use __copy_to_user() rather than __put_user_error() for individual members when saving VFP state. This has the benefit of disabling/enabling PAN once per copied struct intead of once per write. Signed-off-by: Julien Thierry <julien.thierry@arm.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent 7383979 commit 3aa2df6

3 files changed

Lines changed: 17 additions & 20 deletions

File tree

‎arch/arm/include/asm/thread_info.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ extern void vfp_flush_hwstate(struct thread_info *);
121121
struct user_vfp;
122122
struct user_vfp_exc;
123123

124-
extern int vfp_preserve_user_clear_hwstate(struct user_vfp __user *,
125-
struct user_vfp_exc __user *);
124+
extern int vfp_preserve_user_clear_hwstate(struct user_vfp *,
125+
struct user_vfp_exc *);
126126
extern int vfp_restore_user_hwstate(struct user_vfp *,
127127
struct user_vfp_exc *);
128128
#endif

‎arch/arm/kernel/signal.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ static int restore_iwmmxt_context(char __user **auxp)
137137

138138
static int preserve_vfp_context(struct vfp_sigframe __user *frame)
139139
{
140-
const unsigned long magic = VFP_MAGIC;
141-
const unsigned long size = VFP_STORAGE_SIZE;
140+
struct vfp_sigframe kframe;
142141
int err = 0;
143142

144-
__put_user_error(magic, &frame->magic, err);
145-
__put_user_error(size, &frame->size, err);
143+
memset(&kframe, 0, sizeof(kframe));
144+
kframe.magic = VFP_MAGIC;
145+
kframe.size = VFP_STORAGE_SIZE;
146146

147+
err = vfp_preserve_user_clear_hwstate(&kframe.ufp, &kframe.ufp_exc);
147148
if (err)
148-
return -EFAULT;
149+
return err;
149150

150-
return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc);
151+
return __copy_to_user(frame, &kframe, sizeof(kframe));
151152
}
152153

153154
static int restore_vfp_context(char __user **auxp)

‎arch/arm/vfp/vfpmodule.c‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,11 @@ void vfp_flush_hwstate(struct thread_info *thread)
554554
* Save the current VFP state into the provided structures and prepare
555555
* for entry into a new function (signal handler).
556556
*/
557-
int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
558-
struct user_vfp_exc __user *ufp_exc)
557+
int vfp_preserve_user_clear_hwstate(struct user_vfp *ufp,
558+
struct user_vfp_exc *ufp_exc)
559559
{
560560
struct thread_info *thread = current_thread_info();
561561
struct vfp_hard_struct *hwstate = &thread->vfpstate.hard;
562-
int err = 0;
563562

564563
/* Ensure that the saved hwstate is up-to-date. */
565564
vfp_sync_hwstate(thread);
@@ -568,22 +567,19 @@ int vfp_preserve_user_clear_hwstate(struct user_vfp __user *ufp,
568567
* Copy the floating point registers. There can be unused
569568
* registers see asm/hwcap.h for details.
570569
*/
571-
err |= __copy_to_user(&ufp->fpregs, &hwstate->fpregs,
572-
sizeof(hwstate->fpregs));
570+
memcpy(&ufp->fpregs, &hwstate->fpregs, sizeof(hwstate->fpregs));
571+
573572
/*
574573
* Copy the status and control register.
575574
*/
576-
__put_user_error(hwstate->fpscr, &ufp->fpscr, err);
575+
ufp->fpscr = hwstate->fpscr;
577576

578577
/*
579578
* Copy the exception registers.
580579
*/
581-
__put_user_error(hwstate->fpexc, &ufp_exc->fpexc, err);
582-
__put_user_error(hwstate->fpinst, &ufp_exc->fpinst, err);
583-
__put_user_error(hwstate->fpinst2, &ufp_exc->fpinst2, err);
584-
585-
if (err)
586-
return -EFAULT;
580+
ufp_exc->fpexc = hwstate->fpexc;
581+
ufp_exc->fpinst = hwstate->fpinst;
582+
ufp_exc->fpinst2 = ufp_exc->fpinst2;
587583

588584
/* Ensure that VFP is disabled. */
589585
vfp_flush_hwstate(thread);

0 commit comments

Comments
 (0)