From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id B02A41A39289; Thu, 12 Mar 2026 12:35:59 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B02A41A39289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1773308159; bh=2qruQS5xYcD19sOwaOpr/i8CV9AL/fWHrlbI7q04spA=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=WMLEMoDLAm3yfARN4Pqh5ngmaliCMQgZ6rzCZXqeD4H048RYx3yCRMxZDXMNjyoH2 dDyvSG/stCNVKApGdidT03yageumpJtYLallJed804H8nJqCKlRnlX+9hH3/BMVPJh cycUaR2rl+GAGHv9tl8umxg+QqXaqE8R5q4NjJRk= Received: from send241.i.mail.ru (send241.i.mail.ru [95.163.59.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 490B91A392BD for ; Thu, 12 Mar 2026 12:35:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 490B91A392BD Received: by exim-smtp-64cdfc6c8d-fnnln with esmtpa (envelope-from ) id 1w0cST-00000000QbC-0clw; Thu, 12 Mar 2026 12:35:57 +0300 Date: Thu, 12 Mar 2026 12:36:51 +0300 To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD91ABAE9865AC7DC889514E9E256EAD50689274261A8C811C4182A05F5380850406561EF9E861BC7633DE06ABAFEAF6705846DD400A288EBAFFDAA45DD7DE27B5BA5E3C45D6879BF4E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AED985C8E545F588EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756627194F95AE6E7C2D0439F8F47E6981D199E2F6F2DB79082A37BE2197E7BB49B5389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0A3E989B1926288338941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C224937D475550F2A941776E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B5A354413552ABC1C3AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735D2D576BCF940C736C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A503207329F3E7F3FD5002B1117B3ED696EDF85D52B7BAFB9630E4A65F242F5898823CB91A9FED034534781492E4B8EEADC24E78AA85F86F6CBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE1918E10F71CB4DF9F96AB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659ECA8004C4420FB8C5C64374038793B90699EBE8DC252248D53C82E6F026C0442989D9D3CB010C855B8341EE9D5BE9A0AF71F73BDA430D69CDB591D67AE1D6933AA949E32927F04978CD93680B12512CF4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVdbVVJCphTR/50VZBWylZ0A= X-Mailru-Sender: 583F1D7ACE8F49BDD951BA70C165859E8014999D9F9905734756507F36A35F4BE0FC8365100D348EDC04C74680AE455DF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/3][v3] LJ_FR2: Fix stack checks in vararg calls. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! LGTM, after fixing my nits below. Please add the iterational diff for the fixes. On 12.03.26, Sergey Bronnikov wrote: > From: Mike Pall > > Thanks to Peter Cawley. > > (cherry picked from commit d1a2fef8a8f53b0055ee041f7f63d83a27444ffa) > > Stack overflow can cause a segmentation fault in a vararg > function on ARM64 and MIPS64 in LJ_FR2 mode. This happens > because the stack check in BC_IFUNCV is off by one on these > platforms without the patch. The original stack check > for ARM64 and MIPS64 was incorrect: > > | RA == BASE + (RD=NARGS)*8 + framesize * 8 >= maxstack > > while the stack check on x86_64 is correct and therefore is > not affected by the problem: > > | RA == BASE + (RD=NARGS+1)*8 + framesize * 8 +8 > maxstack Typo: s/ +8/ + 8/ > > The patch partially fixes the aforementioned issue by bumping > LJ_STACK_EXTRA by 1 to give a space to the entire frame link for a > vararg function as the __newindex metamethod. > > A fixup for a number of required slots in `call_init()` was added > for consistency with non-GC64 flavor. The check is too strict, so > this can't lead to any crash. > > This patch also corrects the number of redzone slots in > luajit-gdb.py to match the updated LJ_STACK_EXTRA and adds the test luajit_lldb.py should be updated as well. > that will help to avoid gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue tracker. > a regression in the future, see details in [1]. Just mention details here like the following: | The patch partially fixes the aforementioned issue by bumping | LJ_STACK_EXTRA by 1 to give a space to the entire frame link for a | vararg function as the __newindex metamethod. | | A fixup for a number of required slots in `call_init()` was added for | consistency with the non-GC64 flavor. The check is too strict (if | comparing the corresponding checks in the VM BC_IFUNCV), so this can't | lead to any crash. To avoid possible regression in the future the | corresponding test is added. | | This patch also corrects the number of redzone slots in luajit-gdb.py | and luajit_lldb.py to match the updated LJ_STACK_EXTRA. > > Sergey Bronnikov: > * added the description and the test for the problem > > Part of tarantool/tarantool#12134 > > 1. https://github.com/LuaJIT/LuaJIT/issues/1402 Please, don't mention the issue during backporting, to avoid messing the issue tracker. > --- > src/lj_def.h | 2 +- > src/lj_dispatch.c | 2 +- > src/luajit-gdb.py | 2 +- > src/vm_arm64.dasc | 1 + > src/vm_mips64.dasc | 1 + > .../gh-1402-call_init-regression.test.lua | 36 +++++++++++++ gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue tracker. > ...048-fix-stack-checks-vararg-calls.test.lua | 53 +++++++++++++++++++ > 7 files changed, 94 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/gh-1402-call_init-regression.test.lua > create mode 100644 test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > > diff --git a/src/lj_def.h b/src/lj_def.h > index a5bca6b0..7e4f251e 100644 > --- a/src/lj_def.h > +++ b/src/lj_def.h > diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c > index a44a5adf..431cb3c2 100644 > --- a/src/lj_dispatch.c > +++ b/src/lj_dispatch.c > diff --git a/src/luajit-gdb.py b/src/luajit-gdb.py > index 0ae2a6e0..dab07b35 100644 > --- a/src/luajit-gdb.py > +++ b/src/luajit-gdb.py > diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc > index 6600e226..5ef37243 100644 > --- a/src/vm_arm64.dasc > +++ b/src/vm_arm64.dasc > diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc > index da187a7a..6c2975b4 100644 > --- a/src/vm_mips64.dasc > +++ b/src/vm_mips64.dasc > diff --git a/test/tarantool-tests/gh-1402-call_init-regression.test.lua b/test/tarantool-tests/gh-1402-call_init-regression.test.lua Please, avoid _ in the file names, lets name it like: lj-1402-vararg-stkov-check-gc64.test.lua Same for the name of the test. > new file mode 100644 > index 00000000..b20f9e39 > --- /dev/null > +++ b/test/tarantool-tests/gh-1402-call_init-regression.test.lua > @@ -0,0 +1,36 @@ > +local tap = require('tap') > + > +-- A test file to demonstrate a probably quite strict stack > +-- check for vararg functions in call_init. This is not about quite strict stack check. We need this to test the behaviour of the LuaJIT while recording the vararg function. Let's rephrase like the following: | -- The test file to verify correctness of stack size check during | -- recording of vararg functions. The test file to verify correctness of stack size check during recording of vararg functions. > +-- See also https://github.com/LuaJIT/LuaJIT/issues/1402 > +local test = tap.test('gh-1402-call_init-regression.test.lua'):skipcond({ gh- prefix is for the Tarantool issue tracker, use lj- for LuaJIT issue tracker. > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(1) > + > +local function vararg(...) -- luacheck: no unused Let's use this comment before the vararg declaration. It helps with the _ below as well. > + -- None. > +end > + > +-- Make compilation aggressive. Excess comment. It's quite general approach in our tests. > +jit.opt.start("hotloop=1") Typo: s/"/'/g > + Please add the following comment: | -- This function utilizes the exact amount of stack slots | -- to cause the stack reallocation during `call_init()` in the | -- GC64 mode. > +local function caller() > + -- luacheck: push no unused Lets drop this luacheck suppression, see the comment above. > + local _, _, _, _, _, _, _, _, _, _ > + local _, _, _, _, _, _, _, _, _, _ > + local _, _, _, _, _, _, _, _, _, _ > + -- luacheck: pop > + local n = 1 > + while n < 3 do > + vararg() > + n = n + 1 > + end > +end > + > +pcall(coroutine.wrap(caller)) The pcall is excess lets do it without it: | coroutine.wrap(caller)() > + > +test:ok(true, 'no assertion for vararg functions in call_init') Just mention 'no assertion failure' (this assertion isn't in the `call_init()`, but during recording in `rec_check_slots()`). > + > +test:done(true) > diff --git a/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > new file mode 100644 > index 00000000..3a8ad63d > --- /dev/null > +++ b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > -- > 2.43.0 > -- Best regards, Sergey Kaplun