linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, Denis Kirjanov <kda@linux-powerpc.org>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	"Peter Zijlstra" <peterz@infradead.org>
Subject: [PATCH 3.16 14/86] locking/static_keys: Rework update logic
Date: Thu, 16 May 2019 16:55:33 +0100	[thread overview]
Message-ID: <lsq.1558022133.477445986@decadent.org.uk> (raw)
In-Reply-To: <lsq.1558022132.52852998@decadent.org.uk>

3.16.68-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Peter Zijlstra <peterz@infradead.org>

commit 706249c222f68471b6f8e9e8e9b77665c404b226 upstream.

Instead of spreading the branch_default logic all over the place,
concentrate it into the one jump_label_type() function.

This does mean we need to actually increment/decrement the enabled
count _before_ calling the update path, otherwise jump_label_type()
will not see the right state.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 kernel/jump_label.c | 88 ++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 50 deletions(-)

--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -54,12 +54,7 @@ jump_label_sort_entries(struct jump_entr
 	sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
 }
 
-static void jump_label_update(struct static_key *key, int enable);
-
-static inline bool static_key_type(struct static_key *key)
-{
-	return (unsigned long)key->entries & JUMP_TYPE_MASK;
-}
+static void jump_label_update(struct static_key *key);
 
 void static_key_slow_inc(struct static_key *key)
 {
@@ -68,13 +63,8 @@ void static_key_slow_inc(struct static_k
 		return;
 
 	jump_label_lock();
-	if (atomic_read(&key->enabled) == 0) {
-		if (!static_key_type(key))
-			jump_label_update(key, JUMP_LABEL_JMP);
-		else
-			jump_label_update(key, JUMP_LABEL_NOP);
-	}
-	atomic_inc(&key->enabled);
+	if (atomic_inc_return(&key->enabled) == 1)
+		jump_label_update(key);
 	jump_label_unlock();
 }
 EXPORT_SYMBOL_GPL(static_key_slow_inc);
@@ -92,10 +82,7 @@ static void __static_key_slow_dec(struct
 		atomic_inc(&key->enabled);
 		schedule_delayed_work(work, rate_limit);
 	} else {
-		if (!static_key_type(key))
-			jump_label_update(key, JUMP_LABEL_NOP);
-		else
-			jump_label_update(key, JUMP_LABEL_JMP);
+		jump_label_update(key);
 	}
 	jump_label_unlock();
 }
@@ -161,7 +148,7 @@ static int __jump_label_text_reserved(st
 	return 0;
 }
 
-/* 
+/*
  * Update code which is definitely not currently executing.
  * Architectures which need heavyweight synchronization to modify
  * running code can override this to make the non-live update case
@@ -170,29 +157,17 @@ static int __jump_label_text_reserved(st
 void __weak __init_or_module arch_jump_label_transform_static(struct jump_entry *entry,
 					    enum jump_label_type type)
 {
-	arch_jump_label_transform(entry, type);	
+	arch_jump_label_transform(entry, type);
 }
 
-static void __jump_label_update(struct static_key *key,
-				struct jump_entry *entry,
-				struct jump_entry *stop, int enable)
+static inline struct jump_entry *static_key_entries(struct static_key *key)
 {
-	for (; (entry < stop) &&
-	      (entry->key == (jump_label_t)(unsigned long)key);
-	      entry++) {
-		/*
-		 * entry->code set to 0 invalidates module init text sections
-		 * kernel_text_address() verifies we are not in core kernel
-		 * init code, see jump_label_invalidate_module_init().
-		 */
-		if (entry->code && kernel_text_address(entry->code))
-			arch_jump_label_transform(entry, enable);
-	}
+	return (struct jump_entry *)((unsigned long)key->entries & ~JUMP_TYPE_MASK);
 }
 
-static inline struct jump_entry *static_key_entries(struct static_key *key)
+static inline bool static_key_type(struct static_key *key)
 {
-	return (struct jump_entry *)((unsigned long)key->entries & ~JUMP_TYPE_MASK);
+	return (unsigned long)key->entries & JUMP_TYPE_MASK;
 }
 
 static inline struct static_key *jump_entry_key(struct jump_entry *entry)
@@ -200,14 +175,30 @@ static inline struct static_key *jump_en
 	return (struct static_key *)((unsigned long)entry->key);
 }
 
-static enum jump_label_type jump_label_type(struct static_key *key)
+static enum jump_label_type jump_label_type(struct jump_entry *entry)
 {
+	struct static_key *key = jump_entry_key(entry);
 	bool enabled = static_key_enabled(key);
 	bool type = static_key_type(key);
 
 	return enabled ^ type;
 }
 
+static void __jump_label_update(struct static_key *key,
+				struct jump_entry *entry,
+				struct jump_entry *stop)
+{
+	for (; (entry < stop) && (jump_entry_key(entry) == key); entry++) {
+		/*
+		 * entry->code set to 0 invalidates module init text sections
+		 * kernel_text_address() verifies we are not in core kernel
+		 * init code, see jump_label_invalidate_module_init().
+		 */
+		if (entry->code && kernel_text_address(entry->code))
+			arch_jump_label_transform(entry, jump_label_type(entry));
+	}
+}
+
 void __init jump_label_init(void)
 {
 	struct jump_entry *iter_start = __start___jump_table;
@@ -221,8 +212,8 @@ void __init jump_label_init(void)
 	for (iter = iter_start; iter < iter_stop; iter++) {
 		struct static_key *iterk;
 
+		arch_jump_label_transform_static(iter, jump_label_type(iter));
 		iterk = jump_entry_key(iter);
-		arch_jump_label_transform_static(iter, jump_label_type(iterk));
 		if (iterk == key)
 			continue;
 
@@ -262,17 +253,15 @@ static int __jump_label_mod_text_reserve
 				start, end);
 }
 
-static void __jump_label_mod_update(struct static_key *key, int enable)
+static void __jump_label_mod_update(struct static_key *key)
 {
-	struct static_key_mod *mod = key->next;
+	struct static_key_mod *mod;
 
-	while (mod) {
+	for (mod = key->next; mod; mod = mod->next) {
 		struct module *m = mod->mod;
 
 		__jump_label_update(key, mod->entries,
-				    m->jump_entries + m->num_jump_entries,
-				    enable);
-		mod = mod->next;
+				    m->jump_entries + m->num_jump_entries);
 	}
 }
 
@@ -294,9 +283,8 @@ void jump_label_apply_nops(struct module
 	if (iter_start == iter_stop)
 		return;
 
-	for (iter = iter_start; iter < iter_stop; iter++) {
+	for (iter = iter_start; iter < iter_stop; iter++)
 		arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
-	}
 }
 
 static int jump_label_add_module(struct module *mod)
@@ -337,8 +325,8 @@ static int jump_label_add_module(struct
 		jlm->next = key->next;
 		key->next = jlm;
 
-		if (jump_label_type(key) == JUMP_LABEL_JMP)
-			__jump_label_update(key, iter, iter_stop, JUMP_LABEL_JMP);
+		if (jump_label_type(iter) == JUMP_LABEL_JMP)
+			__jump_label_update(key, iter, iter_stop);
 	}
 
 	return 0;
@@ -458,14 +446,14 @@ int jump_label_text_reserved(void *start
 	return ret;
 }
 
-static void jump_label_update(struct static_key *key, int enable)
+static void jump_label_update(struct static_key *key)
 {
 	struct jump_entry *stop = __stop___jump_table;
 	struct jump_entry *entry = static_key_entries(key);
 #ifdef CONFIG_MODULES
 	struct module *mod;
 
-	__jump_label_mod_update(key, enable);
+	__jump_label_mod_update(key);
 
 	preempt_disable();
 	mod = __module_address((unsigned long)key);
@@ -475,7 +463,7 @@ static void jump_label_update(struct sta
 #endif
 	/* if there are no users, entry can be NULL */
 	if (entry)
-		__jump_label_update(key, entry, stop, enable);
+		__jump_label_update(key, entry, stop);
 }
 
 #endif


  parent reply	other threads:[~2019-05-16 16:04 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 15:55 [PATCH 3.16 00/86] 3.16.68-rc1 review Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 04/86] MIPS: jump_label.c: Correct the span of the J instruction Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 01/86] x86/cpufeature: Add bug flags to /proc/cpuinfo Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 08/86] jump_label: Allow asm/jump_label.h to be included in assembly Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 07/86] s390/jump label: use different nop instruction Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 10/86] module, jump_label: Fix module locking Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 02/86] module: add within_module() function Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 03/86] jump_label: Fix small typos in the documentation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 09/86] jump_label: Allow jump labels to be used in assembly Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 05/86] MIPS: jump_label.c: Handle the microMIPS J instruction encoding Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 06/86] s390/jump label: add sanity checks Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 75/86] x86/speculation: Move arch_smt_update() call to after mitigation decisions Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 43/86] x86/speculation: Rework SMT state change Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 78/86] x86/speculation/mds: Print SMT vulnerable on MSBDS with mitigations off Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 68/86] x86/speculation/mds: Conditionally clear CPU buffers on idle entry Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 32/86] x86/speculation: Enable cross-hyperthread spectre v2 STIBP mitigation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 63/86] x86/speculation/mds: Add basic bug infrastructure for MDS Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 34/86] x86/speculation: Update the TIF_SSBD comment Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 64/86] x86/speculation/mds: Add BUG_MSBDS_ONLY Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 79/86] cpu/speculation: Add 'mitigations=' cmdline option Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 66/86] x86/speculation/mds: Add mds_clear_cpu_buffers() Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 76/86] x86/speculation/mds: Add SMT warning message Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 21/86] x86/asm: Error out if asm/jump_label.h is included inappropriately Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 51/86] x86/speculation: Avoid __switch_to_xtra() calls Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 45/86] x86/speculation: Mark string arrays const correctly Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 41/86] x86/Kconfig: Select SCHED_SMT if SMP enabled Ben Hutchings
2019-05-16 15:55 ` Ben Hutchings [this message]
2019-05-16 15:55 ` [PATCH 3.16 77/86] x86/speculation/mds: Fix comment Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 27/86] x86/speculation: Support Enhanced IBRS on future CPUs Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 38/86] x86/speculation: Disable STIBP when enhanced IBRS is in use Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 31/86] x86/speculation: Apply IBPB more strictly to avoid cross-process data leak Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 33/86] x86/speculation: Propagate information about RSB filling mitigation to sysfs Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 70/86] x86/speculation/l1tf: Document l1tf in sysfs Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 16/86] jump label, locking/static_keys: Update docs Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 81/86] x86/speculation/mds: Add 'mitigations=' support for MDS Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 44/86] x86/speculation: Reorder the spec_v2 code Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 60/86] kvm: x86: Report STIBP on GET_SUPPORTED_CPUID Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 35/86] x86/speculation: Clean up spectre_v2_parse_cmdline() Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 18/86] locking/static_keys: Fix a silly typo Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 80/86] x86/speculation: Support 'mitigations=' cmdline option Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 40/86] x86/speculation: Reorganize speculation control MSRs update Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 30/86] x86/cpu: Sanitize FAM6_ATOM naming Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 58/86] x86/speculation: Add seccomp Spectre v2 user space protection mode Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 39/86] x86/speculation: Rename SSBD update functions Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 50/86] x86/process: Consolidate and simplify switch_to_xtra() code Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 37/86] x86/speculation: Move STIPB/IBPB string conditionals out of cpu_show_common() Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 82/86] x86/mds: Add MDSUM variant to the MDS documentation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 36/86] x86/speculation: Remove unnecessary ret variable in cpu_show_common() Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 52/86] x86/speculation: Prepare for conditional IBPB in switch_mm() Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 54/86] x86/speculation: Prepare arch_smt_update() for PRCTL mode Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 69/86] x86/speculation/mds: Add mitigation control for MDS Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 28/86] x86/speculation: Simplify the CPU bug detection logic Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 71/86] x86/speculation/mds: Add sysfs reporting for MDS Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 57/86] x86/speculation: Enable prctl mode for spectre_v2_user Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 86/86] x86/bugs: Change L1TF mitigation string to match upstream Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 59/86] x86/speculation: Provide IBPB always command line options Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 48/86] x86/speculation: Add command line control for indirect branch speculation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 83/86] Documentation: Correct the possible MDS sysfs values Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 23/86] x86/headers: Don't include asm/processor.h in asm/atomic.h Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 22/86] x86/asm: Add asm macros for static keys/jump labels Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 29/86] x86/speculation: Remove SPECTRE_V2_IBRS in enum spectre_v2_mitigation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 74/86] Documentation: Add MDS vulnerability documentation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 24/86] x86/cpufeature: Carve out X86_FEATURE_* Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 62/86] x86/speculation: Consolidate CPU whitelists Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 73/86] Documentation: Move L1TF to separate directory Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 19/86] locking/static_keys: Fix up the static keys documentation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 15/86] locking/static_keys: Add a new static_key interface Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 49/86] x86/speculation: Prepare for per task indirect branch speculation control Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 46/86] x86/speculataion: Mark command line parser data __initdata Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 53/86] x86/speculation: Split out TIF update Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 11/86] jump_label: Rename JUMP_LABEL_{EN,DIS}ABLE to JUMP_LABEL_{JMP,NOP} Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 85/86] x86/cpu/bugs: Use __initconst for 'const' init data Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 13/86] jump_label: Add jump_entry_key() helper Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 61/86] x86/msr-index: Cleanup bit defines Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 55/86] x86/speculation: Prevent stale SPEC_CTRL msr content Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 84/86] x86/speculation/mds: Fix documentation typo Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 67/86] x86/speculation/mds: Clear CPU buffers on exit to user Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 65/86] x86/kvm: Expose X86_FEATURE_MD_CLEAR to guests Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 56/86] x86/speculation: Add prctl() control for indirect branch speculation Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 12/86] jump_label, locking/static_keys: Rename JUMP_LABEL_TYPE_* and related helpers to the static_key* pattern Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 47/86] x86/speculation: Unify conditional spectre v2 print functions Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 26/86] locking/static_keys: Provide DECLARE and well as DEFINE macros Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 25/86] locking/static_key: Fix concurrent static_key_slow_inc() Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 17/86] jump_label/x86: Work around asm build bug on older/backported GCCs Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 20/86] jump_label: make static_key_enabled() work on static_key_true/false types too Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 72/86] x86/speculation/mds: Add mitigation mode VMWERV Ben Hutchings
2019-05-16 15:55 ` [PATCH 3.16 42/86] sched: Add sched_smt_active() Ben Hutchings

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=lsq.1558022133.477445986@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=kda@linux-powerpc.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).