Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case.
@ 2023-02-10 13:01 Sergey Kaplun via Tarantool-patches
  2023-02-15  1:43 ` Maxim Kokryashkin via Tarantool-patches
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2023-02-10 13:01 UTC (permalink / raw)
  To: Sergey Ostanevich, Maxim Kokryashkin; +Cc: tarantool-patches

From: Mike Pall <mike>

Reported by Alex Orlenko.

(cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)

The `pcall()` assembler preambule modifies `RC` (`x28`) (N args * 8)
during the check of the amount of the given arguments. So, this wrong
value using in the `fff_fallback` routine leading to a crash on the
error throwing, because the Lua stack is filled incorrect and can't be
unwound.

This patch adds the additional comparison before taking the fallback
branch and modifies `RC` only after this branch.

Sergey Kaplun:
* added the description and the test for the problem

Part of tarantool/tarantool#8069
---

PR: https://github.com/tarantool/tarantool/pull/8295
Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-762-arm64-pcall-no-arg
Issues:
* https://github.com/tarantool/tarantool/issues/8069
* https://github.com/LuaJIT/LuaJIT/issues/762

 src/vm_arm64.dasc                                 |  3 ++-
 test/tarantool-tests/lj-762-pcall-no-arg.test.lua | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 test/tarantool-tests/lj-762-pcall-no-arg.test.lua

diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index f517a808..e8b63d33 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -1168,9 +1168,10 @@ static void build_subroutines(BuildCtx *ctx)
   |//-- Base library: catch errors ----------------------------------------
   |
   |.ffunc pcall
+  |   cmp NARGS8:RC, #8
   |  ldrb TMP0w, GL->hookmask
-  |   subs NARGS8:RC, NARGS8:RC, #8
   |   blo ->fff_fallback
+  |   sub NARGS8:RC, NARGS8:RC, #8
   |    mov RB, BASE
   |    add BASE, BASE, #16
   |  ubfx TMP0w, TMP0w, #HOOK_ACTIVE_SHIFT, #1
diff --git a/test/tarantool-tests/lj-762-pcall-no-arg.test.lua b/test/tarantool-tests/lj-762-pcall-no-arg.test.lua
new file mode 100644
index 00000000..6cbfe707
--- /dev/null
+++ b/test/tarantool-tests/lj-762-pcall-no-arg.test.lua
@@ -0,0 +1,15 @@
+local tap = require('tap')
+
+-- Test file to check error raising for `pcall()` without
+-- arguments. Regardless that the problem is aarch64-specific,
+-- it is good to test it for all arches.
+-- See also https://github.com/LuaJIT/LuaJIT/issues/762.
+local test = tap.test('lj-762-pcall-no-arg')
+test:plan(2)
+
+local result, err = pcall(pcall)
+
+test:ok(not result, 'pcall() without args: bad status')
+test:like(err, 'value expected', 'pcall() without args: error message')
+
+os.exit(test:check() and 0 or 1)
-- 
2.34.1


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

* Re: [Tarantool-patches]  [PATCH luajit] ARM64: Fix pcall() error case.
  2023-02-10 13:01 [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case Sergey Kaplun via Tarantool-patches
@ 2023-02-15  1:43 ` Maxim Kokryashkin via Tarantool-patches
  2023-02-15  6:57   ` Sergey Kaplun via Tarantool-patches
  2023-02-28 12:43 ` Igor Munkin via Tarantool-patches
  2023-03-30 17:38 ` Igor Munkin via Tarantool-patches
  2 siblings, 1 reply; 6+ messages in thread
From: Maxim Kokryashkin via Tarantool-patches @ 2023-02-15  1:43 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 3019 bytes --]


Hi, Sergey!
LGTM, except for a few nits regarding the commit message.
 
> 
>>From: Mike Pall <mike>
>>
>>Reported by Alex Orlenko.
>>
>>(cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)
>>
>>The `pcall()` assembler preambule modifies `RC` (`x28`) (N args * 8)
>The «`RC` (`x28`) (N args * 8)» expression is hard to percieve. I suggest
>reformulating it in a way like «modifies `RC`, which is mapped to `x28`, so
>it has value ...». Feel free to ignore.
>>during the check of the amount of the given arguments. So, this wrong
>>value using in the `fff_fallback` routine leading to a crash on the
>Typo: s/using/being used/
>Typo: s/leading/leads
>Typo: s/on the/on
>>error throwing, because the Lua stack is filled incorrect and can't be
>Typo: s/is filled incorrect/is incorrectly filled/
>>unwound.
>>
>>This patch adds the additional comparison before taking the fallback
>>branch and modifies `RC` only after this branch.
>>
>>Sergey Kaplun:
>>* added the description and the test for the problem
>>
>>Part of tarantool/tarantool#8069
>>---
>>
>>PR:  https://github.com/tarantool/tarantool/pull/8295
>>Branch:  https://github.com/tarantool/luajit/tree/skaplun/lj-762-arm64-pcall-no-arg
>>Issues:
>>*  https://github.com/tarantool/tarantool/issues/8069
>>*  https://github.com/LuaJIT/LuaJIT/issues/762
>>
>> src/vm_arm64.dasc | 3 ++-
>> test/tarantool-tests/lj-762-pcall-no-arg.test.lua | 15 +++++++++++++++
>> 2 files changed, 17 insertions(+), 1 deletion(-)
>> create mode 100644 test/tarantool-tests/lj-762-pcall-no-arg.test.lua
>>
>>diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
>>index f517a808..e8b63d33 100644
>>--- a/src/vm_arm64.dasc
>>+++ b/src/vm_arm64.dasc
>>@@ -1168,9 +1168,10 @@ static void build_subroutines(BuildCtx *ctx)
>>   |//-- Base library: catch errors ----------------------------------------
>>   |
>>   |.ffunc pcall
>>+ | cmp NARGS8:RC, #8
>>   | ldrb TMP0w, GL->hookmask
>>- | subs NARGS8:RC, NARGS8:RC, #8
>>   | blo ->fff_fallback
>>+ | sub NARGS8:RC, NARGS8:RC, #8
>>   | mov RB, BASE
>>   | add BASE, BASE, #16
>>   | ubfx TMP0w, TMP0w, #HOOK_ACTIVE_SHIFT, #1
>>diff --git a/test/tarantool-tests/lj-762-pcall-no-arg.test.lua b/test/tarantool-tests/lj-762-pcall-no-arg.test.lua
>>new file mode 100644
>>index 00000000..6cbfe707
>>--- /dev/null
>>+++ b/test/tarantool-tests/lj-762-pcall-no-arg.test.lua
>>@@ -0,0 +1,15 @@
>>+local tap = require('tap')
>>+
>>+-- Test file to check error raising for `pcall()` without
>>+-- arguments. Regardless that the problem is aarch64-specific,
>>+-- it is good to test it for all arches.
>>+-- See also  https://github.com/LuaJIT/LuaJIT/issues/762 .
>>+local test = tap.test('lj-762-pcall-no-arg')
>>+test:plan(2)
>>+
>>+local result, err = pcall(pcall)
>>+
>>+test:ok(not result, 'pcall() without args: bad status')
>>+test:like(err, 'value expected', 'pcall() without args: error message')
>>+
>>+os.exit(test:check() and 0 or 1)
>>--
>>2.34.1
>--
>Best regards,
>Maxim Kokryashkin
> 

[-- Attachment #2: Type: text/html, Size: 4627 bytes --]

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

* Re: [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case.
  2023-02-15  1:43 ` Maxim Kokryashkin via Tarantool-patches
@ 2023-02-15  6:57   ` Sergey Kaplun via Tarantool-patches
  2023-02-15  8:05     ` Maxim Kokryashkin via Tarantool-patches
  0 siblings, 1 reply; 6+ messages in thread
From: Sergey Kaplun via Tarantool-patches @ 2023-02-15  6:57 UTC (permalink / raw)
  To: Maxim Kokryashkin; +Cc: tarantool-patches

Hi, Maxim!
Thanks for the review!

On 15.02.23, Maxim Kokryashkin wrote:
> 
> Hi, Sergey!
> LGTM, except for a few nits regarding the commit message.

Fixed your comments, the new commit message is the following:


| ARM64: Fix pcall() error case.
|
| Reported by Alex Orlenko.
|
| (cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)
|
| The `pcall()` assembler preambule modifies `RC`, which is mapped to
| `x28` (the value is N_args * 8), during the check of the amount of the
| given arguments. So, this wrong value being used in the `fff_fallback`
| routine leads to a crash on error throwing, because the Lua stack is
| incorrectly filled and can't be unwound.
|
| This patch adds the additional comparison before taking the fallback
| branch and modifies `RC` only after this branch.
|
| Sergey Kaplun:
| * added the description and the test for the problem
|
| Part of tarantool/tarantool#8069

Branch is force-pushed.

>  
> > 
> >>From: Mike Pall <mike>
> >>
> >>Reported by Alex Orlenko.
> >>
> >>(cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)
> >>
> >>The `pcall()` assembler preambule modifies `RC` (`x28`) (N args * 8)
> >The «`RC` (`x28`) (N args * 8)» expression is hard to percieve. I suggest
> >reformulating it in a way like «modifies `RC`, which is mapped to `x28`, so
> >it has value ...». Feel free to ignore.
> >>during the check of the amount of the given arguments. So, this wrong
> >>value using in the `fff_fallback` routine leading to a crash on the
> >Typo: s/using/being used/
> >Typo: s/leading/leads
> >Typo: s/on the/on
> >>error throwing, because the Lua stack is filled incorrect and can't be
> >Typo: s/is filled incorrect/is incorrectly filled/
> >>unwound.
> >>
> >>This patch adds the additional comparison before taking the fallback
> >>branch and modifies `RC` only after this branch.
> >>
> >>Sergey Kaplun:
> >>* added the description and the test for the problem
> >>
> >>Part of tarantool/tarantool#8069
> >>---

<snipped>

> >--
> >Best regards,
> >Maxim Kokryashkin
> > 

-- 
Best regards,
Sergey Kaplun

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

* Re: [Tarantool-patches]  [PATCH luajit] ARM64: Fix pcall() error case.
  2023-02-15  6:57   ` Sergey Kaplun via Tarantool-patches
@ 2023-02-15  8:05     ` Maxim Kokryashkin via Tarantool-patches
  0 siblings, 0 replies; 6+ messages in thread
From: Maxim Kokryashkin via Tarantool-patches @ 2023-02-15  8:05 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 2329 bytes --]


Hi, Sergey!
Thanks for the fixes!
LGTM
--
Best regards,
Maxim Kokryashkin
 
 
> 
>>Hi, Maxim!
>>Thanks for the review!
>>
>>On 15.02.23, Maxim Kokryashkin wrote:
>>>
>>> Hi, Sergey!
>>> LGTM, except for a few nits regarding the commit message.
>>
>>Fixed your comments, the new commit message is the following:
>>
>>
>>| ARM64: Fix pcall() error case.
>>|
>>| Reported by Alex Orlenko.
>>|
>>| (cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)
>>|
>>| The `pcall()` assembler preambule modifies `RC`, which is mapped to
>>| `x28` (the value is N_args * 8), during the check of the amount of the
>>| given arguments. So, this wrong value being used in the `fff_fallback`
>>| routine leads to a crash on error throwing, because the Lua stack is
>>| incorrectly filled and can't be unwound.
>>|
>>| This patch adds the additional comparison before taking the fallback
>>| branch and modifies `RC` only after this branch.
>>|
>>| Sergey Kaplun:
>>| * added the description and the test for the problem
>>|
>>| Part of tarantool/tarantool#8069
>>
>>Branch is force-pushed.
>>
>>>  
>>> > 
>>> >>From: Mike Pall <mike>
>>> >>
>>> >>Reported by Alex Orlenko.
>>> >>
>>> >>(cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)
>>> >>
>>> >>The `pcall()` assembler preambule modifies `RC` (`x28`) (N args * 8)
>>> >The «`RC` (`x28`) (N args * 8)» expression is hard to percieve. I suggest
>>> >reformulating it in a way like «modifies `RC`, which is mapped to `x28`, so
>>> >it has value ...». Feel free to ignore.
>>> >>during the check of the amount of the given arguments. So, this wrong
>>> >>value using in the `fff_fallback` routine leading to a crash on the
>>> >Typo: s/using/being used/
>>> >Typo: s/leading/leads
>>> >Typo: s/on the/on
>>> >>error throwing, because the Lua stack is filled incorrect and can't be
>>> >Typo: s/is filled incorrect/is incorrectly filled/
>>> >>unwound.
>>> >>
>>> >>This patch adds the additional comparison before taking the fallback
>>> >>branch and modifies `RC` only after this branch.
>>> >>
>>> >>Sergey Kaplun:
>>> >>* added the description and the test for the problem
>>> >>
>>> >>Part of tarantool/tarantool#8069
>>> >>---
>>
>><snipped>
>>
>>> >--
>>> >Best regards,
>>> >Maxim Kokryashkin
>>> > 
>>
>>--
>>Best regards,
>>Sergey Kaplun
> 

[-- Attachment #2: Type: text/html, Size: 3227 bytes --]

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

* Re: [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case.
  2023-02-10 13:01 [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case Sergey Kaplun via Tarantool-patches
  2023-02-15  1:43 ` Maxim Kokryashkin via Tarantool-patches
@ 2023-02-28 12:43 ` Igor Munkin via Tarantool-patches
  2023-03-30 17:38 ` Igor Munkin via Tarantool-patches
  2 siblings, 0 replies; 6+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-02-28 12:43 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

Thanks for the patch! LGTM considering the fixes for the comments left
by Max.

-- 
Best regards,
IM

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

* Re: [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case.
  2023-02-10 13:01 [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case Sergey Kaplun via Tarantool-patches
  2023-02-15  1:43 ` Maxim Kokryashkin via Tarantool-patches
  2023-02-28 12:43 ` Igor Munkin via Tarantool-patches
@ 2023-03-30 17:38 ` Igor Munkin via Tarantool-patches
  2 siblings, 0 replies; 6+ messages in thread
From: Igor Munkin via Tarantool-patches @ 2023-03-30 17:38 UTC (permalink / raw)
  To: Sergey Kaplun; +Cc: tarantool-patches

Sergey,

I've checked the patchset into all long-term branches in
tarantool/luajit and bumped a new version in master, 2.11 and 2.10.

On 10.02.23, Sergey Kaplun via Tarantool-patches wrote:
> From: Mike Pall <mike>
> 
> Reported by Alex Orlenko.
> 
> (cherry picked from commit b4b2dce9fc3ffaaaede39b36d06415311e2aa516)
> 
> The `pcall()` assembler preambule modifies `RC` (`x28`) (N args * 8)
> during the check of the amount of the given arguments. So, this wrong
> value using in the `fff_fallback` routine leading to a crash on the
> error throwing, because the Lua stack is filled incorrect and can't be
> unwound.
> 
> This patch adds the additional comparison before taking the fallback
> branch and modifies `RC` only after this branch.
> 
> Sergey Kaplun:
> * added the description and the test for the problem
> 
> Part of tarantool/tarantool#8069
> ---
> 
> PR: https://github.com/tarantool/tarantool/pull/8295
> Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-762-arm64-pcall-no-arg
> Issues:
> * https://github.com/tarantool/tarantool/issues/8069
> * https://github.com/LuaJIT/LuaJIT/issues/762
> 
>  src/vm_arm64.dasc                                 |  3 ++-
>  test/tarantool-tests/lj-762-pcall-no-arg.test.lua | 15 +++++++++++++++
>  2 files changed, 17 insertions(+), 1 deletion(-)
>  create mode 100644 test/tarantool-tests/lj-762-pcall-no-arg.test.lua
> 

<snipped>

> -- 
> 2.34.1
> 

-- 
Best regards,
IM

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

end of thread, other threads:[~2023-03-30 17:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-10 13:01 [Tarantool-patches] [PATCH luajit] ARM64: Fix pcall() error case Sergey Kaplun via Tarantool-patches
2023-02-15  1:43 ` Maxim Kokryashkin via Tarantool-patches
2023-02-15  6:57   ` Sergey Kaplun via Tarantool-patches
2023-02-15  8:05     ` Maxim Kokryashkin via Tarantool-patches
2023-02-28 12:43 ` Igor Munkin via Tarantool-patches
2023-03-30 17:38 ` Igor Munkin via Tarantool-patches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox