From nobody Thu Nov 6 17:09:47 2025 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.zoho.com; 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488361144737762.5050571571046; Wed, 1 Mar 2017 01:39:04 -0800 (PST) Received: from localhost ([::1]:39316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0it-0006Y6-Eg for importer@patchew.org; Wed, 01 Mar 2017 04:39:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0hy-0006XL-Cf for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj0ht-0006pi-Iy for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:06 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:62166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj0ht-0006p8-A0 for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:01 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LpfUc-1c3bPk3NHq-00fR0r; Wed, 01 Mar 2017 10:37:51 +0100 From: Laurent Vivier To: Riku Voipio Date: Wed, 1 Mar 2017 10:37:47 +0100 Message-Id: <20170301093748.28033-2-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170301093748.28033-1-laurent@vivier.eu> References: <20170301093748.28033-1-laurent@vivier.eu> X-Provags-ID: V03:K0:CaJrGISoSwrFbeIGOnf6kqoWHDEB+thcA0Wf9CY3a4X0d+vfZrW LS5AjufLzZPN3Mt1IkfElwYkGGc1BB+Fp5Dxk9gr/kvRxEZFxVRA1bA/x0cWQRELY3MjE4G pjLIpi7gNGto3tuLveezlnKlNLGMMrj2Gfi9qxc0VQb4pJ+VfqK8Ud5E9LxQN9Pe+flyIBV jypzAQublNRDF6ainIvUQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:lQIu/PTXxHs=:TcCacSI8bOI0yRNamDO7L4 H5qitNdHmeRMp4JB3Oc+/1A4bdW3pML/dybUtDkF3RMRm8XH142VGbHoXrKdz24OOfIE6Fnv9 R46ekaym6JrbWPdyfJ/M3cNh6kWhCC1PyFlykzESfjMkwtQ/WYFUwDHUdXUTdKTW90CWJ5WTC oVsHUVYipOTkLQScsr/FKO+m6J069M3fbOp7wh2+OkVcjUhJKmYEACrwPvTyOl4OcwPi9X9Dg ctMMTsfsUqNPLIajmiiuu0BfFS0QfXZFKfJqgp1Dw8gUtQvXflHoHshWoR35k6Yo24L4/VUOk 3OQieyY9P47KzP6wFgf73RVGGwtJWgqrsW7srBb9enzPCo2KjXUlMolK+T7yc0g+6EbwyH6/7 MefHiy9ynF6YKQkLA7icqsGsZaR9JMXhAUs3lpTb8Fpwu/TnhLkoznzKa6rKo9fxntbJ4ku4/ vl+ET+Ajm8fqr3nZbWu3a96JEGT54k//nxaQASyxFI0GDyGLTX3h2jpslisXoApDIy5PjkHxg X/f19LJz9Q9k37nTOM/TYrxPbm1I0FpW2LVwUkgHPzq7xyO/40W/lTbVbbJdnhVDcPmttHggz tgokMFlJIA71fd7mmeE35MYV23xLW/iJvFWsHO+K4O2mcR2xvKGaKwPvWEuHkr9c8GrMdDR9o BrnetppuuLccNLxfemgtQ2FhmpUe91W/EKllz/PoaIZdc6r7ESKu3fXXB5Scx2J8ltWM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.74 Subject: [Qemu-devel] [PATCH 1/2] linux-user: call fd_trans_target_to_host_data() for write() 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: qemu-devel@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As for sendmsg() or sendto(), we must call the target to host data translator if it is defined. This is needed for eventfd(): the write() syscall allows to add a value to the internal counter, and so, it must be byte-swapped to the host order. Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index cec8428..b2b563e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7767,7 +7767,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long= arg1, case TARGET_NR_write: if (!(p =3D lock_user(VERIFY_READ, arg2, arg3, 1))) goto efault; - ret =3D get_errno(safe_write(arg1, p, arg3)); + if (fd_trans_target_to_host_data(arg1)) { + void *copy =3D g_malloc(arg3); + memcpy(copy, p, arg3); + ret =3D fd_trans_target_to_host_data(arg1)(copy, arg3); + if (ret >=3D 0) { + ret =3D get_errno(safe_write(arg1, copy, ret)); + } + g_free(copy); + } else { + ret =3D get_errno(safe_write(arg1, p, arg3)); + } unlock_user(p, arg2, 0); break; #ifdef TARGET_NR_open --=20 2.9.3 From nobody Thu Nov 6 17:09:47 2025 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.zoho.com; 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488361145037989.0668988961206; Wed, 1 Mar 2017 01:39:05 -0800 (PST) Received: from localhost ([::1]:39317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0it-0006YO-SI for importer@patchew.org; Wed, 01 Mar 2017 04:39:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0hz-0006XN-6w for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj0hu-0006q1-9g for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:07 -0500 Received: from mout.kundenserver.de ([217.72.192.75]:53763) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj0hu-0006pR-03 for qemu-devel@nongnu.org; Wed, 01 Mar 2017 04:38:02 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MSao8-1cqoAt1Lfg-00Rb7z; Wed, 01 Mar 2017 10:37:51 +0100 From: Laurent Vivier To: Riku Voipio Date: Wed, 1 Mar 2017 10:37:48 +0100 Message-Id: <20170301093748.28033-3-laurent@vivier.eu> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170301093748.28033-1-laurent@vivier.eu> References: <20170301093748.28033-1-laurent@vivier.eu> X-Provags-ID: V03:K0:iINZ8dArog/LxcGXXcdjm2QI0l9fZoBoScUJam4q4Wf4/0f3TVQ s79DvAftATll7DwRMEDN1Z46yAgsTLY42zeWDC+R39bNPDJnsrH96Jcj+SUkjqRFpV6uh2/ vBx8I175H7Jr4PFjTWE+blX5/nWFXXdbFN58d1ySXi5b7V+hSRChpXtEThY3/Dkd3WSHt/t k78IILVwI+nKiDJXTt3NQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:hOQHhRYpxWw=:jSySVA356pcFTtTXujEzch sn4P2DAXCRh6UI8yjPy53zXsnv3Rf84s7rJPC/3P4V8GFP7cIlLc4CotX3pZjFQ2jQ3CiQ2ad EWLoVqoGARLN6xh4VnkKo2/Mauic57677nEt2L1tIwdptb7xDf+r/jUWhwnFSUcCLLSnJrzia d1Hq/pC7TE9w/zTD/PIFUgEldjQBuqqZcWMQN6Fnzf7WblwspS12aIEr8LNvW1E6gK5FkViol oHPLcPm9OI6wBKbpc1xbE2cxE+py23mCPOyC6YjbonqsbZytDzuQOEYrfVeOLQnx5/StaEo0x CXJpu0mk6y4Jb48BL5OEXKdBVNsZw1Wc4nPDXRdkVWIt9/K01f4ww6S+OkitQwS1ImEgKnYOp 3Y/U+YVXli/gf+g8rN+TpnHAiK+YCktwB2le3CAVGKEKcIfXRpF/YYn/O1OJbgaekMv5vphyW BnkzT7LcFbENZZa7/EAZmkDdH7pjdokWcmuAZ58v2bv7HvPfXxD1/2349mPULNj7c+r2x9sED BC9Flve4YJVs3e9rDldqEJGS1Xtuj5V041NfwbUonQkZLFz52Ajcv+BHg+hBXjxM4OVkIODzu epZBTm074EXyF4WowWVW6i7bbtYN0PDirWAHkJ7KOh4hLU1nc+0SA00JO+ZAykX+E86AVp0+J M0KWlaC3QkYOgSA0xWwYTrfhKJ6PX7BWysOeGGMRpbtIAF7rs+dE34W4FzfF+kc4IVTs= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.75 Subject: [Qemu-devel] [PATCH 2/2] 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: qemu-devel@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 b2b563e..2da8426 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; } =20 +static abi_long swap_data_eventfd(void *buf, size_t len) +{ + uint64_t *counter =3D buf; + int i; + + if (len < sizeof(uint64_t)) { + return -EINVAL; + } + + for (i =3D 0; i < len; i +=3D sizeof(uint64_t)) { + *counter =3D tswap64(*counter); + counter++; + } + + return len; +} + +static TargetFdTrans target_eventfd_trans =3D { + .host_to_target_data =3D swap_data_eventfd, + .target_to_host_data =3D 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_lon= g arg1, #if defined(TARGET_NR_eventfd) case TARGET_NR_eventfd: ret =3D 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_lon= g arg1, host_flags |=3D O_CLOEXEC; } ret =3D get_errno(eventfd(arg1, host_flags)); - fd_trans_unregister(ret); + fd_trans_register(ret, &target_eventfd_trans); break; } #endif --=20 2.9.3