From patchwork Fri Jul 7 13:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13304889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C12C3EB64D9 for ; Fri, 7 Jul 2023 13:21:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHlN7-0005QY-V8; Fri, 07 Jul 2023 09:19:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlN3-0005Q4-P9 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:38 -0400 Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlMz-0001Lf-Sc for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1688735969; x=1689340769; i=deller@gmx.de; bh=kW+aRGZnsWLqxw+XdUu3PLEnhXuIX+DbTAQorTksg3s=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=K9m4YF7YTMwB3FAZTJeIZAMIHRhcSbxiq6DuAuYBwRqD8Ddz9Jnwhk0u+YyDDaeojKpBRox TFmXT0Sm9xfn2caR2pvPQqY8cIXvnYzx1WPH8Y87c0K97j6644G4Xe1NOyOceosnDs1DZ8TE0 X6AmKVH3mk/yxBy+ON2glw3BIVNEGUjdppk8PwxLsbkMk72M7SBbcMJ+U3Lk/XpwHqRqPjWU1 bJhWNMb8DBpVymQ5XcGh9lhmEdXHTZgGmWqg2KPBLp+0j2vefEDTHwOTJuQ5G1iIe8ujXYbL1 JvGGxVJAGwi2Ya/Z4tohfZm/Fr5ZesDSe+0bH/Q2GuaqDVGpZ/IQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.153.180]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M8ykg-1qNnmh0iUY-00670Y; Fri, 07 Jul 2023 15:19:29 +0200 From: Helge Deller To: Laurent Vivier , Richard Henderson , qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 1/4] linux-user: Fix fcntl64() to return O_LARGEFILE for 32-bit targets Date: Fri, 7 Jul 2023 15:19:25 +0200 Message-ID: <20230707131928.89500-2-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230707131928.89500-1-deller@gmx.de> References: <20230707131928.89500-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZlUQJHL0WzuzH6nmDdzcVxEsTrW9dBTQ1reCPhnXQJbtVH4Begu GRNfzozyKHZVMXwtzJjDxO+mvT7fcZpwdECcxll3sQjlYfRLbTjC1E3ZHne4aFR96On8wBJ HjPDh6sY9DJdlW+wfoFP1GjWtuhg2f9nubucmjGJwVxORlEfq6NbIb5NlM4mcA1oXqalD0b HdkZVb5m3z/Vv/wKJzoeA== UI-OutboundReport: notjunk:1;M01:P0:r0dqhEGywF0=;1+MhtO3SEotqwaxRTKPr1oSWmW4 KpeDdvWOd17lEIGB9xoIKbur9h5KHNa8u/f1SVru/jGmDEEwcJS1YIw5D4hStzaDUwpfaK3W+ K3GkJOD25ue1W2zbmHK+t/L24dsS76YF4W3vLU7GU0zJ7BLSWYY20tVuQ3JNa+jMv/F1feGXE Q+MdgSfHC5QKcg2poYwXTxPhl+n/z28KsmciS+Z6jLQodfjjN2DzEw7kpCjBEEaDCq9iDPV9s zIXyV22vXRg8oae5G+utpKCOqYeGJUcL+tgH+S3bEpHRstW/3w8TeqBTkm7geWdvZJZ9Hr4u7 hDC8b4F2/U4v8PEpVJXlxAAnIw8E0IKSx6vmcXahC3aqVK479cuoyidEqwuPn3ekLNbh+LhO1 7FXjoFg0eHHWrXnbDQ1TuMZEhlO1Sz5VyhyuWIyeVvFvNU9JdgcKEYeWQbDodO6dg0eLUvgLd ZFovtmg/LRYK53jplrwBQA1UqYVY5enz1+FdSBtDFZvNn/0KxDgoBpBJg7OjjGij35x2MVzLY GxVKuHgvKrApbx3XFc75II/pScA0Y03dOVxNSGlyaC5po98UVK8AwfS8E7ytp8DzaSUzjl2rv kIM5ehgXImIrM3aS3npIM73dwIImhejles4sINjSEoOIcUAlM6B4tTIhTMPYpP+VspiKR9/K/ 9Kuum8KfchGRs/0v95XGYDh2LrxxBP5jImyOKgXONKybnzJbX/L5Mb1SbMT+6MuKyJV2uAy1O r5N2wOSvt9RCIcRlBaDM9vxyXbdo3aCcYwaelTyVLmmYZ0bmPunSTTktscLxYW/Ox1p9qnNLP s3jRV+s5ZpdGt84sU4YTGDGLQKpeNm3ZXPhZopL4I9/WF35DxW0PYVcy0pJSL8h+nVLs8iSER eCL+bNnLFdO3hnC3qJzP/sSRgv/y8aDsFLnbO3ZgNMHUW6xHTSVLUaRlroVSztEAjVDszHiFp IYQHdtEn4l/z8eVfum1BvgsKxkE= Received-SPF: pass client-ip=212.227.17.22; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On a 64-bit host, O_LARGEFILE has the value 0. When running a 32-bit guest on a 64-bit host, fcntl64(F_GETFL) should return with the O_LARGEFILE flag set, because the 64-bit host supports large files unconditionally. The flag translation should have happened in do_fcntl(), but since O_LARGEFILE is zero for 64-bit hosts, the translation can't be done with the translation table. Fix it by setting the TARGET_O_LARGEFILE flag unconditionally for 32-bit guests on 64-bit hosts when fcntl64() is called. Signed-off-by: Helge Deller --- linux-user/syscall.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.41.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 08162cc966..3f1e8e7ad9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12328,6 +12328,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, } switch(arg2) { +#if HOST_LONG_BITS == 64 && TARGET_LONG_BITS == 32 && \ + O_LARGEFILE == 0 && TARGET_O_LARGEFILE != 0 + case TARGET_F_GETFL: + ret = do_fcntl(arg1, arg2, arg3); + if (ret > 0) { + ret |= TARGET_O_LARGEFILE; + } + break; +#endif case TARGET_F_GETLK64: ret = copyfrom(&fl, arg3); if (ret) { From patchwork Fri Jul 7 13:19:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13304886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C509AEB64DA for ; Fri, 7 Jul 2023 13:20:29 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHlN4-0005Q5-67; Fri, 07 Jul 2023 09:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlN2-0005Ps-99 for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:36 -0400 Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlMz-0001Li-Hs for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1688735969; x=1689340769; i=deller@gmx.de; bh=6WonJGiwb08NSRPDtMmJ1dH8R4RTnTU1bZ6SBt5f838=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=O0xfyCjtoGEoFkNrKoqHjXbaGFeMR/Lsket6S4em5mdAaoRspi+r6ICZl88Fhiz4InbzOsQ 0YFtl8hmIznWl40aR/ACI+1iMsLh3mOEVFDw8p3g4BvqPwDP/KuJmD79pj3BZE4aGGBrdZsSC 1o041lUn8mSaC95e4C9NN9Ijhq6gW2oqeGr4KuNkdTQ8VbDU/QDtz5RJ1GbuC9F+3nuPILiXP iUP2oDKYGbHRsKH1ov4fbnJnqWGy3q33HszmKaAJu3kFE3Lcz+DpEmjhMFDgOCiazb26XBapn ictSNzr01XAFcJCr2fnCyxLXrywGLuWyOUYZB/bpKA4RbtCqAXWQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.153.180]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MgNct-1pmpH41M9X-00hufH; Fri, 07 Jul 2023 15:19:29 +0200 From: Helge Deller To: Laurent Vivier , Richard Henderson , qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 2/4] linux-user: Fix accept4(SOCK_NONBLOCK) syscall Date: Fri, 7 Jul 2023 15:19:26 +0200 Message-ID: <20230707131928.89500-3-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230707131928.89500-1-deller@gmx.de> References: <20230707131928.89500-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:H3OsHRqftZMyy6QFccnT4G6ZGuRzPTxzIO04ehjJ0/KwIcK1Esw LiL7LpTMLOayteUPs1z4LY9Kx2pj3OXEBoZeMUdHr4Z4uGwBqPLNSBMGK+hoel9MScUp/uB DjW5RLUYsCsachg8fEBbIhymhvXnYGmyzxzoaprbAKUCCj1e5jzDXOdzK0cOuBQ9/UUpuXu a1GjzBHfYUok5xwSAgR0A== UI-OutboundReport: notjunk:1;M01:P0:DkHW+fIjIXE=;jPtiNwaZeo0rAJSU5AfdQyaSXJA SlbIjxEC2qkLTLHxciYl+R/2lZ1yNuthB7nsdzPvOrR31eiRK0DB4kDZkLiKzZqdIejimBmAU V9VnbIZzc/ohVYttZ2Lx5WxJDOcLEv2OxjAoWwsL1KUXvJNRLne/+WLXw+rAIRiFAt1O9RQWG 1McNyFiOdKNKixKyhfrkjwsSMj2QSQ/ux39Ky6NW3tYdwSDWXwe0AFxxiN0hKYzYu65FYAPGk HmbVDtaxU29GkJFt0jGn0Elo4Zxe0uELyvLcbzs3tNaWOCaiHlUX63N4OskvQjjpxAfWVJQiT bi1u3cnIrfnqP2Mejr5DeIRzTKaQu4odRrMfTuJSA2k5i3Yu6nNQIhE37Z8LFvHLWQMR1vBnU o/i4M436KA2qWIYbo3Q+m4aRx+Kja72Rc3oSTfiA+YLG8aoJ/d/LUPDIReLowfa4EUEw0RMMR 12OP5aK3qZNDQvtgS0UZJeWRYRk4U/PSyXw2lzSpl2d2gdWtj+zrdU7nzxIcMJ0G9CNjt9fX0 bzXlBT89iXrrAmCIQn1NaEZQzHSzh/8AtrQW55WPnP7NVNMsKa6A+AqfHy+MypPOwvMkUeYHx 6+CWGehoANA4IT7pG9IU6h8s4qhBPbI1uZCFaalvq1QhUY3I722wUJ2kEg4JwINobniIxllRc 3miVT08gCSYgxx6LtbRjt72Ml94yI/DXOYUHytNZwQO6q/ybHKhCQXQwxX1c6Djsl5A19JLWo MkwwgC8YROAzIdvchrvfCQ3jvIK16TQJVT79Uov1L4JmURhc/5LGjmR41Cs4rJB0uHIxXmmTq tPYtpKAjOeRMAYra203oYqD2jPxds0snsH/n2I3F83lx01BpL1Psx89g/p27VzlH17LpqyUMH qEqQfCdTJpW/50m4ziEmQeN2ZKf7lLM7iaQK4ZrO3HE4tDQsEafeLlFUHlf9U/IGwI03Wr3lF S6Ez1U4mTX0WGyMEaxUCGnQmG/E= Received-SPF: pass client-ip=212.227.17.22; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The accept4() syscall takes two flags only: SOCK_NONBLOCK and SOCK_CLOEXEC. Even the real Linux kernel returns -EINVAL if any other bits have been set. Change the implementation of accept4() to recognize those two values only, instead of using the fcntl_flags_tbl[] bitmask translation. Beside this correction in behaviour, it actually fixes the accept4() emulation for hppa, mips and alpha targets for which SOCK_NONBLOCK is different than TARGET_SOCK_NONBLOCK. I noticed this wrong behaviour with the testcase of the debian lwt package which failed (by timeout while hanging in the read() syscall) in qemu but succeeded on real hardware. Signed-off-by: Helge Deller --- linux-user/syscall.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.41.0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3f1e8e7ad9..9e9317237d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3440,7 +3440,18 @@ static abi_long do_accept4(int fd, abi_ulong target_addr, abi_long ret; int host_flags; - host_flags = target_to_host_bitmask(flags, fcntl_flags_tbl); + host_flags = 0; +#if defined(SOCK_NONBLOCK) + if (flags & ~(TARGET_SOCK_CLOEXEC | TARGET_SOCK_NONBLOCK)) { + return -TARGET_EINVAL; + } + if (flags & TARGET_SOCK_NONBLOCK) { + host_flags |= SOCK_NONBLOCK; + } +#endif + if (flags & TARGET_SOCK_CLOEXEC) { + host_flags |= SOCK_CLOEXEC; + } if (target_addr == 0) { return get_errno(safe_accept4(fd, NULL, NULL, host_flags)); From patchwork Fri Jul 7 13:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13304890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7653DC001B0 for ; Fri, 7 Jul 2023 13:21:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHlNL-0005Sm-R9; Fri, 07 Jul 2023 09:19:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlNH-0005SA-ES for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:51 -0400 Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlMz-0001Lm-Sg for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1688735969; x=1689340769; i=deller@gmx.de; bh=3gegbpErrgWaM8LS/WzGk53g29olHqbZ9U4vgGMbxUM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=TLLqhc0ykZ5f5U5Sl/3uJZJZdrl56wCDAxafQCZfNgYoblA5t9eEni5WK19I2MhvvsVWGwb tRXY3VLwWpGsqGnUbxLfB3SiweBCEfFhMFSkCLY0gKJrzGZIBbgMqU96pZmnBx5R0xfPWQ1ep YT3mSS5HWuBEb6g8ZpzRDr6fceX9Vc1lcgAnGnde8602EVCQnUDTGhwhWEMSB9z/h/KwP8HuS YkIxtJezZOY2rFr4IjurUTA6/pOsKmQilyrokna9s+PlxGduoA/aWo4Awvc4D3HP5ow7+vnvB QhLk9wpZshgSZiVgoK1U2nEViNYuWuRl7NK9wZAGXUUFGurBlSkQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.153.180]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Ma24y-1qW9UD1zIi-00Vzcy; Fri, 07 Jul 2023 15:19:29 +0200 From: Helge Deller To: Laurent Vivier , Richard Henderson , qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 3/4] linux-user: Fix mmap2() syscall on 32-bit targets to allow file mapping beyond 4GB Date: Fri, 7 Jul 2023 15:19:27 +0200 Message-ID: <20230707131928.89500-4-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230707131928.89500-1-deller@gmx.de> References: <20230707131928.89500-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:ZAW1h6YRj62/VI73zK0JQ/vPesQQW5PKqUog3suzcwjwc239gOS 6+poevozp01xLPtXKTP+K5HJjaBDBS79QmJuWnW/nyzcWElI3lplz60OHI+4PCeLIg6WC7X 0749UIOQXjRXbBRLu/0XmxOrhPAPfye92OrigUoAMIx6ZWbNM0ulhGiA1Wrg+rmHcpHm6T9 zThLnbem3Fw6x7lFuuz+A== UI-OutboundReport: notjunk:1;M01:P0:/v1ePx1exIY=;lyXlUau7DSYU38Petpgv8MBopnj bbXMci6KYUHF7HRIR5wKkAeeuryotSNiyoonxZ06mHhGuqceWNtEgZgqH+Pr4emhF3vwqZJFa VbdFvmfvknfsvk5ysyFaU7ORDrS2jr52kGNa5C+y0iMM2MdHKP43lFevCdGcp+iEjX9yB+3mv vH6qvSnK8Vw6zdUAWN00F0GPqXL3OBxkD/mtoKy0V4lTadYLLui9CSlZCyFJDTro4i3Fe7f3z Ft4br4v/cnIbDTDXsSzHC6A+DJ8QOA5gg2MC6loxTby6N441+B5eWZvJdLxZmpVeHqgdUNQwf 2YkJAbLeN1PbsnUmC1kP6+1xs9JminlZo2Un4N8eiZjQOV+EdUomIoT2vPdn+JPrGV81Uwc+T NxVuqvUDeBPiZQv+r6ZuhhDOVV/8mWgvDE3QDMy2hipfCb/gmfCEABC/DQISGje+BWlWTkoDB xrxf3QWJXTMnNpNqmtO9MG0+VarRgRO/MbXdxMFAUnE8RWzNy7vpNWILYWRWO+Pj4VRMDMyTa 1kh+oadBn5gYsblju7FZgmIBaLirsYnlNUmCnG8nLdkweWsRbIDnfkmF9qMUYgjCPSFjAxcRG zIkxn1uK0AMAfM6FcdugOFvyikTYogbO7wbtxIca0rv6Qd0s4nui0UlVP12/bN2mxzsJt9jKb r/t0Jo7VjZI5WaiENKb+mhpb/hU8yL+7EQkWp55XonBtKtOnFo7aX8M4GIT9X/wtckpqzWGGS vHNAaQhIvj1SaoZGTPPrdSrEfkJQ/b/LebY9bLmhg6ni+BzDw1MowSvvXfeBYZdqmAVpOVDtb 2H/Q4IKftU2+I0ohnL40xbKDnmakOUAAzEH2bkJPnPFi2qFsDON9U6RVDtJ6R0K0iMxSoeKPe /dtucuKE30ER+lkAYeuTmftGd6gLz9dFrl58eVHpgAKrCmGwrzPklyZSuBDNzWIoo6cOLvmN8 fyxrK2GkudWw2zczFTVd0mu//j8= Received-SPF: pass client-ip=212.227.17.20; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The mmap2() syscall allows 32-bit guests to specify the offset into a file in page units (instead of bytes, as done by mmap(2)). On physical machines this allows 32-bit applications to map such parts of large files which are stored beyond the 4GB limit. Allow the same behaviour when emulating 32-bit guests with qemu. For that switch the mmap2() function to always take an abi_ullong (64-bit) offset parameter for target_mmap() and mmap_frag() to avoid an arithmetical overflow when shifing a 32-bit offset parameter by 12 bits (=PAGE_SHIFT) and thus possibly overflow the abi_ulong (32-bit) type. Signed-off-by: Helge Deller --- linux-user/mmap.c | 9 +++++---- linux-user/syscall.c | 2 +- linux-user/user-mmap.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) -- 2.41.0 diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 2692936773..2750146758 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -192,7 +192,7 @@ error: /* map an incomplete host page */ static int mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong end, - int prot, int flags, int fd, abi_ulong offset) + int prot, int flags, int fd, abi_ullong offset) { abi_ulong real_end, addr; void *host_start; @@ -436,10 +436,11 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) /* NOTE: all the constants are the HOST ones */ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, - int flags, int fd, abi_ulong offset) + int flags, int fd, abi_ullong offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len, + abi_ulong ret, end, real_start, real_end, retaddr, host_len, passthrough_start = -1, passthrough_end = -1; + abi_ullong host_offset; int page_flags, host_prot; mmap_lock(); @@ -627,7 +628,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_end) { void *p; - unsigned long offset1; + off_t offset1; if (flags & MAP_ANONYMOUS) offset1 = 0; else diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9e9317237d..5ebc502f71 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10427,7 +10427,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #endif ret = target_mmap(arg1, arg2, arg3, target_to_host_bitmask(arg4, mmap_flags_tbl), - arg5, arg6 << MMAP_SHIFT); + arg5, ((abi_ullong)arg6) << MMAP_SHIFT); return get_errno(ret); #endif case TARGET_NR_munmap: diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 480ce1c114..72e99000d9 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,7 +20,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, - int flags, int fd, abi_ulong offset); + int flags, int fd, abi_ullong offset); int target_munmap(abi_ulong start, abi_ulong len); abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, From patchwork Fri Jul 7 13:19:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13304888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F6E9C001B0 for ; Fri, 7 Jul 2023 13:20:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHlNH-0005Rs-69; Fri, 07 Jul 2023 09:19:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlND-0005R9-Ls for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:47 -0400 Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHlMz-0001Lp-KB for qemu-devel@nongnu.org; Fri, 07 Jul 2023 09:19:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1688735969; x=1689340769; i=deller@gmx.de; bh=IOgfBhVbwG0r69fo32lc7jonL/HryVyaw1Y9m04uDho=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=avQy9ehZwHO7KXT7+xNPgmDhxhJaoJIGHWlX6XcPrjlHVe4+fnJY09hrXs2orQ1ASUE4Nr1 BqGiJGguhVwoVFAEjFgTFiOpzx18azsb+VWHfAJoSxeXZ874PP09oVbtfVrCaKr9xJMs1+3Wb hSIntebY4N4Z+5tNCBP4XbMJof3U+r0Y7g/UaDZwTlELkixwaY5wi9xxfb8r6VCj54ufg9lgZ drAdIjp1LWsgOs/k/CfRiIxEvnzUVpscW03tIQSmgP8xaGoinH5Y2B28oOkkYXsl9oQlWIdPq 30sCgavbEq9qwbYi7y6chLNdrUr8n8tTsdhGNlsNipUrp54/NTxQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from p100.fritz.box ([94.134.153.180]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MplXp-1pdVbI2bPh-00q7sL; Fri, 07 Jul 2023 15:19:29 +0200 From: Helge Deller To: Laurent Vivier , Richard Henderson , qemu-devel@nongnu.org Cc: Helge Deller Subject: [PATCH 4/4] linux-user: Improve strace output of pread64() and pwrite64() Date: Fri, 7 Jul 2023 15:19:28 +0200 Message-ID: <20230707131928.89500-5-deller@gmx.de> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230707131928.89500-1-deller@gmx.de> References: <20230707131928.89500-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:w5aGYmQFcHDQ3bfY+lti8c3erT+KGUBxeJfx6LqDPz2QsCWxpW4 nCmH31ZG+QENIYAYuhHH25ilqxtT/vtj+5nWS9f0cR+KR8sLR9tW8YifiXjnLuEpitjyRw6 +YwZpy1B25caLRGl93xbOIptSyLwTAEy3ugnsonCwr+kheWngwY2jHKdpjaej2gECEN6eWh d9/vu1meAJyLLHOiTSK1g== UI-OutboundReport: notjunk:1;M01:P0:nQv6cQuPpdo=;ZNQ6bnpFCI39SFqKbPtVOcYohZF XQ5uIV6RhIPubsO9R1SBN5jS24RjVZImME9aM/fwGJBi+VYcclh99H98bjsC3sL3kUtS7Zrc3 m8GzgCE4l8H4SfQyTX/hzY49fkao+lNvFT9k0ADWoGC7TTbtYYL0pjNdi0ShfSQMpgXfS3ZoC TzxDByPExjoKJMFTUQJi/6c9Retls/CfIq7BFd+JYezktUidOUsFhmOgJBxFANSRcLrCAacXZ gK/inV+kNJmJ1cPd5+hzOg+312U+LZc82QJvN+rk238SIJLW8srmSwVRdsZexkeNRMB8ljZN1 TZdO9UD2gRSNM8q0F1lErhaDY9kwH1nNrcgYEdyMWo1A6w7rQhyRemhMSgIfMfEaSeLqguSZz FNkS9PBl+zvc05TqMxPyX1/wJbedFP+y+F0y3qN2faoT18rEeFj+Ew9dbGNoeFsboAW3Gp6eK oev8gKYqbta33Fo48H8LRgfmriQkjw6+5EzVLCB4UcBMkvR+5RxjVUraG9hloZBrBEYc059fQ Qm14PimuAqOI29K84fMMPVZ26DUKOf4A2jodJthO2RgPMvR5yVGfq+i8mlZ1sl+5aSC6wMG3Y 5Wfwog9U35jsUYoAqsE/D6X7FNUXfbfXNNa/znKH+ZmtlQcOjr1mousFp8gyLF3DES/d4GaSA fYR9k/Fy8HBAudJGOSLufgrov5QakduP0szF20lmqiK5TWY0SS7pMXiryv8W7x5mGv7mqfTo5 uvFP1btxIFPJcTyMTechY4WDJ2WsWZreLMlWEyA5x/wsx7Z7Ux3kc8ZRAQMlVHpjrVqyPMffR lzr0gEOxhYbuvK4DLdfrgw22XjGe6y6I5YrvY9/bA1ChaSCiJbSjyASbLz2njKA3YUk7z0VQf xWVqcn9z493e9CW6d7rGznOJsK5Vd4+53pRtjqKw+O7rMizXMaMCNTyhzHKQeHoGM/YDsJ0sh dHRwsg== Received-SPF: pass client-ip=212.227.17.22; envelope-from=deller@gmx.de; helo=mout.gmx.net X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Make the strace look nicer for those two syscalls. Signed-off-by: Helge Deller Reviewed-by: Richard Henderson --- linux-user/strace.c | 19 +++++++++++++++++++ linux-user/strace.list | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) -- 2.41.0 diff --git a/linux-user/strace.c b/linux-user/strace.c index aad2b62ca4..669200c4a4 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -3999,6 +3999,25 @@ print_tgkill(CPUArchState *cpu_env, const struct syscallname *name, } #endif +#if defined(TARGET_NR_pread64) || defined(TARGET_NR_pwrite64) +static void +print_pread64(CPUArchState *cpu_env, const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + if (regpairs_aligned(cpu_env, TARGET_NR_pread64)) { + arg3 = arg4; + arg4 = arg5; + } + print_syscall_prologue(name); + print_raw_param("%d", arg0, 0); + print_pointer(arg1, 0); + print_raw_param("%d", arg2, 0); + print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1); + print_syscall_epilogue(name); +} +#endif + #ifdef TARGET_NR_statx static void print_statx(CPUArchState *cpu_env, const struct syscallname *name, diff --git a/linux-user/strace.list b/linux-user/strace.list index c7808ea118..6655d4f26d 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1068,7 +1068,7 @@ { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_pread64 -{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL }, +{ TARGET_NR_pread64, "pread64" , NULL, print_pread64, NULL }, #endif #ifdef TARGET_NR_preadv { TARGET_NR_preadv, "preadv" , NULL, NULL, NULL }, @@ -1099,7 +1099,7 @@ { TARGET_NR_putpmsg, "putpmsg" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_pwrite64 -{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL }, +{ TARGET_NR_pwrite64, "pwrite64" , NULL, print_pread64, NULL }, #endif #ifdef TARGET_NR_pwritev { TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL },