2017-11-28 05:23:38

by Andy Lutomirski

[permalink] [raw]
Subject: Re: [PATCH 16/24] x86/mm/kaiser: Use PCID feature to make user and kernel switches faster

On Mon, Nov 27, 2017 at 2:49 AM, Ingo Molnar <[email protected]> wrote:
> From: Dave Hansen <[email protected]>
>
> Short summary: Use x86 PCID feature to avoid flushing the TLB at all
> interrupts and syscalls. Speed them up. Makes context switches
> and TLB flushing slower.

I suspect that, if we actually did it right (by doing a deferred
usermode flush when we switch CR3), it wouldn't make context switches
or TLB flushing slower.

> + /*
> + * On systems with PCIDs, but no INVPCID, the only
> + * way to flush a PCID is a CR3 write. Note that
> + * we use the kernel page tables with the *user*
> + * ASID here.
> + */
> + unsigned long user_asid_flush_cr3;
> + user_asid_flush_cr3 = build_cr3(pgd, user_asid(kern_asid));
> + write_cr3(user_asid_flush_cr3);

This is wrong. If we could atomically switch CR3 and switch it back
without any speculative fills in the mean time, we might be okay, but
that's not what's happening. We could be filling the TLB with
usermode-tagged kernel entries, which is a big no-no.

(And I'm ignoring the fact that this code seems to have forgotten the
"switch back" part.)

> + /*
> + * We do not use PCIDs with KAISER unless we also
> + * have INVPCID. Getting here is unexpected.
> + */
> + WARN_ON_ONCE(1);

Well that's a bummer.

From 1585216414570762682@xxx Mon Nov 27 10:56:20 +0000 2017
X-GM-THRID: 1585216414570762682
X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread