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 14AD5286901; Thu, 22 Feb 2024 17:07:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 14AD5286901 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1708610822; bh=k0Vyc66LEomP9u0VcgzpTQ+DKQzTl9x3HA5SeFsVg9Q=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=VxTfiM4XORv4bPMT+yu9jSVUrMMHzzwR1iOwIQle2hqK5aAKBO448cDBXjsPWdJSb De9EeHljHpqDHWDfZvrFfxbVOvqmoZlea8FpRw7D+RkkZ5ao80QWd399S5bSrlF3et qvkOgfoHgXGWyQxHT3q1DH4uxhr3QBKYFKGGqHtg= Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [95.163.41.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 A1491286901 for ; Thu, 22 Feb 2024 17:07:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A1491286901 Received: by smtp39.i.mail.ru with esmtpa (envelope-from ) id 1rd9j1-0000000B01n-2arl; Thu, 22 Feb 2024 17:07:00 +0300 Date: Thu, 22 Feb 2024 17:03:01 +0300 To: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org Message-ID: References: <20240216111152.152025-1-m.kokryashkin@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: 4F1203BC0FB41BD90B4B6FE9E606E496C65EA655E51029FF73D1A064B28042F300894C459B0CD1B9E7405A13B65126B2D4590478A5FB85F2CE69C15B52FD2E91DB0174DC0F557787F8D9167951636F18 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F1942E6D70B4A2F0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E565730CA785C4918638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89C3E974AB5B6373EFF26919519EFFA118AADB8E618427FB0CC7F00164DA146DAFE8445B8C89999728AA50765F7900637CAEE156C82D3D7D9389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8062BEEFFB5F8EA3EF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE33AC447995A7AD182BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7356436AE5DD6441DC7C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5E0D0D520684D29F95002B1117B3ED6961A780196D9298850D57BAD45EC4C5DE1823CB91A9FED034534781492E4B8EEADB1D70E2111C441FFBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D3480665FBD8F49180CC4914ED52CFAD93E52733856EB70F34EC17F4B852FD19F810FCD95C12B46DAE41D7E09C32AA3244C5D7C62C1B25B9C497B0DC8E7D22A103AB47460D9E69388FFEA455F16B58544A2E30DDF7C44BCB90DA5AE236DF995FB59829709634694AABAED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojjw0udeJQYBRr27auYmP6zQ== X-DA7885C5: 111D5C8B88375A43F255D290C0D534F9B06BE91014D9A1C45D2B0CA9F24EEC915DDD7BACFFC4315A5B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393590D8C940224AE3336E062DD51C494B28BA6822D18381312B832CC4DD992D3F2E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Throw any errors before stack changes in trace stitching. 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, again, folks! On 21.02.24, Sergey Kaplun via Tarantool-patches wrote: > Hi, Maxim! > Thanks for the patch! > Please consider my comments below. > > On 16.02.24, Maxim Kokryashkin wrote: > > From: Mike Pall > > > > Thanks to doujiang24. > > > > (cherry-picked from commit 3f9389edc6cdf3f78a6896d550c236860aed62b2) > > > > The Lua stack is changed in the `lj_record_stop`, so if the trace > > Actually, it is changed in the `recff_stitch()` -- the continuation frame > is inserted below a function with arguments. > > > is aborted, for example, when the `maxsnap` is reached, and an > > If there are any other situations, we must handle them too: > > 1) AFAICS, when LuaJIT is built with -DLUAJIT_ENABLE_TABLE_BUMP, the > following lines may lead to the error, and thereby the Lua stack > becomes unbalanced: > > `lj_record_stop()`: > | if (J->retryrec) > | lj_trace_err(J, LJ_TRERR_RETRY); > > Build with the following flags: > | cmake -DCMAKE_C_FLAGS="-DLUAJIT_ENABLE_TABLE_BUMP" -DLUA_USE_APICHECK=ON \ > | -DLUA_USE_ASSERT=ON -DCMAKE_BUILD_TYPE=Debug \ > | -DLUAJIT_ENABLE_GC64=OFF . && make -j > > The following script reproduces the issue (`maxsnap` configuration option > is gone): > > | src/luajit -e " > | local modf = math.modf > | jit.opt.start('hotloop=1') > | > | local t1 > | for i = 1, 2 do > | t1 = {} > | t1[i] = i > | -- Forcify stitch. > | modf(1.2) > | end > | " > | LuaJIT ASSERT src/lj_dispatch.c:502: lj_dispatch_call: unbalanced stack after hot instruction > > 2) Also, it may happen when the memory error is raised when we try to > reallocate the IR buffer for the next instruction in `lj_ir_nextins()`. > > The reproducer for this issue is much more tricky. > > My suggestions here are the following: > Resolve the special case in the scope of backporting this patch, and > report the 2 follow-ups with suggested solutions to the upstream. > As I can see, this issue should be fixed in the following way: > Add the `lj_vm_cpcall()` to the `record_stop()` call and rethrow > the error, if needed, after clenup. > Reported here: https://github.com/LuaJIT/LuaJIT/issues/1166 > > > > -- > Best regards, > Sergey Kaplun -- Best regards, Sergey Kaplun