From patchwork Fri Dec 18 06:51:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 558761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CB5EA1402B4 for ; Fri, 18 Dec 2015 17:52:22 +1100 (AEDT) Received: from localhost ([::1]:58643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9oto-0003wI-MD for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2015 01:52:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ota-0003ex-7y for qemu-devel@nongnu.org; Fri, 18 Dec 2015 01:52:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9otV-0002y3-7m for qemu-devel@nongnu.org; Fri, 18 Dec 2015 01:52:06 -0500 Received: from mail113-248.mail.alibaba.com ([205.204.113.248]:47425 helo=us-alimail-mta1.hst.scl.en.alidc.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9otU-0002u5-Hy for qemu-devel@nongnu.org; Fri, 18 Dec 2015 01:52:01 -0500 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.07477574|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03304; MF=chengang@emindsoft.com.cn; NM=1; PH=DS; RN=5; RT=4; SR=0; TI=SMTPD_----4MhNZnn_1450421502; Received: from 192.168.0.165(mailfrom:chengang@emindsoft.com.cn ip:36.110.17.42) by smtp.aliyun-inc.com(10.147.43.194); Fri, 18 Dec 2015 14:51:43 +0800 To: riku.voipio@iki.fi References: <5673A718.40103@emindsoft.com.cn> From: Chen Gang Message-ID: <5673ACFA.6060900@emindsoft.com.cn> Date: Fri, 18 Dec 2015 14:51:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <5673A718.40103@emindsoft.com.cn> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 205.204.113.248 Cc: Peter Maydell , qemu-devel , Richard Henderson Subject: Re: [Qemu-devel] [PATCH] linux-user/syscall.c: Notice about lock bitmask translation for fcntl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org I found this issue during my working time, it is about sw_64 (almost the same as alpha) host running i386 wine programs. I also found another issue, but I am not quite sure whether it is worth enough for our upstream: The related fix patch is below, which will let the initialization slower, but for most archs, they have no this issue. linux-user/mmap.c: Always zero MAP_ANONYMOUS memory in target_mmap() In some architectures, they have no policy to zero MAP_ANONYMOUS memory, which will cause issue for qemu target_mmap. Signed-off-by: Chen Gang Thanks. On 2015年12月18日 14:26, Chen Gang wrote: > > For fcntl, it always needs to notice about it, just like do_fcntl() has > done, or it will cause issue (e.g. alpha host run i386 guest). > > Signed-off-by: Chen Gang > --- > linux-user/syscall.c | 18 ++++++++++++------ > 1 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index 0f8adeb..1a60e6f 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -9007,7 +9007,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > if (((CPUARMState *)cpu_env)->eabi) { > if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) > goto efault; > - fl.l_type = tswap16(target_efl->l_type); > + fl.l_type = target_to_host_bitmask(tswap16(target_fl->l_type), > + flock_tbl); > fl.l_whence = tswap16(target_efl->l_whence); > fl.l_start = tswap64(target_efl->l_start); > fl.l_len = tswap64(target_efl->l_len); > @@ -9018,7 +9019,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > { > if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) > goto efault; > - fl.l_type = tswap16(target_fl->l_type); > + fl.l_type = target_to_host_bitmask(tswap16(target_fl->l_type), > + flock_tbl); > fl.l_whence = tswap16(target_fl->l_whence); > fl.l_start = tswap64(target_fl->l_start); > fl.l_len = tswap64(target_fl->l_len); > @@ -9031,7 +9033,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > if (((CPUARMState *)cpu_env)->eabi) { > if (!lock_user_struct(VERIFY_WRITE, target_efl, arg3, 0)) > goto efault; > - target_efl->l_type = tswap16(fl.l_type); > + target_efl->l_type = host_to_target_bitmask( > + tswap16(fl.l_type), flock_tbl); > target_efl->l_whence = tswap16(fl.l_whence); > target_efl->l_start = tswap64(fl.l_start); > target_efl->l_len = tswap64(fl.l_len); > @@ -9042,7 +9045,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > { > if (!lock_user_struct(VERIFY_WRITE, target_fl, arg3, 0)) > goto efault; > - target_fl->l_type = tswap16(fl.l_type); > + target_fl->l_type = host_to_target_bitmask( > + tswap16(fl.l_type), flock_tbl); > target_fl->l_whence = tswap16(fl.l_whence); > target_fl->l_start = tswap64(fl.l_start); > target_fl->l_len = tswap64(fl.l_len); > @@ -9058,7 +9062,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > if (((CPUARMState *)cpu_env)->eabi) { > if (!lock_user_struct(VERIFY_READ, target_efl, arg3, 1)) > goto efault; > - fl.l_type = tswap16(target_efl->l_type); > + fl.l_type = target_to_host_bitmask(tswap16(target_fl->l_type), > + flock_tbl); > fl.l_whence = tswap16(target_efl->l_whence); > fl.l_start = tswap64(target_efl->l_start); > fl.l_len = tswap64(target_efl->l_len); > @@ -9069,7 +9074,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, > { > if (!lock_user_struct(VERIFY_READ, target_fl, arg3, 1)) > goto efault; > - fl.l_type = tswap16(target_fl->l_type); > + fl.l_type = target_to_host_bitmask(tswap16(target_fl->l_type), > + flock_tbl); > fl.l_whence = tswap16(target_fl->l_whence); > fl.l_start = tswap64(target_fl->l_start); > fl.l_len = tswap64(target_fl->l_len); > diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 7b459d5..9c9152d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -567,6 +567,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, printf("\n"); #endif tb_invalidate_phys_range(start, start + len); + if ((prot & PROT_WRITE) && (flags & MAP_ANONYMOUS) + && ((flags & MAP_PRIVATE) || (fd == -1))) { + memset(g2h(start), 0, len); + } mmap_unlock(); return start; fail: