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 811BE69C437; Fri, 13 Oct 2023 08:48:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 811BE69C437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1697176112; bh=E2kBx2E+3/EkgjCnp20yfH9mejffEtHX3CUFJPRaQrk=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=jCOWFyARd/zO89XniRkTcRXrLIsxvrCNNQnjR7xkxuMIAZJWbgze8vvO9FxN3ZlY1 sBU2Vwlo1yX7z5xoSZWCPVS+cwuYQHzs5lutZtxhKTHetIVzR3237Wkf8tNbipyf59 jkUwpk8YQHDJ3W3d8g3FDMNaoLPhtEuY9dbDfaX0= Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [95.163.41.75]) (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 4FD025F2B01 for ; Fri, 13 Oct 2023 08:48:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4FD025F2B01 Received: by smtp34.i.mail.ru with esmtpa (envelope-from ) id 1qrB2E-00G19W-1l; Fri, 13 Oct 2023 08:48:30 +0300 Date: Fri, 13 Oct 2023 08:48:30 +0300 To: Sergey Kaplun Message-ID: References: <9b2713c1405073d42c14f3179ff5a8fb338a37dd.1697034851.git.skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9b2713c1405073d42c14f3179ff5a8fb338a37dd.1697034851.git.skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD93E991D2DB989D7D3BAA9FC5EFBE5074B287955EC723EE216182A05F538085040C6F9C9979C87EA03118E5EFD56A7594A5066DA48076522DF15413BB15D4D3D72 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3295C83650092F9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637629A2DB6D7098C1B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82DF01FF7B7E367C50311844B2FFB2426117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD1828451B159A507268D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEB28585415E75ADA9CEDA8D6C8C3B0531D8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE367F1C1C3ABB44F3A6E0066C2D8992A16C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947C5FF72824B19451C62E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BC6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A54EF63DE80378101FBE81F95B685E3C58DDD4B58190BA6399F87CCE6106E1FC07E67D4AC08A07B9B04B3849D6E5CCBAFDBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFA1FA8979E1E161AB348BFA76AB3F8DF2A3B067C4FC8CD2A66282FA8B79AADAA9715D154A38A044DC27E9EA44DF0471FDEF844D6866649072E1570F0F1C8C221AE48CAC7CA610320002C26D483E81D6BE64ACE4A408B72B61B0CA6F94E606A667A52EF62A646584F811BD90D3D42C882D43082AE146A756F3 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojBYtV3BjG6I78AJ4mxQmswA== X-Mailru-Sender: EFA0F3A8419EF21662C2E89D2219EA70F5C5E4E7933877F1118E5EFD56A7594AFE5F7FEA15315F1604C9FB44FCBCE9EE92D99EB8CC7091A7ECEABDC5717908DEF544888E8238EB4872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [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: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! LGTM, except for a few nits below. On Wed, Oct 11, 2023 at 06:04:09PM +0300, Sergey Kaplun wrote: > 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 Typo: s/spoiled/spilled/ > snapshot by stack overflow -- we are in trouble. > > The moment when IR is spoiled is when we set a hint on the register Typo: s/spoiled/spilled/ > 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 >