All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: determine whether the fault address is canonical
@ 2019-10-04 13:45 Changbin Du
  2019-10-04 14:39 ` Dave Hansen
  2019-10-04 14:59 ` Andy Lutomirski
  0 siblings, 2 replies; 9+ messages in thread
From: Changbin Du @ 2019-10-04 13:45 UTC (permalink / raw)
  To: Dave Hansen, Andy Lutomirski; +Cc: x86, linux-kernel, Changbin Du

We know the answer, so don't ask the user.

Signed-off-by: Changbin Du <changbin.du@gmail.com>
---
 arch/x86/mm/extable.c     |  5 ++++-
 arch/x86/mm/mm_internal.h | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index 4d75bc656f97..5196e586756f 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -8,6 +8,8 @@
 #include <asm/traps.h>
 #include <asm/kdebug.h>
 
+#include "mm_internal.h"
+
 typedef bool (*ex_handler_t)(const struct exception_table_entry *,
 			    struct pt_regs *, int, unsigned long,
 			    unsigned long);
@@ -123,7 +125,8 @@ __visible bool ex_handler_uaccess(const struct exception_table_entry *fixup,
 				  unsigned long error_code,
 				  unsigned long fault_addr)
 {
-	WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. Non-canonical address?");
+	WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault at %s address in user access.",
+		  is_canonical_addr(fault_addr) ? "canonical" : "non-canonical");
 	regs->ip = ex_fixup_addr(fixup);
 	return true;
 }
diff --git a/arch/x86/mm/mm_internal.h b/arch/x86/mm/mm_internal.h
index eeae142062ed..4c8a0fdd1c64 100644
--- a/arch/x86/mm/mm_internal.h
+++ b/arch/x86/mm/mm_internal.h
@@ -2,6 +2,17 @@
 #ifndef __X86_MM_INTERNAL_H
 #define __X86_MM_INTERNAL_H
 
+static inline bool is_canonical_addr(u64 addr)
+{
+#ifdef CONFIG_X86_64
+	int shift = 64 - boot_cpu_data.x86_phys_bits;
+
+	return ((int64_t)addr << shift >> shift) == addr;
+#else
+	return true;
+#endif
+}
+
 void *alloc_low_pages(unsigned int num);
 static inline void *alloc_low_page(void)
 {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-10-07 15:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 13:45 [PATCH] x86/mm: determine whether the fault address is canonical Changbin Du
2019-10-04 14:39 ` Dave Hansen
2019-10-04 15:31   ` Sean Christopherson
2019-10-07 14:32     ` Ingo Molnar
2019-10-07 14:44       ` Ingo Molnar
2019-10-07 15:13         ` Sean Christopherson
2019-10-04 14:59 ` Andy Lutomirski
2019-10-04 15:14   ` Dave Hansen
2019-10-06  2:29     ` Changbin Du

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.