From nobody Sat May 4 20:01:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1558539705; cv=none; d=zoho.com; s=zohoarc; b=UIJ9xpS3yEI66izkG5M0H6lICbGmKNbkhcxyKGMJAZVs7CorfCatH2Mx0phw5aXjt92kfw5QrybbC64T4K0jCpljpbJqszZjcDRhaTlpz4Hm1TLQzTXSt4YGc8RNM/KFqILmWq0u8BwYrJ1AXefE4yRCIfJPZle5coipThifJMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558539705; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=a9sHnmGnZbMHLopomdpuQGjIT6f+FW8MtIGrO3UDCmU=; b=hPAEKTkhDl9iLFqKZnyi4FFUL+LXJ2oJZvinfvw292PccVxizgL1LM2EXyMAJSW5olZlwwOscXrIsxrkPPa8DjalqnVEwRDxXbbbTWqanx90H7du04ibRaQui3stvLlHxr9MguuBYAKizS9eJCHKocz5mosptPFtrCrG5eV3ygY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558539705063970.9909116230311; Wed, 22 May 2019 08:41:45 -0700 (PDT) Received: from localhost ([127.0.0.1]:46168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTTN6-0008Db-QQ for importer@patchew.org; Wed, 22 May 2019 11:41:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTTLI-0006Ra-L4 for qemu-devel@nongnu.org; Wed, 22 May 2019 11:39:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTTIN-0006jI-H6 for qemu-devel@nongnu.org; Wed, 22 May 2019 11:36:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:57584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTTIN-0006dU-2Z for qemu-devel@nongnu.org; Wed, 22 May 2019 11:36:47 -0400 Received: from wens.tw (mirror2.csie.ntu.edu.tw [140.112.30.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 381B820868; Wed, 22 May 2019 15:36:45 +0000 (UTC) Received: by wens.tw (Postfix, from userid 1000) id 35F14602F9; Wed, 22 May 2019 23:36:42 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558539405; bh=LOdC4corK+KeXRAyuWvkbfNSPl5KZ7kzktBbJu4P2sQ=; h=From:To:Cc:Subject:Date:From; b=DjTRXMdzvb5DTU2ehHPuwVlMVpQayFL+Cwz1HfWhFEn1H1AIsQfXSejgmXedqea+F FLKVWRr9vxXbY8IHgUAZrxXK24i4ixuDeug4a1BnOdyvyhVuNjO3OqjuaUh5yxCj3k LVwpyZ1gd/J5w8lqOBLsMfRYtkwvmJ0gaPI2YVko= From: Chen-Yu Tsai To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 23:36:31 +0800 Message-Id: <20190522153631.17152-1-wens@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PATCH v2] linux-user: Pass through nanosecond timestamp components for stat syscalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Chen-Yu Tsai , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Chen-Yu Tsai Since Linux 2.6 the stat syscalls have mostly supported nanosecond components for each of the file-related timestamps. QEMU user mode emulation currently does not pass through the nanosecond portion of the timestamp, even when the host system fills in the value. This results in a mismatch when run on subsecond resolution filesystems such as ext4 or XFS. An example of this leading to inconsistency is cross-debootstraping a full desktop root filesystem of Debian Buster. Recent versions of fontconfig store the full timestamp (instead of just the second portion) of the directory in its per-directory cache file, and checks this against the directory to see if the cache is up-to-date. With QEMU user mode emulation, the timestamp stored is incorrect, and upon booting the rootfs natively, fontconfig discovers the mismatch, and proceeds to rebuild the cache on the comparatively slow machine (low-power ARM vs x86). This stalls the first attempt to open whatever application that incorporates fontconfig. This patch renames the "unused" padding trailing each timestamp element to its nanosecond counterpart name if such an element exists in the kernel sources for the given platform. Not all do. Then have the syscall wrapper fill in the nanosecond portion if the host supports it, as specified by the _POSIX_C_SOURCE and _XOPEN_SOURCE feature macros. Recent versions of glibc only use stat64 and newfstatat syscalls on 32-bit and 64-bit platforms respectively. The changes in this patch were tested by directly calling the stat, stat64 and newfstatat syscalls directly, in addition to the glibc wrapper, on arm and aarch64 little endian targets. Reviewed-by: Laurent Vivier Signed-off-by: Chen-Yu Tsai --- Changes since v1: - Define TARGET_STAT_HAS_NSEC for targets that have the *_nsec fields in their struct stat - Only copy the *_nsec fields in the stat (not stat64) code path if TARGET_STAT_HAS_NSEC is defined - Picked up Reviewed-by from Laurent As Laurent mentioned, linux-user/syscall_defs.h is indented with tabs, so the checkpatch.pl errors can be ignored. Original cover letter: This issue was found while integrating some software that uses newer versions of fontconfig into Raspbian images. We found that the first launch of said software always stalls with fontconfig regenerating its font cache files. Upon closer examination I found the timestamps were not matching. The rest is explained above. Currently we're just working around the problem by patching the correct timestamps into the cache files after the fact. Please consider this a drive-by scratch-my-own-itch contribution, but I will stick around to deal with any comments raised during review. I'm not on the mailing lists either, so please keep me in CC. checkpatch returns "ERROR: code indent should never use tabs" for linux-user/syscall_defs.h, however as far as I can tell the whole file is indented with tabs. I'm not sure what to make of this. Finally, I think this could be worth backporting to older versions. --- linux-user/syscall.c | 19 +++++++++++++++ linux-user/syscall_defs.h | 49 +++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index efa3ec2837..6d0f13c155 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6408,6 +6408,11 @@ static inline abi_long host_to_target_stat64(void *c= pu_env, __put_user(host_st->st_atime, &target_st->target_st_atime); __put_user(host_st->st_mtime, &target_st->target_st_mtime); __put_user(host_st->st_ctime, &target_st->target_st_ctime); +#if _POSIX_C_SOURCE >=3D 200809L || _XOPEN_SOURCE >=3D 700 + __put_user(host_st->st_atim.tv_nsec, &target_st->target_st_atime_n= sec); + __put_user(host_st->st_mtim.tv_nsec, &target_st->target_st_mtime_n= sec); + __put_user(host_st->st_ctim.tv_nsec, &target_st->target_st_ctime_n= sec); +#endif unlock_user_struct(target_st, target_addr, 1); } else #endif @@ -6438,6 +6443,11 @@ static inline abi_long host_to_target_stat64(void *c= pu_env, __put_user(host_st->st_atime, &target_st->target_st_atime); __put_user(host_st->st_mtime, &target_st->target_st_mtime); __put_user(host_st->st_ctime, &target_st->target_st_ctime); +#if _POSIX_C_SOURCE >=3D 200809L || _XOPEN_SOURCE >=3D 700 + __put_user(host_st->st_atim.tv_nsec, &target_st->target_st_atime_n= sec); + __put_user(host_st->st_mtim.tv_nsec, &target_st->target_st_mtime_n= sec); + __put_user(host_st->st_ctim.tv_nsec, &target_st->target_st_ctime_n= sec); +#endif unlock_user_struct(target_st, target_addr, 1); } =20 @@ -8866,6 +8876,15 @@ static abi_long do_syscall1(void *cpu_env, int num, = abi_long arg1, __put_user(st.st_atime, &target_st->target_st_atime); __put_user(st.st_mtime, &target_st->target_st_mtime); __put_user(st.st_ctime, &target_st->target_st_ctime); +#if (_POSIX_C_SOURCE >=3D 200809L || _XOPEN_SOURCE >=3D 700) && \ + defined(TARGET_STAT_HAS_NSEC) + __put_user(st.st_atim.tv_nsec, + &target_st->target_st_atime_nsec); + __put_user(st.st_mtim.tv_nsec, + &target_st->target_st_mtime_nsec); + __put_user(st.st_ctim.tv_nsec, + &target_st->target_st_ctime_nsec); +#endif unlock_user_struct(target_st, arg2, 1); } } diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 1f5b2d18db..f02f3deb6a 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -1179,6 +1179,7 @@ struct target_winsize { #if (defined(TARGET_I386) && defined(TARGET_ABI32)) \ || (defined(TARGET_ARM) && defined(TARGET_ABI32)) \ || defined(TARGET_CRIS) +#define TARGET_STAT_HAS_NSEC struct target_stat { unsigned short st_dev; unsigned short __pad1; @@ -1193,11 +1194,11 @@ struct target_stat { abi_ulong st_blksize; abi_ulong st_blocks; abi_ulong target_st_atime; - abi_ulong __unused1; + abi_ulong target_st_atime_nsec; abi_ulong target_st_mtime; - abi_ulong __unused2; + abi_ulong target_st_mtime_nsec; abi_ulong target_st_ctime; - abi_ulong __unused3; + abi_ulong target_st_ctime_nsec; abi_ulong __unused4; abi_ulong __unused5; }; @@ -1229,13 +1230,13 @@ struct target_stat64 { abi_ulong __pad4; /* future possible st_blocks high bits */ =20 abi_ulong target_st_atime; - abi_ulong __pad5; + abi_ulong target_st_atime_nsec; =20 abi_ulong target_st_mtime; - abi_ulong __pad6; + abi_ulong target_st_mtime_nsec; =20 abi_ulong target_st_ctime; - abi_ulong __pad7; /* will be high 32 bits of ctime someday */ + abi_ulong target_st_ctime_nsec; =20 unsigned long long st_ino; } QEMU_PACKED; @@ -1314,19 +1315,20 @@ struct target_stat64 { unsigned int st_blocks; =20 abi_ulong target_st_atime; - abi_ulong __unused1; + abi_ulong target_st_atime_nsec; =20 abi_ulong target_st_mtime; - abi_ulong __unused2; + abi_ulong target_st_mtime_nsec; =20 abi_ulong target_st_ctime; - abi_ulong __unused3; + abi_ulong target_st_ctime_nsec; =20 abi_ulong __unused4[3]; }; =20 #elif defined(TARGET_SPARC) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { unsigned short st_dev; abi_ulong st_ino; @@ -1337,14 +1339,14 @@ struct target_stat { unsigned short st_rdev; abi_long st_size; abi_long target_st_atime; - abi_ulong __unused1; + abi_ulong target_st_atime_nsec; abi_long target_st_mtime; - abi_ulong __unused2; + abi_ulong target_st_mtime_nsec; abi_long target_st_ctime; - abi_ulong __unused3; + abi_ulong target_st_ctime_nsec; abi_long st_blksize; abi_long st_blocks; - abi_ulong __unused4[2]; + abi_ulong __unused1[2]; }; =20 #define TARGET_HAS_STRUCT_STAT64 @@ -1372,20 +1374,21 @@ struct target_stat64 { unsigned int st_blocks; =20 unsigned int target_st_atime; - unsigned int __unused1; + unsigned int target_st_atime_nsec; =20 unsigned int target_st_mtime; - unsigned int __unused2; + unsigned int target_st_mtime_nsec; =20 unsigned int target_st_ctime; - unsigned int __unused3; + unsigned int target_st_ctime_nsec; =20 - unsigned int __unused4; - unsigned int __unused5; + unsigned int __unused1; + unsigned int __unused2; }; =20 #elif defined(TARGET_PPC) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1443,6 +1446,7 @@ struct QEMU_PACKED target_stat64 { =20 #elif defined(TARGET_MICROBLAZE) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1558,6 +1562,7 @@ struct target_stat64 { =20 #elif defined(TARGET_ABI_MIPSN64) =20 +#define TARGET_STAT_HAS_NSEC /* The memory layout is the same as of struct stat64 of the 32-bit kernel.= */ struct target_stat { unsigned int st_dev; @@ -1597,6 +1602,7 @@ struct target_stat { =20 #elif defined(TARGET_ABI_MIPSN32) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_pad0[3]; /* Reserved for st_dev expansion */ @@ -1621,6 +1627,7 @@ struct target_stat { =20 #elif defined(TARGET_ABI_MIPSO32) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { unsigned st_dev; abi_long st_pad1[3]; /* Reserved for network id */ @@ -1737,6 +1744,7 @@ struct target_stat64 { =20 #elif defined(TARGET_SH4) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1796,6 +1804,7 @@ struct QEMU_PACKED target_stat64 { }; =20 #elif defined(TARGET_I386) && !defined(TARGET_ABI32) +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1841,6 +1850,7 @@ struct target_stat { abi_ulong __unused[3]; }; #elif defined(TARGET_AARCH64) +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1863,6 +1873,7 @@ struct target_stat { unsigned int __unused[2]; }; #elif defined(TARGET_XTENSA) +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1912,6 +1923,7 @@ struct target_stat64 { =20 /* These are the asm-generic versions of the stat and stat64 structures */ =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_ulong st_dev; abi_ulong st_ino; @@ -1963,6 +1975,7 @@ struct target_stat64 { =20 #elif defined(TARGET_HPPA) =20 +#define TARGET_STAT_HAS_NSEC struct target_stat { abi_uint st_dev; abi_uint st_ino; --=20 2.20.1