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 AD120D72AA0; Wed, 13 Mar 2024 14:33:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AD120D72AA0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1710329620; bh=XGxZPadlHPCksXfIM/YXBDW6UxB77ZjEOrUko/g0Vug=; 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=MkI1CSzYTK0UshpeLdjGOLUoEOElrY2jmzK1BbM3JRXdgu5HUlQ4NfeU6NLv0fjvq 2MJDoOaKLP0Idqb10uWojdmJd3n+5D/gN9f7R+5MYpSVRFFBpxXS5DLUMHlu/Z248u CiwJE0FlKaLl/5eXSObo/1krDS3da/3VhOOA7Hhc= 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 818FE46DF3A for ; Wed, 13 Mar 2024 14:33:39 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 818FE46DF3A Received: by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1rkMra-00000005qRA-352V; Wed, 13 Mar 2024 14:33:39 +0300 Message-ID: Date: Wed, 13 Mar 2024 14:33:37 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun References: <20240312052627.21222-1-skaplun@tarantool.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD987C0EE6E7F0A597DA4A6782E56D87B648E017E9626570F41182A05F538085040A2EEE321CCA4CC59D27678DDAA806314DF361DB59D52A053F4425C75638A54CFECA116FACD37B17E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F8E53417176C7207EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637C558246F87AE15468638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D862EF62A54DC4A79B583EAE5F687BD99F63B2EFD469E89C65CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC82FFDA4F57982C5F4F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C1F9513A7CA91E555040F9FF01DFDA4A84AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C363F4B9C2FB5BF80FBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFED8438A78DFE0A9E1DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C31205B1F03D11AAAB35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A50521E010B2EAB17C5002B1117B3ED69683D94539822454B05B6221DB6D7A72AD823CB91A9FED034534781492E4B8EEAD14747542773C033FBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D340D3A19269BBEBAAF4DC6A9F8F09E19F2A88B5D24D18D9CED1C0DEC615CF24CBE82E7524099142D211D7E09C32AA3244C2B246C9C8FCEF1F22887F5EA2DDCF3446A8BAFFE7B9262CFEA455F16B58544A2557BDE0DD54B3590A5AE236DF995FB59978A700BF655EAEEED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtv/CB9kl0S1wkMxjDvS2Vg== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F25884582D6D7E62A9CB8A7287A35C9C7BBE74BE3D3731B01D5949A10FF2D94DDA5A807D645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, LGTM with minor comment below. On 3/13/24 12:37, Sergey Kaplun wrote: > 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 Thanks! >>> --- >>> >>> 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. It is not perfect, but I don't know how to link macros in C and constant in Lua better. Thanks for the fix. > > 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() > + ]] here brackets are on a new line with indentation and below brackets on the same line with code. looks inconsistently. > > -- 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 >