public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: torvalds@transmeta.com
Cc: akpm@digeo.com, linux-kernel@vger.kernel.org
Subject: [PATCH] preempt_count overflow with brlocks
Date: 07 Oct 2002 21:53:15 -0400	[thread overview]
Message-ID: <1034041998.30670.280.camel@phantasy> (raw)

Linus,

Now that brlocks loop over NR_CPUS, on SMP every brlock/brunlock results
in the acquire/release of 32 locks.  This incs/decs the preempt_count by
32.

Since we only have 7 bits now for actually storing the lock depth, we
cannot nest but 3 locks deep.  I doubt we ever acquire three brlocks
concurrently, but it is still a concern.

Attached patch disables/enables preemption explicitly once and only once
for each lock/unlock.  This is also an optimization as it removes 31
incs, decs, and conditionals. :)

Problem reported by Andrew Morton.

Patch is against 2.5.41, please apply.

	Robert Love

diff -urN linux-2.5.41/lib/brlock.c linux/lib/brlock.c
--- linux-2.5.41/lib/brlock.c	2002-10-07 14:24:45.000000000 -0400
+++ linux/lib/brlock.c	2002-10-07 21:38:02.000000000 -0400
@@ -24,8 +24,9 @@
 {
 	int i;
 
+	preempt_disable();
 	for (i = 0; i < NR_CPUS; i++)
-		write_lock(&__brlock_array[i][idx]);
+		_raw_write_lock(&__brlock_array[i][idx]);
 }
 
 void __br_write_unlock (enum brlock_indices idx)
@@ -33,7 +34,8 @@
 	int i;
 
 	for (i = 0; i < NR_CPUS; i++)
-		write_unlock(&__brlock_array[i][idx]);
+		_raw_write_unlock(&__brlock_array[i][idx]);
+	preempt_enable();
 }
 
 #else /* ! __BRLOCK_USE_ATOMICS */
@@ -48,11 +50,12 @@
 {
 	int i;
 
+	preempt_disable();
 again:
-	spin_lock(&__br_write_locks[idx].lock);
+	_raw_spin_lock(&__br_write_locks[idx].lock);
 	for (i = 0; i < NR_CPUS; i++)
 		if (__brlock_array[i][idx] != 0) {
-			spin_unlock(&__br_write_locks[idx].lock);
+			_raw_spin_unlock(&__br_write_locks[idx].lock);
 			barrier();
 			cpu_relax();
 			goto again;


                 reply	other threads:[~2002-10-08  1:47 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=1034041998.30670.280.camel@phantasy \
    --to=rml@tech9.net \
    --cc=akpm@digeo.com \
    --cc=linux-kernel@vger.kernel.org \
    --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