From nobody Sat May 11 06:31:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522978699104803.4800853565605; Thu, 5 Apr 2018 18:38:19 -0700 (PDT) Received: from localhost ([::1]:42009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f4GKM-0007l5-C1 for importer@patchew.org; Thu, 05 Apr 2018 21:38:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f4GJJ-0007O6-Dn for qemu-devel@nongnu.org; Thu, 05 Apr 2018 21:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f4GJI-00065L-FB for qemu-devel@nongnu.org; Thu, 05 Apr 2018 21:37:01 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:54628) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f4GJI-000657-7N for qemu-devel@nongnu.org; Thu, 05 Apr 2018 21:37:00 -0400 Received: by mail-wm0-x241.google.com with SMTP id r191so9976666wmg.4 for ; Thu, 05 Apr 2018 18:36:59 -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 j74-v6sm1788924lfi.97.2018.04.05.18.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 18:36:57 -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=n/fLfD7/PS/aYpWiUK47pTdnjyOFOQf1mDcJ8fpwcvA=; b=ZuSssOlsV8zK0JVvrQjdLtGjm3q/fHdi4l9TwT8jqusATM6hyc0HNOBdnBfzXZl98H XV3xvZQqj409DHh57LNF304EcMliz7b89XyTib3oSt/vydnu5YNWDhN5GG0UfNWh2G8s 2mAHZ3pxrxCYxu1/ZV/36hTAnbV+7Mo/U+WejaOMHFlxmX38tYYC0O1PFrLUTEcbUoco WSZUO7g4PU7H6wMRTiOMjOs5XWyUD1FC6tBISs6rIG9f/IVWtILVv5zqHzosPj0bJMB2 ZltDX7g2b1rEQ3WrNJ8Nklw1nhQkAY33c4apwbkyZ7QHA2InBGae6+ZQgY2nAcskHFQR F1hA== 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=n/fLfD7/PS/aYpWiUK47pTdnjyOFOQf1mDcJ8fpwcvA=; b=Z/QruhcZ4648ENbay5u0FqYdjP8/jmTbW7D2EAlcmepsMZ8xdiOq4hv7bKval1o5Tz prZ9oen2yAngS7fLZNEtGMcDWtguwUBt//UBcxoV7vEUScbTaqE/0tJ4DnS8cItR/rI2 Uccx3VO2wBfYF8cGbxemoY+NyOcwdHyO2e+9nlfxZZ+UxRI4lH0Blvv3O3c1DzY6vQW8 VwnTNHGgf5XLtc9SfIv0vDlB4aFZK6EGGliq7DhfbX1TX0TqvEwdQ2L/3omYeGZAHjow iZihYnnEDIHCV95OagxDnNOvcWM2vIzNKkEqn8N4OP+9zkADZ2nMQEJL5CzPaCP1H5fG PSUw== X-Gm-Message-State: ALQs6tAMtm2SCnu0sM0+N3GxWgld9YlOT5k3UTcDer+EyPsVxBoFHyqJ BbnrwJJe7h4PeEaaQ4kM7YNA5Q== X-Google-Smtp-Source: AIpwx4/bMfkycXeq0meiVlOaL1CUbH8XX0AEJDk2vcL95HYIyY4MyUMkVw5GP4yV+IpFkRcCnVxCYQ== X-Received: by 10.46.45.10 with SMTP id t10mr9250571ljt.110.1522978618742; Thu, 05 Apr 2018 18:36:58 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Thu, 5 Apr 2018 18:36:28 -0700 Message-Id: <20180406013628.25900-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::241 Subject: [Qemu-devel] [PATCH v4] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson --- Changes v3->v4: - recombine offset into unsigned long long and split it into two longs. 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 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5ef517613577..eb9a31f1e092 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3386,6 +3386,20 @@ static abi_long do_getsockopt(int sockfd, int level,= int optname, return ret; } =20 +static void target_to_host_low_high(abi_ulong tlow, + abi_ulong thigh, + unsigned long *hlow, + unsigned long *hhigh) +{ + unsigned long long off =3D tlow | + ((unsigned long long)thigh << TARGET_LONG_BITS / 2) << + TARGET_LONG_BITS / 2; + + *hlow =3D (unsigned long)off; + *hhigh =3D (unsigned long)((off >> HOST_LONG_BITS / 2) >> + HOST_LONG_BITS / 2); +} + static struct iovec *lock_iovec(int type, abi_ulong target_addr, abi_ulong count, int copy) { @@ -10449,7 +10463,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_lo= ng arg1, { struct iovec *vec =3D lock_iovec(VERIFY_WRITE, arg2, arg3, 0); if (vec !=3D NULL) { - ret =3D get_errno(safe_preadv(arg1, vec, arg3, arg4, arg5)= ); + unsigned long low, high; + + target_to_host_low_high(arg4, arg5, &low, &high); + ret =3D get_errno(safe_preadv(arg1, vec, arg3, low, high)); unlock_iovec(vec, arg2, arg3, 1); } else { ret =3D -host_to_target_errno(errno); @@ -10462,7 +10479,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_lo= ng arg1, { struct iovec *vec =3D lock_iovec(VERIFY_READ, arg2, arg3, 1); if (vec !=3D NULL) { - ret =3D get_errno(safe_pwritev(arg1, vec, arg3, arg4, arg5= )); + unsigned long low, high; + + target_to_host_low_high(arg4, arg5, &low, &high); + ret =3D get_errno(safe_pwritev(arg1, vec, arg3, low, high)= ); unlock_iovec(vec, arg2, arg3, 0); } else { ret =3D -host_to_target_errno(errno); --=20 2.11.0