From patchwork Sun Aug 6 03:36:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710878 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826325rwb; Sat, 5 Aug 2023 20:39:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRvkJ/mJkUZN7zytfoGdz06vPRmtar4AhTmaXLKy15xGjIaWBmKC7YKkTe1t59LauJBK17 X-Received: by 2002:a05:622a:1652:b0:40f:df95:213e with SMTP id y18-20020a05622a165200b0040fdf95213emr7012422qtj.58.1691293194229; Sat, 05 Aug 2023 20:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293194; cv=none; d=google.com; s=arc-20160816; b=R5W6d6WAOZ01if6dZz56wukWm2RRLu/1g1JBtl+6aQ0ByjLL1kaNQ9Q1JPD+0g04Tb Qq2JMAYXwwvMi1xvxO+atfLREUC6EiZHccvioLstscKL4bSchwWR8v5p78e/WNscejMt bO+4QYpUlNYeGqMxrwQevsv22y51PLrSsa93c0+BJGHh0jVmHc9MaArlVPZksME0PUfB V/TQeSYbFW0Nj41c/PaUbposgKf1yoMBocj0Hk5DxExYQIKWne1r03SxQ+Sv/JXG+m1N DEpUHBf4ayncAD7ncnXWmy0/kScQnkobMczVHs5YHsBlwItAmaBUqyGjZDogkfTQPpCK mPrw== 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=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=No20SQ8QvAzbd72URHtHnGhvIVHOamTfWJ3mlogaLau1NW6COzlQWS08vv6IPVEGsj tIEn8O80yBUlxUMxbAQE/xhRP5LhCquVlisU9LktOKd3/mWxS3iXhwEcn75csktavg5J i20/mEMVY+hA0I+w8xUSJsET6HaVnc0v+jL8zEfcjMBwlSfiUoxGVpAb4r0XYeJSRONA 9Syp0S7Utv4KqgoFfZIlPubfeuAYgu/M6Gx7YSvxKk20UUJ+Bnpps26B1XFCMb36SY1u Cuowv0/s3hSzBmL+awXC+ghq9vepzIXYBU/cETr7dez5d/BufBA0iL8DPDYWWUkyxV7c 9miQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YhRjrWag; 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 s7-20020ac85cc7000000b00403b1d1599asi3444401qta.2.2023.08.05.20.39.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:39:54 -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=YhRjrWag; 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 1qSUa7-0003eY-Bz; Sat, 05 Aug 2023 23:37:27 -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 1qSUa5-0003dj-Rr for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:25 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa4-0007Xa-7n for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:25 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686ea67195dso2458964b3a.2 for ; Sat, 05 Aug 2023 20:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293043; x=1691897843; 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=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; b=YhRjrWagjbp13SDviaVcq4SUcJqN8fFgf1kOTYRE5xGpALC0SXlo4yKQhBZT4RwFhd vPuXFP/fLW0Od+P3O7xl0j+H/OD0k5QaFEHqWjsfTxdBuPmx5MDfS6m89RgZ70/Emvza jrxbhtQaaRsXqia8xXY/ai24XnVOMHfDWM53mDmcws8obe15lffBBp5TgBp0s2wpyRit JWOPuFL1yZXe0yctgcRjswZUbYOKsdkgnvugCUKi7lQveUV83nOt04+w+eIagYiPxlXo YXSbMTXQBg2MlryX+UGwpJhPYRS40bJAsbiOkOngTAnIDqm6GtEm3CQM6R4n9g+6fTsX nvAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293043; x=1691897843; 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=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; b=fi5BmKlbNCrd/AAWJLgTJVOLJ/jMD5xpHj/ljuyWykla7RkAdN4JKDn1sg5gDNeisN 8OK41czmgFtFXRUThlExUg+oBUSjPqwV0gIKh2Ar9YdrroxNFxaa+H8G2IBzL6GPJedX gf4SNsadkTWDOg/9EuqzJYwx4zTRwYpBZA+KCs6fEHE5/T4XLCxI+SXhAPzrXFmY2caR LIK/QdZF8/10AdUw/Z/Vl7p0fXenraV2U6Vq+tGqxh05UlIbkiv/0XiACAmnEhW74l6M dPeYAgwN+czME238tSX7aUflipUQgWHNl0CJLfITvDiizBO+KXEXZwHUdmmPk+0+hWDR 7f2g== X-Gm-Message-State: AOJu0Yw5Z4hPWquzQYwnYrdAxjuf2RYIRUlHTp5d6qhLmuaCh0gTeKNh 2nW7YJf8Mak/om/7tke0/iQ8Mp5FZSV3KgJmhps= X-Received: by 2002:a17:903:2587:b0:1b8:b564:b531 with SMTP id jb7-20020a170903258700b001b8b564b531mr5870990plb.60.1691293042786; Sat, 05 Aug 2023 20:37:22 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 08/24] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() Date: Sat, 5 Aug 2023 20:36:59 -0700 Message-Id: <20230806033715.244648-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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 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] Reviewed-by: Richard Henderson 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)