More padata cleanups
Subsystems (2)
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
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
@@ -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
PATCH 2/2 padata: Free the padata_works when they're no longer needed
In reply to Eric BiggersThe 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
@@ -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
Re: [PATCH 1/2] padata: Mark remaining code as __init and data as __initdata
In reply to Eric BiggersQuoted 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
__initand 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 <[email protected]>
Re: [PATCH 2/2] padata: Free the padata_works when they're no longer needed
In reply to Eric BiggersQuoted 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.cis 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 <[email protected]>
Thanks!