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 C23F647D296; Thu, 25 May 2023 09:19:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C23F647D296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1684995556; bh=0iGEmUmwRpSe81P78mPn2Bk5uEPGx7pHRjUf+7G1Ess=; 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=tk+Z9LFfaCfSgo5zJGtQYkMdWqju/7qVqOnrP52PDWhwQyvjGRxMga5eaIC7EpFai 3zbyuXoDiBLzhV5gKsZKGNT6SBE1o89V/YOVvirMb1Y8dbtK64D9Vg5nRi67xJCOGe MjVjSx1e1XW/CGvvfvXh57fqPiAPQH7dFa98aAIM= Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [95.163.41.78]) (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 11BCB4457FC for ; Thu, 25 May 2023 09:19:15 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 11BCB4457FC Received: by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1q24Je-002Jad-3J; Thu, 25 May 2023 09:19:14 +0300 Date: Thu, 25 May 2023 06:16:20 +0000 To: Sergey Kaplun Message-ID: References: <20230322082739.25391-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230322082739.25391-1-skaplun@tarantool.org> X-Clacks-Overhead: GNU Terry Pratchett X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD97F7D51D8A9E85DF809859B6367B16A6818905D30BC03AEF7182A05F5380850404C228DA9ACA6FE27E771F39A0DBBA92661DFDA50F1D2776AC6E3147341C65915FC14303832F62911 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7876E9C5582D2D91DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373C9FC9F3BACECB908638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D853FD878C8BFEEE3D6C62FEB4560AEA7B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCB816BE3345416868389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8B4B51A2BAB7FBE05117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF7D867A29DFE2655CBA3038C0950A5D36C8A9BA7A39EFB766EC990983EF5C0329BA3038C0950A5D36D5E8D9A59859A8B63C6898C3C2F22CEE76E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CB1724D34C644744043847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A502E4649BAF0F951AE20D98D4F893439CFA1E484DB0A5760AF87CCE6106E1FC07E67D4AC08A07B9B01F9513A7CA91E555CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34431D0341F6B74DD3076027544E6B1540F5FB1B79630B017202080CA3C8B8C07820FFE4321A12517D1D7E09C32AA3244C2537F0841BE375D8A80455946C7C54F4B4DF56057A86259F927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj7RK+RruQK1eDJVwEe0cmtw== X-Mailru-Sender: 2FEBA92C8E508479FE7B9A1DF348D53197FB8A270294057A42042AD89CCAE3BCA0346B1C636DA0E72326FE6F2A341ACE0FB9F97486540B4CD9E8847AB8CFED4D9ABF8A61C016C2CFB0DAF586E7D11B3E67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] x64/LJ_GC64: Fix emit_rma(). 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Sergey, I've checked the patchset into all long-term branches in tarantool/luajit and bumped a new version in master, 2.11 and 2.10. On 22.03.23, Sergey Kaplun via Tarantool-patches wrote: > From: Mike Pall > > (cherry picked from commit 7e662e4f87134f1e84f7bea80933e033c5bf53a3) > > The accessing of memory address for some operation `emit_rma()` may be > encoded in one of the following ways: > a. If the offset of the accessing address from the dispatch table > (pinned to r14 that is not changed while trace execution) fits into > 32-bit, then encode this as an access to 32-bit displacement > relative to r14. > b. If the offset of the accessing address from the mcode (i.e. rip) > fits into 32-bit, then encode this as an access to 32-bit > displacement relative to rip (considering long mode specifics and > `RID_RIP` hack). > c. If the address doesn't fit into 32-bit one and we use `mov` or > `movsd`, then encode 64-bit load from this address. > d. Elsewhere, encode it as an access to 32-bit (the address should fit > into 32-bit one) displacement (the only option for non-GC64 mode). > > So, each instruction in GC64 mode differs from `mov` or `movsd` should > be encoded via the last option. But if we got a 64-bit address with a > big enough offset it can't be encoded and the assertion in `ptr2addr()` > will fail. > > There are several cases, when `emit_rma()` is used with non `mov` > instruction: > * `IR_LDEXP` with `fld` instruction for loading constant > number `TValue` by address. > * `IR_OBAR` with the corresponding `test` instruction on > `marked` field of `GCobj`. > All these instructions require an additional register to store value by > address. We can't truly allocate a register here due to possibility to > break IR assembling which depends on specific register usage. So, we use > and restore r14 here for emitting. > > Also, this patch removes `movsd` from condition from the `x86Op` type > check, as far as it never uses for the `emit_rma()` routine (see also > `emit_loadk64()` for details). > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#8069 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-fix-emit-rma > PR: https://github.com/tarantool/tarantool/pull/8477 > Related issue: https://github.com/tarantool/tarantool/issues/8069 > > AFAICS, other places with `emit_rma()` usage are not related to the > patch as far as they take an offset for the address of JIT constants > stored in `jit_State`, so it always be near enough to dispatch. > > Side note: you may check test-correctness of the last check with GC by > changing the corresponding condition check on `GC_WHITES` in asm_obar to > CC_NZ (like it will be treated for incorrect check). Be carefull, member > that instructions are emitted from bottom to top! > > src/lj_emit_x86.h | 24 ++++- > test/tarantool-tests/fix-emit-rma.test.lua | 102 +++++++++++++++++++++ > 2 files changed, 123 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/fix-emit-rma.test.lua > > -- > 2.34.1 > -- Best regards, IM