Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH 0/2] More padata cleanups
@ 2026-07-17 17:18 Eric Biggers
  2026-07-17 17:18 ` [PATCH 1/2] padata: Mark remaining code as __init and data as __initdata Eric Biggers
  2026-07-17 17:18 ` [PATCH 2/2] padata: Free the padata_works when they're no longer needed Eric Biggers
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Biggers @ 2026-07-17 17:18 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: linux-kernel, Daniel Jordan, Steffen Klassert, Eric Biggers

Two more padata cleanups.  Applies on top of
https://lore.kernel.org/linux-crypto/20260713223234.24812-1-ebiggers@kernel.org/
which removes the no-longer-needed serialized job support.

Eric Biggers (2):
  padata: Mark remaining code as __init and data as __initdata
  padata: Free the padata_works when they're no longer needed

 kernel/padata.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)


base-commit: df373d39c6f038d176af303ae72f02c7c70b953d
prerequisite-patch-id: 57ddb64f17182e9382163da55150610d385274df
prerequisite-patch-id: 9ea2c856c57f6c92abe7f2b52e701e46398cb5bb
-- 
2.55.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] padata: Mark remaining code as __init and data as __initdata
  2026-07-17 17:18 [PATCH 0/2] More padata cleanups Eric Biggers
@ 2026-07-17 17:18 ` Eric Biggers
  2026-07-17 17:18 ` [PATCH 2/2] padata: Free the padata_works when they're no longer needed Eric Biggers
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2026-07-17 17:18 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: linux-kernel, Daniel Jordan, Steffen Klassert, Eric Biggers

Since the serialized job support was removed from padata, the remaining
code is used only by the multithreaded job support, whose public
functions are __init.

Therefore, also mark the internal functions as __init and the internal
data as __initdata.

This makes them be discarded after the kernel boots.  It also eliminates
the need to mark padata_work_init() as __ref.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 kernel/padata.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/kernel/padata.c b/kernel/padata.c
index 6eb130d31024..e7f89e3e44e9 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -31,9 +31,9 @@ struct padata_work {
 	void			*pw_data;
 };
 
-static DEFINE_SPINLOCK(padata_works_lock);
-static struct padata_work *padata_works;
-static LIST_HEAD(padata_free_works);
+static __initdata DEFINE_SPINLOCK(padata_works_lock);
+static __initdata struct padata_work *padata_works;
+static __initdata LIST_HEAD(padata_free_works);
 
 struct padata_mt_job_state {
 	spinlock_t		lock;
@@ -46,7 +46,7 @@ struct padata_mt_job_state {
 
 static void __init padata_mt_helper(struct work_struct *work);
 
-static struct padata_work *padata_work_alloc(void)
+static struct padata_work *__init padata_work_alloc(void)
 {
 	struct padata_work *pw;
 
@@ -60,16 +60,8 @@ static struct padata_work *padata_work_alloc(void)
 	return pw;
 }
 
-/*
- * This function is marked __ref because this function may be optimized in such
- * a way that it directly refers to work_fn's address, which causes modpost to
- * complain when work_fn is marked __init. This scenario was observed with clang
- * LTO, where padata_work_init() was optimized to refer directly to
- * padata_mt_helper() because the calls to padata_work_init() with other work_fn
- * values were eliminated or inlined.
- */
-static void __ref padata_work_init(struct padata_work *pw, work_func_t work_fn,
-				   void *data, int flags)
+static void __init padata_work_init(struct padata_work *pw, work_func_t work_fn,
+				    void *data, int flags)
 {
 	if (flags & PADATA_WORK_ONSTACK)
 		INIT_WORK_ONSTACK(&pw->pw_work, work_fn);
@@ -98,7 +90,7 @@ static int __init padata_work_alloc_mt(int nworks, void *data,
 	return i;
 }
 
-static void padata_work_free(struct padata_work *pw)
+static void __init padata_work_free(struct padata_work *pw)
 {
 	lockdep_assert_held(&padata_works_lock);
 	list_add(&pw->pw_list, &padata_free_works);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] padata: Free the padata_works when they're no longer needed
  2026-07-17 17:18 [PATCH 0/2] More padata cleanups Eric Biggers
  2026-07-17 17:18 ` [PATCH 1/2] padata: Mark remaining code as __init and data as __initdata Eric Biggers
@ 2026-07-17 17:18 ` Eric Biggers
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2026-07-17 17:18 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu
  Cc: linux-kernel, Daniel Jordan, Steffen Klassert, Eric Biggers

The memory pointed to by 'padata_works' is never freed.

Originally this was necessary because it was used to support the
serialized job APIs used by pcrypt, which can be used long after boot.

However, now that's been removed, and the remaining code in padata.c is
used only at boot time.  The pointer 'padata_works' is now __initdata.

The result is that this essentially turned into a memory leak.  Fix it.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 kernel/padata.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/padata.c b/kernel/padata.c
index e7f89e3e44e9..a28fe0c4f66b 100644
--- a/kernel/padata.c
+++ b/kernel/padata.c
@@ -230,3 +230,12 @@ void __init padata_init(void)
 	for (i = 0; i < possible_cpus; ++i)
 		list_add(&padata_works[i].pw_list, &padata_free_works);
 }
+
+static int __init padata_exit(void)
+{
+	kfree(padata_works);
+	padata_works = NULL;
+	INIT_LIST_HEAD(&padata_free_works);
+	return 0;
+}
+late_initcall_sync(padata_exit);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-17 17:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17 17:18 [PATCH 0/2] More padata cleanups Eric Biggers
2026-07-17 17:18 ` [PATCH 1/2] padata: Mark remaining code as __init and data as __initdata Eric Biggers
2026-07-17 17:18 ` [PATCH 2/2] padata: Free the padata_works when they're no longer needed Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox