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 3D34271E560; Fri, 8 Dec 2023 09:10:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3D34271E560 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1702015831; bh=+/CPGs6qisc2VJVdbfuhOkBCEDQoapGJjlq7wmP60DQ=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jPEk4Irwun9Po16O4apw2rX1Z4DTbb+L+kyiRVRJfaPbgL+1mwFR5B2tCwkQdILul e6YDFRsftnDVEpf+PgBsJHJdVq0yMTmcqnGZ3tMMtcCQfaXfSuBsgaxKOoVa0adhv/ +yoNtM4naj0FWowjr317R5SVmjOW8PXwQfRYB5Kw= Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 89DF96F44CD for ; Fri, 8 Dec 2023 09:10:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 89DF96F44CD Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2c9eca5bbaeso20564291fa.3 for ; Thu, 07 Dec 2023 22:10:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702015828; x=1702620628; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Up2tdmck+BNy+uYHB3dFp9Vwe0TOwBf3jKlSVloe5eM=; b=sGrhByvrOw+QTJaFcLbmtst+BdO9fogduvVbjkmueg/MGlWEcYLSdqtixq51mPuyah xsam8Dah+wtEY4n0KtIdXErUxqTMi8o/WxZRcFwfHMCqSyubtXGMKEQlBx7lhXsIrfxi RG4s+E18tKn7ZTLESR6GOF8eMqsQHu58zZ0Qyi3BjaD9ylJPD1lY/33VbIYXC3QR1HnD n6l1SWcNVzb3j79pjWk70n3AO7s9rxS6rEpqhUlOPU4lZ0VvVkt1XkneL9yhxr50+HHl gwdrFcKcNOuWA0keQGYMzT9nlT/nkzjzN1qnzNG8mnbcThanChXwSDXcNZ+wYHetmuWu mr7Q== X-Gm-Message-State: AOJu0YwV1SOp6VGCZqK980pCV7QGee4n9qOyNVa5gVQDlkOqSrdxRci7 buBcb++CFtXY0+x53sS6FvbXLlk3NEMTSJTA X-Google-Smtp-Source: AGHT+IGsQ653l69U//CFLli/ong/D2coQxDpm/KYnxTXmGLUeQt8eSpTEGWWVywfAbJDMMW9RXV5Eg== X-Received: by 2002:a2e:9203:0:b0:2c9:edfb:710a with SMTP id k3-20020a2e9203000000b002c9edfb710amr1080773ljg.192.1702015828131; Thu, 07 Dec 2023 22:10:28 -0800 (PST) Received: from localhost.localdomain ([93.175.28.1]) by smtp.gmail.com with ESMTPSA id a24-20020a2eb178000000b002ca02370000sm136177ljm.56.2023.12.07.22.10.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 07 Dec 2023 22:10:26 -0800 (PST) To: tarantool-patches@dev.tarantool.org, sergeyb@tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Date: Fri, 8 Dec 2023 09:10:23 +0300 Message-Id: <20231208061023.89512-1-max.kokryashkin@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit] sysprof: disable runtime host symtab updates 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: Maksim Kokryashkin via Tarantool-patches Reply-To: Maksim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Maxim Kokryashkin The symtab update for newly loaded shared libraries requires memory allocation, which is not signal-safe and can cause crashes. Updating symtab in a VM hook is not a viable option either, as there are no guarantees that the symbol will be dumped before its address is streamed. This patch completely disables the runtime updates of the symtab for host symbols. That means all Lua-C modules, FFI modules, and shared libraries must be loaded before starting the profiler. There is no test along with the patch for two main reasons: 1. The signal should land on an instruction inside the allocator such that the second allocator call would cause a crash because of an inconsistent inner state. Although we have ptrace-based machinery for testing, the control is not that fine-grained. The only option we have left is to rely on empirical offsets, which is not a robust solution. Moreover, it is possible to build LuaJIT with `malloc` as an allocator, and the test should be adapted to that too. Needless to say, malloc sources may differ from platform to platform, making the test unreliable. 2. Regression is unlikely here since this patch removes the only call that could allocate memory inside the signal handler. Resolves tarantool/tarantool#8140 --- Branch: https://github.com/tarantool/luajit/tree/fckxorg/gh-8140-crash-in-allocator Issue: https://github.com/tarantool/tarantool/issues/8140 PR: https://github.com/tarantool/tarantool/pull/9460 src/lj_sysprof.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lj_sysprof.c b/src/lj_sysprof.c index c6c20de2..88c7a41b 100644 --- a/src/lj_sysprof.c +++ b/src/lj_sysprof.c @@ -75,7 +75,6 @@ struct sysprof { luam_Sysprof_backtracer backtracer; /* Backtracing function for the host stack. */ lj_profile_timer timer; /* Profiling timer. */ int saved_errno; /* Saved errno when profiler failed. */ - uint32_t lib_adds; /* Number of libs loaded. Monotonic. */ }; /* ** XXX: Only one VM can be profiled at a time. @@ -100,7 +99,11 @@ static int is_unconfigured(struct sysprof *sp) static void stream_prologue(struct sysprof *sp) { - lj_symtab_dump(&sp->out, sp->g, &sp->lib_adds); + /* + ** XXX: Must be zero for the symtab module to dump all loaded libraries. + */ + uint32_t unused_lib_adds = 0; + lj_symtab_dump(&sp->out, sp->g, &unused_lib_adds); lj_wbuf_addn(&sp->out, ljp_header, sizeof(ljp_header)); } @@ -256,8 +259,6 @@ static void stream_guest(struct sysprof *sp, uint32_t vmstate) static void stream_host(struct sysprof *sp, uint32_t vmstate) { - struct lua_State *L = gco2th(gcref(sp->g->cur_L)); - lj_symtab_dump_newc(&sp->lib_adds, &sp->out, LJP_SYMTAB_CFUNC_EVENT, L); lj_wbuf_addbyte(&sp->out, (uint8_t)vmstate); stream_backtrace_host(sp); } -- 2.39.3 (Apple Git-145)