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 7C4596ECCC; Mon, 1 Aug 2022 12:38:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7C4596ECCC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1659346699; bh=zHJeytbtYTSVAyEMf890lbVcQo0MSqNOQkR8HHs8br4=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=TPW8jOKR1KqZxW2iTnI53e+M6tpSXHB8duPRRBzH8KTGyVszJm/gBQe4Om8XP142+ gL3bLp60KRMTngDq+pkIyGoe1fi3/nhapjPOj0p/fROEdeZhVqfkfg6AVP2GgXfPDA wcjS64jVuJ8jExsRc/bBIdzMnXLH1wwPT2idlbRo= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 583BC6ECCC for ; Mon, 1 Aug 2022 12:38:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 583BC6ECCC Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1oIRsO-0001OY-EO; Mon, 01 Aug 2022 12:38:16 +0300 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) In-Reply-To: <2409b71740006f7ea89e8f360ea77f68de7be1d5.1659264154.git.skaplun@tarantool.org> Date: Mon, 1 Aug 2022 12:38:15 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <2409b71740006f7ea89e8f360ea77f68de7be1d5.1659264154.git.skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9626C4810127D410704E254B5F4661BBDBB661CBD648A7578182A05F538085040E2516ABEF791E7E7D64DC6032BC29FE40F34941F788C91E89FB67B2B775A9582 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76C0A440987CA342DC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE79EDB57D1FB735487EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B8859CA687ABA27BAEDC87803056027B0FEF4878FCCFBA3CACC7F00164DA146DAFE8445B8C89999728AA50765F79006375A3B25A3A11CE7E4389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8EDCF5861DED71B2F389733CBF5DBD5E9B5C8C57E37DE458BD9DD9810294C998ED8FC6C240DEA76428AA50765F79006378285154E99393965D81D268191BDAD3DBD4B6F7A4D31EC0BEA7A3FFF5B025636D81D268191BDAD3D78DA827A17800CE71D45920C5ABEE4FCEC76A7562686271EEC990983EF5C03292E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C3865B847893077FB535872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E142185AC9E3593CE4B31AB1881A6453793CE9274300E5CE05BD4401A9E91200F654B0F56C66D0505D98346791A85E4603CDE24A7B20828F942C5B511699F3F6E198A79C2B6934AE262D3EE7EAB7254005DCED8DA55E71E02F9FC08E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D041FB2E16F174C473A797709FB540301DC5FE8A49241AE471F58245FF2E1A265959F58C668ABA531D7E09C32AA3244CCB756FAEE5641C3DA2283CDD96243B3564EE5813BBCA3A9DFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPX9Kc2YQ0o0mssKy+T5o2Q== X-Mailru-Sender: 5AA3D5B9D8C4864612F3A0B4F632CB4935F30B95278BF400F83C7499C86F7FFFE1E1E2713883DFAD19381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2] Fix handling of errors during snapshot restore. 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: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! With some comments fixes LGTM. Sergos > On 31 Jul 2022, at 13:58, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > (cherry picked from commit 12ab596997b9cb27846a5b254d11230c3f9c50c8) >=20 > When an error is raised during snapshot restore, `err_unwind()` = skipped the the the > correct cframe to stop unwinding. It happens due this frame is C frame that should stop The reason is a =20 > without Lua frame and the special negative value of `cfram_nres()` for ^^^^^^^ ^e not sure if I got it right - wrapping frame? Anyways an article = is missing > this frame isn't set. >=20 > This patch sets `cframe_nres()` for cframe with snap restoration to the a that contains a > `-2*LUAI_MAXSTACK` to guarantee that an error will be always caught > here. Not quite clear why this should be done always, since you mentioned = before the Lua frame presence mitigates the problem. Does it mean the cframe_nres() = is ignored if Lua frame is present? Mention it if it is true. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#7230 > --- > src/lj_trace.c | 2 ++ > .../lj-603-err-snap-restore.test.lua | 30 +++++++++++++++++++ > 2 files changed, 32 insertions(+) > create mode 100644 = test/tarantool-tests/lj-603-err-snap-restore.test.lua >=20 > diff --git a/src/lj_trace.c b/src/lj_trace.c > index d7a78d4d..68a657a7 100644 > --- a/src/lj_trace.c > +++ b/src/lj_trace.c > @@ -803,6 +803,8 @@ static TValue *trace_exit_cp(lua_State *L, = lua_CFunction dummy, void *ud) > { > ExitDataCP *exd =3D (ExitDataCP *)ud; > cframe_errfunc(L->cframe) =3D -1; /* Inherit error function. */ > + /* Always catch error here. */ > + cframe_nres(L->cframe) =3D -2*LUAI_MAXSTACK*(int)sizeof(TValue); > exd->pc =3D lj_snap_restore(exd->J, exd->exptr); > UNUSED(dummy); > return NULL; > diff --git a/test/tarantool-tests/lj-603-err-snap-restore.test.lua = b/test/tarantool-tests/lj-603-err-snap-restore.test.lua > new file mode 100644 > index 00000000..82ce6a8f > --- /dev/null > +++ b/test/tarantool-tests/lj-603-err-snap-restore.test.lua > @@ -0,0 +1,30 @@ > +local tap =3D require('tap') > + > +-- Test file to demonstrate the incorrect JIT behaviour when an ???=20 > +-- error is raised on restoration from the snapshot. > +-- See also https://github.com/LuaJIT/LuaJIT/issues/603. > +local test =3D tap.test('lj-603-err-snap-restore.test.lua') > +test:plan(1) > + > +local recursive_f > +local function errfunc() > + xpcall(recursive_f, errfunc) > +end > + > +-- A recursive call to itself leads to trace with up-recursion. > +-- When the Lua stack can't be grown more, error is raised on > +-- restoration from the snapshot. > +recursive_f =3D function() > + xpcall(recursive_f, errfunc) > + errfunc =3D function() end > + recursive_f =3D function() end > +end > +recursive_f() > + > +test:ok(true) > + > +-- XXX: Don't use `os.exit()` here intense. When error on snap ^^^ explicitly? | by intention? =20 > +-- restoration is raised, `err_unwind()` doesn't stop on correct > +-- cframe. So later, on exit from VM this corrupted cframe chain > +-- shows itself. `os.exit()` literally calls `exit()` and doesn't > +-- show the issue. > --=20 > 2.34.1 >=20