public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Avi Kivity <avi@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@elte.hu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Paul Turner <pjt@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: Re: NMI vs #PF clash
Date: Tue, 22 May 2012 11:22:55 -0400	[thread overview]
Message-ID: <20120522152255.GB25697@Krystal> (raw)
In-Reply-To: <1337698229.13348.46.camel@gandalf.stny.rr.com>

* Steven Rostedt (rostedt@goodmis.org) wrote:
> On Tue, 2012-05-22 at 17:37 +0300, Avi Kivity wrote:
> > > 
> > > 
> > > Is reading it fast? Then we could do a two reads and only write when
> > > needed.
> > 
> > The upside is 70 cycles on one machine, see d3edefc0035669.
> 
> Thanks
> 
> > 
> > 
> > > 
> > > Something like this pseudo assembly
> > >  
> > > 	mov cr2, rax
> > > 	push rax
> > > 
> > > 	call do_nmi
> > > 
> > > 	pop rax
> > > 	mov cr2, rbx
> > > 	cmp rax, rbx
> > > 	be skip
> > > 	mov rax, cr2
> > > skip:
> > > 
> > 
> > 
> > Yes, provided no exceptions can happen at those points.
> 
> Yes, exceptions can only happen in the do_nmi area. There should not be
> any breakpoints or page faults in the assembly code of the NMI handler.
> 
> Now another NMI may come in at any point here, but it will detect that
> it is nested and return without doing anything (but telling this NMI to
> repeat itself).

That should take care of cr2. Those are faraway memories, but I think we
should be careful about pdg_offset too. If we look at x86-64
vmalloc_fault(), we notice that it uses the current task struct:

        WARN_ON_ONCE(in_nmi()); <--- we should take that as a hint ;)

        /*
         * Copy kernel mappings over when needed. This can also
         * happen within a race in page table update. In the later
         * case just flush:
         */
        pgd = pgd_offset(current->active_mm, address);

x86-32 does not have this problem, since it reads the cr3 register to
get the pgd_addr.

x86-64 using the current task can be an issue if the NMI nests over the
scheduler execution.

A few years ago, I posted this patch
http://www.gossamer-threads.com/lists/linux/kernel/1249694?do=post_view_threaded
that tried to fix this by reading cr3 on x86_64. However, after reports
that it caused some x86_64 machines to fail to boot, I removed this
patch from the LTTng patchset. So there was certainly something I missed
back then.

Just food for thoughts,

Thanks,

Mathieu

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2012-05-22 15:23 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 [this message]
2012-05-22 15:33           ` Linus Torvalds
2012-05-22 15:45             ` Avi Kivity
2012-05-22 15:47             ` H. Peter Anvin
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=20120522152255.GB25697@Krystal \
    --to=mathieu.desnoyers@efficios.com \
    --cc=avi@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --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