linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001()
@ 2020-04-18  5:19 Tiezhu Yang
  2020-04-18  5:19 ` [PATCH 2/4] kmod: Remove redundant "be an" in the comment Tiezhu Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-18  5:19 UTC (permalink / raw)
  To: Luis Chamberlain, Shuah Khan; +Cc: linux-kselftest, linux-kernel, Xuefeng Li

Use the variable NAME instead of "\000" directly in kmod_test_0001().

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/testing/selftests/kmod/kmod.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kmod/kmod.sh b/tools/testing/selftests/kmod/kmod.sh
index 3702dbc..da60c3b 100755
--- a/tools/testing/selftests/kmod/kmod.sh
+++ b/tools/testing/selftests/kmod/kmod.sh
@@ -341,7 +341,7 @@ kmod_test_0001_driver()
 
 	kmod_defaults_driver
 	config_num_threads 1
-	printf '\000' >"$DIR"/config_test_driver
+	printf $NAME >"$DIR"/config_test_driver
 	config_trigger ${FUNCNAME[0]}
 	config_expect_result ${FUNCNAME[0]} MODULE_NOT_FOUND
 }
@@ -352,7 +352,7 @@ kmod_test_0001_fs()
 
 	kmod_defaults_fs
 	config_num_threads 1
-	printf '\000' >"$DIR"/config_test_fs
+	printf $NAME >"$DIR"/config_test_fs
 	config_trigger ${FUNCNAME[0]}
 	config_expect_result ${FUNCNAME[0]} -EINVAL
 }
-- 
2.1.0


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

* [PATCH 2/4] kmod: Remove redundant "be an" in the comment
  2020-04-18  5:19 [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Tiezhu Yang
@ 2020-04-18  5:19 ` Tiezhu Yang
  2020-04-18  5:47   ` Luis Chamberlain
  2020-04-18  5:19 ` [PATCH 3/4] kmod: Return directly if module name is empty in request_module() Tiezhu Yang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-18  5:19 UTC (permalink / raw)
  To: Luis Chamberlain, Shuah Khan; +Cc: linux-kselftest, linux-kernel, Xuefeng Li

There exists redundant "be an" in the comment, remove it.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 kernel/kmod.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/kmod.c b/kernel/kmod.c
index 37c3c4b..3cd075c 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -36,9 +36,8 @@
  *
  * If you need less than 50 threads would mean we're dealing with systems
  * smaller than 3200 pages. This assumes you are capable of having ~13M memory,
- * and this would only be an be an upper limit, after which the OOM killer
- * would take effect. Systems like these are very unlikely if modules are
- * enabled.
+ * and this would only be an upper limit, after which the OOM killer would take
+ * effect. Systems like these are very unlikely if modules are enabled.
  */
 #define MAX_KMOD_CONCURRENT 50
 static atomic_t kmod_concurrent_max = ATOMIC_INIT(MAX_KMOD_CONCURRENT);
-- 
2.1.0


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

* [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-18  5:19 [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Tiezhu Yang
  2020-04-18  5:19 ` [PATCH 2/4] kmod: Remove redundant "be an" in the comment Tiezhu Yang
@ 2020-04-18  5:19 ` Tiezhu Yang
  2020-04-18  5:45   ` Luis Chamberlain
  2020-04-18  5:20 ` [PATCH 4/4] test_kmod: Avoid potential double free in trigger_config_run_type() Tiezhu Yang
  2020-04-18  5:46 ` [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Luis Chamberlain
  3 siblings, 1 reply; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-18  5:19 UTC (permalink / raw)
  To: Luis Chamberlain, Shuah Khan; +Cc: linux-kselftest, linux-kernel, Xuefeng Li

If module name is empty, it is better to return directly at the beginning
of request_module() without doing the needless call_modprobe() operation.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 kernel/kmod.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/kmod.c b/kernel/kmod.c
index 3cd075c..5851444 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -28,6 +28,8 @@
 
 #include <trace/events/module.h>
 
+#define MODULE_NOT_FOUND 256
+
 /*
  * Assuming:
  *
@@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
 	if (ret >= MODULE_NAME_LEN)
 		return -ENAMETOOLONG;
 
+	if (strlen(module_name) == 0)
+		return MODULE_NOT_FOUND;
+
 	ret = security_kernel_module_request(module_name);
 	if (ret)
 		return ret;
-- 
2.1.0


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

* [PATCH 4/4] test_kmod: Avoid potential double free in trigger_config_run_type()
  2020-04-18  5:19 [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Tiezhu Yang
  2020-04-18  5:19 ` [PATCH 2/4] kmod: Remove redundant "be an" in the comment Tiezhu Yang
  2020-04-18  5:19 ` [PATCH 3/4] kmod: Return directly if module name is empty in request_module() Tiezhu Yang
@ 2020-04-18  5:20 ` Tiezhu Yang
  2020-04-18  5:47   ` Luis Chamberlain
  2020-04-18  5:46 ` [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Luis Chamberlain
  3 siblings, 1 reply; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-18  5:20 UTC (permalink / raw)
  To: Luis Chamberlain, Shuah Khan; +Cc: linux-kselftest, linux-kernel, Xuefeng Li

It should set config->test_fs instead of config->test_driver as NULL
after kfree_const(config->test_fs) to avoid potential double free.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 lib/test_kmod.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/test_kmod.c b/lib/test_kmod.c
index e651c37..eab5277 100644
--- a/lib/test_kmod.c
+++ b/lib/test_kmod.c
@@ -745,7 +745,7 @@ static int trigger_config_run_type(struct kmod_test_device *test_dev,
 		break;
 	case TEST_KMOD_FS_TYPE:
 		kfree_const(config->test_fs);
-		config->test_driver = NULL;
+		config->test_fs = NULL;
 		copied = config_copy_test_fs(config, test_str,
 					     strlen(test_str));
 		break;
-- 
2.1.0


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

* Re: [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-18  5:19 ` [PATCH 3/4] kmod: Return directly if module name is empty in request_module() Tiezhu Yang
@ 2020-04-18  5:45   ` Luis Chamberlain
  2020-04-18  5:48     ` Luis Chamberlain
  0 siblings, 1 reply; 13+ messages in thread
From: Luis Chamberlain @ 2020-04-18  5:45 UTC (permalink / raw)
  To: Tiezhu Yang; +Cc: Shuah Khan, linux-kselftest, linux-kernel, Xuefeng Li

On Sat, Apr 18, 2020 at 01:19:59PM +0800, Tiezhu Yang wrote:
> If module name is empty, it is better to return directly at the beginning
> of request_module() without doing the needless call_modprobe() operation.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  kernel/kmod.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/kernel/kmod.c b/kernel/kmod.c
> index 3cd075c..5851444 100644
> --- a/kernel/kmod.c
> +++ b/kernel/kmod.c
> @@ -28,6 +28,8 @@
>  
>  #include <trace/events/module.h>
>  
> +#define MODULE_NOT_FOUND 256
> +
>  /*
>   * Assuming:
>   *
> @@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
>  	if (ret >= MODULE_NAME_LEN)
>  		return -ENAMETOOLONG;
>  
> +	if (strlen(module_name) == 0)
> +		return MODULE_NOT_FOUND;

I'd rather we just use something standard like -EINVAL.
What do we return if its not found? Then use that value.

> +
>  	ret = security_kernel_module_request(module_name);
>  	if (ret)
>  		return ret;
> -- 
> 2.1.0
> 

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

* Re: [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001()
  2020-04-18  5:19 [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Tiezhu Yang
                   ` (2 preceding siblings ...)
  2020-04-18  5:20 ` [PATCH 4/4] test_kmod: Avoid potential double free in trigger_config_run_type() Tiezhu Yang
@ 2020-04-18  5:46 ` Luis Chamberlain
  3 siblings, 0 replies; 13+ messages in thread
From: Luis Chamberlain @ 2020-04-18  5:46 UTC (permalink / raw)
  To: Tiezhu Yang, Andrew Morton
  Cc: Shuah Khan, linux-kselftest, linux-kernel, Xuefeng Li

On Sat, Apr 18, 2020 at 01:19:57PM +0800, Tiezhu Yang wrote:
> Use the variable NAME instead of "\000" directly in kmod_test_0001().
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Acked-by: Luis Chamberlain <mcgrof@kernel.org>

  Luis

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

* Re: [PATCH 2/4] kmod: Remove redundant "be an" in the comment
  2020-04-18  5:19 ` [PATCH 2/4] kmod: Remove redundant "be an" in the comment Tiezhu Yang
@ 2020-04-18  5:47   ` Luis Chamberlain
  0 siblings, 0 replies; 13+ messages in thread
From: Luis Chamberlain @ 2020-04-18  5:47 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Shuah Khan, linux-kselftest, linux-kernel, Xuefeng Li, Andrew Morton

On Sat, Apr 18, 2020 at 01:19:58PM +0800, Tiezhu Yang wrote:
> There exists redundant "be an" in the comment, remove it.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Acked-by: Luis Chamberlain <mcgrof@kernel.org>

  Luis

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

* Re: [PATCH 4/4] test_kmod: Avoid potential double free in trigger_config_run_type()
  2020-04-18  5:20 ` [PATCH 4/4] test_kmod: Avoid potential double free in trigger_config_run_type() Tiezhu Yang
@ 2020-04-18  5:47   ` Luis Chamberlain
  0 siblings, 0 replies; 13+ messages in thread
From: Luis Chamberlain @ 2020-04-18  5:47 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Shuah Khan, linux-kselftest, linux-kernel, Xuefeng Li, Andrew Morton

On Sat, Apr 18, 2020 at 01:20:00PM +0800, Tiezhu Yang wrote:
> It should set config->test_fs instead of config->test_driver as NULL
> after kfree_const(config->test_fs) to avoid potential double free.
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

Acked-by:  Luis Chamberlain <mcgrof@kernel.org>

   Luis

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

* Re: [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-18  5:45   ` Luis Chamberlain
@ 2020-04-18  5:48     ` Luis Chamberlain
  2020-04-18  5:58       ` Tiezhu Yang
  0 siblings, 1 reply; 13+ messages in thread
From: Luis Chamberlain @ 2020-04-18  5:48 UTC (permalink / raw)
  To: Tiezhu Yang, Andrew Morton
  Cc: Shuah Khan, open list:KERNEL SELFTEST FRAMEWORK, linux-kernel,
	Xuefeng Li

On Fri, Apr 17, 2020 at 11:45 PM Luis Chamberlain <mcgrof@kernel.org> wrote:
>
> On Sat, Apr 18, 2020 at 01:19:59PM +0800, Tiezhu Yang wrote:
> > If module name is empty, it is better to return directly at the beginning
> > of request_module() without doing the needless call_modprobe() operation.
> >
> > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> > ---
> >  kernel/kmod.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/kernel/kmod.c b/kernel/kmod.c
> > index 3cd075c..5851444 100644
> > --- a/kernel/kmod.c
> > +++ b/kernel/kmod.c
> > @@ -28,6 +28,8 @@
> >
> >  #include <trace/events/module.h>
> >
> > +#define MODULE_NOT_FOUND 256
> > +
> >  /*
> >   * Assuming:
> >   *
> > @@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
> >       if (ret >= MODULE_NAME_LEN)
> >               return -ENAMETOOLONG;
> >
> > +     if (strlen(module_name) == 0)
> > +             return MODULE_NOT_FOUND;
>
> I'd rather we just use something standard like -EINVAL.
> What do we return if its not found? Then use that value.

Also, are we testing for this condition yet? If not can we add one?

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

* Re: [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-18  5:48     ` Luis Chamberlain
@ 2020-04-18  5:58       ` Tiezhu Yang
  2020-04-18  7:19         ` Luis Chamberlain
  0 siblings, 1 reply; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-18  5:58 UTC (permalink / raw)
  To: Luis Chamberlain, Andrew Morton
  Cc: Shuah Khan, open list:KERNEL SELFTEST FRAMEWORK, linux-kernel,
	Xuefeng Li

On 04/18/2020 01:48 PM, Luis Chamberlain wrote:
> On Fri, Apr 17, 2020 at 11:45 PM Luis Chamberlain <mcgrof@kernel.org> wrote:
>> On Sat, Apr 18, 2020 at 01:19:59PM +0800, Tiezhu Yang wrote:
>>> If module name is empty, it is better to return directly at the beginning
>>> of request_module() without doing the needless call_modprobe() operation.
>>>
>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>>> ---
>>>   kernel/kmod.c | 5 +++++
>>>   1 file changed, 5 insertions(+)
>>>
>>> diff --git a/kernel/kmod.c b/kernel/kmod.c
>>> index 3cd075c..5851444 100644
>>> --- a/kernel/kmod.c
>>> +++ b/kernel/kmod.c
>>> @@ -28,6 +28,8 @@
>>>
>>>   #include <trace/events/module.h>
>>>
>>> +#define MODULE_NOT_FOUND 256
>>> +
>>>   /*
>>>    * Assuming:
>>>    *
>>> @@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
>>>        if (ret >= MODULE_NAME_LEN)
>>>                return -ENAMETOOLONG;
>>>
>>> +     if (strlen(module_name) == 0)
>>> +             return MODULE_NOT_FOUND;
>> I'd rather we just use something standard like -EINVAL.
>> What do we return if its not found? Then use that value.
> Also, are we testing for this condition yet? If not can we add one?

Yes, kmod_test_0001_driver() in tools/testing/selftests/kmod/kmod.sh tests
this case and expects result MODULE_NOT_FOUND which is 256.


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

* Re: [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-18  5:58       ` Tiezhu Yang
@ 2020-04-18  7:19         ` Luis Chamberlain
  2020-04-20  4:08           ` Tiezhu Yang
  0 siblings, 1 reply; 13+ messages in thread
From: Luis Chamberlain @ 2020-04-18  7:19 UTC (permalink / raw)
  To: Tiezhu Yang, Jessica Yu
  Cc: Andrew Morton, Shuah Khan, open list:KERNEL SELFTEST FRAMEWORK,
	linux-kernel, Xuefeng Li

On Sat, Apr 18, 2020 at 01:58:45PM +0800, Tiezhu Yang wrote:
> On 04/18/2020 01:48 PM, Luis Chamberlain wrote:
> > On Fri, Apr 17, 2020 at 11:45 PM Luis Chamberlain <mcgrof@kernel.org> wrote:
> > > On Sat, Apr 18, 2020 at 01:19:59PM +0800, Tiezhu Yang wrote:
> > > > If module name is empty, it is better to return directly at the beginning
> > > > of request_module() without doing the needless call_modprobe() operation.
> > > > 
> > > > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> > > > ---
> > > >   kernel/kmod.c | 5 +++++
> > > >   1 file changed, 5 insertions(+)
> > > > 
> > > > diff --git a/kernel/kmod.c b/kernel/kmod.c
> > > > index 3cd075c..5851444 100644
> > > > --- a/kernel/kmod.c
> > > > +++ b/kernel/kmod.c
> > > > @@ -28,6 +28,8 @@
> > > > 
> > > >   #include <trace/events/module.h>
> > > > 
> > > > +#define MODULE_NOT_FOUND 256
> > > > +
> > > >   /*
> > > >    * Assuming:
> > > >    *
> > > > @@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
> > > >        if (ret >= MODULE_NAME_LEN)
> > > >                return -ENAMETOOLONG;
> > > > 
> > > > +     if (strlen(module_name) == 0)
> > > > +             return MODULE_NOT_FOUND;
> > > I'd rather we just use something standard like -EINVAL.
> > > What do we return if its not found? Then use that value.
> > Also, are we testing for this condition yet? If not can we add one?
> 
> Yes, kmod_test_0001_driver() in tools/testing/selftests/kmod/kmod.sh tests
> this case and expects result MODULE_NOT_FOUND which is 256.

OK I see now I had put:

errno_name_to_val()                                                             
{                                                                               
        case "$1" in                                                            
	# kmod calls modprobe and upon of a module not found                    
	# modprobe returns just 1... However in the
	# kernel we *sometimes* see 256... 
	MODULE_NOT_FOUND)                                                       
		echo 256;;

I found that through testing, however there was nothing set in stone,
nothing documented. While you are at it, can you find the places where
this is returned in the kernel code? We should clear this up and
se things straight. We cannot change what we gave userspace already
though.

  Luis

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

* Re: [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-18  7:19         ` Luis Chamberlain
@ 2020-04-20  4:08           ` Tiezhu Yang
  2020-04-20  4:11             ` Tiezhu Yang
  0 siblings, 1 reply; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-20  4:08 UTC (permalink / raw)
  To: Luis Chamberlain, Jessica Yu
  Cc: Andrew Morton, Shuah Khan, open list:KERNEL SELFTEST FRAMEWORK,
	linux-kernel, Xuefeng Li

On 04/18/2020 03:19 PM, Luis Chamberlain wrote:
> On Sat, Apr 18, 2020 at 01:58:45PM +0800, Tiezhu Yang wrote:
>> On 04/18/2020 01:48 PM, Luis Chamberlain wrote:
>>> On Fri, Apr 17, 2020 at 11:45 PM Luis Chamberlain <mcgrof@kernel.org> wrote:
>>>> On Sat, Apr 18, 2020 at 01:19:59PM +0800, Tiezhu Yang wrote:
>>>>> If module name is empty, it is better to return directly at the beginning
>>>>> of request_module() without doing the needless call_modprobe() operation.
>>>>>
>>>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>>>>> ---
>>>>>    kernel/kmod.c | 5 +++++
>>>>>    1 file changed, 5 insertions(+)
>>>>>
>>>>> diff --git a/kernel/kmod.c b/kernel/kmod.c
>>>>> index 3cd075c..5851444 100644
>>>>> --- a/kernel/kmod.c
>>>>> +++ b/kernel/kmod.c
>>>>> @@ -28,6 +28,8 @@
>>>>>
>>>>>    #include <trace/events/module.h>
>>>>>
>>>>> +#define MODULE_NOT_FOUND 256
>>>>> +
>>>>>    /*
>>>>>     * Assuming:
>>>>>     *
>>>>> @@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
>>>>>         if (ret >= MODULE_NAME_LEN)
>>>>>                 return -ENAMETOOLONG;
>>>>>
>>>>> +     if (strlen(module_name) == 0)
>>>>> +             return MODULE_NOT_FOUND;
>>>> I'd rather we just use something standard like -EINVAL.
>>>> What do we return if its not found? Then use that value.
>>> Also, are we testing for this condition yet? If not can we add one?
>> Yes, kmod_test_0001_driver() in tools/testing/selftests/kmod/kmod.sh tests
>> this case and expects result MODULE_NOT_FOUND which is 256.
> OK I see now I had put:
>
> errno_name_to_val()
> {
>          case "$1" in
> 	# kmod calls modprobe and upon of a module not found
> 	# modprobe returns just 1... However in the
> 	# kernel we *sometimes* see 256...
> 	MODULE_NOT_FOUND)
> 		echo 256;;
>
> I found that through testing, however there was nothing set in stone,
> nothing documented. While you are at it, can you find the places where
> this is returned in the kernel code? We should clear this up and
> se things straight. We cannot change what we gave userspace already
> though.

Call Trace:

__request_module()
       |
       |
call_modprobe()
       |
       |
call_usermodehelper_exec()   -- retval = sub_info->retval;
       |
       |
call_usermodehelper_exec_work()
       |
       |
call_usermodehelper_exec_sync()   -- sub_info->retval = ret;
       |
       | --> call_usermodehelper_exec_async() --> do_execve()
       |
kernel_wait4(pid, (int __user *)&ret, 0, NULL);

__request_module() returns the exist status of child process, if module name
is empty or non-exist, sub_info->retval is 256 after call kernel_wait4().

Should I add this analysis to the commit message?

Thanks,
Tiezhu Yang

>
>    Luis


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

* Re: [PATCH 3/4] kmod: Return directly if module name is empty in request_module()
  2020-04-20  4:08           ` Tiezhu Yang
@ 2020-04-20  4:11             ` Tiezhu Yang
  0 siblings, 0 replies; 13+ messages in thread
From: Tiezhu Yang @ 2020-04-20  4:11 UTC (permalink / raw)
  To: Luis Chamberlain, Jessica Yu
  Cc: Andrew Morton, Shuah Khan, open list:KERNEL SELFTEST FRAMEWORK,
	linux-kernel, Xuefeng Li

On 04/20/2020 12:08 PM, Tiezhu Yang wrote:
> On 04/18/2020 03:19 PM, Luis Chamberlain wrote:
>> On Sat, Apr 18, 2020 at 01:58:45PM +0800, Tiezhu Yang wrote:
>>> On 04/18/2020 01:48 PM, Luis Chamberlain wrote:
>>>> On Fri, Apr 17, 2020 at 11:45 PM Luis Chamberlain 
>>>> <mcgrof@kernel.org> wrote:
>>>>> On Sat, Apr 18, 2020 at 01:19:59PM +0800, Tiezhu Yang wrote:
>>>>>> If module name is empty, it is better to return directly at the 
>>>>>> beginning
>>>>>> of request_module() without doing the needless call_modprobe() 
>>>>>> operation.
>>>>>>
>>>>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>>>>>> ---
>>>>>>    kernel/kmod.c | 5 +++++
>>>>>>    1 file changed, 5 insertions(+)
>>>>>>
>>>>>> diff --git a/kernel/kmod.c b/kernel/kmod.c
>>>>>> index 3cd075c..5851444 100644
>>>>>> --- a/kernel/kmod.c
>>>>>> +++ b/kernel/kmod.c
>>>>>> @@ -28,6 +28,8 @@
>>>>>>
>>>>>>    #include <trace/events/module.h>
>>>>>>
>>>>>> +#define MODULE_NOT_FOUND 256
>>>>>> +
>>>>>>    /*
>>>>>>     * Assuming:
>>>>>>     *
>>>>>> @@ -144,6 +146,9 @@ int __request_module(bool wait, const char 
>>>>>> *fmt, ...)
>>>>>>         if (ret >= MODULE_NAME_LEN)
>>>>>>                 return -ENAMETOOLONG;
>>>>>>
>>>>>> +     if (strlen(module_name) == 0)
>>>>>> +             return MODULE_NOT_FOUND;
>>>>> I'd rather we just use something standard like -EINVAL.
>>>>> What do we return if its not found? Then use that value.
>>>> Also, are we testing for this condition yet? If not can we add one?
>>> Yes, kmod_test_0001_driver() in tools/testing/selftests/kmod/kmod.sh 
>>> tests
>>> this case and expects result MODULE_NOT_FOUND which is 256.
>> OK I see now I had put:
>>
>> errno_name_to_val()
>> {
>>          case "$1" in
>>     # kmod calls modprobe and upon of a module not found
>>     # modprobe returns just 1... However in the
>>     # kernel we *sometimes* see 256...
>>     MODULE_NOT_FOUND)
>>         echo 256;;
>>
>> I found that through testing, however there was nothing set in stone,
>> nothing documented. While you are at it, can you find the places where
>> this is returned in the kernel code? We should clear this up and
>> se things straight. We cannot change what we gave userspace already
>> though.
>
> Call Trace:
>
> __request_module()
>       |
>       |
> call_modprobe()
>       |
>       |
> call_usermodehelper_exec()   -- retval = sub_info->retval;
>       |
>       |
> call_usermodehelper_exec_work()
>       |
>       |
> call_usermodehelper_exec_sync()   -- sub_info->retval = ret;
>       |
>       | --> call_usermodehelper_exec_async() --> do_execve()
>       |
> kernel_wait4(pid, (int __user *)&ret, 0, NULL);
>
> __request_module() returns the exist status of child process, if 
> module name

Sorry for the typo: exist status --> exit status

> is empty or non-exist, sub_info->retval is 256 after call kernel_wait4().
>
> Should I add this analysis to the commit message?
>
> Thanks,
> Tiezhu Yang
>
>>
>>    Luis
>


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

end of thread, other threads:[~2020-04-20  4:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18  5:19 [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Tiezhu Yang
2020-04-18  5:19 ` [PATCH 2/4] kmod: Remove redundant "be an" in the comment Tiezhu Yang
2020-04-18  5:47   ` Luis Chamberlain
2020-04-18  5:19 ` [PATCH 3/4] kmod: Return directly if module name is empty in request_module() Tiezhu Yang
2020-04-18  5:45   ` Luis Chamberlain
2020-04-18  5:48     ` Luis Chamberlain
2020-04-18  5:58       ` Tiezhu Yang
2020-04-18  7:19         ` Luis Chamberlain
2020-04-20  4:08           ` Tiezhu Yang
2020-04-20  4:11             ` Tiezhu Yang
2020-04-18  5:20 ` [PATCH 4/4] test_kmod: Avoid potential double free in trigger_config_run_type() Tiezhu Yang
2020-04-18  5:47   ` Luis Chamberlain
2020-04-18  5:46 ` [PATCH 1/4] selftests: kmod: Use variable NAME in kmod_test_0001() Luis Chamberlain

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