From patchwork Fri Mar 16 10:34:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 131915 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp566673ljb; Fri, 16 Mar 2018 03:35:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELtKpq8YZ1ygxVHNjKcanlYGuhW7Cpij2y7xtTo4sRHzo9sOnWQg7Pu+WFH4qgwuu0pfO/no X-Received: by 10.237.34.205 with SMTP id q13mr1759374qtc.113.1521196549736; Fri, 16 Mar 2018 03:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521196549; cv=none; d=google.com; s=arc-20160816; b=WhtbO0i9hyKR7UJRjGSdTMyzfvA6S5NsJm7kpMTtxwyrF/x//ZjNBczspKmitibyEs bZTldk5qB6RyWTITGrYM9uAb6wd7js1J3ispg3pWJDiMhZLae0pG9QDqcQg3NsYedQUV 5AecwOHiXgHN3b0vuj0pCpWPebOV1KTJtP4G9d12ZtDu+R1wA2JzKBHbRBF/Hhs76lSt BYgXShrV2hHhyr26AiIpKXXz7vuJ3o6hl5du1oxswS08U3HilFLzwEvB7dQJP2iPNVCf agVZX8F5SLAHfTRX4J8yAJRB4rJIm2e99A7fQhzmgveIE6lAcgzqq3vIGvd/mBFEFcT/ TIBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=aDVyUMJyRTHGyZGcSY8R9M13WBNWj7sJ5+W5PWQLQQw=; b=MXerKHlWKeGqfYGUCmDy+ar84VkUtO4xHw0h1qhgGi3rErjT5sXJ3u9vKGEszkbqMK o2TMfzxUGAvXMP0KaI8K0xUicpmcB8PZTKQ3UGHM5QAKTu7/nIurr29N9FYT5KLiPrMn eYQmwAdpsQWYBjPitbhEOIE77jP/knYJZujud4RBaXUxqWR8L0UvXVwt9Ae7JX9wIcvm pZnFowLGaIXfoQ6fLSj/E18HPI6fr8yfvhqtCzv8ADPz3E/G/ycVEpfbbwr+h5zfIf/l FmWhdATCrOfgvmugEGJv5Hn5Kv85vKLql1CRfmVHWIBAp/fr9GMXslwbuDTZYYficQQt baeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LwPZ9YyL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c56si3785924qtd.9.2018.03.16.03.35.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Mar 2018 03:35:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LwPZ9YyL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewmiC-0003hT-O3 for patch@linaro.org; Fri, 16 Mar 2018 06:35:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewmgu-0003Kz-8g for qemu-devel@nongnu.org; Fri, 16 Mar 2018 06:34:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewmgr-0006o7-71 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 06:34:28 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:39824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ewmgr-0006nu-0u for qemu-devel@nongnu.org; Fri, 16 Mar 2018 06:34:25 -0400 Received: by mail-pl0-x241.google.com with SMTP id k22-v6so4813131pls.6 for ; Fri, 16 Mar 2018 03:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=aDVyUMJyRTHGyZGcSY8R9M13WBNWj7sJ5+W5PWQLQQw=; b=LwPZ9YyLcnf1hXFMuRYzDX2fW3A+6ojLJlK/CbebFo+pgvYYJwW16RSOceNK9iKeUO CmjciQ+xMKooR37YOVe5ReqSQw6VbK9XxK9jbq2eD8JRU3dTiG8f4DtjGGRb3tjJRHFe TOzKwS9CK0dxnJJ2DF1TXRjcsAIDlv2mJaDDI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=aDVyUMJyRTHGyZGcSY8R9M13WBNWj7sJ5+W5PWQLQQw=; b=jUNvVItmAJMmW15GusjeVJFheWBP2NL74VMimamgOd1mAw7TD+WAJj1clWGzSWyv9K Hry9hDAYbOyVKPv+yNs+8NWr3gvoS9XcD/jMhH4Jdvx9IDhfVtEhK75vBG78NCPkSP9/ r4HEQsKf4UyUsYudBKtgCc7tYluNB49Svea1H4Lg1DpxKoqesjPIKn6s4i541F0Gr1TR 3SamCx8CQbqXjLiNMcVMHf0N7Ne5+djLiZHg0tLGJ3rshbQlZG8oSJ/wyTL0EnCE/p9x evdjrGFLMBSHdj6BBwPZE2b8xFtUWWNRUBrGFLEEd0iLuKPF2ePdEPO/PnqMCTKhdiQF eKLw== X-Gm-Message-State: AElRT7H07F4JLI3EuIE26BrcsLhUgS2NE6xV9oZXJs5pdi6hrN+D3iq+ x5vZkWSpvUsKfDdZln4cFpyekEeTDhE= X-Received: by 2002:a17:902:a702:: with SMTP id w2-v6mr1593961plq.340.1521196463136; Fri, 16 Mar 2018 03:34:23 -0700 (PDT) Received: from cloudburst.twiddle.net ([182.239.85.222]) by smtp.gmail.com with ESMTPSA id j83sm15767853pfj.18.2018.03.16.03.34.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Mar 2018 03:34:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 18:34:08 +0800 Message-Id: <20180316103408.22295-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::241 Subject: [Qemu-devel] [PATCH] linux-user: Allocate extra space for brk in PIE executable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, 1749393@bugs.launchpad.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Limit this to 16M; there does not appear to be any special support for this in the kernel itself, at least for i686. Fixes: https://bugs.launchpad.net/bugs/1749393 Signed-off-by: Richard Henderson --- Commentary in the launchpad bug suggests 128M gap for x86_64, but that's somewhat irrelevant to the given i686 test case. There's certainly nothing in the referenced kernel patch that does any more than we had been doing without this patch. I'm not sure what other limits on extra_size might we want to impose. With -R set to something less than the full address space we could easily wind up asking for more space than is available. r~ --- linux-user/elfload.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.14.3 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 9d10a5f592..e51d441fb9 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2055,7 +2055,15 @@ static void load_elf_image(const char *image_name, int image_fd, image is pre-linked, LOADDR will be non-zero. Since we do not supply MAP_FIXED here we'll use that address if and only if it remains available. */ - load_addr = target_mmap(loaddr, hiaddr - loaddr, PROT_NONE, + abi_ulong total_size = hiaddr - loaddr; + if (pinterp_name != NULL) { + /* This is the main executable. + * Hack to reserve some extra space for brk. + */ + abi_ulong extra_size = 16 * 1024 * 1024; + load_addr = mmap_find_vma(loaddr, total_size + extra_size); + } + load_addr = target_mmap(load_addr, total_size, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0); if (load_addr == -1) {