From 3b06d458ffc5cc8de8d701926e5d86979185fa04 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 4 Jul 2024 15:21:39 +0200 Subject: [PATCH] Avoid dev/inode check on btrfs with --sanity-level=3 With --sanity-level=3 or higher the aspacemgr sanity checks the device/inode numbers from /proc/self/maps to the file stat results. These don't match on btrfs. So detect when a file is on a btrfs volume and ignore the check in that case. https://bugs.kde.org/show_bug.cgi?id=317127 --- NEWS | 1 + coregrind/m_aspacemgr/aspacemgr-linux.c | 13 +++++++++++++ include/vki/vki-linux.h | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/NEWS b/NEWS index 87aa1bd7dd..dde8713d60 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. valgrind: vex x86->IR: unhandled instruction bytes: 0x66 0xF 0x3A 0x2 311655 --log-file=FILE leads to apparent fd leak +317127 Fedora18/x86_64 --sanity-level=3 : aspacem segment mismatch 337388 fcntl works on Valgrind's own file descriptors 377966 arm64 unhandled instruction dc zva392146 aarch64: unhandled instruction 0xD5380001 (MRS rT, midr_el1) diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c index 9362f65af3..bae4f781a8 100644 --- a/coregrind/m_aspacemgr/aspacemgr-linux.c +++ b/coregrind/m_aspacemgr/aspacemgr-linux.c @@ -891,6 +891,19 @@ static void sync_check_mapping_callback ( Addr addr, SizeT len, UInt prot, /* hack apparently needed on MontaVista Linux */ if (filename && VG_(strstr)(filename, "/.lib-ro/")) cmp_devino = False; + + /* On linux systems we want to avoid dev/inode check on btrfs, + we can use the statfs call for that, except on nanomips + (which also doesn't have a sys_fstatfs syswrap). + See https://bugs.kde.org/show_bug.cgi?id=317127 */ +#if !defined(VGP_nanomips_linux) + struct vki_statfs statfs = {0}; + SysRes res = VG_(do_syscall2)(__NR_statfs, (UWord)filename, + (UWord)&statfs); + if (!sr_isError(res) && statfs.f_type == VKI_BTRFS_SUPER_MAGIC) { + cmp_devino = False; + } +#endif #endif /* If we are doing sloppy execute permission checks then we diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index be3d76690c..ccdb808af7 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -5455,6 +5455,12 @@ struct vki_open_how { #define VKI_CLOSE_RANGE_UNSHARE (1U << 1) #define VKI_CLOSE_RANGE_CLOEXEC (1U << 2) +//---------------------------------------------------------------------- +// From linux/magic.h +//---------------------------------------------------------------------- + +#define VKI_BTRFS_SUPER_MAGIC 0x9123683E + /*--------------------------------------------------------------------*/ /*--- end ---*/ /*--------------------------------------------------------------------*/ -- 2.47.2