Skip to contentSkip to conversation

call_usermodehelper_setup() should use GFP_KERNEL

PATCH In review KOSAKI Motohiro 4 participants 12 messages May 8, 2008 – May 9, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 call_usermodehelper_setup() should use GFP_KERNEL

Now, call_usermodehelper_setup() use GFP_ATOMIC.
but it is slighly odd.
because call_usermodehelper() is always called process context.

GFP_KERNEL is robust and better.

CC "Paul Menage" <[email protected]>
CC Li Zefan <[email protected]>
CC Jeremy Fitzhardinge <[email protected]>
CC Andi Kleen <[email protected]>
CC Rusty Russell <[email protected]>
---
 kernel/kmod.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kmod.c +1 -1
Index: b/kernel/kmod.c
===================================================================
@@ -360,7 +360,7 @@ struct subprocess_info *call_usermodehel
 						  char **argv, char **envp)
 {
 	struct subprocess_info *sub_info;
-	sub_info = kzalloc(sizeof(struct subprocess_info),  GFP_ATOMIC);
+	sub_info = kzalloc(sizeof(struct subprocess_info),  GFP_KERNEL);
 	if (!sub_info)
 		goto out;
 
#1 lore raw
Quoted 4 lines · KOSAKI Motohiro

Now, call_usermodehelper_setup() use GFP_ATOMIC.
but it is slighly odd.
because call_usermodehelper() is always called process context.

Are you sure? I found the following call chain:

  static irqreturn_t power_handler(int irq, void *dev_id)
  ->orderly_poweroff(true);
    ->call_usermodehelper_setup()
Quoted 31 lines

GFP_KERNEL is robust and better.

CC "Paul Menage" <[email protected]>
CC Li Zefan <[email protected]>
CC Jeremy Fitzhardinge <[email protected]>
CC Andi Kleen <[email protected]>
CC Rusty Russell <[email protected]>
---
 kernel/kmod.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: b/kernel/kmod.c
===================================================================

kernel/kmod.c +1 -1
@@ -360,7 +360,7 @@ struct subprocess_info *call_usermodehel
 						  char **argv, char **envp)
 {
 	struct subprocess_info *sub_info;
-	sub_info = kzalloc(sizeof(struct subprocess_info),  GFP_ATOMIC);
+	sub_info = kzalloc(sizeof(struct subprocess_info),  GFP_KERNEL);
 	if (!sub_info)
 		goto out;
 
#2 lore raw
Quoted 11 lines
Quoted 4 lines · KOSAKI Motohiro

Now, call_usermodehelper_setup() use GFP_ATOMIC.
but it is slighly odd.
because call_usermodehelper() is always called process context.

Are you sure? I found the following call chain:

  static irqreturn_t power_handler(int irq, void *dev_id)
  ->orderly_poweroff(true);
    ->call_usermodehelper_setup()

sorry, you are right.
I'll make patch again.

#3 lore raw
Quoted 6 lines · On Thu, 08 May 2008 16:31:29 +0900 KOSAKI Motohiro…
Quoted 6 lines
Quoted 4 lines · KOSAKI Motohiro

Now, call_usermodehelper_setup() use GFP_ATOMIC.
but it is slighly odd.
because call_usermodehelper() is always called process context.

Quoted 8 lines
Quoted 5 lines

Are you sure? I found the following call chain:

  static irqreturn_t power_handler(int irq, void *dev_id)
  ->orderly_poweroff(true);
    ->call_usermodehelper_setup()

sorry, you are right.
I'll make patch again.

How many times do we have to make this mistake :(

Only the caller knows what allocation mode the callee can use. call_usermodehelper_setup() should be extended to take a gfp_t argument.

#4 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Are you sure? I found the following call chain:

  static irqreturn_t power_handler(int irq, void *dev_id)
  ->orderly_poweroff(true);
    ->call_usermodehelper_setup()
Quoted 7 lines
Quoted 2 lines

sorry, you are right.
I'll make patch again.

How many times do we have to make this mistake :(

Only the caller knows what allocation mode the callee can use. call_usermodehelper_setup() should be extended to take a gfp_t argument.

Agreed.
I'm testing so patch.
I'll post tommorow, myabe.

#5 lore raw
In reply to Andrew Morton
Quoted 16 lines · Andrew Morton
Quoted 13 lines · On Thu, 08 May 2008 16:31:29 +0900 KOSAKI Motohiro…
Quoted 13 lines
Quoted 5 lines · KOSAKI Motohiro

Now, call_usermodehelper_setup() use GFP_ATOMIC.
but it is slighly odd.
because call_usermodehelper() is always called process context.

Are you sure? I found the following call chain:

  static irqreturn_t power_handler(int irq, void *dev_id)
  ->orderly_poweroff(true);
    ->call_usermodehelper_setup()
Quoted 8 lines
Quoted 3 lines

sorry, you are right.
I'll make patch again.

How many times do we have to make this mistake :(

Only the caller knows what allocation mode the callee can use. call_usermodehelper_setup() should be extended to take a gfp_t argument.

Yeah, but making the caller need to know about the internal implementation details of the callee (ie, whether it needs to allocate memory or not) leads to pretty warty interfaces. In this case, you could push the gfp_t up to the call_usermodehelper_setup() level, but pushing it any higher wouldn't make much sense.

Not that I have a better answer.

J

#6 lore raw

Hi

Thanks good comment!

Quoted 10 lines
Quoted 4 lines

How many times do we have to make this mistake :(

Only the caller knows what allocation mode the callee can use. call_usermodehelper_setup() should be extended to take a gfp_t argument.

Yeah, but making the caller need to know about the internal implementation details of the callee (ie, whether it needs to allocate memory or not) leads to pretty warty interfaces. In this case, you could push the gfp_t up to the call_usermodehelper_setup() level, but pushing it any higher wouldn't make much sense.

No problem :)
almost caller doesn't call call_usermodehelper_setup() directly.

thus, call_usermodehelper_setup() chage is hided in call_usermodehelper().

----------------chunk of my current testing patch-----------------------------

@@ -68,8 +69,9 @@ static inline int
call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait) {
struct subprocess_info *info;
+ gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;

- info = call_usermodehelper_setup(path, argv, envp);
+ info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
if (info == NULL)
return -ENOMEM;
return call_usermodehelper_exec(info, wait);

#7 lore raw
Quoted 9 lines · KOSAKI Motohiro

Hi

Thanks good comment!

Quoted 4 lines
Quoted 4 lines

How many times do we have to make this mistake :(

Only the caller knows what allocation mode the callee can use. call_usermodehelper_setup() should be extended to take a gfp_t argument.

Quoted 8 lines
Quoted 2 lines

Yeah, but making the caller need to know about the internal implementation details of the callee (ie, whether it needs to allocate memory or not) leads to pretty warty interfaces. In this case, you could push the gfp_t up to the call_usermodehelper_setup() level, but pushing it any higher wouldn't make much sense.

No problem :)
almost caller doesn't call call_usermodehelper_setup() directly.

thus, call_usermodehelper_setup() chage is hided in call_usermodehelper().

Yep, seems reasonable. Are there any UMH_NO_WAIT callers who could be using GFP_KERNEL?

Quoted 5 lines

----------------chunk of my current testing patch-----------------------------

Review static inline int · line 77

Quoted 10 lines
(quoted diff) +2 -1
@@ -68,8 +69,9 @@ static inline int
 call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
 {
 	struct subprocess_info *info;
+	gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
 
-	info = call_usermodehelper_setup(path, argv, envp);
+	info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
 	if (info == NULL)
 		return -ENOMEM;
 	return call_usermodehelper_exec(info, wait);

J

#8 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Yeah, but making the caller need to know about the internal implementation details of the callee (ie, whether it needs to allocate memory or not) leads to pretty warty interfaces. In this case, you could push the gfp_t up to the call_usermodehelper_setup() level, but pushing it any higher wouldn't make much sense.

Quoted 7 lines
Quoted 4 lines

No problem :)
almost caller doesn't call call_usermodehelper_setup() directly.

thus, call_usermodehelper_setup() chage is hided in call_usermodehelper().

Yep, seems reasonable. Are there any UMH_NO_WAIT callers who could be using GFP_KERNEL?

UMH_WAIT_EXEC and UMH_WAIT_PROC mean wait on finish of exec or process exit. I can't imagine situation that exec is waitable *and* allocate isn't waitable.

#9 lore raw
Quoted 3 lines · KOSAKI Motohiro

UMH_WAIT_EXEC and UMH_WAIT_PROC mean wait on finish of exec or process exit. I can't imagine situation that exec is waitable *and* allocate isn't waitable.

Yeah, that's why I was asking about UMH_NO_WAIT, where the caller may not want to wait, but the context would allow the allocation to block if necessary.

J

#10 lore raw
Quoted 7 lines
Quoted 2 lines · KOSAKI Motohiro

UMH_WAIT_EXEC and UMH_WAIT_PROC mean wait on finish of exec or process exit. I can't imagine situation that exec is waitable *and* allocate isn't waitable.

Yeah, that's why I was asking about UMH_NO_WAIT, where the caller may not want to wait, but the context would allow the allocation to block if necessary.

sorry, I misunderstood ;)

Yeah, you are right.
but it is no regression.
I agree with my plan have improve chance, but it is better than current.

#11 lore raw
Quoted 4 lines · KOSAKI Motohiro

Yeah, you are right.
but it is no regression.
I agree with my plan have improve chance, but it is better than current.

Sure. I was just curious and wondered if you'd already looked at it.

J