From: Haibo Li <haibo.li@mediatek.com>
To: <amergnat@baylibre.com>
Cc: <alexander.sverdlin@nokia.com>,
<angelogioacchino.delregno@collabora.com>,
<haibo.li@mediatek.com>, <linus.walleij@linaro.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
<linux-mediatek@lists.infradead.org>, <linux@armlinux.org.uk>,
<matthias.bgg@gmail.com>, <rmk+kernel@armlinux.org.uk>,
<xiaoming.yu@mediatek.com>
Subject: Re: [PATCH] ARM:unwind:fix unwind abort for uleb128 case
Date: Thu, 13 Apr 2023 15:19:25 +0800 [thread overview]
Message-ID: <20230413071925.42858-1-haibo.li@mediatek.com> (raw)
In-Reply-To: <7d567846-a000-1bd2-6e43-7ca170366d76@baylibre.com>
> On 07/04/2023 05:33, Haibo Li wrote:
> > When unwind instruction is 0xb2,the subsequent instructions are
> > uleb128 bytes.
> > For now,it uses only the first uleb128 byte in code.
> >
> > For vsp increments of 0x204~0x400,use one uleb128 byte like below:
> > 0xc06a00e4 <unwind_test_work>: 0x80b27fac
> > Compact model index: 0
> > 0xb2 0x7f vsp = vsp + 1024
> > 0xac pop {r4, r5, r6, r7, r8, r14}
> >
> > For vsp increments larger than 0x400,use two uleb128 bytes like below:
> > 0xc06a00e4 <unwind_test_work>: @0xc0cc9e0c
> > Compact model index: 1
> > 0xb2 0x81 0x01 vsp = vsp + 1032
> > 0xac pop {r4, r5, r6, r7, r8, r14}
> > The unwind works well since the decoded uleb128 byte is also 0x81.
> >
> > For vsp increments larger than 0x600,use two uleb128 bytes like below:
> > 0xc06a00e4 <unwind_test_work>: @0xc0cc9e0c
> > Compact model index: 1
> > 0xb2 0x81 0x02 vsp = vsp + 1544
> > 0xac pop {r4, r5, r6, r7, r8, r14}
> > In this case,the decoded uleb128 result is 0x101(vsp=0x204+(0x101<<2)).
> > While the uleb128 used in code is 0x81(vsp=0x204+(0x81<<2)).
> > The unwind aborts at this frame since it gets incorrect vsp.
> >
> > To fix this,add uleb128 decode to cover all the above case.
> >
> > Signed-off-by: Haibo Li <haibo.li@mediatek.com>
> > ---
> > arch/arm/kernel/unwind.c | 19 +++++++++++++++++--
> > 1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index
> > 53be7ea6181b..e5796a5acba1 100644
> > --- a/arch/arm/kernel/unwind.c
> > +++ b/arch/arm/kernel/unwind.c
> > @@ -20,7 +20,6 @@
> > #warning Change compiler or disable ARM_UNWIND option.
> > #endif
> > #endif /* __CHECKER__ */
> > -
>
> Why delete this line ?
It may be changed by mistake.I will restore it.
>
> > #include <linux/kernel.h>
> > #include <linux/init.h>
> > #include <linux/export.h>
> > @@ -308,6 +307,22 @@ static int
> unwind_exec_pop_subset_r0_to_r3(struct unwind_ctrl_block *ctrl,
> > return URC_OK;
> > }
> >
> > +static unsigned long unwind_decode_uleb128(struct unwind_ctrl_block
> > +*ctrl) {
> > + unsigned long result = 0;
> > + unsigned long insn;
> > + unsigned long bytes = 0;
>
> Alphabetical order please.
get it.
>
> > +
> > + do {
> > + insn = unwind_get_byte(ctrl);
> > + result |= (insn & 0x7f) << (bytes * 7);
> > + bytes++;
> > + if (bytes == sizeof(result))
> > + break;
> > + } while (!!(insn & 0x80));
> > +
> > + return result;
> > +}
>
> Please add a blank line for readability.
OK.
>
> > /*
> > * Execute the current unwind instruction.
> > */
> > @@ -361,7 +376,7 @@ static int unwind_exec_insn(struct
> unwind_ctrl_block *ctrl)
> > if (ret)
> > goto error;
> > } else if (insn == 0xb2) {
> > - unsigned long uleb128 = unwind_get_byte(ctrl);
> > + unsigned long uleb128 = unwind_decode_uleb128(ctrl);
> >
> > ctrl->vrs[SP] += 0x204 + (uleb128 << 2);
> > } else {
>
> Great job! I'm aligned with Linus Walleij's feedback about the need of few
> comments to explain the decode loop, even if your code is clear, light and
> robust.
Thanks for reviewing the patch.I will add the comment in later patch.
>
prev parent reply other threads:[~2023-04-13 7:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 3:33 Haibo Li
2023-04-11 21:31 ` Linus Walleij
2023-04-12 2:44 ` Haibo Li
2023-04-12 12:25 ` Linus Walleij
2023-04-12 12:43 ` Alexandre Mergnat
2023-04-13 7:19 ` Haibo Li [this message]
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=20230413071925.42858-1-haibo.li@mediatek.com \
--to=haibo.li@mediatek.com \
--cc=alexander.sverdlin@nokia.com \
--cc=amergnat@baylibre.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.bgg@gmail.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=xiaoming.yu@mediatek.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®