Skip to contentSkip to conversation

More padata cleanups

PATCH In review Eric Biggers 2 participants 5 messages Jul 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover More padata cleanups

Two more padata cleanups. Applies on top of
https://lore.kernel.org/linux-crypto/[email protected]/
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

Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 padata: Mark remaining code as __init and data as __initdata

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.

---
 kernel/padata.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
kernel/padata.c +7 -15
index 6eb130d31024..e7f89e3e44e9 100644
@@ -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);
Signature · 1 line
2.55.0
#3 lore raw

PATCH 2/2 padata: Free the padata_works when they're no longer needed

In reply to 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.

---
 kernel/padata.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/padata.c +9 -0
index e7f89e3e44e9..a28fe0c4f66b 100644
@@ -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);
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] padata: Mark remaining code as __init and data as __initdata

In reply to Eric Biggers
Quoted 11 lines · 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.

maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] padata: Free the padata_works when they're no longer needed

In reply to Eric Biggers
Quoted 11 lines · 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.

Thanks!