linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Baron <jasonbaron0@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>,
	Andy Lutomirski <luto@amacapital.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Paul Mackerras <paulus@samba.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Vince Weaver <vince@deater.net>,
	"hillf.zj" <hillf.zj@alibaba-inc.com>,
	Valdis Kletnieks <Valdis.Kletnieks@vt.edu>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: Kernel broken on processors without performance counters
Date: Fri, 24 Jul 2015 10:15:09 -0400	[thread overview]
Message-ID: <55B2486D.1040505@gmail.com> (raw)
In-Reply-To: <20150724123643.GL18673@twins.programming.kicks-ass.net>



On 07/24/2015 08:36 AM, Peter Zijlstra wrote:
> On Fri, Jul 24, 2015 at 12:56:02PM +0200, Peter Zijlstra wrote:
>> On Thu, Jul 23, 2015 at 03:14:13PM -0400, Jason Baron wrote:
>>>> +static enum jump_label_type jump_label_type(struct jump_entry *entry)
>>>> +{
>>>> +	struct static_key *key = static_key_cast(iter->key);
>>>> +	bool true_branch = jump_label_get_branch_default(key);
>>>> +	bool state = static_key_enabled(key);
>>>> +	bool inv = static_key_inv(iter->key);
>>>> +
>>>> +	return (true_branch ^ state) ^ inv;
>>> iiuc...this allows both the old style keys to co-exist with the
>>> new ones. IE state wouldn't be set for the new ones. And inv
>>> shouldn't be set for the old ones. Is that correct?
>> @state is the dynamic variable here, the other two are compile time.
>> @true_branch denotes the default (compile time) value, and @inv denotes
>> the (compile time) branch preference.
> Ha!, so that wasn't entirely correct, it turned out @inv means
> arch_static_branch_jump().
>
> That would let us remove the whole argument to the arch functions.
>
> That said, I generated the logic table for @inv meaning the branch type
> and then found a logic similar to what you outlined:
>
>
> /*
>  * Combine the right initial value (type) with the right branch order
>  * to generate the desired result.
>  *
>  *
>  *  type	likely (1)		unlikely (0)
>  * -----------+-----------------------+------------------
>  *            |                       |
>  *  true (1)  |	   ...		      |	   ...
>  *            |    NOP		      |	   JMP L
>  *            |    <br-stmts>	      |	1: ...
>  *            |	L: ...		      |
>  *            |			      |
>  *            |			      |	L: <br-stmts>
>  *            |			      |	   jmp 1b
>  *            |                       |
>  * -----------+-----------------------+------------------
>  *            |                       |
>  *  false (0) |	   ...		      |	   ...
>  *            |    JMP L	      |	   NOP
>  *            |    <br-stmts>	      |	1: ...
>  *            |	L: ...		      |
>  *            |			      |
>  *            |			      |	L: <br-stmts>
>  *            |			      |	   jmp 1b
>  *            |                       |
>  * -----------+-----------------------+------------------
>  *
>  * The initial value is encoded in the LSB of static_key::entries,
>  * type: 0 = false, 1 = true.
>  *
>  * The branch type is encoded in the LSB of jump_entry::key,
>  * branch: 0 = unlikely, 1 = likely.
>  *
>  * This gives the following logic table:
>  *
>  *	enabled	type	branch	  instuction
>  * -----------------------------+-----------
>  *	0	0	0	| NOP
>  *	0	0	1	| JMP
>  *	0	1	0	| NOP
>  *	0	1	1	| JMP
>  *
>  *	1	0	0	| JMP
>  *	1	0	1	| NOP
>  *	1	1	0	| JMP
>  *	1	1	1	| NOP
>  *
>  */
>
> This gives a map: ins = enabled ^ branch, which shows @type to be
> redundant.
>
> And we can trivially switch over the old static_key_{true,false}() to
> emit the right branch type.
>
> Whcih would mean we could remove the type encoding entirely, but I'll
> leave that be for now, maybe it'll come in handy later or whatnot.
>

I would just remove 'type'. Essentially, before we were storing
the 'branch' with the key. However, in this new model the
'branch' is really associated with the branch location, since the
same key can be used now with different branches.

Thanks,

-Jason


  reply	other threads:[~2015-07-24 14:15 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 15:17 Kernel broken on processors without performance counters Mikulas Patocka
2015-07-08 16:07 ` Peter Zijlstra
2015-07-08 16:54   ` Mikulas Patocka
2015-07-09 17:23     ` [PATCH] x86: Fix static_key in load_mm_cr4() Peter Zijlstra
2015-07-09 19:11       ` Mikulas Patocka
2015-07-10  8:27       ` [tip:perf/urgent] x86, perf: Fix static_key bug " tip-bot for Peter Zijlstra
2015-07-08 17:37   ` Kernel broken on processors without performance counters Andy Lutomirski
2015-07-08 20:04     ` Jason Baron
2015-07-09  0:36       ` Andy Lutomirski
2015-07-10 14:13         ` Peter Zijlstra
2015-07-10 15:29           ` Jason Baron
2015-07-21  8:21           ` Peter Zijlstra
2015-07-21 15:43             ` Thomas Gleixner
2015-07-21 15:49               ` Peter Zijlstra
2015-07-21 15:51                 ` Andy Lutomirski
2015-07-21 16:12                   ` Peter Zijlstra
2015-07-21 16:57                     ` Jason Baron
2015-07-23 14:54                       ` Steven Rostedt
2015-07-21 18:15                     ` Borislav Petkov
2015-07-21 18:50                       ` Jason Baron
2015-07-21 18:54                         ` Andy Lutomirski
2015-07-21 19:00                           ` Valdis.Kletnieks
2015-07-21 19:29                             ` Andy Lutomirski
2015-07-21 23:49                               ` Valdis.Kletnieks
2015-07-22  4:24                         ` Borislav Petkov
2015-07-22 17:06                           ` Jason Baron
2015-07-23 10:42                             ` Peter Zijlstra
2015-07-23 10:53                               ` Borislav Petkov
2015-07-23 14:19                               ` Jason Baron
2015-07-23 14:33                                 ` Peter Zijlstra
2015-07-23 14:49                                   ` Peter Zijlstra
2015-07-23 19:14                                     ` Jason Baron
2015-07-24 10:56                                       ` Peter Zijlstra
2015-07-24 12:36                                         ` Peter Zijlstra
2015-07-24 14:15                                           ` Jason Baron [this message]
2015-07-23 14:58                                 ` Peter Zijlstra
2015-07-23 15:34                               ` Steven Rostedt
2015-07-23 17:08                                 ` Peter Zijlstra
2015-07-23 17:18                                   ` Steven Rostedt
2015-07-23 17:33                                   ` Jason Baron
2015-07-23 18:12                                     ` Steven Rostedt
2015-07-23 19:02                                     ` Peter Zijlstra
2015-07-23 17:35                                   ` Andy Lutomirski
2015-07-23 17:54                                   ` Borislav Petkov
2015-07-23 19:02                                     ` Peter Zijlstra
2015-07-24  5:29                                       ` Borislav Petkov
2015-07-24 10:36                                         ` Peter Zijlstra
2015-07-22 20:43                           ` Mikulas Patocka
2015-07-21 15:53                 ` Thomas Gleixner
2015-07-21 15:54                 ` Peter Zijlstra
2015-07-09 17:11       ` Peter Zijlstra
2015-07-09 19:15         ` Jason Baron
2015-07-14  9:35 ` Borislav Petkov
2015-07-14 12:43   ` Mikulas Patocka

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=55B2486D.1040505@gmail.com \
    --to=jasonbaron0@gmail.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=aarcange@redhat.com \
    --cc=acme@kernel.org \
    --cc=bp@alien8.de \
    --cc=hillf.zj@alibaba-inc.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mpatocka@redhat.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vince@deater.net \
    /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;
as well as URLs for NNTP newsgroup(s).