public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>, Avi Kivity <avi@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
	Paul Turner <pjt@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: Re: NMI vs #PF clash
Date: Tue, 22 May 2012 08:47:21 -0700	[thread overview]
Message-ID: <4FBBB509.4090508@zytor.com> (raw)
In-Reply-To: <CA+55aFwx3QjNB2ckQfsThhDn7=Bm1d=n0Ai8zawbpLKBKgugGg@mail.gmail.com>

> 
> Even better: we could do nothing at all.
> 
> We could just say: let's make sure that any #PF case that can happen
> in #NMI can also be re-done with arbitrary 'error_code' and 'struct
> regs' contents.
> 
> At that point, what could happen is
>  - #PF
>   - NMI
>    - #PF
>     - read cr2 for NMI fault
>     - handle the NMI #PF
>     - return from #PF
>   - return from #NMI
>   - read cr2 for original #PF fault - but get the NMI cr2 again
>   - hande the #PF again (this should be a no-op now)
>   - return from #PF
>  - instruction restart causes new #PF
>   - now we do the original page fault
> 
> So one option is to just make sure that the few cases (just the
> vmalloc area?) that NMI can trigger are all ok to be re-done with
> other state.
> 
> I note that right now we have
> 
>         if (unlikely(fault_in_kernel_space(address))) {
>                 if (!(error_code & (PF_RSVD | PF_USER | PF_PROT))) {
>                         if (vmalloc_fault(address) >= 0)
>                                 return;
> 
> and that the error_code check means that the retried NMI #PF would not
> go through that. But maybe we don't even need that check?
> 
> That error_code thing seems to literally be the only thing that keeps
> us from just re-doing the vmalloc_fault() silently.
> 

This concerns me for two reasons:

- We would have to process "chimera" pagefaults like the one you showed
above, where we have the right struct regs and the right error code, but
the wrong %cr2 pointing to the page fault context.

- Getting all this right, reliable, tested and robust and have it stay
that way for what is effectively a race between multiple events seems
implausible.  I really worry that we'll have subtle failures in the
field when people are using their debugging tools.

As such I'd prefer if NMI would save and restore %cr2, or, alternately,
NMI can save %cr2 and the #PF handler could check if it is in NMI
context and then restore %cr2 -- the latter depends on the #PF handler
being able to hide the cost of a load - test - not-taken branch in the
common case, otherwise that is an obvious lose.

	-hpa


-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.

  parent reply	other threads:[~2012-05-22 15:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-22 12:53 NMI vs #PF clash Avi Kivity
2012-05-22 13:30 ` Steven Rostedt
2012-05-22 13:45   ` Avi Kivity
2012-05-22 14:09     ` Steven Rostedt
2012-05-22 14:20       ` Avi Kivity
2012-05-22 14:27         ` Steven Rostedt
2012-05-22 14:37           ` Avi Kivity
2012-05-22 14:50             ` Steven Rostedt
2012-05-22 15:22               ` Mathieu Desnoyers
2012-05-22 15:33           ` Linus Torvalds
2012-05-22 15:45             ` Avi Kivity
2012-05-22 15:47             ` H. Peter Anvin [this message]
2012-05-23  0:39             ` Steven Rostedt
2012-05-23  1:26               ` Brian Gerst
2012-05-23  8:32                 ` Steven Rostedt
2012-05-23  8:56                 ` Steven Rostedt
2012-06-11  4:22                   ` [tip:x86/debug] x86: Save cr2 in NMI in case NMIs take a page fault tip-bot for Steven Rostedt
2012-06-11  4:24 ` [tip:x86/debug] x86: Save cr2 in NMI in case NMIs take a page fault (for i386) tip-bot for Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FBBB509.4090508@zytor.com \
    --to=hpa@zytor.com \
    --cc=avi@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox