* [PATCH v3 1/2] MIPS: fix sibling call handling in get_frame_info
@ 2013-05-12 16:04 Tony Wu
2013-05-17 23:56 ` Ralf Baechle
0 siblings, 1 reply; 2+ messages in thread
From: Tony Wu @ 2013-05-12 16:04 UTC (permalink / raw)
To: ralf, linux-mips
Given a function, get_frame_info() analyzes its instructions
to figure out frame size and return address. get_frame_info()
works as follows:
1. analyze up to 128 instructions if the function size is unknown
2. search for 'addiu/daddiu sp,sp,-immed' for frame size
3. search for 'sw ra,offset(sp)' for return address
4. end search when it sees jr/jal/jalr
This leads to an issue when the given function is a sibling
call, example shown as follows.
801ca110 <schedule>:
801ca110: 8f820000 lw v0,0(gp)
801ca114: 8c420000 lw v0,0(v0)
801ca118: 080726f0 j 801c9bc0 <__schedule>
801ca11c: 00000000 nop
801ca120 <io_schedule>:
801ca120: 27bdffe8 addiu sp,sp,-24
801ca124: 3c028022 lui v0,0x8022
801ca128: afbf0014 sw ra,20(sp)
In this case, get_frame_info() cannot properly detect schedule's
frame info, and eventually returns io_schedule's instead.
This patch adds 'j' to the end search condition to workaround
sibling call cases.
Signed-off-by: Tony Wu <tung7970@gmail.com>
---
arch/mips/kernel/process.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index cfc742d..d66b04d 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -231,8 +231,10 @@ static inline int is_ra_save_ins(union mips_instruction *ip)
ip->i_format.rt == 31;
}
-static inline int is_jal_jalr_jr_ins(union mips_instruction *ip)
+static inline int is_jump_ins(union mips_instruction *ip)
{
+ if (ip->j_format.opcode == j_op)
+ return 1;
if (ip->j_format.opcode == jal_op)
return 1;
if (ip->r_format.opcode != spec_op)
@@ -268,7 +270,7 @@ static int get_frame_info(struct mips_frame_info *info)
for (i = 0; i < max_insns; i++, ip++) {
- if (is_jal_jalr_jr_ins(ip))
+ if (is_jump_ins(ip))
break;
if (!info->frame_size) {
if (is_sp_move_ins(ip))
--
1.7.10.2 (Apple Git-33)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3 1/2] MIPS: fix sibling call handling in get_frame_info
2013-05-12 16:04 [PATCH v3 1/2] MIPS: fix sibling call handling in get_frame_info Tony Wu
@ 2013-05-17 23:56 ` Ralf Baechle
0 siblings, 0 replies; 2+ messages in thread
From: Ralf Baechle @ 2013-05-17 23:56 UTC (permalink / raw)
To: Tony Wu; +Cc: linux-mips
On Mon, May 13, 2013 at 12:04:29AM +0800, Tony Wu wrote:
> Date: Mon, 13 May 2013 00:04:29 +0800
> From: Tony Wu <tung7970@gmail.com>
> To: ralf@linux-mips.org, linux-mips@linux-mips.org
> Subject: [PATCH v3 1/2] MIPS: fix sibling call handling in get_frame_info
> Content-Type: text/plain; charset=us-ascii
I've applied both your patches but both did apply with fuzz so you may
want to verify everything is working fine.
Thanks,
Ralf
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-17 23:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-12 16:04 [PATCH v3 1/2] MIPS: fix sibling call handling in get_frame_info Tony Wu
2013-05-17 23:56 ` Ralf Baechle
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.