From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tim Chen Subject: Re: [RFC 04/10] x86/mm: Only flush indirect branches when switching into non dumpable process Date: Mon, 22 Jan 2018 10:29:23 -0800 Message-ID: References: <1516476182-5153-1-git-send-email-karahmed@amazon.de> <1516476182-5153-5-git-send-email-karahmed@amazon.de> <1516482364.9814.18.camel@amazon.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: Andi Kleen , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , Ashok Raj , Asit Mallick , Borislav Petkov , Dan Williams , Dave Hansen , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , Joerg Roedel , Jun Nakajima , Laura Abbott , Linus Torvalds , Masami Hiramatsu , Paolo Bonzini , Peter Zijlstra , KarimAllah Ahmed , linux-kernel@vger.kernel.org Return-path: Received: from mga04.intel.com ([192.55.52.120]:46526 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751113AbeAVS3Y (ORCPT ); Mon, 22 Jan 2018 13:29:24 -0500 In-Reply-To: <1516482364.9814.18.camel@amazon.co.uk> Content-Language: en-US Sender: kvm-owner@vger.kernel.org List-ID: On 01/20/2018 01:06 PM, Woodhouse, David wrote: > On Sat, 2018-01-20 at 20:22 +0100, KarimAllah Ahmed wrote: >> From: Tim Chen > > I think this is probably From: Andi now rather than From: Tim? This change is from Andi. >> 1 file changed, 12 insertions(+), 1 deletion(-) >> >> diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c >> index 304de7d..f64e80c 100644 >> --- a/arch/x86/mm/tlb.c >> +++ b/arch/x86/mm/tlb.c >> @@ -225,8 +225,19 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, >> * Avoid user/user BTB poisoning by flushing the branch predictor >> * when switching between processes. This stops one process from >> * doing Spectre-v2 attacks on another. >> + * >> + * As an optimization: Flush indirect branches only when >> + * switching into processes that disable dumping. >> + * >> + * This will not flush when switching into kernel threads. >> + * But it would flush when switching into idle and back >> + * >> + * It might be useful to have a one-off cache here >> + * to also not flush the idle case, but we would need some >> + * kind of stable sequence number to remember the previous mm. >> */ >> - indirect_branch_prediction_barrier(); >> + if (tsk && tsk->mm && get_dumpable(tsk->mm) != SUID_DUMP_USER) >> + indirect_branch_prediction_barrier(); We could move this close to the cr3 write. The cr3 write provides barrier against unwanted speculation in the above if check. Tim