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 35B7BA4E12F; Wed, 13 Mar 2024 12:41:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 35B7BA4E12F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1710322866; bh=2+FnPWkm2EY7PpkcAJFC1yHGHY0NH6u7rDHo+QwYXN0=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=THKAXoB96usoCogCeAmgWonptd3AoIXBp9qTZTkC+faWypc99u5pEUcG71AnjDgQI E7X6s+zkoQng2RM+LqAV5GlWBVkw6uASROxpvF7Yqo2qFuMTb3sXcVYrZhxUpqsB7a jtaYeAtD7SxbEw/9K454arTrO5f8itSZdBi1+VL8= Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [95.163.41.66]) (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 B8992A4E131 for ; Wed, 13 Mar 2024 12:41:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B8992A4E131 Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1rkL6d-00000004E8o-2fMP; Wed, 13 Mar 2024 12:41:04 +0300 Date: Wed, 13 Mar 2024 12:37:03 +0300 To: Sergey Bronnikov Message-ID: References: <20240312052627.21222-1-skaplun@tarantool.org> 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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD987C0EE6E7F0A597D21AFE2E000C69B1FB60C465D22E5E337182A05F538085040D2FC8A7394301BAED4FF92D56319F197FF452F624717E06275BDB7675FEE4C11906DE0852CB23DE4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78981306C6E927004EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E1B356F17606A5B08638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D87CC55C0FEB87971505510B10297B49D82C1EB50FD3D9B2CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CDA7BFA4571439BB2BA3038C0950A5D36C8A9BA7A39EFB766D91E3A1F190DE8FDBA3038C0950A5D36D5E8D9A59859A8B6D827CA74CCEABFF33AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FCF1175FABE1C0F9B6E2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BC6A536F79815AD9275ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A54CC14F3AB19E771D5002B1117B3ED696A852BCC311267DEF22DFD5397F446790823CB91A9FED034534781492E4B8EEAD0AA277257C6A5E3DBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34F38194B2C99DC1286E82E03B71402251E4CC51D8E22E10600C303832004AF5A004EDC4800C79EDB41D7E09C32AA3244C0A10DF31126C7FC2AB70F9BE574AE9C63E941732CC74B7CEEA455F16B58544A2557BDE0DD54B3590A5AE236DF995FB59829709634694AABAED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtv/CB9kl0S10CLaEUNqDWw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7695DDF3F677C48E9FFD4FF92D56319F197FF452F624717E062B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Check frame size limit before returning to a lower frame. 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 Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the review! Fixed your comments and force-pushed the branch. On 12.03.24, Sergey Bronnikov wrote: > Hi, Sergey > > > thanks for the patch! > > On 3/12/24 08:26, Sergey Kaplun wrote: > > From: Mike Pall > > > > Thanks to Sergey Kaplun. > > > > (cherry picked from commit 302366a33853b730f1b7eb61d792abc4f84f0caa) > > > > When compiling a stitched (or side) trace, there is no check for the > > frame size of the current prototype during recording. Hence, when we > > return (for example, after stitching) to the lower frame with a maximum > > possible frame size (249), the 251 = `baseslot` (2) + `maxslot` (249) > > slot for GC64 mode may be used. This leads to the corresponding assertion > > failure in `rec_check_slots()`. > > > > This patch adds the corresponding check. > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#9595 Updated commit message to the following, see the comment below. | Check frame size limit before returning to a lower frame. | | Thanks to Sergey Kaplun. | | (cherry picked from commit 302366a33853b730f1b7eb61d792abc4f84f0caa) | | When compiling a stitched (or side) trace, there is no check for the | frame size of the current prototype during recording. Hence, when we | return (for example, after stitching) to the lower frame with a maximum | possible frame size (249), the 251 = `baseslot` (2) + `maxslot` (249) | slot for GC64 mode may be used. This leads to the corresponding assertion | failure in `rec_check_slots()`. | | This patch adds the corresponding check. The `LJ_MAX_JSLOTS` and | `LJ_MAX_SLOTS` are equal by default, but their values may be manually | changed for some custom builds. Hence, the check is not enabled only for | `LJ_GC64` mode. | | Sergey Kaplun: | * added the description and the test for the problem | | Part of tarantool/tarantool#9595 > > --- > > > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1173-frame-limit-lower-frame > > Tarantool PR: https://github.com/tarantool/tarantool/pull/9791 > > Related issues: > > * https://github.com/tarantool/tarantool/issues/9595 > > * https://github.com/LuaJIT/LuaJIT/issues/1173 > > > > diff --git a/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua b/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua > > new file mode 100644 > > index 00000000..91e2c603 > > --- /dev/null > > +++ b/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua > > + > > +local LJ_MAX_JSLOTS = 250 > > I would say in a comment that constant is from . > > Your test depends on this constant (if it will be changed the test will > test nothing), > > how to make sure that LJ_MAX_JSLOTS is equal to LJ_MAX_JSLOTS in > ? Honestly, I don't know any good way to do it now. This limit is "hard-defined", but considering Mike's comment [1] may be changed by hand by someone manually for their installation. For now, I suppose Is should just leave a comment here. Also, by grepping, anyone who applies the patch that changes the `LJ_MAX_JSLOTS` limit should see the following definition and adjust it too. See the iterative patch below. =================================================================== diff --git a/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua b/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua index 468462d2..b454003e 100644 --- a/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua +++ b/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua @@ -17,6 +17,9 @@ local function retf() end _G.retf = retf +-- The maximum number of stack slots for a trace. Defined in the +-- . Also, it equals `LJ_MAX_SLOTS` -- the maximum +-- number of slots in a Lua function. local LJ_MAX_JSLOTS = 250 -- Generate the following function: =================================================================== > > > + > > +-- Generate the following function: > > + > > +local chunk = 'local uv = {key = 1}\n' > > +chunk = chunk .. 'return function()\n' > > +chunk = chunk .. 'local r = retf()\n' > > + > > +-- Each `UGET` occupies 1 slot, `KNIL` occupies the same amount. > > +-- 1 slot is reserved (`r` variable), 1 pair is set outside the > > +-- cycle. 249 slots (the maximum available amount, see > > +-- , `bcreg_bump()` for details) are occupied in > > +-- total. > > +for _ = 1, LJ_MAX_JSLOTS / 2 - 2 do > > + chunk = chunk .. ('uv.key, ') > > +end > > +chunk = chunk .. 'uv.key = nil\n' > > +chunk = chunk .. 'end\n' > Why not to use multiline here and after the loop? Good idea, thanks! Fixed. See the iterative patch below. Branch is force-pushed. =================================================================== diff --git a/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua b/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua index 91e2c603..468462d2 100644 --- a/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua +++ b/test/tarantool-tests/lj-1173-frame-limit-lower-frame.test.lua @@ -44,9 +44,11 @@ local LJ_MAX_JSLOTS = 250 -- `maxslot` (the first free slot) to 249. Hence, the JIT slots -- are overflowing. -local chunk = 'local uv = {key = 1}\n' -chunk = chunk .. 'return function()\n' -chunk = chunk .. 'local r = retf()\n' +local chunk = [[ +local uv = {key = 1} +return function() + local r = retf() + ]] -- Each `UGET` occupies 1 slot, `KNIL` occupies the same amount. -- 1 slot is reserved (`r` variable), 1 pair is set outside the @@ -56,8 +58,8 @@ chunk = chunk .. 'local r = retf()\n' for _ = 1, LJ_MAX_JSLOTS / 2 - 2 do chunk = chunk .. ('uv.key, ') end -chunk = chunk .. 'uv.key = nil\n' -chunk = chunk .. 'end\n' +chunk = chunk .. [[uv.key = nil +end]] local get_func = assert(loadstring(chunk)) local function_max_framesize = get_func() =================================================================== > > +local get_func = assert(loadstring(chunk)) > > +test:done(true) [1]: https://github.com/LuaJIT/LuaJIT/issues/1173#issuecomment-1987290608 -- Best regards, Sergey Kaplun