From patchwork Thu Apr 5 01:33:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10323683 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 70E44602C8 for ; Thu, 5 Apr 2018 01:34:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F8DC29084 for ; Thu, 5 Apr 2018 01:34:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51B4B2908E; Thu, 5 Apr 2018 01:34:46 +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 DF31329084 for ; Thu, 5 Apr 2018 01:34:45 +0000 (UTC) Received: from localhost ([::1]:46094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3tnY-00040b-OQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 Apr 2018 21:34:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3tmV-0003NJ-RH for qemu-devel@nongnu.org; Wed, 04 Apr 2018 21:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f3tmU-0000NA-SN for qemu-devel@nongnu.org; Wed, 04 Apr 2018 21:33:39 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:39328) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f3tmU-0000Lp-LS for qemu-devel@nongnu.org; Wed, 04 Apr 2018 21:33:38 -0400 Received: by mail-wm0-x242.google.com with SMTP id f125so2142379wme.4 for ; Wed, 04 Apr 2018 18:33:38 -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=WHgmjoJ2y7/qc1RwL/+u9Ha0jrDZImfn5cHKA9hgq/U=; b=OqpdTA8FVkXfgQMihP8JNxlvtwv1X5OnGxHkP09Tp9dr8WRezsMA3xN5PRcknK7TWP KmwQ95OVXzR45ba08eVD2LCcz/kqca9AbaZx2N/jW6rGXdL76dLZ+wfkkWrqNyPHLDFd kirRj+oxRaOU+BoB+GwhsxbLOVS3Sn1jTpeG71Oa32NuVAIDepg45ql4wexNJ7NeCOLL Ke7jF45cbNGTXJ2Zf3akkRzmyJYukKOyG/pDIqryAlrC6olReHgz6Ks2BUrn/Nw0f+vX FxcjCxwgbLMczgSpR2YC/w0BpFGqwOlVuexA3x4zLBVk/W+x3g7WgbxSCEJlho7fsy7Q o68A== 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=WHgmjoJ2y7/qc1RwL/+u9Ha0jrDZImfn5cHKA9hgq/U=; b=h6ZMiKVYzycbvI1PYUjCGaQdZGmVxZ4buTjAWBteIZJCWSIOaZxuRNBvbGt3Q9HD5f sQ9sbrMpqH2sOZx9ZCwweFwsU4XOKJbX1wruCCN5gywxuzjnw3Ne2iJmlGg8URb0MLx7 HpKSw1zRdelg/NBbpcTzl+CTjr8I3P6fUehn8K23axiIH8PefJ8qpbOsZlB50jxIsKjN 4wqsvmGbPMOqjkLLxm+DZymzqlcBMwx3+AE7PUacYvcA74xyT5FECk7thZJVVVKPAUiX xXGT9HsigRi03yl1ZQJ5VHLPfDNFkjeTtelPJJHoOYizF41hgBvPsjTBhz56H9Zd6yiK Q4Tw== X-Gm-Message-State: AElRT7FKXgNKCO+vCK/fLk6u47/inFUgGU+tvntRL2wJR3og9fppNvWd 6iEvVkoMsz++0VucOaKRZrDIOg== X-Google-Smtp-Source: AIpwx49Qi+Dt3AAgUqQEnhOFLNIeNQMFZkqGq/VOhpVdFXlUpvmXirAXnc+2gMXAF6LGj9Vwgei3jw== X-Received: by 10.46.137.83 with SMTP id b19mr13024668ljk.111.1522892017232; Wed, 04 Apr 2018 18:33:37 -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 m18-v6sm1257394lfj.32.2018.04.04.18.33.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Apr 2018 18:33:36 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Wed, 4 Apr 2018 18:33:21 -0700 Message-Id: <20180405013321.3129-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:c09::242 Subject: [Qemu-devel] [PATCH] 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 , 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_low_high_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 --- linux-user/syscall.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5ef517613577..dfa015b9354d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3386,6 +3386,23 @@ static abi_long do_getsockopt(int sockfd, int level, int optname, return ret; } +static void target_low_high_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; + *hhigh = 0; +#else + *hlow = (unsigned long)tlow; + *hhigh = (unsigned long)(thigh >> HOST_LONG_BITS); +#endif +} + static struct iovec *lock_iovec(int type, abi_ulong target_addr, abi_ulong count, int copy) { @@ -10449,7 +10466,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_low_high_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 +10482,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_low_high_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);