From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 22 Jan 2019 15:42:17 -0000 Received: from [5.158.153.52] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1glyBs-00088y-3F for speck@linutronix.de; Tue, 22 Jan 2019 16:42:16 +0100 Date: Tue, 22 Jan 2019 16:42:15 +0100 (CET) From: Thomas Gleixner Subject: Re: [PATCH v5 12/27] MDSv5 6 In-Reply-To: Message-ID: References: <697a8918b8203734d1e101b12db7c62f41e7b5de.1547858934.git.ak@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII To: speck@linutronix.de List-ID: On Tue, 22 Jan 2019, speck for Thomas Gleixner wrote: > On Fri, 18 Jan 2019, speck for Andi Kleen wrote: > > void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p); > > @@ -29,6 +30,30 @@ static inline void switch_to_extra(struct task_struct *prev, > > } > > } > > > > + /* > > + * When we switch to a different process, or we switch > > + * from a kernel thread, clear the CPU buffers on next kernel exit. > > + * > > + * This has to be here because switch_mm doesn't get > > + * called in the kernel thread case. That's true, but enter_lazy_tlb() is called and there exists already an indicator that it switched from a user space task to a kernel task: cpu_tlbstate.is_lazy, which is evaluated in the next invocation of switch_mm_irqs_off(). So the question is, whether something like this makes sense: - Have some indicator in cpu_tlbstate that switching is due cpu_tlbstate.tif_flags and use that TIF bit. In the sys_exit() path do cached_flags = READ_ONCE(ti->flags); if (static_key_enabled(mds_cond_clear)) cached_flags |= READ_ONCE(cpu_tlbstate.tif_flags); That's an extra read, but especially with PTI this is cache hot anyway and the store of the flag is done in switch_mm_irqs_off(). Haven't thought it through, but on the first glance this looks simpler and makes the whole thing stick to the CPU instead of playing games with transferring the thread flag on every context switch. Thanks, tglx