@@ -228,7 +228,7 @@ static struct notifier_block x2apic_cpu_nfb = {
.notifier_call = update_clusterinfo
};
-static int8_t __initdata x2apic_phys = -1;
+int8_t __initdata x2apic_phys = -1;
boolean_param("x2apic_phys", x2apic_phys);
const struct genapic *__init apic_x2apic_probe(void)
@@ -27,6 +27,8 @@ enum apic_mode {
extern bool iommu_x2apic_enabled;
extern u8 apic_verbosity;
extern bool directed_eoi_enabled;
+extern uint16_t x2apic_max_cluster_id;
+extern int8_t x2apic_phys;
void check_x2apic_preenabled(void);
void x2apic_bsp_setup(void);
@@ -421,9 +421,15 @@ int __init init_irq_data(void)
int irq, vector;
if ( nr_irqs == 0 )
- nr_irqs = cpu_has_apic ? max(0U + num_present_cpus() *
- NR_DYNAMIC_VECTORS, 8 * nr_irqs_gsi)
+ {
+ unsigned int vec_spaces =
+ (x2apic_enabled && !x2apic_phys) ? x2apic_max_cluster_id + 1
+ : num_present_cpus();
+
+ nr_irqs = cpu_has_apic ? max(vec_spaces * NR_DYNAMIC_VECTORS,
+ 8 * nr_irqs_gsi)
: nr_irqs_gsi;
+ }
else if ( nr_irqs < 16 )
nr_irqs = 16;
@@ -131,6 +131,8 @@ static int __init mpf_checksum(unsigned char *mp, int len)
return sum & 0xFF;
}
+uint16_t __initdata x2apic_max_cluster_id;
+
/* Return xen's logical cpu_id of the new added cpu or <0 if error */
static int MP_processor_info_x(struct mpc_config_processor *m,
u32 apicid, bool hotplug)
@@ -199,6 +201,9 @@ static int MP_processor_info_x(struct mpc_config_processor *m,
def_to_bigsmp = true;
}
+ x2apic_max_cluster_id = max(x2apic_max_cluster_id,
+ (uint16_t)(apicid >> 4));
+
return cpu;
}
Current code to calculate nr_irqs assumes the APIC destination mode to be physical, so all vectors on each possible CPU is available for use by a different interrupt source. This is not true when using Logical (Cluster) destination mode, where CPUs in the same cluster share the vector space. Fix by calculating the maximum Cluster ID and use it to derive the number of clusters in the system. Note the code assumes Cluster IDs to be contiguous, or else we will set nr_irqs to a number higher than the real amount of vectors (still not fatal). The number of clusters is then used instead of the number of present CPUs when calculating the value of nr_irqs. Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> --- xen/arch/x86/genapic/x2apic.c | 2 +- xen/arch/x86/include/asm/apic.h | 2 ++ xen/arch/x86/irq.c | 10 ++++++++-- xen/arch/x86/mpparse.c | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-)