public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
	KarimAllah Ahmed <karahmed@amazon.de>,
	Andi Kleen <ak@linux.intel.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Andy Lutomirski <luto@kernel.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Ashok Raj <ashok.raj@intel.com>,
	Asit Mallick <asit.k.mallick@intel.com>,
	Borislav Petkov <bp@suse.de>,
	Dan Williams <dan.j.williams@intel.com>,
	Dave Hansen <dave.hansen@intel.com>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"H . Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	Janakarajan Natarajan <Janakarajan.Natarajan@amd.com>,
	Joerg Roedel <joro@8bytes.org>,
	Jun Nakajima <jun.nakajima@intel.com>,
	Laura Abbott <labbott@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	rkrcmar@redhat.com, Thomas Gleixner <tglx@linutronix.de>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	x86@kernel.org
Subject: Re: [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process
Date: Thu, 25 Jan 2018 09:58:20 +0100	[thread overview]
Message-ID: <20180125085820.GV2228@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <c5cc429013c2248ddebe0a8480b172ae70b29733.1516840211.git.tim.c.chen@linux.intel.com>

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)) {

  parent reply	other threads:[~2018-01-25  8:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25  0:36 [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process Tim Chen
2018-01-25  0:36 ` [RFC PATCH 2/2] x86/ibpb: Prevent missed IBPB flush Tim Chen
2018-01-25  8:20   ` David Woodhouse
2018-01-25 16:56     ` Tim Chen
2018-01-25  8:58 ` Peter Zijlstra [this message]
2018-01-25  9:22   ` [RFC PATCH 1/2] x86/ibpb: Skip IBPB when we switch back to same user process Peter Zijlstra
2018-01-25 13:21     ` Arjan van de Ven
2018-01-25 13:50       ` Peter Zijlstra
2018-01-25 14:07         ` Arjan van de Ven
2018-01-25 16:41           ` Peter Zijlstra
2018-01-25 17:04             ` Andy Lutomirski
2018-01-25 18:18               ` Peter Zijlstra
2018-01-25 19:32                 ` Tim Chen
2018-01-25 19:34                   ` Arjan van de Ven
2018-01-25 19:45                     ` Dave Hansen
2018-01-25 20:46                   ` Peter Zijlstra
2018-01-25 21:04                     ` Andy Lutomirski
2018-01-25 21:57                       ` Andi Kleen
2018-01-25 22:01                         ` Andy Lutomirski
2018-01-25 23:07                           ` Tim Chen
2018-01-26  0:01                       ` Peter Zijlstra
2018-01-25 17:24             ` Arjan van de Ven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180125085820.GV2228@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Janakarajan.Natarajan@amd.com \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=ashok.raj@intel.com \
    --cc=asit.k.mallick@intel.com \
    --cc=bp@suse.de \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=jun.nakajima@intel.com \
    --cc=karahmed@amazon.de \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox