Received: by 10.223.176.46 with SMTP id f43csp2653612wra; Thu, 25 Jan 2018 13:06:01 -0800 (PST) X-Google-Smtp-Source: AH8x224ctfUyIlBk8udo1GahmfXmYfWsADq7ZEoJfvnAQFQLGkk/3EK1cmf+yjwKEkXKtSpiVBkL X-Received: by 10.101.86.201 with SMTP id w9mr13986514pgs.434.1516914361786; Thu, 25 Jan 2018 13:06:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516914361; cv=none; d=google.com; s=arc-20160816; b=WH3GDEf/2cm3sWq/yRZuVLxxuk388qfMYRi+3wWzK87/5ELmabmZrfw//5epF5bjAQ KWC1ohYmqnemBL/bCMcb9LLw51+u3hpuNMMJTrXtcyQJ/YRyuA2jym5YEAw4XRYfPKtU 7CUe/tcAB0pxXHREZKRxzG4ho1zAbaBTkXDsteZoHtn0S5NZF/e2Np/C3Xn2T0dy2kYm DIpf5GTxhmfBRc+Hhz+y0usUBFgnhvqNddD7621EOTgdqEX6yRvNkoy7ggKjxn60FcUQ dlfmI9Svo1tjpstg1ELgaPvAMX0tfutubXToGjMd6GXcje6CMxC2eyq/QhfoSuxww+Xr GSFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=n2PdStoLhbYFiN4pzlYXmhFfrfpxhCwv8blKtRUIuGU=; b=UkCzLpOYFNLoH23F/+XIBSLIg5blUQC2ChEy+CsLn2rIWM92vaZtfsrVCVRJ38xXiT 2rtLQpM6rzI4j5/DIeUgKYoFQsKbYuxphdsY/cB+khH6OXiS8HWqyOJRGVPZHFq2AQ5O VZxbvHjRcYKqyitDa6w6SN4Ain++4JysuAO6GG+a7wuMK1EpVXJMjljS2z+8AK5vLdHB cU2+4ev/r8eT0y/Udi0gYFO/iBnqgIY35DH7F9a8lfWnrOsNFwTYup+Y5lCQGNPgWWUJ vUcuInVieecY22SKXvuvQrTb2O3cq5q81WTSSw1LxJl8vX0uj4Qxfq5OMGkxdCLK2AGw gHbw== ARC-Authentication-Results: i=1; mx.google.com; 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 d74si1998899pga.326.2018.01.25.13.05.44; Thu, 25 Jan 2018 13:06:01 -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; 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 S1751380AbeAYVEq (ORCPT + 99 others); Thu, 25 Jan 2018 16:04:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:49114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751174AbeAYVEo (ORCPT ); Thu, 25 Jan 2018 16:04:44 -0500 Received: from mail-ot0-f182.google.com (mail-ot0-f182.google.com [74.125.82.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 491B121796 for ; Thu, 25 Jan 2018 21:04:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 491B121796 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org Received: by mail-ot0-f182.google.com with SMTP id 53so8068309otj.2 for ; Thu, 25 Jan 2018 13:04:44 -0800 (PST) X-Gm-Message-State: AKwxytfhN/IQpsfgYmKzR7MYbsZmHdGVaLpXvLqzgaPQEmtRH3wIZUCg 2k0Tw94WSH04b0CH38iAvg93TZMvkGAWrDfVE2QniQ== X-Received: by 10.157.74.50 with SMTP id h47mr11922657otf.247.1516914283556; Thu, 25 Jan 2018 13:04:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.66.36 with HTTP; Thu, 25 Jan 2018 13:04:23 -0800 (PST) In-Reply-To: <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> <20180125204625.GN2269@hirez.programming.kicks-ass.net> From: Andy Lutomirski Date: Thu, 25 Jan 2018 13:04:23 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process To: Peter Zijlstra Cc: Tim Chen , 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 25, 2018 at 12:46 PM, Peter Zijlstra wrote: > 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. > > Can we please not rely on any of the active_mm shit? That thing has really weird semantics and should just die. That being said, just stashing last_user_mm without any refcounting should be fine. After all, the only thing anyone does with it is comparing to next, and next is always alive. Or we could use last_user_ctx_id, since we already have a never-reused ctx_id for each mm on x86. --Andy