From patchwork Wed May 31 13:08:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9756977 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 1ABB5603F7 for ; Wed, 31 May 2017 13:09:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16F93283B4 for ; Wed, 31 May 2017 13:09:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A3012836F; Wed, 31 May 2017 13:09:53 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, 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 8323D2834A for ; Wed, 31 May 2017 13:09:51 +0000 (UTC) Received: from localhost ([::1]:59320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Nm-0007SP-EZ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 May 2017 09:09:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Ma-0007S6-Fc for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG3MZ-0003bt-7L for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:36 -0400 Received: from mail-lf0-x232.google.com ([2a00:1450:4010:c07::232]:35553) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG3MY-0003bT-W4 for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:35 -0400 Received: by mail-lf0-x232.google.com with SMTP id c184so3857929lfe.2 for ; Wed, 31 May 2017 06:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1v97PnDIrhxByjUCVxjqIOe26eIkHOTAzNcJ3Z1LSCM=; b=evZkuvKhphpv82/JZuOI+//5zng4ZCV+nrPT2mBe4WIrUsfqY0vbr/SFQH8vMPG5KY uCAUu5QkpwIqZHYWCj2GBxdpVwIYki2jQAzTPYYpJnHC6V1WdwXIUm0FzK1/N+BKC+gk TH86h1pNItQQfsNdhVZJqXP3D7qUdI0LEqzOM= 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=1v97PnDIrhxByjUCVxjqIOe26eIkHOTAzNcJ3Z1LSCM=; b=b7SgWSixbxVJCCrdqy49XDBIvOnAW8ddCJ2Im2JH6DKTToIb1u4kH2W0942oLnQvYJ oh9zYlo5w/Hi4l/HL5iTWLgCHwqi1NVEjfnAchK/UybFYho91tSXIQ5U7KduH2oL156S QJkg67Du58M7qnUTeg40QmlRz+WrCJovczZWyOq1oLCiBA0n+mKCSvih57Gnz+AuTm8K CaQ843wAuV2Kq7a+8WNcPyyA5ZBCuhrk3z4DdCqSYu+fRBhyaHiYBerzsbOtAiN9TMYY QDJ1aAWWnqF2RWtdhuAwJo36GKgyvtP7XPND/nWG6qKhnE9bzc5miXUw7OpTrq219Yh0 Wc1g== X-Gm-Message-State: AODbwcBGeO3oe6wAOnvPq3cBflVfl9x0AfgR+J0kCVW+cYPoJ9S9yNZY yPkQ2XgJUMslqhiSOd2Y1g== X-Received: by 10.46.15.10 with SMTP id 10mr7836071ljp.12.1496236113559; Wed, 31 May 2017 06:08:33 -0700 (PDT) Received: from localhost.localdomain (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id o101sm3741766lfg.3.2017.05.31.06.08.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 06:08:32 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 16:08:14 +0300 Message-Id: <562a20b4ef63bdde6e2e5bac0da02302aeb5299f.1496234766.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::232 Subject: [Qemu-devel] [PULL 02/15] linux-user: fix eventfd 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@linaro.org, Laurent Vivier , stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Laurent Vivier When a fd is opened using eventfd(), a read provides a 64bit counter in the host byte order, and a write increase the internal counter by the provided 64bit value. Signed-off-by: Laurent Vivier Signed-off-by: Riku Voipio --- linux-user/syscall.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b2b563e388..2da8426aaa 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7671,6 +7671,28 @@ static target_timer_t get_timer_id(abi_long arg) return timerid; } +static abi_long swap_data_eventfd(void *buf, size_t len) +{ + uint64_t *counter = buf; + int i; + + if (len < sizeof(uint64_t)) { + return -EINVAL; + } + + for (i = 0; i < len; i += sizeof(uint64_t)) { + *counter = tswap64(*counter); + counter++; + } + + return len; +} + +static TargetFdTrans target_eventfd_trans = { + .host_to_target_data = swap_data_eventfd, + .target_to_host_data = swap_data_eventfd, +}; + /* do_syscall() should always have a single exit point at the end so that actions, such as logging of syscall results, can be performed. All errnos that do_syscall() returns must be -TARGET_. */ @@ -11876,7 +11898,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #if defined(TARGET_NR_eventfd) case TARGET_NR_eventfd: ret = get_errno(eventfd(arg1, 0)); - fd_trans_unregister(ret); + fd_trans_register(ret, &target_eventfd_trans); break; #endif #if defined(TARGET_NR_eventfd2) @@ -11890,7 +11912,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, host_flags |= O_CLOEXEC; } ret = get_errno(eventfd(arg1, host_flags)); - fd_trans_unregister(ret); + fd_trans_register(ret, &target_eventfd_trans); break; } #endif