From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Aaron Tomlin <atomlin@redhat.com>,
"mcgrof@kernel.org" <mcgrof@kernel.org>
Cc: "cl@linux.com" <cl@linux.com>,
"pmladek@suse.com" <pmladek@suse.com>,
"mbenes@suse.cz" <mbenes@suse.cz>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"jeyu@kernel.org" <jeyu@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-modules@vger.kernel.org" <linux-modules@vger.kernel.org>,
"void@manifault.com" <void@manifault.com>,
"atomlin@atomlin.com" <atomlin@atomlin.com>,
"allen.lkml@gmail.com" <allen.lkml@gmail.com>,
"joe@perches.com" <joe@perches.com>,
"msuchanek@suse.de" <msuchanek@suse.de>,
"oleksandr@natalenko.name" <oleksandr@natalenko.name>
Subject: Re: [PATCH v8 10/13] module: Move procfs support into a separate file
Date: Tue, 22 Feb 2022 17:59:46 +0000 [thread overview]
Message-ID: <cf6a2db2-7155-e1fa-2bce-e8caa2deff69@csgroup.eu> (raw)
In-Reply-To: <20220222141303.1392190-11-atomlin@redhat.com>
Le 22/02/2022 à 15:13, Aaron Tomlin a écrit :
> No functional change.
>
> This patch migrates code that allows one to generate a
> list of loaded/or linked modules via /proc when procfs
> support is enabled into kernel/module/procfs.c.
>
> Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> kernel/module/Makefile | 1 +
> kernel/module/internal.h | 1 +
> kernel/module/main.c | 131 +-----------------------------------
> kernel/module/procfs.c | 142 +++++++++++++++++++++++++++++++++++++++
> 4 files changed, 145 insertions(+), 130 deletions(-)
> create mode 100644 kernel/module/procfs.c
>
> diff --git a/kernel/module/Makefile b/kernel/module/Makefile
> index 9901bed3ab5b..94296c98a67f 100644
> --- a/kernel/module/Makefile
> +++ b/kernel/module/Makefile
> @@ -15,3 +15,4 @@ obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o
> obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o
> obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
> obj-$(CONFIG_KALLSYMS) += kallsyms.o
> +obj-$(CONFIG_PROC_FS) += procfs.o
> diff --git a/kernel/module/internal.h b/kernel/module/internal.h
> index 44ca05b9eb8f..6af40c2d145f 100644
> --- a/kernel/module/internal.h
> +++ b/kernel/module/internal.h
> @@ -72,6 +72,7 @@ struct module *find_module_all(const char *name, size_t len, bool even_unformed)
> int cmp_name(const void *name, const void *sym);
> long module_get_offset(struct module *mod, unsigned int *size, Elf_Shdr *sechdr,
> unsigned int section);
> +char *module_flags(struct module *mod, char *buf);
>
> static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
> {
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 952079987ea4..44b6fd1acc44 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -22,7 +22,6 @@
> #include <linux/slab.h>
> #include <linux/vmalloc.h>
> #include <linux/elf.h>
> -#include <linux/proc_fs.h>
> #include <linux/seq_file.h>
> #include <linux/syscalls.h>
> #include <linux/fcntl.h>
> @@ -805,31 +804,6 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
> return ret;
> }
>
> -static inline void print_unload_info(struct seq_file *m, struct module *mod)
> -{
> - struct module_use *use;
> - int printed_something = 0;
> -
> - seq_printf(m, " %i ", module_refcount(mod));
> -
> - /*
> - * Always include a trailing , so userspace can differentiate
> - * between this and the old multi-field proc format.
> - */
> - list_for_each_entry(use, &mod->source_list, source_list) {
> - printed_something = 1;
> - seq_printf(m, "%s,", use->source->name);
> - }
> -
> - if (mod->init != NULL && mod->exit == NULL) {
> - printed_something = 1;
> - seq_puts(m, "[permanent],");
> - }
> -
> - if (!printed_something)
> - seq_puts(m, "-");
> -}
> -
> void __symbol_put(const char *symbol)
> {
> struct find_symbol_arg fsa = {
> @@ -919,12 +893,6 @@ void module_put(struct module *module)
> EXPORT_SYMBOL(module_put);
>
> #else /* !CONFIG_MODULE_UNLOAD */
> -static inline void print_unload_info(struct seq_file *m, struct module *mod)
> -{
> - /* We don't know the usage count, or what modules are using. */
> - seq_puts(m, " - -");
> -}
> -
> static inline void module_unload_free(struct module *mod)
> {
> }
> @@ -3596,7 +3564,7 @@ static void cfi_cleanup(struct module *mod)
> }
>
> /* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */
> -static char *module_flags(struct module *mod, char *buf)
> +char *module_flags(struct module *mod, char *buf)
> {
> int bx = 0;
>
> @@ -3619,103 +3587,6 @@ static char *module_flags(struct module *mod, char *buf)
> return buf;
> }
>
> -#ifdef CONFIG_PROC_FS
> -/* Called by the /proc file system to return a list of modules. */
> -static void *m_start(struct seq_file *m, loff_t *pos)
> -{
> - mutex_lock(&module_mutex);
> - return seq_list_start(&modules, *pos);
> -}
> -
> -static void *m_next(struct seq_file *m, void *p, loff_t *pos)
> -{
> - return seq_list_next(p, &modules, pos);
> -}
> -
> -static void m_stop(struct seq_file *m, void *p)
> -{
> - mutex_unlock(&module_mutex);
> -}
> -
> -static int m_show(struct seq_file *m, void *p)
> -{
> - struct module *mod = list_entry(p, struct module, list);
> - char buf[MODULE_FLAGS_BUF_SIZE];
> - void *value;
> -
> - /* We always ignore unformed modules. */
> - if (mod->state == MODULE_STATE_UNFORMED)
> - return 0;
> -
> - seq_printf(m, "%s %u",
> - mod->name, mod->init_layout.size + mod->core_layout.size);
> - print_unload_info(m, mod);
> -
> - /* Informative for users. */
> - seq_printf(m, " %s",
> - mod->state == MODULE_STATE_GOING ? "Unloading" :
> - mod->state == MODULE_STATE_COMING ? "Loading" :
> - "Live");
> - /* Used by oprofile and other similar tools. */
> - value = m->private ? NULL : mod->core_layout.base;
> - seq_printf(m, " 0x%px", value);
> -
> - /* Taints info */
> - if (mod->taints)
> - seq_printf(m, " %s", module_flags(mod, buf));
> -
> - seq_puts(m, "\n");
> - return 0;
> -}
> -
> -/*
> - * Format: modulename size refcount deps address
> - *
> - * Where refcount is a number or -, and deps is a comma-separated list
> - * of depends or -.
> - */
> -static const struct seq_operations modules_op = {
> - .start = m_start,
> - .next = m_next,
> - .stop = m_stop,
> - .show = m_show
> -};
> -
> -/*
> - * This also sets the "private" pointer to non-NULL if the
> - * kernel pointers should be hidden (so you can just test
> - * "m->private" to see if you should keep the values private).
> - *
> - * We use the same logic as for /proc/kallsyms.
> - */
> -static int modules_open(struct inode *inode, struct file *file)
> -{
> - int err = seq_open(file, &modules_op);
> -
> - if (!err) {
> - struct seq_file *m = file->private_data;
> - m->private = kallsyms_show_value(file->f_cred) ? NULL : (void *)8ul;
> - }
> -
> - return err;
> -}
> -
> -static const struct proc_ops modules_proc_ops = {
> - .proc_flags = PROC_ENTRY_PERMANENT,
> - .proc_open = modules_open,
> - .proc_read = seq_read,
> - .proc_lseek = seq_lseek,
> - .proc_release = seq_release,
> -};
> -
> -static int __init proc_modules_init(void)
> -{
> - proc_create("modules", 0, NULL, &modules_proc_ops);
> - return 0;
> -}
> -module_init(proc_modules_init);
> -#endif
> -
> /* Given an address, look for it in the module exception tables. */
> const struct exception_table_entry *search_module_extables(unsigned long addr)
> {
> diff --git a/kernel/module/procfs.c b/kernel/module/procfs.c
> new file mode 100644
> index 000000000000..2717e130788e
> --- /dev/null
> +++ b/kernel/module/procfs.c
> @@ -0,0 +1,142 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Module proc support
> + *
> + * Copyright (C) 2008 Alexey Dobriyan
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kallsyms.h>
> +#include <linux/mutex.h>
> +#include <linux/seq_file.h>
> +#include <linux/proc_fs.h>
> +#include "internal.h"
> +
> +#ifdef CONFIG_MODULE_UNLOAD
> +static inline void print_unload_info(struct seq_file *m, struct module *mod)
> +{
> + struct module_use *use;
> + int printed_something = 0;
> +
> + seq_printf(m, " %i ", module_refcount(mod));
> +
> + /*
> + * Always include a trailing , so userspace can differentiate
> + * between this and the old multi-field proc format.
> + */
> + list_for_each_entry(use, &mod->source_list, source_list) {
> + printed_something = 1;
> + seq_printf(m, "%s,", use->source->name);
> + }
> +
> + if (mod->init && !mod->exit) {
> + printed_something = 1;
> + seq_puts(m, "[permanent],");
> + }
> +
> + if (!printed_something)
> + seq_puts(m, "-");
> +}
> +#else /* !CONFIG_MODULE_UNLOAD */
> +static inline void print_unload_info(struct seq_file *m, struct module *mod)
> +{
> + /* We don't know the usage count, or what modules are using. */
> + seq_puts(m, " - -");
> +}
> +#endif /* CONFIG_MODULE_UNLOAD */
> +
> +/* Called by the /proc file system to return a list of modules. */
> +static void *m_start(struct seq_file *m, loff_t *pos)
> +{
> + mutex_lock(&module_mutex);
> + return seq_list_start(&modules, *pos);
> +}
> +
> +static void *m_next(struct seq_file *m, void *p, loff_t *pos)
> +{
> + return seq_list_next(p, &modules, pos);
> +}
> +
> +static void m_stop(struct seq_file *m, void *p)
> +{
> + mutex_unlock(&module_mutex);
> +}
> +
> +static int m_show(struct seq_file *m, void *p)
> +{
> + struct module *mod = list_entry(p, struct module, list);
> + char buf[MODULE_FLAGS_BUF_SIZE];
> + void *value;
> +
> + /* We always ignore unformed modules. */
> + if (mod->state == MODULE_STATE_UNFORMED)
> + return 0;
> +
> + seq_printf(m, "%s %u",
> + mod->name, mod->init_layout.size + mod->core_layout.size);
> + print_unload_info(m, mod);
> +
> + /* Informative for users. */
> + seq_printf(m, " %s",
> + mod->state == MODULE_STATE_GOING ? "Unloading" :
> + mod->state == MODULE_STATE_COMING ? "Loading" :
> + "Live");
> + /* Used by oprofile and other similar tools. */
> + value = m->private ? NULL : mod->core_layout.base;
> + seq_printf(m, " 0x%px", value);
> +
> + /* Taints info */
> + if (mod->taints)
> + seq_printf(m, " %s", module_flags(mod, buf));
> +
> + seq_puts(m, "\n");
> + return 0;
> +}
> +
> +/*
> + * Format: modulename size refcount deps address
> + *
> + * Where refcount is a number or -, and deps is a comma-separated list
> + * of depends or -.
> + */
> +static const struct seq_operations modules_op = {
> + .start = m_start,
> + .next = m_next,
> + .stop = m_stop,
> + .show = m_show
> +};
> +
> +/*
> + * This also sets the "private" pointer to non-NULL if the
> + * kernel pointers should be hidden (so you can just test
> + * "m->private" to see if you should keep the values private).
> + *
> + * We use the same logic as for /proc/kallsyms.
> + */
> +static int modules_open(struct inode *inode, struct file *file)
> +{
> + int err = seq_open(file, &modules_op);
> +
> + if (!err) {
> + struct seq_file *m = file->private_data;
> +
> + m->private = kallsyms_show_value(file->f_cred) ? NULL : (void *)8ul;
> + }
> +
> + return err;
> +}
> +
> +static const struct proc_ops modules_proc_ops = {
> + .proc_flags = PROC_ENTRY_PERMANENT,
> + .proc_open = modules_open,
> + .proc_read = seq_read,
> + .proc_lseek = seq_lseek,
> + .proc_release = seq_release,
> +};
> +
> +static int __init proc_modules_init(void)
> +{
> + proc_create("modules", 0, NULL, &modules_proc_ops);
> + return 0;
> +}
> +module_init(proc_modules_init);
next prev parent reply other threads:[~2022-02-22 17:59 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 14:12 [PATCH v8 00/13] module: core code clean up Aaron Tomlin
2022-02-22 14:12 ` [PATCH v8 01/13] module: Move all into module/ Aaron Tomlin
2022-02-22 17:58 ` Christophe Leroy
2022-02-22 20:00 ` Allen
2022-02-22 14:12 ` [PATCH v8 02/13] module: Simple refactor in preparation for split Aaron Tomlin
2022-02-22 17:58 ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 03/13] module: Make internal.h and decompress.c more compliant Aaron Tomlin
2022-02-22 14:12 ` [PATCH v8 04/13] module: Move livepatch support to a separate file Aaron Tomlin
2022-02-22 17:58 ` Christophe Leroy
2022-02-25 9:34 ` Petr Mladek
2022-02-25 10:33 ` Aaron Tomlin
2022-02-25 16:49 ` Christophe Leroy
2022-02-28 10:56 ` Petr Mladek
2022-02-28 11:46 ` Christophe Leroy
2022-02-28 13:05 ` Petr Mladek
2022-02-22 14:12 ` [PATCH v8 05/13] module: Move latched RB-tree " Aaron Tomlin
2022-02-22 17:58 ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 06/13] module: Move strict rwx " Aaron Tomlin
2022-02-22 17:59 ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 07/13] module: Move extra signature support out of core code Aaron Tomlin
2022-02-22 17:59 ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 08/13] module: Move kmemleak support to a separate file Aaron Tomlin
2022-02-22 17:59 ` Christophe Leroy
2022-02-22 14:12 ` [PATCH v8 09/13] module: Move kallsyms support into " Aaron Tomlin
2022-02-22 17:59 ` Christophe Leroy
2022-02-25 9:15 ` Petr Mladek
2022-02-25 9:27 ` Christophe Leroy
2022-02-25 10:15 ` Petr Mladek
2022-02-25 10:27 ` Aaron Tomlin
2022-02-25 12:21 ` Aaron Tomlin
2022-02-25 12:57 ` Christophe Leroy
2022-02-26 20:27 ` Luis Chamberlain
2022-02-28 9:02 ` Christophe Leroy
2022-02-28 9:31 ` Aaron Tomlin
2022-02-28 9:33 ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 10/13] module: Move procfs " Aaron Tomlin
2022-02-22 17:59 ` Christophe Leroy [this message]
2022-02-22 14:13 ` [PATCH v8 11/13] module: Move sysfs " Aaron Tomlin
2022-02-22 17:59 ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 12/13] module: Move kdb_modules list out of core code Aaron Tomlin
2022-02-22 18:05 ` Christophe Leroy
2022-02-22 14:13 ` [PATCH v8 13/13] module: Move version support into a separate file Aaron Tomlin
2022-02-22 18:06 ` Christophe Leroy
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=cf6a2db2-7155-e1fa-2bce-e8caa2deff69@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=akpm@linux-foundation.org \
--cc=allen.lkml@gmail.com \
--cc=atomlin@atomlin.com \
--cc=atomlin@redhat.com \
--cc=cl@linux.com \
--cc=jeyu@kernel.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mcgrof@kernel.org \
--cc=msuchanek@suse.de \
--cc=oleksandr@natalenko.name \
--cc=pmladek@suse.com \
--cc=void@manifault.com \
/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).