All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H . Peter Anvin" <hpa@zytor.com>, Borislav Petkov <bp@alien8.de>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 15/24] x86/mm: Allow flushing for future ASID switches
Date: Tue, 28 Nov 2017 12:34:17 -0800	[thread overview]
Message-ID: <CALCETrW3hgNJoP9sMWXBmYiRKten1CJNY6AgCxv1wQdcBfd8pQ@mail.gmail.com> (raw)
In-Reply-To: <20171128190505.pqip2v2ewb3isjhd@hirez.programming.kicks-ass.net>

On Tue, Nov 28, 2017 at 11:05 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> On Tue, Nov 28, 2017 at 10:13:30AM -0800, Dave Hansen wrote:
>> Thanks for looking at this, Peter.  I've been resisting doing this for a
>> bit and it's an embarrassingly small amount of code.
>
> Right, well, its not complete yet, and it might be complete crap :-)
>
>> On 11/28/2017 08:39 AM, Peter Zijlstra wrote:
>> > @@ -220,7 +221,21 @@ For 32-bit we have the following conventions - kernel is built with
>> >  .macro SWITCH_TO_USER_CR3 scratch_reg:req
>> >     STATIC_JUMP_IF_FALSE .Lend_\@, kaiser_enabled_key, def=1
>> >     mov     %cr3, \scratch_reg
>> > -   ADJUST_USER_CR3 \scratch_reg
>> > +   push    \scratch_reg
>>
>> Do we have a good stack in all the spots that we need to do this?  It
>> may have changed with the trampoline stack, but I'm 100% sure that it
>> wasn't so in the recent past.
>
> Dunno really. I figured I'd give it a go and see what happens. So far
> the machine still works. But I was hoping Andy would have an opinion on
> this.

I thought we had a stack in all these places even before the
trampoline.  There was an issue with *entry*, but I think exit has
always been okay.

>
>> Let me see if I'm reading the assembly right.
>
> Yep, seems you can read asm :-)
>
>
>> > +DECLARE_PER_CPU(unsigned long, __asid_flush);
>>
>> Could we spare enough space to make this something like
>> user_asid_flush_pending_mask?
>
> Yeah, if I can get it all working we'll bikeshed on a name ;-)
>
>> It took me a minute to realize that it was a mask.  Also, since we only
>> have 6 asids, should we bit a bit more stingy with the type?
>
> I picked unsigned long because our bitops (__set_bit in this case, use
> it), and I know we're LE and could simply use a shorter type, but meh.
>
>> It took me a minute to realize that mixing these is still OK, even if
>> the mm associated with the ASID changes.  It's because once the ASID is
>> stale, it doesn't matter *why* it is stale.  Just that the next guy who
>> *uses* it needs to do the flush.  You can do 1,000 tlb flushes, a
>> context switch, a tlb flush and another context switch, but if you only
>> go out to userspace once, you only need 1 ASID flush.  That fits
>> perfectly with this bit that gets set a bunch of times and only cleared
>> once at exit to userspace.
>
> Just so.
>
> I'm now staring at the RESTORE_CR3 stuff, and that appears to be called
> in the NMI handling where the stack is not to be used (if I read it
> right), so that's going to be a little more tricky.

I think it should be fine.  A very old version of the patches had that
problem, but, in -tip, the nmi RESTORE_CR3 is in the fancy
recursion-protected region, and the stack is okay.  The idea is that
we're already on the old (possibly user) CR3 before we do the crazy
recursion-checking bits.  But that's fine, since all that's accessed
there is the IST stack, and that's in the cpu_entry_area and thus safe
regardless of CR3.

Side question: on extremely quick read, you're doing bt then btr.  Why
not just do a single btr and be done with it?  Are you trying to avoid
getting exclusive access to the cacheline when not needed?

  parent reply	other threads:[~2017-11-28 20:34 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 10:48 [PATCH 00/24] x86/mm: Add KAISER support Ingo Molnar
2017-11-27 10:49 ` [PATCH 01/24] x86/mm/kaiser: Disable global pages by default with KAISER Ingo Molnar
2017-11-27 10:49 ` [PATCH 02/24] x86/mm/kaiser: Prepare the x86/entry assembly code for entry/exit CR3 switching Ingo Molnar
2017-11-27 17:31   ` Peter Zijlstra
2017-11-27 17:33     ` Thomas Gleixner
2017-11-27 21:00       ` Peter Zijlstra
2017-11-27 10:49 ` [PATCH 03/24] x86/mm/kaiser: Introduce user-mapped per-CPU areas Ingo Molnar
2017-11-27 10:49 ` [PATCH 04/24] x86/mm/kaiser: Unmap kernel mappings from userspace page tables, core patch Ingo Molnar
2017-11-27 15:39   ` Peter Zijlstra
2017-11-27 17:04     ` Borislav Petkov
2017-11-27 19:17     ` Dave Hansen
2017-11-28 10:34   ` Peter Zijlstra
2017-11-27 10:49 ` [PATCH 05/24] x86/mm/kaiser: Allow NX poison to be set in p4d/pgd Ingo Molnar
2017-11-27 10:49 ` [PATCH 06/24] x86/mm/kaiser: Make sure the static PGDs are 8k in size Ingo Molnar
2017-11-27 10:49 ` [PATCH 07/24] x86/mm/kaiser: Map the CPU entry area Ingo Molnar
2017-11-27 10:49 ` [PATCH 08/24] x86/mm/kaiser: Map the dynamically-allocated LDTs Ingo Molnar
2017-11-29 22:03   ` [08/24] " Guenter Roeck
2017-11-27 10:49 ` [PATCH 09/24] x86/mm/kaiser: Map the espfix structures Ingo Molnar
2017-11-27 10:49 ` [PATCH 10/24] x86/mm/kaiser: Map the entry stack variables Ingo Molnar
2017-11-27 17:22   ` Peter Zijlstra
2017-11-27 17:32     ` Thomas Gleixner
2017-11-27 21:00       ` Peter Zijlstra
2017-11-27 17:29   ` Peter Zijlstra
2017-11-27 17:32     ` Thomas Gleixner
2017-11-27 10:49 ` [PATCH 11/24] x86/mm/kaiser: Map virtually-addressed performance monitoring buffers Ingo Molnar
2017-11-27 10:49 ` [PATCH 12/24] x86/mm: Move the CR3 construction functions to tlbflush.h Ingo Molnar
2017-11-27 10:49 ` [PATCH 13/24] x86/mm: Remove hard-coded ASID limit checks Ingo Molnar
2017-11-27 10:49 ` [PATCH 14/24] x86/mm: Put MMU-to-h/w ASID translation in one place Ingo Molnar
2017-11-27 10:49 ` [PATCH 15/24] x86/mm: Allow flushing for future ASID switches Ingo Molnar
2017-11-28  5:16   ` Andy Lutomirski
2017-11-28  7:32     ` Dave Hansen
2017-11-28 16:39     ` Peter Zijlstra
2017-11-28 16:48       ` Peter Zijlstra
2017-11-28 18:13       ` Dave Hansen
2017-11-28 19:05         ` Peter Zijlstra
2017-11-28 19:36           ` Peter Zijlstra
2017-11-28 20:34           ` Andy Lutomirski [this message]
2017-11-28 20:39             ` Peter Zijlstra
2017-11-28 20:45             ` Peter Zijlstra
2017-11-30 15:40     ` Peter Zijlstra
2017-11-30 15:42       ` Andy Lutomirski
2017-11-30 15:44   ` Peter Zijlstra
2017-11-30 15:51     ` Dave Hansen
2017-11-30 16:18       ` Peter Zijlstra
2017-11-30 18:44         ` Dave Hansen
2017-11-30 18:48           ` Andy Lutomirski
2017-11-30 18:53             ` Dave Hansen
2017-11-30 20:01             ` Peter Zijlstra
2017-11-30 21:51               ` Andy Lutomirski
2017-11-30 18:55           ` Peter Zijlstra
2017-11-30 19:00             ` Dave Hansen
2017-11-30 19:20               ` Peter Zijlstra
2017-11-27 10:49 ` [PATCH 16/24] x86/mm/kaiser: Use PCID feature to make user and kernel switches faster Ingo Molnar
2017-11-28  5:22   ` Andy Lutomirski
2017-11-28  7:52     ` Dave Hansen
2017-11-27 10:49 ` [PATCH 17/24] x86/mm/kaiser: Disable native VSYSCALL Ingo Molnar
2017-11-27 10:49 ` [PATCH 18/24] x86/mm/kaiser: Add Kconfig Ingo Molnar
2017-11-27 10:49 ` [PATCH 19/24] x86/mm/kaiser: Respect disabled CPU features Ingo Molnar
2017-11-27 10:49 ` [PATCH 20/24] x86/mm/kaiser: Simplify disabling of global pages Ingo Molnar
2017-11-27 10:49 ` [PATCH 21/24] x86/mm/dump_pagetables: Check Kaiser shadow page table for WX pages Ingo Molnar
2017-11-27 10:49 ` [PATCH 22/24] x86/mm/debug_pagetables: Allow dumping current pagetables Ingo Molnar
2017-11-27 10:49 ` [PATCH 23/24] x86/mm/kaiser: Add boot time disable switch Ingo Molnar
2017-11-27 10:49 ` [PATCH 24/24] x86/mm/kaiser: Use the other page_table_lock pattern Ingo Molnar
2017-11-27 13:51 ` [PATCH 00/24] x86/mm: Add KAISER support Borislav Petkov
2017-11-27 13:57   ` Thomas Gleixner
2017-11-27 13:59     ` Borislav Petkov
2017-11-27 14:03       ` Ingo Molnar
2017-11-27 14:08         ` Ingo Molnar
2017-11-27 19:43 ` Linus Torvalds
2017-11-27 20:01   ` Linus Torvalds

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=CALCETrW3hgNJoP9sMWXBmYiRKten1CJNY6AgCxv1wQdcBfd8pQ@mail.gmail.com \
    --to=luto@amacapital.net \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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 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.