All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Andy Lutomirski <luto@kernel.org>, X86 ML <x86@kernel.org>,
	Borislav Petkov <bp@alien8.de>, Andi Kleen <andi@firstfloor.org>,
	lkml@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>,
	stable <stable@vger.kernel.org>
Subject: Re: [PATCH] x86/traps: Don't for in_interrupt() to return true in IST handlers
Date: Tue, 24 May 2016 19:09:34 +0200	[thread overview]
Message-ID: <20160524170934.GD15189@worktop.bitpit.net> (raw)
In-Reply-To: <CALCETrUYrh8LweJBsmDtC4p+S_==n4Y4aw=PGWQ43jQ-PyPP7g@mail.gmail.com>

On Tue, May 24, 2016 at 08:43:57AM -0700, Andy Lutomirski wrote:
> > So this has implications for code like
> > kernel/events/internal.h:get_recursion_context() and
> > kernel/trace/trace.c:get_trace_buf().
> >
> > Which use a sequence of: in_nmi(), in_irq(), in_softirq() to pick 1 out
> > of 4 possible contexts.
> >
> > I would really like the Changelog to reflect on this. The current code
> > will have ISTs land in in_irq(), with this chance, not so much.
> 
> I can change the changelog.

This is basically all I'm asking.

> > Now ISTs as a whole invalidate the whole 'we have only 4 contexts' and
> > the mapping back to those 4 is going to be somewhat arbitrary I suspect,
> > but changes like this should be very much aware of these things. And
> > make an explicit choice.
> 
> I'm not so comfortable with trying to make any particular guarantees
> about what all the in_xyz() things will return for different entry
> types and how they nest.  For example, debug can nest inside itself
> quite easily (at one point I even had a user program to force it to
> happen) -- this can trigger when a watchpoint nests inside a
> single-step trap, and it can also happen when a watchpoint handler is
> interrupted by an NMI than then recursively triggers the watchpoint.
> The latter could easily result in nested NMIs that are directly
> visible to the trace or event code.
> 
> On x86, there's also MCE, which is NMI-ish, and NMI and MCE can freely
> nest inside each other.  (Blech.)

Right; all the nesting possibilities are endless and insane. And I don't
think it makes sense to try and enumerate them all and worse; expose
this to generic code.

I think having the 4: task, softirq, hardirq, nmi is fine. We just need
to be a little careful with how we map to them, that we don't wreck some
common situation and suddenly start loosing trace data.

> Would it make more sense to adjust the trace code to have a percpu
> nesting count and to match up get_trace_buf with put_trace_buf to
> decrement the count?  The event code looks like the same thing could
> happen.

We have, but its coupled with static storage, such as to avoid having to
do it on stack or *horror* dynamically allocate.

So in order to protect these resource we have the per context nesting
count.

> Also, on further reflection, I'm going to get rid of the 3* hack.

Makes sense.

  reply	other threads:[~2016-05-24 17:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24  3:57 [PATCH] x86/traps: Don't for in_interrupt() to return true in IST handlers Andy Lutomirski
2016-05-24  8:59 ` Peter Zijlstra
2016-05-24  9:36   ` Borislav Petkov
2016-05-24  9:51     ` Peter Zijlstra
2016-05-24 15:43   ` Andy Lutomirski
2016-05-24 17:09     ` Peter Zijlstra [this message]
2016-05-24 18:54       ` Andy Lutomirski

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=20160524170934.GD15189@worktop.bitpit.net \
    --to=peterz@infradead.org \
    --cc=andi@firstfloor.org \
    --cc=bp@alien8.de \
    --cc=lkml@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=oleg@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.