Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit 2/2] x64/!LJ_GC64: The allocation limit is required for a no-JIT build, too.
Date: Wed, 4 Mar 2026 18:40:14 +0300	[thread overview]
Message-ID: <ff3a4383-f630-4c19-8025-9c6289f31682@tarantool.org> (raw)
In-Reply-To: <1d2c3bbc66be0d8d2049f0b7605b9ce111df37fa.1772438261.git.skaplun@tarantool.org>

[-- Attachment #1: Type: text/plain, Size: 2977 bytes --]

Hi, Sergey,

thanks for the patch! LGTM

Sergey

On 3/2/26 11:05, Sergey Kaplun wrote:
> From: Mike Pall <mike>
>
> Thanks to Sergey Kaplun.
>
> (cherry picked from commit eff4006837792b6105e0a1743283ddde3548fc09)
>
> For the non-GC64 build with disabled JIT, LuaJIT's internal allocator
> may return 32-bit addresses. This may lead to the assertion failure
> during the reallocation of the array part of the table or to the crash
> (if assertions are disabled) due to an incorrect arithmetic in the x86
> VM. For example, the addition with a 32-bit wide address may overflow
> in TSETV or TGETV and cause the crash.
>
> This patch sets the allocation limit for the build without JIT.
>
> Sergey Kaplun:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#12134
> ---
>   src/lj_alloc.c                                |  4 +-
>   .../lj-1430-internal-alloc-limit.test.lua     | 39 +++++++++++++++++++
>   2 files changed, 41 insertions(+), 2 deletions(-)
>   create mode 100644 test/tarantool-tests/lj-1430-internal-alloc-limit.test.lua
>
> diff --git a/src/lj_alloc.c b/src/lj_alloc.c
> index f82c9854..97eb94d2 100644
> --- a/src/lj_alloc.c
> +++ b/src/lj_alloc.c
> @@ -99,8 +99,8 @@
>   
>   #if LJ_GC64
>   #define LJ_ALLOC_MBITS		47	/* 128 TB in LJ_GC64 mode. */
> -#elif LJ_TARGET_X64 && LJ_HASJIT
> -/* Due to limitations in the x64 compiler backend. */
> +#elif LJ_TARGET_X64
> +/* Due to limitations in the x64 non-GC64 VM. */
>   #define LJ_ALLOC_MBITS		31	/* 2 GB on x64 with !LJ_GC64. */
>   #else
>   #define LJ_ALLOC_MBITS		32	/* 4 GB on other archs with !LJ_GC64. */
> diff --git a/test/tarantool-tests/lj-1430-internal-alloc-limit.test.lua b/test/tarantool-tests/lj-1430-internal-alloc-limit.test.lua
> new file mode 100644
> index 00000000..969d26d6
> --- /dev/null
> +++ b/test/tarantool-tests/lj-1430-internal-alloc-limit.test.lua
> @@ -0,0 +1,39 @@
> +local tap = require('tap')
> +
> +-- Test file to demonstrate incorrect allocation limit for the
> +-- non-GC64 build with disabled JIT.
> +-- See also:https://github.com/LuaJIT/LuaJIT/issues/1430.
> +
> +local test = tap.test('lj-1430-internal-alloc-limit')
> +
> +test:plan(1)
> +
> +-- This function creates a bunch of long array-like tables.
> +-- Eventually for one of the tables the address of the array
> +-- element will not fit in the 31-bit range, causing the incorrect
> +-- arithmetic inside the VM and a crash or assertion failure
> +-- during the reallocation.
> +local function test_payload()
> +  local POOL_SZ = 8
> +  -- luacheck: no unused
> +  local pools = {}
> +  for i = 1, POOL_SZ do
> +    pools[i] = {}
> +  end
> +
> +  local v = 1
> +  for j = 1, POOL_SZ do
> +    for i = 1, 0x2000000 do
> +      pools[j][i] = v
> +    end
> +  end
> +end
> +
> +-- Protect the call to avoid the OOM.
> +pcall(test_payload)
> +
> +-- Free memory for the TAP tests.
> +collectgarbage()
> +
> +test:ok(true, 'no crash or assertion failure')
> +test:done(true)

[-- Attachment #2: Type: text/html, Size: 3398 bytes --]

  reply	other threads:[~2026-03-04 15:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02  8:05 [Tarantool-patches] [PATCH luajit 0/2] Correct allocation limit without JIT Sergey Kaplun via Tarantool-patches
2026-03-02  8:05 ` [Tarantool-patches] [PATCH luajit 1/2] Fix pointer check for non-GC64 mode Sergey Kaplun via Tarantool-patches
2026-03-04 15:21   ` Sergey Bronnikov via Tarantool-patches
2026-03-02  8:05 ` [Tarantool-patches] [PATCH luajit 2/2] x64/!LJ_GC64: The allocation limit is required for a no-JIT build, too Sergey Kaplun via Tarantool-patches
2026-03-04 15:40   ` Sergey Bronnikov via Tarantool-patches [this message]
2026-03-04 15:40 ` [Tarantool-patches] [PATCH luajit 0/2] Correct allocation limit without JIT Sergey Bronnikov via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ff3a4383-f630-4c19-8025-9c6289f31682@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 2/2] x64/'\!'LJ_GC64: The allocation limit is required for a no-JIT build, too.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox