From patchwork Fri Jun 30 13:21:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697938 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp450234wrs; Fri, 30 Jun 2023 06:23:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFkqreTfPa1XxhOjICaW82PlgC39B53Zw6plKlRnHEw8iibogk8IfvEpPzdlJYgxnbNmb+J X-Received: by 2002:a05:620a:2955:b0:765:a55c:b62b with SMTP id n21-20020a05620a295500b00765a55cb62bmr2924911qkp.76.1688131424009; Fri, 30 Jun 2023 06:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131423; cv=none; d=google.com; s=arc-20160816; b=erMewqS3aESeLl0EaeS0ltvaBVvfHgoiNmWuXi819swdSj8LOtgu8ku9vkGNpOiISH QidRcmk/1+m2h5v2vim/xy2oT1/iSb7PyD48Jf3bViE1eGWZ65mbHvlUnNQmvPmkkr2V 66/q2RlyG672Vc1cadREiloTLNLjEt0s/K2dCGLFI+f7jFAG5Xn8e581yAx18GvSCDE8 9UgntedfPZMa8Ef2Ngm55xeo2djsh0wjLZayUjIj2+bjyK52zumo1IA9gnFz/2nzxaI8 aFvY7T5oh58kHNLVIkRnJ5A8+H3pqighzrgkLzMrD5K8AGX8y2FkEuwWNWOKQF0/TokY GrOg== 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=KrYEO83mUZLefivMHniXeqFBDxyfnNPTYsBHzpccNBQ=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=YD+nZusrrb8A9DmqGHbC0Rm95Ur0gSntUayrp9cnkKuIM566O0gxHrYDhuwoe4qvJi q4eUUkisELXt5WdHvMmh/fXeFHcoalb/JBpd1sGQfYzE2ZjeQaO6Z04flk3zK8kYYpYc Gi/JEka4Oxs4xGktqgJeBFbBwi+tWbosladO7AurlyXQR6xw6FVF9pDf1+wao+X2xWhh LW1xS8TWFcXmVErvOT1KlPmPl+byorNuDB2aL8HDlIw/yWiR7v0y6qUATgXysMTKG3Bd 1wcunj3EFaoLEBleVcgz2o3a8hkuvFwGUN10QZKQkCVtV71ykV9Jg40PJ2qhrQ7A15u0 DpTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LXYUpdWr; 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 m18-20020a05620a291200b0076718a3ad56si5477057qkp.185.2023.06.30.06.23.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:23:43 -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=LXYUpdWr; 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 1qFE4k-0007gT-Kg; Fri, 30 Jun 2023 09:22:14 -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 1qFE4g-0007bo-TE for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4f-0003Pi-8T for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:10 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-313e34ab99fso2025483f8f.1 for ; Fri, 30 Jun 2023 06:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131328; x=1690723328; 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=KrYEO83mUZLefivMHniXeqFBDxyfnNPTYsBHzpccNBQ=; b=LXYUpdWrRnIAD1HM6dGh+2e903minFPvPqaLvgDsIHpVZ+3Mlh/GrzybUBu0gQR+Ug Yj3+hKguXBr/5DqXhG4Xe2qISjIS3VNDYDmqhXxmEeeugWB/t02EDUJulRT68/Cakr1o v/tMgCuHQ08x9wjzI6crDrfA8YtjGcTXYzrfSi+U8MQWltpFsNgZAavS1C3twDfLVWL8 RBBWaOEThYCOz7z8K2eOP8E2qlWbLNb+vhLDx2ghcdKC+Fq71dgCwDGMLijVEe3uU1pe 7pMGWqZWN+SfUTMYydRu7Yl29USxhRMoM10FoAXfLCjHYqE1W75ciu37El+lCNdZFNVD aHPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131328; x=1690723328; 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=KrYEO83mUZLefivMHniXeqFBDxyfnNPTYsBHzpccNBQ=; b=YvluMkCbTxARkyFAEv05XWklGZt88XSIgX+33LUgxRScgDcUKdMLVWASkYgIy0mddH QwQnV5rXckeAuUlIdcxWcaVHNQBPi0on5h0fBhT/MMfb96QvH9iKuAusooEIf3D+MC2T NEZnuxYPpT4bp2Op6aDvDoAdQIrlpOHwiDdwDm82h543QgTz0swryX8N6qgAQ4u4fxyd 59Fg5Tgs8OO844Mb2QnT8fuVylL914DXl1x2PNBgQwK2rXLF9PhM4QPILQ4MgOEP8ZT+ S4T+NcjRBitR5aOVD4ncASa42CVwWQdElzSNetxCWu+pJxDPUFgsA9CZFFWdZa8QPQrF Ex2w== X-Gm-Message-State: ABy/qLY5p2+slTcMZFVeES4Pa5FZ3TlxuPuzuLml3sRYYW1uGsMfYZxp 2onWXVlmu3eUUmMIeN7OLv+sXJzNWbdifHOE/sPnYg== X-Received: by 2002:adf:fc12:0:b0:314:14ea:e2db with SMTP id i18-20020adffc12000000b0031414eae2dbmr2088627wrr.0.1688131327731; Fri, 30 Jun 2023 06:22:07 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id a16-20020adfdd10000000b00313ef2150dcsm14571092wrm.45.2023.06.30.06.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 09/24] linux-user: Implement MAP_FIXED_NOREPLACE Date: Fri, 30 Jun 2023 15:21:44 +0200 Message-Id: <20230630132159.376995-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230630132159.376995-1-richard.henderson@linaro.org> References: <20230630132159.376995-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42a.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 --- 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 cb5369d2d1..41c2f09fd5 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -502,7 +502,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); @@ -544,7 +544,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; @@ -593,6 +593,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 @@ -608,7 +615,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;