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 CC7B1A182AC; Mon, 11 Mar 2024 18:58:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CC7B1A182AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1710172699; bh=y5vjq7Ek/TylWgB+5J8vJhffIECe+iTtiKBvlO1Fdts=; 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=Bu95IZEXNzPBq0NOzly2wyCa1fGNoYFp/a7YXZcgF02XuMSqDODFXPVPHJJXL/rQd w4TQ5VBI/5syrUeYF0+1uUw7IANWXP49AncTKtBMI3Xsxtg+7Uo4PxHmFjlfKJqsg1 Guov4XkH/PDALPYeDO9hN2HqynCihOcj84flk6l8= Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [95.163.41.91]) (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 972C55C4041 for ; Mon, 11 Mar 2024 18:58:18 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 972C55C4041 Received: by smtp49.i.mail.ru with esmtpa (envelope-from ) id 1rji2b-0000000BWn0-2eDf; Mon, 11 Mar 2024 18:58:18 +0300 Message-ID: Date: Mon, 11 Mar 2024 18:58:17 +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> <0c07d575-620b-4832-bcc9-04a7ccbfa35e@tarantool.org> Content-Language: en-US In-Reply-To: <0c07d575-620b-4832-bcc9-04a7ccbfa35e@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: 4F1203BC0FB41BD987C0EE6E7F0A597DA4A6782E56D87B648E017E9626570F41182A05F538085040CAAA16499291C1A133594132A326AF8B13D85664C50D3D29FFF403EFF3C9D4882C3955A1DF2D7297 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E30B1A6D2A18B481EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E1AAA91777E61F958638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D80ED11B3B787824A5EFE81726F572786FE02D52914944D0EECC7F00164DA146DAFE8445B8C89999728AA50765F79006372A3B24BF85B2E607389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2DCF9CF1F528DBCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE33AC447995A7AD187441229DB5CFFAA63A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7353946EFC6A664F553C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5F854D3D64CF9322A5002B1117B3ED696C5591CB3F6AC72B33D2BBC1EF78EDEBE823CB91A9FED034534781492E4B8EEADC3194D76C41E9723BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF0C31658A4A5B4E66478D52011DAAB90B1CD97D7D7809457BC0244DA9F46BAE5D31E81B06003A5D53748ED927723DE83FE1852C20BB85FC6BDF1EEAB0B42C7F06A3F160B4EF0AA2EF5F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojT+KSurEfQafGAD4OKSz0AQ== X-DA7885C5: F89647DBCF75A3C2F255D290C0D534F9914DEF12A64A1474F34947B50DA97FDD5B43C654F879B63E5B1A4C17EAA7BC4BEF2421ABFA55128DAF83EF9164C44C7E X-Mailru-Sender: 689FA8AB762F7393590D8C940224AE33A5CB6DEF365AFF21BB17D975B5CBE436428BDC9D860F8A77EF86D5F70DA33880E41E8EF7A07863ECB274557F927329BE2DDF8182D28ACDB545BD1C3CC395C826B4A721A3011E896F 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" Max, thanks for fixes! LGTM On 2/20/24 11:08, Sergey Bronnikov via Tarantool-patches wrote: > 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 >>