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 AFCD85AA586; Tue, 15 Aug 2023 12:36:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AFCD85AA586 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1692092192; bh=pJyEKKFFttT7rcQJKYTCpcTNimE8WnHARSKxaBqZWQU=; 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=dqN972c49C1zq1vHcQH5AglA1zu4XjknnALB2i0wEqp6QSAafvz9x4v2oRMaQRop+ EGvqz8tN45JE9PLmDVWqYrZbDYpk/nPWcAyDAX3xxyFES9U+Nzn4/3JtFYD/qKh9eo 046AGcMtwJsR4+ZxPSOZY7kNU62A+GrMupu6M6xo= 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 892A95AA586 for ; Tue, 15 Aug 2023 12:36:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 892A95AA586 Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1qVqTV-002u5a-2a; Tue, 15 Aug 2023 12:36:31 +0300 Date: Tue, 15 Aug 2023 12:36:29 +0300 To: Sergey Kaplun Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mailru-Src: smtp X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD969E04B5EED670DC804E38A5F9341E5D8C5E4A5EF3DB2E749182A05F538085040EBFCB020B7C78F23FB107E4B0E5262E6224D78DDAAD6E9D4AF8DA857F5746312 X-C1DE0DAB: 0D63561A33F958A5E963BA54A46CC0E4BEB26E41E7BF2546A83E14F4A05CDC4FF87CCE6106E1FC07E67D4AC08A07B9B0CF7CD7A0D5AA5F25CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742DC8270968E61249B1004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34431D0341F6B74DD312EC3E8A0C47FE932CEE4709B40154A407C59A9D81DEFA3BA40A1E0819BAD7071D7E09C32AA3244C09F4513B8C61AFE56218EBF6BF1D6FAEE3D93501275E802FBAD658CF5C8AB4025DA084F8E80FEBD396F07DFE06A4A8314E894E437E78228B66933FA05BD8EF0CAD958392AE682691 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojJ1ceUZTkowl338Crnw/Iuw== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE40758A87153C1EAC6221DB73743C5B3BF960A2EFD50A1F25EA8D51284F0FE6F529ABC7555A253F5B200DF104D74F62EE79D27EC13EC74F6107F4198E0F3ECE9B5443453F38A29522196 X-Mras: OK Subject: Re: [Tarantool-patches] [PATCH luajit 01/19] MIPS: Use precise search for exit jump patching. 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! LGTM, except for a few comments below. On Wed, Aug 09, 2023 at 06:35:50PM +0300, Sergey Kaplun via Tarantool-patches wrote: > From: Mike Pall > > Contributed by Djordje Kovacevic and Stefan Pejic. > > (cherry-picked from commit 7381b620358c2561e8690149f1d25828fdad6675) > > Without the aforementioned checks, some non-branch instructions may be > interpreted as some branch due to memory address collisions. This patch Please add a more comprehensive description of behavior before the patch. Because of magic values it is not obvious that the difference between the current PC and the jump address is XORed with the opcode, to make sure that this is a branching instruction. Typo: s/some branch/branches/ > adds the corresponding comparisons masked values with instruction Typo: s/comparisons masked values/mask values for comparisons/ > opcodes used in the LuaJIT: > * `MIPSI_BEQ` for `beq` and `bne`, > * `MIPSI_BLTZ` for `bltz`, `blez`, `bgtz` and `bgez`, > * `MIPSI_BC1F` for `bc1f` and `bc1t`, > see and MIPS Instruction Set Manual [1] for > details. > > To reproduce this failure, we need specific memory mapping, so testcase Typo: s/testcase/the test case/ > is omitted. > > Since MIPS architecture is not supported by Tarantool (at the moment) > this patch is not necessary for backport. OTOH, it gives to us the Typo: s/gives to us/gives us/ > following benefits: > * Be in sync with the LuaJIT upstream not only for x86_64, arm64 > architectures. > * Avoid conflicts during the future backporting. Typo: s/during the future/during future/ > So, it's more useful to backport some of the patches to avoid conflicts > with the future patch series. > > [1]: https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00086-2B-MIPS32BIS-AFP-6.06.pdf > > Sergey Kaplun: > * added the description for the problem > > Part of tarantool/tarantool#8825 > --- > src/lj_asm_mips.h | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h > index 03417013..03215821 100644 > --- a/src/lj_asm_mips.h > +++ b/src/lj_asm_mips.h > @@ -2472,7 +2472,11 @@ void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, MCode *target) > MCode tjump = MIPSI_J|(((uintptr_t)target>>2)&0x03ffffffu); > for (p++; p < pe; p++) { > if (*p == exitload) { /* Look for load of exit number. */ > - if (((p[-1] ^ (px-p)) & 0xffffu) == 0) { /* Look for exitstub branch. */ > + /* Look for exitstub branch. Yes, this covers all used branch variants. */ > + if (((p[-1] ^ (px-p)) & 0xffffu) == 0 && > + ((p[-1] & 0xf0000000u) == MIPSI_BEQ || > + (p[-1] & 0xfc1e0000u) == MIPSI_BLTZ || > + (p[-1] & 0xffe00000u) == MIPSI_BC1F)) { > ptrdiff_t delta = target - p; > if (((delta + 0x8000) >> 16) == 0) { /* Patch in-range branch. */ > patchbranch: > -- > 2.41.0 > Best regards, Maxim Kokryashkin