Re: NMI vs #PF clash

From: Steven Rostedt
Date: Wed May 23 2012 - 04:32:23 EST


On Tue, 2012-05-22 at 21:26 -0400, Brian Gerst wrote:

> > @@ -1734,6 +1748,13 @@ end_repeat_nmi:
> > nmi_swapgs:
> > SWAPGS_UNSAFE_STACK
> > nmi_restore:
> > + /* Test if the cr2 reg changed */
> > + movq ORIG_RAX-R15+(12*8)(%rsp), %rdx
> > + movq %cr2, %rcx
> > + cmp %rdx, %rcx
> > + je 1f
> > + movq %rdx, %cr2
> > +1:
> > RESTORE_ALL 8
> > /* Clear the NMI executing stack variable */
> > movq $0, 10*8(%rsp)
>
> You could save cr2 in a callee-saved register (like r12) instead of
> putting it on the stack.
>

You know, I thought about that but decided against it. My rational was
that I wanted the store of the cr2 in the first NMI where it would do it
again if it had to do a repeated NMI. At first I thought that a repeated
NMI would corrupt the cr2, but that is not the case as the cr2 would
have been restored before repeating the NMI.

I guess I also wanted to limit the number of reads of the cr2 as well.
But as repeated NMIs is such a seldom case (requires a fault and then
another NMI to come in), that this optimization is practically useless.

I agree, it would be better to just use one of the non-clobbered regs.


Thanks, I'll try that out and this should make the patch much simpler.


-- Steve


--
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/