mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-26 05:40:53 +07:00
x86: fix math_emu register frame access
do_device_not_available() is the handler for #NM and it declares that it takes a unsigned long and calls math_emu(), which takes a long argument and surprisingly expects the stack frame starting at the zero argument would match struct math_emu_info, which isn't true regardless of configuration in the current code. This patch makes do_device_not_available() take struct pt_regs like other exception handlers and initialize struct math_emu_info with pointer to it and pass pointer to the math_emu_info to math_emulate() like normal C functions do. This way, unless gcc makes a copy of struct pt_regs in do_device_not_available(), the register frame is correctly accessed regardless of kernel configuration or compiler used. This doesn't fix all math_emu problems but it at least gets it somewhat working. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
ae6af41f5a
commit
d315760ffa
@ -11,8 +11,8 @@
|
|||||||
struct math_emu_info {
|
struct math_emu_info {
|
||||||
long ___orig_eip;
|
long ___orig_eip;
|
||||||
union {
|
union {
|
||||||
struct pt_regs regs;
|
struct pt_regs *regs;
|
||||||
struct kernel_vm86_regs vm86;
|
struct kernel_vm86_regs *vm86;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
#endif /* _ASM_X86_MATH_EMU_H */
|
#endif /* _ASM_X86_MATH_EMU_H */
|
||||||
|
@ -41,7 +41,7 @@ dotraplinkage void do_int3(struct pt_regs *, long);
|
|||||||
dotraplinkage void do_overflow(struct pt_regs *, long);
|
dotraplinkage void do_overflow(struct pt_regs *, long);
|
||||||
dotraplinkage void do_bounds(struct pt_regs *, long);
|
dotraplinkage void do_bounds(struct pt_regs *, long);
|
||||||
dotraplinkage void do_invalid_op(struct pt_regs *, long);
|
dotraplinkage void do_invalid_op(struct pt_regs *, long);
|
||||||
dotraplinkage void do_device_not_available(struct pt_regs *, long);
|
dotraplinkage void do_device_not_available(struct pt_regs);
|
||||||
dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *, long);
|
dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *, long);
|
||||||
dotraplinkage void do_invalid_TSS(struct pt_regs *, long);
|
dotraplinkage void do_invalid_TSS(struct pt_regs *, long);
|
||||||
dotraplinkage void do_segment_not_present(struct pt_regs *, long);
|
dotraplinkage void do_segment_not_present(struct pt_regs *, long);
|
||||||
@ -77,7 +77,7 @@ extern int panic_on_unrecovered_nmi;
|
|||||||
extern int kstack_depth_to_print;
|
extern int kstack_depth_to_print;
|
||||||
|
|
||||||
void math_error(void __user *);
|
void math_error(void __user *);
|
||||||
asmlinkage void math_emulate(long);
|
void math_emulate(struct math_emu_info *);
|
||||||
#ifdef CONFIG_X86_32
|
#ifdef CONFIG_X86_32
|
||||||
unsigned long patch_espfix_desc(unsigned long, unsigned long);
|
unsigned long patch_espfix_desc(unsigned long, unsigned long);
|
||||||
#else
|
#else
|
||||||
|
@ -896,7 +896,7 @@ asmlinkage void math_state_restore(void)
|
|||||||
EXPORT_SYMBOL_GPL(math_state_restore);
|
EXPORT_SYMBOL_GPL(math_state_restore);
|
||||||
|
|
||||||
#ifndef CONFIG_MATH_EMULATION
|
#ifndef CONFIG_MATH_EMULATION
|
||||||
asmlinkage void math_emulate(long arg)
|
void math_emulate(struct math_emu_info *info)
|
||||||
{
|
{
|
||||||
printk(KERN_EMERG
|
printk(KERN_EMERG
|
||||||
"math-emulation not enabled and no coprocessor found.\n");
|
"math-emulation not enabled and no coprocessor found.\n");
|
||||||
@ -906,16 +906,19 @@ asmlinkage void math_emulate(long arg)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_MATH_EMULATION */
|
#endif /* CONFIG_MATH_EMULATION */
|
||||||
|
|
||||||
dotraplinkage void __kprobes
|
dotraplinkage void __kprobes do_device_not_available(struct pt_regs regs)
|
||||||
do_device_not_available(struct pt_regs *regs, long error)
|
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_X86_32
|
#ifdef CONFIG_X86_32
|
||||||
if (read_cr0() & X86_CR0_EM) {
|
if (read_cr0() & X86_CR0_EM) {
|
||||||
conditional_sti(regs);
|
struct math_emu_info info = { };
|
||||||
math_emulate(0);
|
|
||||||
|
conditional_sti(®s);
|
||||||
|
|
||||||
|
info.regs = ®s;
|
||||||
|
math_emulate(&info);
|
||||||
} else {
|
} else {
|
||||||
math_state_restore(); /* interrupts still off */
|
math_state_restore(); /* interrupts still off */
|
||||||
conditional_sti(regs);
|
conditional_sti(®s);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
math_state_restore();
|
math_state_restore();
|
||||||
|
@ -131,7 +131,7 @@ u_char emulating = 0;
|
|||||||
static int valid_prefix(u_char *Byte, u_char __user ** fpu_eip,
|
static int valid_prefix(u_char *Byte, u_char __user ** fpu_eip,
|
||||||
overrides * override);
|
overrides * override);
|
||||||
|
|
||||||
asmlinkage void math_emulate(long arg)
|
void math_emulate(struct math_emu_info *info)
|
||||||
{
|
{
|
||||||
u_char FPU_modrm, byte1;
|
u_char FPU_modrm, byte1;
|
||||||
unsigned short code;
|
unsigned short code;
|
||||||
@ -161,7 +161,7 @@ asmlinkage void math_emulate(long arg)
|
|||||||
RE_ENTRANT_CHECK_ON;
|
RE_ENTRANT_CHECK_ON;
|
||||||
#endif /* RE_ENTRANT_CHECKING */
|
#endif /* RE_ENTRANT_CHECKING */
|
||||||
|
|
||||||
SETUP_DATA_AREA(arg);
|
FPU_info = info;
|
||||||
|
|
||||||
FPU_ORIG_EIP = FPU_EIP;
|
FPU_ORIG_EIP = FPU_EIP;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ extern void ffreep(void);
|
|||||||
extern void fst_i_(void);
|
extern void fst_i_(void);
|
||||||
extern void fstp_i(void);
|
extern void fstp_i(void);
|
||||||
/* fpu_entry.c */
|
/* fpu_entry.c */
|
||||||
asmlinkage extern void math_emulate(long arg);
|
extern void math_emulate(struct math_emu_info *info);
|
||||||
extern void math_abort(struct math_emu_info *info, unsigned int signal);
|
extern void math_abort(struct math_emu_info *info, unsigned int signal);
|
||||||
/* fpu_etc.c */
|
/* fpu_etc.c */
|
||||||
extern void FPU_etc(void);
|
extern void FPU_etc(void);
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
|
|
||||||
/* This sets the pointer FPU_info to point to the argument part
|
|
||||||
of the stack frame of math_emulate() */
|
|
||||||
#define SETUP_DATA_AREA(arg) FPU_info = (struct math_emu_info *) &arg
|
|
||||||
|
|
||||||
/* s is always from a cpu register, and the cpu does bounds checking
|
/* s is always from a cpu register, and the cpu does bounds checking
|
||||||
* during register load --> no further bounds checks needed */
|
* during register load --> no further bounds checks needed */
|
||||||
#define LDT_DESCRIPTOR(s) (((struct desc_struct *)current->mm->context.ldt)[(s) >> 3])
|
#define LDT_DESCRIPTOR(s) (((struct desc_struct *)current->mm->context.ldt)[(s) >> 3])
|
||||||
@ -38,12 +34,12 @@
|
|||||||
#define I387 (current->thread.xstate)
|
#define I387 (current->thread.xstate)
|
||||||
#define FPU_info (I387->soft.info)
|
#define FPU_info (I387->soft.info)
|
||||||
|
|
||||||
#define FPU_CS (*(unsigned short *) &(FPU_info->regs.cs))
|
#define FPU_CS (*(unsigned short *) &(FPU_info->regs->cs))
|
||||||
#define FPU_SS (*(unsigned short *) &(FPU_info->regs.ss))
|
#define FPU_SS (*(unsigned short *) &(FPU_info->regs->ss))
|
||||||
#define FPU_DS (*(unsigned short *) &(FPU_info->regs.ds))
|
#define FPU_DS (*(unsigned short *) &(FPU_info->regs->ds))
|
||||||
#define FPU_EAX (FPU_info->regs.ax)
|
#define FPU_EAX (FPU_info->regs->ax)
|
||||||
#define FPU_EFLAGS (FPU_info->regs.flags)
|
#define FPU_EFLAGS (FPU_info->regs->flags)
|
||||||
#define FPU_EIP (FPU_info->regs.ip)
|
#define FPU_EIP (FPU_info->regs->ip)
|
||||||
#define FPU_ORIG_EIP (FPU_info->___orig_eip)
|
#define FPU_ORIG_EIP (FPU_info->___orig_eip)
|
||||||
|
|
||||||
#define FPU_lookahead (I387->soft.lookahead)
|
#define FPU_lookahead (I387->soft.lookahead)
|
||||||
|
@ -29,43 +29,43 @@
|
|||||||
#define FPU_WRITE_BIT 0x10
|
#define FPU_WRITE_BIT 0x10
|
||||||
|
|
||||||
static int reg_offset[] = {
|
static int reg_offset[] = {
|
||||||
offsetof(struct math_emu_info, regs.ax),
|
offsetof(struct pt_regs, ax),
|
||||||
offsetof(struct math_emu_info, regs.cx),
|
offsetof(struct pt_regs, cx),
|
||||||
offsetof(struct math_emu_info, regs.dx),
|
offsetof(struct pt_regs, dx),
|
||||||
offsetof(struct math_emu_info, regs.bx),
|
offsetof(struct pt_regs, bx),
|
||||||
offsetof(struct math_emu_info, regs.sp),
|
offsetof(struct pt_regs, sp),
|
||||||
offsetof(struct math_emu_info, regs.bp),
|
offsetof(struct pt_regs, bp),
|
||||||
offsetof(struct math_emu_info, regs.si),
|
offsetof(struct pt_regs, si),
|
||||||
offsetof(struct math_emu_info, regs.di)
|
offsetof(struct pt_regs, di)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REG_(x) (*(long *)(reg_offset[(x)]+(u_char *) FPU_info))
|
#define REG_(x) (*(long *)(reg_offset[(x)] + (u_char *)FPU_info->regs))
|
||||||
|
|
||||||
static int reg_offset_vm86[] = {
|
static int reg_offset_vm86[] = {
|
||||||
offsetof(struct math_emu_info, regs.cs),
|
offsetof(struct pt_regs, cs),
|
||||||
offsetof(struct math_emu_info, vm86.ds),
|
offsetof(struct kernel_vm86_regs, ds),
|
||||||
offsetof(struct math_emu_info, vm86.es),
|
offsetof(struct kernel_vm86_regs, es),
|
||||||
offsetof(struct math_emu_info, vm86.fs),
|
offsetof(struct kernel_vm86_regs, fs),
|
||||||
offsetof(struct math_emu_info, vm86.gs),
|
offsetof(struct kernel_vm86_regs, gs),
|
||||||
offsetof(struct math_emu_info, regs.ss),
|
offsetof(struct pt_regs, ss),
|
||||||
offsetof(struct math_emu_info, vm86.ds)
|
offsetof(struct kernel_vm86_regs, ds)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define VM86_REG_(x) (*(unsigned short *) \
|
#define VM86_REG_(x) (*(unsigned short *) \
|
||||||
(reg_offset_vm86[((unsigned)x)]+(u_char *) FPU_info))
|
(reg_offset_vm86[((unsigned)x)] + (u_char *)FPU_info->regs))
|
||||||
|
|
||||||
static int reg_offset_pm[] = {
|
static int reg_offset_pm[] = {
|
||||||
offsetof(struct math_emu_info, regs.cs),
|
offsetof(struct pt_regs, cs),
|
||||||
offsetof(struct math_emu_info, regs.ds),
|
offsetof(struct pt_regs, ds),
|
||||||
offsetof(struct math_emu_info, regs.es),
|
offsetof(struct pt_regs, es),
|
||||||
offsetof(struct math_emu_info, regs.fs),
|
offsetof(struct pt_regs, fs),
|
||||||
offsetof(struct math_emu_info, regs.ds), /* dummy, not saved on stack */
|
offsetof(struct pt_regs, ds), /* dummy, not saved on stack */
|
||||||
offsetof(struct math_emu_info, regs.ss),
|
offsetof(struct pt_regs, ss),
|
||||||
offsetof(struct math_emu_info, regs.ds)
|
offsetof(struct pt_regs, ds)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PM_REG_(x) (*(unsigned short *) \
|
#define PM_REG_(x) (*(unsigned short *) \
|
||||||
(reg_offset_pm[((unsigned)x)]+(u_char *) FPU_info))
|
(reg_offset_pm[((unsigned)x)] + (u_char *)FPU_info->regs))
|
||||||
|
|
||||||
/* Decode the SIB byte. This function assumes mod != 0 */
|
/* Decode the SIB byte. This function assumes mod != 0 */
|
||||||
static int sib(int mod, unsigned long *fpu_eip)
|
static int sib(int mod, unsigned long *fpu_eip)
|
||||||
@ -346,34 +346,34 @@ void __user *FPU_get_address_16(u_char FPU_modrm, unsigned long *fpu_eip,
|
|||||||
}
|
}
|
||||||
switch (rm) {
|
switch (rm) {
|
||||||
case 0:
|
case 0:
|
||||||
address += FPU_info->regs.bx + FPU_info->regs.si;
|
address += FPU_info->regs->bx + FPU_info->regs->si;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
address += FPU_info->regs.bx + FPU_info->regs.di;
|
address += FPU_info->regs->bx + FPU_info->regs->di;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
address += FPU_info->regs.bp + FPU_info->regs.si;
|
address += FPU_info->regs->bp + FPU_info->regs->si;
|
||||||
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
||||||
addr_modes.override.segment = PREFIX_SS_;
|
addr_modes.override.segment = PREFIX_SS_;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
address += FPU_info->regs.bp + FPU_info->regs.di;
|
address += FPU_info->regs->bp + FPU_info->regs->di;
|
||||||
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
||||||
addr_modes.override.segment = PREFIX_SS_;
|
addr_modes.override.segment = PREFIX_SS_;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
address += FPU_info->regs.si;
|
address += FPU_info->regs->si;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
address += FPU_info->regs.di;
|
address += FPU_info->regs->di;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
address += FPU_info->regs.bp;
|
address += FPU_info->regs->bp;
|
||||||
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
if (addr_modes.override.segment == PREFIX_DEFAULT)
|
||||||
addr_modes.override.segment = PREFIX_SS_;
|
addr_modes.override.segment = PREFIX_SS_;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
address += FPU_info->regs.bx;
|
address += FPU_info->regs->bx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user