]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] smp_call_function doco fix
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 22 May 2002 05:23:59 +0000 (22:23 -0700)
committerLinus Torvalds <torvalds@penguin.transmeta.com>
Wed, 22 May 2002 05:23:59 +0000 (22:23 -0700)
Trivial patch update against 2.5.17:
dipankar@in.ibm.com: smp_call_function change:
  My earlier patch fixed only i386. As per Dave Miller's suggestion,
  I have fixed smp_call_function for other smp architectures too.

  Description
  -----------
  Going by the documentation and use of _bh version of spin_lock(),
  smp_call_function() is allowed to be called from BH context,
  We can run into a deadlock with some locks if we do so.
  This because reader-writer locks can sometimes be used optimally
  by not disabling irqs while taking the reader side if only the
  reader side of the lock is taken from irq context.

        CPU #0                                CPU #1

        read_lock(&tasklist_lock)
                                         write_lock_irq(&tasklist_lock)
                                         [spins with interrupt disabled]
        [Interrupted by BH]
        smp_call_function() for BH
             handler
                                         [ doesn't take the IPI]

  So, cpu #1 doesn't take the IPI and cpu #0 spinwaits
  for the IPI handler to start, resulting in a deadlock.

  The last time I looked, I couldn't see smp_call_function() being
  called from BH context anywhere. So, there is no immediate problem.
  However it seems right to correct the documentation and also not
  disable BH while taking the call lock since it isn't necessary.
  This patch does exactly that.

  Thanks
  --
  Dipankar Sarma  <dipankar@in.ibm.com> http://lse.sourceforge.net
  Linux Technology Center, IBM Software Lab, Bangalore, India.

  smp_call_func-2.5.14-1.patch
  ----------------------------

arch/alpha/kernel/smp.c
arch/i386/kernel/smp.c
arch/ia64/kernel/smp.c
arch/mips/kernel/smp.c
arch/ppc/kernel/smp.c
arch/ppc64/kernel/smp.c
arch/s390/kernel/smp.c
arch/s390x/kernel/smp.c
arch/sparc64/kernel/smp.c
arch/x86_64/kernel/smp.c

index 45e5f58ad85e3b465ebd4d1e4831f68338f626b0..f20a8b08594a38e34dac66111162db6665e99bdb 100644 (file)
@@ -868,6 +868,8 @@ smp_send_stop(void)
  *
  * Does not return until remote CPUs are nearly ready to execute <func>
  * or are or have executed.
+ * You must not call this function with disabled interrupts or from a
+ * hardware interrupt handler or from a bottom half handler.
  */
 
 int
index e269f71131123210030048f11b1fa222860832b6..ebf89b926dbdcb0975de89191a7ba93a5377b25c 100644 (file)
@@ -544,7 +544,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  *
  * You must not call this function with disabled interrupts or from a
- * hardware interrupt handler, you may call it from a bottom half handler.
+ * hardware interrupt handler or from a bottom half handler.
  */
 {
        struct call_data_struct data;
@@ -560,7 +560,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
        call_data = &data;
        wmb();
        /* Send a message to all other CPUs and wait for them to respond */
@@ -573,7 +573,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                while (atomic_read(&data.finished) != cpus)
                        barrier();
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
 
        return 0;
 }
index f2176bb9a11fdf8524a6036e00a946ec333eb623..4c1eaa259cb2961caa6952b81163d3b02b03218a 100644 (file)
@@ -283,8 +283,8 @@ smp_call_function_single (int cpuid, void (*func) (void *info), void *info, int
  * Does not return until remote CPUs are nearly ready to execute <func> or are or have
  * executed.
  *
- * You must not call this function with disabled interrupts or from a hardware interrupt
- * handler, you may call it from a bottom half handler.
+ * You must not call this function with disabled interrupts or from a
+ * hardware interrupt handler or from a bottom half handler.
  */
 int
 smp_call_function (void (*func) (void *info), void *info, int nonatomic, int wait)
@@ -302,7 +302,7 @@ smp_call_function (void (*func) (void *info), void *info, int nonatomic, int wai
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
 
        call_data = &data;
        mb();   /* ensure store to call_data precedes setting of IPI_CALL_FUNC */
@@ -317,7 +317,7 @@ smp_call_function (void (*func) (void *info), void *info, int nonatomic, int wai
                        barrier();
        call_data = NULL;
 
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
        return 0;
 }
 
index 6157e23ecc803e228b5abeec3d20adb297a1c59c..96276f71ebb21dc37d78e155ac4a2487a4091e53 100644 (file)
@@ -191,6 +191,8 @@ void FASTCALL(smp_send_reschedule(int cpu))
  * The caller of this wants the passed function to run on every cpu.  If wait
  * is set, wait until all cpus have finished the function before returning.
  * The lock is here to protect the call structure.
+ * You must not call this function with disabled interrupts or from a
+ * hardware interrupt handler or from a bottom half handler.
  */
 int smp_call_function (void (*func) (void *info), void *info, int retry, 
                                                                int wait)
@@ -202,7 +204,7 @@ int smp_call_function (void (*func) (void *info), void *info, int retry,
                return 0;
        }
 
-       spin_lock_bh(&smp_fn_call.lock);
+       spin_lock(&smp_fn_call.lock);
 
        atomic_set(&smp_fn_call.finished, 0);
        smp_fn_call.fn = func;
@@ -219,7 +221,7 @@ int smp_call_function (void (*func) (void *info), void *info, int retry,
                while(atomic_read(&smp_fn_call.finished) != cpus) {}
        }
 
-       spin_unlock_bh(&smp_fn_call.lock);
+       spin_unlock(&smp_fn_call.lock);
        return 0;
 }
 
index 738c81b583ea5d64b23483c9e80069fae9c7d506..b3a9580ed31fb7454e5aaae053a78ff0fd5c12e2 100644 (file)
@@ -209,7 +209,7 @@ int smp_call_function(void (*func) (void *info), void *info, int nonatomic,
  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  *
  * You must not call this function with disabled interrupts or from a
- * hardware interrupt handler, you may call it from a bottom half handler.
+ * hardware interrupt handler or from a bottom half handler.
  */
 {
        if (smp_num_cpus <= 1)
@@ -237,7 +237,7 @@ static int __smp_call_function(void (*func) (void *info), void *info,
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
        call_data = &data;
        /* Send a message to all other CPUs and wait for them to respond */
        smp_message_pass(target, PPC_MSG_CALL_FUNCTION, 0, 0);
@@ -269,7 +269,7 @@ static int __smp_call_function(void (*func) (void *info), void *info,
        ret = 0;
 
  out:
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
        return ret;
 }
 
index 951691af4054bf9f4003610f96f3aea739c0c968..3c7cadd3ea01d5f8943ab476bbaeed7872fbfc6e 100644 (file)
@@ -466,7 +466,7 @@ static struct call_data_struct {
  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  *
  * You must not call this function with disabled interrupts or from a
- * hardware interrupt handler, you may call it from a bottom half handler.
+ * hardware interrupt handler or from a bottom half handler.
  */
 int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
                        int wait)
@@ -486,7 +486,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
        call_data = &data;
        /* Send a message to all other CPUs and wait for them to respond */
        smp_message_pass(MSG_ALL_BUT_SELF, PPC_MSG_CALL_FUNCTION, 0, 0);
@@ -530,7 +530,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
 
  out:
        HMT_medium();
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
        return ret;
 }
 
index 5c269b806b8f6ffdaf333aad16cfc916428dba7b..64d5adc6978849d6a065b301ddf227bc1b49a989 100644 (file)
@@ -146,7 +146,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  *
  * You must not call this function with disabled interrupts or from a
- * hardware interrupt handler, you may call it from a bottom half handler.
+ * hardware interrupt handler or from a bottom half handler.
  */
 {
        struct call_data_struct data;
@@ -162,7 +162,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
        call_data = &data;
        /* Send a message to all other CPUs and wait for them to respond */
         smp_ext_bitcall_others(ec_call_function);
@@ -174,7 +174,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                while (atomic_read(&data.finished) != cpus)
                        barrier();
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
 
        return 0;
 }
index 6c9c37f24ab74c46fea1defcb5780b919fc2dda3..e7f2e02604b47eb37dffb78d82fb36b17fe24c79 100644 (file)
@@ -146,7 +146,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  *
  * You must not call this function with disabled interrupts or from a
- * hardware interrupt handler, you may call it from a bottom half handler.
+ * hardware interrupt handler or from a bottom half handler.
  */
 {
        struct call_data_struct data;
@@ -162,7 +162,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
        call_data = &data;
        /* Send a message to all other CPUs and wait for them to respond */
         smp_ext_bitcall_others(ec_call_function);
@@ -174,7 +174,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                while (atomic_read(&data.finished) != cpus)
                        barrier();
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
 
        return 0;
 }
index 7024df48fa3658e76f69a01474ba80f748aa3744..9f4ea11d8b935b699e4f3bbecd1353635be898bb 100644 (file)
@@ -551,6 +551,10 @@ static struct call_data_struct *call_data;
 
 extern unsigned long xcall_call_function;
 
+/*
+ * You must not call this function with disabled interrupts or from a
+ * hardware interrupt handler or from a bottom half handler.
+ */
 int smp_call_function(void (*func)(void *info), void *info,
                      int nonatomic, int wait)
 {
@@ -566,7 +570,7 @@ int smp_call_function(void (*func)(void *info), void *info,
        atomic_set(&data.finished, 0);
        data.wait = wait;
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
 
        call_data = &data;
 
@@ -584,12 +588,12 @@ int smp_call_function(void (*func)(void *info), void *info,
                udelay(1);
        }
 
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
 
        return 0;
 
 out_timeout:
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
        printk("XCALL: Remote cpus not responding, ncpus=%d finished=%d\n",
               smp_num_cpus - 1, atomic_read(&data.finished));
        return 0;
index 677a0b3d0aa99587970603671ba1b7648a943a46..8ee1772d261c473f0c34cfeabbd827928164cb61 100644 (file)
@@ -380,7 +380,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
  * remote CPUs are nearly ready to execute <<func>> or are or have executed.
  *
  * You must not call this function with disabled interrupts or from a
- * hardware interrupt handler, you may call it from a bottom half handler.
+ * hardware interrupt handler or from a bottom half handler.
  */
 {
        struct call_data_struct data;
@@ -396,7 +396,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                atomic_set(&data.finished, 0);
 
-       spin_lock_bh(&call_lock);
+       spin_lock(&call_lock);
        call_data = &data;
        wmb();
        /* Send a message to all other CPUs and wait for them to respond */
@@ -409,7 +409,7 @@ int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
        if (wait)
                while (atomic_read(&data.finished) != cpus)
                        barrier();
-       spin_unlock_bh(&call_lock);
+       spin_unlock(&call_lock);
 
        return 0;
 }