From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x22546GjBpqkpqBcaBfz+C1aQmCGxdqbNkLd58prGx4RWS/LL+iN/2ddt30P+KNYYwMjQraPB ARC-Seal: i=1; a=rsa-sha256; t=1516913196; cv=none; d=google.com; s=arc-20160816; b=EbvdpsExuF1k4VuP9nHc5HEdDKf5Dl9bpk+YaqymbzBzBh8pQ8LxnnoCZPMtiPKCnB 2XH/vAz1pDET5qYLaS8K3nSzQlp7j0Ttat8j3TSs1PIJ6f7hKt1F7GQRgGf2mqhtfdD9 GlU5hrYUKTzBIq5ne2FEK+IoxVUI9TI5Ghfs6lFSBm6tq9qsKeRYfVQVbW/gCtHRhwHv nmPoGsu05rPe7vwQdZdO8ZlwZOeYErvpgn8rlJbJPwA4DMB6X4tvLEtCVn11NG5WiGOH gXGXBMtbt39g61f28xsFBGq380d60OVAqjLYHaGeOdTb/B81oS/o919bJRMHRAcEGwYg srPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=VFe9oGhvVlc7Tlvy7rbVMV1qhLBpahgG984CbZIvz2c=; b=Z3vnE+eJSvsAfeeDKbfonQMz+/sTIWdT0HYJB8DeO63U3d1e1MFcbjbDk8KCLltM1m xv47mfHH8IDqZZK9CkrEHWzS1CQRG5iKHG5QZV0CR5yyxSEN+yRLdstUmrjI5UBg68Lt GION97vyh4t275KcL3tOBJFPDjZbmWyCr/yY2s2SCe9L7CMugfi21ZI2vhqT5rqIH60a TgXRXvCCXPaIjZ2qmg9ctM62ROf349dx91sj4cPLDJPIruHwpM5DBz9m2TGNeJDo9vYM jsbu1VkoB+aH2szIqLiKrQac7ycfWQCUxDoOS9nrn/An6hNeajtvYvTJ8Ji3EGMupiBO obfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Xc2NHS/O; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=peterz@infradead.org Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Xc2NHS/O; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=peterz@infradead.org Date: Thu, 25 Jan 2018 21:46:25 +0100 From: Peter Zijlstra To: Tim Chen Cc: Andy Lutomirski , 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 Subject: Re: [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process Message-ID: <20180125204625.GN2269@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590523944221221739?= X-GMAIL-MSGID: =?utf-8?q?1590598772407280928?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On Thu, Jan 25, 2018 at 11:32:46AM -0800, Tim Chen wrote: > > 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? I still think the existing active_mm is sufficient. Something like: switch_mm() { ... if (prev && next != prev) ibpb(); ... } should work. Because while the idle crud does leave_mm() and PCID does enter_lazy_tlb() and both end up doing: switch_mm(NULL, &init_mm, NULL), nothing there affects tsk->active_mm. So over the "A -> idle -> A" transition, active_mm should actually track what you want.