Skip to contentSkip to conversation

Avoid taking global tasklist_lock for single threaded process at getrusage()

RFC PATCH Nippun Goel 1 participant 1 message Dec 24, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 5 lines · Christoph Lameter

Please put the copy_to_user() invocation into sys_getrusage. That is the only function that needs to deal with user space issues includding the transfer of the contents of struct rusage. Define
a local rusage in sys_getrusage. Pass that address to the other functions and only copy on success to user space.

rusage_both is called at various places in exit.c, all of which are in turn called from sys_wait4 through do_wait. They pass a user space rusage struct pointer and expect the results to be copied there. Similarly, rusage_self and rusage_children are called from sysirix.c which also seemingly passes a user space pointer to them. Hence, the copy to user in all three functions.

n.

Quoted 42 lines

copy_to_user occurs repeatedly:

Quoted 7 lines · Ravikiran G Thirumalai
(quoted diff) +4 -1
 	if (unlikely(!p->signal))
-		return;
+		 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
 
+	cputime_to_timeval(utime, &r.ru_utime);
+	cputime_to_timeval(stime, &r.ru_stime);
+

Review

Quoted 10 lines
(quoted diff) +8 -0
+	return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
+}
+
+
+	return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
 }
 
+	if (unlikely(!p->signal))
+		 return copy_to_user(ru, &r, sizeof(r)) ? -EFAULT : 0;
+

But its only needed here:

Quoted 15 lines

asmlinkage long sys_getrusage(int who, struct rusage __user *ru) {

(quoted diff) +9 -3
-	if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
-		return -EINVAL;
-	return getrusage(current, who, ru);
+	switch (who) {
+		case RUSAGE_SELF:
+			return getrusage_self(ru);
+		case RUSAGE_CHILDREN:
+			return getrusage_children(ru);
+		default:
+			break;
+	}
+	return -EINVAL;
 }