Skip to contentSkip to conversation

EFI: Fix gdt load

PATCH In review Edgar Hucek 3 participants 5 messages Mar 2, 2006 – Mar 5, 2006 EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 EFI: Fix gdt load

This patch makes the kernel bootable again on ia32 EFI systems.

arch/i386/kernel/efi.c +7 -7
diff -uNr linux-2.6.16-rc5/arch/i386/kernel/efi.c linux-2.6.16-rc5.efi/arch/i386/kernel/efi.c
@@ -70,7 +70,8 @@
 {
 	unsigned long cr4;
 	unsigned long temp;
-
+	struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
+	
 	spin_lock(&efi_rt_lock);
 	local_irq_save(efi_rt_eflags);
 
@@ -103,18 +104,17 @@
 	 */
 	local_flush_tlb();
 
-	per_cpu(cpu_gdt_descr, 0).address =
-				 __pa(per_cpu(cpu_gdt_descr, 0).address);
-	load_gdt((struct Xgt_desc_struct *)__pa(&per_cpu(cpu_gdt_descr, 0)));
+	cpu_gdt_descr->address = __pa(cpu_gdt_descr->address);
+	load_gdt(cpu_gdt_descr);
 }
 
 static void efi_call_phys_epilog(void)
 {
 	unsigned long cr4;
+	struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
 
-	per_cpu(cpu_gdt_descr, 0).address =
-			(unsigned long)__va(per_cpu(cpu_gdt_descr, 0).address);
-	load_gdt((struct Xgt_desc_struct *)__va(&per_cpu(cpu_gdt_descr, 0)));
+	cpu_gdt_descr->address = __va(cpu_gdt_descr->address);
+	load_gdt(cpu_gdt_descr);
 
 	cr4 = read_cr4();
 
#1 lore raw
Quoted 4 lines · Edgar Hucek

This patch makes the kernel bootable again on ia32 EFI systems.

spin_lock(&efi_rt_lock);
local_irq_save(efi_rt_eflags);

That looks like a race, not to mention that efi_rt_eflags is a global variable. The same strange ordering occurs on unlock, i presume this code 'works' because it's done early during boot?

#3 lore raw
In reply to Edgar Hucek
Quoted 34 lines · Edgar Hucek

This patch makes the kernel bootable again on ia32 EFI systems.

------------------------------------------------------------------------

diff -uNr linux-2.6.16-rc5/arch/i386/kernel/efi.c linux-2.6.16-rc5.efi/arch/i386/kernel/efi.c

arch/i386/kernel/efi.c +4 -4
@@ -70,7 +70,8 @@
 {
 	unsigned long cr4;
 	unsigned long temp;
-
+	struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
+	
 	spin_lock(&efi_rt_lock);
 	local_irq_save(efi_rt_eflags);
 
@@ -103,18 +104,17 @@
 	 */
 	local_flush_tlb();
 
-	per_cpu(cpu_gdt_descr, 0).address =
-				 __pa(per_cpu(cpu_gdt_descr, 0).address);
-	load_gdt((struct Xgt_desc_struct *)__pa(&per_cpu(cpu_gdt_descr, 0)));
+	cpu_gdt_descr->address = __pa(cpu_gdt_descr->address);
+	load_gdt(cpu_gdt_descr);
 }
 
 static void efi_call_phys_epilog(void)
 {
 	unsigned long cr4;

arch/i386/kernel/efi.c line 120

Quoted 10 lines
arch/i386/kernel/efi.c +3 -3
+	struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
 
-	per_cpu(cpu_gdt_descr, 0).address =
-			(unsigned long)__va(per_cpu(cpu_gdt_descr, 0).address);
-	load_gdt((struct Xgt_desc_struct *)__va(&per_cpu(cpu_gdt_descr, 0)));
+	cpu_gdt_descr->address = __va(cpu_gdt_descr->address);
+	load_gdt(cpu_gdt_descr);
 
 	cr4 = read_cr4();
 

I don't know if it is a race condition. At least it makes the kernel bootable agin on my box. Any idea what i could try to make a better patch ?

cu

Edgar (gimli) Hucek

#4 lore raw
In reply to Edgar Hucek
Quoted 3 lines · Edgar Hucek

This patch makes the kernel bootable again on ia32 EFI systems.

Argh, thanks. I'll move the per_cpu() call inside the lock, just in case we happen to be running preemptibly there.

Zach, Matt: please review, test and ack asap?

arch/i386/kernel/efi.c renamed from arch/i386/kernel/efi.c~efi-fix-gdt-load +8 -6
diff -puN arch/i386/kernel/efi.c~efi-fix-gdt-load arch/i386/kernel/efi.c
@@ -70,10 +70,13 @@ static void efi_call_phys_prelog(void)
 {
 	unsigned long cr4;
 	unsigned long temp;
+	struct Xgt_desc_struct *cpu_gdt_descr;
 
 	spin_lock(&efi_rt_lock);
 	local_irq_save(efi_rt_eflags);
 
+	cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
+
 	/*
 	 * If I don't have PSE, I should just duplicate two entries in page
 	 * directory. If I have PSE, I just need to duplicate one entry in
@@ -103,18 +106,17 @@ static void efi_call_phys_prelog(void)
 	 */
 	local_flush_tlb();
 
-	per_cpu(cpu_gdt_descr, 0).address =
-				 __pa(per_cpu(cpu_gdt_descr, 0).address);
-	load_gdt((struct Xgt_desc_struct *)__pa(&per_cpu(cpu_gdt_descr, 0)));
+	cpu_gdt_descr->address = __pa(cpu_gdt_descr->address);
+	load_gdt(cpu_gdt_descr);
 }
 
 static void efi_call_phys_epilog(void)
 {
 	unsigned long cr4;
+	struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, 0);
 
-	per_cpu(cpu_gdt_descr, 0).address =
-			(unsigned long)__va(per_cpu(cpu_gdt_descr, 0).address);
-	load_gdt((struct Xgt_desc_struct *)__va(&per_cpu(cpu_gdt_descr, 0)));
+	cpu_gdt_descr->address = __va(cpu_gdt_descr->address);
+	load_gdt(cpu_gdt_descr);
 
 	cr4 = read_cr4();
 

_

#2 lore raw
In reply to Zwane Mwaikambo
Quoted 11 lines · Zwane Mwaikambo
Quoted 4 lines · Edgar Hucek

This patch makes the kernel bootable again on ia32 EFI systems.

arch/i386/kernel/efi.c +0 -0
 	spin_lock(&efi_rt_lock);
 	local_irq_save(efi_rt_eflags);
Quoted 3 lines

That looks like a race, not to mention that efi_rt_eflags is a global variable. The same strange ordering occurs on unlock, i presume this code 'works' because it's done early during boot?

No, the code's OK. This is the prologue function. The epilogue function
does the opposite. In between, this CPU will dink around with EFI stuff.

And the order is correct too - the lock protects efi_rt_eflags.