From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226IjuLSI2tfPU1Hdaw9yIKGDbjCW52ozgQvuAiis5NacdvjzdG/G1cxxIJqIrqE9evkKECr ARC-Seal: i=1; a=rsa-sha256; t=1516870709; cv=none; d=google.com; s=arc-20160816; b=BPu42cJRT5yJ+oXYX26/YBkAQm8q8lGQTeK/b/LTiEHJ+zivRVxPDQ9spD4Y1mKKek lQFmW/5I5sGn0KDsyvwHAl6p6M/TRd5I0/MH7ETWzaX5Jd70Jazs7LsdkUXnxAiMoYIu X6FrYRZU2mbSOVNvudUYHMzikznNHfU4ZtJFEkdaPgtoS41k7q3jAUid7asGt3ODqzlR nxA/SDylFbKQZjgOGlZtOFtP3OdMI7QDc7S8l1MSJV2m4v3a8+BnXqaz3rBmH7wZ8WTi Ez93N2UgCzOjSiBYcYUpVag7I8FlqfPIeKlz3RqP49grac7weIILy9CkL2EAJAj8Xc7l j8RQ== 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=1hxS/hLXtmTsyKeOk4xM6wIYapyq0S9Al778QhH/Zco=; b=hh3CfK6b89ADSpQNjiKOWeEgfpNtpr+ZlIOqID5cX5wtU+Z+Xl4CzI4CjJjcsxJ4UV a8EfuqFWI1jC4sepLnqjBVCuwnRGDe/QVnrGlkT3h0w74MB/ynZXGFvsMSHp4h2SBxEJ 34s61Eq7PQV4+azyaiWBgjc8uDC4gE4Blnqq9aAVeGgq9TQoO7ctjXWlYJaBO+jRqbR1 4pIKkN2b3KGPm7LVbdm1kmR57PjI2hsJWishzqJrjtLKhbkUBaC6KS2VmRwmpT3k72Fn kb+Dg/o4b+IdsKKBw96ulutQp9MfaBglSPfU2rlcQF8oePCsOVrfGFfCw6s0PtK6p2mD Sunw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=IPwXfIxq; 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=IPwXfIxq; 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 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) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590523944221221739?= X-GMAIL-MSGID: =?utf-8?q?1590554221630000918?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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)) {