Created attachment 5231 [details] locktest.c is a simple test program to demonstrate the issue. Problem: The x86_64 build of qemu-arm incorrectly returns EINVAL for the syscall fcntl64(F_SETLK64). This causes SQLite and any ARM binaries that rely on POSIX advisory file locking to fail with a "disk I/O error". The same binaries run correctly under the i386 build of qemu-arm and on real ARM hardware. This appears to be a syscall translation issue in QEMU’s 64-bit user-mode implementation of struct flock64. Expected behavior: The fcntl64(F_SETLK64) call should succeed, matching the behavior of real ARM hardware, the i386 qemu-arm build, and the Linux kernel’s expected handling of 32-bit file locks. Actual behavior: When running under x86_64 qemu-arm, the following output is observed: fcntl64(F_SETLK64) failed: errno=22 (Invalid argument) When running the same binary under i386 qemu-arm, the call succeeds. When running on actual ARM hardware, the call also succeeds. Minimal reproducer: The attached ARM test program demonstrates the issue. It opens a file and attempts to acquire a write lock using F_SETLK64. When run under x86_64 qemu-arm, the lock attempt fails with EINVAL. When run under i386 qemu-arm or on real ARM hardware, the lock succeeds. How to reproduce: Build the test program using the Yocto SDK compiler. Run the resulting ARM binary under x86_64 qemu-arm. The lock attempt fails with EINVAL. Run the same binary under i386 qemu-arm. The lock attempt succeeds. Run the same binary on actual ARM hardware. The lock attempt succeeds. Impact: This issue prevents many ARM binaries from running correctly under the Yocto SDK’s qemu-arm, including SQLite, LMDB, Berkeley DB, and any application that relies on POSIX file locking. This makes the x86_64 qemu-arm unsuitable for testing or running 32-bit ARM userlands that depend on file locking. Suggested fix: Provide a 32-bit (i386) build of qemu-arm in addition to the x86_64 build, or document that the i386 build is required for correct emulation of 32-bit ARM file-locking behavior.
This is probably worth filing a bug upstream with qemu. Can you do that?
Before filing an upstream bug with qemu, I downloaded and built the latest qemu release (11.0.1). qemu-arm 11.0.1 successfully runs the attached test program. qemu-arm that ships with my version of Yocto (Scarthgap) is version 8.2.1 and it fails to successfully run the test program. It looks like qemu has addressed this issue sometime between version 8 and 11.
Could you see if you can figure out a patch for qemu 8 that we could apply for Scarthgap?
I am not familiar with qemu source code at all. I'm not able to create a patch to backport the fix.
Thanks Daniel. We don't have anyone to work on this issue unfortunately.
Patch sent on ML: https://patchwork.yoctoproject.org/project/oe-core/patch/20261001233250.7-1-bbnpreetsingh@gmail.com/
(In reply to Yoann Congal from comment #6) > Patch sent on ML: > https://patchwork.yoctoproject.org/project/oe-core/patch/20261001233250.7-1- > bbnpreetsingh@gmail.com/ @Daniel, can you help test/review it?
(In reply to Yoann Congal from comment #7) > (In reply to Yoann Congal from comment #6) > > Patch sent on ML: > > https://patchwork.yoctoproject.org/project/oe-core/patch/20261001233250.7-1- > > bbnpreetsingh@gmail.com/ > > @Daniel, can you help test/review it? I applied the patch to my Scarthgap build, rebuilt the toolchain, and now qemu-arm successfully runs the locktest test program: The original version: ``` [dslat@feynman-wsl:~] Σ /opt/thermo-imx-fb/5.0/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-arm -L /opt/thermo-imx-fb/5.0/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi ./locktest fcntl64(F_SETLK64) failed: errno=22 (Invalid argument) ``` and the patched version: ``` [dslat@feynman-wsl:~] Σ /opt/thermo-imx-fb/5.0-qemu-patched/sysroots/x86_64-pokysdk-linux/usr/bin/qemu-arm -L /opt/thermo-imx-fb/5.0-qemu-patched/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi ./locktest fcntl64(F_SETLK64) succeeded ```
(In reply to Daniel R. Slater from comment #8) > (In reply to Yoann Congal from comment #7) > > (In reply to Yoann Congal from comment #6) > > > Patch sent on ML: > > > https://patchwork.yoctoproject.org/project/oe-core/patch/20261001233250.7-1- > > > bbnpreetsingh@gmail.com/ > > > > @Daniel, can you help test/review it? > > I applied the patch to my Scarthgap build, rebuilt the toolchain, and now > qemu-arm successfully runs the locktest test program: Excellent, thanks! If you want to be credited for this work you can reply on list with (either/both): Reviewed-by: ... Tested-by: ... ... and I'll add this to the merged commit.
Reviewed-by: Daniel R. Slater <daniel.slater@thermofisher.com> Tested-by: Daniel R. Slater <daniel.slater@thermofisher.com> Reviewed the patch, applied it to my Scarthgap build, and verified the fix.