From patchwork Fri Mar 1 23:05:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 777099 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp1603280wrn; Fri, 1 Mar 2024 15:15:07 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUDlLNfebPqj2p71djIO3I8e7Ko40nxPtB8dYcBmZxV3PaXC4Q46OCCTohQoMR+GlUN0fV820TVUBl+rK+GwA4l X-Google-Smtp-Source: AGHT+IGZpe6+S5Ue9v/IfyxW3hSRZbqxlr9Tl+oS9CObepsoMVs6GiEVsd4Tgeipf/Kz33eGanyd X-Received: by 2002:a05:620a:57b:b0:787:83b3:2283 with SMTP id p27-20020a05620a057b00b0078783b32283mr3069073qkp.23.1709334907188; Fri, 01 Mar 2024 15:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709334907; cv=none; d=google.com; s=arc-20160816; b=PJ65bg8n2M9cxhb2NOnYuDqQ4F1DcQIUolCVrpSmVQ2mY5elxXOwD82nOm5HZVgGm5 r5y214nZ56bkOEZAf+yL1LanF8Xw7hIAva6ntVi7B5+IlMT76DtbRHjQu0OACRUSGfUp +ALEPXamUG8KNGOa5MPHA0dMVD79nfOdw5UEL0aOij3ReeZUtuENEYNmzb/rcqMTcIn5 da2zTli8Yr9Lu3DdEJG55LtpSTqhJxTWefWXXeen/mhoUJ2NI30CtMtVpkYCjwXykiN3 bdgXbye+hOSXnnz3TYU6t0xvwjf2l13MBFOm9v3KAeWhJjIYg7AFBYrjOJmTJr9ym4o5 1fqw== 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=5K1zjw+5Oj4rrjx8HADPxYdAwsCVv3T9uofL+YVvOaU=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=C6o/8jmcsxwG7sGAGCScnKsOGYQCDAJfkRq1XHi4roN+5Asg5RHDXIASJGO9g75h2f PAlEK3UdO+igfpCLsvYVt0Eg2XJ5Dl1dnYI5X5L9+UjSd22E+kuSddSudHz5EmhFDPqS C9EB2g36GmqpDzokajMnCVf5qtOquZECrbcS9DAhGKj7m3Wt61mQZeh4FY1Dpxn57n1M njDw5Ew7if5uYNXsoT/5qee5/m27JfWd1LlcY4FMW2d3ympO/CQp21Hm2JAMEz62dpd5 J8mMbBrlBVF+PkyBdDNjjuqQjW9T7Jlt0waN4mmTuLuUEhTI4MbrNtT33fa7iVwWMiMd 4cBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CK234zOU; 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 k20-20020a05620a0b9400b00788138b4f76si782650qkh.345.2024.03.01.15.15.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Mar 2024 15:15:07 -0800 (PST) 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=CK234zOU; 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 1rgByd-0006ZF-MB; Fri, 01 Mar 2024 18:07:43 -0500 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 1rgByW-0006Jg-Rt for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:32 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rgByK-0004RP-Cy for qemu-devel@nongnu.org; Fri, 01 Mar 2024 18:07:32 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dc29f1956cso23797255ad.0 for ; Fri, 01 Mar 2024 15:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709334439; x=1709939239; darn=nongnu.org; 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=5K1zjw+5Oj4rrjx8HADPxYdAwsCVv3T9uofL+YVvOaU=; b=CK234zOUflO5hGuofTmOE4SXh0GZ0yenbjYm3JgX2WgnmINR5gqIDVeLytPXr1wf2P lwyBw9lwRoHAsdA1mwAJCk9WTktTt4fWvA1CP6Ew3zluZePdQHGE6Ik7wH277nJQrVZW v5Bl1UVLHwnZRbhvSRQgv5UjH3QQ8cemmpmFfLz2xILdGBO/CU+rspc4BRbn3esc48QS 3VI6Ta6aq93jVcM2na3QK2SmpyPZJ9kn6A68NqnVxKuAi4hicuPkHL8plqjnDHRIfNIK RYZJEpmlNDTICmRRRunhhGLMi4z4ZOADpWdwqXKcAKfxISXxipeZGjIL38O6n/9RaSbP gANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709334439; x=1709939239; 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=5K1zjw+5Oj4rrjx8HADPxYdAwsCVv3T9uofL+YVvOaU=; b=R6P6PKUfrl3f/1ec0oEqe87TmCD0AWHY7nRIstgRz1sZGpyBdII9al/B8xl5cI27sT +Y5PRZkdiNW3l7Kl2hHzeNYgnrLe6tzy5x3qB5ObsToL5dFvs/j4BmoUkEZQBgLv5/0T MxgDhym6NpM866nxHEmt+Qm0XIzLuou4SCOdLBiYoK+EHmXvTNWeIw+yX4cXk4F143Ao rtaxBSTLqvtMFf3PhzG3DNI4OukmFUgXZHhxKiw5pF6TeDDiXssiSAr3OIM18IHwGiGR 5y0BBZK6zAl/YGEEdU2gA5Vy8AqSkqDAQehDKzAT93rQseC8BVGty4EQ9FPbCWoe6KxF dH9g== X-Gm-Message-State: AOJu0YwX5e4si6FclzvWss/G4kZWQ5XzF6h21dn2t+cCMr/6/LHpBdcc snNiG1a3gHQ8MthrzcMzo3xpNWEVkJ+mYk9TQao0jNPDIlqWVb6OxRtDzDS18g05ds11TDkbt2c i X-Received: by 2002:a17:902:d4c8:b0:1db:edb8:35d8 with SMTP id o8-20020a170902d4c800b001dbedb835d8mr3636482plg.34.1709334438803; Fri, 01 Mar 2024 15:07:18 -0800 (PST) Received: from stoup.. (098-147-055-211.res.spectrum.com. [98.147.55.211]) by smtp.gmail.com with ESMTPSA id lc11-20020a170902fa8b00b001dc668e145asm3988580plb.200.2024.03.01.15.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 15:07:18 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 39/60] linux-user: Split out do_munmap Date: Fri, 1 Mar 2024 13:05:58 -1000 Message-Id: <20240301230619.661008-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240301230619.661008-1-richard.henderson@linaro.org> References: <20240301230619.661008-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/mmap.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 1bbfeb25b1..8ebcca4444 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -267,6 +267,21 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) return ret; } +/* + * Perform munmap on behalf of the target, with host parameters. + * If reserved_va, we must replace the memory reservation. + */ +static int do_munmap(void *addr, size_t len) +{ + if (reserved_va) { + void *ptr = mmap(addr, len, PROT_NONE, + MAP_FIXED | MAP_ANONYMOUS + | MAP_PRIVATE | MAP_NORESERVE, -1, 0); + return ptr == addr ? 0 : -1; + } + return munmap(addr, len); +} + /* map an incomplete host page */ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, int prot, int flags, int fd, off_t offset) @@ -854,13 +869,7 @@ static int mmap_reserve_or_unmap(abi_ulong start, abi_ulong len) real_len = real_last - real_start + 1; host_start = g2h_untagged(real_start); - if (reserved_va) { - void *ptr = mmap(host_start, real_len, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS - | MAP_PRIVATE | MAP_NORESERVE, -1, 0); - return ptr == host_start ? 0 : -1; - } - return munmap(host_start, real_len); + return do_munmap(host_start, real_len); } int target_munmap(abi_ulong start, abi_ulong len)