From: Steffen Rumler <steffen.rumler.ext@nsn.com>
To: ext Benjamin Herrenschmidt <benh@kernel.crashing.org>, paulus@samba.org
Cc: Wrobel Heinz-R39252 <r39252@freescale.com>,
Michael Ellerman <michael@ellerman.id.au>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: [PATCH] kernel panic during kernel module load (powerpc specific part)
Date: Wed, 06 Jun 2012 16:37:17 +0200 [thread overview]
Message-ID: <4FCF6B1D.50009@nsn.com> (raw)
In-Reply-To: <1338982323.7150.165.camel@pasglop>
Hi,
The patch below is intended to fix the following problem.
According to the PowerPC EABI specification, the GPR r11 is assigned
the dedicated function to point to the previous stack frame.
In the powerpc-specific kernel module loader, do_plt_call()
(in arch/powerpc/kernel/module_32.c), the GPR r11 is also used
to generate trampoline code.
This combination crashes the kernel, in the following case:
+ The compiler has been generated the prologue and epilogue,
which is part of the .text section.
+ The compiler has been generated the code for the module init entry point,
part of the .init.text section (in the case it is marked with __init).
+ By returning from the module init entry point, the epilogue is called by doing
a branch instruction.
+ If the epilogue is too far away, a relative branch instruction cannot be applied.
Instead trampoline code is generated in do_plt_call(), in order to jump via register.
Unfortunately the code generated by do_plt_call() destroys the content of GPR r11.
+ Because GPR r11 does not more keep the right stack frame pointer,
the kernel crashes right after the epilogue.
The fix just uses GPR r12 instead of GPR r11 for generating the trampoline code.
According to the statements from Freescale, this is also save from EABI perspective.
I've tested the fix for kernel 2.6.33 on MPC8541.
Signed-off-by: Steffen Rumler <steffen.rumler.ext@nsn.com>
---
--- orig/arch/powerpc/kernel/module_32.c 2012-06-06 16:04:28.956446788 +0200
+++ new/arch/powerpc/kernel/module_32.c 2012-06-06 16:04:17.746290683 +0200
@@ -187,8 +187,8 @@
static inline int entry_matches(struct ppc_plt_entry *entry, Elf32_Addr val)
{
- if (entry->jump[0] == 0x3d600000 + ((val + 0x8000) >> 16)
- && entry->jump[1] == 0x396b0000 + (val & 0xffff))
+ if (entry->jump[0] == 0x3d800000 + ((val + 0x8000) >> 16)
+ && entry->jump[1] == 0x398c0000 + (val & 0xffff))
return 1;
return 0;
}
@@ -215,10 +215,9 @@
entry++;
}
- /* Stolen from Paul Mackerras as well... */
- entry->jump[0] = 0x3d600000+((val+0x8000)>>16); /* lis r11,sym@ha */
- entry->jump[1] = 0x396b0000 + (val&0xffff); /* addi r11,r11,sym@l*/
- entry->jump[2] = 0x7d6903a6; /* mtctr r11 */
+ entry->jump[0] = 0x3d800000+((val+0x8000)>>16); /* lis r12,sym@ha */
+ entry->jump[1] = 0x398c0000 + (val&0xffff); /* addi r12,r12,sym@l*/
+ entry->jump[2] = 0x7d8903a6; /* mtctr r12 */
entry->jump[3] = 0x4e800420; /* bctr */
DEBUGP("Initialized plt for 0x%x at %p\n", val, entry);
next prev parent reply other threads:[~2012-06-06 14:37 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-30 14:33 kernel panic during kernel module load (powerpc specific part) Steffen Rumler
2012-05-30 23:24 ` Michael Ellerman
2012-05-31 7:04 ` Wrobel Heinz-R39252
2012-05-31 11:04 ` Gabriel Paubert
2012-06-01 9:18 ` Benjamin Herrenschmidt
2012-06-01 11:33 ` Wrobel Heinz-R39252
2012-06-04 7:43 ` Steffen Rumler
2012-06-04 10:53 ` Paul Mackerras
2012-06-04 11:03 ` Gabriel Paubert
2012-06-04 22:00 ` Benjamin Herrenschmidt
2012-06-05 10:44 ` Gabriel Paubert
2012-06-05 22:47 ` Benjamin Herrenschmidt
2012-06-05 11:32 ` Gabriel Paubert
2012-06-05 22:14 ` Benjamin Herrenschmidt
2012-06-06 7:36 ` Steffen Rumler
2012-06-06 11:32 ` Benjamin Herrenschmidt
2012-06-06 14:37 ` Steffen Rumler [this message]
2012-06-21 15:27 ` [PATCH] " roger blofeld
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=4FCF6B1D.50009@nsn.com \
--to=steffen.rumler.ext@nsn.com \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=michael@ellerman.id.au \
--cc=paulus@samba.org \
--cc=r39252@freescale.com \
/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 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.