From patchwork Fri Jun 30 13:21:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 697928 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp449594wrs; Fri, 30 Jun 2023 06:22:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlGX3CBr14D7eodYcDcIIQsnuNwRipglFwcpC6VLY7A/+0Rz1ndFSxLclSlOzKlXcGN2Cie7 X-Received: by 2002:a05:690c:d07:b0:576:f0d6:3d68 with SMTP id cn7-20020a05690c0d0700b00576f0d63d68mr1933748ywb.32.1688131352927; Fri, 30 Jun 2023 06:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688131352; cv=none; d=google.com; s=arc-20160816; b=yR5iGWU0l3WL9aSXWdGG0fEX78puxdZwig92La+/HTd4eSs+xDi5un5mc5vljy8jE5 xRzRmcDyXI//eaBaQTQmsvjcwCDqKpRww2ExCMIWGTWNx8EyRGXvv+Xb/vyGTzi7Z3+K v8bFmeOvg1iMPjmQin3s1E5upxfcKXX+x4xmQ+Kp3gRm8YP2Ax4dFEv/he64PuoVmnD5 O7SW8m7LbGX5w0JOVJ3x1qCLR7oUQ6G9K36HeR+zaPO6BvJIFtw8HALm3StYDqnsOd9U 4IxQjCM1Cey4SplIlm7G8lTHmumqMQk5LuBC69YVCk8oPfjUxEFA3j3WjEMrRnXs2aPg /3EA== 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=mwwpiV6MaHNjI0ciuX+pvMo7jFfE+x6J89Pmy8AxQUY=; fh=6bnXD+ip8BuPvzTWf97csbR5QVhpZvBV1AID0n9STS8=; b=TJBwVhG0/3nxZ+ovMVq9gf3Kr+JEhWUdgI9RFW6zUh0K3XSbhaLpi5SvkJpd6HDmGp SWuT4tXA1/fW5zveVKMpzrgxhRevRxE9jzX6mbgGIx1x5dBsDlhmU3PeffSYjN2sxGat pmciwzkOvjqAW9WWYwK154+Wzfx7RrCURnN2nEF5uwNfq12DX0BzCfFKuk9r5joxyTxB lGZifG1HZEX98BeKHCw93h4O/3gqADIh50UkBIkzPv9OkDYWFA4px5sW5V07t2oexCrz oQTzWthPKRYMBeuLXQIo5hSy7wR2RNl7fhaLx4YIVJ/b+uQdG0S81IdCpNRrGYiNs7hL Jxuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bf9ReICQ; 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 b1-20020a05622a020100b004034999222fsi45463qtx.663.2023.06.30.06.22.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 06:22:32 -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=Bf9ReICQ; 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 1qFE4s-0007mu-Qi; Fri, 30 Jun 2023 09:22:22 -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 1qFE4p-0007jx-14 for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:19 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFE4n-0003ST-AC for qemu-devel@nongnu.org; Fri, 30 Jun 2023 09:22:18 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbc0981733so16661035e9.3 for ; Fri, 30 Jun 2023 06:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688131336; x=1690723336; 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=mwwpiV6MaHNjI0ciuX+pvMo7jFfE+x6J89Pmy8AxQUY=; b=Bf9ReICQepZmHlH27q33m7J8RebYRc2M5lM7V4u1l7+l2O1Kp/9SX3IVGixiMEXLfN x/q3zFe8/yQPHf6G04ektFlh8qwL5feJRETU/sDVUDpa/6/04xpaUVNI8qJ/O8eufd54 fy64p3g0M/u47sXQmDxwevFxxYkfcldGn1SSuCBklvSaciG9q9X1uMx3w8PHtNn8wGAs 9F4k1ia3RnT5ga9aobQJl+HDp5WuSjIGEpn+gxUKWTxBzyj19oLOIzHa8o12QPAP4FsS pUN5XdXiVdAO8+0Yt+MKeVgnbCfGveAH4NbSPDgV4pmk4CQGRTxHYPy2lihH0Wva5rYV pkng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688131336; x=1690723336; 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=mwwpiV6MaHNjI0ciuX+pvMo7jFfE+x6J89Pmy8AxQUY=; b=j5u3E+TqbmqEclzGxO8ezj6OolHeGu15mpgVIOLTpG892G2oUREFgIEPmeIIkz84cf silRQYBVHLgYexJ7L9Cime+hEZBq09+cmnAM+p99xuSEofcpqM4I/gaviwnrXqZ7/STU cZ9oDNfZlEBEli8CllPViwWK7qoT3oZ9x1LEzHXBr0VYH8Qe0OCX2og1w62asxPlar3i Oo8f0jrmDcpj19Yj2C0e3oYYM4rlRzgv36be60wrvprjdJNnSP7cQ+3/Q0FVwfyo3gK2 USzLMnSTHYDD0NyD5K8TpP0HL2Rw3Q9tKGy2hYUiSkXu1tOLs1l5Xv3j41zsat1L0yv2 yRtg== X-Gm-Message-State: AC+VfDyKlI+F74Gy+fbj2kwKnvqxACpwSWUf1YJI8FNgG6IT7YvN0l7F xyawnj3+lpZ9kzY4GLze0Gl4ZyCyznoCo1/wmY+dIQ== X-Received: by 2002:a7b:c8d1:0:b0:3fa:9554:fb23 with SMTP id f17-20020a7bc8d1000000b003fa9554fb23mr2192997wml.21.1688131335472; Fri, 30 Jun 2023 06:22:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 06:22:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mjt@tls.msk.ru, laurent@vivier.eu Subject: [PATCH 19/24] linux-user: Rename mmap_reserve to mmap_reserve_or_unmap Date: Fri, 30 Jun 2023 15:21:54 +0200 Message-Id: <20230630132159.376995-20-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::32c; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32c.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 If !reserved_va, munmap instead and assert success. Update all callers. Signed-off-by: Richard Henderson --- linux-user/mmap.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 6b030dac42..8c90a690dd 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -722,14 +722,14 @@ fail: return -1; } -static void mmap_reserve(abi_ulong start, abi_ulong len) +static void mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) { abi_ulong real_start; abi_ulong real_last; abi_ulong real_len; abi_ulong last; abi_ulong a; - void *host_start, *ptr; + void *host_start; int prot; last = start + len - 1; @@ -776,9 +776,15 @@ static void mmap_reserve(abi_ulong start, abi_ulong len) real_len = real_last - real_start + 1; host_start = g2h_untagged(real_start); - ptr = mmap(host_start, real_len, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - assert(ptr == host_start); + if (reserved_va) { + void *ptr = mmap(host_start, real_len, PROT_NONE, + MAP_FIXED | MAP_ANONYMOUS + | MAP_PRIVATE | MAP_NORESERVE, -1, 0); + assert(ptr == host_start); + } else { + int ret = munmap(host_start, real_len); + assert(ret == 0); + } } int target_munmap(abi_ulong start, abi_ulong len) @@ -830,11 +836,7 @@ int target_munmap(abi_ulong start, abi_ulong len) ret = 0; /* unmap what we can */ if (real_start < real_end) { - if (reserved_va) { - mmap_reserve(real_start, real_end - real_start); - } else { - ret = munmap(g2h_untagged(real_start), real_end - real_start); - } + mmap_reserve_or_unmap(real_start, real_end - real_start); } if (ret == 0) { @@ -871,7 +873,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, * If new and old addresses overlap then the above mremap will * already have failed with EINVAL. */ - mmap_reserve(old_addr, old_size); + mmap_reserve_or_unmap(old_addr, old_size); } } else if (flags & MREMAP_MAYMOVE) { abi_ulong mmap_start; @@ -886,7 +888,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, flags | MREMAP_FIXED, g2h_untagged(mmap_start)); if (reserved_va) { - mmap_reserve(old_addr, old_size); + mmap_reserve_or_unmap(old_addr, old_size); } } } else { @@ -912,7 +914,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, errno = ENOMEM; host_addr = MAP_FAILED; } else if (reserved_va && old_size > new_size) { - mmap_reserve(old_addr + old_size, old_size - new_size); + mmap_reserve_or_unmap(old_addr + old_size, + old_size - new_size); } } } else {