From patchwork Wed May 2 17:18:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 907630 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40blQF00P1z9s02 for ; Thu, 3 May 2018 03:19:46 +1000 (AEST) Received: from localhost ([::1]:51649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDvPr-0007mp-2B for incoming@patchwork.ozlabs.org; Wed, 02 May 2018 13:19:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDvPS-0007lO-HY for qemu-devel@nongnu.org; Wed, 02 May 2018 13:19:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDvPO-0007fk-Vj for qemu-devel@nongnu.org; Wed, 02 May 2018 13:19:18 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:55883) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fDvPO-0007dr-8W for qemu-devel@nongnu.org; Wed, 02 May 2018 13:19:14 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MZlny-1evib80h2c-00LYoz; Wed, 02 May 2018 19:19:04 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Wed, 2 May 2018 19:18:53 +0200 Message-Id: <20180502171853.25332-1-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 X-Provags-ID: V03:K1:KQlSbyVRdzi4ZNwAmT4dhOjg4adNWXdEJblutSTG7+XtdVXombo B6lrN284ztqvZ6KUANRH8UUm/wDm70acts+bZV68brZRMjkBHU1Yc8oKhM0wKN5bIa0EL+R GWaJh1ZzpmOL/BtV7pREvsyp/DMk/RZvoUegUQtGzFOutLHdO0fbGtdi2dLFtNIV6bHKg75 njMGfdpSGcwncp9HhLOgg== X-UI-Out-Filterresults: notjunk:1; V01:K0:fA9s7j7adGg=:JbkqwsekHDuisk61Md7r9E EEHQHLxsA4+6a6NfkKaiO8Leoj4Nz2x7PlWlPc+qh58oxgc/LUG3klaNGA4fr+ryJvbaufDG1 LUL7s5aE3/qS/M4OnSw3tb+HPpRtIU1YJJwwkW5DNmoz9J8yrWvvTJNMtEIb+zp+nJ04zf0w2 zS9DSeg8ah1Rh5FKIB7/wokuP4GeXHDSgc+HMjV/zfL5EH7SSISkHxnpMfr7fB4bmJe8UMhlU yFvva3Msj6Z3FOvLvwglkx/A/hNFI+E6Mz1+81GxI5BE3GJZe8DzWx4yQIJBklSqT9DZdyhq5 W3EisS4BzRSBow4mKYlUm2c3XzXPID1jBocYZkDknY5B1GWcczFSwdo+ImJF06pHg5MW0xnMK 3lPaujk772IeC11VHKzILzH+K8rzVxAxTQebBNBJ6vdEz3VL1Z5J6OATK1ULzjtG1nFlY2TrM Z4AipKrvwlDWZqgG9F24AsIXrcDdAfEvHUkXKS9YVNCRh/yS0TjKgf07TR+lPhK6OvwfogQA9 iJ1MWraPMOwF3QYYW/zdrOnIBYySHEUOv+i40TvaVOwXjJ0j4vjLxJeiLNOqzvZm03YlpW08B VCigbHUDOeqEC+HPtmcRNxxyDBWc4p7sUHbFu8p87GuBirU30hzTK4QBNXZG+DOuWYtPpRz47 8L9B8/13cqFGwVAHyWT8UzI61r7bc56xYrnnli023QNyToxDuLJjohKvsfMVsLh6m3zw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH v2] linux-user: remove useless padding in flock64 structure 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 , Richard Henderson , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 <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 #define __USE_LARGEFILE64 #include 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 Reviewed-by: Richard Henderson --- Notes: v2: - use target_flock64 for ARM EABI, and define target_oabi_flock64 for ARM OABI I missed the change in v1 because I've tested the result of gcc offsetof() and it uses the EABI whereas target_flock64 was OABI. include/exec/user/abitypes.h | 2 +- linux-user/syscall.c | 14 +++++++------- linux-user/syscall_defs.h | 25 +++++++++---------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h index ba188608c2..743b8bb9ea 100644 --- a/include/exec/user/abitypes.h +++ b/include/exec/user/abitypes.h @@ -15,7 +15,7 @@ #define ABI_LLONG_ALIGNMENT 2 #endif -#if defined(TARGET_I386) && !defined(TARGET_X86_64) +#if (defined(TARGET_I386) && !defined(TARGET_X86_64)) || defined(TARGET_SH4) #define ABI_LLONG_ALIGNMENT 4 #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 404be44ad5..e4825747f9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6600,10 +6600,10 @@ typedef abi_long from_flock64_fn(struct flock64 *fl, abi_ulong target_addr); typedef abi_long to_flock64_fn(abi_ulong target_addr, const struct flock64 *fl); #if defined(TARGET_ARM) && TARGET_ABI_BITS == 32 -static inline abi_long copy_from_user_eabi_flock64(struct flock64 *fl, +static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl, abi_ulong target_flock_addr) { - struct target_eabi_flock64 *target_fl; + struct target_oabi_flock64 *target_fl; short l_type; if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { @@ -6620,10 +6620,10 @@ static inline abi_long copy_from_user_eabi_flock64(struct flock64 *fl, return 0; } -static inline abi_long copy_to_user_eabi_flock64(abi_ulong target_flock_addr, +static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr, const struct flock64 *fl) { - struct target_eabi_flock64 *target_fl; + struct target_oabi_flock64 *target_fl; short l_type; if (!lock_user_struct(VERIFY_WRITE, target_fl, target_flock_addr, 0)) { @@ -11629,9 +11629,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, to_flock64_fn *copyto = copy_to_user_flock64; #ifdef TARGET_ARM - if (((CPUARMState *)cpu_env)->eabi) { - copyfrom = copy_from_user_eabi_flock64; - copyto = copy_to_user_eabi_flock64; + if (!((CPUARMState *)cpu_env)->eabi) { + copyfrom = copy_from_user_oabi_flock64; + copyto = copy_to_user_oabi_flock64; } #endif diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 23f5bccf0e..9a075eb3fd 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -2649,27 +2649,20 @@ struct target_flock { }; struct target_flock64 { - short l_type; - short l_whence; -#if defined(TARGET_PPC) || defined(TARGET_X86_64) || defined(TARGET_MIPS) \ - || defined(TARGET_SPARC) || defined(TARGET_HPPA) \ - || defined(TARGET_MICROBLAZE) || defined(TARGET_TILEGX) \ - || defined(TARGET_XTENSA) - int __pad; -#endif + abi_short l_type; + abi_short l_whence; abi_llong l_start; abi_llong l_len; - int l_pid; -} QEMU_PACKED; + abi_int l_pid; +}; -#ifdef TARGET_ARM -struct target_eabi_flock64 { - short l_type; - short l_whence; - int __pad; +#if defined(TARGET_ARM) && defined(TARGET_ABI32) +struct target_oabi_flock64 { + abi_short l_type; + abi_short l_whence; abi_llong l_start; abi_llong l_len; - int l_pid; + abi_int l_pid; } QEMU_PACKED; #endif