From patchwork Sun Jul 9 18:29:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 700917 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp4830219wrs; Sun, 9 Jul 2023 11:43:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6OKGyO/+9OdeL8ObV2DQhKK5MocQM7PTIEcJCA+0v11Unq0dcdq4hUNFmf1UF4KCgUbt9 X-Received: by 2002:a05:622a:15ca:b0:403:aed5:99c6 with SMTP id d10-20020a05622a15ca00b00403aed599c6mr1370552qty.20.1688928190925; Sun, 09 Jul 2023 11:43:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688928190; cv=none; d=google.com; s=arc-20160816; b=uGORpFtvY1ODJO0oo9c91uJOHViDAhT6WPzXodQAhd1j2+T4XH/tMQ5sAIDQeXCUzS aozzbDlLFWNIMUFRKskVI99QlwT81LX5/O62iQMZXGbt0XMz7OK3OrhrDAKkrPp14cP0 Z+7BF3pjaMtwa3bo++QqMnijA+dA2OzB+7Bg5lnS2gi3b3aFyIs6Y/vVDRNA4ZLvuRhy XQ9ukRNH06/vTGUUTu6vIs7OtEU6fViRMsan88loaqygvhO+yShVOqOHQDaEnYt5Gaje opi5t1NovieC+GTxPKsrlND+HujFt/FBNtx3ZPZFsbI162aA6uBK0wf8QKaDZsEdF1mr 6RVA== 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=QVp7bvOVNX9kOQlZjcnMWNBhc4o39/6I/4Tb+lJViFc=; fh=4nfr0hkxlMpWE4oToQ1q4rzQVecv6te3cGVRc3YFjiI=; b=Z9Z4LyQj2PmxXCmPwncyBh7dR7P7VCqmhTIk7w0Tk3MkZFeS8Rk6DJ0h/t7QFUPqIy 1G4twc+OnFpGMcKJtBYljpPgoVdPvYBOTDot0VQ2WbT4/MrnL6B1pMiSl6Ln0h8ElU4W icgGUXuzPC1FsENCaHyNeTYx5kFL8FlWP61u5Q/RUp54FEutYVZf6yBbW9Ef5AqhCi4U lVa6T4EaZpNvTlYUVOYnEAFE2A0nzl3+pIRlXigqA3oxXjMycPT6SqFXvZjt4uH7j5mT dutkax7gDNXGh2/r/TFQS9UZRTvsh4Vx5fVywSx9aleZl0FRSSlGXY4rXYdZEottZdte kNuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Te502nSt; 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 i18-20020ac85e52000000b003ef3c2fd077si5023702qtx.740.2023.07.09.11.43.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2023 11:43:10 -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=Te502nSt; 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 1qIZE9-0004Ui-Qd; Sun, 09 Jul 2023 14:33:45 -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 1qIZDu-0003Wp-DC for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:33 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIZDq-0004ED-9a for qemu-devel@nongnu.org; Sun, 09 Jul 2023 14:33:29 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbfa811667so19654605e9.1 for ; Sun, 09 Jul 2023 11:33:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688927604; x=1691519604; 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=QVp7bvOVNX9kOQlZjcnMWNBhc4o39/6I/4Tb+lJViFc=; b=Te502nStAJsDxJZLfJsnaWCc+RMx+MF1zCZjPakbbQtsg/Rc1mtz0RnR/0CeANyusO gIRnBrABCPxdL14RfGVY/REJR7og2Y+sFJHPF8lIiGVbdbw8B+OGcNQ+pMKEHkHaLkw7 tzEVrCxNxVq5llKILPE3bSqWAV2en3Q0cy5+XGRXn6z8UTTaCdg5rJdaNQhYqRUAFlto VN3WJypkEkEccQH4Lnb14C27MIWW4EF6C08dVQctBJIZSbu9GP6C8U8JozV5BbEG+8Fr G5PMvMiirbNzTok0x2PGGmQ9gg9uBdi8zVBWgGq68W4kMlUouNUlzz1dUwavC84g6nbV HQig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688927604; x=1691519604; 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=QVp7bvOVNX9kOQlZjcnMWNBhc4o39/6I/4Tb+lJViFc=; b=L55pMAj72HiEE7JikmKcs9pUrsr1uzpqJj11/2scs5GxQTuiVyFGDxgU9X5VW8BOMe TkKxme/FJBgQH8IHVekdvfRHJbO5n8qEcXePQgCd+FO1eJq5crO2gqdbzxYctlCMT18l emHOaBk9cfXhqPXQOdNiua/rGMy+asrtSBD/QJq+ZEEoet8oZ3tpDpYVKvnqPAJjdofb q7YWJhleyJdxJRb5Vy9EkAbVBJVg3b/7Rn5iuwMfppw5feBwY5CR/DAFeynAPiQgERjR wfwmhn5VAQZyWFTlUVZ0k2ZisAoDAhk+EHeLRhs/vM/U/hovNZMSAfTd4bW5UO5VFPMZ 0vvA== X-Gm-Message-State: ABy/qLZXdeLIyLctlSzvanNB8v2bBJnVaFY3IVecBnS0fgzOWTFSDJXv /3YUrCKpNSObOrZMl48/v5OAHRnS6WUl53EE+R7/fg== X-Received: by 2002:a1c:cc02:0:b0:3fb:4064:7e22 with SMTP id h2-20020a1ccc02000000b003fb40647e22mr3602869wmb.19.1688927604024; Sun, 09 Jul 2023 11:33:24 -0700 (PDT) Received: from stoup.. ([148.252.133.210]) by smtp.gmail.com with ESMTPSA id e17-20020a5d4e91000000b0031433760a92sm9635256wru.115.2023.07.09.11.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 11:33:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH 28/45] linux-user: Implement MAP_FIXED_NOREPLACE Date: Sun, 9 Jul 2023 19:29:07 +0100 Message-Id: <20230709182934.309468-56-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230709182934.309468-1-richard.henderson@linaro.org> References: <20230709182934.309468-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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, 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 Signed-off-by: Richard Henderson Message-Id: <20230707204054.8792-12-richard.henderson@linaro.org> --- linux-user/mmap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 639921dba0..9dc34fc29d 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -509,7 +509,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, * If the user is asking for the kernel to find a location, do that * before we truncate the length for mapping files below. */ - if (!(flags & MAP_FIXED)) { + if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { host_len = len + offset - host_offset; host_len = HOST_PAGE_ALIGN(host_len); start = mmap_find_vma(real_start, host_len, TARGET_PAGE_SIZE); @@ -551,7 +551,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, } } - if (!(flags & MAP_FIXED)) { + if (!(flags & (MAP_FIXED | MAP_FIXED_NOREPLACE))) { unsigned long host_start; void *p; @@ -600,6 +600,13 @@ 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, end - 1)) { + errno = EEXIST; + goto fail; + } + /* * worst case: we cannot map the file because the offset is not * aligned, so we read it @@ -615,7 +622,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } retaddr = target_mmap(start, len, target_prot | PROT_WRITE, - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + (flags & (MAP_FIXED | MAP_FIXED_NOREPLACE)) + | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (retaddr == -1) { goto fail;