From patchwork Thu Aug 3 01:52:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709592 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354513ltf; Wed, 2 Aug 2023 18:56:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjN91/I361OTPdXrGwCsFjAQek8NUipLOj4+f1vctxgWFPg/akC/N08sAWYIksPZM5bJUp X-Received: by 2002:a05:620a:4483:b0:76c:c20f:2d10 with SMTP id x3-20020a05620a448300b0076cc20f2d10mr8630355qkp.61.1691027768057; Wed, 02 Aug 2023 18:56:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027768; cv=none; d=google.com; s=arc-20160816; b=yfxXhkSbxCJWowwsKkpLZRpUpEg2yU+4C7g8qkIVyc5B74BEcyv89znpFPZhss6HVF rhxx+lk8GKykQizPXf8eeWnKo2E0AY4W8oqW/5rpdvBVfNT8+5wfv1Bg3piDWP7UOllH ZRChK0TSQUiP4gSoU9lVywNHsCd5PFSK5MNWNx6SDJ2UPPeIXCKErVIAhsxbg/NpHt6+ VMfMlFrvQyazAQy4tiuDlW0sX2S57FzAVwSea4aWTmUAihtJ+7ck5riCk7putBHBcgET yo/WzI1SCIh+i7D5e1aLVtocWJ8HSFErhcTkZPtQW4bww6oW39xlnyTe0WKGSkOmN5PM M3+g== 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=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=01CaMZwMiE/K6Keh1cbDzFlRbmQSxrSsaWA0Cm1sTYxG9t5eJxigX6q7Quzu6CpBFY zSHWhsUXL4BwE0+IBRF8FwWV8V4S3VSy+xra0PmIrbaMAf1f6pEE5cpEM8/ns9M2bvSk B6MIMORSXRlT3LFy3vgOXtkyt4m7cWbhuWfr0tkWuogbaXcElT5vgZKaRi0jdqkH0Gpp +rIshV7B89V77EXV+89XdhoKqY5rpMZ9EGORQATVWdafvK2LjOImQ/qMSnJHTpwEJqDX GMYIR+FxTWFumqali+sZ1yy5TTIA8JUEuLQna0jmbw/VkiNCwppbgxWUxRL+HcnbG2PS 8asA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D2cL7cl0; 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 dp10-20020a05620a2b4a00b00765a5168fd0si9555540qkb.677.2023.08.02.18.56.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:56:08 -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=D2cL7cl0; 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 1qRNWc-0000fz-A3; Wed, 02 Aug 2023 21:53: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 1qRNWY-0000e8-OM for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:10 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWX-0000kI-2y for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:10 -0400 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3a37909a64eso325452b6e.1 for ; Wed, 02 Aug 2023 18:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027587; x=1691632387; 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=D2cL7cl0jhRcNMi7CBZSli4u5yGtIkTCqy1obOL+stzpF2Cs+q4l/IWa4yjzQlQpl6 /+hjOKr80bEPmjQldonmTc8sgOhqecCOM++37nL3wwgDJkxDxOO5wO4g7iJCH+dTZcls dmxevF81TRZSbs4Emd8vv7zq52/rrm+zaGP6dQjtT0DcezQmrF8O8NrSD+jiIKymghUz smlUgXG0Wb71h55k4iQQWx0I2m8FXOX7aowvE+Kf7Kv+fIYTwXeDSNTgsjFkdah+1TQc fbAyt3jKtm3UoWpFT6atKAwypMZ4Psu1YVoRkEqQWVbpX+/+eb9MymQR1mhrvjyOnxgd 70bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027587; x=1691632387; 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=PYEvokaME63J/nzTVYAz/3hJOyLlPC2KkWuF2ennXDgG7etuNEcygbTc2bGAgsfzZe PPXGBHg5ol32E5/n6oplyFfHSew6mFMayirB1fIe2qDGc3cVstCilSpp1KTwHqG2X0WB I+CIniVzEYgCsGrMSuo1YD6LkveLq8/P1MSadqAzOiTm1umLMLwzw6yf5VyRdq5VUHwV HjLCPFoYcwQznvJZK9aupgVGQRJpUSRMlqupwR0W/CjtmBGS4KzeOJ9nnkiz7Mah0/PK 7ujX37gb0rrndBsK6Dy+0oaXZCsDRJ7HMUVbvE9J7v/Dotz9hiLDHmBYtEYoHSTHWSZB Jy8A== X-Gm-Message-State: ABy/qLZ64tOE+HHhQeNMShAZ2Ps50J68U32PDUzjaxx1pGXsXED4wVoZ 5Rqb+EevFwF+aY6rfZNn+iyvdCtOsFTVy0h6VA4= X-Received: by 2002:a05:6358:708:b0:139:d277:354d with SMTP id e8-20020a056358070800b00139d277354dmr10597854rwj.22.1691027587468; Wed, 02 Aug 2023 18:53:07 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:b659:bbad:1a22:7ef9]) by smtp.gmail.com with ESMTPSA id s25-20020a63a319000000b005649cee408fsm157123pge.0.2023.08.02.18.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de, laurent@vivier.eu, akihiko.odaki@daynix.com, joel@jms.id.au Subject: [PATCH v7 04/14] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() Date: Wed, 2 Aug 2023 18:52:52 -0700 Message-Id: <20230803015302.407219-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803015302.407219-1-richard.henderson@linaro.org> References: <20230803015302.407219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x230.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)