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 85A3D141DA19; Wed, 25 Jun 2025 13:05:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 85A3D141DA19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1750845929; bh=nWOogYOoVN8BBmcqqqbDbJt5bQjlVxAksL4XN+WAC9E=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=W9Jm7y2j5Zl7M/MJjxpz/QDf19FFvjcrMYsO2CZtqgbTNB7zUH8COz6oQf/lu8b+e DhizPOZOOGktNkhoAbBc9GJ3AcOz4OSV8oZqxRR74Q+E3y9IEbOPcMzB9ES+oXSI4N 6r3CoEaHABVA+jIABOdr7WkaFniHBJCUREOS125w= Received: from send240.i.mail.ru (send240.i.mail.ru [95.163.59.79]) (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 819843952C0 for ; Wed, 25 Jun 2025 13:05:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 819843952C0 Received: by exim-smtp-6c944dc5d-rndnw with esmtpa (envelope-from ) id 1uUN0Q-000000009ez-2qmF; Wed, 25 Jun 2025 13:05:27 +0300 To: Sergey Bronnikov Date: Wed, 25 Jun 2025 13:03:27 +0300 Message-ID: <20250625100327.5563-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D919194CF4FC66049C0A9CD0C14EACC91FBAD6F40ABEEC9E00894C459B0CD1B9223079E494BBA1365D1BE6A8D71B10A5888323752ED9197E803DA0848C9F79C4DAEE934B56E2D9F8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72F22E6DC541F75D9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB553375669C5B23AD11DEB7B9DFAC8FF009D082C2F233C0E70291875D55618E657B5ECE41389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0A29E2F051442AF778941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B64854413538E1713FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249AEF4DCA51A11EB8276E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B18E7440D383AA13B3AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FCF1175FABE1C0F9B6E2021AF6380DFAD18AA50765F7900637F09814068C508CC822CA9DD8327EE4930A3850AC1BE2E73589424AA0EF8DE9BAC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5BA0516A63D703AA65002B1117B3ED69652069EE27F2EF825ED71F038FC046993823CB91A9FED034534781492E4B8EEADA757276DBF662F3EC79554A2A72441328621D336A7BC284946AD531847A6065A17B107DEF921CE79BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF77DD89D51EBB7742D3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFEAEA0EB4402727479FABB0D774E7502CB9DA4794A0966A7461D4D4036F735CA4A703FE8D8B528221DA027526E6D8A3D2A9D9CB2E0364DA0E13A759CBFB8B90E48A958C618BF91CD15F4332CA8FE04980913E6812662D5F2A5EAB5682573093F7837F15F2B5E4A70B33F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVVWXk7QTiVzH9S7H3DjvqkY= X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B599D468B88662365283DE06ABAFEAF670567E1619E8B44ACC4B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] sysprof: fix sampling outside the VM 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" If the signal by timer is handled outside the VM, the `g->vmstate` equals zero. This was interpreted by the sysprof as the trace with the corresponding number and leads to the assertion failure. This patch fixes that by checking this case and dumping only the host stack outside the VM. Resolves tarantool/tarantool#11185 Resolves tarantool/tarantool#11429 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-11185-stream-trace-assert Related issues: * https://github.com/tarantool/tarantool/issues/11185 * https://github.com/tarantool/tarantool/issues/11429 Mentinoned in the test: * https://github.com/tarantool/tarantool/issues/10803 src/lj_sysprof.c | 4 +- .../gh-11185-stream-trace-assert.test.c | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/tarantool-c-tests/gh-11185-stream-trace-assert.test.c diff --git a/src/lj_sysprof.c b/src/lj_sysprof.c index cf6161a5..013df2cd 100644 --- a/src/lj_sysprof.c +++ b/src/lj_sysprof.c @@ -297,7 +297,9 @@ static void sysprof_record_sample(struct sysprof *sp, siginfo_t *info) { global_State *g = sp->g; uint32_t _vmstate = ~(uint32_t)(g->vmstate); - uint32_t vmstate = _vmstate < LJ_VMST_TRACE ? _vmstate : LJ_VMST_TRACE; + /* `g->vmstate` is 0 outside the VM. Hence, dump only the host stack. */ + uint32_t vmstate = ~_vmstate == 0 ? LJ_VMST_INTERP : + _vmstate < LJ_VMST_TRACE ? _vmstate : LJ_VMST_TRACE; lj_assertX(pthread_self() == sp->thread, "bad thread during sysprof record sample"); diff --git a/test/tarantool-c-tests/gh-11185-stream-trace-assert.test.c b/test/tarantool-c-tests/gh-11185-stream-trace-assert.test.c new file mode 100644 index 00000000..c4d7ea67 --- /dev/null +++ b/test/tarantool-c-tests/gh-11185-stream-trace-assert.test.c @@ -0,0 +1,54 @@ +#include "lua.h" +#include "lauxlib.h" + +/* Need for skipcond for OS and ARCH. */ +#include "lj_arch.h" + +#include "test.h" +#include "utils.h" + +#include +#include + +/* + * Check that there is no assertion failure during the dump of the + * sample outside the VM. + */ +static int gh_11185_stream_trace_assert(void *test_state) +{ + lua_State *L = test_state; + (void)luaL_dostring(L, + "misc.sysprof.start({mode = 'C', path = '/dev/null'})"); + + pid_t self_pid = getpid(); + /* Dump the single sample outside the VM. */ + kill(self_pid, SIGPROF); + + /* No assertion fail -- stop the profiler and exit. */ + (void)luaL_dostring(L, "misc.sysprof.stop()"); + return TEST_EXIT_SUCCESS; +} + +int main(void) +{ +#if LUAJIT_USE_VALGRIND + return skip_all("Disabled due to #10803"); +#elif LUAJIT_DISABLE_SYSPROF + return skip_all("Sysprof is disabled"); +#else /* LUAJIT_DISABLE_SYSPROF */ + if (LUAJIT_OS != LUAJIT_OS_LINUX) + return skip_all("Sysprof is implemented for Linux only"); + if (LUAJIT_TARGET != LUAJIT_ARCH_X86 + && LUAJIT_TARGET != LUAJIT_ARCH_X64) + return skip_all("Sysprof is implemented for x86_64 only"); + + lua_State *L = utils_lua_init(); + + const struct test_unit tgroup[] = { + test_unit_def(gh_11185_stream_trace_assert) + }; + const int test_result = test_run_group(tgroup, L); + utils_lua_close(L); + return test_result; +#endif /* LUAJIT_DISABLE_SYSPROF */ +} -- 2.49.0