linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: alignment faults in 3.6
Date: Fri, 5 Oct 2012 11:51:33 +0100	[thread overview]
Message-ID: <20121005105133.GP4625@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20121005072914.GE4625@n2100.arm.linux.org.uk>

On Fri, Oct 05, 2012 at 08:29:14AM +0100, Russell King - ARM Linux wrote:
> On Thu, Oct 04, 2012 at 06:10:26PM -0500, Rob Herring wrote:
> > I would think the scheduling while atomic messages are harmless in this
> > case. However, in addition to spewing out BUG messages this commit also
> > seems to eventually cause a kernel panic in __napi_complete. That panic
> > seems to go away if I put barrier() between the 2 accesses above which
> > eliminates the alignment faults. I haven't figured that part out yet.
> > 
> > There's at least a couple of problems here:
> > 
> > This seems like an overly aggressive compiler optimization considering
> > unaligned accesses are not supported by ldm/stm.
> > 
> > The alignment fault handler should handle kernel address faults atomically.
> 
> This is bad news.  do_alignment() can be called in almost any kernel
> context, and it must work.  die() and oops dumps - specifically dump_mem()
> and dump_instr() will suffer from exactly the same problem.

Okay, this should fix the issue...  I've only compile tested it so far.
Rob, as you have a way to trigger this easily, can you give this patch
a go and let me know if it solves your problem?  Thanks.

 arch/arm/kernel/traps.c |   34 +++++++---------------------------
 arch/arm/mm/alignment.c |   11 ++++-------
 2 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index b0179b8..62f429e 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -89,17 +89,8 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom,
 		     unsigned long top)
 {
 	unsigned long first;
-	mm_segment_t fs;
 	int i;
 
-	/*
-	 * We need to switch to kernel mode so that we can use __get_user
-	 * to safely read from kernel space.  Note that we now dump the
-	 * code first, just in case the backtrace kills us.
-	 */
-	fs = get_fs();
-	set_fs(KERNEL_DS);
-
 	printk("%s%s(0x%08lx to 0x%08lx)\n", lvl, str, bottom, top);
 
 	for (first = bottom & ~31; first < top; first += 32) {
@@ -112,7 +103,7 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom,
 		for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
 			if (p >= bottom && p < top) {
 				unsigned long val;
-				if (__get_user(val, (unsigned long *)p) == 0)
+				if (probe_kernel_address(p, val) == 0)
 					sprintf(str + i * 9, " %08lx", val);
 				else
 					sprintf(str + i * 9, " ????????");
@@ -120,8 +111,6 @@ static void dump_mem(const char *lvl, const char *str, unsigned long bottom,
 		}
 		printk("%s%04lx:%s\n", lvl, first & 0xffff, str);
 	}
-
-	set_fs(fs);
 }
 
 static void dump_instr(const char *lvl, struct pt_regs *regs)
@@ -129,25 +118,18 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 	unsigned long addr = instruction_pointer(regs);
 	const int thumb = thumb_mode(regs);
 	const int width = thumb ? 4 : 8;
-	mm_segment_t fs;
 	char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
 	int i;
 
-	/*
-	 * We need to switch to kernel mode so that we can use __get_user
-	 * to safely read from kernel space.  Note that we now dump the
-	 * code first, just in case the backtrace kills us.
-	 */
-	fs = get_fs();
-	set_fs(KERNEL_DS);
-
 	for (i = -4; i < 1 + !!thumb; i++) {
 		unsigned int val, bad;
 
-		if (thumb)
-			bad = __get_user(val, &((u16 *)addr)[i]);
-		else
-			bad = __get_user(val, &((u32 *)addr)[i]);
+		if (thumb) {
+			u16 instr;
+			bad = probe_kernel_address(addr, instr);
+			val = instr;
+		} else
+			bad = probe_kernel_address(addr, val);
 
 		if (!bad)
 			p += sprintf(p, i == 0 ? "(%0*x) " : "%0*x ",
@@ -158,8 +140,6 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
 		}
 	}
 	printk("%sCode: %s\n", lvl, str);
-
-	set_fs(fs);
 }
 
 #ifdef CONFIG_ARM_UNWIND
diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
index b9f60eb..f8f14fc 100644
--- a/arch/arm/mm/alignment.c
+++ b/arch/arm/mm/alignment.c
@@ -749,7 +749,6 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	unsigned long instr = 0, instrptr;
 	int (*handler)(unsigned long addr, unsigned long instr, struct pt_regs *regs);
 	unsigned int type;
-	mm_segment_t fs;
 	unsigned int fault;
 	u16 tinstr = 0;
 	int isize = 4;
@@ -760,16 +759,15 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 
 	instrptr = instruction_pointer(regs);
 
-	fs = get_fs();
-	set_fs(KERNEL_DS);
 	if (thumb_mode(regs)) {
-		fault = __get_user(tinstr, (u16 *)(instrptr & ~1));
+		unsigned long ptr = instrptr;
+		fault = probe_kernel_address(ptr, tinstr);
 		if (!fault) {
 			if (cpu_architecture() >= CPU_ARCH_ARMv7 &&
 			    IS_T32(tinstr)) {
 				/* Thumb-2 32-bit */
 				u16 tinst2 = 0;
-				fault = __get_user(tinst2, (u16 *)(instrptr+2));
+				fault = probe_kernel_address(ptr + 2, tinst2);
 				instr = (tinstr << 16) | tinst2;
 				thumb2_32b = 1;
 			} else {
@@ -778,8 +776,7 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 			}
 		}
 	} else
-		fault = __get_user(instr, (u32 *)instrptr);
-	set_fs(fs);
+		fault = probe_kernel_address(instrptr, instr);
 
 	if (fault) {
 		type = TYPE_FAULT;

  reply	other threads:[~2012-10-05 10:51 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 23:10 alignment faults in 3.6 Rob Herring
2012-10-05  0:58 ` Michael Hope
2012-10-05  1:26   ` Mans Rullgard
2012-10-05  1:56     ` Rob Herring
2012-10-05  2:25       ` Mans Rullgard
2012-10-05  3:04         ` Rob Herring
2012-10-05  5:37           ` Khem Raj
2012-10-05  7:12         ` Russell King - ARM Linux
2012-10-05  8:20           ` Mans Rullgard
2012-10-05  8:24             ` Russell King - ARM Linux
2012-10-05  8:33               ` Mans Rullgard
2012-10-05  8:33                 ` Russell King - ARM Linux
2012-10-05  8:37                   ` Mans Rullgard
2012-10-05  8:50                     ` Russell King - ARM Linux
2012-10-05 13:49                     ` Mikael Pettersson
2012-10-05 12:24               ` Rob Herring
2012-10-05 13:51                 ` Mikael Pettersson
2012-10-05 16:01                   ` Rob Herring
2012-10-05 22:37                     ` Mans Rullgard
2012-10-05 22:42                       ` Russell King - ARM Linux
2012-10-06  1:41                         ` Nicolas Pitre
2012-10-06 16:04                         ` Mans Rullgard
2012-10-06 16:19                           ` Nicolas Pitre
2012-10-06 16:31                           ` Russell King - ARM Linux
2012-10-06 10:58                     ` Mikael Pettersson
2012-10-09 14:05                     ` Scott Bambrough
2012-10-09 14:18                       ` Mans Rullgard
2012-10-05 14:05                 ` Russell King - ARM Linux
2012-10-05 14:33                   ` Rob Herring
2012-10-11  0:59                     ` Jon Masters
2012-10-11  2:27                       ` Måns Rullgård
2012-10-11  2:34                         ` Jon Masters
2012-10-11  8:21                         ` David Laight
2012-10-11  8:53                           ` Russell King - ARM Linux
2012-10-11  9:45                           ` Måns Rullgård
2012-10-11 10:00                             ` Eric Dumazet
2012-10-11 10:20                               ` Måns Rullgård
2012-10-11 10:22                               ` Eric Dumazet
2012-10-11 10:32                                 ` Russell King - ARM Linux
2012-10-11 10:49                                   ` Eric Dumazet
2012-10-11 10:56                                     ` Maxime Bizon
2012-10-11 11:28                                       ` Eric Dumazet
2012-10-11 11:47                                         ` Maxime Bizon
2012-10-11 11:54                                           ` Eric Dumazet
2012-10-11 12:00                                             ` Eric Dumazet
2012-10-11 12:51                                             ` Maxime Bizon
2012-10-11 12:59                                               ` Eric Dumazet
2012-10-11 12:28                                     ` Arnd Bergmann
2012-10-11 12:40                                       ` Eric Dumazet
2012-10-11 13:20                                         ` Rob Herring
2012-10-11 13:32                                           ` Måns Rullgård
2012-10-11 13:35                                           ` Arnd Bergmann
2012-10-11 13:47                                           ` Eric Dumazet
2012-10-11 15:23                                             ` Rob Herring
2012-10-11 15:39                                               ` David Laight
2012-10-11 16:18                                                 ` Måns Rullgård
2012-10-12  8:11                                                   ` Arnd Bergmann
2012-10-12  9:03                                                     ` Russell King - ARM Linux
2012-10-12 10:04                                                       ` Eric Dumazet
2012-10-12 12:24                                                         ` Russell King - ARM Linux
2012-10-12 11:00                                                       ` Måns Rullgård
2012-10-12 11:07                                                         ` Russell King - ARM Linux
2012-10-12 11:18                                                           ` Måns Rullgård
2012-10-12 11:44                                                             ` Russell King - ARM Linux
2012-10-12 12:08                                                               ` Eric Dumazet
2012-10-12 14:22                                                                 ` Benjamin LaHaise
2012-10-12 14:36                                                                   ` David Laight
2012-10-12 14:48                                                                   ` Eric Dumazet
2012-10-12 15:00                                                                     ` Benjamin LaHaise
2012-10-12 15:04                                                                     ` Ben Hutchings
2012-10-12 15:47                                                                       ` David Laight
2012-10-12 16:13                                                                         ` Ben Hutchings
2012-10-12 12:16                                                               ` Måns Rullgård
2012-10-12 11:19                                                           ` Russell King - ARM Linux
2012-10-11 16:15                                               ` Eric Dumazet
2012-10-11 16:59                                   ` Catalin Marinas
2012-10-11 10:16                             ` David Laight
2012-10-11 10:46                               ` Måns Rullgård
2012-10-05 16:08   ` Rob Herring
2012-10-05  7:29 ` Russell King - ARM Linux
2012-10-05 10:51   ` Russell King - ARM Linux [this message]
2012-10-23 16:30     ` Jon Masters
2012-10-23 16:58       ` Russell King - ARM Linux
2012-10-23 17:15         ` Jon Masters
2012-10-23 19:14         ` Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121005105133.GP4625@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).