From patchwork Sun Aug 6 03:36:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710885 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp827088rwb; Sat, 5 Aug 2023 20:42:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb9SlGuTGsW9jq9LNck1t02FiUrw/T/LtpVTJVRI6KSbZ8cIB6+kCqf9OX22+Z9qjAo8Zc X-Received: by 2002:a05:620a:40c4:b0:767:dfcb:7094 with SMTP id g4-20020a05620a40c400b00767dfcb7094mr7775458qko.52.1691293364758; Sat, 05 Aug 2023 20:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293364; cv=none; d=google.com; s=arc-20160816; b=hU9ShmWtExybQVSemXWtGxcsaxjDg7/M4if6xs+8Z9zN6q5KgWQG1WexT6JWK/oMlu XM3mgMcqZuir1u7tl1bijYkKTK2HOEcqxWRZJuHzU9uopkTbY7MvMK1VewQWfyWxKoA5 cUd+M+RMKOey0mOBEfHFMSKrUWlfpN96viYRg3Ia0FF/cqu/zj9Csq37WoP847tM782Q URvIL6JcRu7Jy6Umoq0FM1MI2Adr3zi3VN+qcu9Yl/KHa0uZvvtn3b/XiMQU7fm8CCjt QitxBkT1MvfqsYNW44W1t1C9HrvIX6ERk1KL3LjYGYnt/8ZaPMxzne/ADi9kOCjcQU4K zJXA== 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:dkim-signature; bh=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=YfdOdEyG1ACNK9GahVbznVUjwZYPku0dl5xBVkoqegDN/2PJmIsGH8nsgxzbUWbZZy vi8KVoeTmXrZuhCHLPoPEiSWlOX6/+dVzblEkw5AbUVeUYdDKRu/0ZEkbdOznDlrG5x0 11s/2ASwbr+E5FSq5Z+XsQlOoTlVLbdbeodiwbBu+xFwA3JWbQ8bxV7LiPaPgW9Xs2b4 arz1Idc+VpKLjyiGETPCt/sywIUQA+fleT5NGBlDIo8KUqNdUpvHB08UgD+gzTVnuGRj 1lEyTpwJVDX7ghlo53+xCQr53bFbc+zzvcDZLrwWNsPz7D1Hmt01CKLK/hOt+Iho6OpW dq5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x2y0mcyl; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u19-20020a05620a121300b0075cf18aacaasi3171469qkj.328.2023.08.05.20.42.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:42:44 -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; dkim=pass header.i=@linaro.org header.s=google header.b=x2y0mcyl; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa4-0003ca-Hx; Sat, 05 Aug 2023 23:37:24 -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 1qSUa3-0003cN-AR for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:23 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa1-0007We-Mz for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:23 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-53482b44007so1893071a12.2 for ; Sat, 05 Aug 2023 20:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293040; x=1691897840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; b=x2y0mcylR08z82S81nt+uxpnFQEPS/6RZCpX5qz+p2kNgHElMGgrDYZFD/i5JXFuy4 Yurd0qW1jwJzlsjbIZZx/JpCMUymPwfwB2XavBsltw8THKtc0oFHba14H3eFWUi6Vi3w egouuTi5AF3GLi6gKXeDixw68UP+dDSNYZxi5NBEsGzyvSYs1nITcLWZMJt6I1zQVOBd A8WH9zqFj4a60LfcW0IveaibSTTx95/k0yxtxDdfNMnxnOaV6E8SZWdMP9mcDsQaTo2S P2Yf2I3riKz2ES2X4lFGi4VAqRVW8sOtT63shgSufHAFJX9ygPgIF82U9vuLwJb5S2Qx eaNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293040; x=1691897840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; b=jpuGRn2xqEtUotbmZQSY8ScaIBmP6+J427BFpV5TbsuMofPSP3dBPmndhg7/OQYbzX J2983yF3o2dVrfp4CNw4SkacdL8vvOfdqQzCTH2jRbb3nc6mNXIQFwirguv2CbY478i1 5zv3yzoVpwalM/gogiXNr26xqgXnqiLW2r8ciV6oFNjU7JtPcFg8CLwgAcTwWTggPg5Y 4M93ArlDvUyaeeNXStXYTqUK3k9DlIPP6Mq4gt/p2tp21c9d4YAA0y0TqZjXBESNTq5h pK/Qs1aHxs16kescFssqcZr1HDYhMN9Xo2XSzK6VPCB0CtDMdCxot2Myn840k0oZmjOs 1JCw== X-Gm-Message-State: AOJu0YzkoDPWysbOjl3rIdgOO5Rd89/2/sqCyLM/JxBKZNh+o164g1TZ 0cogZRaGfY2eqX2ePe1j1h010CQ3OMns2k0kcBQ= X-Received: by 2002:a17:90a:1c09:b0:269:5821:5808 with SMTP id s9-20020a17090a1c0900b0026958215808mr18801pjs.32.1691293040326; Sat, 05 Aug 2023 20:37:20 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 05/24] linux-user: Unset MAP_FIXED_NOREPLACE for host Date: Sat, 5 Aug 2023 20:36:56 -0700 Message-Id: <20230806033715.244648-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Akihiko Odaki Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because the address space is reserved with mmap. Replace it with MAP_FIXED in that case. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-2-akihiko.odaki@daynix.com> [rth: Expand inline commentary.] Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a5dfb56545..a11c630a7b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno = EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno = EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something else. + * We have just checked that the guest address is not mapped + * within the guest, but need to replace the host reservation. + * + * Without reserved_va, despite the guest address check above, + * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite + * any host address mappings. + */ + if (reserved_va) { + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } /*