From patchwork Sat Jul 15 13:52:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 703243 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e4d:0:b0:314:25da:8dc4 with SMTP id r13csp158829wrt; Sat, 15 Jul 2023 07:00:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGIKduGbbepX2NB6f4birgsJP7fP0ofyp0bo3MCDWapfkfBZP96fnYaKRZQ8H/QvA/V6jQZ X-Received: by 2002:a05:620a:1a92:b0:767:1cd5:3456 with SMTP id bl18-20020a05620a1a9200b007671cd53456mr9987139qkb.39.1689429606984; Sat, 15 Jul 2023 07:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689429606; cv=none; d=google.com; s=arc-20160816; b=M3rh27byxXrwVQaVRG9h5O6v91zDI41SdwD+lb88mR7af8Q3rsq9cbGtdtF7i8mM/H CSBE3XI7y2iFyJ548pblBxRZAEGPabuWNllPAER2P2fNXuJ25yZbrcvOR3c04LOyG+4p Z4N7/H/3zwQY/j+X6SStKcsnPBxDmkKJJ1UFX3phVoH+LsglBNdqDwyzdlSI+l/bFPvN Dt2uinoFDtRhdN5aaphW+1QdIYg8Md12O1qivtLaHauLoxarVHs21DmnuNC54Fez0qF4 EefSLOTchZf2+lBd3Lfo1XoJl/1s4z0CN60FCIDnId0bQ/KU31pAqFKpsQDa/8Mosr3g MSmQ== 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:to:from :dkim-signature; bh=QVp7bvOVNX9kOQlZjcnMWNBhc4o39/6I/4Tb+lJViFc=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=SIdMgAKI1fcKzse42mfk2a1zCJRf8+3Doo856utYPW/8ot/d3z0NFZsqRmCzmCHZoO rGD7fJNu2tl5KGD8OK32ZT0U8vjqx4w4Oc9wKxx2c6k3Due0BRCYMoiqIAp76e71Gr84 GRd2QDfptfB7QJYYSjTNbSk5QO6JRRpOoURONTwnYYyeA0Hr58piPegq0a9dOwa1lvs/ cCuEgb2Ut0VYBjfMzmkfQaSXQNstaIuYQweEanLIqRIjK/GC3ylRnk7Z6crqyESYuWen 1w/ex9Ebpl2fl+25FMf6dQWPqEVpU2WiMcuuIEceQpRgra0mbVDzY2y9mbrDwziHYyxo /SIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XtKFtlKt; 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 a15-20020a05622a064f00b00403a49182b3si5583344qtb.579.2023.07.15.07.00.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 15 Jul 2023 07:00:06 -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=XtKFtlKt; 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 1qKfjn-0007Aa-3e; Sat, 15 Jul 2023 09:55:07 -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 1qKfiX-00047p-Qy for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:51 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qKfiR-0001JC-Qc for qemu-devel@nongnu.org; Sat, 15 Jul 2023 09:53:48 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fbdfda88f4so25773525e9.1 for ; Sat, 15 Jul 2023 06:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689429222; x=1692021222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QVp7bvOVNX9kOQlZjcnMWNBhc4o39/6I/4Tb+lJViFc=; b=XtKFtlKtko5uNMNACbbQ8r4U2tisRfWIEcBb7Hisl4tuzSAwhWmJUppQ+Wo75Ra0OP 0aLh6cpShYGhnrovksSTlYIfe9jgyrerjJimiIPUzL9tT5LhwWNT0Ts9JKLtNFSzEr26 lb9wg9q5jVyRJyiU4ve3H5DRlmkGC7IC8zwrorouHPqrlqTzlve6gY9vOXWaDKGDGb3s kH4Hy7N8i9tD6ag/FHbInrfnW9YtDwyQEY+up6SKoLpJopqrItwW8q6V4cbnuc65yVDu qtN4jfcPbhow2pX+0l/q9lreJnUf3IxLmtLvnaUMXjnFsrEDI3ZO3N6hMCABXVFNU9d9 iFUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689429222; x=1692021222; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QVp7bvOVNX9kOQlZjcnMWNBhc4o39/6I/4Tb+lJViFc=; b=QTKZv7axUHLiPxrehzkLOpHKyDF0hN1sjQuL/TaH5JgsPBtchHWOpN4m0zvYAAdZmM X889mS1pL8pYcincts2RGf+xzmoY/PzqM8VCcQEmswTuHBUdw5cWlBE8G248OVbx2YUz qJD6s8vowGxBkQSXMFNZpm11zJkIy2NrDnS4A2i9wWxhdhWDAaiwrXNFkPTEp6v3AyG7 5gsEaLf2qTiE4G1sSVCQG2qPgWixTg3OElDtR74C+Bg47F/wHIpQgPl90DSO5mKlGiVB 1QGlZVvY6rRKv3ZaOn5PpDbemyPcjNkWQCmOIRLqhA1fjgJvV2C6nLlqf2i3Q09SvAqa auew== X-Gm-Message-State: ABy/qLb0303xeDByTMbbLGJgisbCzFaSeD3pVZhY5EmG9OALkkO6oeEH JXCjh5kguOzoK/fI30WlrWlYr4Mo/PkeqpTk55mE4Q== X-Received: by 2002:adf:fe49:0:b0:314:1ca4:dbd9 with SMTP id m9-20020adffe49000000b003141ca4dbd9mr6080779wrs.27.1689429221787; Sat, 15 Jul 2023 06:53:41 -0700 (PDT) Received: from stoup.lan ([51.219.12.49]) by smtp.gmail.com with ESMTPSA id k10-20020a5d66ca000000b00313f9085119sm13838014wrw.113.2023.07.15.06.53.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jul 2023 06:53:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 28/47] linux-user: Implement MAP_FIXED_NOREPLACE Date: Sat, 15 Jul 2023 14:52:58 +0100 Message-Id: <20230715135317.7219-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230715135317.7219-1-richard.henderson@linaro.org> References: <20230715135317.7219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x331.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;