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 96B9CB87965; Fri, 1 Mar 2024 16:21:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 96B9CB87965 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1709299293; bh=LAuElxjG1f+1hXxugz0eZ5QoR1CRmqAGi3xbp04emOI=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=zqpgkI+nyLFkNUZnB0Gh7xIJqhw6CvTfeAVy+XjAwlx6TQ5bXkcJNw49Qv9GoY3cW Hf7v9mB5B/CHFNof3UD5k1ECHHJUSyWv+K9RuduNwPMrtTyKYp37UNa53XJ6QBYQHU MPPcGAeb/ZX3SHDNrFumLs6wMzv5uhXs9T9mVtpE= Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 C67B8B87965 for ; Fri, 1 Mar 2024 16:21:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C67B8B87965 Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so22947611fa.3 for ; Fri, 01 Mar 2024 05:21:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709299292; x=1709904092; 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=gdO661bxv0WCUb5go6aOuPXaG8Q9Y70lSvgOs0F1TnA=; b=bFcepq/t5wlsLqMMC0sjxogoNS4Xc2bG3c2eX2dCrwDQ+dIjLy8Rp9W+3U7SFYeIol X61jsjx8BekJd9iG6WJgMUb7A8vWPkfDI/0abIr+PDq7Ogyqn4+Ain/DNIj3Qgdf4+ax QoPSTocr7wzaS4AHDJjdxyduNpLCYLN9hC28hO2I4xNVQk9k9AtQQo57m5ieixRa5DKJ oaBOhfTm3Ztfz2zoZ2u9oK8dh2+1wlNFVo5OEojRIymU2UVEruCAeh1HlS8Rm8TGudUJ lI3SPOd7/88xleoK2mSPU7LyEaUnKaqRJtVv26HDZk2aHHPWDvDPwU07Xoprm9GQEnSg NIBA== X-Gm-Message-State: AOJu0YxCl2hf4x0Lg41KROZGAVCPjMWvZ/qDZ69L5HsdzCvvShkDqF7O H6KEei4dro1rIDMoEGDJsce5qvbkAtXmoBdqEPISJIe/fxiyBmjPNyidFn7Tr1I= X-Google-Smtp-Source: AGHT+IFF2YF93UDdQO+YRzmwaXzmcsD9GNgt0KLB3U08TM9SmNo0CAIXu/U2ZJb8zEu2wgWjq6+njQ== X-Received: by 2002:a2e:a545:0:b0:2d2:a3c4:4f with SMTP id e5-20020a2ea545000000b002d2a3c4004fmr1340031ljn.35.1709299291392; Fri, 01 Mar 2024 05:21:31 -0800 (PST) Received: from fckxorg.mail.msk ([2a00:1148:b0ba:16:a3e8:bdc1:dbed:dbc8]) by smtp.gmail.com with ESMTPSA id h19-20020a2eb0f3000000b002d08f3640b5sm598878ljl.11.2024.03.01.05.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 05:21:30 -0800 (PST) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org, sergeyb@tarantool.org Date: Fri, 1 Mar 2024 16:21:23 +0300 Message-ID: <20240301132127.136533-1-m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v2] Throw any errors before stack changes in trace stitching. 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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Thanks to doujiang24. (cherry-picked from commit 3f9389edc6cdf3f78a6896d550c236860aed62b2) The Lua stack is changed in the `recff_stitch`, so if the trace is aborted, for example, when the `maxsnap` is reached, and an error is thrown from there, the execution continues with an unbalanced stack. This patch adds a check for snapshot overflow to the `recff_stitch` to overcome the issue for the `LJ_TRERR_SNAPOV` case, but other cases remain unresolved and should be fixed in other series. For a detailed description of the remaining cases, see the issue[1]. [1]: https://github.com/LuaJIT/LuaJIT/issues/1166 Maxim Kokryashkin: * added the description and the test for the problem Part of tarantool/tarantool#9595 --- Changes in v2: - Fixed comments as per review by Sergey Kaplun Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-720-errors-before-stitch src/lj_ffrecord.c | 4 ++++ .../lj-720-errors-before-stitch.test.lua | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/tarantool-tests/lj-720-errors-before-stitch.test.lua diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 1b2ddb72..e3ed80fb 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -107,6 +107,10 @@ static void recff_stitch(jit_State *J) const BCIns *pc = frame_pc(base-1); TValue *pframe = frame_prevl(base-1); + /* Check for this now. Throwing in lj_record_stop messes up the stack. */ + if (J->cur.nsnap >= (MSize)J->param[JIT_P_maxsnap]) + lj_trace_err(J, LJ_TRERR_SNAPOV); + /* Move func + args up in Lua stack and insert continuation. */ memmove(&base[1], &base[-1-LJ_FR2], sizeof(TValue)*nslot); setframe_ftsz(nframe, ((char *)nframe - (char *)pframe) + FRAME_CONT); diff --git a/test/tarantool-tests/lj-720-errors-before-stitch.test.lua b/test/tarantool-tests/lj-720-errors-before-stitch.test.lua new file mode 100644 index 00000000..00fb0b9b --- /dev/null +++ b/test/tarantool-tests/lj-720-errors-before-stitch.test.lua @@ -0,0 +1,20 @@ +local tap = require('tap') +local test = tap.test('lj-720-errors-before-stitch'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), +}) +test:plan(1) + +-- `math.modf` recording is NYI. +local modf = math.modf +jit.opt.start('hotloop=1', 'maxsnap=1') + +-- The loop has only two iterations: the first to detect its +-- hotness and the second to record it. The snapshot limit is +-- set to one and is certainly reached. +for _ = 1, 2 do + -- Forcify stitch. + modf(1.2) +end + +test:ok(true, 'stack is balanced') +test:done(true) -- 2.43.0