public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Dowad <alexinbeijing@gmail.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>, Rik van Riel <riel@redhat.com>,
	Vladimir Davydov <vdavydov@parallels.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Kees Cook <keescook@chromium.org>,
	Aaron Tomlin <atomlin@redhat.com>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] do_fork(): Rename 'stack_size' argument to reflect actual use
Date: Fri, 06 Mar 2015 08:07:23 +0200	[thread overview]
Message-ID: <54F9441B.20408@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1503051228060.23808@chino.kir.corp.google.com>


On 05/03/15 22:29, David Rientjes wrote:
> On Thu, 5 Mar 2015, Alex Dowad wrote:
>
>>>> diff --git a/kernel/fork.c b/kernel/fork.c
>>>> index cf65139..b38a2ae 100644
>>>> --- a/kernel/fork.c
>>>> +++ b/kernel/fork.c
>>>> @@ -1186,10 +1186,12 @@ init_task_pid(struct task_struct *task, enum
>>>> pid_type type, struct pid *pid)
>>>>     * It copies the registers, and all the appropriate
>>>>     * parts of the process environment (as per the clone
>>>>     * flags). The actual kick-off is left to the caller.
>>>> + *
>>>> + * When copying a kernel thread, 'stack_start' is the function to run.
>>>>     */
>>>>    static struct task_struct *copy_process(unsigned long clone_flags,
>>>>    					unsigned long stack_start,
>>>> -					unsigned long stack_size,
>>>> +					unsigned long kthread_arg,
>>>>    					int __user *child_tidptr,
>>>>    					struct pid *pid,
>>>>    					int trace)
>>>> @@ -1401,7 +1403,7 @@ static struct task_struct *copy_process(unsigned
>>>> long clone_flags,
>>>>    	retval = copy_io(clone_flags, p);
>>>>    	if (retval)
>>>>    		goto bad_fork_cleanup_namespaces;
>>>> -	retval = copy_thread(clone_flags, stack_start, stack_size, p);
>>>> +	retval = copy_thread(clone_flags, stack_start, kthread_arg, p);
>>>>    	if (retval)
>>>>    		goto bad_fork_cleanup_io;
>>>>    @@ -1629,8 +1631,8 @@ struct task_struct *fork_idle(int cpu)
>>>>     * it and waits for it to finish using the VM if required.
>>>>     */
>>>>    long do_fork(unsigned long clone_flags,
>>>> -	      unsigned long stack_start,
>>>> -	      unsigned long stack_size,
>>>> +	      unsigned long stack_start, /* or function for kthread to run */
>>>> +	      unsigned long kthread_arg,
>>>>    	      int __user *parent_tidptr,
>>>>    	      int __user *child_tidptr)
>>>>    {
>>> Looks fine, but I'm not sure about commenting functional formals.  Since
>>> copy_process() and do_fork() can have formals with different meanings,
>>> then why not just rename them "arg1" and "arg2" respectively and then
>>> define in the comment above the function what the possible combinations
>>> are?
>> The second argument is *only* ever used for one thing: an argument passed to a
>> kernel thread. That's why I would like to rename it to "kthread_arg". The
>> previous argument (currently named "stack_start") is indeed used for 2
>> different things: a new stack pointer for a user thread, or a function to be
>> executed by a kernel thread. Rather than "arg1", what would you think of
>> something like "sp_or_fn", or "usp_or_fn"?
>>
> I would recommend exactly "arg" since it can be used for multiple purposes
> and if the formal could ever be used for a third purpose we don't want to
> go through another re-naming patch to change it from sp_or_fn or
> usp_or_fn.
>
> If that's done, then the comment above the function could define what arg
> can represent.
Do others concur with this idea? Personally, I feel the code will be 
more readable/maintainable if the naming of args/variables/etc reflects 
what they are actually used for.

(Case in point: on IA64, copy_thread() adds the kernel thread arg to the 
user stack pointer. The kernel thread arg is always 0 when forking a 
user process, so this "works", but it's certainly not what the author 
intended. Good names make it harder to write buggy code!)

For readability, using the same arg for 2 different purposes is a bad 
practice (though it might be good for keeping the object code small). I 
hate to think that "arg" might be co-opted for another purpose again.

      reply	other threads:[~2015-03-06  6:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-04 12:40 [PATCH] do_fork(): Rename 'stack_size' argument to reflect actual use Alex Dowad
2015-03-04 20:45 ` Kees Cook
2015-03-04 23:07 ` David Rientjes
2015-03-05 11:18   ` Alex Dowad
2015-03-05 20:29     ` David Rientjes
2015-03-06  6:07       ` Alex Dowad [this message]

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=54F9441B.20408@gmail.com \
    --to=alexinbeijing@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=atomlin@redhat.com \
    --cc=keescook@chromium.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=rientjes@google.com \
    --cc=tglx@linutronix.de \
    --cc=vdavydov@parallels.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