From patchwork Tue Jul 25 13:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 706142 Delivered-To: patch@linaro.org Received: by 2002:a5d:464f:0:b0:317:2194:b2bc with SMTP id j15csp195580wrs; Tue, 25 Jul 2023 06:52:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHYWQZFc6lTkavG/cg8QcDT9Sd/ct1l3Y+orUIGFdhrXD+jYIcUFSCjuczUI4EXHQxrzRWt X-Received: by 2002:ac8:59d3:0:b0:405:3a8b:d753 with SMTP id f19-20020ac859d3000000b004053a8bd753mr3406645qtf.47.1690293139632; Tue, 25 Jul 2023 06:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690293139; cv=none; d=google.com; s=arc-20160816; b=R7CTQv3Z8mtXHIGcthx9Uv5/xV3zp5tYz9YXRAI3mCpc80XKQNt32JM47q4T9UKPD9 Ow033KCNEfra38x5lrkKBBdDEzziDj8r+RP+F59KkCO13jS74wQxi7lMuqGDeEn2Zzit 826uWP9zEhFT55KDYVo7Rw3yCxhGcjGrIaDM7UFWPHTja9RvHC+Lzjjf+7GnURBny8pn BUjG3EExlPWVf8e+Qa6xCzIM2F7Yd4U2GyOa45TPV0tfYhIb1B/3A/Jt+ds4VYWFmke0 63xglT0DDSgpULUrkJa2jQWjOqpoI//n7znkEN61gfftx68fZ6zt9EUanIuFmbFFvkFf 5kNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=JAagleDxxN9hC3CBJXDpuUZu61qYtSfnart72cbu6bg=; fh=fE54LLX1ksKgAWqXP2sVbot0faJG0Jr+3uWME2EBXXU=; b=pG8NryD1KtFBXHHfwdUz6D6O1q/MhfXjZo248mrqF6QHCoUHUdTBxrXXURGn6E6OCM PRhK8O5lU2BT/AKW0LGkRN9f+AVlSZtDorzhKW44N6IcC88MuXA7xqyxr9kQBm9KCVWv exc0+iQN2My1Zm8GxyNYgg+mIzki65Jlu5ZH0FckWfionzFzF3+c7cKpIXPh5mSf5Cco 8N91TZu8k0sIp4hdDaDV59QBXWOqCKoWUCnJGDSZw+/44MoWQaX5aXr+1t46hHyUt/jn XQXOMsQ708dxukQGpsWzTQ4E0AFddZtTb+dlyCQu8ynrQiAi7N6pLMVOQrwGkd9cwlky AF6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d7-20020a05622a15c700b00403bfdaa607si6625272qty.777.2023.07.25.06.52.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jul 2023 06:52:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOINb-0007KV-7B; Tue, 25 Jul 2023 09:47:11 -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 1qOIMo-0005l7-6f; Tue, 25 Jul 2023 09:46:32 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOIMm-0001U7-AI; Tue, 25 Jul 2023 09:46:21 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D72EF160F5; Tue, 25 Jul 2023 16:45:34 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 77C7B194B8; Tue, 25 Jul 2023 16:45:32 +0300 (MSK) Received: (nullmailer pid 3370822 invoked by uid 1000); Tue, 25 Jul 2023 13:45:29 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Pierrick Bouvier , Richard Henderson , Michael Tokarev Subject: [Stable-8.0.4 13/31] linux-user/syscall: Implement execve without execveat Date: Tue, 25 Jul 2023 16:44:58 +0300 Message-Id: <20230725134517.3370706-13-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier Support for execveat syscall was implemented in 55bbe4 and is available since QEMU 8.0.0. It relies on host execveat, which is widely available on most of Linux kernels today. However, this change breaks qemu-user self emulation, if "host" qemu version is less than 8.0.0. Indeed, it does not implement yet execveat. This strange use case happens with most of distribution today having binfmt support. With a concrete failing example: $ qemu-x86_64-7.2 qemu-x86_64-8.0 /bin/bash -c /bin/ls /bin/bash: line 1: /bin/ls: Function not implemented -> not implemented means execve returned ENOSYS qemu-user-static 7.2 and 8.0 can be conveniently grabbed from debian packages qemu-user-static* [1]. One usage of this is running wine-arm64 from linux-x64 (details [2]). This is by updating qemu embedded in docker image that we ran into this issue. The solution to update host qemu is not always possible. Either it's complicated or ask you to recompile it, or simply is not accessible (GitLab CI, GitHub Actions). Thus, it could be worth to implement execve without relying on execveat, which is the goal of this patch. This patch was tested with example presented in this commit message. [1] http://ftp.us.debian.org/debian/pool/main/q/qemu/ [1] https://www.linaro.org/blog/emulate-windows-on-arm/ Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson Reviewed-by: Michael Tokarev Message-Id: <20230705121023.973284-1-pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson (cherry picked from commit 7a8d9f3a0e882df50681e40f09c29cfb4966ea2d) Signed-off-by: Michael Tokarev diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0901884495..150d70633e 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -659,6 +659,7 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ #endif safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ int, options, struct rusage *, rusage) +safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp) safe_syscall5(int, execveat, int, dirfd, const char *, filename, char **, argv, char **, envp, int, flags) #if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \ @@ -8398,9 +8399,9 @@ static int do_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int return safe_openat(dirfd, path(pathname), flags, mode); } -static int do_execveat(CPUArchState *cpu_env, int dirfd, - abi_long pathname, abi_long guest_argp, - abi_long guest_envp, int flags) +static int do_execv(CPUArchState *cpu_env, int dirfd, + abi_long pathname, abi_long guest_argp, + abi_long guest_envp, int flags, bool is_execveat) { int ret; char **argp, **envp; @@ -8479,11 +8480,14 @@ static int do_execveat(CPUArchState *cpu_env, int dirfd, goto execve_efault; } + const char *exe = p; if (is_proc_myself(p, "exe")) { - ret = get_errno(safe_execveat(dirfd, exec_path, argp, envp, flags)); - } else { - ret = get_errno(safe_execveat(dirfd, p, argp, envp, flags)); + exe = exec_path; } + ret = is_execveat + ? safe_execveat(dirfd, exe, argp, envp, flags) + : safe_execve(exe, argp, envp); + ret = get_errno(ret); unlock_user(p, pathname, 0); @@ -9022,9 +9026,9 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, return ret; #endif case TARGET_NR_execveat: - return do_execveat(cpu_env, arg1, arg2, arg3, arg4, arg5); + return do_execv(cpu_env, arg1, arg2, arg3, arg4, arg5, true); case TARGET_NR_execve: - return do_execveat(cpu_env, AT_FDCWD, arg1, arg2, arg3, 0); + return do_execv(cpu_env, AT_FDCWD, arg1, arg2, arg3, 0, false); case TARGET_NR_chdir: if (!(p = lock_user_string(arg1))) return -TARGET_EFAULT; From patchwork Tue Jul 25 13:44:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 706141 Delivered-To: patch@linaro.org Received: by 2002:a5d:464f:0:b0:317:2194:b2bc with SMTP id j15csp194896wrs; Tue, 25 Jul 2023 06:50:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlESkFlXANtQuapb4XohxP5diyL4sPRDME11cbT8XCN1ogX378HkrVCq1dja9h+fzTyWBVJS X-Received: by 2002:a05:622a:182:b0:403:a98a:dcd1 with SMTP id s2-20020a05622a018200b00403a98adcd1mr3711155qtw.29.1690293046500; Tue, 25 Jul 2023 06:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690293046; cv=none; d=google.com; s=arc-20160816; b=gRDsNMiUQK5f01lX1KsTCP1OhWswoe7LkaL9pLSjRN1CnoyrbslRgj1RYuQ8RGioo0 aBN5u0Gqy/yK2Bcoakm46/TaRQHV+v5Cs63DrhV8QUADb1Qq4yMElW7LQmq9ZvVYV2Sx ovuQZz0AlbVptv1E0Vje06SoMI6UVbtPQ59eJX+5O3R+BnPMKRwn3PpdBjaKKwps/a0y vos5+fVsmNVM3a2iJboq523+q/tNcltOZk7VUIFEgXFhDS/d8ZgusazSbVmS6WEfRuFU 5zRz+z7ljCtFHElriNWQWwvQJ3j029XcI0grDNb+IhKzRYArNJEj9tpn7PcczpJpEv6j 43Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=6IGXKFxm0uipGsF4C5bCoIlSxWEitK3Xy43vAyCuRpA=; fh=5JdQHG30MWzFvV/nMAZA9GY4o6OT/LgtWD8WVMxftDg=; b=s+J6/LCx9lH7LMHX+s0mkPTmBvPEr6KCoJi6Jo5Xrmzykp58R+ouVyZH6EqGFXswFZ ZsFuHo8LfyutV4+tcqClFXwY+e8iHuuj2Jsd4dhf5yUspC1AYxkITCfWgGMCi1uYJjcu mcsp+8fZXMepjjt0ycE2jFX6T7ud2NgSnNqkQU+V516d+uyTkAgFBr3wa8CbNAZnNlp1 eHh6yhfeoWbRpkGN52RYjvN0zemXDIom+Vea6uMLtzmxH6GKMnsc3PDI/L59TFE9zhI1 lW16dmk3h3VtZjnLZFIU6yBmSdIoL1wo+vontFIMrM2nmN69VjuRFBuBf28DEqqYrLX4 JllA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y9-20020a05622a004900b00403c5ae5a58si6529411qtw.804.2023.07.25.06.50.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jul 2023 06:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOINY-0007HQ-LM; Tue, 25 Jul 2023 09:47:08 -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 1qOIMo-0005ms-Ue; Tue, 25 Jul 2023 09:46:32 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOIMn-0001UV-DI; Tue, 25 Jul 2023 09:46:22 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 0C542160F6; Tue, 25 Jul 2023 16:45:35 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id B8885194B9; Tue, 25 Jul 2023 16:45:32 +0300 (MSK) Received: (nullmailer pid 3370825 invoked by uid 1000); Tue, 25 Jul 2023 13:45:29 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , Michael Tokarev Subject: [Stable-8.0.4 14/31] tcg: Fix info_in_idx increment in layout_arg_by_ref Date: Tue, 25 Jul 2023 16:44:59 +0300 Message-Id: <20230725134517.3370706-14-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Off by one error, failing to take into account that layout_arg_1 already incremented info_in_idx for the first piece. We only need care for the n-1 TCG_CALL_ARG_BY_REF_N pieces here. Cc: qemu-stable@nongnu.org Fixes: 313bdea84d2 ("tcg: Add TCG_CALL_{RET,ARG}_BY_REF") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1751 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Tested-by: Peter Maydell (cherry picked from commit e18ed26ce785f74a17e6f3a095647e08ba6fc669) Signed-off-by: Michael Tokarev diff --git a/tcg/tcg.c b/tcg/tcg.c index bb52bc060b..f3bf471274 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -732,7 +732,7 @@ static void layout_arg_by_ref(TCGCumulativeArgs *cum, TCGHelperInfo *info) .ref_slot = cum->ref_slot + i, }; } - cum->info_in_idx += n; + cum->info_in_idx += n - 1; /* i=0 accounted for in layout_arg_1 */ cum->ref_slot += n; } From patchwork Tue Jul 25 13:45:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 706140 Delivered-To: patch@linaro.org Received: by 2002:a5d:464f:0:b0:317:2194:b2bc with SMTP id j15csp194482wrs; Tue, 25 Jul 2023 06:49:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlHR/cN3xYnH12B2Xcdzg+z2bIGvDXcT/ClWPepMBxAeVcLEr8vUf7j4+O3tJlpD3w1+R7Vb X-Received: by 2002:a05:6214:e48:b0:63d:3b2:482f with SMTP id o8-20020a0562140e4800b0063d03b2482fmr2387044qvc.5.1690292996331; Tue, 25 Jul 2023 06:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690292996; cv=none; d=google.com; s=arc-20160816; b=atqL2WGcfHDISciJLmM6+132Mwr/7yygoGw0fvlkLXGvYi/xrtEuaImKE8LrSyEpt8 YGZERzCtO96rttCshE9p8Mzn8osGTXboiUcimdIN1z6VQf/DucKGpHzD8nFcSWDRczwS 7Mpltn5pjRL6bV9TN78wVmGVRTn/B6uCxqLdnRrfeYBJWain0jkooji5niPupnoi+nMo GzXihLxmRPGNkkINYW07ok74ww9Iv2BDhgK5O48cLPhCmqPNEg2iYtKtgky/i/WgJ4TB 9VeALghjy0HUjLd+MYxAMgMIK50TKfT6HNUGVtI4kUfxfLxHv8cnbUpluM3zJwlGkoCw 1rrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=+bPnbTyYrBxPQsqdbKAUP7s8dak6Cz+8p1IJIQfU9nM=; fh=UV4TdQm0rfmebv6eoDMuLGgChsbF/Gadsx8n5DdbuK4=; b=Mtes+5q6Ax69jdbV5wdIkCG5KcU6PXwU66gNk9GYPk/BQygXIfRDNK48PvCrh0cnpJ ZXU9fDgNtiajQFBxiu8E+Z05TQo1OMkqYA7ugnXCpX/j337WwiFiVo/H091lubibezMD moybzfxGzr/YQhlfyrNyzB291WAah3Bp5PoPopqYLg+L7zS8adNnfMZwnOmNHuJ+SK0b Y+fuH42GOo5sp0AqiCKB1MTIJ6QrylHkJwjcYq1rfu8EEs64nlJMB+OqoaP25l0ImO2H C94PGogatLg4vqXniwK9ueoz1chURI8l60P1qNRJobi/qWaXpvpJvtCQKVutdJPZ2UcT XlPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j20-20020a0ce014000000b0062ded861543si6275633qvk.616.2023.07.25.06.49.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Jul 2023 06:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOINc-0007Rs-DX; Tue, 25 Jul 2023 09:47:12 -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 1qOIMr-0005mz-Tr; Tue, 25 Jul 2023 09:46:34 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOIMp-0001Wx-Oi; Tue, 25 Jul 2023 09:46:25 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 3E482160F7; Tue, 25 Jul 2023 16:45:35 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id E19A0194BA; Tue, 25 Jul 2023 16:45:32 +0300 (MSK) Received: (nullmailer pid 3370828 invoked by uid 1000); Tue, 25 Jul 2023 13:45:29 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Christophe Lyon , Richard Henderson , Anton Johansson , Michael Tokarev Subject: [Stable-8.0.4 15/31] linux-user/arm: Do not allocate a commpage at all for M-profile CPUs Date: Tue, 25 Jul 2023 16:45:00 +0300 Message-Id: <20230725134517.3370706-15-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Since commit fbd3c4cff6 ("linux-user/arm: Mark the commpage executable") executing bare-metal (linked with rdimon.specs) cortex-M code fails as: $ qemu-arm -cpu cortex-m3 ~/hello.exe.m3 qemu-arm: ../../accel/tcg/user-exec.c:492: page_set_flags: Assertion `last <= GUEST_ADDR_MAX' failed. Aborted (core dumped) Commit 4f5c67f8df ("linux-user/arm: Take more care allocating commpage") already took care of not allocating a commpage for M-profile CPUs, however it had to be reverted as commit 6cda41daa2. Re-introduce the M-profile fix from commit 4f5c67f8df. Fixes: fbd3c4cff6 ("linux-user/arm: Mark the commpage executable") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1755 Reported-by: Christophe Lyon Suggested-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Anton Johansson Reviewed-by: Richard Henderson Message-Id: <20230711153408.68389-1-philmd@linaro.org> Signed-off-by: Richard Henderson (cherry picked from commit d713cf4d6c71076513a10528303b3e337b4d5998) Signed-off-by: Michael Tokarev diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f1370a7a8b..88ef26dc03 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -423,10 +423,23 @@ enum { static bool init_guest_commpage(void) { - abi_ptr commpage = HI_COMMPAGE & -qemu_host_page_size; - void *want = g2h_untagged(commpage); - void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + ARMCPU *cpu = ARM_CPU(thread_cpu); + abi_ptr commpage; + void *want; + void *addr; + + /* + * M-profile allocates maximum of 2GB address space, so can never + * allocate the commpage. Skip it. + */ + if (arm_feature(&cpu->env, ARM_FEATURE_M)) { + return true; + } + + commpage = HI_COMMPAGE & -qemu_host_page_size; + want = g2h_untagged(commpage); + addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); if (addr == MAP_FAILED) { perror("Allocating guest commpage");