linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: Rik van Riel <riel@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Markus Trippelsdorf <markus@trippelsdorf.de>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: Current mainline git (24e700e291d52bd2) hangs when building e.g. perf
Date: Sun, 10 Sep 2017 18:46:47 -0700	[thread overview]
Message-ID: <CALCETrU5iZo5_7+cn=NLYws2r8nvu7huxBQOJcMvanGKsFs7+A@mail.gmail.com> (raw)
In-Reply-To: <1505092341.21121.34.camel@redhat.com>

On Sun, Sep 10, 2017 at 6:12 PM, Rik van Riel <riel@redhat.com> wrote:
> On Sat, 2017-09-09 at 12:28 -0700, Andy Lutomirski wrote:
>> -
>> I propose the following fix.  If PCID is on, then, in
>> enter_lazy_tlb(), we switch to init_mm with the no-flush flag set.
>> (And we give init_mm its own dedicated ASID to keep it simple and
>> fast
>> -- no need to use the LRU ASID mapping to assign one
>> dynamically.)  We
>> clear the bit in mm_cpumask.  That is, we more or less just skip the
>> whole lazy TLB optimization and rely on PCID CPUs having reasonably
>> fast CR3 writes.  No extra IPIs.
>
> Avoiding the IPIs is probably what matters the most, especially
> on systems with deep C states, and virtual machines where the
> host may be running something else, causing the IPI service time
> to go through the roof for idle VCPUs.
>
>> Also, sorry Rik, this means your old increased laziness optimization
>> is dead in the water.  It will have exactly the same speculative load
>> problem.
>
> Doesn't a memory barrier solve that speculative load
> problem?
>
> The memory barrier could be added only to the path
> that potentially skips reloading the TLB, under the
> assumption that a memory barrier is cheaper than a
> TLB reload (even with ASID).

No, nothing stops the problematic speculative load.  Here's the issue.
One CPU removes a reference to a page table from a higher-level page
table, flushes, and then frees the page table.  Then it re-allocates
it and writes something unrelated there.  Another CPU that has CR3
pointing to the page hierarchy in question could have a reference to
the freed table in its paging structure cache.  Even if it's
guaranteed to not try to access the addresses in question (because
they're user addresses and the other CPU is in kernel mode, etc), but
there is never a guarantee that the CPU doesn't randomly try to fill
its TLB for the affected addresses.  This results in invalid PTEs in
the TLB, possible accesses using bogus memory types, and maybe even
reads from IO space.

It looks like we actually need to propagate flushes everywhere that
could have references to the flushed range, even if the software won't
access that range.

  reply	other threads:[~2017-09-11  1:47 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05  7:27 Current mainline git (24e700e291d52bd2) hangs when building e.g. perf Markus Trippelsdorf
2017-09-05  8:53 ` Peter Zijlstra
2017-09-05  9:55   ` Markus Trippelsdorf
2017-09-06 12:52     ` Thomas Gleixner
2017-09-06 13:15       ` Markus Trippelsdorf
2017-09-07  6:28         ` Markus Trippelsdorf
2017-09-08  5:35           ` Markus Trippelsdorf
2017-09-08  6:26             ` Thomas Gleixner
2017-09-08  8:05               ` Borislav Petkov
2017-09-08  9:16                 ` Borislav Petkov
2017-09-08  9:48                   ` Markus Trippelsdorf
2017-09-08 10:35                     ` Ingo Molnar
2017-09-08 10:39                       ` Markus Trippelsdorf
2017-09-08 11:30                         ` Markus Trippelsdorf
2017-09-08 16:12                           ` Andy Lutomirski
2017-09-08 17:16                             ` Markus Trippelsdorf
2017-09-08 21:47                               ` Andy Lutomirski
2017-09-08 21:56                                 ` Borislav Petkov
2017-09-08 23:07                                   ` Andy Lutomirski
2017-09-08 23:23                                     ` Linus Torvalds
2017-09-09  0:00                                       ` Andy Lutomirski
2017-09-09  1:05                                         ` Linus Torvalds
2017-09-09  1:39                                           ` Andy Lutomirski
2017-09-09 17:49                                             ` Andy Lutomirski
2017-09-09 18:02                                               ` Linus Torvalds
2017-09-09  6:39                                   ` Markus Trippelsdorf
2017-09-09 10:18                                     ` Borislav Petkov
2017-09-09 11:07                                       ` Markus Trippelsdorf
2017-09-09 13:07                                         ` Borislav Petkov
2017-09-09 13:37                                           ` Markus Trippelsdorf
2017-09-09 13:39                                             ` Markus Trippelsdorf
2017-09-09 14:07                                               ` Borislav Petkov
2017-09-09 14:20                                                 ` Markus Trippelsdorf
2017-09-09 14:33                                                   ` Borislav Petkov
2017-09-09 14:43                                                     ` Markus Trippelsdorf
2017-09-09 16:32                                                       ` Markus Trippelsdorf
2017-09-09 17:05                                                         ` Borislav Petkov
2017-09-09 17:23                                                           ` Markus Trippelsdorf
2017-09-09 17:36                                                             ` Borislav Petkov
2017-09-09 18:14                                                               ` Markus Trippelsdorf
2017-09-09 18:26                                                                 ` Borislav Petkov
2017-09-09 18:46                                                                   ` Markus Trippelsdorf
2017-09-09 19:11                                                                     ` Borislav Petkov
2017-09-09 19:19                                                                       ` Borislav Petkov
2017-09-09 18:26                                                                 ` Linus Torvalds
2017-09-09 18:29                                                                   ` Borislav Petkov
2017-09-09 18:47                                                                     ` Linus Torvalds
2017-09-09 19:09                                                                       ` Borislav Petkov
2017-09-09 19:21                                                                         ` Linus Torvalds
2017-09-09 19:28                                                                         ` Andy Lutomirski
2017-09-09 19:37                                                                           ` Borislav Petkov
2017-09-10  4:42                                                                             ` Andy Lutomirski
2017-09-10 20:22                                                                               ` Peter Zijlstra
2017-09-10 20:25                                                                                 ` Andy Lutomirski
2017-09-17 17:04                                                                               ` Ingo Molnar
2017-09-11  1:12                                                                           ` Rik van Riel
2017-09-11  1:46                                                                             ` Andy Lutomirski [this message]
2017-09-11 15:08                                                                               ` Rik van Riel
2017-09-12  7:14                                                                   ` Markus Trippelsdorf
2017-09-09  8:13                                 ` Markus Trippelsdorf
2017-09-08 14:51                   ` Borislav Petkov

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='CALCETrU5iZo5_7+cn=NLYws2r8nvu7huxBQOJcMvanGKsFs7+A@mail.gmail.com' \
    --to=luto@kernel.org \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus@trippelsdorf.de \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --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;
as well as URLs for NNTP newsgroup(s).