2008-03-04 01:12:53 +08:00
|
|
|
#include <linux/cpumask.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/mc146818rtc.h>
|
|
|
|
#include <linux/cache.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/mtrr.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
#include <asm/mmu_context.h>
|
2009-02-17 20:58:15 +08:00
|
|
|
#include <asm/apic.h>
|
2008-03-04 01:12:53 +08:00
|
|
|
#include <asm/proto.h>
|
2009-01-30 11:31:49 +08:00
|
|
|
#include <asm/ipi.h>
|
2008-03-04 01:12:53 +08:00
|
|
|
|
2009-01-31 09:29:27 +08:00
|
|
|
void default_send_IPI_mask_sequence_phys(const struct cpumask *mask, int vector)
|
|
|
|
{
|
|
|
|
unsigned long query_cpu;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hack. The clustered APIC addressing mode doesn't allow us to send
|
|
|
|
* to an arbitrary mask, so I do a unicast to each CPU instead.
|
|
|
|
* - mbligh
|
|
|
|
*/
|
|
|
|
local_irq_save(flags);
|
|
|
|
for_each_cpu(query_cpu, mask) {
|
|
|
|
__default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
|
|
|
|
query_cpu), vector, APIC_DEST_PHYSICAL);
|
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_send_IPI_mask_allbutself_phys(const struct cpumask *mask,
|
|
|
|
int vector)
|
|
|
|
{
|
|
|
|
unsigned int this_cpu = smp_processor_id();
|
|
|
|
unsigned int query_cpu;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* See Hack comment above */
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
for_each_cpu(query_cpu, mask) {
|
|
|
|
if (query_cpu == this_cpu)
|
|
|
|
continue;
|
|
|
|
__default_send_IPI_dest_field(per_cpu(x86_cpu_to_apicid,
|
|
|
|
query_cpu), vector, APIC_DEST_PHYSICAL);
|
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2011-01-23 21:37:29 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
|
2009-01-31 09:29:27 +08:00
|
|
|
void default_send_IPI_mask_sequence_logical(const struct cpumask *mask,
|
|
|
|
int vector)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int query_cpu;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hack. The clustered APIC addressing mode doesn't allow us to send
|
|
|
|
* to an arbitrary mask, so I do a unicasts to each CPU instead. This
|
|
|
|
* should be modified to do 1 message per cluster ID - mbligh
|
|
|
|
*/
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
for_each_cpu(query_cpu, mask)
|
|
|
|
__default_send_IPI_dest_field(
|
2011-01-23 21:37:31 +08:00
|
|
|
early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
|
|
|
|
vector, apic->dest_logical);
|
2009-01-31 09:29:27 +08:00
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_send_IPI_mask_allbutself_logical(const struct cpumask *mask,
|
|
|
|
int vector)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int query_cpu;
|
|
|
|
unsigned int this_cpu = smp_processor_id();
|
|
|
|
|
|
|
|
/* See Hack comment above */
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
for_each_cpu(query_cpu, mask) {
|
|
|
|
if (query_cpu == this_cpu)
|
|
|
|
continue;
|
|
|
|
__default_send_IPI_dest_field(
|
2011-01-23 21:37:31 +08:00
|
|
|
early_per_cpu(x86_cpu_to_logical_apicid, query_cpu),
|
|
|
|
vector, apic->dest_logical);
|
2009-01-31 09:29:27 +08:00
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is only used on smaller machines.
|
|
|
|
*/
|
|
|
|
void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector)
|
|
|
|
{
|
|
|
|
unsigned long mask = cpumask_bits(cpumask)[0];
|
|
|
|
unsigned long flags;
|
|
|
|
|
x86: don't send an IPI to the empty set of CPU's
The default_send_IPI_mask_logical() function uses the "flat" APIC mode
to send an IPI to a set of CPU's at once, but if that set happens to be
empty, some older local APIC's will apparently be rather unhappy. So
just warn if a caller gives us an empty mask, and ignore it.
This fixes a regression in 2.6.30.x, due to commit 4595f9620 ("x86:
change flush_tlb_others to take a const struct cpumask"), documented
here:
http://bugzilla.kernel.org/show_bug.cgi?id=13933
which causes a silent lock-up. It only seems to happen on PPro, P2, P3
and Athlon XP cores. Most developers sadly (or not so sadly, if you're
a developer..) have more modern CPU's. Also, on x86-64 we don't use the
flat APIC mode, so it would never trigger there even if the APIC didn't
like sending an empty IPI mask.
Reported-by: Pavel Vilim <wylda@volny.cz>
Reported-and-tested-by: Thomas Björnell <thomas.bjornell@gmail.com>
Reported-and-tested-by: Martin Rogge <marogge@onlinehome.de>
Cc: Mike Travis <travis@sgi.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-08-22 00:23:57 +08:00
|
|
|
if (WARN_ONCE(!mask, "empty IPI mask"))
|
|
|
|
return;
|
|
|
|
|
2009-01-31 09:29:27 +08:00
|
|
|
local_irq_save(flags);
|
|
|
|
WARN_ON(mask & ~cpumask_bits(cpu_online_mask)[0]);
|
|
|
|
__default_send_IPI_dest_field(mask, vector, apic->dest_logical);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_send_IPI_allbutself(int vector)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* if there are no other CPUs in the system then we get an APIC send
|
|
|
|
* error if we try to broadcast, thus avoid sending IPIs in this case.
|
|
|
|
*/
|
|
|
|
if (!(num_online_cpus() > 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
__default_local_send_IPI_allbutself(vector);
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_send_IPI_all(int vector)
|
|
|
|
{
|
|
|
|
__default_local_send_IPI_all(vector);
|
|
|
|
}
|
|
|
|
|
2009-01-28 22:42:24 +08:00
|
|
|
void default_send_IPI_self(int vector)
|
2008-03-04 01:12:53 +08:00
|
|
|
{
|
2009-01-30 11:31:49 +08:00
|
|
|
__default_send_IPI_shortcut(APIC_DEST_SELF, vector, apic->dest_logical);
|
2008-03-04 01:12:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* must come after the send_IPI functions above for inlining */
|
|
|
|
static int convert_apicid_to_cpu(int apic_id)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_possible_cpu(i) {
|
|
|
|
if (per_cpu(x86_cpu_to_apicid, i) == apic_id)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int safe_smp_processor_id(void)
|
|
|
|
{
|
|
|
|
int apicid, cpuid;
|
|
|
|
|
2009-07-06 00:01:54 +08:00
|
|
|
if (!cpu_has_apic)
|
2008-03-04 01:12:53 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
apicid = hard_smp_processor_id();
|
|
|
|
if (apicid == BAD_APICID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cpuid = convert_apicid_to_cpu(apicid);
|
|
|
|
|
|
|
|
return cpuid >= 0 ? cpuid : 0;
|
|
|
|
}
|
|
|
|
#endif
|