Repository navigation
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Since #114331 was solved, we once again attempted to build Python with freethreading on s390x Fedora Linux.
test.test_io.CBufferedReaderTest.test_constructor fails. The traceback:
test_constructor (test.test_io.CBufferedReaderTest.test_constructor) ... Fatal Python error: Floating point exception
Current thread 0x000003ff8aa77b60 (most recent call first):
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/case.py", line 238 in handle
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/case.py", line 795 in assertRaises
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/test_io.py", line 1710 in test_constructor
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/case.py", line 606 in _callTestMethod
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/case.py", line 651 in run
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/case.py", line 707 in __call__
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/suite.py", line 122 in run
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/suite.py", line 84 in __call__
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/suite.py", line 122 in run
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/suite.py", line 84 in __call__
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/unittest/runner.py", line 240 in run
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 57 in _run_suite
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 37 in run_unittest
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 132 in test_func
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 88 in regrtest_runner
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 135 in _load_run_test
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 178 in _runtest_env_changed_exc
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 278 in _runtest
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/single.py", line 306 in run_single_test
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/worker.py", line 77 in worker_process
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/worker.py", line 112 in main
File "/builddir/build/BUILD/Python-3.13.0a6/Lib/test/libregrtest/worker.py", line 116 in <module>
File "<frozen runpy>", line 88 in _run_code
File "<frozen runpy>", line 198 in _run_module_as_main
1 test failed again:
test_io
Is this freethreading related? I don't know. Hoping to raise visibility and pointers as where the issue comes from. cc @vstinner
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
[-]3.13.0a6: `test.test_io.CBufferedReaderTest.test_constructor` ends with `Fatal Python error: Floating point exception`[/-][+]3.13.0a6: `test.test_io.CBufferedReaderTest.test_constructor` ends with `Fatal Python error: Floating point exception` on s390x[/+][-]3.13.0a6: `test.test_io.CBufferedReaderTest.test_constructor` ends with `Fatal Python error: Floating point exception` on s390x[/-][+]3.13.0a6: `test.test_io.CBufferedReaderTest.test_constructor` ends with `Fatal Python error: Floating point exception` on s390x with freethreading[/+]pythongh-117755: Skip test_io.test_constructor() on s390x
vstinner commentedon Apr 12, 2024
The root issue is a division by zero in mimalloc when requested memory is huge: 0x7fffffffffffffff bytes.
It can be reproduced on s390x without test_io:
vstinner commentedon Apr 12, 2024
I can reproduce the issue with a Python built with:
I disable all compiler optimizations (
-O0) to ease debugging in gdb.gdb logs when the bug occurs:
vstinner commentedon Apr 12, 2024
PyObject_Malloc():
mi_segment_huge_page_alloc() is called with size=0x8000000000000000:
uint8_t* start = _mi_segment_page_start(segment, page, &psize);withslice->slice_count = 0setspsizeto 0.The problem is that
slice->slice_countis 0: integer overflow.mi_page_t.slice_counttype isuint32_t, whereas on s390x, we try to set it to 0x8000_00000000 (140737488355328) which doesn't fit:gdb:
pythongh-117755: Fix mimalloc for huge allocation on s390x
vstinner commentedon Apr 12, 2024
On x86-64, we don't reach this bug, since mmap() fails before.
strace on the big mmap() call:
mmap(NULL, 9223372036863164416, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = -1 ENOMEMmmap(NULL, 9223372036858970112, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x3ffdcf80000.On x86-64, gdb traces around mmap():
[-]3.13.0a6: `test.test_io.CBufferedReaderTest.test_constructor` ends with `Fatal Python error: Floating point exception` on s390x with freethreading[/-][+]Python 3.13.0a6 freethreading: `test.test_io.CBufferedReaderTest.test_constructor` crash with `Floating point exception` on s390x[/+][-]Python 3.13.0a6 freethreading: `test.test_io.CBufferedReaderTest.test_constructor` crash with `Floating point exception` on s390x[/-][+]Python 3.13.0a6 freethreading on s390x: `test.test_io.CBufferedReaderTest.test_constructor` crash with `Floating point exception`[/+]colesbury commentedon Apr 12, 2024
One thing I'm curious about: even with overcommit, I think that
mmap()still needs to create the page mappings. With 4KB pages, that's trillions of pages. The page table itself is too bit to store in memory.Why does it succeed on s390x? Is mmap able to use much bigger pages on IBM Z? Something else?
vstinner commentedon Apr 12, 2024
Sorry, I have no idea 🤷🏻♂️
gh-117755: Skip test_io.test_constructor() on s390x (#117801)
pythongh-117755: Fix mimalloc for huge allocation on s390x
pythongh-117755: Remove tests on huge memory allocations
gh-117755: Remove tests on huge memory allocations (#117938)
gh-117755: Fix mimalloc for huge allocation on s390x (#117809)
pythongh-117755: Skip test_io.test_constructor() on s390x (python#117801
pythongh-117755: Remove tests on huge memory allocations (python#117938)
pythongh-117755: Fix mimalloc for huge allocation on s390x (python#11…