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 376AA5764A0; Wed, 9 Aug 2023 18:41:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 376AA5764A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1691595687; bh=v3RbYfQdHBKbzkQwfilXq+S6p8q6+b0+Jf+3TzPZtRE=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=omPVPovGEvKM8V+KfglHpPWoThMIagUxVs9G+5J9zVg3S6m/IZGszePWCadugTL9o 1Llzb5vkbUbRymMb5hxTjoLN7IIqZ9eLBVPd+maiIp7MAUz95B2NhmTurSSmfbaNRh 2X4MeCv7bVfO31bS871L1zvhYgP0Wf128fLc3Tg4= 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 EE52E57648B for ; Wed, 9 Aug 2023 18:40:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EE52E57648B Received: by smtp32.i.mail.ru with esmtpa (envelope-from ) id 1qTlIu-003Nbf-11; Wed, 09 Aug 2023 18:40:56 +0300 To: Igor Munkin , Sergey Bronnikov Date: Wed, 9 Aug 2023 18:35:50 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD969E04B5EED670DC804E38A5F9341E5D89B81E0241E25E490182A05F5380850406EC42C528514C18C39BC923D1AD8FECE6416DCC602E438B18D4E79E850EFD82A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72F22E6DC541F75D9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371750936FC250F8708638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B0DE9B52580D9097919876C455C056F3117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC2FD16FCC8DB5F8BEA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751F2CC0D3CB04F14752D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE4B6963042765DA4B3D5BA627BF9F2FCFD8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE368E4D7E803FA7AD503F1AB874ED89028C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637B8F435DEDE9E76EBEFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A5EA9AA64B413CE1612F6BEBBAB7CE8134FC72FAD20FC545BAF87CCE6106E1FC07E67D4AC08A07B9B04B3849D6E5CCBAFDC79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742424CF958EAFF5D571004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34682FD2D2951524C555DC28A8AC4AF996E1E4F69302B652A2CBD70B6E2982297FDF7B33785237DE4B1D7E09C32AA3244CDFCF9742D7C228411B954E5D1C52367633C9DC155518937FBAD658CF5C8AB4025DA084F8E80FEBD3202CD0F03380D9577A83BD0C44CE203720ABEDE4BBDD9CDD X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojUzxoxvtYX2pv7fbVKyzzQg== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769A0DC0DED60E0048739BC923D1AD8FECEBC4EE72AB2E748C5DEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: [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: 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" 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 adds the corresponding comparisons masked values with instruction 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 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 following benefits: * Be in sync with the LuaJIT upstream not only for x86_64, arm64 architectures. * Avoid conflicts during the future backporting. 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