Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7abc0753 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Ingo Molnar
Browse files

x86: apic: Do not use stacked physid_mask_t



We should not use physid_mask_t as a stack based
variable in apic code. This type depends on MAX_APICS
parameter which may be huge enough.

Especially it became a problem with apic NOOP driver which
is portable between 32 bit and 64 bit environment
(where we have really huge MAX_APICS).

So apic driver should operate with pointers and a caller
in turn should aware of allocation physid_mask_t variable.

As a side (but positive) effect -- we may use already
implemented physid_set_mask_of_physid function eliminating
default_apicid_to_cpu_present completely.

Note that physids_coerce and physids_promote turned into static
inline from macro (since macro hides the fact that parameter is
being interpreted as unsigned long, make it explicit).

Signed-off-by: default avatarCyrill Gorcunov <gorcunov@openvz.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Maciej W. Rozycki <macro@linux-mips.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
LKML-Reference: <20091109220659.GA5568@lenovo>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent f4a70c55
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -297,20 +297,20 @@ struct apic {
	int disable_esr;

	int dest_logical;
	unsigned long (*check_apicid_used)(physid_mask_t bitmap, int apicid);
	unsigned long (*check_apicid_used)(physid_mask_t *map, int apicid);
	unsigned long (*check_apicid_present)(int apicid);

	void (*vector_allocation_domain)(int cpu, struct cpumask *retmask);
	void (*init_apic_ldr)(void);

	physid_mask_t (*ioapic_phys_id_map)(physid_mask_t map);
	void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap);

	void (*setup_apic_routing)(void);
	int (*multi_timer_check)(int apic, int irq);
	int (*apicid_to_node)(int logical_apicid);
	int (*cpu_to_logical_apicid)(int cpu);
	int (*cpu_present_to_apicid)(int mps_cpu);
	physid_mask_t (*apicid_to_cpu_present)(int phys_apicid);
	void (*apicid_to_cpu_present)(int phys_apicid, physid_mask_t *retmap);
	void (*setup_portio_remap)(void);
	int (*check_phys_apicid_present)(int phys_apicid);
	void (*enable_apic_mode)(void);
@@ -534,9 +534,9 @@ default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
	return (unsigned int)(mask1 & mask2 & mask3);
}

static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid)
static inline unsigned long default_check_apicid_used(physid_mask_t *map, int apicid)
{
	return physid_isset(apicid, bitmap);
	return physid_isset(apicid, *map);
}

static inline unsigned long default_check_apicid_present(int bit)
@@ -544,9 +544,9 @@ static inline unsigned long default_check_apicid_present(int bit)
	return physid_isset(bit, phys_cpu_present_map);
}

static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map)
static inline void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
{
	return phys_map;
	*retmap = *phys_map;
}

/* Mapping from cpu number to logical apicid */
@@ -585,11 +585,6 @@ extern int default_cpu_present_to_apicid(int mps_cpu);
extern int default_check_phys_apicid_present(int phys_apicid);
#endif

static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid)
{
	return physid_mask_of_physid(phys_apicid);
}

#endif /* CONFIG_X86_LOCAL_APIC */

#ifdef CONFIG_X86_32
+9 −7
Original line number Diff line number Diff line
@@ -163,14 +163,16 @@ typedef struct physid_mask physid_mask_t;
#define physids_shift_left(d, s, n)				\
	bitmap_shift_left((d).mask, (s).mask, n, MAX_APICS)

#define physids_coerce(map)			((map).mask[0])
static inline unsigned long physids_coerce(physid_mask_t *map)
{
	return map->mask[0];
}

#define physids_promote(physids)					\
	({								\
		physid_mask_t __physid_mask = PHYSID_MASK_NONE;		\
		__physid_mask.mask[0] = physids;			\
		__physid_mask;						\
	})
static inline void physids_promote(unsigned long physids, physid_mask_t *map)
{
	physids_clear(*map);
	map->mask[0] = physids;
}

/* Note: will create very large stack frames if physid_mask_t is big */
#define physid_mask_of_physid(physid)					\
+4 −14
Original line number Diff line number Diff line
@@ -54,11 +54,6 @@ static u64 noop_apic_icr_read(void)
	return 0;
}

static physid_mask_t noop_ioapic_phys_id_map(physid_mask_t phys_map)
{
	return phys_map;
}

static int noop_cpu_to_logical_apicid(int cpu)
{
	return 0;
@@ -100,9 +95,9 @@ static const struct cpumask *noop_target_cpus(void)
	return cpumask_of(0);
}

static unsigned long noop_check_apicid_used(physid_mask_t bitmap, int apicid)
static unsigned long noop_check_apicid_used(physid_mask_t *map, int apicid)
{
	return physid_isset(apicid, bitmap);
	return physid_isset(apicid, *map);
}

static unsigned long noop_check_apicid_present(int bit)
@@ -155,19 +150,14 @@ struct apic apic_noop = {
	.vector_allocation_domain	= noop_vector_allocation_domain,
	.init_apic_ldr			= noop_init_apic_ldr,

	.ioapic_phys_id_map		= noop_ioapic_phys_id_map,
	.ioapic_phys_id_map		= default_ioapic_phys_id_map,
	.setup_apic_routing		= NULL,
	.multi_timer_check		= NULL,
	.apicid_to_node			= noop_apicid_to_node,

	.cpu_to_logical_apicid		= noop_cpu_to_logical_apicid,
	.cpu_present_to_apicid		= default_cpu_present_to_apicid,

#ifdef CONFIG_X86_32
	.apicid_to_cpu_present		= default_apicid_to_cpu_present,
#else
	.apicid_to_cpu_present		= NULL,
#endif
	.apicid_to_cpu_present		= physid_set_mask_of_physid,

	.setup_portio_remap		= NULL,
	.check_phys_apicid_present	= default_check_phys_apicid_present,
+4 −9
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ static const struct cpumask *bigsmp_target_cpus(void)
#endif
}

static unsigned long bigsmp_check_apicid_used(physid_mask_t bitmap, int apicid)
static unsigned long bigsmp_check_apicid_used(physid_mask_t *map, int apicid)
{
	return 0;
}
@@ -93,11 +93,6 @@ static int bigsmp_cpu_present_to_apicid(int mps_cpu)
	return BAD_APICID;
}

static physid_mask_t bigsmp_apicid_to_cpu_present(int phys_apicid)
{
	return physid_mask_of_physid(phys_apicid);
}

/* Mapping from cpu number to logical apicid */
static inline int bigsmp_cpu_to_logical_apicid(int cpu)
{
@@ -106,10 +101,10 @@ static inline int bigsmp_cpu_to_logical_apicid(int cpu)
	return cpu_physical_id(cpu);
}

static physid_mask_t bigsmp_ioapic_phys_id_map(physid_mask_t phys_map)
static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
{
	/* For clustered we don't have a good way to do this yet - hack */
	return physids_promote(0xFFL);
	physids_promote(0xFFL, retmap);
}

static int bigsmp_check_phys_apicid_present(int phys_apicid)
@@ -230,7 +225,7 @@ struct apic apic_bigsmp = {
	.apicid_to_node			= bigsmp_apicid_to_node,
	.cpu_to_logical_apicid		= bigsmp_cpu_to_logical_apicid,
	.cpu_present_to_apicid		= bigsmp_cpu_present_to_apicid,
	.apicid_to_cpu_present		= bigsmp_apicid_to_cpu_present,
	.apicid_to_cpu_present		= physid_set_mask_of_physid,
	.setup_portio_remap		= NULL,
	.check_phys_apicid_present	= bigsmp_check_phys_apicid_present,
	.enable_apic_mode		= NULL,
+6 −10
Original line number Diff line number Diff line
@@ -466,11 +466,11 @@ static const struct cpumask *es7000_target_cpus(void)
	return cpumask_of(smp_processor_id());
}

static unsigned long
es7000_check_apicid_used(physid_mask_t bitmap, int apicid)
static unsigned long es7000_check_apicid_used(physid_mask_t *map, int apicid)
{
	return 0;
}

static unsigned long es7000_check_apicid_present(int bit)
{
	return physid_isset(bit, phys_cpu_present_map);
@@ -539,14 +539,10 @@ static int es7000_cpu_present_to_apicid(int mps_cpu)

static int cpu_id;

static physid_mask_t es7000_apicid_to_cpu_present(int phys_apicid)
static void es7000_apicid_to_cpu_present(int phys_apicid, physid_mask_t *retmap)
{
	physid_mask_t mask;

	mask = physid_mask_of_physid(cpu_id);
	physid_set_mask_of_physid(cpu_id, retmap);
	++cpu_id;

	return mask;
}

/* Mapping from cpu number to logical apicid */
@@ -561,10 +557,10 @@ static int es7000_cpu_to_logical_apicid(int cpu)
#endif
}

static physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map)
static void es7000_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
{
	/* For clustered we don't have a good way to do this yet - hack */
	return physids_promote(0xff);
	physids_promote(0xFFL, retmap);
}

static int es7000_check_phys_apicid_present(int cpu_physical_apicid)
Loading