Bug 16326

Summary: [scarthgap] x86_64 qemu-arm fails to emulate F_SETLK64 (EINVAL), breaking SQLite and file-locking on 32‑bit ARM userlands
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Daniel R. Slater <daniel.slater>
Component: oe-core otherAssignee: Babanpreet Singh <bbnpreetsingh>
Status: IN PROGRESS REVIEW --- QA Contact:
Severity: major    
Priority: Medium CC: daniel.slater, randy.macleod, ross.burton, tim.orling, yoann.congal
Version: unspecified   
Target Milestone: 5.0.22   
Hardware: x86   
OS: arm   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know
Attachments:
Description Flags
locktest.c is a simple test program to demonstrate the issue. none

Description Daniel R. Slater 2026-06-18 16:31:47 UTC
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.
Comment 1 Tim Orling 2026-06-25 14:38:47 UTC
This is probably worth filing a bug upstream with qemu. Can you do that?
Comment 2 Daniel R. Slater 2026-06-25 18:47:04 UTC
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.
Comment 3 Tim Orling 2026-07-02 15:25:56 UTC
Could you see if you can figure out a patch for qemu 8 that we could apply for Scarthgap?
Comment 4 Daniel R. Slater 2026-07-24 17:39:38 UTC
I am not familiar with qemu source code at all. I'm not able to create a patch to backport the fix.
Comment 5 Randy MacLeod 2026-07-30 15:17:00 UTC
Thanks Daniel.
We don't have anyone to work on this issue unfortunately.
Comment 7 Yoann Congal 2026-10-12 09:26:14 UTC
(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?
Comment 8 Daniel R. Slater 2026-10-12 15:47:53 UTC
(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
```
Comment 9 Yoann Congal 2026-10-12 15:55:35 UTC
(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.
Comment 10 Daniel R. Slater 2026-10-12 16:08:50 UTC
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.