Re: [PATCH 1/3] x86: allow kernel exception fixup for divide errors (#DE)

From: Brian Gerst
Date: Tue Aug 24 2010 - 08:48:06 EST


On Tue, Aug 24, 2010 at 7:10 AM, Avi Kivity <avi@xxxxxxxxxx> wrote:
> KVM wants to emulate the DIV and IDIV instructions by executing them natively;
> this can cause a #DE to be raised.
>
> Allow the exception handling mechanism to process #DE exceptions so KVM can
> catch and process them.
>
> Signed-off-by: Avi Kivity <avi@xxxxxxxxxx>
> ---
> Âarch/x86/kernel/traps.c | Â 10 +++++++++-
> Â1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> index 725ef4d..dd313cf 100644
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -205,7 +205,8 @@ dotraplinkage void do_##name(struct pt_regs *regs, long error_code) \
> Â Â Â Âdo_trap(trapnr, signr, str, regs, error_code, &info); Â Â Â Â Â \
> Â}
>
> -DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error, FPE_INTDIV, regs->ip)
> +static DO_ERROR_INFO(0, SIGFPE, "divide error", divide_error_user,
> + Â Â Â Â Â Â Â Â Â ÂFPE_INTDIV, regs->ip)
> ÂDO_ERROR(4, SIGSEGV, "overflow", overflow)
> ÂDO_ERROR(5, SIGSEGV, "bounds", bounds)
> ÂDO_ERROR_INFO(6, SIGILL, "invalid opcode", invalid_op, ILL_ILLOPN, regs->ip)
> @@ -217,6 +218,13 @@ DO_ERROR(12, SIGBUS, "stack segment", stack_segment)
> Â#endif
> ÂDO_ERROR_INFO(17, SIGBUS, "alignment check", alignment_check, BUS_ADRALN, 0)
>
> +dotraplinkage void do_divide_error(struct pt_regs *regs, long error_code)
> +{
> + Â Â Â if (!user_mode_vm(regs) && fixup_exception(regs))
> + Â Â Â Â Â Â Â return;
> + Â Â Â do_divide_error_user(regs, error_code);
> +}
> +
> Â#ifdef CONFIG_X86_64
> Â/* Runs on IST stack */
> Âdotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)

Kernel mode exceptions should already be handled by do_trap(). This
is unnecessary.

--
Brian Gerst
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/