Skip to contentSkip to conversation

x86/MCE: Cast rIP to respective width before printing

PATCH New Borislav Petkov 2 participants 2 messages Feb 10, 2018 – Feb 12, 2018 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/MCE: Cast rIP to respective width before printing

From: Borislav Petkov <[email protected]>

7b6061627eb8 ("x86: do not use print_symbol()") got rid of print_symbol() uses in favor of passing a %pS format specifier to printk() in order to print "symbolic direct pointers with offset".

We use this to print the RIP as part of the MCE record. And %pS requires a void *.

However, mce.ip is u64 and casting it to a void * on 32-bit rightfully warns:

arch/x86/kernel/cpu/mcheck/mce.c:237:21: warning: cast to pointer from integer \

	  of different size [-Wint-to-pointer-cast]
      pr_cont("{%pS}", (void *)m->ip);
                       ^

about the size mismatch.

So cast the RIP to the machine-specific unsigned long address width first.

Cc Sergey Senozhatsky <[email protected]>
Fixes 7b6061627eb8 ("x86: do not use print_symbol()")
---
 arch/x86/kernel/cpu/mcheck/mce.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -1
index 3a8e88a611eb..75f405ac085c 100644
@@ -234,7 +234,7 @@ static void __print_mce(struct mce *m)
 			m->cs, m->ip);
 
 		if (m->cs == __KERNEL_CS)
-			pr_cont("{%pS}", (void *)m->ip);
+			pr_cont("{%pS}", (void *)(unsigned long)m->ip);
 		pr_cont("\n");
 	}
 
Signature · 1 line
2.13.0
#1 lore raw

[tip:x86/urgent] x86/MCE: Fix build warning introduced by "x86: do not use print_symbol()"

x86/MCE: Fix build warning introduced by "x86: do not use print_symbol()"
Commit-ID:  c80c5ec1b2fa8d3675fc2a6807a64771ea156698
Gitweb:     https://git.kernel.org/tip/c80c5ec1b2fa8d3675fc2a6807a64771ea156698
Author:     Borislav Petkov <[email protected]>
AuthorDate: Sat, 10 Feb 2018 15:53:14 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 11 Feb 2018 11:37:39 +0100

x86/MCE: Fix build warning introduced by "x86: do not use print_symbol()"

The following commit:

7b6061627eb8 ("x86: do not use print_symbol()")

... introduced a new build warning on 32-bit x86:

arch/x86/kernel/cpu/mcheck/mce.c:237:21: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

      pr_cont("{%pS}", (void *)m->ip);
                       ^

Fix the type mismatch between the 'void *' expected by %pS and the mce->ip field which is u64 by casting to long.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tony Luck <[email protected]>
Fixes 7b6061627eb8 ("x86: do not use print_symbol()")
[ Cleaned up the changelog. ]
---
 arch/x86/kernel/cpu/mcheck/mce.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/mcheck/mce.c +1 -1
index 3a8e88a..75f405a 100644
@@ -234,7 +234,7 @@ static void __print_mce(struct mce *m)
 			m->cs, m->ip);
 
 		if (m->cs == __KERNEL_CS)
-			pr_cont("{%pS}", (void *)m->ip);
+			pr_cont("{%pS}", (void *)(unsigned long)m->ip);
 		pr_cont("\n");
 	}