mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Erik A. Hendriks" <hendriks@lanl.gov>
To: marcelo@conectiva.com.br, torvalds@transmeta.com,
	linux-kernel@vger.kernel.org
Subject: Linux 2.4.17,2.5.3 process ID allocator isn't quite SMP safe.
Date: Tue, 5 Feb 2002 13:20:46 -0700	[thread overview]
Message-ID: <20020205132046.D5217@lanl.gov> (raw)

The get_pid function in kernel/fork.c returns the value of last_pid
after releasing the lock protecting it.  On SMPs, I have observed two
processes occasionally being assigned the same process ID as a result.

I'm pretty sure the sequence of events looks like this: The first
process releases the lock after coming up with a suitable pid (stored
in last_pid).  Then after it releases the lock but before it does the
return (IRQ or something happens here to create delay?) another
processor comes a long and updates it.  Then get_pid returns the value
of last_pid which is now the pid chosen by the other process.

Attached below is a little patch to fix it.

- Erik

--- linux-2.4.17/kernel/fork.c.orig	Mon Feb  4 14:53:31 2002
+++ linux-2.4.17/kernel/fork.c	Mon Feb  4 14:53:53 2002
@@ -85,6 +85,7 @@
 {
 	static int next_safe = PID_MAX;
 	struct task_struct *p;
+	int pid;
 
 	if (flags & CLONE_PID)
 		return current->pid;
@@ -120,9 +121,10 @@
 		}
 		read_unlock(&tasklist_lock);
 	}
+	pid = last_pid;
 	spin_unlock(&lastpid_lock);
 
-	return last_pid;
+	return pid;
 }
 
 static inline int dup_mmap(struct mm_struct * mm)



                 reply	other threads:[~2002-02-05 20:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20020205132046.D5217@lanl.gov \
    --to=hendriks@lanl.gov \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    --cc=torvalds@transmeta.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

all inboxes | Powered by JetHome®