lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 4 Apr 2007 12:39:27 +0400
From:	Oleg Nesterov <oleg@...sign.ru>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Ulrich Drepper <drepper@...hat.com>,
	Linux Kernel <linux-kernel@...r.kernel.org>,
	Gautham R Shenoy <ego@...ibm.com>,
	Dipankar Sarma <dipankar@...ibm.com>,
	Paul Jackson <pj@....com>, Ingo Molnar <mingo@...e.hu>
Subject: Re: getting processor numbers

On 04/03, Andrew Morton wrote:
>
> On Tue, 03 Apr 2007 16:00:50 -0700
> Ulrich Drepper <drepper@...hat.com> wrote:
> 
> > If there is possibility to treat this case special and make it faster,
> > please do so.  It would be best to allow pid==0 as a special case so
> > that callers don't have to find out the TID (which they shouldn't have
> > to know).
> > 
> 
> OK.
> 
> Does anyone see a reason why we cannot do this?
> 
> --- a/kernel/sched.c~sched_getaffinity-speedup
> +++ a/kernel/sched.c
> @@ -4381,8 +4381,12 @@ long sched_getaffinity(pid_t pid, cpumas
>  	struct task_struct *p;
>  	int retval;
>  
> -	lock_cpu_hotplug();
> -	read_lock(&tasklist_lock);
> +	if (pid) {
> +		lock_cpu_hotplug();
> +		read_lock(&tasklist_lock);
> +	} else {
> +		preempt_disable();	/* Prevent CPU hotplugging */
> +	}

But we don't need tasklist_lock at all, we can use rcu_read_lock/unlock.

Q: don't we need task_rq_lock() to read ->cpus_allowed "atomically" ?

UNTESTED.

--- OLD/kernel/sched.c~	2007-04-03 13:05:02.000000000 +0400
+++ OLD/kernel/sched.c	2007-04-04 12:29:04.000000000 +0400
@@ -4433,22 +4433,17 @@ long sched_setaffinity(pid_t pid, cpumas
 	int retval;
 
 	mutex_lock(&sched_hotcpu_mutex);
-	read_lock(&tasklist_lock);
+	rcu_read_lock();
 
 	p = find_process_by_pid(pid);
 	if (!p) {
-		read_unlock(&tasklist_lock);
+		rcu_read_unlock();
 		mutex_unlock(&sched_hotcpu_mutex);
 		return -ESRCH;
 	}
 
-	/*
-	 * It is not safe to call set_cpus_allowed with the
-	 * tasklist_lock held.  We will bump the task_struct's
-	 * usage count and then drop tasklist_lock.
-	 */
 	get_task_struct(p);
-	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
 
 	retval = -EPERM;
 	if ((current->euid != p->euid) && (current->euid != p->uid) &&
@@ -4523,7 +4518,7 @@ long sched_getaffinity(pid_t pid, cpumas
 	int retval;
 
 	mutex_lock(&sched_hotcpu_mutex);
-	read_lock(&tasklist_lock);
+	rcu_read_lock();
 
 	retval = -ESRCH;
 	p = find_process_by_pid(pid);
@@ -4537,7 +4532,7 @@ long sched_getaffinity(pid_t pid, cpumas
 	cpus_and(*mask, p->cpus_allowed, cpu_online_map);
 
 out_unlock:
-	read_unlock(&tasklist_lock);
+	rcu_read_unlock();
 	mutex_unlock(&sched_hotcpu_mutex);
 	if (retval)
 		return retval;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ