All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>,
	X86 ML <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Brian Gerst <brgerst@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>, Willy Tarreau <w@1wt.eu>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe
Date: Sat, 25 Jul 2015 10:59:57 -0700	[thread overview]
Message-ID: <CALCETrVzO86DoMjGarW0J0vwrVQy-0C+BTWGHQo6MctzVMcF6A@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFyXn0zuM4yCD7MQk1Qvxu0MVB1WKgFrrtcKhzhJPSWtQQ@mail.gmail.com>

On Sat, Jul 25, 2015 at 10:56 AM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> On Fri, Jul 24, 2015 at 9:59 PM, Andy Lutomirski <luto@amacapital.net> wrote:
>>
>> And people will give me five new heads if I ignore Linus and do RET
>> even with IF=1, saving 300 cycles?
>
> So I'm still nervous about that "sti; ret" when we're back on the
> original kernel stack that took the original fault or interrupt.  But
> it's probably ok.
>
> Yes, it's irq-safe. But it's not NMI-safe, so if an NMI happens there,
> when the NMI returns, an interrupt might occur there too. But since
> we're back on the original stack where the original fault happened,
> and since interrupts were enabled, I don't see why that would be
> horrible. In theory, we might have a growing stack if this keeps
> happening, but since the only way to get that is to get the NMI in
> that one-instruction window (and apparently on at least _some_
> microarchitectures the sti shadow stops even NMI's), I don't see how
> any kind of unbounded growth would happen.
>
> So.
>
> I think it would work, and it might even be good for "coverage" (ie
> the whole "iret-to-ret-conversion" will not have a lot of testing if
> it only happens for faults with interrupts disabled).
>
> But it still worries me a bit.
>

What if we added something like:

if (regs->ip == ret_after_sti && !user_mode(regs) && (regs->flags &
X86_EFLAGS_IF)) {
  regs->ip--;
  regs->flags &= ~X86_EFLAGS_IF;
}

to do_nmi, do_machine_check, and do_debug (the latter because kernel
breakpoints, damnit)?

--Andy

  reply	other threads:[~2015-07-25 18:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23 22:37 [PATCH 0/3] x86_64: Make int3 non-magical Andy Lutomirski
2015-07-23 22:37 ` [PATCH 1/3] x86/entry/64: Refactor IRQ stacks and make then NMI-safe Andy Lutomirski
2015-07-24  6:08   ` Andy Lutomirski
2015-07-24 10:25     ` Borislav Petkov
2015-07-24 18:02       ` Andy Lutomirski
2015-07-25  4:16         ` Borislav Petkov
2015-07-25  4:28           ` Andy Lutomirski
2015-07-25  4:32             ` Borislav Petkov
2015-07-25  4:59               ` Andy Lutomirski
2015-07-25  8:39                 ` Borislav Petkov
2015-07-25 17:56                 ` Linus Torvalds
2015-07-25 17:59                   ` Andy Lutomirski [this message]
2015-07-25 18:12                     ` Linus Torvalds
2015-08-05  8:59   ` Ingo Molnar
2015-08-05 18:24     ` Andy Lutomirski
2015-08-05 18:27       ` Steven Rostedt
2015-08-05 18:32         ` Andy Lutomirski
2015-08-22 13:55           ` Ingo Molnar
2015-07-23 22:37 ` [PATCH 2/3] x86/entry/64: Teach idtentry to use the IRQ stack Andy Lutomirski
2015-07-23 22:37 ` [PATCH 3/3] x86/entry/64: Move #BP from IST to " Andy Lutomirski
2015-07-24 11:02   ` Borislav Petkov
2015-07-23 22:39 ` [PATCH 0/3] x86_64: Make int3 non-magical 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=CALCETrVzO86DoMjGarW0J0vwrVQy-0C+BTWGHQo6MctzVMcF6A@mail.gmail.com \
    --to=luto@amacapital.net \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=w@1wt.eu \
    --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.