Skip to contentSkip to conversation

x86/microcode_intel_early.c: Get 32-bit physical address by __pa_nodebug()

PATCH In review Fenghua Yu 6 participants 10 messages Mar 19, 2013 – Mar 21, 2013 x86

lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 x86/microcode_intel_early.c: Get 32-bit physical address by __pa_nodebug()

From: Fenghua Yu <[email protected]>

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data (e.g. max_low_pfn) that haven't been setup yet in such early boot phase. To fix the issue, __pa_nodebug() replaces __pa_symbol() to get a global symbol's physical address.

---
 arch/x86/kernel/microcode_intel_early.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/x86/kernel/microcode_intel_early.c +13 -13
index 7890bc8..5992ee8 100644
@@ -90,13 +90,13 @@ microcode_phys(struct microcode_intel **mc_saved_tmp,
 	struct microcode_intel ***mc_saved;
 
 	mc_saved = (struct microcode_intel ***)
-		   __pa_symbol(&mc_saved_data->mc_saved);
+		   __pa_nodebug(&mc_saved_data->mc_saved);
 	for (i = 0; i < mc_saved_data->mc_saved_count; i++) {
 		struct microcode_intel *p;
 
 		p = *(struct microcode_intel **)
-			__pa(mc_saved_data->mc_saved + i);
-		mc_saved_tmp[i] = (struct microcode_intel *)__pa(p);
+			__pa_nodebug(mc_saved_data->mc_saved + i);
+		mc_saved_tmp[i] = (struct microcode_intel *)__pa_nodebug(p);
 	}
 }
 #endif
@@ -562,7 +562,7 @@ scan_microcode(unsigned long start, unsigned long end,
 	struct cpio_data cd;
 	long offset = 0;
 #ifdef CONFIG_X86_32
-	char *p = (char *)__pa_symbol(ucode_name);
+	char *p = (char *)__pa_nodebug(ucode_name);
 #else
 	char *p = ucode_name;
 #endif
@@ -630,8 +630,8 @@ static void __cpuinit print_ucode(struct ucode_cpu_info *uci)
 	if (mc_intel == NULL)
 		return;
 
-	delay_ucode_info_p = (int *)__pa_symbol(&delay_ucode_info);
-	current_mc_date_p = (int *)__pa_symbol(&current_mc_date);
+	delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
+	current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
 
 	*delay_ucode_info_p = 1;
 	*current_mc_date_p = mc_intel->hdr.date;
@@ -741,15 +741,15 @@ load_ucode_intel_bsp(void)
 #ifdef CONFIG_X86_32
 	struct boot_params *boot_params_p;
 
-	boot_params_p = (struct boot_params *)__pa_symbol(&boot_params);
+	boot_params_p = (struct boot_params *)__pa_nodebug(&boot_params);
 	ramdisk_image = boot_params_p->hdr.ramdisk_image;
 	ramdisk_size  = boot_params_p->hdr.ramdisk_size;
 	initrd_start_early = ramdisk_image;
 	initrd_end_early = initrd_start_early + ramdisk_size;
 
 	_load_ucode_intel_bsp(
-		(struct mc_saved_data *)__pa_symbol(&mc_saved_data),
-		(unsigned long *)__pa_symbol(&mc_saved_in_initrd),
+		(struct mc_saved_data *)__pa_nodebug(&mc_saved_data),
+		(unsigned long *)__pa_nodebug(&mc_saved_in_initrd),
 		initrd_start_early, initrd_end_early, &uci);
 #else
 	ramdisk_image = boot_params.hdr.ramdisk_image;
@@ -772,10 +772,10 @@ void __cpuinit load_ucode_intel_ap(void)
 	unsigned long *initrd_start_p;
 
 	mc_saved_in_initrd_p =
-		(unsigned long *)__pa_symbol(mc_saved_in_initrd);
-	mc_saved_data_p = (struct mc_saved_data *)__pa_symbol(&mc_saved_data);
-	initrd_start_p = (unsigned long *)__pa_symbol(&initrd_start);
-	initrd_start_addr = (unsigned long)__pa_symbol(*initrd_start_p);
+		(unsigned long *)__pa_nodebug(mc_saved_in_initrd);
+	mc_saved_data_p = (struct mc_saved_data *)__pa_nodebug(&mc_saved_data);
+	initrd_start_p = (unsigned long *)__pa_nodebug(&initrd_start);
+	initrd_start_addr = (unsigned long)__pa_nodebug(*initrd_start_p);
 #else
 	mc_saved_data_p = &mc_saved_data;
 	mc_saved_in_initrd_p = mc_saved_in_initrd;
Signature · 1 line
1.8.0.1
#1 lore raw
Quoted 6 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data (e.g. max_low_pfn) that haven't been setup yet in such early boot phase. To fix the issue, __pa_nodebug() replaces __pa_symbol() to get a global symbol's physical address.

That explanation is not precise.

__phys_addr in 32bit when DEBUG_VIRTUAL is set, it does have check

        /* max_low_pfn is set early, but not _that_ early */
        if (max_low_pfn) {
         ....
        }

the reason should be:
in head_32.S, 32bit flat mode, you need to switch to phys addr to access global variable max_low_pfn.

Thanks

Yinghai

#2 lore raw
Quoted 10 lines · Yinghai Lu
Quoted 6 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data (e.g. max_low_pfn) that haven't been setup yet in such early boot phase. To fix the issue, __pa_nodebug() replaces __pa_symbol() to get a global symbol's physical address.

That explanation is not precise.

Quoted 9 lines

__phys_addr in 32bit when DEBUG_VIRTUAL is set, it does have check

        /* max_low_pfn is set early, but not _that_ early */
        if (max_low_pfn) {
         ....
        }

the reason should be:
in head_32.S, 32bit flat mode, you need to switch to phys addr to access global variable max_low_pfn.

Uh, no.

It already does that. The problem is that __pa_symbol() breaks with CONFIG_DEBUG_VIRTUAL at this point; we need to use __pa_nodebug().

-hpa

#3 lore raw
In reply to Yinghai Lu
Quoted 17 lines

From: [email protected] [mailto:[email protected]] On Behalf Of Yinghai Lu

Quoted 3 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data

(e.g.

Quoted 1 line

max_low_pfn) that haven't been setup yet in such early boot phase. To

fix the

Quoted 1 line

issue, __pa_nodebug() replaces __pa_symbol() to get a global symbol's

physical

Quoted 1 line

address.

That explanation is not precise.

__phys_addr in 32bit when DEBUG_VIRTUAL is set, it does have check

Quoted 8 lines
        /* max_low_pfn is set early, but not _that_ early */
        if (max_low_pfn) {
         ....
        }

the reason should be:
in head_32.S, 32bit flat mode, you need to switch to phys addr to access
global variable max_low_pfn.

Max_low_pfn is not set up yet at this point, but __pa_symbol() reads it if CONFIG_DEBUG_VIRTUAL. There is no need to access max_low_pfn or any other data that is not setup yet if CONFIG_DEBUG_VIRTUAL.

So I think the explanation is ok.

Thanks.

-Fenghua

#4 lore raw
Quoted 26 lines · Fenghua
Quoted 17 lines

From: [email protected] [mailto:[email protected]] On Behalf Of Yinghai Lu

Quoted 3 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data

(e.g.

Quoted 1 line

max_low_pfn) that haven't been setup yet in such early boot phase. To

fix the

Quoted 1 line

issue, __pa_nodebug() replaces __pa_symbol() to get a global symbol's

physical

Quoted 1 line

address.

That explanation is not precise.

__phys_addr in 32bit when DEBUG_VIRTUAL is set, it does have check

Quoted 8 lines
        /* max_low_pfn is set early, but not _that_ early */
        if (max_low_pfn) {
         ....
        }

the reason should be:
in head_32.S, 32bit flat mode, you need to switch to phys addr to access
global variable max_low_pfn.

Quoted 5 lines

Max_low_pfn is not set up yet at this point, but __pa_symbol() reads it if CONFIG_DEBUG_VIRTUAL. There is no need to access max_low_pfn or any other data that is not setup yet if CONFIG_DEBUG_VIRTUAL.

So I think the explanation is ok.

Changlog said:

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data
(e.g. max_low_pfn) that haven't been setup yet in such early boot phase.

---

So do you mean we have to change all __pa_symbol before setup.c::setup_arch/find_low_pfn_range ? because only at that time max_low_pfn get setup.

#5 lore raw
Quoted 5 lines · Yinghai Lu

So do you mean we have to change all __pa_symbol before setup.c::setup_arch/find_low_pfn_range ? because only at that time max_low_pfn get setup.

No, I suspect the problem is that the debugging code fails to notice that max_low_pfn isn't set up yet because it is in linear mode, and so it reads the wrong address when it checks max_low_pfn.

-hpa

#6 lore raw
In reply to Fenghua Yu
Quoted 7 lines · Fenghua Yu

From: Fenghua Yu <[email protected]>

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data (e.g. max_low_pfn) that haven't been setup yet in such early boot phase. To fix the issue, __pa_nodebug() replaces __pa_symbol() to get a global symbol's physical address.

Quoted 5 lines
---
 arch/x86/kernel/microcode_intel_early.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

This patch fixes my problem. Thank you.

#7 lore raw

[tip:x86/urgent] x86-32, microcode_intel_early: Fix crash with CONFIG_DEBUG_VIRTUAL

In reply to Fenghua Yu
x86-32, microcode_intel_early: Fix crash with CONFIG_DEBUG_VIRTUAL
Commit-ID:  c83a9d5e425d4678b05ca058fec6254f18601474
Gitweb:     http://git.kernel.org/tip/c83a9d5e425d4678b05ca058fec6254f18601474
Author:     Fenghua Yu <[email protected]>
AuthorDate: Tue, 19 Mar 2013 08:04:44 -0700
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Tue, 19 Mar 2013 19:51:08 -0700

x86-32, microcode_intel_early: Fix crash with CONFIG_DEBUG_VIRTUAL

In 32-bit, __pa_symbol() in CONFIG_DEBUG_VIRTUAL accesses kernel data (e.g. max_low_pfn) that not only hasn't been setup yet in such early boot phase, but since we are in linear mode, cannot even be detected as uninitialized.

Thus, use __pa_nodebug() rather than __pa_symbol() to get a global symbol's physical address.

---
 arch/x86/kernel/microcode_intel_early.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/x86/kernel/microcode_intel_early.c +13 -13
index 7890bc8..5992ee8 100644
@@ -90,13 +90,13 @@ microcode_phys(struct microcode_intel **mc_saved_tmp,
 	struct microcode_intel ***mc_saved;
 
 	mc_saved = (struct microcode_intel ***)
-		   __pa_symbol(&mc_saved_data->mc_saved);
+		   __pa_nodebug(&mc_saved_data->mc_saved);
 	for (i = 0; i < mc_saved_data->mc_saved_count; i++) {
 		struct microcode_intel *p;
 
 		p = *(struct microcode_intel **)
-			__pa(mc_saved_data->mc_saved + i);
-		mc_saved_tmp[i] = (struct microcode_intel *)__pa(p);
+			__pa_nodebug(mc_saved_data->mc_saved + i);
+		mc_saved_tmp[i] = (struct microcode_intel *)__pa_nodebug(p);
 	}
 }
 #endif
@@ -562,7 +562,7 @@ scan_microcode(unsigned long start, unsigned long end,
 	struct cpio_data cd;
 	long offset = 0;
 #ifdef CONFIG_X86_32
-	char *p = (char *)__pa_symbol(ucode_name);
+	char *p = (char *)__pa_nodebug(ucode_name);
 #else
 	char *p = ucode_name;
 #endif
@@ -630,8 +630,8 @@ static void __cpuinit print_ucode(struct ucode_cpu_info *uci)
 	if (mc_intel == NULL)
 		return;
 
-	delay_ucode_info_p = (int *)__pa_symbol(&delay_ucode_info);
-	current_mc_date_p = (int *)__pa_symbol(&current_mc_date);
+	delay_ucode_info_p = (int *)__pa_nodebug(&delay_ucode_info);
+	current_mc_date_p = (int *)__pa_nodebug(&current_mc_date);
 
 	*delay_ucode_info_p = 1;
 	*current_mc_date_p = mc_intel->hdr.date;
@@ -741,15 +741,15 @@ load_ucode_intel_bsp(void)
 #ifdef CONFIG_X86_32
 	struct boot_params *boot_params_p;
 
-	boot_params_p = (struct boot_params *)__pa_symbol(&boot_params);
+	boot_params_p = (struct boot_params *)__pa_nodebug(&boot_params);
 	ramdisk_image = boot_params_p->hdr.ramdisk_image;
 	ramdisk_size  = boot_params_p->hdr.ramdisk_size;
 	initrd_start_early = ramdisk_image;
 	initrd_end_early = initrd_start_early + ramdisk_size;
 
 	_load_ucode_intel_bsp(
-		(struct mc_saved_data *)__pa_symbol(&mc_saved_data),
-		(unsigned long *)__pa_symbol(&mc_saved_in_initrd),
+		(struct mc_saved_data *)__pa_nodebug(&mc_saved_data),
+		(unsigned long *)__pa_nodebug(&mc_saved_in_initrd),
 		initrd_start_early, initrd_end_early, &uci);
 #else
 	ramdisk_image = boot_params.hdr.ramdisk_image;
@@ -772,10 +772,10 @@ void __cpuinit load_ucode_intel_ap(void)
 	unsigned long *initrd_start_p;
 
 	mc_saved_in_initrd_p =
-		(unsigned long *)__pa_symbol(mc_saved_in_initrd);
-	mc_saved_data_p = (struct mc_saved_data *)__pa_symbol(&mc_saved_data);
-	initrd_start_p = (unsigned long *)__pa_symbol(&initrd_start);
-	initrd_start_addr = (unsigned long)__pa_symbol(*initrd_start_p);
+		(unsigned long *)__pa_nodebug(mc_saved_in_initrd);
+	mc_saved_data_p = (struct mc_saved_data *)__pa_nodebug(&mc_saved_data);
+	initrd_start_p = (unsigned long *)__pa_nodebug(&initrd_start);
+	initrd_start_addr = (unsigned long)__pa_nodebug(*initrd_start_p);
 #else
 	mc_saved_data_p = &mc_saved_data;
 	mc_saved_in_initrd_p = mc_saved_in_initrd;
#8 lore raw
In reply to Fenghua Yu

arch/x86/kernel/microcode_intel_early.c void __cpuinit load_ucode_intel_ap(void) · line 778

Quoted 2 lines · Fenghua Yu
arch/x86/kernel/microcode_intel_early.c +2 -0
+	initrd_start_p = (unsigned long *)__pa_nodebug(&initrd_start);
+	initrd_start_addr = (unsigned long)__pa_nodebug(*initrd_start_p);

We should probably use __pa_early() for that - aliased to __pa_nodebug(). That would self-document the purpose.

Thanks,

Ingo

#9 lore raw
Quoted 9 lines · Ingo Molnar

arch/x86/kernel/microcode_intel_early.c void __cpuinit load_ucode_intel_ap(void) · line 778

Quoted 2 lines · Fenghua Yu
arch/x86/kernel/microcode_intel_early.c +2 -0
+	initrd_start_p = (unsigned long *)__pa_nodebug(&initrd_start);
+	initrd_start_addr = (unsigned long)__pa_nodebug(*initrd_start_p);

We should probably use __pa_early() for that - aliased to __pa_nodebug(). That would self-document the purpose.

Well, it's not that it is early, it is that it actually can execute in linear mode (paging off).

-hpa