Skip to content

Commit 7d8eb50

Browse files
committed
Merge branch 'for-linus-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml
Pull UML updates from Richard Weinberger: "This contains a nice FPU fixup from Eli Cooper for UML" * 'for-linus-4.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml: um: add extended processor state save/restore support um: extend fpstate to _xstate to support YMM registers um: fix FPU state preservation around signal handlers
2 parents 23a3e17 + a78ff11 commit 7d8eb50

9 files changed

Lines changed: 95 additions & 50 deletions

File tree

‎arch/um/include/shared/registers.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <sysdep/ptrace.h>
1010
#include <sysdep/archsetjmp.h>
1111

12+
extern int save_i387_registers(int pid, unsigned long *fp_regs);
13+
extern int restore_i387_registers(int pid, unsigned long *fp_regs);
1214
extern int save_fp_registers(int pid, unsigned long *fp_regs);
1315
extern int restore_fp_registers(int pid, unsigned long *fp_regs);
1416
extern int save_fpx_registers(int pid, unsigned long *fp_regs);

‎arch/um/kernel/process.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,6 @@ int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
398398
{
399399
int cpu = current_thread_info()->cpu;
400400

401-
return save_fp_registers(userspace_pid[cpu], (unsigned long *) fpu);
401+
return save_i387_registers(userspace_pid[cpu], (unsigned long *) fpu);
402402
}
403403

‎arch/um/os-Linux/signal.c‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,29 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *) = {
2929

3030
static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc)
3131
{
32-
struct uml_pt_regs r;
32+
struct uml_pt_regs *r;
3333
int save_errno = errno;
3434

35-
r.is_user = 0;
35+
r = malloc(sizeof(struct uml_pt_regs));
36+
if (!r)
37+
panic("out of memory");
38+
39+
r->is_user = 0;
3640
if (sig == SIGSEGV) {
3741
/* For segfaults, we want the data from the sigcontext. */
38-
get_regs_from_mc(&r, mc);
39-
GET_FAULTINFO_FROM_MC(r.faultinfo, mc);
42+
get_regs_from_mc(r, mc);
43+
GET_FAULTINFO_FROM_MC(r->faultinfo, mc);
4044
}
4145

4246
/* enable signals if sig isn't IRQ signal */
4347
if ((sig != SIGIO) && (sig != SIGWINCH) && (sig != SIGALRM))
4448
unblock_signals();
4549

46-
(*sig_info[sig])(sig, si, &r);
50+
(*sig_info[sig])(sig, si, r);
4751

4852
errno = save_errno;
53+
54+
free(r);
4955
}
5056

5157
/*
@@ -83,11 +89,17 @@ void sig_handler(int sig, struct siginfo *si, mcontext_t *mc)
8389

8490
static void timer_real_alarm_handler(mcontext_t *mc)
8591
{
86-
struct uml_pt_regs regs;
92+
struct uml_pt_regs *regs;
93+
94+
regs = malloc(sizeof(struct uml_pt_regs));
95+
if (!regs)
96+
panic("out of memory");
8797

8898
if (mc != NULL)
89-
get_regs_from_mc(&regs, mc);
90-
timer_handler(SIGALRM, NULL, &regs);
99+
get_regs_from_mc(regs, mc);
100+
timer_handler(SIGALRM, NULL, regs);
101+
102+
free(regs);
91103
}
92104

93105
void timer_alarm_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)

‎arch/x86/um/os-Linux/registers.c‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,56 @@
1111
#endif
1212
#include <longjmp.h>
1313
#include <sysdep/ptrace_user.h>
14+
#include <sys/uio.h>
15+
#include <asm/sigcontext.h>
16+
#include <linux/elf.h>
1417

15-
int save_fp_registers(int pid, unsigned long *fp_regs)
18+
int have_xstate_support;
19+
20+
int save_i387_registers(int pid, unsigned long *fp_regs)
1621
{
1722
if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
1823
return -errno;
1924
return 0;
2025
}
2126

22-
int restore_fp_registers(int pid, unsigned long *fp_regs)
27+
int save_fp_registers(int pid, unsigned long *fp_regs)
28+
{
29+
struct iovec iov;
30+
31+
if (have_xstate_support) {
32+
iov.iov_base = fp_regs;
33+
iov.iov_len = sizeof(struct _xstate);
34+
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
35+
return -errno;
36+
return 0;
37+
} else {
38+
return save_i387_registers(pid, fp_regs);
39+
}
40+
}
41+
42+
int restore_i387_registers(int pid, unsigned long *fp_regs)
2343
{
2444
if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
2545
return -errno;
2646
return 0;
2747
}
2848

49+
int restore_fp_registers(int pid, unsigned long *fp_regs)
50+
{
51+
struct iovec iov;
52+
53+
if (have_xstate_support) {
54+
iov.iov_base = fp_regs;
55+
iov.iov_len = sizeof(struct _xstate);
56+
if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
57+
return -errno;
58+
return 0;
59+
} else {
60+
return restore_i387_registers(pid, fp_regs);
61+
}
62+
}
63+
2964
#ifdef __i386__
3065
int have_fpx_regs = 1;
3166
int save_fpx_registers(int pid, unsigned long *fp_regs)
@@ -85,6 +120,16 @@ int put_fp_registers(int pid, unsigned long *regs)
85120
return restore_fp_registers(pid, regs);
86121
}
87122

123+
void arch_init_registers(int pid)
124+
{
125+
struct _xstate fp_regs;
126+
struct iovec iov;
127+
128+
iov.iov_base = &fp_regs;
129+
iov.iov_len = sizeof(struct _xstate);
130+
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
131+
have_xstate_support = 1;
132+
}
88133
#endif
89134

90135
unsigned long get_thread_reg(int reg, jmp_buf *buf)

‎arch/x86/um/ptrace_32.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static int get_fpregs(struct user_i387_struct __user *buf, struct task_struct *c
194194
int err, n, cpu = ((struct thread_info *) child->stack)->cpu;
195195
struct user_i387_struct fpregs;
196196

197-
err = save_fp_registers(userspace_pid[cpu], (unsigned long *) &fpregs);
197+
err = save_i387_registers(userspace_pid[cpu],
198+
(unsigned long *) &fpregs);
198199
if (err)
199200
return err;
200201

@@ -214,7 +215,7 @@ static int set_fpregs(struct user_i387_struct __user *buf, struct task_struct *c
214215
if (n > 0)
215216
return -EFAULT;
216217

217-
return restore_fp_registers(userspace_pid[cpu],
218+
return restore_i387_registers(userspace_pid[cpu],
218219
(unsigned long *) &fpregs);
219220
}
220221

‎arch/x86/um/ptrace_64.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ int is_syscall(unsigned long addr)
222222
static int get_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
223223
{
224224
int err, n, cpu = ((struct thread_info *) child->stack)->cpu;
225-
long fpregs[HOST_FP_SIZE];
225+
struct user_i387_struct fpregs;
226226

227-
BUG_ON(sizeof(*buf) != sizeof(fpregs));
228-
err = save_fp_registers(userspace_pid[cpu], fpregs);
227+
err = save_i387_registers(userspace_pid[cpu],
228+
(unsigned long *) &fpregs);
229229
if (err)
230230
return err;
231231

232-
n = copy_to_user(buf, fpregs, sizeof(fpregs));
232+
n = copy_to_user(buf, &fpregs, sizeof(fpregs));
233233
if (n > 0)
234234
return -EFAULT;
235235

@@ -239,14 +239,14 @@ static int get_fpregs(struct user_i387_struct __user *buf, struct task_struct *c
239239
static int set_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
240240
{
241241
int n, cpu = ((struct thread_info *) child->stack)->cpu;
242-
long fpregs[HOST_FP_SIZE];
242+
struct user_i387_struct fpregs;
243243

244-
BUG_ON(sizeof(*buf) != sizeof(fpregs));
245-
n = copy_from_user(fpregs, buf, sizeof(fpregs));
244+
n = copy_from_user(&fpregs, buf, sizeof(fpregs));
246245
if (n > 0)
247246
return -EFAULT;
248247

249-
return restore_fp_registers(userspace_pid[cpu], fpregs);
248+
return restore_i387_registers(userspace_pid[cpu],
249+
(unsigned long *) &fpregs);
250250
}
251251

252252
long subarch_ptrace(struct task_struct *child, long request,

‎arch/x86/um/shared/sysdep/ptrace_64.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
#define UPT_SYSCALL_ARG5(r) UPT_R8(r)
5858
#define UPT_SYSCALL_ARG6(r) UPT_R9(r)
5959

60-
static inline void arch_init_registers(int pid)
61-
{
62-
}
60+
extern void arch_init_registers(int pid);
6361

6462
#endif

‎arch/x86/um/signal.c‎

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,16 @@ static int copy_sc_from_user(struct pt_regs *regs,
225225
} else
226226
#endif
227227
{
228-
struct user_i387_struct fp;
229-
230-
err = copy_from_user(&fp, (void *)sc.fpstate,
231-
sizeof(struct user_i387_struct));
228+
err = copy_from_user(regs->regs.fp, (void *)sc.fpstate,
229+
sizeof(struct _xstate));
232230
if (err)
233231
return 1;
234-
235-
err = restore_fp_registers(pid, (unsigned long *) &fp);
236-
if (err < 0) {
237-
printk(KERN_ERR "copy_sc_from_user - "
238-
"restore_fp_registers failed, errno = %d\n",
239-
-err);
240-
return 1;
241-
}
242232
}
243233
return 0;
244234
}
245235

246236
static int copy_sc_to_user(struct sigcontext __user *to,
247-
struct _fpstate __user *to_fp, struct pt_regs *regs,
237+
struct _xstate __user *to_fp, struct pt_regs *regs,
248238
unsigned long mask)
249239
{
250240
struct sigcontext sc;
@@ -310,25 +300,22 @@ static int copy_sc_to_user(struct sigcontext __user *to,
310300
return 1;
311301
}
312302

313-
err = convert_fxsr_to_user(to_fp, &fpx);
303+
err = convert_fxsr_to_user(&to_fp->fpstate, &fpx);
314304
if (err)
315305
return 1;
316306

317-
err |= __put_user(fpx.swd, &to_fp->status);
318-
err |= __put_user(X86_FXSR_MAGIC, &to_fp->magic);
307+
err |= __put_user(fpx.swd, &to_fp->fpstate.status);
308+
err |= __put_user(X86_FXSR_MAGIC, &to_fp->fpstate.magic);
319309
if (err)
320310
return 1;
321311

322-
if (copy_to_user(&to_fp->_fxsr_env[0], &fpx,
312+
if (copy_to_user(&to_fp->fpstate._fxsr_env[0], &fpx,
323313
sizeof(struct user_fxsr_struct)))
324314
return 1;
325315
} else
326316
#endif
327317
{
328-
struct user_i387_struct fp;
329-
330-
err = save_fp_registers(pid, (unsigned long *) &fp);
331-
if (copy_to_user(to_fp, &fp, sizeof(struct user_i387_struct)))
318+
if (copy_to_user(to_fp, regs->regs.fp, sizeof(struct _xstate)))
332319
return 1;
333320
}
334321

@@ -337,7 +324,7 @@ static int copy_sc_to_user(struct sigcontext __user *to,
337324

338325
#ifdef CONFIG_X86_32
339326
static int copy_ucontext_to_user(struct ucontext __user *uc,
340-
struct _fpstate __user *fp, sigset_t *set,
327+
struct _xstate __user *fp, sigset_t *set,
341328
unsigned long sp)
342329
{
343330
int err = 0;
@@ -353,7 +340,7 @@ struct sigframe
353340
char __user *pretcode;
354341
int sig;
355342
struct sigcontext sc;
356-
struct _fpstate fpstate;
343+
struct _xstate fpstate;
357344
unsigned long extramask[_NSIG_WORDS-1];
358345
char retcode[8];
359346
};
@@ -366,7 +353,7 @@ struct rt_sigframe
366353
void __user *puc;
367354
struct siginfo info;
368355
struct ucontext uc;
369-
struct _fpstate fpstate;
356+
struct _xstate fpstate;
370357
char retcode[8];
371358
};
372359

@@ -495,7 +482,7 @@ struct rt_sigframe
495482
char __user *pretcode;
496483
struct ucontext uc;
497484
struct siginfo info;
498-
struct _fpstate fpstate;
485+
struct _xstate fpstate;
499486
};
500487

501488
int setup_signal_stack_si(unsigned long stack_top, struct ksignal *ksig,

‎arch/x86/um/user-offsets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void foo(void)
5050
DEFINE(HOST_GS, GS);
5151
DEFINE(HOST_ORIG_AX, ORIG_EAX);
5252
#else
53-
DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
53+
DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
5454
DEFINE_LONGS(HOST_BX, RBX);
5555
DEFINE_LONGS(HOST_CX, RCX);
5656
DEFINE_LONGS(HOST_DI, RDI);

0 commit comments

Comments
 (0)