Commit 57078435 authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] smp_call_function doco fix

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
  ----------------------------
parent 87c25437
......@@ -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
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment