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 2E01DB4A6E4; Tue, 20 Feb 2024 11:08:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2E01DB4A6E4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1708416494; bh=QZL7/YmmmsCtxDQmxJyUq3m9HYmygenksrmOakoEL+Q=; 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=KbfCSP3VpbxP9NWa9xDOKhX/JhCbpd32yqEh5TscVcRFaKN1ixMsfMog0P6CNOEcQ JDTkpcYf1QKyBPLwrEttFoiWmc+TJMDt+nWz3ydGTiGn5bRQdwAsgYj5ineMvYGsVI Lqs7GreVhdK26mjddYMWf3ESAH4IuTAsmboCXiv4= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [95.163.41.86]) (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 8CE20453841 for ; Tue, 20 Feb 2024 11:08:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8CE20453841 Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1rcLAg-00000009sZi-2iCN; Tue, 20 Feb 2024 11:08:11 +0300 Message-ID: <0c07d575-620b-4832-bcc9-04a7ccbfa35e@tarantool.org> Date: Tue, 20 Feb 2024 11:08:10 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org, skaplun@tarantool.org References: <20240216111152.152025-1-m.kokryashkin@tarantool.org> Content-Language: en-US In-Reply-To: <20240216111152.152025-1-m.kokryashkin@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9001F8F2F6BAD20218FDFC93A65F85DDC59E3B8317EBE436000894C459B0CD1B940660E93A2F633864EE244ABC9E222BAD59167E8CD598A0CD249852C9805576AF82D89A8CF7DB8F5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74E9055D3307A84CAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637993F4D0874F024C68638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8696F7897583BD50F9AA7CDA520FC2F82AFDAC165E2ABFB04CC7F00164DA146DAFE8445B8C89999728AA50765F79006372A3B24BF85B2E607389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2DCF9CF1F528DBCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C6089696B24BB1D19AD7EC71F1DB884274AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3E152ED169DC56D4DBA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFE478A468B35FE7671DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C37727919777A35F2B35872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A521C9CCEA82395DA65002B1117B3ED696C11ED36FA4BE3BDD69995D676B7B4CBE823CB91A9FED034534781492E4B8EEAD2B25D9E4C92BC8ACBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFCA89E57DF0608CA67A1847B7709DC3979F7246326C33F15460DD27C58C631788378A699BB2730F8CF1AD97FD9824DBCDA48411BA22F35B306FC327AA77E540800DA4F5CDBDD6AA025F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojiWfz0I2sVCmOkvxZj0Yo0w== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7690D58233C3FB396205D1BE6A8D71B10A557F1BD027AA7FAE9B7CBEF92542CD7C8795FA72BAB74744FC77752E0C033A69EA16A481184E8BB1C9B38E6EA4F046BE03A5DB60FBEB33A8A0DA7A0AF5A3A8387 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hello, Max, thanks for the patch! see my comments Sergey On 2/16/24 14:11, 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 > is aborted, for example, when the `maxsnap` is reached, and an > error is thrown from there, the execution continues with an > unbalanced stack. > > Since the only error that is thrown from the `lj_record_stop` > with modified stack is `LJ_TRERR_SNAPOV`, this patch adds a As I see lj_record_stop [1] throws only LJ_TRERR_RETRY or I got you wrong. 1. https://github.com/LuaJIT/LuaJIT/blob/0d313b243194a0b8d2399d8b549ca5a0ff234db5/src/lj_record.c#L299 > check for snapshot overflow to the `recff_stitch`. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#9595 > --- > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-pr-720-errors-before-stitch > PR: https://github.com/tarantool/tarantool/pull/9703 > Issues: > https://github.com/tarantool/tarantool/issues/9595 > https://github.com/LuaJIT/LuaJIT/pull/720 > > src/lj_ffrecord.c | 4 ++++ > .../lj-pr-720-errors-before-stitch.test.lua | 20 +++++++++++++++++++ > 2 files changed, 24 insertions(+) > create mode 100644 test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua > > diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c > index 1b2ddb72..e3ed80fb 100644 > --- a/src/lj_ffrecord.c > +++ b/src/lj_ffrecord.c > @@ -107,6 +107,10 @@ static void recff_stitch(jit_State *J) > const BCIns *pc = frame_pc(base-1); > TValue *pframe = frame_prevl(base-1); > > + /* Check for this now. Throwing in lj_record_stop messes up the stack. */ > + if (J->cur.nsnap >= (MSize)J->param[JIT_P_maxsnap]) > + lj_trace_err(J, LJ_TRERR_SNAPOV); > + > /* Move func + args up in Lua stack and insert continuation. */ > memmove(&base[1], &base[-1-LJ_FR2], sizeof(TValue)*nslot); > setframe_ftsz(nframe, ((char *)nframe - (char *)pframe) + FRAME_CONT); > diff --git a/test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua b/test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua > new file mode 100644 > index 00000000..53b7b5ea > --- /dev/null > +++ b/test/tarantool-tests/lj-pr-720-errors-before-stitch.test.lua You could omit "-pr" in the name, anyway https://github.com/LuaJIT/LuaJIT/issues/720 redirects to https://github.com/LuaJIT/LuaJIT/pull/720. > @@ -0,0 +1,20 @@ > +local tap = require('tap') > +local test = tap.test('lj-pr-720-errors-before-stitch'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > +test:plan(1) > + > +-- `math.modf` recording is NYI. > +local modf = require('math').modf > +jit.opt.start('hotloop=1', 'maxsnap=1') > + > +-- The loop has only two iterations: the first to detect its > +-- hotness and the second to record it. The snapshot limit is > +-- set to one and is certainly reached. > +for _ = 1, 2 do > + -- Forcify stitch. > + modf(1.2) > +end > + > +test:ok(true, 'stack is balanced') > +test:done(true) > -- > 2.43.0 >