From patchwork Fri Aug 4 01:45:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710215 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233134rwb; Thu, 3 Aug 2023 18:47:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+7QMslC/qHsRkIquUI5VhTsTf11LWT/lz0N28nBd0YyNTIyPA91DoB17WaEyRLqvMUtZ+ X-Received: by 2002:a05:622a:1822:b0:40f:e09d:3743 with SMTP id t34-20020a05622a182200b0040fe09d3743mr504689qtc.15.1691113654161; Thu, 03 Aug 2023 18:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113654; cv=none; d=google.com; s=arc-20160816; b=wTlJjy30mJaMkcbK27g41EzvFeR1rKzCWmVHIX91MpEH0WELKmoNi8GrqA52W1c1Oy EpOapGbXZR4eBHmzGwr2YnQuwiLEpNIubakZ8ktSKfPGBAuGbIIKTjFNSPsc3p+urann PVoz8ndz/KH/A45O/kUOHJ2bmD/nBYI3p8H3gXf6A9qkdMHWN9iozp7U+l1ugZnB3d4L cYmSpAYgchz5O6yptBrK0aiFAEdYpPamwH8bbZcomNi8rzZvHBQgrSvy1un1ykFXqvOC UAULTOa0vV4d7RL0JnXflMzdokhjmVwNZSIpv0sHjZSgjFkoMDzldJhiX4/MxargN704 avEQ== 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=ZjeFygd6IIkR9M2DIG513e5CPYAFIDSvTnL6qX1fRv4=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=VwUrJu+g83zNx3DJtzglg+glfF8BZ/7upYbLnofwtH6bRytF9xvelkbktL1VTvcHVz 4zRF3tebgsFTKyWdzzDJdTIFmcPNWkzwNEPn37HShelByG/KbdR8DlZZ1BW8BbodIO0I jufMuGDKlcuifoj8Til3JZSOg1jDs+rwuYP8BdAOYW7fXxYdiZTr7pHSEtUkYhquZHdp EBE59WESWdQ8E0vKvpBkfda3yCsT88ZcDZ4vnE68tLYAWdqzdtrvjPs5L5f3lRtTIF5C K4Va68yO/WE4rx0rqMnvZUe3f0zKrD+WFDZfOv1vz6Eta4KTV2enNdIMuGyKRA1gKbQ2 G0uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aWD5SYAO; 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 o18-20020a05622a045200b00403e72e49f0si596644qtx.783.2023.08.03.18.47.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:34 -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=aWD5SYAO; 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 1qRjsr-0002fa-HZ; Thu, 03 Aug 2023 21:45:41 -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 1qRjsc-0002co-CK for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsY-00058m-VB for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:24 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686f19b6dd2so1183660b3a.2 for ; Thu, 03 Aug 2023 18:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113522; x=1691718322; 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=ZjeFygd6IIkR9M2DIG513e5CPYAFIDSvTnL6qX1fRv4=; b=aWD5SYAOqOrW8KVpkC/8GTDCWzxvrXTEJiXrbjpavdfbS6fsurSzd66YcblmUd8aq9 0F2Jrne0Aczwlw7LVR/8ddOKk0p8NYhcw60AJV6jNywdoAepPRSkG/+FyMBC+iGRDwtt QqNPKFjO5xsShxXE3aSWnTOuqK1gfzQRTStySWnc6MlPvb8cDO55R1wMdWzWp25x4O9Q 3k9GDji0nJMulTihAN/z8xrZnnE3goZgAxUYpGJWoRjgXSAlAgA98D3LBEybJ0WIplZO 1jfPbjEElSoscC7F2eAsbG1BiZxcDXT5O2R3ra6DwMtaS78EMXv2S1T+9ykGXm38N1n+ 27lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113522; x=1691718322; 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=ZjeFygd6IIkR9M2DIG513e5CPYAFIDSvTnL6qX1fRv4=; b=gUspSzCZhL20zM3A5ZqxIBoGdCwtIuWt5EEvgYlMgR3i2BBR9wSM2+8AEW4RpgXfIW xv9Q1eYHnakyrEL+B6968HiM+pqs5CLdjOSFfJG6pMuERE+hUPyaBJJQrpbeffr7mD+2 Q9TxVZaiIIrIOPm9v22KZSzhSCUv8b12c7+V00zfNZAxIRrLyQDeK16doSFClx1Uz5RO rQNOdNl//9wu1MyZi9pKDYVNRTkECsG0guEnqH2VvafBim3375w1HqkfIHQET+0yapmX E5Gveua2vB5MtlKLrb/j3Z/jw4U4VmCx/DXGQsD7B2uiY1tvsT99Bf4RZAHFvsCuCkXq rODg== X-Gm-Message-State: AOJu0YzAX2LisuSLIQKlIHgOo5e3oS4FhOiigCUZOWtJXjvtdlg+6Rph bnkED2OOU/5kE42PbmVS5XpJMIrOBiHeSq8VKQg= X-Received: by 2002:a05:6a20:9191:b0:12c:f124:5b72 with SMTP id v17-20020a056a20919100b0012cf1245b72mr278850pzd.43.1691113521699; Thu, 03 Aug 2023 18:45:21 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 04/17] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() Date: Thu, 3 Aug 2023 18:45:04 -0700 Message-Id: <20230804014517.6361-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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 From: Akihiko Odaki MAP_FIXED_NOREPLACE can ensure the mapped address is fixed without concerning that the new mapping overwrites something else. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-5-akihiko.odaki@daynix.com> [rth: Pass -1 as fd for MAP_ANON] Signed-off-by: Richard Henderson --- linux-user/syscall.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b9d2ec02f9..f64024273f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -854,17 +854,12 @@ abi_long do_brk(abi_ulong brk_val) return target_brk; } - /* We need to allocate more memory after the brk... Note that - * we don't use MAP_FIXED because that will map over the top of - * any existing mapping (like the one with the host libc or qemu - * itself); instead we treat "mapped but at wrong address" as - * a failure and unmap again. - */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0); + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; @@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val) target_brk = brk_val; brk_page = new_host_brk_page; return target_brk; - } else if (mapped_addr != -1) { - /* Mapped but at wrong address, meaning there wasn't actually - * enough space for this brk. - */ - target_munmap(mapped_addr, new_alloc_size); - mapped_addr = -1; } #if defined(TARGET_ALPHA)