From patchwork Thu Apr 5 13:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10324651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9F5ED600CB for ; Thu, 5 Apr 2018 13:48:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EB4A28FD4 for ; Thu, 5 Apr 2018 13:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82C7529086; Thu, 5 Apr 2018 13:48:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1232F28FD4 for ; Thu, 5 Apr 2018 13:48:28 +0000 (UTC) Received: from localhost ([::1]:59096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f45Fc-0005Ft-4B for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 Apr 2018 09:48:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f45Ei-0004r2-Vs for qemu-devel@nongnu.org; Thu, 05 Apr 2018 09:47:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f45Ed-0001Ds-3X for qemu-devel@nongnu.org; Thu, 05 Apr 2018 09:47:33 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:38072) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f45Ec-0001Df-Se for qemu-devel@nongnu.org; Thu, 05 Apr 2018 09:47:27 -0400 Received: by mail-wr0-x242.google.com with SMTP id m13so28536378wrj.5 for ; Thu, 05 Apr 2018 06:47:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PuodgsbA8IDd283uzH+24nshLtwInHw0HJpl8kdJHT0=; b=i2F6YFUg+9IdZZaR9wYmPIxnELMPbzflcAoS/NXrHc396BLb4CEnLhd6OFVnM+lKAH SbIBf0ClFmcKyX3CuVXlXeyb+tU4UV34p6NmO7AZaqQnAsajHn/C7shCcLHV7VATeVRt S+SP84OfCNdCf/DW9/3XiHkR/9mi4Ef7dXEErAM6YiINL4Zv/FsXAAQQbKToWX3ASD6P qajg3Wqg+VrXqyTZ8F3zPmEiHvH6EPVcojdWOtuMJwatoHAkJtUR0nFXtZ7NrUHnoN2h hXEh8nw4PX1ldNGfo2Epba3b6D14uNWDHzL/NsWHO+KL3zODOp3wQ01ucvehc4zzF4J6 jlqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PuodgsbA8IDd283uzH+24nshLtwInHw0HJpl8kdJHT0=; b=O39m81Bb1thkTmY6e4GlMINm8L++Fmwu2upTUDJDfHdBjH78itZdefUEe+T+6Wq4bB vBz8tIUjf9aRMi7VxsYZP0reidpEcjKH6lvi7ApznzOuDPopgbRl6hdD56e7d27nuJn5 2A7+etYas1QPzc7JNKXACmoaiTxHrJBbA0XHM7GzBptxFlx9rEmbBeAL/7SqLkWAc3WN Yl4ZLDh6HdG4IkxqLHGrtJdsasr565jsI//ZNbaMXj+TUzVAAu7ljVx7r/WbxtzUwoQx TpnaX3u+0Yet8e3ARaBO13WWjyL/Wz//78T6yk1YxAubpCyYJdvif2tw0DY0iGx5XIq6 6RhA== X-Gm-Message-State: ALQs6tBjmxRg7wIP02lL0TZztWq6YIPenExe0B5g2R/5Hzm/V0LS9Jyu pm1HbG5byOLEAwHPaT0LEij3Cw== X-Google-Smtp-Source: AIpwx4/iwD1St29eoO2LZq2f2aPLmYweLzzEmQODNlrwnzras851CxZiwv876kW9fV5WoxuDNtXyEQ== X-Received: by 2002:a19:914a:: with SMTP id y10-v6mr13990824lfj.91.1522936045446; Thu, 05 Apr 2018 06:47:25 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net. (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id 1sm1304819lje.38.2018.04.05.06.47.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 06:47:24 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Thu, 5 Apr 2018 06:47:02 -0700 Message-Id: <20180405134702.5020-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH v3] linux-user: fix preadv/pwritev offsets 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: Peter Maydell , Riku Voipio , Richard Henderson , Laurent Vivier , Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP preadv/pwritev accept low and high parts of file offset in two separate parameters. When host bitness doesn't match guest bitness these parts must be appropriately recombined. Introduce target_to_host_low_high that does this recombination and use it in preadv/pwritev syscalls. This fixes glibc testsuite test misc/tst-preadvwritev64. Signed-off-by: Max Filippov --- Changes v2->v3: - rename helper to target_to_host_low_high; - handle cases TARGET_LONG_BITS * 2 > HOST_LONG_BITS and TARGET_LONG_BITS < 2 * HOST_LONG_BITS correctly. Changes v1->v2: - fix host high computation in TARGET_LONG_BITS > HOST_LONG_BITS case linux-user/syscall.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5ef517613577..13ad572e0d3b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3386,6 +3386,30 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, return ret; } +static void target_to_host_low_high(abi_ulong tlow, + abi_ulong thigh, + unsigned long *hlow, + unsigned long *hhigh) +{ +#if TARGET_LONG_BITS == HOST_LONG_BITS + *hlow = tlow; + *hhigh = thigh; +#elif TARGET_LONG_BITS < HOST_LONG_BITS + *hlow = tlow | (unsigned long)thigh << TARGET_LONG_BITS; +#if TARGET_LONG_BITS * 2 <= HOST_LONG_BITS + *hhigh = 0; +#else + *hhigh = (unsigned long)thigh >> (HOST_LONG_BITS - TARGET_LONG_BITS); +#endif +#else + *hlow = (unsigned long)tlow; + *hhigh = (unsigned long)(tlow >> HOST_LONG_BITS); +#if TARGET_LONG_BITS < 2 * HOST_LONG_BITS + *hhigh |= (unsigned long)thigh << (TARGET_LONG_BITS - HOST_LONG_BITS); +#endif +#endif +} + static struct iovec *lock_iovec(int type, abi_ulong target_addr, abi_ulong count, int copy) { @@ -10449,7 +10473,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0); if (vec != NULL) { - ret = get_errno(safe_preadv(arg1, vec, arg3, arg4, arg5)); + unsigned long low, high; + + target_to_host_low_high(arg4, arg5, &low, &high); + ret = get_errno(safe_preadv(arg1, vec, arg3, low, high)); unlock_iovec(vec, arg2, arg3, 1); } else { ret = -host_to_target_errno(errno); @@ -10462,7 +10489,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1); if (vec != NULL) { - ret = get_errno(safe_pwritev(arg1, vec, arg3, arg4, arg5)); + unsigned long low, high; + + target_to_host_low_high(arg4, arg5, &low, &high); + ret = get_errno(safe_pwritev(arg1, vec, arg3, low, high)); unlock_iovec(vec, arg2, arg3, 0); } else { ret = -host_to_target_errno(errno);