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 E6CD5733EC2; Thu, 14 Dec 2023 15:25:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E6CD5733EC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1702556727; bh=VOk0yGuyp29ZTtFCcB5QSHuAmdX4I3lRoBQK1I5UdPo=; 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=xDu30+5oCSoadB5xmXDsLxWbOuiYHOE8nVsTGk0sRQLaC1ysdH4kta0ED7aOhj8cg Lbm3dneF9vIiWfEjKa+yUSrjVOXoFTFm250kL5n7xHjJ//u2mBk94f97f7LYRfM+N6 /an5RaaUs2cmutY0A3svmAPNcLRSF3ZBF5KSWaNk= Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [95.163.41.82]) (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 96D92733EC2 for ; Thu, 14 Dec 2023 15:25:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 96D92733EC2 Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1rDkmK-003UHO-1e; Thu, 14 Dec 2023 15:25:25 +0300 Date: Thu, 14 Dec 2023 15:20:53 +0300 To: Maxim Kokryashkin Message-ID: References: <20231214114458.17929-1-m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214114458.17929-1-m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97533543916A0F71A84F3C54A5E5B8DE1EEF7405543D6F01ACD62213F67905E7A5DCF76B02DABD1BD0C8B80EE9796D9E5F0EE55AD39BC64D2F8D9167951636B18 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE728F774C865CF4B07EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637B6346D94A32A1DEB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81B2E539989AACF61E90A63487DAE7E80117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAE9A1BBD95851C5BA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD186FD1C55BDD38FC3FD2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B68E75A379BAF682BD8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE30085B890FD2717DA03F1AB874ED89028C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CA9FF340AA05FB58C2E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F616AD31D0D18CD5CA91E23F1B6B78B78B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A50E7AB19EA2A6CA59051E8FA6A85377067FFD362CAC26E3F2F87CCE6106E1FC07E67D4AC08A07B9B06A1CB4668A9CA5FACB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF771022ED53427542563379B5422A739DD1974B62B5B70947D33663240505C3507BCAC92FCA26627061E41F2809366B388D7CFE7659ACD26B5337FE827CC7D59EE48CAC7CA610320002C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtsCAqtdyux1D2mgltoKjiQ== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7698B5885A7B2B7E2612BD164C9CF4B4B321E1E156D000DABDBDEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Avoid assertion in case of stack overflow from stitched trace. 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, Maxim! Thanks for the patch! Please, consider my comments below. On 14.12.23, Maxim Kokryashkin wrote: > From: Mike Pall > > Reported by Sergey Bronnikov. Fixed by Sergey Kaplun. > > (cherry-picked from commit 1d75cd4d7be638babe6d4e47bf73ea05fc65d81c) > > When we exit from a stitched trace due to the Lua stack overflow > error, the Lua and JIT stacks are not synchronized, and they > won't be as long as the mentioned error is raised. Because of The reason is not the stack synchornization, but the determination of the bytecode when the error is raised. In the case of stitched trace (see the dumps below), the last slot in the snapshot map is the argument for the function to stitch (in our case, ref to 42). Or for the second trace, we have any other function where the recording is stopped but not the function where it was started. So determine bytecode position isn't trivial. And it is better just return `NO_BCPOS` in such cases. | Trace 1 start | ---- TRACE IR | .... SNAP #0 [ ---- ] | 0001 fun SLOAD [L ] lit: #0 lit: R | 0002 tab FLOAD [L ] ref: 0001 lit: func.env | 0003 int FLOAD [L ] ref: 0002 lit: tab.hmask | 0004 > int EQ [C ] ref: 0003 ref: integer 63 | 0005 p32 FLOAD [L ] ref: 0002 lit: tab.node | 0006 > p32 HREFK [R ] ref: 0005 ref: string "math" @ 0x400061e8 KSLOT: @54 | 0007 > tab HLOAD [L ] ref: 0006 | 0008 int FLOAD [L ] ref: 0007 lit: tab.hmask | 0009 > int EQ [C ] ref: 0008 ref: integer 31 | 0010 p32 FLOAD [L ] ref: 0007 lit: tab.node | 0011 > p32 HREFK [R ] ref: 0010 ref: string "fmod" @ 0x40006c88 KSLOT: @18 | 0012 > fun HLOAD [L ] ref: 0011 | 0013 > fun EQ [C ] ref: 0012 ref: fast function #58 | .... SNAP #1 [ ---- {trace 0x1 @ 0x400271d8} contpc ftsz | {number 42} {number 42} ] | 0014 NOP [N ] | | Trace 2 start | ---- TRACE IR | .... SNAP #0 [ ---- ] | 0001 fun SLOAD [L ] lit: #0 lit: R | 0002 > fun EQ [C ] ref: 0001 ref: Lua function @ 0x400157f0, 1 upvalues, "@../master/test/tarantool-tests/lj-913-so-stitched.test.lua":11 | .... SNAP #1 [ ftsz | ftsz | ] | 0003 NOP [N ] > that, we get the incorrect bytecode instruction in > `debug_framepc`. This patch fixes this behavior, so the > `debug_framepc` now returns `NO_BCPOS` for this case. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#9145 > --- > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-913-avoid-assertion-stkov-from-stitched-trace > PR: https://github.com/tarantool/tarantool/pull/9484 > Issues: https://github.com/tarantool/tarantool/issues/9145 > https://github.com/LuaJIT/LuaJIT/issues/913 > > src/lj_debug.c | 9 +++++--- > ...-913-stackoverflow-stitched-trace.test.lua | 23 +++++++++++++++++++ > 2 files changed, 29 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua > > diff --git a/src/lj_debug.c b/src/lj_debug.c > index 46c442c6..107f464c 100644 > --- a/src/lj_debug.c > +++ b/src/lj_debug.c > diff --git a/test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua b/test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua > new file mode 100644 > index 00000000..3c12f0d9 > --- /dev/null > +++ b/test/tarantool-tests/lj-913-stackoverflow-stitched-trace.test.lua > @@ -0,0 +1,23 @@ > +local tap = require('tap') > +-- Test to demonstrate the incorrect LuaJIT behavior when exiting > +-- from a snapshot for stitched trace. > +local test = tap.test('lj-913-stackoverflow-stitched-trace'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(3) > + > +-- Recursion to cause stack overflow. > +local function callee() > + -- `math.fmod()` is NYI, so trace will be stitched here. > + local _ = math.fmod(42, 42) We don't need this `_` variable here. Just using `math.fmod()` is enough. > + callee() > +end > + > +local st, err = pcall(callee) > + > +test:ok(true, 'assertion is not triggered') > +test:ok(not st, 'error happened') > +test:like(err, 'stack overflow', 'stack overflow happened') > + > +test:done(true) > -- > 2.43.0 > -- Best regards, Sergey Kaplun