Reduce stack usage in time.c
PATCH 1/1 Reduce stack usage in time.c
Attempt to reduce stack usage in time.c (linux-2.6.12-rc1-mm3). Stack usage was noted using checkstack.pl. Specifically:
Before patch
------------sys_adjtimex - 128
After patch
-----------sys_adjtimex - none (register usage only)
kernel/time.c +16 -6
@@ -413,17 +413,27 @@asmlinkage long sys_adjtimex (struct timex __user *txc_p) { -struct timex txc;/* Local copy of parameter */ -int ret; +struct timex *txc;/* Local copy of parameter */ +int retval; + + txc =kmalloc (sizeof (struct timex ),GFP_KERNEL ); +if (!txc) +return -ENOMEM ;/* Copy the user data space into the kernel copy * structure. But bear in mind that the structures * may change */ -if (copy_from_user (&txc, txc_p,sizeof (struct timex ))) -return -EFAULT ; - ret =do_adjtimex (&txc); -return copy_to_user (txc_p, &txc,sizeof (struct timex )) ? -EFAULT : ret; +if (copy_from_user (txc, txc_p,sizeof (struct timex ))) { + retval = -EFAULT ; + goto free_txc; + } + retval =do_adjtimex (txc); +if (copy_to_user (txc_p, txc,sizeof (struct timex ))) + retval = -EFAULT ; +free_txc: +kfree (txc); +return retval; }inline struct timespec current_kernel_time (void )
Quoted 34 lines · Yum Rayan
Attempt to reduce stack usage in
time.c(linux-2.6.12-rc1-mm3). Stack usage was noted using checkstack.pl. Specifically:Before patch
------------sys_adjtimex- 128After patch
-----------sys_adjtimex- none (register usage only)Signed-off-by Yum Rayan <[email protected]>kernel/time.c +6
-4@@ -413,17 +413,27 @@asmlinkage long sys_adjtimex (struct timex __user *txc_p) { -struct timex txc;/* Local copy of parameter */ -int ret; +struct timex *txc;/* Local copy of parameter */ +int retval; + + txc =kmalloc (sizeof (struct timex ),GFP_KERNEL ); +if (!txc) +return -ENOMEM ;/* Copy the user data space into the kernel copy * structure. But bear in mind that the structures * may change */ -if (copy_from_user (&txc, txc_p,sizeof (struct timex ))) -return -EFAULT ;
kernel/time.c line 434
Quoted 10 lines
kernel/time.c +8
-2- ret =do_adjtimex (&txc); -return copy_to_user (txc_p, &txc,sizeof (struct timex )) ? -EFAULT : ret; +if (copy_from_user (txc, txc_p,sizeof (struct timex ))) { + retval = -EFAULT ; + goto free_txc; + } + retval =do_adjtimex (txc); +if (copy_to_user (txc_p, txc,sizeof (struct timex ))) + retval = -EFAULT ; +free_txc:
It seems quite unhealthy to add a kmalloc(,GFP_KERNEL) allocation into a time-sensitive function.
Jeff
Quoted 29 lines · Jeff Garzik
Quoted 28 lines · Yum Rayan
Attempt to reduce stack usage in
time.c(linux-2.6.12-rc1-mm3). Stack usage was noted using checkstack.pl. Specifically:Before patch
------------sys_adjtimex- 128After patch
-----------sys_adjtimex- none (register usage only)Signed-off-by Yum Rayan <[email protected]>kernel/time.c +6
-2@@ -413,17 +413,27 @@asmlinkage long sys_adjtimex (struct timex __user *txc_p) { -struct timex txc;/* Local copy of parameter */ -int ret; +struct timex *txc;/* Local copy of parameter */ +int retval; + + txc =kmalloc (sizeof (struct timex ),GFP_KERNEL ); +if (!txc) +return -ENOMEM ;
Quoted 16 lines
Quoted 6 lines
kernel/time.c +0
-2/* Copy the user data space into the kernel copy * structure. But bear in mind that the structures * may change */ -if (copy_from_user (&txc, txc_p,sizeof (struct timex ))) -return -EFAULT ;kernel/time.c line 434
Quoted 10 lines
kernel/time.c +8
-2- ret =do_adjtimex (&txc); -return copy_to_user (txc_p, &txc,sizeof (struct timex )) ? -EFAULT : ret; +if (copy_from_user (txc, txc_p,sizeof (struct timex ))) { + retval = -EFAULT ; + goto free_txc; + } + retval =do_adjtimex (txc); +if (copy_to_user (txc_p, txc,sizeof (struct timex ))) + retval = -EFAULT ; +free_txc:
Is this a syscall?
Is it ever called from some deeply nested kernel function? --
vda
Quoted 3 lines · Denis Vlasenko
Is this a syscall?
Is it ever called from some deeply nested kernel function?
Never showed up in any of my callchain-tests. I'd leave it as is.
Jörn
Signature · 4 lines
When I am working on a problem I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong. -- R. Buckminster Fuller