From patchwork Tue Apr 10 02:17:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10332221 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 4F62F6028A for ; Tue, 10 Apr 2018 02:19:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 409E7287DA for ; Tue, 10 Apr 2018 02:19:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 357E52882A; Tue, 10 Apr 2018 02:19:37 +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=-7.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,MAILING_LIST_MULTI, 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 A42E0287DA for ; Tue, 10 Apr 2018 02:19:36 +0000 (UTC) Received: from localhost ([::1]:57397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f5ish-0006Tt-Tt for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Apr 2018 22:19:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f5ira-0005hi-B6 for qemu-devel@nongnu.org; Mon, 09 Apr 2018 22:18:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f5irZ-0003Xb-Ap for qemu-devel@nongnu.org; Mon, 09 Apr 2018 22:18:26 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:35117) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f5irZ-0003X9-1y for qemu-devel@nongnu.org; Mon, 09 Apr 2018 22:18:25 -0400 Received: by mail-lf0-x241.google.com with SMTP id j20-v6so9379846lfk.2 for ; Mon, 09 Apr 2018 19:18:24 -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:in-reply-to:references; bh=NRO+5mIvbqQRFPnoeDlYIrscQvaqurzKZaIc1Ev/rdg=; b=MCe1e4hTvw69+VjgmtfGBz5cZh2kWqcyOQ8gXMVqvT0Zqd1fDW44DM7ufYhQ8Q+ip0 qNhGku63yywwedV5Ugcegig65/mH2ugsARPpfptSSW2Vm4K0uRMhbWblY2dHv+jU71gu IDOcDKJeX7ijO4kfdzN4SNrOVTdixJ9pypyp8A4XRRv5rVOdoPk23GbLfmNyEtiNFhp/ M3be935KB1RJWu/d74CzEFdeLNq6W5HQDKPvNFePAAkeI75tOQRT7vr4tXCimRr7Th9a Ycma9aeXGYhskKOyVWa0p8brYdE/Hu8Klaf5JzYYaAP49vriE9pG4fxJAcxD68T9GIEq 38wA== 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:in-reply-to :references; bh=NRO+5mIvbqQRFPnoeDlYIrscQvaqurzKZaIc1Ev/rdg=; b=pBo9iDkQ8sqeq4hIumQ2SOlNc7tzuwr5FdydW1zD/C6jddbTvT3pcFpLO7e7OIdIrU v5lX6rybM4hozBHSncEWz+zocB3kQ9sRAJ7Zistdzf9bhHS/cg9YkupMUw7SjkwGZcK5 qhaS2QUBnsNDyl/oxSbbYkRDHZltsoC/BIkrUxSkYa0h4Sx7r8fzkJilWlkm/f36k1oG Xxr8UdOP9jOMMWSqc5GbTSyYNSMFA+S8oVAxPTwSkFqSjqF9C6x7+dZbUjqjOP8oondy 2xt5o/K/anDZ9bcXfD/m/cU1EGmxIuR+wtL6wg1BgI+vhIVcaPVJBlyIkY6bp7dSVvbB yy5w== X-Gm-Message-State: ALQs6tDenF6sj3pyABfktmrEYIyCBlSdb2p2UWAS31sbiv7H2MEMAn6t +xkZXcgzyY8jqeuRQtHE2uxIDQ== X-Google-Smtp-Source: AIpwx49i+DnbdoUNKQ9wFLfU+FCYODESjQg4Ma7AQJXq+cJycZtfwdICBHee0JLe06M7+EctuU1cxA== X-Received: by 10.46.1.213 with SMTP id f82mr24051571lji.35.1523326703574; Mon, 09 Apr 2018 19:18:23 -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 h10sm283308ljc.96.2018.04.09.19.18.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Apr 2018 19:18:22 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Mon, 9 Apr 2018 19:17:45 -0700 Message-Id: <20180410021745.32378-2-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180410021745.32378-1-jcmvbkbc@gmail.com> References: <20180410021745.32378-1-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PULL 1/1] 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. Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson 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..0eab5cc6ade1 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; } +/* Convert target low/high pair representing file offset into the host + * low/high pair. This function doesn't handle offsets bigger than 64 bits + * as the kernel doesn't handle them either. + */ +static void target_to_host_low_high(abi_ulong tlow, + abi_ulong thigh, + unsigned long *hlow, + unsigned long *hhigh) +{ + uint64_t off = tlow | + ((unsigned long long)thigh << TARGET_LONG_BITS / 2) << + TARGET_LONG_BITS / 2; + + *hlow = off; + *hhigh = (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 +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_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_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);