Skip to contentSkip to conversation

Request for documentation of PID handling functions

DISCUSSION David Howells 3 participants 3 messages Jul 28, 2008 – Jul 30, 2008

lore
Share & tools
lore
#0 lore raw

Hi Pavel,

Can you please provide documentation for the PID handling functions you supplied in commit:

	7af5729474b5b8ad385adadab78d6e723e7655a3

In particular I'd like to know what locks are required when. I'm trying to determine if in this piece of code:

		read_lock(&tasklist_lock);
		ret = 0;
		if (pid != task_pid_vnr(current))
			ret = -EPERM;
		read_unlock(&tasklist_lock);

the lock of tasklist_lock is necessary.

David

#1 lore raw
Quoted 10 lines · David Howells

Hi Pavel,

Can you please provide documentation for the PID handling functions you supplied in commit:

	7af5729474b5b8ad385adadab78d6e723e7655a3

In particular I'd like to know what locks are required when. I'm trying to determine if in this piece of code:

Quoted 7 lines
		read_lock(&tasklist_lock);
		ret = 0;
		if (pid != task_pid_vnr(current))
			ret = -EPERM;
		read_unlock(&tasklist_lock);

the lock of tasklist_lock is necessary.

The RCU protection is enough to get pids from tasks. However, the pids are detached under the tasklist lock write-locked, so provided you're *already* sitting under it the RCU is excessive.

However, Oleg pointed me out some time ago, that in some cases RCU-only protection was not enough in some cases, so I put him in Cc.

Quoted 2 lines

David

#2 lore raw
Quoted 18 lines · Pavel Emelyanov
Quoted 16 lines · David Howells

Hi Pavel,

Can you please provide documentation for the PID handling functions you supplied in commit:

	7af5729474b5b8ad385adadab78d6e723e7655a3

In particular I'd like to know what locks are required when. I'm trying to determine if in this piece of code:

		read_lock(&tasklist_lock);
		ret = 0;
		if (pid != task_pid_vnr(current))
			ret = -EPERM;
		read_unlock(&tasklist_lock);
Quoted 5 lines
Quoted 1 line

the lock of tasklist_lock is necessary.

The RCU protection is enough to get pids from tasks. However, the pids are detached under the tasklist lock write-locked, so provided you're *already* sitting under it the RCU is excessive.

Yes, tasklist OR rcu is enough.

But, since the task == current, the code above doesn't need any locks at all.

Unless this code runs after exit_notify() of course, in that case we need rcu/tasklist and task_pid_vnr(current) can return 0.

Oleg.