Skip to contentSkip to conversation

qemu: restore 64-bit file lock handling for 32-bit guests

PATCH Superseded Babanpreet Singh 2 participants 4 messages Aug 2 – Oct 1

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu: restore 64-bit file lock handling for 32-bit guests

0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch removes the TARGET_F_GETLK64, TARGET_F_SETLK64 and TARGET_F_SETLKW64 cases from target_to_host_fcntl_cmd(), along with the struct target_flock64 conversions. Those are guest ABI, not host libc spellings, so every 32-bit guest calling fcntl64() to lock a file now gets -TARGET_EINVAL; under qemu-arm SQLite reports "disk I/O error".

Backport ac1bbe8ca46c ("linux-user/syscall.c: drop 64 suffix from flock64 &Co", 9.2.0), which makes the same musl-driven change without dropping the guest side, and remove the hunks it supersedes from the local patch.

[YOCTO #16326]

AI-Generated: Uses Claude (claude-opus-5)

---
Only scarthgap is affected. master and wrynose carry qemu 11.0.3 and 10.2.0 respectively, both of which contain ac1bbe8ca46c, and neither still carries 0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch, so there is no master commit to backport from and nothing to send there first.

Verified by building qemu 8.2.7 with the current and proposed patch stacks and running a 32-bit ARM test program under each resulting qemu-arm:
F_SETLK64, F_GETLK64, F_SETLKW64 and a lock at a 5 GiB offset all return EINVAL before the change and succeed after it, with plain 32-bit F_SETLK unaffected either way. bitbake qemu-native also builds clean on scarthgap with the new stack.

 meta/recipes-devtools/qemu/qemu.inc           |   1 +
 ...all.c-drop-64-suffix-from-flock64-Co.patch | 225 +++++++++++++++
 ...ce-use-of-lfs64-related-functions-an.patch | 265 +-----------------
 3 files changed, 228 insertions(+), 263 deletions(-)
 create mode 100644 meta/recipes-devtools/qemu/qemu/0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch
meta/recipes-devtools/qemu/qemu.inc +1 -0
index 46cc7cb5cb0..91fd6df3e12 100644
@@ -30,6 +30,7 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
            file://0008-tests-meson.build-use-relative-path-to-refer-to-file.patch \
            file://0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch \
            file://0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch \
+           file://0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch \
            file://0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch \
            file://fixedmeson.patch \
            file://no-pip.patch \
meta/recipes-devtools/qemu/qemu/0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch new file +225 -0

225 lines not on this page · raw message

meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch +2 -263

279 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
Quoted 85 lines · Babanpreet Singh

0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch removes the TARGET_F_GETLK64, TARGET_F_SETLK64 and TARGET_F_SETLKW64 cases from target_to_host_fcntl_cmd(), along with the struct target_flock64 conversions. Those are guest ABI, not host libc spellings, so every 32-bit guest calling fcntl64() to lock a file now gets -TARGET_EINVAL; under qemu-arm SQLite reports "disk I/O error".

Backport ac1bbe8ca46c ("linux-user/syscall.c: drop 64 suffix from flock64 &Co", 9.2.0), which makes the same musl-driven change without dropping the guest side, and remove the hunks it supersedes from the local patch.

[YOCTO #16326]

AI-Generated: Uses Claude (claude-opus-5)

---
Only scarthgap is affected. master and wrynose carry qemu 11.0.3 and 10.2.0 respectively, both of which contain ac1bbe8ca46c, and neither still carries 0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch, so there is no master commit to backport from and nothing to send there first.

Verified by building qemu 8.2.7 with the current and proposed patch stacks and running a 32-bit ARM test program under each resulting qemu-arm:
F_SETLK64, F_GETLK64, F_SETLKW64 and a lock at a 5 GiB offset all return EINVAL before the change and succeed after it, with plain 32-bit F_SETLK unaffected either way. bitbake qemu-native also builds clean on scarthgap with the new stack.

 meta/recipes-devtools/qemu/qemu.inc           |   1 +
 ...all.c-drop-64-suffix-from-flock64-Co.patch | 225 +++++++++++++++
 ...ce-use-of-lfs64-related-functions-an.patch | 265 +-----------------
 3 files changed, 228 insertions(+), 263 deletions(-)
 create mode 100644 meta/recipes-devtools/qemu/qemu/0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch
meta/recipes-devtools/qemu/qemu.inc +1 -0
index 46cc7cb5cb0..91fd6df3e12 100644
@@ -30,6 +30,7 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
            file://0008-tests-meson.build-use-relative-path-to-refer-to-file.patch \
            file://0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch \
            file://0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch \
+           file://0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch \
            file://0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch \
            file://fixedmeson.patch \
            file://no-pip.patch \
meta/recipes-devtools/qemu/qemu/0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch new file +27 -0
new file mode 100644
index 00000000000..6ebe2b895db
@@ -0,0 +1,225 @@
+From ac1bbe8ca46c550b3ad99c85744119a3ace7b4f4 Mon Sep 17 00:00:00 2001
+From: Michael Tokarev <[email protected]>
+Date: Thu, 29 Aug 2024 09:39:50 +0300
+Subject: [PATCH] linux-user/syscall.c: drop 64 suffix from flock64 &Co
+
+Since we are always building with LFS enabled, in particular
+with -D_FILE_OFFSET_BITS=64, we should always have struct flock
+mapped to the 64bit variant (with off64_t), and F_GETLK mapped
+to F_GETLK64 etc, automatically.
+
+So there should be no need to explicitly use the "64" suffix
+for these things anymore.
+
+Also fix a misleading comment near safe_fcntl telling us to
+always use flock64 (since v2.6.0-1311-g435da5e7092a "linux-user:
+Use safe_syscall wrapper for fcntl").
+
+Reference: https://gitlab.com/qemu-project/qemu/-/issues/2215
+Signed-off-by: Michael Tokarev <[email protected]>
+Reviewed-by: Richard Henderson <[email protected]>
+
+Upstream-Status: Backport [https://gitlab.com/qemu-project/qemu/-/commit/ac1bbe8ca46c550b3ad99c85744119a3ace7b4f4]
+---
+ linux-user/syscall.c | 92 ++++++++++++++++++++--------------------------------
+ 1 file changed, 40 insertions(+), 52 deletions(-)
+
[...]
+ 
meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch +0 -0
index ceae67be644..b10a76090b8 100644

meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2022-1

Quoted 1 line
meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch +0 -0
@@ -13,234 +13,13 @@ Upstream-Status: Submitted [https://lists.gnu.org/archive/html/qemu-devel/2022-1
[...]

Hello,

I'm sorry but something look not right to me here.

I don't understand how you can modify a 0002 by backporting 0001... Was Khem patch reverted? In that case, I think we better remove it and re-do the backport with non-reverted patches.

Also, Khem's patch is merged now, can you fix the Upstream-status if we end up keeping it?

Thanks!

Signature · 2 lines
Yoann Congal
Smile ECS
#2 lore raw
Quoted 3 lines · Yoann Congal

I don't understand how you can modify a 0002 by backporting 0001... Was Khem patch reverted? In that case, I think we better remove it and re-do the backport with non-reverted patches.

Fair, the trimmed 0002 is confusing. Nothing was reverted: Khem's patch was never merged as such. What qemu took instead is two commits from Michael Tokarev on 2024-08-29, both in 9.2.0:

ac1bbe8ca46c linux-user/syscall.c: drop 64 suffix from flock64 &Co 99174ce39e86 linux-user/syscall.c: eliminate other explicit LFS usages

The first covers the fcntl side without dropping the guest F_*LK64 cases the way the local patch does, which is the bug. The second is line for line what was left of 0002 after my trim (truncate64, lseek64, pread64, pwrite64). I only backported the first because it was enough to fix the locks, and I agree that carrying half a local patch on top of it is the wrong shape.

Quoted 2 lines

Also, Khem's patch is merged now, can you fix the Upstream-status if we end up keeping it?

The Submitted link in 0002 points at a series that never landed, so I'd rather not keep it. v2 follows in this thread: it drops 0002 and carries both upstream commits as Backports. With both applied, syscall.c comes out byte for byte the same as with the v1 stack, so the lock test results from v1 still hold. qemu-native builds clean with it.

Thanks,
Baban

#3 lore raw

PATCH v2 1/1 qemu: restore 64-bit file lock handling for 32-bit guests

In reply to Yoann Congal

0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch removes the TARGET_F_GETLK64, TARGET_F_SETLK64 and TARGET_F_SETLKW64 cases from target_to_host_fcntl_cmd(), along with the struct target_flock64 conversions. So every 32-bit guest calling fcntl64() to lock a file gets -TARGET_EINVAL.

[YOCTO #16326]

AI-Generated: Uses Claude (claude-fable-5-1)

---
Changes since v1: the local lfs64 patch is dropped instead of trimmed, and 99174ce39e86 is backported alongside ac1bbe8ca46c. Together the two upstream commits cover exactly what the local patch changed, minus the guest-side removals that broke fcntl64() locking. Applied to 8.2.7 they give the same linux-user/syscall.c as the v1 stack, byte for byte, so the v1 runtime results below still describe this source.

Only scarthgap is affected. master and wrynose carry qemu 11.0.3 and 10.2.0 respectively, both of which contain the two commits, and neither still carries 0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch, so there is nothing to send to master first.

Verified by building qemu 8.2.7 with the current and proposed patch stacks and running a 32-bit ARM test program under each resulting qemu-arm:
F_SETLK64, F_GETLK64, F_SETLKW64 and a lock at a 5 GiB offset all return EINVAL before the change and succeed after it, with plain 32-bit F_SETLK unaffected either way. bitbake qemu-native builds clean on scarthgap with the new stack.

 meta/recipes-devtools/qemu/qemu.inc           |   3 +-
 ...all.c-drop-64-suffix-from-flock64-Co.patch | 225 +++++++++++
 ...ce-use-of-lfs64-related-functions-an.patch | 355 ------------------
 ...-eliminate-other-explicit-LFS-usages.patch | 107 ++++++
 4 files changed, 334 insertions(+), 356 deletions(-)
 create mode 100644 meta/recipes-devtools/qemu/qemu/0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch
 delete mode 100644 meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch
 create mode 100644 meta/recipes-devtools/qemu/qemu/0002-linux-user-syscall.c-eliminate-other-explicit-LFS-usages.patch
meta/recipes-devtools/qemu/qemu.inc +2 -1
index 46cc7cb5cb..1f510cbcb9 100644
@@ -30,7 +30,8 @@ SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
            file://0008-tests-meson.build-use-relative-path-to-refer-to-file.patch \
            file://0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch \
            file://0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch \
-           file://0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch \
+           file://0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch \
+           file://0002-linux-user-syscall.c-eliminate-other-explicit-LFS-usages.patch \
            file://fixedmeson.patch \
            file://no-pip.patch \
            file://4a8579ad8629b57a43daa62e46cc7af6e1078116.patch \
meta/recipes-devtools/qemu/qemu/0001-linux-user-syscall.c-drop-64-suffix-from-flock64-Co.patch new file +225 -0

225 lines not on this page · raw message

meta/recipes-devtools/qemu/qemu/0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch deleted +0 -355

355 lines not on this page · raw message

meta/recipes-devtools/qemu/qemu/0002-linux-user-syscall.c-eliminate-other-explicit-LFS-usages.patch new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.43.0