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 7DD7CB021DA; Sun, 5 May 2024 15:34:17 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7DD7CB021DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1714912457; bh=aY01er1TnvULY119X7/wVwX9aulsIjP9lToSoRg7wlU=; 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=ixafxmsNLjvLhE26iA3WgCaPdxt8wP/9mkTuliaEeW7Ps4Gp9EnUCBDIU9zvdZBLc y9EVQ6/TouXcXYkrg77pJg9umLnxRi/7nwAFvKN6Qz6v10PrALa5a4Qoy+a28iHJRZ 7NdYdn45/vH0QPnDB9DpbbqxR1zWojE1BlCpOiP8= Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [95.163.41.84]) (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 9FD29B021DA for ; Sun, 5 May 2024 15:34:16 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9FD29B021DA Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1s3b4J-0000000EmDH-3rMT; Sun, 05 May 2024 15:34:16 +0300 Date: Sun, 5 May 2024 15:34:15 +0300 To: Sergey Kaplun Message-ID: References: <20240424103720.9464-1-skaplun@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240424103720.9464-1-skaplun@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9C1015E4FDF537780A2F08B6F60F716B4DB387A7C23605DDE182A05F538085040D47E15990F830ED703ED270C30F246C5D858AE5F8C5672A8A5E5CAF7D1578E232A407B5933F66546 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE728F774C865CF4B07EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370218B86C916BF3528638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8F89DA8AEF56F73876F6ED658C80210E6B1421A3A23A0EA55CC7F00164DA146DAFE8445B8C89999728AA50765F7900637D0FEED2715E18529389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8062BEEFFB5F8EA3EF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C2A336C65186350916E0066C2D8992A164AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C32F36E1858E9CF555BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF17B107DEF921CE791DD303D21008E298D5E8D9A59859A8B6D082881546D9349175ECD9A6C639B01B78DA827A17800CE7BB1D8AFE8C29F51C731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A53D62CFECEEE4BE075002B1117B3ED6968D8C3C2D9E9A81F7484B8D70797403F6823CB91A9FED034534781492E4B8EEAD003C2D46C52F18F2BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF6E651D0FBD222395899344143EFE533A65AB69080584D24D5EC81FF2CD184536AF1510F4A86D2C81643425263F8C9A4E33E35B1B3986168B0A66781BFA3C5534D3F26D141A7C77BD5F4332CA8FE04980913E6812662D5F2A54F6898A6FDCBDC72A617DFBE5FEC2C6383653B6C8D9AE0FD16FCAA6493B703A X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj3Gch4W13RDFBBIn1YSrb7w== X-Mailru-Sender: 00097D31F91C944BAED0411CFB052B985A93CC871C52B315B951B70A5BD4BD8EDE2814F15569F059D38A1BEA64D5C64A04C9FB44FCBCE9EE92D99EB8CC7091A7ECEABDC5717908DEF544888E8238EB4872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Check for IR_HREF vs. IR_HREFK aliasing in non-nil store check. 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 two nits below. On Wed, Apr 24, 2024 at 01:37:20PM UTC, Sergey Kaplun wrote: > From: Mike Pall > > Thanks to Peter Cawley. > > (cherry picked from commit 658530562c2ac7ffa8e4ca5d18856857471244e9) > > The `lj_opt_fwd_wasnonnil()` skips the check for HREF and HREFK that may > alias. Hence, the guard for the non-nil value may be skipped, and the > `__newindex` metamethod call is omitted too. > > This patch adds the aforementioned check for different reference types > (HREF vs. HREFK), which were not detected by the previous analysis. > Also, the helper macro `irt_isp32()` is introduced to check that the IR > type is `IRT_P32` (KSLOT type). > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9924 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1133-fwd-href-hrefk-alias > Related issues: > * https://github.com/tarantool/tarantool/issues/9924 > * https://github.com/LuaJIT/LuaJIT/issues/1133 > diff --git a/test/tarantool-tests/lj-1133-fwd-href-hrefk-alias.test.lua b/test/tarantool-tests/lj-1133-fwd-href-hrefk-alias.test.lua > new file mode 100644 > index 00000000..6b72c97a > --- /dev/null > +++ b/test/tarantool-tests/lj-1133-fwd-href-hrefk-alias.test.lua > @@ -0,0 +1,94 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate the LuaJIT's incorrect aliasing check > +-- for HREFK and HREF IRs during the non-nil check. > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1133. > + > +local test = tap.test('lj-1133-fwd-href-hrefk-alias'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > +test:plan(1) > + > +local rawset = rawset > + > +-- The maximum value that can be stored in a 16-bit `op2` > +-- field in HREFK IR. > +local HASH_NODES = 65535 > + > +-- Amount of iteration to compile and execute the trace. Typo: s/iteration/iterations/ > +local LOOP_LIMIT = 4 > + > +-- Function to be called twice to emit the trace and take the side > +-- exit. > +local function trace_aliased_tables(t1, t2) > + -- The criteria is the number of new index creations. > + local count = 0 > + local mt = {__newindex = function(t, k, v) > + count = count + 1 > + rawset(t, k, v) > + end} > + setmetatable(t1, mt) > + setmetatable(t2, mt) > + > + for _ = 1, LOOP_LIMIT do > + -- XXX: Keys values have no special meaning here, just be sure > + -- that they are HREF/HREFK and not in the array table part. > + -- `t1` is empty, emitting HREFK. > + t1[10] = 1 > + -- `t2` on recording has more than `HASH_NODES` table nodes, > + -- so this emits HREF. > + t2[10] = nil > + -- Resolve `__newindex` if t1 == t2. > + -- `lj_opt_fwd_wasnonnil()` missed the check that HREFK and > + -- HREF may alias before the patch, so the guarded HLOAD IR > + -- with the corresponding snapshot is skipped. > + -- The difference in the emitted IR before and afterthe patch Typo: s/afterthe/after the/ > + -- is the following: > + -- | 0004 > tab SLOAD #1 T > + -- | ... > + -- | 0009 p32 FLOAD 0004 tab.node > + -- | 0010 > p32 HREFK 0009 +10 @0 > + -- | 0011 > num HLOAD 0010 > + -- | 0012 num HSTORE 0010 +1 > + -- | .... SNAP #1 > + -- | 0013 > tab SLOAD #2 T > + -- | 0014 int FLOAD 0013 tab.asize > + -- | 0015 > int ULE 0014 +10 > + -- | 0016 p32 HREF 0013 +10 > + -- | 0017 > p32 NE 0016 [0x415554e8] > + -- | 0018 > num HLOAD 0016 > + -- | 0019 nil HSTORE 0016 nil > + -- | -0020 num HSTORE 0010 +30 > + -- | .... SNAP #2 > + -- | +0020 > num HLOAD 0010 > + -- | +0021 num HSTORE 0010 +30 > + -- | +.... SNAP #3 > + -- > + -- Hence, the taken exit is not resolving `__newindex` before > + -- the patch. > + t1[10] = 1 > + -- The exit 2 of the trace is here. > + -- Resolve `__newindex` if t1 ~= t2. > + t2[10] = 1 > + end > + -- `__newindex` is called twice on the first iteration and once > + -- on each other. > + return count == LOOP_LIMIT + 1 > +end > + > +-- Create a big table to emit HREF IR (not HREFK) to trick > +-- the alias checking. > +local bigt = {} > +for i = 1, HASH_NODES + 1 do > + bigt[-i] = true > +end > + > +jit.opt.start('hotloop=1') > + > +trace_aliased_tables({}, bigt) > + > +-- Now use tables that are aliased. > +local smallt = {} > +test:ok(trace_aliased_tables(smallt, smallt), 'aliasing check is correct') > + > +test:done(true) > -- > 2.44.0 >