From patchwork Fri May 12 11:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239136 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 E2091C77B75 for ; Fri, 12 May 2023 11:23:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrM-00062U-V2; Fri, 12 May 2023 07:22:52 -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 1pxQrL-00061o-CF for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:51 -0400 Received: from mout.kundenserver.de ([212.227.126.135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrJ-0002PM-HD for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:51 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MCXhr-1q5vJj114l-009dog; Fri, 12 May 2023 13:22:40 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Afonso Bordado , Palmer Dabbelt , Laurent Vivier , Alistair Francis , LIU Zhiwei Subject: [PULL 1/9] linux-user: Emulate /proc/cpuinfo output for riscv Date: Fri, 12 May 2023 13:22:30 +0200 Message-Id: <20230512112238.85272-2-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:I4rMKSwAL0IuP4QDTZP5cBkepjeqY/TU5Co7ldp0YnY9Tpy9vov BOQPnRui93RoJ8fscfsBSYaAiXpwUJTnbJ/5fzfNLfg7eww384x7Wqwv96qpMQJG1BnaiLT xQmxibZa9Apbs4KDKW83wiMdI8VTJm/affDmuuu95n6+LJ/t4idQWKe/aIU7FE9Cp9XnICp 6yzonAQ+VQtFv/1rAaraw== UI-OutboundReport: notjunk:1;M01:P0:36wJv0rPpp4=;W0QapBdhMtYy5xZ5FdRfRIk/AgW p/HRw419lbUgq4h2eeLEwYqqv10M9nOu6GcNbDd9rsWp9JpXjm2ZRDWLn7At/hwF1S68oXrau RifoPvmvCvcxIH3m1gdGLhv9X8MvKWz5/329/XDmBBYH3UN2+uO+7qDBJSVv3mHpETn80J2RS pAugn8yZ5X1KDNvKaKk6vTmzAY7Dv48Szvss9Qf5b4AhfIKd5/0MrkFqscxPAwHSdYHL+rYeX QI1ruKbXvhJhYufw5+A4LoBjZLL4PnjUAdfGojCtiCLg+OpQDuY1OBa84APR2IybYfwtbHZtl 06hk6KG0IEPK47QYjz7MIrN4oK31HS/1sRhFW0j09Rvn7eumIwKLcv2ruNNjCBYTjyGNgpvSk LUOIXYbFZR7/9PGMXsOSQbtXIE5fV6quUtVOYt0K/u2Tw2XRN2UQezXl+Uo+2Y2gq+/a8U5OZ HJFGHBwdChEiJIP5MsKhOW1/eR4LFbDotBqUGkBDENC1Ia2M2u7h1bIQoqayGoF3rgE5SVxT6 rV71qt3bHQQs02NRJ6inY5m+enAOX/ftXLt5Uwjdbis+oDiKhLmuEDfrzwYWjtmp0D5pEK/4R hc8lC8XD8P8ruDh8X0zUI0svDrDqtkU8YC3Qq9hbASz84fWciUkyaPVXnKQWtYCfPtrAME2oi 6w16eHG8XlNoPEg1g+SpMnBewmKLnXu27cePiMkboA== Received-SPF: none client-ip=212.227.126.135; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Afonso Bordado RISC-V does not expose all extensions via hwcaps, thus some userspace applications may want to query these via /proc/cpuinfo. Currently when querying this file the host's file is shown instead which is slightly confusing. Emulate a basic /proc/cpuinfo file with mmu info and an ISA string. Signed-off-by: Afonso Bordado Reviewed-by: Palmer Dabbelt Acked-by: Palmer Dabbelt Reviewed-by: Laurent Vivier Reviewed-by: Alistair Francis Reviewed-by: LIU Zhiwei Message-Id: <167873059442.9885.15152085316575248452-0@git.sr.ht> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 34 +++++++++++++++++++++++++++++-- tests/tcg/riscv64/Makefile.target | 1 + tests/tcg/riscv64/cpuinfo.c | 30 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/tcg/riscv64/cpuinfo.c diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 69f740ff98c8..085ce530213e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8231,7 +8231,8 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code) } #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ - defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) + defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \ + defined(TARGET_RISCV) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; @@ -8309,6 +8310,35 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd) } #endif +#if defined(TARGET_RISCV) +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int i; + int num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + RISCVCPU *cpu = env_archcpu(cpu_env); + const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env); + char *isa_string = riscv_isa_string(cpu); + const char *mmu; + + if (cfg->mmu) { + mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48"; + } else { + mmu = "none"; + } + + for (i = 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + dprintf(fd, "hart\t\t: %d\n", i); + dprintf(fd, "isa\t\t: %s\n", isa_string); + dprintf(fd, "mmu\t\t: %s\n", mmu); + dprintf(fd, "uarch\t\t: qemu\n\n"); + } + + g_free(isa_string); + return 0; +} +#endif + #if defined(TARGET_M68K) static int open_hardware(CPUArchState *cpu_env, int fd) { @@ -8333,7 +8363,7 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN { "/proc/net/route", open_net_route, is_proc }, #endif -#if defined(TARGET_SPARC) || defined(TARGET_HPPA) +#if defined(TARGET_SPARC) || defined(TARGET_HPPA) || defined(TARGET_RISCV) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif #if defined(TARGET_M68K) diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target index 9973ba3b5f8c..2da65dccaf6a 100644 --- a/tests/tcg/riscv64/Makefile.target +++ b/tests/tcg/riscv64/Makefile.target @@ -4,6 +4,7 @@ VPATH += $(SRC_PATH)/tests/tcg/riscv64 TESTS += test-div TESTS += noexec +TESTS += cpuinfo # Disable compressed instructions for test-noc TESTS += test-noc diff --git a/tests/tcg/riscv64/cpuinfo.c b/tests/tcg/riscv64/cpuinfo.c new file mode 100644 index 000000000000..296abd0a8cf9 --- /dev/null +++ b/tests/tcg/riscv64/cpuinfo.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#define BUFFER_SIZE 1024 + +int main(void) +{ + char buffer[BUFFER_SIZE]; + FILE *fp = fopen("/proc/cpuinfo", "r"); + assert(fp != NULL); + + while (fgets(buffer, BUFFER_SIZE, fp) != NULL) { + if (strstr(buffer, "processor") != NULL) { + assert(strstr(buffer, "processor\t: ") == buffer); + } else if (strstr(buffer, "hart") != NULL) { + assert(strstr(buffer, "hart\t\t: ") == buffer); + } else if (strstr(buffer, "isa") != NULL) { + assert(strcmp(buffer, "isa\t\t: rv64imafdc_zicsr_zifencei\n") == 0); + } else if (strstr(buffer, "mmu") != NULL) { + assert(strcmp(buffer, "mmu\t\t: sv48\n") == 0); + } else if (strstr(buffer, "uarch") != NULL) { + assert(strcmp(buffer, "uarch\t\t: qemu\n") == 0); + } + } + + fclose(fp); + return 0; +} From patchwork Fri May 12 11:22:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239137 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 01491C77B7F for ; Fri, 12 May 2023 11:23:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrG-0005yE-B2; Fri, 12 May 2023 07:22:46 -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 1pxQrF-0005xx-8d for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:45 -0400 Received: from mout.kundenserver.de ([212.227.126.134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrD-0002NO-M1 for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:45 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MIKs0-1q0ieq3JX2-00EJ2r; Fri, 12 May 2023 13:22:40 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , =?utf-8?q?Philippe_?= =?utf-8?q?Mathieu-Daud=C3=A9?= , Laurent Vivier Subject: [PULL 2/9] linux-user: report ENOTTY for unknown ioctls Date: Fri, 12 May 2023 13:22:31 +0200 Message-Id: <20230512112238.85272-3-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:nrDFSSlwAHBE+w+8jBtHunwlit12ol0VSyaFu9Mo51TNCoXZpz/ UjdbAdV0LKUXIa4H5LFgb2+35zL0D6dCseMpyEGaq6ktiPQjYNk7rE4lYg6mqyd7B+FV2wA kR95VvNDwKKaKD3ytl30Zs1nmJman5r0oGbEKy+7qChUnZuw6x+jTaYJ3hHjYgR/7sS2PHq b/0yOud25JpNHhm6Pm1Rg== UI-OutboundReport: notjunk:1;M01:P0:JOHsqeoBxeE=;vRo/FeZuOp/SQ2LSssMZCDFeoMz h3Z7i17YbpEiG/2v39sN83aO2Uyz+1lHjtEtXoUHcn4SA7rWI1hJLpAQfJHcdlgdeU+1LZLNP 3IX4ZymnTMFkRmAjD9+BHIKUjWAjdAZbN0w3oOQHdZ61wREN0/QI7VzISD/ihlXl/KpcWjCRr 72aqczefdyU+na12cidRw59fXntKKqokkXYQAi643t7KKsXexPWaxmtZbKMS6D+CL4JBEBdvx vcBfnz3N9D9m5IFjRa66M5BoZbAyyJrSo82o2vlZ9C7sAbBPC1ZUArLriJt2rCZSSN13aCaBS 81jsqjG/p3EQE2SH3fyU63h7pHFh2rpF9VG2kHKoQmZWiupP2zqAnP36nSN6/S8wLjx4KBoXl /832WcpKsuE7xEOhqlcHaq2o5K3OZ3jAuOctfsM+eKRIW1NIKSvIYBzl0eNJoG93WqPvDbP6X W1LRpKy6Ht4Xrow/KdFpm/OckyTi8pIwybhQU7HOggomfH+PQytpcanfLKGC0vSEQ7b8w2K1O OJeueIToGMzZVbOPxIe7cBcmGSJ5siAxuwCpeXRJKDOWGf6cBpXz+YBgWyZwQVpL/QfQff0dO 8Xesp9kaC0hbfIYVCU+o5kI0UVBE3Ixh1+hT04VV84GQTVe6nI+RBjM55ig9aiBv3ws09unKy sjvYlvjFe9iL0Z4xaxfWtKALL0gQIgMewtORfrH0MQ== Received-SPF: none client-ip=212.227.126.134; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Thomas Weißschuh The correct error number for unknown ioctls is ENOTTY. ENOSYS would mean that the ioctl() syscall itself is not implemented, which is very improbable and unexpected for userspace. ENOTTY means "Inappropriate ioctl for device". This is what the kernel returns on unknown ioctls, what qemu is trying to express and what userspace is prepared to handle. Signed-off-by: Thomas Weißschuh Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230426070659.80649-1-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 085ce530213e..954ed14df4c0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5747,7 +5747,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) if (ie->target_cmd == 0) { qemu_log_mask( LOG_UNIMP, "Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); - return -TARGET_ENOSYS; + return -TARGET_ENOTTY; } if (ie->target_cmd == cmd) break; @@ -5759,7 +5759,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) } else if (!ie->host_cmd) { /* Some architectures define BSD ioctls in their headers that are not implemented in Linux. */ - return -TARGET_ENOSYS; + return -TARGET_ENOTTY; } switch(arg_type[0]) { @@ -5817,7 +5817,7 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg) qemu_log_mask(LOG_UNIMP, "Unsupported ioctl type: cmd=0x%04lx type=%d\n", (long)cmd, arg_type[0]); - ret = -TARGET_ENOSYS; + ret = -TARGET_ENOTTY; break; } return ret; From patchwork Fri May 12 11:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239139 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 CF02BC7EE24 for ; Fri, 12 May 2023 11:23:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrG-0005yR-QE; Fri, 12 May 2023 07:22:46 -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 1pxQrF-0005xy-9J for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:45 -0400 Received: from mout.kundenserver.de ([212.227.126.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrD-0002NQ-M9 for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:45 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Ml3ym-1qcFGX1HEC-00lT0P; Fri, 12 May 2023 13:22:41 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 3/9] linux-user: Add move_mount() syscall Date: Fri, 12 May 2023 13:22:32 +0200 Message-Id: <20230512112238.85272-4-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:hvN8bIFdImY//8+dCAbzXbVCpAbVL3mEo7cifPGLTgquh5CxzDm bUtuXK0LvWkc7q9hK2lfMHyTrRyTmvpBmkXGJjDqMkkiWw36jnYIR7qkh1DMTvnvjlowk7X Cmu2bDcSxEUbpiyfsepf7qIWkXOZ7FUlygfRS9nUJ9J4b/ZLnJjKYXRh2Knxfg0uK11t8uR M2fgf9Gw1CRFdfcEBStgQ== UI-OutboundReport: notjunk:1;M01:P0:6Hmxy6q8dyU=;YHT11MqpgHSKdcQXj1eSynI4bTQ 1TmNCwdVdYxJX8SCzZUPOV/8e9imvu0Wu0NehZvcGBRiwPuzGGpvElpIZmRIJkNT2IG2lio51 mQDuqrZ0Ds0fMtO3vKBTcYlSq20vyEgweZS2RLCYSf+TxXjFEtC1IQwJv4KVvN73Odifc1nLP W4kyHKfEaBm2QDdI7C6dXrxGMutZDJHLsZ2XHU01YIMOgpXvjxT+JFgOUVcG7B8p+P7QS8GX7 BSoo62ziYloCxzfn8XnuyjgeHW84+Y9QDHjhYqQSY1D0ziyK/LcCEz50nd3U3ZILQqMok3uBH 8DFv6ewYXuNT5CSUpdha0cPaP5GiswkCQv4Be8K7pYWe4lZ04ZEHMo8/DcxOk9C1BtMURGaAO XKDsYJGzzDu8BQ0GzLgkfRnaqHBUm55MjV6+2PfhxWNnPPwWWNgHFlH6c1tE0D0DrvIWGHUzi o0zmFcWsptDmOrOOuyf91KI8b5K7DKntxrYeRV31Ivnz36u0I4pSaUz7kFVI36Cr8SbH9Aar9 J10z0N3/RdJlnk76N7100gfSfgxrWOAX74ushLro7r8RK8WjG69pnVtrFeTe2SdU/vmNINGaN pf52I9I4HQzJnxmTvf4i7h2afGam5HJhZqhMv3pAmXaUyXOY4tI4k4cZcj4LhBvWq/CojyjMk aorR3KKVXdQGgxUo5/uDUpFDAZuPAY/z+Pa2ugf63g== Received-SPF: none client-ip=212.227.126.187; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Thomas Weißschuh Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230424153429.276788-1-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 954ed14df4c0..fccc46e609c6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9169,6 +9169,33 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, unlock_user(p, arg1, 0); return ret; #endif +#ifdef TARGET_NR_move_mount + case TARGET_NR_move_mount: + { + void *p2, *p4; + + if (!arg2 || !arg4) { + return -TARGET_EFAULT; + } + + p2 = lock_user_string(arg2); + if (!p2) { + return -TARGET_EFAULT; + } + + p4 = lock_user_string(arg4); + if (!p4) { + unlock_user(p2, arg2, 0); + return -TARGET_EFAULT; + } + ret = get_errno(move_mount(arg1, p2, arg3, p4, arg5)); + + unlock_user(p2, arg2, 0); + unlock_user(p4, arg4, 0); + + return ret; + } +#endif #ifdef TARGET_NR_stime /* not on alpha */ case TARGET_NR_stime: { From patchwork Fri May 12 11:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239145 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 C4B1EC77B75 for ; Fri, 12 May 2023 11:24:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrI-0005zJ-BW; Fri, 12 May 2023 07:22:48 -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 1pxQrG-0005yF-DO for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:46 -0400 Received: from mout.kundenserver.de ([212.227.126.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrE-0002Nc-FK for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:46 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MdNwm-1qWlbl2vdw-00ZOC9; Fri, 12 May 2023 13:22:41 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 4/9] linux-user: Add open_tree() syscall Date: Fri, 12 May 2023 13:22:33 +0200 Message-Id: <20230512112238.85272-5-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:k31WPcUb3Wzr14sVJOGDuT4UgyB34ZMQXCpbobdXMa7ExMAIqwE FG9BOvRJ4Yu2DdOLW+34WMWgiWpiCKBA6Te5ZpfzmdS/wymc5YyKEA8TSeRx9auAtNKYVsq gEXVLkuZUqH+ovbVjPLHhMdiHnGfvR5JFIYuvpycE3xntf1aP+Erz6LUVL06F8w5agEzZrQ CrcD4+S94IVqzMJNdK5pA== UI-OutboundReport: notjunk:1;M01:P0:UlQd+4hqhpw=;GCYYZISm9BDxr7x5tTbpPICd9fA o5qnZPs7E6sjHB0tlZkgJ3B0MfuhhHd7SgqZVO65bW6I9BxxC8OGtq3q2Zs0ySYGolcjw4TtV htkzajzxQcIfGuFA1i9j8vAcHGB4yAKCxHMawbNjw+u6+H4ONinRxugJxPfjmJ3LvEeqIJLQn VTfMI1lCjV6qdJfQD9y0SqObDqr6dXgsi/o30WcRocM1ex7CWjokhyEc9gzJD50Jf41Vaswrk JIibr4aYGuzURZ6McbvAg0NScuTqHPKY74DXSYQ4H/SFdWX7aD7skunc/iDTQmc/ZToB5kxWB iCh/Lvp1/4DqAyJfeh1fQUOUvqq92ccF8i7/TbOlpIfptwM+d5tR3ZBS103loZUy/eW5OMQGf 3Jv7Srj82YmMKgJyBhmhvE0CGdFfWseIpfXvc4azAPmhRD3uKm5X0gak/to5fSnTKa0Dh5iPF ReGG1Bsl9g6mvFK1/Zb9tvR8f2QRXMvWrW90bP83OLCqtvafS9FpLDd2F//5as5tjSleQDsmx lX/ESqwcPdUgPPky8yAj6v0vGWHCXqD0GsWUoaN/504JQhwLgBO6IyyvSOvrxOjDXgaP9E1pV O/1LvWCn/lCxY3PlMS5vzbvi7C320bAtlKS6sshUQpNOUTStSxIaeiWWHM8V0Ygk8gQdo6hBN vhhRQ0r3A63r5JsDsrJ7GU/+TI+Mx6eb7h7nhKPr/Q== Received-SPF: none client-ip=212.227.126.131; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Thomas Weißschuh Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230424153429.276788-2-thomas@t-8ch.de> [lv: move declaration at the beginning of the block] Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fccc46e609c6..95da74ab1234 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9196,6 +9196,33 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, return ret; } #endif +#ifdef TARGET_NR_open_tree + case TARGET_NR_open_tree: + { + void *p2; + int host_flags; + + if (!arg2) { + return -TARGET_EFAULT; + } + + p2 = lock_user_string(arg2); + if (!p2) { + return -TARGET_EFAULT; + } + + host_flags = arg3 & ~TARGET_O_CLOEXEC; + if (arg3 & TARGET_O_CLOEXEC) { + host_flags |= O_CLOEXEC; + } + + ret = get_errno(open_tree(arg1, p2, host_flags)); + + unlock_user(p2, arg2, 0); + + return ret; + } +#endif #ifdef TARGET_NR_stime /* not on alpha */ case TARGET_NR_stime: { From patchwork Fri May 12 11:22:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239138 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 36230C77B75 for ; Fri, 12 May 2023 11:23:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrK-00061n-V8; Fri, 12 May 2023 07:22:50 -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 1pxQrI-0005zF-2u for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:48 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrG-0002Oa-K4 for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:47 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MTfgb-1plee70rq1-00U4e4; Fri, 12 May 2023 13:22:42 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Thomas Huth , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Laurent Vivier Subject: [PULL 5/9] linux-user/main: Use list_cpus() instead of cpu_list() Date: Fri, 12 May 2023 13:22:34 +0200 Message-Id: <20230512112238.85272-6-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:VTO7fFvcDJnQf1xL20Q6ZxS1TwiZu6aIq588bgnD6Xr2Gf3cp+4 s7ZL9Pw7bTg1LN7i3UinIIgrKCCeAlnF3ofT50vqcyB+imrXyt9DnJ+SSFngdPT9tVWcKRx xf/kDyWbWZgFLeEHQGHmI/XLs8/0vubj1zKk02lLoimnMRVIv83biZcWzxyG/zAUhCDizWL 35p/LEt7eL9TkD2Cg8vRQ== UI-OutboundReport: notjunk:1;M01:P0:K3P2rFZUWn4=;t5fxcI8pejON6nUJ/MYnDnCBZEq MMT1VL/e/7fzwokwgcKEMJCxdu7KacKTYEdO1eX71C1F7VPfuxuEmFVLoAEPKmbuvntj6Frf/ YQX9zhf/hEYd8lHAU+xucXIHpCfEvxWdXZuFMXj/Ut2jyERXPK9Jap+4b+Wpmv1RXY3ScZVsL Fi3irBDsswQovLH/n5+CYToOlR5zejV+KcGQetvGXN9rZk5bWzbkjlXv/fHgfS6NMrDb0vNl9 YfhbuiZJAwt3kqnJpsnxiRSSEhf0rK9MHdPaPG+gWT+ES0gSI/iVjYPGKWwM8UKCSlfu4l2cd iGID05HVLKVe5/vyGDnkySNXrdv6K72XWBxO5uHahmGPadhB9FxaqntaEWyj+FnfUg2+YG9DZ IjjVv322E42bBEoIeyKKDni0+Afqzg4JzYd+0Bta1xclkErWQoqTlLdXCuSdyJkZ+MIrDIJVk BZsgSqQvWRxlwoNeen5jPvyGDq2EfCW/xO70IzdlCttJYW1DiPJ1j2s/7gRBN9ffCP7YS82dN SoI4dqO9Y/+iJ4LygVessVVPtDtrucixc2tllELjRi96oMf89sOIAf+iVaQ0sLfcFJkD5pVjI XBudwj92Qpfo/+ds9oZ9PwlKgErZjo/cGw4Uq3UZVN/6SCS5d8/6QeiRZzRZbO2yK090xkXlc vui88d67wIfkyx9cezCfYUFHSlxZpsHm2AlzFX86jQ== Received-SPF: none client-ip=212.227.126.133; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Thomas Huth This way we can get rid of the if'deffery and the XXX comment here (it's repeated in the list_cpus() function anyway). Signed-off-by: Thomas Huth Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230424122126.236586-1-thuth@redhat.com> Signed-off-by: Laurent Vivier --- linux-user/main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index fe03293516a5..aece4d9e9119 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -359,10 +359,7 @@ static void handle_arg_cpu(const char *arg) { cpu_model = strdup(arg); if (cpu_model == NULL || is_help_option(cpu_model)) { - /* XXX: implement xxx_cpu_list for targets that still miss it */ -#if defined(cpu_list) - cpu_list(); -#endif + list_cpus(); exit(EXIT_FAILURE); } } From patchwork Fri May 12 11:22:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239144 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 8ADD6C7EE25 for ; Fri, 12 May 2023 11:24:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrI-0005zK-CT; Fri, 12 May 2023 07:22:48 -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 1pxQrG-0005yK-HJ for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:46 -0400 Received: from mout.kundenserver.de ([212.227.126.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrF-0002Nx-0X for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:46 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MiuGK-1qRHy22WXc-00esN3; Fri, 12 May 2023 13:22:42 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 6/9] linux-user: Add new flag VERIFY_NONE Date: Fri, 12 May 2023 13:22:35 +0200 Message-Id: <20230512112238.85272-7-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:+xfPM3iDdaLbeBVT++aWi23UYN92M5nHH0NUXbj6UzguDtFcrL2 FTPYde8iFLEbh3Qx8c2gvBHkia/4MP+Vfao1fbAVQN2YhsjwoIdeQrk/DmcfbEGnmwC5kGe M7rMtDVpJPCN+JIETUFe1wbUs+Q/mm2HlAVYK68X/+olmAqqjSxZMwyk2YH6/QWZR3Ve8w3 1YoEL2cjksXlkFPtGsgZQ== UI-OutboundReport: notjunk:1;M01:P0:qfM9XZ/vedY=;Q62LfUdFee6vl7PbCKaSCYpwiGw 6/U5r18ddctOWSsohng9gowTudb9a731Dw9RpVjrddvaexYcEI15MgfVKjK1ZTwSWjiPBJqMN 8ew89SvKb52Ufg4EQN06NNmnz8+DIcLQif55cMjsXtIrd1esisTgg0Jby4D1vXyfzgn8h0bD9 3bCToWfU+RYOilrwj0BcrZTIL4LpeUlz4MNanuIYDIJ58xbaAD1/LkmAiEpCUtCQqTbIC8jpJ szmDu74IePoM4hWUGT+rqTTiosQUbx0JIuDawAuPZBa+6WMhEWRDZH504oXU7H6ZUe6JT7gyC xhPCWcD7HQin98Ns9IzgOadQ73MN8NEE81eOoXvyXch1z8DvfGlkcs0mq0GLya2x7MBKVB/OD fQhK6HondrVtcMLf2ZlRLrHWGwIvR1dmeTAdW3nw5dU9l2GkhLJbE41z/MS4k2XUuvb5LKNhD ezLNu2Ljq0suEvNDlzqThN6Br0qM3Yx/Dq+Z9iUIsNoA4xn9zfBk3iK7+9B+yHRjTN3tuSOZl siIUG8Xf954GdwqER/jS2z1PerLfxB42ES9kUYsH9GoG9G4ebfU4DqJ34xzyb3BAtL1pnJZG6 3Xap6FCm6+d7bzqQmxuE/rY4JXvHgRNYu+F7CNoLBqRcx+HGR6z+xDrS/+sqncr1qzWMU/CHR 9b0SipoxSCapyV69mYAtp66roFClyKDiix2YamooKw== Received-SPF: none client-ip=212.227.126.130; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Thomas Weißschuh This can be used to validate that an address range is mapped but without being readable or writable. It will be used by an updated implementation of mincore(). Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230422100314.1650-2-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/qemu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index e2e93fbd1d5d..92f9f5af41c7 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -168,6 +168,7 @@ abi_long do_brk(abi_ulong new_brk); /* user access */ +#define VERIFY_NONE 0 #define VERIFY_READ PAGE_READ #define VERIFY_WRITE (PAGE_READ | PAGE_WRITE) From patchwork Fri May 12 11:22:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239146 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 B6086C77B75 for ; Fri, 12 May 2023 11:24:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrI-0005zI-Aw; Fri, 12 May 2023 07:22:48 -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 1pxQrG-0005yQ-N0 for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:46 -0400 Received: from mout.kundenserver.de ([212.227.126.187]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrF-0002O4-56 for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:46 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MBBCI-1q2MY8498w-00CgDf; Fri, 12 May 2023 13:22:43 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Laurent Vivier Subject: [PULL 7/9] linux-user: Don't require PROT_READ for mincore Date: Fri, 12 May 2023 13:22:36 +0200 Message-Id: <20230512112238.85272-8-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:kF8Qqf3UVZfsQUstMkyw6i+ijgyOZHjAHvjbJkqWpttWGDScJs+ rZV0jhRFUszyUtsHFyIDGX9LiviS/xv6N2RiZqZw0czu+aTuUZs/ondsblbOIymjyy9YYYM OZCBZX5+XdaDi6dat4GwqZKtqCw6uD0P8tG5RERXLEsXpM+IKkxZBVNONbiMetj/vNFdP8d OTCHmd6poKxLj/O7eHlBw== UI-OutboundReport: notjunk:1;M01:P0:CXB9Qp3eomA=;wPbnJXydmxfOSSKz1brmZKVD/b1 2WN9PjRDp6P5GDxGY/V9uJ5i+qelbCuH3bMKOgzuL8Iga8c7HfouuZy6AnWE4291/sthjXOIJ JwAPJLJz2kHyvnOCw/wJM1LU9CNjj/2vgLAPXfMXvXIUNYJQZFRppTSw5aFm3xB1mbJ+HkI7F uSKr7DVgxJ+JISG+hQzfkKiJqhhRBWijpkrWyUJKm9GHJ2i1vfKzf8wAySDvTX/yoVoFKn8Au 9ymvxwnJb5QGeiNI8D3jzOkKKqe0dFlCSxrFKAUITbgSuUXfPpDprAMqpkXIHHxU07o50oCyN HNcuoVNU5QlXwTgz0LwnCO0rn5YgaBr6pppC9mHW128GEsMyr6RvTk2hbNw9rM9x3v5JIXTfb X3mQ8pS8pWsGR1he70RtEC049xxb24q7FR7YmyeZrVOXxNfwkPMketOe+hz7nwIVgviTGIQe6 xqtF8EEVDtZkQRt43sE+JJ34FDAo9ABucNjwvY9OmrasrcEf9pfdszxgq/4iP5fK3Mu39vAch sOEArUn+4UYPJes/uMiP/5wUmgwaOUuDNu592pTani5WNo0xGbDGJZyTRwymrvGu8Cx1+XrIY 56oIHw+hTJkfLa+RlnpNNY473mvWXHmUk+A2WHmUpmOT9yfT9gXOuj6GKdzP7E2Lfl0az50/r W0BvnZL27nnLIY9kBxnuOcPQosAb5d+lvcKCA7ssiA== Received-SPF: none client-ip=212.227.126.187; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Thomas Weißschuh The kernel does not require PROT_READ for addresses passed to mincore. For example the fincore(1) tool from util-linux uses PROT_NONE and currently does not work under qemu-user. Example (with fincore(1) from util-linux 2.38): $ fincore /proc/self/exe RES PAGES SIZE FILE 24K 6 22.1K /proc/self/exe $ qemu-x86_64 /usr/bin/fincore /proc/self/exe fincore: failed to do mincore: /proc/self/exe: Cannot allocate memory With this patch: $ ./build/qemu-x86_64 /usr/bin/fincore /proc/self/exe RES PAGES SIZE FILE 24K 6 22.1K /proc/self/exe Signed-off-by: Thomas Weißschuh Reviewed-by: Laurent Vivier Message-Id: <20230422100314.1650-3-thomas@t-8ch.de> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95da74ab1234..7170332041ca 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11981,7 +11981,7 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #ifdef TARGET_NR_mincore case TARGET_NR_mincore: { - void *a = lock_user(VERIFY_READ, arg1, arg2, 0); + void *a = lock_user(VERIFY_NONE, arg1, arg2, 0); if (!a) { return -TARGET_ENOMEM; } From patchwork Fri May 12 11:22:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239140 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 B69DBC7EE25 for ; Fri, 12 May 2023 11:24:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrN-00062Y-3b; Fri, 12 May 2023 07:22:53 -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 1pxQrL-000624-RZ for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:51 -0400 Received: from mout.kundenserver.de ([212.227.126.135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrJ-0002PL-HO for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:51 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MC0HF-1q3BUs21kL-00CPEi; Fri, 12 May 2023 13:22:43 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Daniil Kovalev , Jiaxun Yang , Laurent Vivier Subject: [PULL 8/9] linux-user: Fix mips fp64 executables loading Date: Fri, 12 May 2023 13:22:37 +0200 Message-Id: <20230512112238.85272-9-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:Abi2VJYAiPvO3Bo9u7tHPh5g20oYvFmbE5FUTROq+OcAgFhHJkZ VyUG98nMXyuN58stbpVJ5ZmEm1CajB/Ob/BcehDeuPH4ypBNHODVRbunpU6gwF+ZA/oMsQ7 s+Dnpwlz4HH+0PFFvg73eBP5fJGoqRBHiQ8k3R5dkIEkZmQG20xIuxcDPwk3VFYRN3sprgm 8lNiE8/bAxI2ZplE2IIxQ== UI-OutboundReport: notjunk:1;M01:P0:/jssH677x9E=;MYVKNXsCnQfF9ebryN5Sld2Va9A YQN3OKLRtSLPZ4dtaSrTo2C1kwFV5DZ2875FhFacRPxYjoYOu3f+Hl7ypy2FqEcnERGcePXie Fq2frxKFjLeGzlMpwuLWDO7Ql+KNpF8186LPDoDZBCtomQg+6g2NJcJ/8P7JLJfU+yqKQmCuD KzmMPA/VlOkg0KvquvGMrzK2GFvDkQifH7v5bh0inxlhesdmxo+1M6dDhQaZFov5M4geyYTmL N3rFxcKlUyhQLj6zZBN+BbzhTOFPxiCD2gGAspUFaUJUHqDFnTnviuhUPNgthflIs26m2tXCA ZXuOKtJNUlqP75I7P6ZL7hoinvaJthLUux4HZTKm+f1uyjK1G/eI4XDFjad9/s6PB14RnqchF L9ZJOGebDxixuvNJBH2jKxUS7bmbSW5KZAhgs7dFC3rZxzL14LyjH+MS0g7mCqshLOI6xxRmn wjf+H6BFDsihqCAWwaWTqFKmtMEjadcN2GrbDv2cZDLf9ObsWMBn1becuEa+wLsOPJQy9MvM4 hWRYxcF3sBnIEr2oPAgPrjxKCtvKAgPVBVKEAmisux5dcrJ8jz4WENDaAhNRmCf9SO8dAn2+O mnk1hMPplC6FphS7fB+mKP2vT81qEeMsZbB5eFndiNGkIwjSXiLPyZ2wqUE/7T5S4v/oDQ9Z5 wp5z6N0hKdkyHU4wzoHxtZDJMe7Om67pD1vJpf1M1Q== Received-SPF: none client-ip=212.227.126.135; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Daniil Kovalev If a program requires fr1, we should set the FR bit of CP0 control status register and add F64 hardware flag. The corresponding `else if` branch statement is copied from the linux kernel sources (see `arch_check_elf` function in linux/arch/mips/kernel/elf.c). Signed-off-by: Daniil Kovalev Reviewed-by: Jiaxun Yang Message-Id: <20230404052153.16617-1-dkovalev@compiler-toolchain-for.me> Signed-off-by: Laurent Vivier --- linux-user/mips/cpu_loop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c index d5c1c7941d34..8735e58bada0 100644 --- a/linux-user/mips/cpu_loop.c +++ b/linux-user/mips/cpu_loop.c @@ -290,7 +290,10 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) env->CP0_Status |= (1 << CP0St_FR); env->hflags |= MIPS_HFLAG_F64; } - } else if (!prog_req.fre && !prog_req.frdefault && + } else if (prog_req.fr1) { + env->CP0_Status |= (1 << CP0St_FR); + env->hflags |= MIPS_HFLAG_F64; + } else if (!prog_req.fre && !prog_req.frdefault && !prog_req.fr1 && !prog_req.single && !prog_req.soft) { fprintf(stderr, "qemu: Can't find a matching FPU mode\n"); exit(1); From patchwork Fri May 12 11:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 13239143 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 C2D01C77B7F for ; Fri, 12 May 2023 11:24:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pxQrL-00061q-Hq; Fri, 12 May 2023 07:22: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 1pxQrJ-0005zt-5M for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:49 -0400 Received: from mout.kundenserver.de ([212.227.126.133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pxQrH-0002Om-52 for qemu-devel@nongnu.org; Fri, 12 May 2023 07:22:48 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MlsWZ-1qfG4N2waJ-00iyZG; Fri, 12 May 2023 13:22:44 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Michael Tokarev , Laurent Vivier Subject: [PULL 9/9] linux-user: fix getgroups/setgroups allocations Date: Fri, 12 May 2023 13:22:38 +0200 Message-Id: <20230512112238.85272-10-laurent@vivier.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230512112238.85272-1-laurent@vivier.eu> References: <20230512112238.85272-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:iRJlWj3Gcwv32sYb+8bRrL7E6Z7BK0F/lJCUdcrclFucul2udKF YA2Goa9O3gbUAIYaLy3Vm9NvoNUhIlHO+PgGUGsVCWc3WbMx/jgApJCs6WTqT+HzEbkUj1e j9BOBm8GYZjhy5vuMwzg+FPLCP89BW0Aj0UndEKai8X/ncqdP4aLi1S1sr4CklBgbuJZQjN aOPlBEK2PSU16bQDLamTA== UI-OutboundReport: notjunk:1;M01:P0:pJQgYKHQdis=;nwUO9pwLQzc8LIN4INzbxIODITf zVqTn62hnKRapSA55MASZ4s0b6h8Yx5oV8nnCsc9yQre+8rYVLUk0wpJpq0ZeG2m22cSk9ebJ A7G8mAsESZhArzJ3aV2LHa9EhpII7cPil9MsTqb8EbVfIW5X02c1uAgKa+Ybma1DVdh1y9LcF ZXismGvZvq+GOJihOvRU8rwPdYJRButOT3wMi2luLV9JqN8yLhnlpBeZabnDKpeXJ4Q4av9Au 1oTcstdkX0/cHy0sCydAyCg8HbRzkwf1vzaR9O/A51kaYV/wdR1dDxFvtHB1zREUUwdkKPbhz n8/VGG8tpp1JBzyG1vqNTIN4V3N1c8FmOJTZ7BYyb3Q3zPO7xm+k8vlCJgPxCL1ygQNwJGoJH qJyIZedfcMRBZy3BU90XuVMJ8eVUtdkDNJS9ezeTWqjuKiXTJWWBd6b4Bk45b7B8kx7UDTD33 FcqDQjKl6KtzMohTW3Q6S7rix0ujR1d8HnK44X0RDPI+Hp1/KnniOdh1tu0PQ9BCJGH04o9yp j1TswZqrJY7CDbWh+4KzhGhqjkYyNcy6y9DNPifEqiLXZfdJFkydI9ddWy7cY7edMOtx2jm/u uF5xLSgIifNTiG6EdBvEBuTpIbde17epVBV6wa8u2fgSlEzBZozdwfuak4rlh6MqHS7Mz5Kvz jgaMJXfq41DPfJ7YODtyR4VYvUodmLgDuzfZgScDqA== Received-SPF: none client-ip=212.227.126.133; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 From: Michael Tokarev linux-user getgroups(), setgroups(), getgroups32() and setgroups32() used alloca() to allocate grouplist arrays, with unchecked gidsetsize coming from the "guest". With NGROUPS_MAX being 65536 (linux, and it is common for an application to allocate NGROUPS_MAX for getgroups()), this means a typical allocation is half the megabyte on the stack. Which just overflows stack, which leads to immediate SIGSEGV in actual system getgroups() implementation. An example of such issue is aptitude, eg https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=811087#72 Cap gidsetsize to NGROUPS_MAX (return EINVAL if it is larger than that), and use heap allocation for grouplist instead of alloca(). While at it, fix coding style and make all 4 implementations identical. Try to not impose random limits - for example, allow gidsetsize to be negative for getgroups() - just do not allocate negative-sized grouplist in this case but still do actual getgroups() call. But do not allow negative gidsetsize for setgroups() since its argument is unsigned. Capping by NGROUPS_MAX seems a bit arbitrary, - we can do more, it is not an error if set size will be NGROUPS_MAX+1. But we should not allow integer overflow for the array being allocated. Maybe it is enough to just call g_try_new() and return ENOMEM if it fails. Maybe there's also no need to convert setgroups() since this one is usually smaller and known beforehand (KERN_NGROUPS_MAX is actually 63, - this is apparently a kernel-imposed limit for runtime group set). The patch fixes aptitude segfault mentioned above. Signed-off-by: Michael Tokarev Message-Id: <20230409105327.1273372-1-mjt@msgid.tls.msk.ru> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 99 ++++++++++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7170332041ca..f49fbd0529d9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11559,39 +11559,58 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; target_id *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = NULL; int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (gidsetsize > NGROUPS_MAX) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + } ret = get_errno(getgroups(gidsetsize, grouplist)); - if (gidsetsize == 0) - return ret; - if (!is_error(ret)) { - target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * sizeof(target_id), 0); - if (!target_grouplist) + if (!is_error(ret) && gidsetsize > 0) { + target_grouplist = lock_user(VERIFY_WRITE, arg2, + gidsetsize * sizeof(target_id), 0); + if (!target_grouplist) { return -TARGET_EFAULT; - for(i = 0;i < ret; i++) + } + for (i = 0; i < ret; i++) { target_grouplist[i] = tswapid(high2lowgid(grouplist[i])); - unlock_user(target_grouplist, arg2, gidsetsize * sizeof(target_id)); + } + unlock_user(target_grouplist, arg2, + gidsetsize * sizeof(target_id)); } + return ret; } - return ret; case TARGET_NR_setgroups: { int gidsetsize = arg1; target_id *target_grouplist; - gid_t *grouplist = NULL; + g_autofree gid_t *grouplist = NULL; int i; - if (gidsetsize) { - grouplist = alloca(gidsetsize * sizeof(gid_t)); - target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * sizeof(target_id), 1); + + if (gidsetsize > NGROUPS_MAX || gidsetsize < 0) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + target_grouplist = lock_user(VERIFY_READ, arg2, + gidsetsize * sizeof(target_id), 1); if (!target_grouplist) { return -TARGET_EFAULT; } for (i = 0; i < gidsetsize; i++) { grouplist[i] = low2highgid(tswapid(target_grouplist[i])); } - unlock_user(target_grouplist, arg2, 0); + unlock_user(target_grouplist, arg2, + gidsetsize * sizeof(target_id)); } return get_errno(setgroups(gidsetsize, grouplist)); } @@ -11876,41 +11895,59 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, { int gidsetsize = arg1; uint32_t *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = NULL; int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); + if (gidsetsize > NGROUPS_MAX) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + } ret = get_errno(getgroups(gidsetsize, grouplist)); - if (gidsetsize == 0) - return ret; - if (!is_error(ret)) { - target_grouplist = lock_user(VERIFY_WRITE, arg2, gidsetsize * 4, 0); + if (!is_error(ret) && gidsetsize > 0) { + target_grouplist = lock_user(VERIFY_WRITE, arg2, + gidsetsize * 4, 0); if (!target_grouplist) { return -TARGET_EFAULT; } - for(i = 0;i < ret; i++) + for (i = 0; i < ret; i++) { target_grouplist[i] = tswap32(grouplist[i]); + } unlock_user(target_grouplist, arg2, gidsetsize * 4); } + return ret; } - return ret; #endif #ifdef TARGET_NR_setgroups32 case TARGET_NR_setgroups32: { int gidsetsize = arg1; uint32_t *target_grouplist; - gid_t *grouplist; + g_autofree gid_t *grouplist = NULL; int i; - grouplist = alloca(gidsetsize * sizeof(gid_t)); - target_grouplist = lock_user(VERIFY_READ, arg2, gidsetsize * 4, 1); - if (!target_grouplist) { - return -TARGET_EFAULT; + if (gidsetsize > NGROUPS_MAX || gidsetsize < 0) { + return -TARGET_EINVAL; + } + if (gidsetsize > 0) { + grouplist = g_try_new(gid_t, gidsetsize); + if (!grouplist) { + return -TARGET_ENOMEM; + } + target_grouplist = lock_user(VERIFY_READ, arg2, + gidsetsize * 4, 1); + if (!target_grouplist) { + return -TARGET_EFAULT; + } + for (i = 0; i < gidsetsize; i++) { + grouplist[i] = tswap32(target_grouplist[i]); + } + unlock_user(target_grouplist, arg2, 0); } - for(i = 0;i < gidsetsize; i++) - grouplist[i] = tswap32(target_grouplist[i]); - unlock_user(target_grouplist, arg2, 0); return get_errno(setgroups(gidsetsize, grouplist)); } #endif