From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: ARC-Seal: i=1; a=rsa-sha256; t=1517133373; cv=none; d=google.com; s=arc-20160816; b=rGKLzmRUMq+XB6w/Lyzaicqs4upXrQIuH/KLSb9dYWcH2tEYSIvJ0NpiLsI4gQtZgh uL2JqYodL3MAIFjSTRjPQrPwMC3nxlxyIPqXc5j0aTvj2lNGBzOhzC6xenNckB0nJbjV 2w2IENpeQS6Zuq1ytSVUy0xxh9DeKVCaqy5mV/O3X8yeXVjcDo/UJkvsRepMt8d7oaJd R4IB7YPFAhIJ0hCR+6pNtCSmoLn88Zy5/8LUvdASbpmtRo+FfECMhmZgohETR1tE5J4L vUw+YN/0lACFTJTTc3BsHEgugZk0lb3e35yKINz2W4SJe+WhYKxpnRuohMhzP9xM2rff 1iuw== 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:sender:dkim-signature :arc-authentication-results; bh=sMAxUxcQgqxsTDU8UfZUPyHEIMYmcRsKAxdYhDu8TVs=; b=saOsLptT817kruL3I7JFliidKWvmaJ6SE25yZnYEXDO5ibvO3Vowi4saAHgojefRPR XgyDeBOLhXcBRsP/rr7GrauGDztp0jER/KPNO+mJhljhe+5Yo0nZf7pV78hOoYDHgBBK 9N4XERTKhx0eUlh42As+66hF/0W0AhLP51B55vKA25fsepGIuWXzIbj7jTP75pVfD7RG sArUnV+R8eCIqENjfmUj7aE77Ndld+PwtHbujTbFA76T9fnNto7aTDFSWb3INUnYGwMh 5u0nMdnvfabGAoK3Ie4UIoGwaNRM8w3n2MUkv0fg02HqllgmgBYfYSra8uF4g56E/Qci JfZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SEJcCHte; spf=pass (google.com: domain of mingo.kernel.org@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mingo.kernel.org@gmail.com Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SEJcCHte; spf=pass (google.com: domain of mingo.kernel.org@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mingo.kernel.org@gmail.com X-Google-Smtp-Source: AH8x224d7VU5quzlvyOTjoiRa7ip48LvXVWBJ5n0Q70M7F1AkPpbxy2RVwS4VC8QjocSO/jgv7sTUg== Sender: Ingo Molnar Date: Sun, 28 Jan 2018 10:56:09 +0100 From: Ingo Molnar 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 , Peter Zijlstra , rkrcmar@redhat.com, Thomas Gleixner , Tom Lendacky , x86@kernel.org Subject: Re: [PATCH v2] x86/ibpb: Skip IBPB when we switch back to same user process Message-ID: <20180128095609.rfcnv3itu3clrkru@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590523944221221739?= X-GMAIL-MSGID: =?utf-8?q?1590829644000430572?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: * Tim Chen wrote: > Thanks to the reviewers and Andy Lutomirski for the suggestion of > using ctx_id which got rid of the problem of mm pointer recycling. > Here's an update of this patch based on Andy's suggestion. > > 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. > > We track the last mm user context id before we switch to init_mm by calling > leave_mm when tlb_defer_switch_to_init_mm returns false (pcid available). > > The cost is to have an extra u64 mm context id to track the last mm we were using before > switching to the init_mm used by idle. Avoiding the extra IBPB > is probably worth the extra memory for this common scenario. > > For those cases where tlb_defer_switch_to_init_mm returns true (non pcid), > lazy tlb will defer switch to init_mm, so we will not be changing > the mm for the process A -> idle -> process A switch. So > IBPB will be skipped for this case. > > v2: > 1. Save last user context id instead of last user mm to avoid the problem of recycled mm > > Signed-off-by: Tim Chen > --- > arch/x86/include/asm/tlbflush.h | 2 ++ > arch/x86/mm/tlb.c | 23 ++++++++++++++++------- > 2 files changed, 18 insertions(+), 7 deletions(-) What tree is this patch against? It doesn't apply to linus's latest, nor to tip:master. Thanks, Ingo