linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] module: add usage links when calling ref_module func
@ 2019-06-28 12:32 Zhiqiang Liu
  2019-07-01 13:55 ` Jessica Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Zhiqiang Liu @ 2019-06-28 12:32 UTC (permalink / raw)
  To: jeyu, rusty, kay.sievers, clabbe.montjoie
  Cc: linux-kernel, wangxiaogang (F), Zhoukang (A), Mingfangsen

From: Zhiqiang Liu <liuzhiqiang26@huawei.com>

Problem: Users can call ref_module func in their modules to construct
relationships with other modules. However, the holders
'/sys/module/<mod-name>/holders' of the target module donot include
the users` module. So lsmod command misses detailed info of 'Used by'.

When load module, the process is given as follows,
load_module()
	-> mod_sysfs_setup()
		-> add_usage_links
	-> do_init_module
		-> mod->init()

add_usage_links func creates holders of target modules linking to
this module. If ref_module is called in mod->init() func, the usage
links cannot be added.

Here, we will add usage link of a to b's holder_dir.

Fixes: 9bea7f239 ("module: fix bne2 "gave up waiting for init of module libcrc32c")
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 kernel/module.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/module.c b/kernel/module.c
index 80c7c09584cf..11c6aff37b1f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -871,6 +871,11 @@ int ref_module(struct module *a, struct module *b)
 		module_put(b);
 		return err;
 	}
+
+	err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
+	if (err)
+		return err;
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ref_module);
-- 
2.19.1


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

* Re: [PATCH] module: add usage links when calling ref_module func
  2019-06-28 12:32 [PATCH] module: add usage links when calling ref_module func Zhiqiang Liu
@ 2019-07-01 13:55 ` Jessica Yu
  2019-07-03  1:28   ` Zhiqiang Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Jessica Yu @ 2019-07-01 13:55 UTC (permalink / raw)
  To: Zhiqiang Liu
  Cc: rusty, kay.sievers, clabbe.montjoie, linux-kernel,
	wangxiaogang (F), Zhoukang (A),
	Mingfangsen

+++ Zhiqiang Liu [28/06/19 20:32 +0800]:
>From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>
>Problem: Users can call ref_module func in their modules to construct
>relationships with other modules. However, the holders
>'/sys/module/<mod-name>/holders' of the target module donot include
>the users` module. So lsmod command misses detailed info of 'Used by'.
>
>When load module, the process is given as follows,
>load_module()
>	-> mod_sysfs_setup()
>		-> add_usage_links
>	-> do_init_module
>		-> mod->init()
>
>add_usage_links func creates holders of target modules linking to
>this module. If ref_module is called in mod->init() func, the usage
>links cannot be added.
>
>Here, we will add usage link of a to b's holder_dir.
>
>Fixes: 9bea7f239 ("module: fix bne2 "gave up waiting for init of module libcrc32c")

I think we can drop this tag; it doesn't fix a bug specifically
introduced by that particular commit.

>Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>---
> kernel/module.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
>diff --git a/kernel/module.c b/kernel/module.c
>index 80c7c09584cf..11c6aff37b1f 100644
>--- a/kernel/module.c
>+++ b/kernel/module.c
>@@ -871,6 +871,11 @@ int ref_module(struct module *a, struct module *b)
> 		module_put(b);
> 		return err;
> 	}
>+
>+	err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
>+	if (err)
>+		return err;

We need to fix the error handling here - the module_use struct
allocated in the call to add_module_usage() needs to be freed (you
could just modify add_module_usage() to return the use pointer so that
it's easier to free from within ref_module()), module_put() needs to
be called, and the use struct should be removed from its respective
lists (see module_unload_free()).

Thanks,

Jessica


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

* Re: [PATCH] module: add usage links when calling ref_module func
  2019-07-01 13:55 ` Jessica Yu
@ 2019-07-03  1:28   ` Zhiqiang Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Zhiqiang Liu @ 2019-07-03  1:28 UTC (permalink / raw)
  To: Jessica Yu
  Cc: rusty, kay.sievers, clabbe.montjoie, linux-kernel,
	wangxiaogang (F), Zhoukang (A),
	Mingfangsen

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 1984 bytes --]

On 2019/7/1 21:55, Jessica Yu wrote:
> +++ Zhiqiang Liu [28/06/19 20:32 +0800]:
>> From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>>
>> Problem: Users can call ref_module func in their modules to construct
>> relationships with other modules. However, the holders
>> '/sys/module/<mod-name>/holders' of the target module donot include
>> the users` module. So lsmod command misses detailed info of 'Used by'.
>>
>> Here, we will add usage link of a to b's holder_dir.
>>
>> Fixes: 9bea7f239 ("module: fix bne2 "gave up waiting for init of module libcrc32c")
> 
> I think we can drop this tag; it doesn't fix a bug specifically
> introduced by that particular commit.
> 
Thanks for your reply.
I will remove the Fixes tag in v2 patch.

>> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>> ---
>> kernel/module.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/kernel/module.c b/kernel/module.c
>> index 80c7c09584cf..11c6aff37b1f 100644
>> --- a/kernel/module.c
>> +++ b/kernel/module.c
>> @@ -871,6 +871,11 @@ int ref_module(struct module *a, struct module *b)
>> 0„20„20„20„20„20„20„2 module_put(b);
>> 0„20„20„20„20„20„20„2 return err;
>> 0„20„20„20„2}
>> +
>> +0„20„20„2 err = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
>> +0„20„20„2 if (err)
>> +0„20„20„20„20„20„20„2 return err;
> 
> We need to fix the error handling here - the module_use struct
> allocated in the call to add_module_usage() needs to be freed (you
> could just modify add_module_usage() to return the use pointer so that
> it's easier to free from within ref_module()), module_put() needs to
> be called, and the use struct should be removed from its respective
> lists (see module_unload_free()).
> 
Thanks again for your advice.
We will modify add_module_usage func to return the use pointer as your suggestion.
In the error handling, We will call module_put() and call list_del() to remove the use.

> Thanks,
> 
> Jessica
> 
> 
> .
> 


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

end of thread, other threads:[~2019-07-03  1:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-28 12:32 [PATCH] module: add usage links when calling ref_module func Zhiqiang Liu
2019-07-01 13:55 ` Jessica Yu
2019-07-03  1:28   ` Zhiqiang Liu

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).