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

linux-user: remove useless padding in flock64 structure

Since commit 8efb2ed5ec ("linux-user: Correct signedness of
target_flock l_start and l_len fields"), flock64 structure uses
abi_llong for l_start and l_len in place of "unsigned long long"
this should force them to be aligned accordingly to the target
rules. So we can remove the padding field and the QEMU_PACKED
attribute.

I have compared the result of the following program before and
after the change:

cat -> flock64_dump <<EOF
p/d sizeof(struct target_flock64)
p/d &((struct target_flock64 *)0)->l_type
p/d &((struct target_flock64 *)0)->l_whence
p/d &((struct target_flock64 *)0)->l_start
p/d &((struct target_flock64 *)0)->l_len
p/d &((struct target_flock64 *)0)->l_pid
quit
EOF

for file in build/all/*-linux-user/qemu-* ; do
echo $file
gdb -batch -nx -x flock64_dump $file 2> /dev/null
done

The sizeof() changes because we remove the QEMU_PACKED.
The new size is 32 (except for i386 and m68k) and this is
the real size of "struct flock64" on the target architecture.

The following architectures differ:
aarch64_be, aarch64, alpha, armeb, arm, cris, hppa, nios2, or1k,
riscv32, riscv64, s390x.

For a subset of these architectures, I have checked with the following
program the new structure is the correct one:

#include <stdio.h>
#define __USE_LARGEFILE64
#include <fcntl.h>

int main(void)
{
printf("struct flock64 %d\n", sizeof(struct flock64));
printf("l_type %d\n", &((struct flock64 *)0)->l_type);
printf("l_whence %d\n", &((struct flock64 *)0)->l_whence);
printf("l_start %d\n", &((struct flock64 *)0)->l_start);
printf("l_len %d\n", &((struct flock64 *)0)->l_len);
printf("l_pid %d\n", &((struct flock64 *)0)->l_pid);
}

[I have checked aarch64, alpha, hppa, s390x]

For ARM, the target_flock64 becomes the EABI definition, so we need to
define the OABI one in place of the EABI one and use it when it is
needed.

I have also fixed the alignment value for sh4 (to align llong on 4 bytes)
(see c2e3dee6e0 "linux-user: Define target alignment size")
[We should check alignment properties for cris, nios2 and or1k]

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20180502215730.28162-1-laurent@vivier.eu>

+19 -29
+1 -1
include/exec/user/abitypes.h
··· 15 15 #define ABI_LLONG_ALIGNMENT 2 16 16 #endif 17 17 18 - #if defined(TARGET_I386) && !defined(TARGET_X86_64) 18 + #if (defined(TARGET_I386) && !defined(TARGET_X86_64)) || defined(TARGET_SH4) 19 19 #define ABI_LLONG_ALIGNMENT 4 20 20 #endif 21 21
+7
linux-user/arm/target_structs.h
··· 49 49 abi_ulong __unused5; 50 50 }; 51 51 52 + struct target_oabi_flock64 { 53 + abi_short l_type; 54 + abi_short l_whence; 55 + abi_llong l_start; 56 + abi_llong l_len; 57 + abi_int l_pid; 58 + } QEMU_PACKED; 52 59 #endif
+7 -7
linux-user/syscall.c
··· 6600 6600 typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 *fl); 6601 6601 6602 6602 #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32 6603 - static inline abi_long copy_from_user_eabi_flock64(struct flock64 *fl, 6603 + static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl, 6604 6604 abi_ulong target_flock_addr) 6605 6605 { 6606 - struct target_eabi_flock64 *target_fl; 6606 + struct target_oabi_flock64 *target_fl; 6607 6607 short l_type; 6608 6608 6609 6609 if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { ··· 6620 6620 return 0; 6621 6621 } 6622 6622 6623 - static inline abi_long copy_to_user_eabi_flock64(abi_ulong target_flock_addr, 6623 + static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr, 6624 6624 const struct flock64 *fl) 6625 6625 { 6626 - struct target_eabi_flock64 *target_fl; 6626 + struct target_oabi_flock64 *target_fl; 6627 6627 short l_type; 6628 6628 6629 6629 if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) { ··· 11629 11629 to_flock64_fn *copyto = copy_to_user_flock64; 11630 11630 11631 11631 #ifdef TARGET_ARM 11632 - if (((CPUARMState *)cpu_env)->eabi) { 11633 - copyfrom = copy_from_user_eabi_flock64; 11634 - copyto = copy_to_user_eabi_flock64; 11632 + if (!((CPUARMState *)cpu_env)->eabi) { 11633 + copyfrom = copy_from_user_oabi_flock64; 11634 + copyto = copy_to_user_oabi_flock64; 11635 11635 } 11636 11636 #endif 11637 11637
+4 -21
linux-user/syscall_defs.h
··· 2649 2649 }; 2650 2650 2651 2651 struct target_flock64 { 2652 - short l_type; 2653 - short l_whence; 2654 - #if defined(TARGET_PPC) || defined(TARGET_X86_64) || defined(TARGET_MIPS) \ 2655 - || defined(TARGET_SPARC) || defined(TARGET_HPPA) \ 2656 - || defined(TARGET_MICROBLAZE) || defined(TARGET_TILEGX) \ 2657 - || defined(TARGET_XTENSA) 2658 - int __pad; 2659 - #endif 2652 + abi_short l_type; 2653 + abi_short l_whence; 2660 2654 abi_llong l_start; 2661 2655 abi_llong l_len; 2662 - int l_pid; 2663 - } QEMU_PACKED; 2664 - 2665 - #ifdef TARGET_ARM 2666 - struct target_eabi_flock64 { 2667 - short l_type; 2668 - short l_whence; 2669 - int __pad; 2670 - abi_llong l_start; 2671 - abi_llong l_len; 2672 - int l_pid; 2673 - } QEMU_PACKED; 2674 - #endif 2656 + abi_int l_pid; 2657 + }; 2675 2658 2676 2659 struct target_f_owner_ex { 2677 2660 int type; /* Owner type of ID. */