qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

linux-user: Add strace support for printing arguments of fallocate()

This patch implements strace argument printing functionality for following syscall:

*fallocate - manipulate file space

int fallocate(int fd, int mode, off_t offset, off_t len)
man page: https://www.man7.org/linux/man-pages/man2/fallocate.2.html

Implementation notes:

This syscall's second argument "mode" is composed of predefined values
which represent flags that determine the type of operation that is
to be performed on the file space. For that reason, a printing
function "print_fallocate" was stated in file "strace.list". This printing
function uses an already existing function "print_flags()" to print flags of
the "mode" argument. These flags are stated inside an array "falloc_flags"
that contains values of type "struct flags". These values are instantiated
using an existing macro "FLAG_GENERIC()". Most of these flags are defined
after kernel version 3.0 which is why they are enwrapped in an #ifdef
directive.
The syscall's third ant fourth argument are of type "off_t" which can
cause variations between 32/64-bit architectures. To handle this variation,
function "target_offset64()" was copied from file "strace.c" and used in
"print_fallocate" to print "off_t" arguments for 32-bit architectures.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200619123331.17387-7-filip.bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>

authored by

Filip Bozuta and committed by
Laurent Vivier
f4d92c5e 5844f4bc

+57 -17
+16
linux-user/qemu.h
··· 670 670 return (abi_ulong)ret >= (abi_ulong)(-4096); 671 671 } 672 672 673 + #if TARGET_ABI_BITS == 32 674 + static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) 675 + { 676 + #ifdef TARGET_WORDS_BIGENDIAN 677 + return ((uint64_t)word0 << 32) | word1; 678 + #else 679 + return ((uint64_t)word1 << 32) | word0; 680 + #endif 681 + } 682 + #else /* TARGET_ABI_BITS == 32 */ 683 + static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) 684 + { 685 + return word0; 686 + } 687 + #endif /* TARGET_ABI_BITS != 32 */ 688 + 673 689 /** 674 690 * preexit_cleanup: housekeeping before the guest exits 675 691 *
+40
linux-user/strace.c
··· 1135 1135 FLAG_END, 1136 1136 }; 1137 1137 1138 + UNUSED static struct flags falloc_flags[] = { 1139 + FLAG_GENERIC(FALLOC_FL_KEEP_SIZE), 1140 + FLAG_GENERIC(FALLOC_FL_PUNCH_HOLE), 1141 + #ifdef FALLOC_FL_NO_HIDE_STALE 1142 + FLAG_GENERIC(FALLOC_FL_NO_HIDE_STALE), 1143 + #endif 1144 + #ifdef FALLOC_FL_COLLAPSE_RANGE 1145 + FLAG_GENERIC(FALLOC_FL_COLLAPSE_RANGE), 1146 + #endif 1147 + #ifdef FALLOC_FL_ZERO_RANGE 1148 + FLAG_GENERIC(FALLOC_FL_ZERO_RANGE), 1149 + #endif 1150 + #ifdef FALLOC_FL_INSERT_RANGE 1151 + FLAG_GENERIC(FALLOC_FL_INSERT_RANGE), 1152 + #endif 1153 + #ifdef FALLOC_FL_UNSHARE_RANGE 1154 + FLAG_GENERIC(FALLOC_FL_UNSHARE_RANGE), 1155 + #endif 1156 + }; 1157 + 1138 1158 /* 1139 1159 * print_xxx utility functions. These are used to print syscall 1140 1160 * parameters in certain format. All of these have parameter ··· 1548 1568 print_string(arg1, 0); 1549 1569 print_flags(access_flags, arg2, 0); 1550 1570 print_flags(at_file_flags, arg3, 1); 1571 + print_syscall_epilogue(name); 1572 + } 1573 + #endif 1574 + 1575 + #ifdef TARGET_NR_fallocate 1576 + static void 1577 + print_fallocate(const struct syscallname *name, 1578 + abi_long arg0, abi_long arg1, abi_long arg2, 1579 + abi_long arg3, abi_long arg4, abi_long arg5) 1580 + { 1581 + print_syscall_prologue(name); 1582 + print_raw_param("%d", arg0, 0); 1583 + print_flags(falloc_flags, arg1, 0); 1584 + #if TARGET_ABI_BITS == 32 1585 + print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0); 1586 + print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1); 1587 + #else 1588 + print_raw_param(TARGET_ABI_FMT_ld, arg2, 0); 1589 + print_raw_param(TARGET_ABI_FMT_ld, arg3, 1); 1590 + #endif 1551 1591 print_syscall_epilogue(name); 1552 1592 } 1553 1593 #endif
+1 -1
linux-user/strace.list
··· 182 182 { TARGET_NR_fadvise64_64, "fadvise64_64" , NULL, NULL, NULL }, 183 183 #endif 184 184 #ifdef TARGET_NR_fallocate 185 - { TARGET_NR_fallocate, "fallocate" , NULL, NULL, NULL }, 185 + { TARGET_NR_fallocate, "fallocate" , NULL, print_fallocate, NULL }, 186 186 #endif 187 187 #ifdef TARGET_NR_fanotify_init 188 188 { TARGET_NR_fanotify_init, "fanotify_init" , NULL, NULL, NULL },
-16
linux-user/syscall.c
··· 6712 6712 } 6713 6713 } 6714 6714 6715 - #if TARGET_ABI_BITS == 32 6716 - static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) 6717 - { 6718 - #ifdef TARGET_WORDS_BIGENDIAN 6719 - return ((uint64_t)word0 << 32) | word1; 6720 - #else 6721 - return ((uint64_t)word1 << 32) | word0; 6722 - #endif 6723 - } 6724 - #else /* TARGET_ABI_BITS == 32 */ 6725 - static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) 6726 - { 6727 - return word0; 6728 - } 6729 - #endif /* TARGET_ABI_BITS != 32 */ 6730 - 6731 6715 #ifdef TARGET_NR_truncate64 6732 6716 static inline abi_long target_truncate64(void *cpu_env, const char *arg1, 6733 6717 abi_long arg2,