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 70AAD6A8173; Wed, 11 Oct 2023 18:09:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 70AAD6A8173 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1697036951; bh=96/iktLiUVq4CcAIUdS8olT1+nSnz/DKD8r/l2Z/Sm4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=M0DkxiRBy8VPqoRW6pYNOVmrUdF3vAK1ILV4f2pTVkBY7FZzPEAMlZ/cVj4GW1Z/8 gHQv08jrrGYNQ0EkcWPWOYRvLZpGmW1zWymY15sh7kiXuIE5n7ZWpyeop1XNkHMLiW oybEtCJ1HOhmjz4ZIp2VtIsZ7ebE4hCKH3efM8+c= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [95.163.41.95]) (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 69F286A5AF4 for ; Wed, 11 Oct 2023 18:08:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 69F286A5AF4 Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1qqapE-00DjtE-39; Wed, 11 Oct 2023 18:08:41 +0300 To: Maxim Kokryashkin , Sergey Bronnikov Date: Wed, 11 Oct 2023 18:04:09 +0300 Message-ID: <9b2713c1405073d42c14f3179ff5a8fb338a37dd.1697034851.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9FE0487E502468146884F21831C55F1A17097FC19E6381A7B00894C459B0CD1B9475F3990419CA44E4E5ECF6D78E2334330A35E3AB8DF4460E1BDF786614B4017 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7AD2F2D6F6013FF7FC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7EA4B66823129EB3CEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BE5CCB53A13BC8DBAA5D5D88CA52B4CBE149B7BB0D66EC8EACC7F00164DA146DAFE8445B8C89999728AA50765F790063767B9C6E70FBE8DD8389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8D2A98E5A6551E3E5117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CFA5A5C9631F7CC0DCBA3038C0950A5D36C8A9BA7A39EFB766D91E3A1F190DE8FDBA3038C0950A5D36D5E8D9A59859A8B6ED9849331FF67AB576E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C224949BD6D9C51793B4DE827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6ADE2ED557203A23075ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5EA6138A90DC368E84FD24AD5479A91D3E82865275326A57DF87CCE6106E1FC07E67D4AC08A07B9B0B6FBD635917D924D9C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFC73EB75CCD12E730975A42F9754B0772DC3263F05CC914689E54170AB06F8FC3F31E0254ADC75A06ED8146B44B5935894DF442220AE971DA8970A34480D1C14EA74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojPxfa+LcGtji5TzJABmLAoQ== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769BEBC661731838B84F9E925D02E05F3DF6CCF71F689FD47EEDEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 1/2] Fix register mask for stack check in head of side 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" From: Mike Pall Analyzed by Sergey Kaplun. (cherry-picked from commit b7a8c7c184257858699454408420dd5f0b6c8a75) Assume we have parent and child traces with the following IRs from the IR dump: Parent: | 0009 rax > tab TNEW 0 0 | 0010 p32 FLOAD 0008 tab.node | 0011 p32 HREFK 0010 "Name" @1 | 0012 {0008} tab HSTORE 0011 0009 | .... SNAP 2 [ ---- 0001 0002 0008 ---- ] | 0013 {sink} tab TNEW 0 0 | 0014 {0008} fal HSTORE 0011 false | .... SNAP 3 [ ---- 0001 0002 0008 ---- ] Child: | 0001 r15 tab SLOAD 1 PI | 0002 rbp tab SLOAD 2 PI | 0003 tab PVAL 9 As we can see from the trace dump above, the `rax` register is missing in the `0003 PVAL` IR for the side trace -- so it is assumed to be available in the allow RegSet inside `asm_stack_check()` and its value is spoiled during this check, so if we are restoring from the 3rd snapshot by stack overflow -- we are in trouble. The moment when IR is spoiled is when we set a hint on the register inherited from the parent trace (see `asm_setup_regsp()` for details). The 0th register (`rax`) shapeshifts into `RID_NONE`. Hence, when collecting register dependencies from the parent trace, `0003 PVAL` is considered the IR with `RID_NONE`, i.e., without an assigned register. So, this register is considered free (picked as bottom from the free set) in the `asm_stack_check()` and is used for stack overflow check, so the table reference is gone. This patch introduces another register set for the context of the parent trace to use in the stack check. All registers used on the child trace are excluded from this set. The test case for this patch is omitted since it requires specific register allocation, which is hard to construct and not stable in any future patches. Part of tarantool/tarantool#9145 Sergey Kaplun: * added the description for the problem --- src/lj_asm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lj_asm.c b/src/lj_asm.c index 3a1909d5..ca06860a 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c @@ -1859,6 +1859,7 @@ static void asm_head_side(ASMState *as) IRRef1 sloadins[RID_MAX]; RegSet allow = RSET_ALL; /* Inverse of all coalesced registers. */ RegSet live = RSET_EMPTY; /* Live parent registers. */ + RegSet pallow = RSET_GPR; /* Registers needed by the parent stack check. */ IRIns *irp = &as->parent->ir[REF_BASE]; /* Parent base. */ int32_t spadj, spdelta; int pass2 = 0; @@ -1899,6 +1900,7 @@ static void asm_head_side(ASMState *as) sloadins[rs] = (IRRef1)i; rset_set(live, rs); /* Block live parent register. */ } + if (!ra_hasspill(regsp_spill(rs))) rset_clear(pallow, regsp_reg(rs)); } /* Calculate stack frame adjustment. */ @@ -2015,7 +2017,7 @@ static void asm_head_side(ASMState *as) ExitNo exitno = as->J->exitno; #endif as->T->topslot = (uint8_t)as->topslot; /* Remember for child traces. */ - asm_stack_check(as, as->topslot, irp, allow & RSET_GPR, exitno); + asm_stack_check(as, as->topslot, irp, pallow, exitno); } } -- 2.42.0