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 CDD769D0C86; Tue, 6 Feb 2024 12:46:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CDD769D0C86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1707212770; bh=XAZLBrmK/gOKTZjzdy4CufSclH2uTxPJpB8tTENFHGg=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Cz7Jjs/W7iQMGOGVSRP+zX9gBP6YI6jn1UOhmOq5XLO+GWP2nKitg83TNbJ8Zgw6J CXuB5FbuqlNWKW6uRBrhrh6aR3bre7efZZRvtQ5LKW6gJSoF9woihCkOWR/OeGMjKL RgxGuuL4Twm9pUBqFDOV4BX6PbW/3TDrje5QtR1Q= Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [95.163.41.68]) (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 ABD2327C100 for ; Tue, 6 Feb 2024 12:46:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org ABD2327C100 Received: by smtp29.i.mail.ru with esmtpa (envelope-from ) id 1rXI1o-00000004bNA-3Q4p; Tue, 06 Feb 2024 12:46:09 +0300 Message-ID: <38004fc1-a985-4cf5-98bd-d207360f753d@tarantool.org> Date: Tue, 6 Feb 2024 12:46:08 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <0d003159c9a1811d98e30a863cc75c11bab658a3.1706104777.git.skaplun@tarantool.org> In-Reply-To: <0d003159c9a1811d98e30a863cc75c11bab658a3.1706104777.git.skaplun@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: 4F1203BC0FB41BD94C460F083DF69F519C7FE39648913355F55DE976E2925CCD182A05F538085040563DD2309DBEA3ACD4FF92D56319F197BEDB61EA764D4C264FFA7DF02C68FB3002A17C04448FB737 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C59BC9C499248573C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE73C696014E2DCCA1EEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B73AB1701401CD871D7AB7C894E470516C078A1195EB843281D3906EEBC9CEAE2A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE77E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C224952CC2016F1857FE476E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8BFE70A72D01850D713AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC8C7ADC89C2F0B2A5E2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BD9166E38712C78CA75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5E9D96BBF1006CFE65002B1117B3ED696F586F802CCB53DB18D59E407A97E9958823CB91A9FED034534781492E4B8EEAD1247ADC107F68C7B X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFE3BAACB3089EE0BD6FBAC4DCA1A4F42FCD8F7A62E47F905CB0116F4713A2C36ABA297A5F7262141F807D692F32DC7032A75E66FADA1564ADA7FCBE05A2D7A00424EFD39013D579265F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojh/iSjD2txnM3fAHFcOVxTg== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A7690570CEEF61CAEEC7D4FF92D56319F197BEDB61EA764D4C26B7CBEF92542CD7C8795FA72BAB74744FC77752E0C033A69EA16A481184E8BB1C9B38E6EA4F046BE03A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] Only emit proper parent references in snapshot replay. 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" Hi, Sergey thanks for the patch! test is passed with reverted patch. cmake -S . -B build -DLUA_USE_ASSERT=ON -DLUA_USE_APICHECK=ON cmake --builddir  build cmake --builddir build -t LuaJIT-tests On 1/24/24 17:11, Sergey Kaplun wrote: > From: Mike Pall > > Thanks to Peter Cawley. > > (cherry picked from commit 9bdfd34dccb913777be0efcc6869b6eeb5b9b43b) > > Assume we have a trace containing the IR instruction: > | {sink} tab TNEW #32762 #0 > > `lj_snap_replay()` assumes that 32762 (0x7ffa) (op1 of TNEW) is a > constant reference. It is passed to the `snap_replay_const()` lookup to > the IR constant in the 0x7ffa slot. If this slot contains the second > part of the IR constant number 0.5029296875 (step of the cycle) in its > raw form (0x3fe0180000000000). The 0x18 part is treated as IROp > (IR_KGC), and JIT is trying to continue with a store of an invalid GC > object, which leads to a crash. > > This patch checks that only the IRMref IR operand is needed to restore. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9595 > --- > src/lj_snap.c | 12 ++++--- > .../lj-1132-bad-snap-refs.test.lua | 36 +++++++++++++++++++ > 2 files changed, 44 insertions(+), 4 deletions(-) > create mode 100644 test/tarantool-tests/lj-1132-bad-snap-refs.test.lua > > diff --git a/src/lj_snap.c b/src/lj_snap.c > index 3f0fccec..3eb0cd28 100644 > --- a/src/lj_snap.c > +++ b/src/lj_snap.c > @@ -516,13 +516,15 @@ void lj_snap_replay(jit_State *J, GCtrace *T) > IRRef refp = snap_ref(sn); > IRIns *ir = &T->ir[refp]; > if (regsp_reg(ir->r) == RID_SUNK) { > + uint8_t m; > if (J->slot[snap_slot(sn)] != snap_slot(sn)) continue; > pass23 = 1; > lj_assertJ(ir->o == IR_TNEW || ir->o == IR_TDUP || > ir->o == IR_CNEW || ir->o == IR_CNEWI, > "sunk parent IR %04d has bad op %d", refp - REF_BIAS, ir->o); > - if (ir->op1 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op1); > - if (ir->op2 >= T->nk) snap_pref(J, T, map, nent, seen, ir->op2); > + m = lj_ir_mode[ir->o]; > + if (irm_op1(m) == IRMref) snap_pref(J, T, map, nent, seen, ir->op1); > + if (irm_op2(m) == IRMref) snap_pref(J, T, map, nent, seen, ir->op2); > if (LJ_HASFFI && ir->o == IR_CNEWI) { > if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) > snap_pref(J, T, map, nent, seen, (ir+1)->op2); > @@ -550,14 +552,16 @@ void lj_snap_replay(jit_State *J, GCtrace *T) > IRIns *ir = &T->ir[refp]; > if (regsp_reg(ir->r) == RID_SUNK) { > TRef op1, op2; > + uint8_t m; > if (J->slot[snap_slot(sn)] != snap_slot(sn)) { /* De-dup allocs. */ > J->slot[snap_slot(sn)] = J->slot[J->slot[snap_slot(sn)]]; > continue; > } > op1 = ir->op1; > - if (op1 >= T->nk) op1 = snap_pref(J, T, map, nent, seen, op1); > + m = lj_ir_mode[ir->o]; > + if (irm_op1(m) == IRMref) op1 = snap_pref(J, T, map, nent, seen, op1); > op2 = ir->op2; > - if (op2 >= T->nk) op2 = snap_pref(J, T, map, nent, seen, op2); > + if (irm_op2(m) == IRMref) op2 = snap_pref(J, T, map, nent, seen, op2); > if (LJ_HASFFI && ir->o == IR_CNEWI) { > if (LJ_32 && refp+1 < T->nins && (ir+1)->o == IR_HIOP) { > lj_needsplit(J); /* Emit joining HIOP. */ > diff --git a/test/tarantool-tests/lj-1132-bad-snap-refs.test.lua b/test/tarantool-tests/lj-1132-bad-snap-refs.test.lua > new file mode 100644 > index 00000000..1f2b5400 > --- /dev/null > +++ b/test/tarantool-tests/lj-1132-bad-snap-refs.test.lua > @@ -0,0 +1,36 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT's crash in cases of sunk > +-- restore for huge tables. > +-- See also https://github.com/LuaJIT/LuaJIT/issues/1132. > + > +local test = tap.test('lj-1132-bad-snap-refs'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(1) > + > +local table_new = require('table.new') > + > +jit.opt.start('hotloop=1', 'hotexit=1') > + > +local result_tab > +-- Create a trace containing the IR instruction: > +-- | {sink} tab TNEW #32762 #0 > +-- `lj_snap_replay()` assumes that 32762 (0x7ffa) (op1 of TNEW) is > +-- a constant reference. It is passed to the `snap_replay_const()` > +-- lookup to the IR constant in the 0x7ffa slot. > +-- This slot contains the second part of the IR constant > +-- number 0.5029296875 (step of the cycle) in its raw form > +-- (0x3fe0180000000000). The 0x18 part is treated as IROp > +-- (IR_KGC), and JIT is trying to continue with a store of an > +-- invalid GC object, which leads to a crash. > +for i = 1, 2.5, 0.5029296875 do > + local sunk_tab = table_new(0x7ff9, 0) > + -- Force the side exit with restoration of the sunk table. > + if i > 2 then result_tab = sunk_tab end > +end > + > +test:ok(type(result_tab) == 'table', 'no crash during sunk restore') > + > +test:done(true)