From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226ZkxjVOfnn6TFFLRit2J8/m4oKGOJ/jcMutZ//WGfTeFlxfO5QpQtTnEiIcjg3l254RYPR ARC-Seal: i=1; a=rsa-sha256; t=1516908767; cv=none; d=google.com; s=arc-20160816; b=HKGppRPtBk4BoZLEtZ32qr2x7ESF2fuU73Hgvk4LfMbbhEYXWoVJ3w8q7tPXYjnRwk 923ihJZcVZoS0KPewNTPU/UC26bjxH1yl61vodzAOvmP+vRtbUkuDpjtdN3bYybrOuI8 lVjL3zSf5QQQMeZi2JcDb21tzB9gUhozNnv+32H3eZ1LypG4shryGPHs1JV2+saI3W0a XtZh33f8JU8XVejyChBu0dS6Mv1F2RXJE43YvV31BHZsnkEXe63f8ysTSjmmhGlE1ac5 q4Mq12u+uOFgzAsahqJt9uCCBiipcmaOqW/pzjwsD9c+nAZ+FwEo1rQPkOK51PB0v5Wu aepQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :arc-authentication-results; bh=Em7wVtAqoeUHvrZO00tFR0z9QjpyRrOLZ4HtJRYspDg=; b=DB/OTi1Hd6T/rJHtRRF4r162RAP2E3FM4Su2TIGDupWh/bt2XB1b3m1N0xgpqYmDl/ xaYdM8MkGLQAESptkcMqePUz+yjl0Yoo/WwiXizKIgNAtf3IUUlVul9zRAfzHwxDvmdz rUsTJId0EGb4ey5Am+IuR9L+91xFKpBS2HlAjgD4inQ7U38q9S7QboKvsWaiUbb0w6rv +z9d7EnBIk8i9QyR3D6rkQC6ARqRegBKH5zP+/1ilZZzIhYRrqQOUZq2lnzzel9yBjcm 0J7P9mTQ03NCvIX6AorYq0sUlky7NY6BxcDhPq1dKPu28w2dT4IlpFO3sZRbrE/t3qxo XrCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of tim.c.chen@linux.intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=tim.c.chen@linux.intel.com Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of tim.c.chen@linux.intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=tim.c.chen@linux.intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,413,1511856000"; d="scan'208";a="13492916" Subject: Re: [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process To: Peter Zijlstra , Andy Lutomirski Cc: Arjan van de Ven , LKML , KarimAllah Ahmed , Andi Kleen , Andrea Arcangeli , Ashok Raj , Asit Mallick , Borislav Petkov , Dan Williams , Dave Hansen , David Woodhouse , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , Joerg Roedel , Jun Nakajima , Laura Abbott , Linus Torvalds , Masami Hiramatsu , Paolo Bonzini , Radim Krcmar , Thomas Gleixner , Tom Lendacky , X86 ML References: <20180125085820.GV2228@hirez.programming.kicks-ass.net> <20180125092233.GE2295@hirez.programming.kicks-ass.net> <86541aca-8de7-163d-b620-083dddf29184@linux.intel.com> <20180125135055.GK2249@hirez.programming.kicks-ass.net> <20180125164139.GM2269@hirez.programming.kicks-ass.net> <20180125181852.GL2249@hirez.programming.kicks-ass.net> From: Tim Chen Message-ID: Date: Thu, 25 Jan 2018 11:32:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <20180125181852.GL2249@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590523944221221739?= X-GMAIL-MSGID: =?utf-8?q?1590594127887650342?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On 01/25/2018 10:18 AM, Peter Zijlstra wrote: > On Thu, Jan 25, 2018 at 09:04:21AM -0800, Andy Lutomirski wrote: >> I haven't tried to fully decipher the patch, but I think the idea is >> wrong. (I think it's the same wrong idea that Rik and I both had and >> that I got into Linus' tree for a while...) The problem is that it's >> not actually correct to run indefinitely in kernel mode using stale >> cached page table data. The stale PTEs themselves are fine, but the >> stale intermediate translations can cause the CPU to speculatively >> load complete garbage into the TLB, and that's bad (and causes MCEs on >> AMD CPUs). > > Urggh.. indeed :/ > >> I think we only really have two choices: tlb_defer_switch_to_init_mm() >> == true and tlb_defer_switch_to_init_mm() == false. The current >> heuristic is to not defer if we have PCID, because loading CR3 is >> reasonably fast. > > I just _really_ _really_ hate idle drivers doing leave_mm(). I don't > suppose limiting the !IPI case to just the idle case would be correct > either, because between waking from idle and testing our 'should I have > invalidated' bit it can (however unlikely) speculate into stale TLB > entries too.. > > Peter, This patch is not ideal as it comes with the caveats that patch 2 tries to close. I put it out here to see if it can prompt people to come up with a better solution. Keeping active_mm around would have been cleaner but it looks like there are issues that Andy mentioned. The "A -> idle -> A" case would not trigger IBPB if tlb_defer_switch_to_init_mm() is true (non pcid) as we does not change the mm. This patch tries to address the case when we do switch to init_mm and back. Do you still have objections to the approach in this patch to save the last active mm before switching to init_mm? Tim