Skip to contentSkip to conversation

Fix apic.flat

PATCH New Avi Kivity 1 participant 4 messages Sep 6, 2011 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

cover Fix apic.flat

apic.flat is failing due to an IPI hitting an uninitialized IDT entry. This patchset fixes the issue.

Avi Kivity (3):
x86/desc: switch to using boot_idt
x86/desc: allow multiple initializations
x86/smp: use desc.c for setting up IPI handler

 lib/x86/desc.c |   23 +++++++++--------------
 lib/x86/smp.c  |   23 ++---------------------
 2 files changed, 11 insertions(+), 35 deletions(-)
Signature · 1 line
1.7.6.1
author
#1 lore raw

PATCH 1/3 x86/desc: switch to using boot_idt

boot_idt is set up an all cpus by the startup code, unlike the idt local to desc.c.

---
 lib/x86/desc.c |   17 +++--------------
 1 files changed, 3 insertions(+), 14 deletions(-)
lib/x86/desc.c +3 -14
index 11bd2a2..0ed8c22 100644
@@ -62,21 +62,11 @@ typedef struct {
 	u16 iomap_base;
 } tss32_t;
 
-static idt_entry_t idt[256] __attribute__((aligned(4096)));
-
-void load_lidt(idt_entry_t *idt, int nentries)
-{
-    struct descriptor_table_ptr dt;
-
-    dt.limit = nentries * sizeof(*idt) - 1;
-    dt.base = (unsigned long)idt;
-    lidt(&dt);
-    asm volatile ("lidt %0" : : "m"(dt));
-}
+extern idt_entry_t boot_idt[256];
 
 void set_idt_entry(int vec, void *addr, int dpl)
 {
-    idt_entry_t *e = &idt[vec];
+    idt_entry_t *e = &boot_idt[vec];
     memset(e, 0, sizeof *e);
     e->offset0 = (unsigned long)addr;
     e->selector = read_cs();
@@ -92,7 +82,7 @@ void set_idt_entry(int vec, void *addr, int dpl)
 
 void set_idt_sel(int vec, u16 sel)
 {
-    idt_entry_t *e = &idt[vec];
+    idt_entry_t *e = &boot_idt[vec];
     e->selector = sel;
 }
 
@@ -239,7 +229,6 @@ static void *idt_handlers[32] = {
 void setup_idt(void)
 {
     int i;
-    load_lidt(idt, 256);
     for (i = 0; i < 32; i++)
 	    if (idt_handlers[i])
 		    set_idt_entry(i, idt_handlers[i], 0);
Signature · 1 line
1.7.6.1
author
#2 lore raw

PATCH 2/3 x86/desc: allow multiple initializations

In reply to Avi Kivity

There are multiple callers, so be forgiving.

---
 lib/x86/desc.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
lib/x86/desc.c +6 -0
index 0ed8c22..c268955 100644
@@ -229,6 +229,12 @@ static void *idt_handlers[32] = {
 void setup_idt(void)
 {
     int i;
+    static bool idt_initialized = false;
+
+    if (idt_initialized) {
+        return;
+    }
+    idt_initialized = true;
     for (i = 0; i < 32; i++)
 	    if (idt_handlers[i])
 		    set_idt_entry(i, idt_handlers[i], 0);
Signature · 1 line
1.7.6.1
author
#3 lore raw

PATCH 3/3 x86/smp: use desc.c for setting up IPI handler

In reply to Avi Kivity

This allows other callers to use desc.c without conflict. Fixes apic.flat failure with -smp 2.

---
 lib/x86/smp.c |   23 ++---------------------
 1 files changed, 2 insertions(+), 21 deletions(-)
lib/x86/smp.c +2 -21
index 0d8bae8..d4c8106 100644
@@ -42,26 +42,6 @@ asm (
 #endif
      );
 
-
-static void set_ipi_descriptor(void (*ipi_entry)(void))
-{
-    unsigned short *desc = (void *)(IPI_VECTOR * sizeof(long) * 2);
-    unsigned short cs;
-    unsigned long ipi = (unsigned long)ipi_entry;
-
-    asm ("mov %%cs, %0" : "=r"(cs));
-    desc[0] = ipi;
-    desc[1] = cs;
-    desc[2] = 0x8e00;
-    desc[3] = ipi >> 16;
-#ifdef __x86_64__
-    desc[4] = ipi >> 32;
-    desc[5] = ipi >> 48;
-    desc[6] = 0;
-    desc[7] = 0;
-#endif
-}
-
 void spin_lock(struct spinlock *lock)
 {
     int v = 1;
@@ -134,7 +114,8 @@ void smp_init(void)
 
     _cpu_count = fwcfg_get_nb_cpus();
 
-    set_ipi_descriptor(ipi_entry);
+    setup_idt();
+    set_idt_entry(IPI_VECTOR, ipi_entry, 0);
 
     setup_smp_id(0);
     for (i = 1; i < cpu_count(); ++i)
Signature · 1 line
1.7.6.1