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 E9E1D5426C8; Mon, 24 Jul 2023 19:10:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E9E1D5426C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1690215045; bh=ZsflYjW/SKvKcsm18e/hCkTd5sCEFMkAyfklVsemtrw=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=FrKly9eC4+qzJLmXnKVAzu/vWciTbzqvHIodJmqXBHjDdMpc5wYYSF3IsdpXqO+0B QYrRgruNglMU+tBp2lhoN54usWnMQAqSG2xw0jkQa5L0uSnBc3VC4bcHZhcj/Nx00r +zsOkJL7iaG0djDJ7ItUiaJucXycmEMWjHFtHxUw= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 A88635426C8 for ; Mon, 24 Jul 2023 19:10:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A88635426C8 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1qNy8w-000554-Of; Mon, 24 Jul 2023 19:10:43 +0300 Message-ID: <601f955a-d281-9e09-aad0-06366bb44bbe@tarantool.org> Date: Mon, 24 Jul 2023 19:10:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: Maxim Kokryashkin , tarantool-patches@dev.tarantool.org, skaplun@tarantool.org References: <20230724144148.289140-1-m.kokryashkin@tarantool.org> Content-Language: en-US In-Reply-To: <20230724144148.289140-1-m.kokryashkin@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9227D43F3CB451B410BF03CE1B48E4F6DE839A4FE7D2C1877182A05F538085040360D1A1A027B6D186562875348857EE9DCDA24027D0725C3CBA0AA18CDEC5AF2 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7484B509D84968742EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378ABD31E9FF1CD53C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8105F00C8D2EE49967BCF23782DC2DCC8117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F4460429728776938767073520599709FD55CB46A6E5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269176DF2183F8FC7C007B7C037059AA88D68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C5351985B4A98E2A443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A50EB6568F9FF8706178F78AE8755993B291948E5B6077A485F87CCE6106E1FC07E67D4AC08A07B9B0A816C540FC8EEC30CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFC70C8F8BB6DFFECBFEA72AD84C91DAB835421205BB5AD782F87B89AFECA7F11A80BEFAEC9D272008C81315DA36159FFB8A0F9E445E78AC9A765A085C83A21B1BA74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojQWAQuM+Ftg/UXL7+Az0imA== X-DA7885C5: 3365246249751FB80EBE207757CFA5D8356213D87173E1F8BAEDDAA33473CE7C262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F73930F533AC2B33E986B66A75C7973D36EA30F2EE15692FC246BDD788429FD8613638ED9BB8B05EE7B3AFB559BB5D741EB96D19CD4E7312BAA970A04DAD6CC59E3365FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix frame for on-trace out-of-memory error. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Max, Thanks for the patch! LGTM P.S. I've made an attempt to reproduce the original issue without a portion of Lua C code and build userdata with calling "newproxy()", but attempt is failed, so  seems Lua C is required here. Also I'm upset that test triggers an OOM but we cannot reliably distinct that triggered OOM is exactly that OOM that we want. Discussed this verbally, perhaps such places should be closed with other tests Sergey On 7/24/23 17:41, Maxim Kokryashkin wrote: > Reported by ruidong007. > > (cherry-picked from commit 2d8300c1944f3a62c10f0829e9b7847c5a6f0482) > > When an on-trace OOM error is triggered from a frame that is > child in regard to `jit_base`, and `L->base` is not updated > correspondingly (FUNCC, for example), it is possible to > encounter an inconsistent Lua stack in the error handler. > > This patch adds a fixup for OOM errors on trace that always > sets the Lua stack base to `jit_base`, so the stack is > now consistent. > > Part of tarantool/tarantool#8825 > --- > PR: https://github.com/tarantool/tarantool/pull/8909 > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-1004-oom-error-frame LJ issue: https://github.com/LuaJIT/LuaJIT/issues/1004 > src/lj_err.c | 4 ++++ > test/tarantool-tests/CMakeLists.txt | 1 + > .../lj-1004-oom-error-frame.test.lua | 24 +++++++++++++++++++ > .../lj-1004-oom-error-frame/CMakeLists.txt | 1 + > .../lj-1004-oom-error-frame/testoomframe.c | 17 +++++++++++++ > 5 files changed, 47 insertions(+) > create mode 100644 test/tarantool-tests/lj-1004-oom-error-frame.test.lua > create mode 100644 test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt > create mode 100644 test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c > > diff --git a/src/lj_err.c b/src/lj_err.c > index 9903d273..09729791 100644 > --- a/src/lj_err.c > +++ b/src/lj_err.c > @@ -802,6 +802,10 @@ LJ_NOINLINE void lj_err_mem(lua_State *L) > { > if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */ > lj_vm_unwind_c(L->cframe, LUA_ERRMEM); > + if (LJ_HASJIT) { > + TValue *base = tvref(G(L)->jit_base); > + if (base) L->base = base; > + } > if (curr_funcisL(L)) L->top = curr_topL(L); > setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM)); > lj_err_throw(L, LUA_ERRMEM); > diff --git a/test/tarantool-tests/CMakeLists.txt b/test/tarantool-tests/CMakeLists.txt > index 6218f76a..93230677 100644 > --- a/test/tarantool-tests/CMakeLists.txt > +++ b/test/tarantool-tests/CMakeLists.txt > @@ -66,6 +66,7 @@ add_subdirectory(lj-416-xor-before-jcc) > add_subdirectory(lj-601-fix-gc-finderrfunc) > add_subdirectory(lj-727-lightuserdata-itern) > add_subdirectory(lj-flush-on-trace) > +add_subdirectory(lj-1004-oom-error-frame) > > # The part of the memory profiler toolchain is located in tools > # directory, jit, profiler, and bytecode toolchains are located > diff --git a/test/tarantool-tests/lj-1004-oom-error-frame.test.lua b/test/tarantool-tests/lj-1004-oom-error-frame.test.lua > new file mode 100644 > index 00000000..fd167d14 > --- /dev/null > +++ b/test/tarantool-tests/lj-1004-oom-error-frame.test.lua > @@ -0,0 +1,24 @@ > +local tap = require('tap') > +local test = tap.test('lj-1004-oom-error-frame'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > + ['Test requires GC64 mode disabled'] = require('ffi').abi('gc64'), > +}) > + > +test:plan(1) > + > +local testoomframe = require('testoomframe') > + > +local anchor = {} > +local function extra_frame(val) > + table.insert(anchor, val) > +end > + > +local function chomp() > + while true do > + extra_frame(testoomframe.allocate_userdata()) > + end > +end > + > +local st, _ = pcall(chomp) > +test:ok(st == false, 'on-trace error handled successfully') > +os.exit(test:check() and 0 or 1) > diff --git a/test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt b/test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt > new file mode 100644 > index 00000000..3bca5df8 > --- /dev/null > +++ b/test/tarantool-tests/lj-1004-oom-error-frame/CMakeLists.txt > @@ -0,0 +1 @@ > +BuildTestCLib(testoomframe testoomframe.c) > diff --git a/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c > new file mode 100644 > index 00000000..13071b4e > --- /dev/null > +++ b/test/tarantool-tests/lj-1004-oom-error-frame/testoomframe.c > @@ -0,0 +1,17 @@ > +#include > +#include > + > +static int allocate_userdata(lua_State *L) { > + lua_newuserdata(L, 16); > + return 1; > +} > + > +static const struct luaL_Reg testoomframe[] = { > + {"allocate_userdata", allocate_userdata}, > + {NULL, NULL} > +}; > + > +LUA_API int luaopen_testoomframe(lua_State *L) { > + luaL_register(L, "testoomframe", testoomframe); > + return 1; > +}