public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Jason Baron <jbaron@akamai.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Will McVicker <willmcvicker@google.com>,
	Kees Cook <keescook@chromium.org>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2.1 01/11] static_call: Improve key type abstraction
Date: Tue, 21 Mar 2023 22:02:22 -0700	[thread overview]
Message-ID: <20230322050222.3okw7d2cd4y3w4ug@treble> (raw)
In-Reply-To: <c8bc83b2c70aeaad3ce01d12dc1153981ab693f8.1679456900.git.jpoimboe@kernel.org>

Make the static_call_key union less fragile by abstracting all knowledge
about the type bit into helper functions.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 include/linux/static_call_types.h       |  4 +--
 kernel/static_call_inline.c             | 47 ++++++++++++++++++-------
 tools/include/linux/static_call_types.h |  4 +--
 3 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/include/linux/static_call_types.h b/include/linux/static_call_types.h
index 5a00b8b2cf9f..87c3598609e8 100644
--- a/include/linux/static_call_types.h
+++ b/include/linux/static_call_types.h
@@ -63,8 +63,8 @@ struct static_call_key {
 	union {
 		/* bit 0: 0 = mods, 1 = sites */
 		unsigned long type;
-		struct static_call_mod *mods;
-		struct static_call_site *sites;
+		struct static_call_mod *_mods;
+		struct static_call_site *_sites;
 	};
 };
 
diff --git a/kernel/static_call_inline.c b/kernel/static_call_inline.c
index 639397b5491c..1328370d3cf6 100644
--- a/kernel/static_call_inline.c
+++ b/kernel/static_call_inline.c
@@ -115,12 +115,17 @@ static inline bool static_call_key_has_mods(struct static_call_key *key)
 	return !(key->type & 1);
 }
 
-static inline struct static_call_mod *static_call_key_next(struct static_call_key *key)
+static inline struct static_call_mod *static_call_key_mods(struct static_call_key *key)
 {
 	if (!static_call_key_has_mods(key))
 		return NULL;
 
-	return key->mods;
+	return key->_mods;
+}
+
+static inline void static_call_key_set_mods(struct static_call_key *key, struct static_call_mod *mods)
+{
+	key->_mods = mods;
 }
 
 static inline struct static_call_site *static_call_key_sites(struct static_call_key *key)
@@ -131,6 +136,12 @@ static inline struct static_call_site *static_call_key_sites(struct static_call_
 	return (struct static_call_site *)(key->type & ~1);
 }
 
+static inline void static_call_key_set_sites(struct static_call_key *key, struct static_call_site *sites)
+{
+	key->_sites = sites;
+	key->type |= 1;
+}
+
 void __static_call_update(struct static_call_key *key, void *tramp, void *func)
 {
 	struct static_call_site *site, *stop;
@@ -154,7 +165,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
 		goto done;
 
 	first = (struct static_call_mod){
-		.next = static_call_key_next(key),
+		.next = static_call_key_mods(key),
 		.mod = NULL,
 		.sites = static_call_key_sites(key),
 	};
@@ -250,8 +261,7 @@ static int __static_call_init(struct module *mod,
 			 * static_call_init() before memory allocation works.
 			 */
 			if (!mod) {
-				key->sites = site;
-				key->type |= 1;
+				static_call_key_set_sites(key, site);
 				goto do_transform;
 			}
 
@@ -266,10 +276,10 @@ static int __static_call_init(struct module *mod,
 			 */
 			if (static_call_key_sites(key)) {
 				site_mod->mod = NULL;
-				site_mod->next = NULL;
 				site_mod->sites = static_call_key_sites(key);
+				site_mod->next = NULL;
 
-				key->mods = site_mod;
+				static_call_key_set_mods(key, site_mod);
 
 				site_mod = kzalloc(sizeof(*site_mod), GFP_KERNEL);
 				if (!site_mod)
@@ -278,8 +288,9 @@ static int __static_call_init(struct module *mod,
 
 			site_mod->mod = mod;
 			site_mod->sites = site;
-			site_mod->next = static_call_key_next(key);
-			key->mods = site_mod;
+			site_mod->next = static_call_key_mods(key);
+
+			static_call_key_set_mods(key, site_mod);
 		}
 
 do_transform:
@@ -406,7 +417,7 @@ static void static_call_del_module(struct module *mod)
 	struct static_call_site *stop = mod->static_call_sites +
 					mod->num_static_call_sites;
 	struct static_call_key *key, *prev_key = NULL;
-	struct static_call_mod *site_mod, **prev;
+	struct static_call_mod *site_mod, *prev;
 	struct static_call_site *site;
 
 	for (site = start; site < stop; site++) {
@@ -416,15 +427,25 @@ static void static_call_del_module(struct module *mod)
 
 		prev_key = key;
 
-		for (prev = &key->mods, site_mod = key->mods;
+		site_mod = static_call_key_mods(key);
+		if (!site_mod)
+			continue;
+
+		if (site_mod->mod == mod) {
+			static_call_key_set_mods(key, site_mod->next);
+			kfree(site_mod);
+			continue;
+		}
+
+		for (prev = site_mod, site_mod = site_mod->next;
 		     site_mod && site_mod->mod != mod;
-		     prev = &site_mod->next, site_mod = site_mod->next)
+		     prev = site_mod, site_mod = site_mod->next)
 			;
 
 		if (!site_mod)
 			continue;
 
-		*prev = site_mod->next;
+		prev->next = site_mod->next;
 		kfree(site_mod);
 	}
 }
diff --git a/tools/include/linux/static_call_types.h b/tools/include/linux/static_call_types.h
index 5a00b8b2cf9f..87c3598609e8 100644
--- a/tools/include/linux/static_call_types.h
+++ b/tools/include/linux/static_call_types.h
@@ -63,8 +63,8 @@ struct static_call_key {
 	union {
 		/* bit 0: 0 = mods, 1 = sites */
 		unsigned long type;
-		struct static_call_mod *mods;
-		struct static_call_site *sites;
+		struct static_call_mod *_mods;
+		struct static_call_site *_sites;
 	};
 };
 
-- 
2.39.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2023-03-22  5:04 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22  4:00 [PATCH v2 00/11] static_call: Improve NULL/ret0 handling Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 01/11] static_call: Improve key type abstraction Josh Poimboeuf
2023-03-22  4:53   ` Josh Poimboeuf
2023-03-22  5:02   ` Josh Poimboeuf [this message]
2023-03-22  4:00 ` [PATCH v2 02/11] static_call: Flip key type union bit Josh Poimboeuf
2023-03-22  5:03   ` [PATCH v2.1 " Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 03/11] static_call: Remove static_call_mod_init() declaration Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 04/11] static_call: Remove static_call.h dependency on cpu.h Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 05/11] static_call: Make ARCH_ADD_TRAMP_KEY() generic Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 06/11] static_call: "EXPORT_STATIC_CALL_TRAMP" -> "EXPORT_STATIC_CALL_RO" Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 07/11] static_call: Reorganize static call headers Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 08/11] arm64/static_call: Fix static call CFI violations Josh Poimboeuf
2023-03-22 12:22   ` Mark Rutland
2023-03-22 14:19     ` Peter Zijlstra
2023-03-22 18:26       ` Josh Poimboeuf
2023-03-22 18:09     ` Josh Poimboeuf
2023-03-22 18:07   ` Sami Tolvanen
2023-03-22 18:33     ` Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 09/11] static_call: Make NULL static calls consistent Josh Poimboeuf
2023-03-22 14:45   ` Peter Zijlstra
2023-03-22 14:59   ` Peter Zijlstra
2023-03-22 18:35     ` Josh Poimboeuf
2023-03-22 15:04   ` Christophe Leroy
2023-03-22  4:00 ` [PATCH v2 10/11] static_call: Remove static_call_cond() Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 11/11] static_call: Remove DEFINE_STATIC_CALL_RET0() Josh Poimboeuf
2023-03-22 15:04   ` Christophe Leroy
2023-03-22 18:50     ` Josh Poimboeuf
2023-03-22 15:15   ` Peter Zijlstra
2023-03-22 18:45     ` Josh Poimboeuf

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=20230322050222.3okw7d2cd4y3w4ug@treble \
    --to=jpoimboe@kernel.org \
    --cc=ardb@kernel.org \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jbaron@akamai.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ndesaulniers@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=seanjc@google.com \
    --cc=willmcvicker@google.com \
    --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