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 06AD7AF790A; Wed, 3 Apr 2024 09:16:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 06AD7AF790A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1712125016; bh=JXLCxq8z0zdteVzLZPJDSaKoapGpznDNi8Ihxm4peK8=; 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=PKCRM7R/hjQ9TTHZWj3s01kxyM536opqyqlJj1ZmlXLCMjosGlzMJ3W2hK2W6TMA8 7066UF+Bgyg3TnBja57CZ0H0vPAzj2iZcofSk6PUGmkMLP7jmoWW/9MCVXuOSEEwn5 aKr1KS7WWVHmrtSw+k6KW9RxK9KcGM/V8rau4814= Received: from smtp32.i.mail.ru (smtp32.i.mail.ru [95.163.41.73]) (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 6A2CEAF7901 for ; Wed, 3 Apr 2024 09:16:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6A2CEAF7901 Received: by smtp32.i.mail.ru with esmtpa (envelope-from ) id 1rrtvY-00000007sm9-2kyb; Wed, 03 Apr 2024 09:16:53 +0300 Date: Wed, 3 Apr 2024 09:12:54 +0300 To: Sergey Bronnikov Message-ID: References: <20240319164148.22506-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D135BF24EC7C3B84F4481F7E27D197A12AFDB31AE04A9497182A05F538085040B66B2D55CBCCF88E91417EB218679B82BE085DF6C2E815F379C14A6D8E0B9608CDC27D7208C63596 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE75644E22E05AA81AEB287FD4696A6DC2FA8DF7F3B2552694A4E2F5AFA99E116B42401471946AA11AF7680F9384605B903B10A181A22533F518F08D7030A58E5AD1A62830130A00468AEEEE3FBA3A834EE7353EFBB55337566B1220E26F264B56456E46672DB5B2C4EF644E9D77B69E9C68C0A37FD7F4F1D09389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C04CF195F1528592878941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6E5E764EB5D94DBD4CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249DA32C97373D9A83276E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B48499449926322273AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC2EE5AD8F952D28FBE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B53A69B3AC30C7B9475ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5116E01E79C7528E45002B1117B3ED696AFD99BBE0F5BAAFC361FAC1196A180DE823CB91A9FED034534781492E4B8EEAD887A4342A344B6EDBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34CC972AA0E2E780C4BF37A9EFAE641AD8CAD909BA604D7E098513C9AF78D1A2B1182C4C2622CF59711D7E09C32AA3244CF3D1CD6DADA0A8D20091A80DA37A96F3603BA45F61040D4CEA455F16B58544A2557BDE0DD54B3590A5AE236DF995FB59829709634694AABAED6A17656DB59BCAD427812AF56FC65B X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj/eQ5CRx/6Gybo+XdtWQRgg== X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B59EFC719EF69250F2691417EB218679B82BE085DF6C2E815F3B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Prevent down-recursion for side traces. 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" Hi, Sergey! Thanks for the review! I've fixed your comments, rebased the branch on the current tarantool/master, and force-pushed it. On 26.03.24, Sergey Bronnikov wrote: > Sergey, > > thanks for the patch. LGTM with three minor comments below. > > Sergey > > On 3/19/24 19:41, Sergey Kaplun wrote: > > From: Mike Pall > > > > Thanks to Sergey Kaplun. > > > > (cherry picked from commit cae361187e7e1e3545353fb560c032cdace32d5f) > > > > Assume we have the root trace that uses some spill slots with the > > corresponding stack adjustment. Then its side trace will restore stack > s/stack/the stack/ Fixed, thanks. > > only at its tail. It may look like the following: > > > > | ---- TRACE 4 mcode 1247 > > | 55557f7df953 mov rax, [r14-0xe28] > > | 55557f7df95a mov rax, [rax+0x30] > > | 55557f7df95e sub rax, rdx > > | 55557f7df961 cmp rax, +0x68 > > | 55557f7df965 jb 0x55557f7d004c ->0 > > | 55557f7df96b add rsp, -0x10 > > | ... > > | 55557f6efa71 cmp dword [rdx+0x4], -0x05 > > | 55557f6efa75 jnz 0x55557f6e004c ->0 > > | ... > > | 55557f7dfe29 add rsp, +0x10 > > | 55557f7dfe2d jmp 0x5555556fe573 > > | ---- TRACE 4 stop -> stitch > > | > > | ---- TRACE 5 start 4/0 > > | ---- TRACE 5 mcode 101 > > | 55557f6ef9d4 mov dword [0x40000518], 0x5 > > | ... > > | 55557f6efa30 add rsp, +0x10 > > | 55557f6efa34 jmp 0x55557f6ef9d4 > > | ---- TRACE 5 stop -> down-recursion > > > > Such side traces have no stack addjustment at their heads since their > s/addjustment/adjustment/ Fixed, thanks! > > stack addjustment is inherited from the parent trace. The issue occurs > > if the side trace has a down-recursion, as mentioned above. Before any > > exit, we can jump back to the start of the trace several times with > > growing `rsp`. In that case, the `rsp` is restored incorrectly after > > exiting from the trace. > > > > This patch forbids down-recursion for non-root traces. > > > > Sergey Kaplun: > > * added the description and the test for the problem > > > > Part of tarantool/tarantool#9595 > > --- > > > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1169-down-rec-side > > Related issues: > > * https://github.com/tarantool/tarantool/issues/9595 > > * https://github.com/LuaJIT/LuaJIT/issues/1169 > > + > > +-- If a parent trace has more than the default amount of spill > > +-- slots, the `rsp` register is adjusted at the start of the trace > > +-- and restored after. If there is a side trace created, it > > +-- modifies the stack only at exit (since adjustment is inherited > > +-- from a parent trace). If the side trace has down-recursion (for > s/own-recursion/a down-recursion/ Fixed, see the iterative patch below. =================================================================== diff --git a/test/tarantool-tests/lj-1169-down-rec-side.test.lua b/test/tarantool-tests/lj-1169-down-rec-side.test.lua index 63f9925f..6363edd7 100644 --- a/test/tarantool-tests/lj-1169-down-rec-side.test.lua +++ b/test/tarantool-tests/lj-1169-down-rec-side.test.lua @@ -22,10 +22,10 @@ test:plan(1) -- slots, the `rsp` register is adjusted at the start of the trace -- and restored after. If there is a side trace created, it -- modifies the stack only at exit (since adjustment is inherited --- from a parent trace). If the side trace has down-recursion (for --- now only down-recursion to itself is used), `rsp` may be --- modified several times before exit, so the host stack becomes --- corrupted. +-- from a parent trace). If the side trace has a down-recursion +-- (for now only the down-recursion to itself is used), `rsp` may +-- be modified several times before exit, so the host stack +-- becomes corrupted. -- -- This test provides the example of a side trace (5) with -- down-recursion. =================================================================== > > +-- now only down-recursion to itself is used), `rsp` may be -- Best regards, Sergey Kaplun