apic: APIC ID should not be 255, which is used for broadcast
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 20 Jul 2012 02:31:04 +0000 (10:31 +0800)
committerSascha Wildner <saw@online.de>
Wed, 25 Jul 2012 08:55:07 +0000 (10:55 +0200)
sys/platform/pc32/acpica5/acpi_madt.c
sys/platform/pc32/apic/apicvar.h
sys/platform/pc32/apic/lapic.c
sys/platform/pc32/i386/mptable.c
sys/platform/pc64/acpica5/acpi_madt.c
sys/platform/pc64/apic/apicvar.h
sys/platform/pc64/apic/lapic.c
sys/platform/pc64/x86_64/mptable.c

index 11c9de5..c76a5da 100644 (file)
@@ -40,6 +40,7 @@
 #include <machine_base/isa/isa_intr.h>
 #include <machine_base/apic/lapic.h>
 #include <machine_base/apic/ioapic.h>
+#include <machine_base/apic/apicvar.h>
 
 #include "acpi_sdt.h"
 #include "acpi_sdt_var.h"
@@ -394,6 +395,12 @@ madt_lapic_probe_callback(void *xarg, const struct acpi_madt_ent *ent)
                lapic_ent = (const struct acpi_madt_lapic *)ent;
                if (lapic_ent->ml_flags & MADT_LAPIC_ENABLED)
                        arg->cpu_count++;
+               if (lapic_ent->ml_apic_id == APICID_MAX) {
+                       kprintf("madt_lapic_probe: "
+                           "invalid LAPIC apic id %d\n",
+                           lapic_ent->ml_apic_id);
+                       return EINVAL;
+               }
        } else if (ent->me_type == MADT_ENT_LAPIC_ADDR) {
                const struct acpi_madt_lapic_addr *lapic_addr_ent;
 
@@ -535,6 +542,12 @@ madt_ioapic_probe_callback(void *xarg, const struct acpi_madt_ent *ent)
                        kprintf("madt_ioapic_probe: zero IOAPIC address\n");
                        return EINVAL;
                }
+               if (ioapic_ent->mio_apic_id == APICID_MAX) {
+                       kprintf("madt_ioapic_probe: "
+                           "invalid IOAPIC apic id %d\n",
+                           ioapic_ent->mio_apic_id);
+                       return EINVAL;
+               }
 
                arg->ioapic_cnt++;
                if (ioapic_ent->mio_gsi_base == 0)
index 07982e8..80c035d 100644 (file)
  */
 #define NAPICID                256
 
+/*
+ * APICID must be less than this value
+ * 255 is for "broadcast to all APICs"
+ */
+#define APICID_MAX     255
+
 #endif /* _MACHINE_APICVAR_H_ */
index 4c39d27..1318284 100644 (file)
@@ -671,7 +671,7 @@ lapic_unused_apic_id(int start)
 {
        int i;
 
-       for (i = start; i < NAPICID; ++i) {
+       for (i = start; i < APICID_MAX; ++i) {
                if (APICID_TO_CPUID(i) == -1)
                        return i;
        }
index 36c15ac..dc94ad6 100644 (file)
@@ -59,6 +59,7 @@
 #include <machine_base/apic/ioapic_abi.h>
 #include <machine_base/apic/lapic.h>
 #include <machine_base/apic/ioapic.h>
+#include <machine_base/apic/apicvar.h>
 #include <machine/psl.h>
 #include <machine/segments.h>
 #include <machine/tss.h>
@@ -821,6 +822,12 @@ mptable_lapic_probe_callback(void *xarg, const void *pos, int type)
                return 0;
        arg->cpu_count++;
 
+       if (ent->apic_id == APICID_MAX) {
+               kprintf("MPTABLE: invalid LAPIC apic id %d\n",
+                   ent->apic_id);
+               return EINVAL;
+       }
+
        if (ent->cpu_flags & PROCENTRY_FLAG_BP) {
                if (arg->found_bsp) {
                        kprintf("more than one BSP in base MP table\n");
@@ -904,6 +911,11 @@ mptable_ioapic_list_callback(void *xarg, const void *pos, int type)
                kprintf("mptable_ioapic_create_list: zero IOAPIC addr\n");
                return EINVAL;
        }
+       if (ent->apic_id == APICID_MAX) {
+               kprintf("mptable_ioapic_create_list: "
+                   "invalid IOAPIC apic id %d\n", ent->apic_id);
+               return EINVAL;
+       }
 
        TAILQ_FOREACH(ioapic, &mptable_ioapic_list, mio_link) {
                if (ioapic->mio_apic_id == ent->apic_id) {
index a1d7f53..3744bd0 100644 (file)
@@ -40,6 +40,7 @@
 #include <machine_base/isa/isa_intr.h>
 #include <machine_base/apic/lapic.h>
 #include <machine_base/apic/ioapic.h>
+#include <machine_base/apic/apicvar.h>
 
 #include "acpi_sdt.h"
 #include "acpi_sdt_var.h"
@@ -394,6 +395,12 @@ madt_lapic_probe_callback(void *xarg, const struct acpi_madt_ent *ent)
                lapic_ent = (const struct acpi_madt_lapic *)ent;
                if (lapic_ent->ml_flags & MADT_LAPIC_ENABLED)
                        arg->cpu_count++;
+               if (lapic_ent->ml_apic_id == APICID_MAX) {
+                       kprintf("madt_lapic_probe: "
+                           "invalid LAPIC apic id %d\n",
+                           lapic_ent->ml_apic_id);
+                       return EINVAL;
+               }
        } else if (ent->me_type == MADT_ENT_LAPIC_ADDR) {
                const struct acpi_madt_lapic_addr *lapic_addr_ent;
 
@@ -535,6 +542,12 @@ madt_ioapic_probe_callback(void *xarg, const struct acpi_madt_ent *ent)
                        kprintf("madt_ioapic_probe: zero IOAPIC address\n");
                        return EINVAL;
                }
+               if (ioapic_ent->mio_apic_id == APICID_MAX) {
+                       kprintf("madt_ioapic_probe: "
+                           "invalid IOAPIC apic id %d\n",
+                           ioapic_ent->mio_apic_id);
+                       return EINVAL;
+               }
 
                arg->ioapic_cnt++;
                if (ioapic_ent->mio_gsi_base == 0)
index 8df9b7a..80928b5 100644 (file)
  */
 #define NAPICID                256
 
+/*
+ * APICID must be less than this value
+ * 255 is for "broadcast to all APICs"
+ */
+#define APICID_MAX     255
+
 #endif /* _MACHINE_APICVAR_H_ */
index da6eada..a79e032 100644 (file)
@@ -732,7 +732,7 @@ lapic_unused_apic_id(int start)
 {
        int i;
 
-       for (i = start; i < NAPICID; ++i) {
+       for (i = start; i < APICID_MAX; ++i) {
                if (APICID_TO_CPUID(i) == -1)
                        return i;
        }
index 3b92d74..4eeb8b0 100644 (file)
@@ -53,6 +53,7 @@
 #include <machine/smp.h>
 #include <machine_base/isa/isa_intr.h>
 #include <machine_base/apic/apicreg.h>
+#include <machine_base/apic/apicvar.h>
 #include <machine/atomic.h>
 #include <machine/cpufunc.h>
 #include <machine/cputypes.h>
@@ -822,6 +823,12 @@ mptable_lapic_probe_callback(void *xarg, const void *pos, int type)
                return 0;
        arg->cpu_count++;
 
+       if (ent->apic_id == APICID_MAX) {
+               kprintf("MPTABLE: invalid LAPIC apic id %d\n",
+                   ent->apic_id);
+               return EINVAL;
+       }
+
        if (ent->cpu_flags & PROCENTRY_FLAG_BP) {
                if (arg->found_bsp) {
                        kprintf("more than one BSP in base MP table\n");
@@ -905,6 +912,11 @@ mptable_ioapic_list_callback(void *xarg, const void *pos, int type)
                kprintf("mptable_ioapic_create_list: zero IOAPIC addr\n");
                return EINVAL;
        }
+       if (ent->apic_id == APICID_MAX) {
+               kprintf("mptable_ioapic_create_list: "
+                   "invalid IOAPIC apic id %d\n", ent->apic_id);
+               return EINVAL;
+       }
 
        TAILQ_FOREACH(ioapic, &mptable_ioapic_list, mio_link) {
                if (ioapic->mio_apic_id == ent->apic_id) {