Received: by 10.223.176.46 with SMTP id f43csp1857731wra; Thu, 25 Jan 2018 00:59:11 -0800 (PST) X-Google-Smtp-Source: AH8x2253aZOJTsthVmcBO9S+Kv+IGI5/1xm4f6XiAMCqZFbRH9oGBsZ25B18fIKcZ1uXQF99cjB4 X-Received: by 10.98.247.25 with SMTP id h25mr10401674pfi.162.1516870751266; Thu, 25 Jan 2018 00:59:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516870751; cv=none; d=google.com; s=arc-20160816; b=ejqgnsM9jmezcVdLN2JV6j8GEH3cFSXMv8x75E6pBvOl6x5oeTTlP5WFzkEkewQhPl fBcnPc0g66JNBKzxT9QZvjQ/jN4Eb0SqCBXIw0468tVMKX31bJID/2MDp9b+87euxx9G LezK7U083TZVT0qfwKb2tdxc+8mmI85Bu4Z4plME8DzjWnNfYste3OT5BOyp13lxEqP7 xd2koOQDN01s80Tb6fAVk88J0vLmrlidV54UOnVxXi7PKUAatdzWANxOGWxsdPQf/R1v SG8htHtd77M5lQWDro4TS0cJMgWGejCzLEyXctXzPVH3TA0/Kf3T0sViQyu2ZV1kV/OY n/Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=1hxS/hLXtmTsyKeOk4xM6wIYapyq0S9Al778QhH/Zco=; b=G2OllrQu45GF45Osh8BbAqQ/QnY96LPzJ0SnAVNFPxP0lr6DsGUR3fsYDsM/oum2LS g35wAtjQjqB2XlpgdKUepZ28mkdmBCykI5BnnRGcn3g1ufQp8jYGV8ybJ2RP2e7rLDYh +1lYU8bq9K+GqvlTrju8IWU04UUsUPWkWdnpfzf7XSapH44n6m9d9ncCu/Q8VoaZwlgd cRA6/UraoBRqiKhKwaoa9VvDRq6yDDs4MnIGDi3ZY/RvdB9k/77JnRPCoBpCQTac2qdQ 1O2mcYej0Pk5DgfVzigvLf7WT7aZR42SJeWGL3OVQKfBk8zNuPg4diEvvHge/hsgslXw BHWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=IPwXfIxq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si1294384pgf.611.2018.01.25.00.58.56; Thu, 25 Jan 2018 00:59:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=IPwXfIxq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751409AbeAYI6c (ORCPT + 99 others); Thu, 25 Jan 2018 03:58:32 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:59135 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751295AbeAYI6b (ORCPT ); Thu, 25 Jan 2018 03:58:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1hxS/hLXtmTsyKeOk4xM6wIYapyq0S9Al778QhH/Zco=; b=IPwXfIxqbN+/X4j/w9h8vQnxF f4oN+KIrjwRlPszesEGQawKPJNS96IlXc3KWMkqH7wtyP4pJo7DOj9ndjQUc+MpK9D0lUR+6mwE1s +NE7VdZ+nnaCYgpwSKaG6ygomKf0UJKzB30CDAZ4zksfG3moZD3gnjOaAIkB9kjrbcvc/DLoQiOgh udbhR9HdvE5K7EQg8rPYGOBCiGhK0BKyCfR1Uxl+w1VZo06lE+XRZAtoE2hnRRGLaIYZhw7z2WNDv GEYBZFbTFvznY0f/9jpU1djTaS8e3Zb/tsDTzAIHF832CKUH7JuUIbJhfQCsowNHoY6tGV3/tEH8G nSOAU0k8Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eedMV-0006P9-OL; Thu, 25 Jan 2018 08:58:24 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3805E2029B0FF; Thu, 25 Jan 2018 09:58:20 +0100 (CET) Date: Thu, 25 Jan 2018 09:58:20 +0100 From: Peter Zijlstra To: Tim Chen Cc: linux-kernel@vger.kernel.org, KarimAllah Ahmed , Andi Kleen , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , 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 , rkrcmar@redhat.com, Thomas Gleixner , Tom Lendacky , x86@kernel.org Subject: Re: [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process Message-ID: <20180125085820.GV2228@hirez.programming.kicks-ass.net> References: 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 24, 2018 at 04:36:41PM -0800, Tim Chen wrote: > These two patches provide optimization to skip IBPB for this > commonly encountered scenario: > We could switch to a kernel idle thread and then back to the original > process such as: > process A -> idle -> process A > > In such scenario, we do not have to do IBPB here even though the process > is non-dumpable, as we are switching back to the same process after > an hiatus. > > The cost is to have an extra pointer to track the last mm we were using before > switching to the init_mm used by idle. But avoiding the extra IBPB > is probably worth the extra memory for such a common scenario. So we already track active_mm for kernel threads. I can't immediately see where this fails for idle and your changelog doesn't say. > @@ -229,15 +230,17 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > * As an optimization flush indirect branches only when > * switching into processes that disable dumping. > * > - * This will not flush branches when switching into kernel > - * threads, but it would flush them when switching to the > - * idle thread and back. > + * This will not flush branches when switching into kernel > + * threads. It will also not flush if we switch to idle > + * thread and back to the same process. It will flush if we > + * switch to a different non-dumpable process. Whitespace damage. > * > * 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. > */ > - if (tsk && tsk->mm && get_dumpable(tsk->mm) != SUID_DUMP_USER) > + if (tsk && tsk->mm && (tsk->mm != last) > + && get_dumpable(tsk->mm) != SUID_DUMP_USER) Broken coding style, operators go at the end of the previous line. > indirect_branch_prediction_barrier(); > > if (IS_ENABLED(CONFIG_VMAP_STACK)) {