From patchwork Thu Aug 3 01:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709584 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354260ltf; Wed, 2 Aug 2023 18:55:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHwcQI1cbMYRgbRk5hNYMvgiOuE6CxtM56CEWejMagqO7LBj/3OU5C6uUu2xDTZ4zyAAck X-Received: by 2002:ac8:7fc3:0:b0:403:9f48:7ce1 with SMTP id b3-20020ac87fc3000000b004039f487ce1mr23086941qtk.53.1691027702690; Wed, 02 Aug 2023 18:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027702; cv=none; d=google.com; s=arc-20160816; b=NVc4WBnOi+3F5yd6vyBijQbXTU6BnTCHwRnRtDorY4+zr6LdF8pO+B/IoFJGHZ//7x MDv8VKJL1X1tQ0ZX5Z+EHXpolNzdqpTfZRTLP0dNluGTyujc2keiJC/3qVtgTgD1PYvL WOEfyVpxfWRUTyv5RfigA0YEbPk363c6kebpGrke0UJqFtLQ7q3sNrrKznKIdQ4Ew2d4 vQFSu5gM/93VBZSGtrrFI64GHR1cjYfVQqgCuDCgYH7wT1yPCrjETBLd5NoxCsq7/hMs iovinax8ekyq3X+VYydFeXx94FRqg+f2voN4uQrrklYfHDigvmOQd5bDmBDy42bTvt0F fQww== 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=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=QLU2ZsoU8TUfYZh12C6dARliqhL1U3Y7uOfR1EPnfvCNTGon/rfqD2NzIAbJsPl8LS c91RDnZ14N+UKp2K0Rj7HmH3IgKmIMp8VzXyXpvsXIAInRX+WgGSJCQJB400eLDPR42c ZsTco9yNk0gaR4uEbjTMrpamwhCndL6h6uCLKqhftPTi+KQ/zRVG5LaCL6/Rb5qDngti CPzJvqVBtg39WBV3Is/0q4I9kfvCntCPEFuXheNUEqkNUHh03rVIaBf5DjIvZNJ+PbEO LoNCJ72r/+mb/lxbRigun7h+yW0ygdQPEK8dkzLQ71ZbZq/TmJ5Lz09ebi1rixzZprJx JxdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vBbIm4OM; 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 h15-20020ac8584f000000b004031c543b8esi9143835qth.734.2023.08.02.18.55.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:02 -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=vBbIm4OM; 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 1qRNWY-0000dr-Ay; Wed, 02 Aug 2023 21:53:10 -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 1qRNWW-0000dP-2b for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:08 -0400 Received: from mail-qk1-x72b.google.com ([2607:f8b0:4864:20::72b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWU-0000j3-Hj for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:07 -0400 Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-7656652da3cso29663985a.1 for ; Wed, 02 Aug 2023 18:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027585; x=1691632385; 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=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; b=vBbIm4OMvxNnQDlgaD4YReZqq86tCOIbKHBI+EadX6byJP4oV0k8Qya5a9MUk5cZe3 Xn7WtQ024EWTyHxFfxPWE6x1OEefbgS2zsBT3zNwWNQsLbF0Pi2JMTejX/7sZYqAHKVg sREv8uU6H2RrNIL6Spo/tGEZY0VM9E4Cc3iAOoItrwM2HrjChgTKZdd3WeF+v8m/VL+9 Cb7zFV9eQ9Ss2BOsWx7ia/2H5sJxz6OFGMpDpKHlVCc1dGntevwJMnAuAuI/jPhsKoYI wDbq7MyVDFMqjDlK7oagAD+Rtc1JY8NHUyhWjxb+UzXm8fjiFsY+ZvmtEsExTYwYsMiU VVoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027585; x=1691632385; 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=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; b=Sjp/82IxMeZ8wxqSgK3bRvLr+i9Qf569023b8YB70ZoU9uJKOqeL6/Cdk06qvBV6Xd rJdl1pFs6U1Xj47l6KXI5i3qZF5iE58J+FRalfVEGxmZY6GFuhRXMbFzpeBHq1ELKXCy GqN7U+XTO+j+Cqu3Fec6FW7PxNfUrhuCVZMBZtRE9nmnQL5enzp+aYxHcziEmgKBcni/ JaTkB+qDmXANScDIGeEF6ePVhoy44It2KKTlXBnJt4wrseATvGqZpt65defkvQ3lf30b zw7d4ZVL80m6eIQJoEkOdqcagwqXhOyXQz5z9AmxEFezgy3VlU8YCKaR9rpIdDHI5zS7 iFWw== X-Gm-Message-State: ABy/qLZ9/YOrEbHhynflPVYtE646AQ6QLj73K34LC+Nff8kR+l/K5Jwa Du5hsY3vin0qv/jEDOmZKvyTT2fWfOeqELcSaAk= X-Received: by 2002:a05:620a:4105:b0:76c:bb4d:97cf with SMTP id j5-20020a05620a410500b0076cbb4d97cfmr9543796qko.24.1691027584875; Wed, 02 Aug 2023 18:53:04 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:04 -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 01/14] linux-user: Unset MAP_FIXED_NOREPLACE for host Date: Wed, 2 Aug 2023 18:52:49 -0700 Message-Id: <20230803015302.407219-2-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::72b; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72b.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 Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because the address space is reserved with mmap. Replace it with MAP_FIXED in that case. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-2-akihiko.odaki@daynix.com> [rth: Expand inline commentary.] Signed-off-by: Richard Henderson --- linux-user/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a5dfb56545..a11c630a7b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno = EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno = EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something else. + * We have just checked that the guest address is not mapped + * within the guest, but need to replace the host reservation. + * + * Without reserved_va, despite the guest address check above, + * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite + * any host address mappings. + */ + if (reserved_va) { + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } /* From patchwork Thu Aug 3 01:52:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709579 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354119ltf; Wed, 2 Aug 2023 18:54:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlEOXdo2nC1JV410juzfFrxDrIH/KdPcW+ek13/e39/FFZO54M1KIqqgKlQ0OOJmE65kDEo6 X-Received: by 2002:a0c:e287:0:b0:63c:d763:77b4 with SMTP id r7-20020a0ce287000000b0063cd76377b4mr15230584qvl.8.1691027668185; Wed, 02 Aug 2023 18:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027668; cv=none; d=google.com; s=arc-20160816; b=oRc5L0cCWWiw8GM1EGioNHHAh1HleD/d7EsJODw6yJgERliVocyQtfDWz6WI3DYfGa DDOvVhbkAH64q0gvm6TyG1JBcdTb7asiKgzqe0YaOtalQvF4f6vTa1qP0vrnfw/Url4q IP/iIDTPGkPJ/tu5E7wwVrqaVq+LcSrVSzFy1rUnvDzW4Ypb4jirrEaRkZuznp4WIEri ksoFz+r87RXgQfLzqcgJRteIFRaYA9wOw3j56JkfepcnBASuoBtIwzmreDUrZ+zBW9T+ fWi5khgPvhj7wG8RKsOFjXqIDls5uHuKacHV8BgrgG6+P5PwNpQu9DIdcILLdngUN1F0 0SrA== 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=/eOGiWVqZ8Y4POmSjtXETDABSVmvc7JlojTPUk6j1vw=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=qlW7DTLzBA/WkBwcarm0v2mS5goh7p2fuoM1kECOhjlxgLEY5wj8fIsyJIESx0ghIQ zmtSWHxYFWqX2V5igOBx5BWjnq48SCufpTs2azGAG2Hb8qpTFVl29IRakUCNfnlTjCC8 tkmtho/DSolX6nt9jOEJJOhNYbuXqTiPbj1HpELNrU3H+VZMNg0BReSoEJBqIA5Kbuqi p2WHLV1dW6rR0gQZ254fb3CLChRBBqvsO9stroILN8MkYmwNQd+EqMKC78/ViPAGfhDu 68Req80zXZKo8f4tuegZFR/d2t35JZRXnMvj9nLLxY/FL/LxwR5lrGp6AqNlaarLgL1T dO8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iOvJMZoW; 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 g7-20020a37b607000000b0076cb9d1d455si3998770qkf.355.2023.08.02.18.54.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:54:28 -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=iOvJMZoW; 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 1qRNWY-0000eC-VQ; Wed, 02 Aug 2023 21:53:10 -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 1qRNWX-0000dZ-DZ for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:09 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWV-0000jb-DE for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:09 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-563f8e8a53dso222173a12.3 for ; Wed, 02 Aug 2023 18:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027586; x=1691632386; 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=/eOGiWVqZ8Y4POmSjtXETDABSVmvc7JlojTPUk6j1vw=; b=iOvJMZoWdwCGfePsK/gD0VKxJ+aJG3D0f0wBWW7Np+urrLTYrNdVjBPbHdxR3SpHSM uc9of+mgcJTnDmQ6XARMwP1rwfQQptvgEvNUvFzG6O1MHx7b/bYW+ppy8b2hBJYveiJX sC+F6RNFaR2rI306vX4aO89mIzZaauRRpRoZ7YJgkRTB8z/OrpeiaDoENbVi4ggN1ihb WHPgDgwfvCz5h9fgL5V2t8kOVA2YZipyDElVCrZ68UawhE9WJJGMoY7lEHlTxtQhKvpy +H6MI5RazYQyPLX1mOoFZSbZhQrwiq4AK4XHSQuDQGwHjhskj9z2PnHt1QFKwiastTpm CEMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027586; x=1691632386; 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=/eOGiWVqZ8Y4POmSjtXETDABSVmvc7JlojTPUk6j1vw=; b=DMm6zn6t4r/ONnBvCwsyOeDnhgV7ZIvZRujApuyLWj1BRobathK0U6mbjEJuI0t9cJ vGsefxibNKalwVdFtz/d9OEwx+TVg0XgOIe/3tTy83021csCkKoxxqZj8qR5btoaZHJw oCyaLzWr80nSUCQC3CWbtnArqWEwIbNO/8eqUsftM5JZs8usVppqMgJn5CAuTtV/BhgR /wMmoN+F4/w7Dhf+bqgv4FtTqY5+ahHXr+qJ7GnPPNE2k8pHxKCtrQLEHHrIvAXhN2oe 1wiebkV60zvx0S5i/Il0QjrY8k9SBvTm9GsGYAlZ7cFTh0diz2T2ElUz9yQC6wiqo0nU QQcg== X-Gm-Message-State: ABy/qLY/mZbt4ToEaLw4Rexs8gVCMxxOrZTzy3brW+fGue91kmNBQ6Xn MPnCbeT5luqA+8aPX44J8lxzD9BFtDyxWjfpcj8= X-Received: by 2002:a17:90a:bb81:b0:268:5f1a:ede1 with SMTP id v1-20020a17090abb8100b002685f1aede1mr14640604pjr.36.1691027585864; Wed, 02 Aug 2023 18:53:05 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:05 -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 02/14] linux-user: Fix MAP_FIXED_NOREPLACE on old kernels Date: Wed, 2 Aug 2023 18:52:50 -0700 Message-Id: <20230803015302.407219-3-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::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.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 The man page states: > Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE > flag will typically (upon detecting a collision with a preexisting > mapping) fall back to a “non-MAP_FIXED” type of behavior: they will > return an address that is different from the requested address. > Therefore, backward-compatible software should check the returned > address against the requested address. https://man7.org/linux/man-pages/man2/mmap.2.html Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-3-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/mmap.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a11c630a7b..90b3ef2140 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -263,7 +263,11 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, void *p = mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { + if (p != host_start) { + if (p != MAP_FAILED) { + munmap(p, qemu_host_page_size); + errno = EEXIST; + } return false; } prot_old = prot; @@ -687,17 +691,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_last) { - void *p; + void *p, *want_p; off_t offset1; + size_t len1; if (flags & MAP_ANONYMOUS) { offset1 = 0; } else { offset1 = offset + real_start - start; } - p = mmap(g2h_untagged(real_start), real_last - real_start + 1, - target_to_host_prot(target_prot), flags, fd, offset1); - if (p == MAP_FAILED) { + len1 = real_last - real_start + 1; + want_p = g2h_untagged(real_start); + + p = mmap(want_p, len1, target_to_host_prot(target_prot), + flags, fd, offset1); + if (p != want_p) { + if (p != MAP_FAILED) { + munmap(p, len1); + errno = EEXIST; + } goto fail; } passthrough_start = real_start; From patchwork Thu Aug 3 01:52:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709586 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354308ltf; Wed, 2 Aug 2023 18:55:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlFO2BI1XETN2fGjQBXNxLM0oynQx58URJIaqogOP1bZX1F2KLPKru+FS4CfR1lcGlYJh5Rg X-Received: by 2002:a05:620a:f88:b0:766:8b00:940b with SMTP id b8-20020a05620a0f8800b007668b00940bmr13568502qkn.48.1691027713934; Wed, 02 Aug 2023 18:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027713; cv=none; d=google.com; s=arc-20160816; b=AvH4/JYN9Ko1BR0TbUebqhOURPEKdJzpICkIeSXZCebjWprZEtE9PTsZn6Sdh9xh5+ 8eHnBTrh8HVBHFHbYbzaggQgeIDgQFLzOYhhNwEuTT0G+jFYC3aX64SvOQS+s9WHRn3U e58dqov7SBCplkdtC/gwIYF96LX3Nf1ZmfzVY187iZsYx8Hv5QHf/s5jutn0uv7/Vkr+ Acn7poHtQe49yrQGZKdMtgz+6cEKAkiROp7AipK2QtYcipk2rFGq+RAO7Fyj2yeLcdz+ ScJvkJDtNVO0a+e3n8e2nPNftEA4Zn2eqoj7WiGjIXF8YCafhIIxGumPeMek1/dfaNTj OByg== 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=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=VDDom1K5/r6uWLI/CTAUxzNjVoc6nCQ+HoA3+0JNVq3yLqyggLfqvuDzEdxLPzvPOj TMwG+Nwospl5e6FQiBssSj1Q96/zCJjSCjhsG5ShsRBKZVmQtCHfzvfjRl8tXBHwxIox a6GYs54bZHBNwv+aJ/rTyjiKzWgrBAJrAYO1MjkQMh/IYNQf26+cGPMOE6Bs8FVD9AlI CgHisbk2g+LIuBOg9itt/+Ux0Yg6eWJU51Y5caWpuvq/ws8sKzuL5O8LZWGBL/R6Azhg URwwt6BnnIA3MS8jLTwyQVxUOGpLR0mt9RUnqR0SnkhScU8ORzx3jLSAXaxkefWZrfA0 uZuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PUQl7ewo; 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 26-20020a05620a049a00b0076ca993daa5si5369121qkr.712.2023.08.02.18.55.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:13 -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=PUQl7ewo; 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 1qRNWa-0000f0-Nm; Wed, 02 Aug 2023 21:53:12 -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 1qRNWX-0000dd-KN for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:09 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWW-0000jp-0d for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:09 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3a741f46fadso329872b6e.0 for ; Wed, 02 Aug 2023 18:53:07 -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=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; b=PUQl7ewocdGUKClZUVQqG1B4IFNhSQEA0NkasIpsB6kJPWpaH80fOs3xAMzKkHzoT6 Otyt0gKRn+vayvSPtKXvW1lM6EvDLOYEznIwqsnPhRj9OOhwEe3TiqxLD3ZQQnkGRS2o lVtDZdBMzzy9AyEb4CoRq8uEHyx6eg6P4pqIJm7uEOANfPhV41rfCGD1ov5KHU4jTZhS ims5AeaQIHF1+O3vh150617dYI541mjraCiNh8sx/5PuH+zsFDdAmunufh2MYf7WLn1o T4apSRVru2PYQG9oqgmjZMcQwZYG7nR1oRBbLWMPrYfJDUILOUU+yJDRMnRQi+sBg3MG uXnA== 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=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; b=I/BlArIQ3++J/UqNHzHcN04+NrkyuQ+C6qgzMfXwcSH1eRcyan5UnstDVIQJwXZAgd XGgqCYxlTfKx52XOFi6C8sIMhAL+lmukstC7/FMqAea8H3X53lzWndY3r9KOP5hF0k/h U2GPP5Le7tU21tANMzlJlxvxGRl2PRo3MVXP0gz/HgQaywkVGCCnbn5YDKrRDNMHF/3b x/M/2bP3DZYU34s9yhmWNlyz2rYvqR77bKgVRX/z1biGihenl2fOqTyBygR6zIkdhBcR nsezNOSwJJG9vspDVCFbEkJlMb1XBVsxrWM6YRNfcdU6yOejaGDs0xXbIKZjQqm2R6TP 2ghw== X-Gm-Message-State: ABy/qLb8h9qQrX6bWVIRjq8O02KiTD+XQxfeVc7G4Ar4Uw+IQHDFK1U2 DEmTrGWSIcRPpR+Mpiz5ZMqR1XQ191DsnkaO44M= X-Received: by 2002:a54:4e11:0:b0:3a7:9d0:b71 with SMTP id a17-20020a544e11000000b003a709d00b71mr14241976oiy.53.1691027586704; Wed, 02 Aug 2023 18:53:06 -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:06 -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 03/14] linux-user: Do not call get_errno() in do_brk() Date: Wed, 2 Aug 2023 18:52:51 -0700 Message-Id: <20230803015302.407219-4-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::22a; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22a.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 Later the returned value is compared with -1, and negated errno is not expected. Fixes: 00faf08c95 ("linux-user: Don't use MAP_FIXED in do_brk()") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-4-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95727a816a..b9d2ec02f9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -862,9 +862,9 @@ abi_long do_brk(abi_ulong brk_val) */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0)); + mapped_addr = target_mmap(brk_page, new_alloc_size, + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, 0, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; 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) From patchwork Thu Aug 3 01:52:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709585 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354265ltf; Wed, 2 Aug 2023 18:55:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlGavPllXBZfYcxVAXV6xVO47Hs7de6cXYP2LQeQm7KKywB8dqZUz+yJAQDi+kxLHtQvtpPt X-Received: by 2002:ad4:5184:0:b0:626:80f:a05e with SMTP id b4-20020ad45184000000b00626080fa05emr18204373qvp.26.1691027705473; Wed, 02 Aug 2023 18:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027705; cv=none; d=google.com; s=arc-20160816; b=HdjmXQS+iVJK8bbKTc32L9DIStAqVHEMiXo92oyiihcxtSdkOpKT2PUgElrpMWQJ2m 0S6us9jQ0ahdiYIPhnagAxbstJ5bDSc99DZSmxLNoUT5ss/CO93Oa9piSLEKjIf5xDc5 vRQXh8YONuLwz4HThoijUa/ppC0NZzzHLQ3Gnc9ESr7L6SIQ2MHzf5kdw8vKdQXlUQO0 5Sab1kmsk68/oeaymgvFnPlFd+DA//BmxOhPSeG+DIVxwJUNdPSUq5Up3Gywck0Q5cCl 7UDgc5oa5dWQs0RdlE+KN80/J4q39ZNhxd5VL54wp4f6p2+ayPtuuFta2sp5wKT2kQ/p z1Tg== 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=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=TirB/rozRu7wubKpXYEJZtf9nh1Dv/jjXqUMi0kBm2b4rX6NUsC0VyHwoXT+mpIMG7 RSjZ12WR4IFER2A+ACFK1knIgdK0Ku/rD7oBnkxGvPA41e4IJsTWMs2Ul01idvW0TuHg apIvhlZ8P6g+OOLd5H8BDNXAcbkHoTRxFHD6RdPMCskVyd5pN2Dfd0tZ48UohOgwOt8x jprN+BpQtyLwBxIm6S5XWGjaxBDJ9gvhCWhYSYUdrcv/kmT+s6r2EtQOlAT2me2Pz6aL XsT3NNc7wYtXyuNLxEz2hLfjNBGDZx9t/FcVRXpO40x+lfYth4vGzm4Xytupka/8CtDD N8Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rCbGeD2c; 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 b14-20020a0cf04e000000b0063a2f8b6ce1si9259485qvl.270.2023.08.02.18.55.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:05 -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=rCbGeD2c; 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-0000gP-VM; 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 1qRNWZ-0000eY-FB for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:11 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWX-0000kj-Nh for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:11 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686c06b806cso297401b3a.2 for ; Wed, 02 Aug 2023 18:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027588; x=1691632388; 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=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; b=rCbGeD2c0E16GfrYdJuv+93Z3QI+nn23DdOSbwqRoiO9Ms3DCqp2WsHU99QzBBy5pW N/LRlt4Uaicx+IMlo1hm21OJORHK79hCuFEQMVXGp5z5Yx7RSxeL+qvkRY7W2UcxQSI8 acYUfW+d9fez7BMwlHPDr6sbEILvxoe7NExXux/727zc83ezpVPix6Xm+NqZsYEs8l6A sSs9egYqAKWK8USdLXD1YEzQa7H/em2WMdcuyqmwdbbfIwpNuDkI6Qa5iBkMoaFgg/Sd Iiia6ONsaJ5BeIljB5wvHbgxSvvfOfHEDyNqKqr3G2M3OkpoR2nHVzVBl6w+WHCtaVB2 fDwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027588; x=1691632388; 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=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; b=BQqOUIwFDkIZiH9XDCsJigwWMhz6fJfgDd6CiuE0k1ue+H0yZm7w2MdXtD1uzfMofC W7r9kzP8YGxKq2ybKY19Jc2f/ie5Foovy1dFIWiiKIi0vpXFRO6/Xy1cg9tgJ3l6ShgW Y6rfvU41fM3JY844eGa+9jmq1TcEwDcD3NjFaMlcm5G7srHrbIQGrB/1ZTdyuox2vsHk TcRRALn++KlHgpNu7AoHMRGs0v7+HvkzK/goLXT9zqrmwLCNu5QccfsbE1m79WvT9011 CXmZ90VjQwkDi5xBLpgfD1Bvnf/I6rIdrrvUHItbnP8uGM5+CQ+oQpdGe/Rhk01l46pt 5f4w== X-Gm-Message-State: ABy/qLYL+MrkTXhqbLdObsyQzAcwG3xk8rV+ZbkArJ42ulVAdJj+3VWY CfEd9VZx3/2V5TyBSpmNfyrQn8aY6FJ9ugAiYlM= X-Received: by 2002:a05:6a00:2e06:b0:66d:263f:d923 with SMTP id fc6-20020a056a002e0600b0066d263fd923mr20213091pfb.20.1691027588220; Wed, 02 Aug 2023 18:53:08 -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.07 (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 05/14] linux-user: Do nothing if too small brk is specified Date: Wed, 2 Aug 2023 18:52:53 -0700 Message-Id: <20230803015302.407219-6-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::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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 Linux 6.4.7 does nothing when a value smaller than the initial brk is specified. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-6-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f64024273f..e1436a3962 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -820,14 +820,14 @@ abi_long do_brk(abi_ulong brk_val) /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged or zero */ - if (!brk_val || brk_val == target_brk) { + /* return old brk value if brk_val unchanged */ + if (brk_val == target_brk) { return target_brk; } /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { - brk_val = initial_target_brk; + return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); From patchwork Thu Aug 3 01:52:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709590 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354417ltf; Wed, 2 Aug 2023 18:55:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQZxDZT2TWXE7PcM+Mt/9R5Q+WjU6u6DmxQOsTe066CJbsFOzLogQomw/vFLw35lhAIi2a X-Received: by 2002:a05:622a:180e:b0:40f:e15e:8f7f with SMTP id t14-20020a05622a180e00b0040fe15e8f7fmr3086135qtc.53.1691027739993; Wed, 02 Aug 2023 18:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027739; cv=none; d=google.com; s=arc-20160816; b=PpzTyIw4rU+vlbGth3Woxr2ZPUR+FGTbNsg0Khxh7Kwn+wowPwGCzLaiVrwdIafD5q 2J5uFJDUUbZyFr5JpudjrXXuyBl3XPkoVUskoAQFyLHSbk6UUUHq88Iubv3YNlK6+9Qd gpu7pj/f7Z5lBgoSdIxS/I9tIfEB4di4ut30qjabDskOBVi8wnxoRA0kk3qA+nDJ9UQu Q0ZC9njTeBZQuNJ8VRA4bvXsi5n1ILENstw3K0ltxlQaL9eH+wFeeUrR2grfv7+lD+PE Yexv2VZtbY07vOArO+87SlwXkMZLNacqRMIILDJIuHT06756OAQfo1aaG0/avch2zS2X XQEg== 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=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=LFTRD2jEEzQU3swVPWa4vy5FivI/2M/1XmxJSRympIUcK6vaEW22MUHTWfHy70PLk/ bGTrSYuW5hr7JWteUIHJo6+BtI9SvkARU0D6a1jJmEGEHek4l+7H/hwgEt28hiLrLgcZ MlSJf1Xv3ZONlElIWhxBXJDtZwXuHMVSd3es0MvI1eF0g1t1vSeU4n2tjDtwq4zdvThN QmGAQLprzlkqcL3R0Vd8vm/hwpAT19NMJTB0tFH9Ja841rbIU3/q+darT99755ZcrhAY QVehvlkccR8nn459O6bVf0drc1L0nggmj+MBtjDNi5TGbnofdss/I1x/xUdfP3TCqiOg yUSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DRLz2fiU; 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 n1-20020ac85b41000000b00403a8dc3c5esi575876qtw.390.2023.08.02.18.55.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:39 -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=DRLz2fiU; 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 1qRNWd-0000gR-9v; Wed, 02 Aug 2023 21:53:15 -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 1qRNWa-0000fC-RD for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:12 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWY-0000lU-HR for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:12 -0400 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3a5ac8717c6so319587b6e.2 for ; Wed, 02 Aug 2023 18:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027589; x=1691632389; 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=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; b=DRLz2fiUfkvPI1zo0oGor91BpNa8cPoJaYsBO8OJXiLyMltIrOkacwpUg/88tnWEag LXERiQtee/WWkVjp/7JMnkhmIPizsgV2C90FyuU4/JiMjEZjY1I5pcVzcejB9QRhO2uG 4ZVINfg7wXwnyf+cazeJJs76NVkH9BCEC/c65w0YTOHMTulwwD3KNeOZ7oMvcE1l9/Sl h2dUMjod1Nd9MSnd31iPpa1kXPCe6Afrnu1GFMTzq/qCxjiESbdTvdn1sfQwFKFMFxmN RuKw5ydFyTQi/8hI508hBkzu9/c4fVJWHTV0w6IC7xNtiFYjuBZb5/ss37W+lwvDvA1v ehDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027589; x=1691632389; 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=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; b=RVIvhhj7+ypI8PbCIkiV5lvZuHw0VnIIQHOQCD+grsD96BVwm9dlP8mPf5igXy1tOK WiADrXu85Ak5CRKFIpuRgsizWWeZXAphfNAFSYC/LUE/85xIcY0dYf1lcPm2pZ31ddff aNbsB2AilULGJhZ9DNxXxy5fUcZTQX8Mpx94a0CrVlvGcVzMM5MBaMufyeMq5E6YqJNV lvPpckjahJKC1fQmIl8608P4SSfPeJh1xoCNOHR1JnJX61UJAzRj+D2EUwjriZZxB6Hc aj1W30hh5wxb3aOm3DTdpG+OiZJBvEQdINzlW2gNk+2dredDcCuLii4u5XYpCmFXJ4ox PoSQ== X-Gm-Message-State: ABy/qLZ2//4xXmDbYVNArnw76JWbawnHw2+wDgnWt6O5AuJdpGj4i9Fz 5DGNfhwxaYruFnwAwSF2qDBs6997qmaggB1w/OM= X-Received: by 2002:a05:6358:5284:b0:135:46d9:12f7 with SMTP id g4-20020a056358528400b0013546d912f7mr8794992rwa.26.1691027589269; Wed, 02 Aug 2023 18:53:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:08 -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 06/14] linux-user: Do not align brk with host page size Date: Wed, 2 Aug 2023 18:52:54 -0700 Message-Id: <20230803015302.407219-7-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::22e; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22e.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 do_brk() minimizes calls into target_mmap() by aligning the address with host page size, which is potentially larger than the target page size. However, the current implementation of this optimization has two bugs: - The start of brk is rounded up with the host page size while brk advertises an address aligned with the target page size as the beginning of brk. This makes the beginning of brk unmapped. - Content clearing after mapping is flawed. The size to clear is specified as HOST_PAGE_ALIGN(brk_page) - brk_page, but brk_page is aligned with the host page size so it is always zero. This optimization actually has no practical benefit. It makes difference when brk() is called multiple times with values in a range of the host page size. However, sophisticated memory allocators try to avoid to make such frequent brk() calls. For example, glibc 2.37 calls brk() to shrink the heap only when there is a room more than 128 KiB. It is rare to have a page size larger than 128 KiB if it happens. Let's remove the optimization to fix the bugs and make the code simpler. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1616 Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-7-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++-- linux-user/syscall.c | 54 ++++++++++---------------------------------- 2 files changed, 14 insertions(+), 44 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 861ec07abc..2aee2298ec 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3678,8 +3678,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * to mmap pages in this space. */ if (info->reserve_brk) { - abi_ulong start_brk = HOST_PAGE_ALIGN(info->brk); - abi_ulong end_brk = HOST_PAGE_ALIGN(info->brk + info->reserve_brk); + abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); + abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); target_munmap(start_brk, end_brk - start_brk); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e1436a3962..7c2c2f6e2f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -802,81 +802,51 @@ static inline int host_to_target_sock_type(int host_type) } static abi_ulong target_brk, initial_target_brk; -static abi_ulong brk_page; void target_set_brk(abi_ulong new_brk) { target_brk = TARGET_PAGE_ALIGN(new_brk); initial_target_brk = target_brk; - brk_page = HOST_PAGE_ALIGN(target_brk); } /* do_brk() must return target values and target errnos. */ abi_long do_brk(abi_ulong brk_val) { abi_long mapped_addr; - abi_ulong new_alloc_size; - abi_ulong new_brk, new_host_brk_page; + abi_ulong new_brk; + abi_ulong old_brk; /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged */ - if (brk_val == target_brk) { - return target_brk; - } - /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); - new_host_brk_page = HOST_PAGE_ALIGN(brk_val); + old_brk = TARGET_PAGE_ALIGN(target_brk); - /* brk_val and old target_brk might be on the same page */ - if (new_brk == TARGET_PAGE_ALIGN(target_brk)) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); + /* new and old target_brk might be on the same page */ + if (new_brk == old_brk) { target_brk = brk_val; return target_brk; } /* Release heap if necesary */ - if (new_brk < target_brk) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); - - /* free unused host pages and set new brk_page */ - target_munmap(new_host_brk_page, brk_page - new_host_brk_page); - brk_page = new_host_brk_page; + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); target_brk = brk_val; return target_brk; } - 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_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, - -1, 0); - } else { - new_alloc_size = 0; - mapped_addr = brk_page; - } - - if (mapped_addr == brk_page) { - /* Heap contents are initialized to zero, as for anonymous - * mapped pages. Technically the new pages are already - * initialized to zero since they *are* anonymous mapped - * pages, however we have to take care with the contents that - * come from the remaining part of the previous page: it may - * contains garbage data due to a previous heap usage (grown - * then shrunken). */ - memset(g2h_untagged(brk_page), 0, HOST_PAGE_ALIGN(brk_page) - brk_page); + mapped_addr = target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); + if (mapped_addr == old_brk) { target_brk = brk_val; - brk_page = new_host_brk_page; return target_brk; } From patchwork Thu Aug 3 01:52:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709587 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354309ltf; Wed, 2 Aug 2023 18:55:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlEI5xpYQFUKCxlAYLoIDoMcxSUSKRqSIzJKzYhd1PoVXgWQ8MgM1qwMFuaNJ4Tb0gVGxyH/ X-Received: by 2002:a05:622a:242:b0:405:379a:d98b with SMTP id c2-20020a05622a024200b00405379ad98bmr23708274qtx.8.1691027714037; Wed, 02 Aug 2023 18:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027714; cv=none; d=google.com; s=arc-20160816; b=iLYWJJlKSaWt2dYwsaQd3CGoqSnr/Gm8rs7Ko2pp8isVFgGo7NJ+yDbk5hA3fZ6IZm mKaIXYWnI3uHDNTQQKaas1c3U7BHvJHKix1jh3JSqcfxMsocjquY4FkMLLS1w1RX2Img /NPrTEDz2+TtsezRYlkKNlWHrVQ5Q4iPPAjyJGIwyD/cCxPazbH1i3gwH4fD2MUbnAia 5Qg6AM7CyZrsSQj3GQuBqY9/KFvM1rQehCVmBPJFGurC2v9fp1vAT+QBTLaP8kHXeLhr JrG28OGpAgCUrbShc0QQ+FH/DFGia2JeJNqjVryMOaF+t9EVUTQjtAmlKbHnrt+6lytr imSQ== 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=S4pOOuQWmq0xrR9pkY2S2VlYgAJ/fJTzo6NDmQNEUSw=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=GuKZjMZIT1TtLbP6ivohu2vqzI3yqymcueiKPEqoeLpoXKJ59qVCmpt6DeKkJ76nK5 Es+BuPpcRm/8Sre0WaXw1YymMFt47GQinGZ410qtdN2BG8NUlXh9dArQ7DdNllm1tnz+ UCItiR5WHmtJMu+Ok0WgnmOV4uYD2XLZQsl++zzSxgifASEiqIcRV6YSzkG4bplXsRgG t3ozHY9zklv5kZmlJDEk3NOaTZeg8cklK+bywyaBDzT8vpl7V+sNE7GyJzYFuXS+w52p CxMleHVsE+7B1dXvou6N+mOMYbjl4bKFAWBHPalaUR8lOS8bLAJhBlhqifcQM9PMcojb spAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=paj9PCta; 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 13-20020ac8590d000000b00409e2477114si7270723qty.626.2023.08.02.18.55.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:14 -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=paj9PCta; 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-0000gN-OJ; 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 1qRNWa-0000fD-Tg for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:12 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWZ-0000lq-Cf for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:12 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3a3373211a1so325196b6e.0 for ; Wed, 02 Aug 2023 18:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027590; x=1691632390; 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=S4pOOuQWmq0xrR9pkY2S2VlYgAJ/fJTzo6NDmQNEUSw=; b=paj9PCtabNua4Z7mbz2qjg1N20UIQkHljBfsF+nI96n+IXbzIm3j6XzPQJWrQ6S26z BpIDq+4m5xcb1HEeppERSG/80azNbA5FYnRyD0ehdvFbSRu92IfGD9TrW4Iudgmyo0Ar v+x0TXl16I5aI2xlHIczWmg1argyVipdNXaxmXlgMl/sSH35Xlta7BDWLjeFAy/uBm9T dGxCK7xxFOzP/syw7zvXgQh4ZrWRLLnb1MGyIjZOzqnsc8CMCFFflTKmWwDVGu3ktjue jpeNiFwzSd8LkyDF0F/wasrHKY2KVEWJc0Co1mdg/dyrMCVl5T8WDIV1xwuzg5DLub6P 9SNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027590; x=1691632390; 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=S4pOOuQWmq0xrR9pkY2S2VlYgAJ/fJTzo6NDmQNEUSw=; b=WxDHWZZk8qnUDJHJvToCLR7rDunEZYdhs2wV6pTaqbV7B1EtlLFvBx6udriOiDlbwS 4+W/QMLmpsrTSCy2XAo5RaAuqwM6dtjXnITLztF1CClts35/cNbW1YC4qNXA7KF4aVnS caOKSTNuDQPJiv3cXCIfiqdjL3j3zwGXZL/36TX9zqrP1OMp9z2WuPoyN74raA5z9GqE Hgja3q88WR7AoX6Mf0O6bVd6hUVg1yayBYKQTd/FHz3JkyS573I1YaXEYLvsIxDXhRf4 vsVCvHTkC8PXS3KUEt70XnuohPgPafbI0uu6g/3pC49Rdxu2TbGLYTOezZAdtFWBYbBz Fx5g== X-Gm-Message-State: ABy/qLapMyf89sO/nkgOW35Gj4Jbqf1l0GdLrvzs8dnxdlh7NjAmBJyB d+L75maXROYYbZmgHho0lOYBDtV7ZHjotIdN1pk= X-Received: by 2002:a05:6358:7212:b0:135:4003:7849 with SMTP id h18-20020a056358721200b0013540037849mr11639993rwa.4.1691027590186; Wed, 02 Aug 2023 18:53:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:09 -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 07/14] linux-user: Remove last_brk Date: Wed, 2 Aug 2023 18:52:55 -0700 Message-Id: <20230803015302.407219-8-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::234; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x234.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 This variable is unused. Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 1 - linux-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 3fc986f92f..7265c2c116 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -26,7 +26,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 90b3ef2140..eb04fab8ab 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -314,8 +314,6 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated * a chunk of guest address space. From patchwork Thu Aug 3 01:52:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709593 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354533ltf; Wed, 2 Aug 2023 18:56:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlE/q+0Nna0qNDNDXknu8WGenlSntp48qaNIbLN5535t6rTQwVG7pP0N5cishIvNhmMhSQkv X-Received: by 2002:ac8:5845:0:b0:403:f659:d716 with SMTP id h5-20020ac85845000000b00403f659d716mr25791268qth.63.1691027772067; Wed, 02 Aug 2023 18:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027772; cv=none; d=google.com; s=arc-20160816; b=p3rhZHtfysIDTlYY2KPD/RmUlck21WvoFPQ7Q53XXX2MyBQWMVl0nrRzImeQdpNxXM emTPWnoRnGEra5u1MsSATnHgARjLjW4FawdyUR2H3uDqfv9zhj1Nyo4j3CcWGutYcD/u VoaTEuewSRKSHvKybyfttigTm1JPGGbLr9aVDto7fcuyufc+vaHoOVdeUFfyANIWR3Tc fOOEfTC0p0juWL+YsD8XD6bLA7kS8ERioB/co308BtzYawPKhOQ0oW1r+2EcMFEEo7jQ oPGWbDAn0km3NS44MpK4vaPuJ+L8pdwhNu4Q0kKjzZNMU7iZzsAtikRN7dAUznnWvUm0 0zvQ== 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=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=aKsIvoHcS89JfOrr2Aoji/2q4xnyTV+eh7tExold10lCTB3Q2o2f5F2GNcywnUqyo0 /3dGhLpDD4A+SeOyaTReo1z1a+eyVOCQbNcFhkXaLZEn+BifRqCOW1llGblWY09XYaG5 vNEB9BiOu0GL9/5c96QC+iRX035MaRsxuKNKFKjdzbMP4gBL5WulpoUKLdU8oM0xS13+ X5DelZrWFlT/nnvrP4HneP/R4wOnxpvZyUSDpBWOLBK8JZ0iga2pUbhgKSXvQdWatKlE xzCYW/IzUvZNv70GpIb094/dRiVgo6PE4McjuNh/PA21Kj8jXVQUFrCIetEBgY+b3/EE Ysdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QjOBdNPw; 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 c11-20020ac85a8b000000b0040fe13367c8si1234282qtc.243.2023.08.02.18.56.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:56:12 -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=QjOBdNPw; 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 1qRNWd-0000hB-UA; Wed, 02 Aug 2023 21:53:15 -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 1qRNWc-0000fr-47 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:14 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWa-0000mE-JR for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:13 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-686be28e1a8so312763b3a.0 for ; Wed, 02 Aug 2023 18:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027591; x=1691632391; 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=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; b=QjOBdNPw59KVzwvVESUSqAtAEJY+f2XN7nDsw0p00A1mdtaG5npTrnCNALq6hXtvL4 3NM5QSgPkP/XOr4N44Glun5KrGgncc0/zXOYiYITpYCV/mUCcEiZbyxiUSoKMg9atB0t 2EIyL94PfxhpFP4Q6SD86MPwFdlxVUQVacq3XI5Y+mZCpG45AmBv5BmZinMIuDQJaEDQ S+8CUh+QoXdwpS/AVxLZDwGRw8r/YB0fpn0Boorb9zOjl/mNuh6ygJ52rXSXsPy3s3QZ TRiXumLr+3ePBtgUj5szmQiN0D4AZqnEK6HnvmDSwe7xZC+a0fjwxD2vajF/LrDo1T8d KFMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027591; x=1691632391; 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=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; b=DED1s+xt7bJzYqEEQ+WndlmLTVNiINkqHR0u/Cg5HSZFN2wpG2uPzP7YiaETNbnWJs WYqH+sRZ1hp07qYzP2c3HDbP+kccMoE5hDQ9eliB9BALz1+pgh8lE260xZhPyY5VUjuB mIvH/3UxZKnk5H6owMCZTx3DLs9gXgcnG6VUW2sqLqhEbyjlj6gazQjlXPl+zFqzx8Sm Eq5g9L4MSfZKu2mLqadxB7M3eU2xmKhgUrN1kPc8pSPFg7Peb8cYpEv8exrMd+FXO+Kc qzsb5OuW+H8UL59D9jJ/TCa7fy5wAWr3ftdw4g32A0LHcPfzFXDn8T9JMTdoN/koyR7a XVHw== X-Gm-Message-State: ABy/qLaZXM25Rgk7vNKf1bKhJRkmuZ9WHVLLj+1VkNRy9V+si6RlmS9b qdJi2ktpPmvPjv3JvBfFIY15oZ5Fo+qP9g87Kyk= X-Received: by 2002:a05:6a20:1615:b0:137:53d1:3e2 with SMTP id l21-20020a056a20161500b0013753d103e2mr19745119pzj.41.1691027590892; Wed, 02 Aug 2023 18:53:10 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:10 -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 08/14] bsd-user: Remove last_brk Date: Wed, 2 Aug 2023 18:52:56 -0700 Message-Id: <20230803015302.407219-9-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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 This variable is unused. Signed-off-by: Richard Henderson --- bsd-user/qemu.h | 1 - bsd-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index edf9602f9b..8f2d6a3c78 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -232,7 +232,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); void TSA_NO_TSA mmap_fork_start(void); diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index b62a69bd07..8e148a2ea3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -214,8 +214,6 @@ static int mmap_frag(abi_ulong real_start, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated a chunk of guest * address space. From patchwork Thu Aug 3 01:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709591 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354461ltf; Wed, 2 Aug 2023 18:55:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHyt5Im/d1D9Q4gwbOnU7FRW9xMhzE/MzEsncIRbfnOHCVMBr32zKnA3LFxXU4zhtkL+DCh X-Received: by 2002:a05:620a:1a1f:b0:76c:e027:2c1f with SMTP id bk31-20020a05620a1a1f00b0076ce0272c1fmr489274qkb.14.1691027754626; Wed, 02 Aug 2023 18:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027754; cv=none; d=google.com; s=arc-20160816; b=gpXUGwm8NiaUbqxyJu/E+nXoJvL8off5sukdkF5ZMmxXUuw7MXw+662VKkv1vGuEF9 7zZvFFId7DzqPR1K+ja6XlbXtUYuPIFer5ZRaKVnb4vwm6HRhVzJRMUy+iePfKzkrBKO +qCdFGUrCNIf9fk6eNmrUScbm/OEd74ncCqIVG2lOGOZ6mNh2/eCTumQRzN3QQ3SyolV RutrQxJ6nNrbm7uAm1p3BHZDujzRXTEhEEl6q3ZODxqiF66lOnpHBDeLYOqX5Yvhw9PN b0Pu+fEyAiEhZrgFekyrac83Csx8Fc0LmjiHUoVpcHGVZabnC+pFM0io/2sa3dAJ+PMv at/A== 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=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=J1FH1zdYJjFFvRyOnXX2YGY1J1amvvKPaNlAwHC9DnD1x/X1595QNIP9aeSRrhjsoQ 4Xi5+0DXn/l1kDVuGsWZu+EYO2tEJMReRteEPNgKcgcvt/ENtd5k5CzCvvykNFa4uxiz ucyq61zQJtpBldfgo43stbtSnevUqyIxhrrR51CwPdM3JkUJCc7Tlt2LoaIqEXuCMbKz xlsSYNk5xAZalyt/iUd9RT+awFcK2h+lxziTy8Rc04K6FZeiu3EU9gwJ0txSI75VZrf8 gN5IFRLp6CvVPFHWJUqNVDTrq3wKYU2aAY8+ig5j+1LtJ8XD7kSuSKLVyCAy954NblXt R96w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h6AXkEcX; 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 h12-20020ac8584c000000b00406848f568dsi9703687qth.671.2023.08.02.18.55.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55: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=h6AXkEcX; 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 1qRNWe-0000hG-FV; Wed, 02 Aug 2023 21:53:16 -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 1qRNWc-0000gE-ES for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:14 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWa-0000mf-Na for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:14 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3a5ad4477a7so316351b6e.1 for ; Wed, 02 Aug 2023 18:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027591; x=1691632391; 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=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; b=h6AXkEcXy7q7Gfjm4SNKw3qfW/GGsR9sEiJZ+T5/0Xswp18ItRzQerWj6Nqh93quF+ vfVm9jQm2XBmrOTarB35619JSQfot6YxNGNrMDhOrvX/fzDmE35+EIpC5/iAa9AJNbuT 4nHC9T+RGEXZbOYcQOW2pYnc/uZB3nXEfyYryg6k3dFYB0d+ji94xkhGYni426WEWZXF 9NxouIJttx+E1Uc2pqXZMDljCkQx1mgB+0bBygyUP+HM8Rqvyao6M/EWE6sVzE+prQX5 G69F1z+Jq6VnKcJF2+vf++wDLAEkmXj8u+plTK7XVnDNWxvz3SE2FEmIIj8mL9QqlSs5 xbcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027591; x=1691632391; 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=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; b=Da4XLQbmvQKNP77nSUyAfa6dxvnTOCebcA8faef3dHFywkw5Zjqo16N8L1HMh5Yykw 9mVvI48M0tybzT1wqYnos9JqNVbZxs9HF84brJxdF2gvtdkuOysAWanAsWXVSMda77ak abAVUVL40Pp4UOQ7o8lH8mSQXxMRwZTmHr6SbIa8/ayTweFSkVF0YCrtWH1mHGt1y+X3 0eWJMYKi+2El93hIEJ80rTdgfbSpsI1VVfLT5ihMWz73veOsAf1g+IgSKKcDZqJp3eIo SAm1u33TvZ4Msn2X8fz92hGBJrpTFTh09TcLg0jeHdf1VrTyC+EQaSH77JCiCdMPK+F3 kGfg== X-Gm-Message-State: ABy/qLZKggRfaTasEjcJ+pL67kWCZTl54ztauU8GdX44o4GwUPpqM9iv GpwcXhd4mA+JLtuuW6Fd6Cy5CiHJM0am97JJs/g= X-Received: by 2002:a05:6808:93:b0:3a7:5075:b0b8 with SMTP id s19-20020a056808009300b003a75075b0b8mr5699447oic.4.1691027591680; Wed, 02 Aug 2023 18:53:11 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:11 -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 09/14] linux-user: Adjust task_unmapped_base for reserved_va Date: Wed, 2 Aug 2023 18:52:57 -0700 Message-Id: <20230803015302.407219-10-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::22a; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22a.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 Ensure that the chosen values for mmap_next_start and task_unmapped_base are within the guest address space. Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 18 +++++++++++++++++- linux-user/main.c | 26 ++++++++++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..fd456e024e 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,23 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H +#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 +#ifdef TARGET_AARCH64 +# define TASK_UNMAPPED_BASE 0x5500000000 +#else +# define TASK_UNMAPPED_BASE (1ul << 38) +#endif +#else +#ifdef TARGET_HPPA +# define TASK_UNMAPPED_BASE 0xfa000000 +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +#endif + +extern abi_ulong task_unmapped_base; +extern abi_ulong mmap_next_start; + int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset); @@ -26,7 +43,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..c207b783d5 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -821,6 +821,32 @@ int main(int argc, char **argv, char **envp) reserved_va = max_reserved_va; } + /* + * Promote X and Y to a common type and compare. + * ??? Perhaps better to locally disable -Werror=type-limits. + */ +#define LESS(X, Y) ((1 ? X : Y) < (1 ? Y : X)) + + /* + * Select an initial value for task_unmapped_base that is in range. + */ + if (reserved_va) { + if (LESS(TASK_UNMAPPED_BASE, reserved_va)) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base = TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (LESS(TASK_UNMAPPED_BASE, UINTPTR_MAX)) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base = 0x10000000; + } + mmap_next_start = task_unmapped_base; + +#undef LESS + { Error *err = NULL; if (seed_optarg != NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index eb04fab8ab..84436d45c8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -299,20 +299,8 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, return true; } -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif -abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; /* * Subroutine of mmap_find_vma, used when we have pre-allocated @@ -391,7 +379,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) if ((addr & (align - 1)) == 0) { /* Success. */ - if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) { + if (start == mmap_next_start && addr >= task_unmapped_base) { mmap_next_start = addr + size; } return addr; From patchwork Thu Aug 3 01:52:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709582 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354169ltf; Wed, 2 Aug 2023 18:54:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlEz9j3K/wnYIixeSYcC4GRGA1GJ+1ltO6kmi5DlyC+wd1AEt6STamVC+HYeX1J23afHsCKe X-Received: by 2002:ac8:7f4a:0:b0:40f:d5df:381b with SMTP id g10-20020ac87f4a000000b0040fd5df381bmr7703190qtk.5.1691027677931; Wed, 02 Aug 2023 18:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027677; cv=none; d=google.com; s=arc-20160816; b=OucEZFiWopBI4zq7BwdnqEbQr0eJymd34gkXKZT/fdzHNDoenXSjYIDO+2WmcLODvo Nd2trguUpd26bg/XRqz9M57tbkd4swHKv3peENxvVXgkqoFgES3u8mZROqpBN09ZXVtm NtNwW5i0DWKV8LW5TUH/IM5xQu/Rv/N0N66YmaD96kEJYFXZFY0jvl1krB4WCa6jppcp HFb6qn+kW11t8YLlD76cUHeHksIli0QMV5JRpAtV+tUys9h4z88WIremYTnNDituAiQt bV4mPZgQpiSIWJMVvGBZIktPvmDCGCDqylqIfKr9wreFg6JpXm4SsxdiXTvjDG27rEaQ ocrA== 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=0g0cVRguWw0x7PzF0MB98ECj4OyJgpksU9rKzq3J1ck=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=gL0AX/oFzB1+6QMsyUVOoqWOrYFG9MAi1tC4ezp48N6LuFbKxg2w4wODbBYFBo6zv+ sYB1gC5y8gqj/dIGJ0225Pw3BPuhhE8xdnFgT4nmEUjwVcdtiXc0nzookHVp6BpQBj+v Y5orq8jrOnAass+uzH7VvRA+3qxJllvbrPhGsDEIkAd2ePBFdL2wg8MD54SeAe1ZOYn5 V4GnnnlkTueM8w/LuW38PluylkLPrVbHDp4mXnYgubuE88uwnwmrHS2VvgUn/xkXBmeB TW8BoU9BvL8yN5eR9xRH6uzqE9a3Mysyu/GVtePqmeoO9eAo3oNma8iXLhuyzYfWYTG8 9mZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jYyKjzOQ; 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 5-20020ac84e85000000b003f9c53b7d70si9572407qtp.703.2023.08.02.18.54.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:54:37 -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=jYyKjzOQ; 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 1qRNWg-0000hs-1V; Wed, 02 Aug 2023 21:53:18 -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 1qRNWe-0000hE-Ak for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:16 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWc-0000nH-0C for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:16 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-563e6524aaeso261558a12.0 for ; Wed, 02 Aug 2023 18:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027592; x=1691632392; 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=0g0cVRguWw0x7PzF0MB98ECj4OyJgpksU9rKzq3J1ck=; b=jYyKjzOQ6qNj53VFBcR64mSvlzJ32b3OemmynC9XQ1o34JMfc8y3sS49KcETaXkYBB Naa3Wj/wSbvzAk4zH8U3CqtBwyIVbW3+GaqlYMaT8vB8CicVT1EqdajNatbpGS+RP50E 9hIQtqUFSe5P1m7DvU7DjT3ULTRjt22tZBAB44eYyy/a5fbuQafrlTHyNfMusFGqP8Kg bn8A+HFgZELI5is08Kz/u2Hz3YiGrM82EEfQTYFmP5+du2rZm37A+pQEvU+JKr6vHGDb wGEG5UViTmYd5gpI/HT4KcCVzjBQDRUCBHiFUfrY2siKIWwl4DnTYLswzfT4vDKXHFfi 4Mig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027592; x=1691632392; 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=0g0cVRguWw0x7PzF0MB98ECj4OyJgpksU9rKzq3J1ck=; b=TWTSGCCNsQbGV82IhzcxteWvX2jocUl8sTHlzwbx6sID3RU0SY9RM2fL2VJ8mXyrhl VHlnbcZf7bW2SJFN4vcnKjAVp4SGdvz7a5sUl9uL0BDHpt5wEvUOekJ8uA4MPaD1K7mu /dUAzV4zgI0iW6+uYjHuoTLg3bqY3wV6ztbUXQWmpIxPQ6HTY62O+bY0B9TCf7CeAZ6P wYjUTUWjJLcFuMBFyE+H1i+w4mWSO5N7W86K+goz0VyiZ45M11piI5X9j2UOA/YGPuzG jB36guxMeCuuk48EQc9G9hBV8uaZG8oCXs2/QlYCmFzB9aFFdlkrJFM55aSVDSF2sx4Z h0Rg== X-Gm-Message-State: ABy/qLbRTppmykio7aUUg8n4H2gP6JylC+HPyhSsr5XQ49GwpIM/pgCV yB2tJwwS+rWsHpqVQMgKebjhusycQVxTOTlhh0A= X-Received: by 2002:a05:6a20:183:b0:138:dbff:f029 with SMTP id 3-20020a056a20018300b00138dbfff029mr10960718pzy.18.1691027592551; Wed, 02 Aug 2023 18:53:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:12 -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 10/14] linux-user: Define TASK_UNMAPPED_BASE in $guest/target_mman.h Date: Wed, 2 Aug 2023 18:52:58 -0700 Message-Id: <20230803015302.407219-11-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::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.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 Provide default values that are as close as possible to the values used by the guest's kernel. Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 10 ++++++++++ linux-user/alpha/target_mman.h | 8 ++++++++ linux-user/arm/target_mman.h | 8 ++++++++ linux-user/cris/target_mman.h | 9 +++++++++ linux-user/hexagon/target_mman.h | 10 ++++++++++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 13 +++++++++++++ linux-user/loongarch64/target_mman.h | 8 ++++++++ linux-user/m68k/target_mman.h | 3 +++ linux-user/microblaze/target_mman.h | 8 ++++++++ linux-user/mips/target_mman.h | 7 +++++++ linux-user/nios2/target_mman.h | 7 +++++++ linux-user/openrisc/target_mman.h | 7 +++++++ linux-user/ppc/target_mman.h | 13 +++++++++++++ linux-user/riscv/target_mman.h | 7 +++++++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 4 ++++ linux-user/sparc/target_mman.h | 14 ++++++++++++++ linux-user/user-mmap.h | 14 -------------- linux-user/x86_64/target_mman.h | 12 ++++++++++++ linux-user/xtensa/target_mman.h | 6 ++++++ 21 files changed, 167 insertions(+), 14 deletions(-) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index f721295fe1..4d3eecfb26 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -4,6 +4,16 @@ #define TARGET_PROT_BTI 0x10 #define TARGET_PROT_MTE 0x20 +/* + * arch/arm64/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE DEFAULT_MAP_WINDOW / 4 + * DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 + * DEFAULT_MAP_WINDOW_64 UL(1) << VA_BITS_MIN + * VA_BITS_MIN 48 (unless explicitly configured smaller) + */ +#define TASK_UNMAPPED_BASE (1ull << (48 - 2)) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index 6bb03e7336..c90b493711 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -20,6 +20,14 @@ #define TARGET_MS_SYNC 2 #define TARGET_MS_INVALIDATE 4 +/* + * arch/alpha/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE TASK_SIZE / 2 + * TASK_SIZE 0x40000000000UL + */ +#define TASK_UNMAPPED_BASE 0x20000000000ull + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index e7ba6070fe..76275b2c7e 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -1 +1,9 @@ +/* + * arch/arm/include/asm/memory.h + * TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) + * TASK_SIZE CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xC0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index e7ba6070fe..9df7b1eda5 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -1 +1,10 @@ +/* + * arch/cris/include/asm/processor.h: + * TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) + * + * arch/cris/include/arch-v32/arch/processor.h + * TASK_SIZE 0xb0000000 + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index e7ba6070fe..c5ae336e07 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -1 +1,11 @@ +/* + * arch/hexgon/include/asm/processor.h + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * + * arch/hexagon/include/asm/mem-layout.h + * TASK_SIZE PAGE_OFFSET + * PAGE_OFFSET 0xc0000000 + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 97f87d042a..6459e7dbdd 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -24,6 +24,9 @@ #define TARGET_MS_ASYNC 2 #define TARGET_MS_INVALIDATE 4 +/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index e7ba6070fe..cc3382007f 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -1 +1,14 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_32_types.h: + * TASK_SIZE_LOW TASK_SIZE + * TASK_SIZE __PAGE_OFFSET + * __PAGE_OFFSET CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index e7ba6070fe..d70e44d44c 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -1 +1,9 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE64 0x1UL << (... ? VA_BITS : ...) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index e7ba6070fe..d3eceb663b 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1 +1,4 @@ +/* arch/m68k/include/asm/processor.h */ +#define TASK_UNMAPPED_BASE 0xC0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index e7ba6070fe..ffee869db4 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -1 +1,9 @@ +/* + * arch/microblaze/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE CONFIG_KERNEL_START + * CONFIG_KERNEL_START 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x48000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index e97694aa4e..fe1eec2d0b 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -14,6 +14,13 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/mips/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index e7ba6070fe..ce18f4f871 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -1 +1,8 @@ +/* + * arch/nios2/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE 0x7FFF0000UL + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index e7ba6070fe..f1aaad809d 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -1 +1,8 @@ +/* + * arch/openrisc/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE (0x80000000UL) + */ +#define TASK_UNMAPPED_BASE 0x30000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 67cc218f2e..04f99c6077 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -4,6 +4,19 @@ #define TARGET_MAP_NORESERVE 0x40 #define TARGET_MAP_LOCKED 0x80 +/* + * arch/powerpc/include/asm/task_size_64.h + * TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4)) + * TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(DEFAULT_MAP_WINDOW_USER64 / 4)) + * TASK_SIZE_USER32 (0x0000000100000000UL - (1 * PAGE_SIZE)) + * DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB (with 4k pages) + */ +#ifdef TARGET_PPC64 +#define TASK_UNMAPPED_BASE 0x0000100000000000ull +#else +#define TASK_UNMAPPED_BASE 0x40000000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index e7ba6070fe..0f06dadbd4 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -1 +1,8 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index e7ba6070fe..40d149b329 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -1 +1,11 @@ +/* + * arch/s390/include/asm/processor.h: + * TASK_UNMAPPED_BASE (... : (_REGION2_SIZE >> 1)) + * + * arch/s390/include/asm/pgtable.h: + * _REGION2_SIZE (1UL << _REGION2_SHIFT) + * _REGION2_SHIFT 42 + */ +#define TASK_UNMAPPED_BASE (1ull << 41) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index e7ba6070fe..bbbc223398 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -1 +1,5 @@ +/* arch/sh/include/asm/processor_32.h */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 9bad99c852..692ebf9dd7 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -5,6 +5,20 @@ #define TARGET_MAP_LOCKED 0x100 #define TARGET_MAP_GROWSDOWN 0x0200 +/* + * arch/sparc/include/asm/page_64.h: + * TASK_UNMAPPED_BASE (test_thread_flag(TIF_32BIT) ? \ + * _AC(0x0000000070000000,UL) : \ + * VA_EXCLUDE_END) + * But VA_EXCLUDE_END is > 0xffff800000000000UL which doesn't work + * in userland emulation. + */ +#ifdef TARGET_ABI32 +#define TASK_UNMAPPED_BASE 0x70000000 +#else +#define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index fd456e024e..bae49059e0 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,20 +18,6 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif - extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index e7ba6070fe..f9ff652b37 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -1 +1,13 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_64_types.h: + * TASK_SIZE_LOW DEFAULT_MAP_WINDOW + * DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index 3933771b5b..c4f671adb7 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -14,6 +14,12 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/xtensa/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 2) + */ +#define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) + #include "../generic/target_mman.h" #endif From patchwork Thu Aug 3 01:52: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: 709588 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354387ltf; Wed, 2 Aug 2023 18:55:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEUHrBvrKDITqNiWwOi2O2l5UpmlhfcFMOSrApRMFYkBpfUoSOijskn8fDLSkTUZyiL2IW X-Received: by 2002:a05:6214:20ca:b0:62d:edb1:89e6 with SMTP id 10-20020a05621420ca00b0062dedb189e6mr23953334qve.31.1691027735198; Wed, 02 Aug 2023 18:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027735; cv=none; d=google.com; s=arc-20160816; b=fCh287wt32HqYIj+V+Crm5xk1sPMfMJLN3gjUr1YrZ+oOzr1Z8rutjWKQ4LG5bNyXs LCqUPtRUwSU6rkXVdcSKdX1qeSTBEjG2Z4zrCytdAbSFTdFfmCmJcgvDwcgi+N9xtp6T zriyrz2yBeD5qOGbWBcitj9Ywkvq5l4rLOv9vtC5VvfdP22qcVcpSTaBl1C2u3Kim3vf Qp0VGKgOpqqpOA2vvyw+1rf3634d7C9WLkQpmb+aJM/AoIOkKL93K+Qv1NoGugRj4LGM TfnyeqGPh99MJDh3PJgGWyRxa9s1GvELra9IqPuGnKL6NWGU+4clV2Fr11jb5o7vw0ul iAuQ== 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=p6THWkmOL3up/JWfXdBzKttFod82ENPWZNu0IzoE7Eg=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=hpWerojsKK2QIKzR2NgGGgB8m/Q/k5xMOMxRTbeT/LqdrhkCzTloBP4yDb+IOTHvzb 13zw1Cg1bdAji2+1QZXcVq1mTkuICBqiKKGA8GnNfpy4H4oP6xITzwZDYbniPY7X5XUN qH9bh6+7viz4P7PC4y4I7MSDFltL5kXK1tnkiB8NFpMXnAwzkl/hd5CeaNxcpmm4edbo oXD24tfcydxtAs8qQb7J017IHQmijvOWAEKEmqF325THAXY2oH208EZQyIJ0sQxF5wK2 lngiNL6lrge8plLYvlSuQx3wLHP2MUD/Vb43xrHrn60nRfxZneqS0R8Sw42Xy+2Bv15y fa+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHPaITfl; 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 a15-20020a0ce34f000000b0062febdde8d3si9326750qvm.450.2023.08.02.18.55.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:35 -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=cHPaITfl; 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 1qRNWh-0000iP-Fk; Wed, 02 Aug 2023 21:53:19 -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 1qRNWe-0000hd-UD for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:16 -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 1qRNWc-0000nt-R3 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:16 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68730bafa6bso1073967b3a.1 for ; Wed, 02 Aug 2023 18:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027593; x=1691632393; 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=p6THWkmOL3up/JWfXdBzKttFod82ENPWZNu0IzoE7Eg=; b=cHPaITfl1On56rbXEPRfLP0IPUQOOLnz7fqVmKUW07MYVINdA++RSrPF2diuC/dXdU 2c9hiXitefATT0BkUlKisybF5tTFxwG7GJWSDOaHN0z4Zr1WimM79hXQlFfF+QMVvMYK JaTWhwG2swCZtc94y5Qlq0TpcQ1itQgzM3nueKWe1hNHOv5eeHrGsBf4DhfkR9iftgYS CbNmXFbRJhzD0jR21uE2db5uUtdaqsKD9RlTbaVPaVUHY62GcnvK3+lLJsnNw0JiHwC7 rdeUU0CHITnsZPqDvfds6+LX4vKw83lysj6wfibmYd0R9oLujPyVcSgXQb00kyp5AVMM IfGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027593; x=1691632393; 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=p6THWkmOL3up/JWfXdBzKttFod82ENPWZNu0IzoE7Eg=; b=BO9VdBDCq9NMgO1E9KuHpiy3UWENR9ccN4TsvzifsyZwF8DlSufHY3kgtEBuHwDa8w SCVPgz58fZj3XFNeqtSufb6KKI0aucaffjJ53RuUii/HKBeaViixoS3O4aJTJlRBRhg7 BJesvc0Blt3t/E3xDtsGMsoo5vEIZvPz8mKcv40m3W+YTb9xRUOmvxN7mo/YPqr69UyC II0CArJEdRAKS3t6OpdyYH5UYStqbn1qvRlXOo4ILE7WmyEJZ/FR5pUvoJsOlWDWEmT2 DS6wmOswRtZo8ZpwsGUDcfHACsbVuh9XWaEufYUAel6wUMmkgxSXJgWbTdF3asKKGS1R 6akg== X-Gm-Message-State: ABy/qLbMl9J2IxKP7Gr8OFS5RUqrUSqPmvHjE3GVzanIqSJfGXHCfniR HHpc2fmhz8gnXxSpkq2nrDvBMp4BftNH+magegM= X-Received: by 2002:a05:6a20:729b:b0:125:4d74:cd6a with SMTP id o27-20020a056a20729b00b001254d74cd6amr22390565pzk.3.1691027593452; Wed, 02 Aug 2023 18:53:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:13 -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 11/14] linux-user: Add ELF_ET_DYN_BASE Date: Wed, 2 Aug 2023 18:52:59 -0700 Message-Id: <20230803015302.407219-12-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::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, 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 Copy each guest kernel's default value, then bound it against reserved_va or the host address space. Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 3 +++ linux-user/alpha/target_mman.h | 3 +++ linux-user/arm/target_mman.h | 3 +++ linux-user/cris/target_mman.h | 3 +++ linux-user/hexagon/target_mman.h | 3 +++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 3 +++ linux-user/loongarch64/target_mman.h | 3 +++ linux-user/m68k/target_mman.h | 2 ++ linux-user/microblaze/target_mman.h | 3 +++ linux-user/mips/target_mman.h | 3 +++ linux-user/nios2/target_mman.h | 3 +++ linux-user/openrisc/target_mman.h | 3 +++ linux-user/ppc/target_mman.h | 7 +++++++ linux-user/riscv/target_mman.h | 3 +++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 3 +++ linux-user/sparc/target_mman.h | 11 +++++++++++ linux-user/user-mmap.h | 1 + linux-user/x86_64/target_mman.h | 3 +++ linux-user/xtensa/target_mman.h | 4 ++++ linux-user/main.c | 15 +++++++++++++++ linux-user/mmap.c | 1 + 23 files changed, 96 insertions(+) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index 4d3eecfb26..69ec5d5739 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -14,6 +14,9 @@ */ #define TASK_UNMAPPED_BASE (1ull << (48 - 2)) +/* arch/arm64/include/asm/elf.h */ +#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index c90b493711..8edfe2b88c 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -28,6 +28,9 @@ */ #define TASK_UNMAPPED_BASE 0x20000000000ull +/* arch/alpha/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index 76275b2c7e..51005da869 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/arm/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index 9df7b1eda5..9ace8ac292 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -7,4 +7,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) +/* arch/cris/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index c5ae336e07..e6b5e2ca36 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -8,4 +8,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/hexagon/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 6459e7dbdd..ccda46e842 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -27,6 +27,9 @@ /* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/parisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index cc3382007f..e3b8e1eaa6 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -11,4 +11,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index d70e44d44c..8c2a3d5596 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -6,4 +6,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/loongarch/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index d3eceb663b..20cfe750c5 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1,4 +1,6 @@ /* arch/m68k/include/asm/processor.h */ #define TASK_UNMAPPED_BASE 0xC0000000 +/* arch/m68k/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index ffee869db4..6b3dd54f89 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x48000000 +/* arch/microblaze/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index fe1eec2d0b..b84fe1e8a8 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -21,6 +21,9 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/mips/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index ce18f4f871..ab16ad4f03 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) +/* arch/nios2/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index f1aaad809d..243c1d5f26 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE 0x30000000 +/* arch/openrisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 04f99c6077..646d1ccae7 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -17,6 +17,13 @@ #define TASK_UNMAPPED_BASE 0x40000000 #endif +/* arch/powerpc/include/asm/elf.h */ +#ifdef TARGET_PPC64 +#define ELF_ET_DYN_BASE 0x100000000ull +#else +#define ELF_ET_DYN_BASE 0x000400000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index 0f06dadbd4..3049bcc67d 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -5,4 +5,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) +/* arch/riscv/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index 40d149b329..c82435e381 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -8,4 +8,14 @@ */ #define TASK_UNMAPPED_BASE (1ull << 41) +/* + * arch/s390/include/asm/elf.h: + * ELF_ET_DYN_BASE (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1) + * + * arch/s390/include/asm/processor.h: + * STACK_TOP VDSO_LIMIT - VDSO_SIZE - PAGE_SIZE + * VDSO_LIMIT _REGION2_SIZE + */ +#define ELF_ET_DYN_BASE (((1ull << 42) / 3 * 2) & ~0xffffffffull) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index bbbc223398..dd9016081e 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -2,4 +2,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/sh/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 692ebf9dd7..696ca73fe4 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -19,6 +19,17 @@ #define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) #endif +/* + * arch/sparc/include/asm/elf_64.h + * Except that COMPAT_ELF_ET_DYN_BASE exactly matches TASK_UNMAPPED_BASE, + * so move it up a bit. + */ +#ifdef TARGET_ABI32 +#define ELF_ET_DYN_BASE 0x78000000 +#else +#define ELF_ET_DYN_BASE 0x0000010000000000ull +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index bae49059e0..5dd48a458d 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,6 +20,7 @@ extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; +extern abi_ulong elf_et_dyn_base; int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index f9ff652b37..48fbf20b42 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -10,4 +10,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index c4f671adb7..8fa6337a97 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -20,6 +20,10 @@ */ #define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) +/* arch/xtensa/include/asm/elf.h */ +#define ELF_ET_DYN_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/main.c b/linux-user/main.c index c207b783d5..2b6f3f22c7 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -845,6 +845,21 @@ int main(int argc, char **argv, char **envp) } mmap_next_start = task_unmapped_base; + /* Similarly for elf_et_dyn_base. */ + if (reserved_va) { + if (LESS(ELF_ET_DYN_BASE, reserved_va)) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3 * 2. */ + elf_et_dyn_base = TARGET_PAGE_ALIGN(reserved_va / 3) * 2; + } + } else if (LESS(ELF_ET_DYN_BASE, UINTPTR_MAX)) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* 32-bit host: pick something medium size. */ + elf_et_dyn_base = 0x18000000; + } + #undef LESS { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 84436d45c8..949c4090f3 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -301,6 +301,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, abi_ulong task_unmapped_base; abi_ulong mmap_next_start; +abi_ulong elf_et_dyn_base; /* * Subroutine of mmap_find_vma, used when we have pre-allocated From patchwork Thu Aug 3 01:53:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709589 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354405ltf; Wed, 2 Aug 2023 18:55:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlEDdqMuKKs1OzBMKwgyrgP4AJLqT3VnCR88AtQLZsLuvsmvU34dv5MZf5Uud/8BNTi3mmzp X-Received: by 2002:ac8:4e8c:0:b0:405:4393:a001 with SMTP id 12-20020ac84e8c000000b004054393a001mr24344240qtp.2.1691027738836; Wed, 02 Aug 2023 18:55:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027738; cv=none; d=google.com; s=arc-20160816; b=hPK4ERfwRKVl2tJYwUvWKrGPnTk1Al5cWS3VE2w8yBA/Xa7YjDgEy9PgjqPNjBTitO awd0Nusf/COGP5IUYhg5usQo0a9OoRTo3RAlHOgrX2rpktu8WbKaOm8mj+T+nlfQvxtI 1c6Z4lFJIcRF+KI/mMYyJ/T+wIDqw+a+l4VSUrElqzDSyxobeQMlRmfkuloy9aml4sHv nmtcZcZwQA42U59k5P4147rNQwAoQ6rlVIFIu2zLn8EznYczjCe3TNGsA0a3trhLZ4+s 2c6NEA2kmnEgtS59EoCI361YFrWsbY/BHLaZYKvfVAt8vXHYu+TtSQoWYF+p1GsivVCW TxRQ== 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=ChEUXUgAPSYhXU4GN1bgmHxBnAzewX2kPCgTDo1jgOA=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=zA6NGtogdZ9OUvnh4UmYIgcDJwg73GA0JuX/uC/ZPCa4hQY9p4aINHb16Yaq3a81mp /sPJNNPaNOfKs9CkojjRq+i2zN3Oxp/NDnLEgrjH07MXuO+k846ZUOtUdAnqclBIkHIN qCTaCX+soAbOJESsAsPXxpDaoLrLsnBBXzR/t+7XiaVlwURnuh0IvPP4rIIsAQbe042r Cm4btPmXORbiycC5OkFTFfiDYMlGqhwy8FJcd1YLE/ux89L01kUOxPixmJVpSBgq2kh8 pee6MSw/uTWpmxrxMf4wwVEJTwOUrBeGDvxUocPC8reFD6up/koG7dtPY0WsHQQgDe4W 6zdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="buVzk17/"; 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 t21-20020ac85895000000b00403df34987asi9252133qta.376.2023.08.02.18.55.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:38 -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="buVzk17/"; 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 1qRNWi-0000iv-5K; Wed, 02 Aug 2023 21:53:20 -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 1qRNWg-0000i6-6K for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:18 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWd-0000oN-LM for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:17 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686be3cbea0so1083315b3a.0 for ; Wed, 02 Aug 2023 18:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027594; x=1691632394; 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=ChEUXUgAPSYhXU4GN1bgmHxBnAzewX2kPCgTDo1jgOA=; b=buVzk17/UzMaI0kKJj0C9HpUwQbWclgya3adJJYiPRubCo2UM0hIZzLQd5f8aDJ7GR CCQCGEyNyEVYJrIK2mhlm/Op0Or1nah3m5Lw0Ica3kfORuqXEgr2Zap9SfLOefBIKCE7 bpgycsabfJMzwJm0iEg4gYMlTz4LNbTRkczu7alcPrg2iyXd4W5VEmbySEOTjfx0W6E3 iCvkgYpmY37W5ellBLXQAC2UmuhMgLY/ZkdR5NjSkjfMpAkzV4DFdvkcA5CdT9J6fNaH hYZyj6xqloIljZSGDkgG+sXSU56lWsYl7RxcmQZaRSV87sahqnOzGQTscK25KerH/7jX eV2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027594; x=1691632394; 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=ChEUXUgAPSYhXU4GN1bgmHxBnAzewX2kPCgTDo1jgOA=; b=V/hT223VrcixJqq9Y5Z+GCTgjUdMgbKyDxFjbNONhUnA8P3KKwe1Pg/bjPdvTicKEf smWOxePKMBeY+VyGe8zwe19GTHCdPH0rpAe24XQ/dqXgcn03/JYf61ys80Zan9XeT6RH LBaZtONISS348wiBuqirZOvNxvTeltoNwZ+sliTb+XLO87wzn7NfGVOisViJDvyE/+ZO abQV+Uu39IS3ETiBQ8JL5VzlQzNxk3FTHdgRrx6JNXlU1USiQ2N9F7nQ+XH2LBvUHQ0l RC9QGIrJiwGkU4btWTvvUasSLcCk3eLn3Ya6ApKcSL2qNx+vGggPj0LbhRLEyMZQl/yd TGZw== X-Gm-Message-State: ABy/qLZhnxJ1M+F2KYVnoINjUDpUlDu2d7iPA95NGITPqZgeHhKZbbf8 9s/613lNB5PUMiUbyE7agHTGZ2NGQs8GWok3aT8= X-Received: by 2002:a05:6a20:72a5:b0:132:d09f:1716 with SMTP id o37-20020a056a2072a500b00132d09f1716mr18620596pzk.2.1691027594197; Wed, 02 Aug 2023 18:53:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:13 -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 12/14] linux-user: Use elf_et_dyn_base for ET_DYN with interpreter Date: Wed, 2 Aug 2023 18:53:00 -0700 Message-Id: <20230803015302.407219-13-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::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.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 Follow the lead of the linux kernel in fs/binfmt_elf.c, in which an ET_DYN executable which uses an interpreter (usually a PIE executable) is loaded away from where the interpreter itself will be loaded. Signed-off-by: Richard Henderson --- linux-user/elfload.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2aee2298ec..fef9a0bc8f 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3021,7 +3021,7 @@ static void load_elf_image(const char *image_name, int image_fd, struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; struct elf_phdr *phdr; abi_ulong load_addr, load_bias, loaddr, hiaddr, error; - int i, retval, prot_exec; + int i, retval, prot_exec, load_map_flags; Error *err = NULL; /* First of all, some simple consistency checks */ @@ -3106,6 +3106,19 @@ static void load_elf_image(const char *image_name, int image_fd, } } + load_addr = loaddr; + + /* + * For ET_EXEC, load_addr is required. Use MAP_FIXED_NOREPLACE instead + * of MAP_FIXED on the off-chance that the guest address overlaps a + * host address. There should be no other conflict this early in the + * loading process. + */ + if (ehdr->e_type == ET_EXEC) { + load_map_flags = MAP_FIXED_NOREPLACE; + } else { + load_map_flags = 0; + } if (pinterp_name != NULL) { /* * This is the main executable. @@ -3135,11 +3148,34 @@ static void load_elf_image(const char *image_name, int image_fd, */ probe_guest_base(image_name, loaddr, hiaddr); } else { + abi_ulong align; + /* * The binary is dynamic, but we still need to * select guest_base. In this case we pass a size. */ probe_guest_base(image_name, 0, hiaddr - loaddr); + + /* + * Avoid collision with the loader by providing a different + * default load address. + */ + load_addr = loaddr + elf_et_dyn_base; + + /* + * TODO: Better support for mmap alignment is desirable. + * Without reserved_va we would prefer any host conflict be + * resolved by choosing a different address, therefore we + * don't want to use MAP_FIXED. But without that we cannot + * cannot guarantee alignment, only suggest it. + */ + align = pow2ceil(info->alignment); + if (align) { + load_addr &= -align; + } + if (reserved_va) { + load_map_flags = MAP_FIXED_NOREPLACE; + } } } @@ -3157,10 +3193,9 @@ static void load_elf_image(const char *image_name, int image_fd, * In both cases, we will overwrite pages in this range with mappings * from the executable. */ - load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, + load_addr = target_mmap(load_addr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), - -1, 0); + load_map_flags, -1, 0); if (load_addr == -1) { goto exit_mmap; } From patchwork Thu Aug 3 01:53:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709581 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354126ltf; Wed, 2 Aug 2023 18:54:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnkap3CYC86EawD4Y1f+O6JFvwRyY8jYGXIF15WwG+Zu1GQ3EmUvwIKC9/XHubEZ32x/Xy X-Received: by 2002:a05:620a:44cc:b0:767:f116:1b92 with SMTP id y12-20020a05620a44cc00b00767f1161b92mr22162511qkp.38.1691027669377; Wed, 02 Aug 2023 18:54:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027669; cv=none; d=google.com; s=arc-20160816; b=ZdbtbyM6f9wb9MNyBLjIbtxXZpcLjmIeFfn38cVIUikkFe1KpxCwEpTNsnD+hgxjb8 I1H/FcBP+ybEegj9bm39xOKVPOjU+wo8Q8G4qFfTZpv+WQeFwUA/kbD9uLwGhlthTJzV fNItsNMgOe9za12fdy/V8Mn1rzXvn00H1TGfkEXZpmNKoFt48C7yeFbAMlUVNhgfuyhT frjywlSEY1ycWIBWGXY27PKtA3R3sSLJ/vMEuyJxMU5n9rUdp+YqMmj4xOFaLsjLpAD6 k54HiB9nGcnPOU7aC1QHeB8uMQX2hbMeMJPFXWZqiZ3N6FJIOUGFLZYL9D/qtrIbqGQY Nbuw== 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=iTYiVzZgwnSBm2cJQnzOd6IorKWpOrXyW6rl98Yh7OU=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=hQenISEfMwRPtKTx/tTyp+AL9u0oJGyx3Wh19BfSMGDrc6CrF5ZnuKJDfeKY5r/y8a TREHlPlqSQJI9YVrFp8wcYsI+eOe2fmGWzUAX6Mh0TeSM6y37jD3qm/GNw65HwejvXPY u5BFyQHCpVp6mqkg8SACImZURR9v1bk1Jm8aV6fsINxPKdWW7jwWwqgFTNIuN1XOmEDe RWUlCCv97eKg0vcySD/NoWsqP5Y+IdUv6PrE8I2khN+FFNJ6urmFJv6RI0X86Jjyg+g9 OiukkU8ITeRrGimD2Nmrh9kXGjuos6cskc/wUMj5dUw3vQzRl+4UztANt0Go9aaJF2Hm CcmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="pt7YBuQ/"; 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 q28-20020a05620a025c00b00767356571a6si7872768qkn.785.2023.08.02.18.54.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:54:29 -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="pt7YBuQ/"; 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 1qRNWl-0000jR-1Y; Wed, 02 Aug 2023 21:53:23 -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 1qRNWg-0000iA-DQ for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:18 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWe-0000oh-Hh for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:18 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-55b22f82ac8so1092514a12.1 for ; Wed, 02 Aug 2023 18:53:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027595; x=1691632395; 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=iTYiVzZgwnSBm2cJQnzOd6IorKWpOrXyW6rl98Yh7OU=; b=pt7YBuQ/7O08Bl4RKc8BNEVYPl6kjlWa6Gr+dxCwfHDUeshjfsf25iSbs/Cbl6P8la YR3X6hChjLzDwy0IHgVWwD1p5pRPvTCNniwZHbNXwqfw3hbpTEIrlyJ7lPI5AVkb0fej yybHH/e5zzECrWNkbNDAubA01lYS6zkLxqS8DPGRfuYA026Px6kFHeVKmuytoFowTZTE TxxV0PWQHu16jacNWCUIk3N6qUSbrEoFF48HpP0ePiuEWbew4MFZ4Qolk7VfAJZeAVsK /GICeDKRo3cKMP9VI2K+ROoqB7nGR2t5cfiQjU98AsY15cnGxObOskYitLsp3Rd9yA7A J23g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027595; x=1691632395; 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=iTYiVzZgwnSBm2cJQnzOd6IorKWpOrXyW6rl98Yh7OU=; b=OwF4sxLnmblsQm7yMa71M5VaxUe3qtbzylEEMrcYjdHprDqlSKidKoqxEfJvk5iV7v qhm+OxJi6hwFVShYcuvd7yBaPc59yFfAkNuh3yJzZFc+c12z08tB/5M7Spp/+Q+o9uDZ hGG/IitfG3aCXhR85602Wv4Z4mS9B56Mp4qlRufJesF25VdKXChAZv5P+3ebvH39TlCO LT7KrMiL4/tnDPYz51o4YtL48oZnF4FU+SoJ94Hkykksv53lwTEwTKCaiwoMkfWKAVlC ML440sgPXm0o0nxtknGYxy0QYfA4wZeRZJau4PHPJM3yfuJwQ2/Z2zVCIzIAr3Ubfx3B APsA== X-Gm-Message-State: ABy/qLaG70VMVVFZw4FJv4MpB7C51z4RgGSzxCShHiP/pXHt1f7rWbZa WgZPGG5t+6TszSoxoy+J45An0hCEZWBewN0fyVY= X-Received: by 2002:a17:90b:1bc6:b0:268:5aaf:fbe with SMTP id oa6-20020a17090b1bc600b002685aaf0fbemr22748015pjb.10.1691027594941; Wed, 02 Aug 2023 18:53:14 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:14 -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 13/14] linux-user: Adjust initial brk when interpreter is close to executable Date: Wed, 2 Aug 2023 18:53:01 -0700 Message-Id: <20230803015302.407219-14-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::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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: Helge Deller While we attempt to load a ET_DYN executable far away from TASK_UNMAPPED_BASE, we are not completely in control of the address space layout. If the interpreter lands close to the executable, leaving insufficient heap space, move brk. Signed-off-by: Helge Deller [rth: Re-order after ELF_ET_DYN_BASE patch so that we do not "temporarily break" tsan, and also to minimize the changes required. Remove image_info.reserve_brk as unused.] Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/elfload.c | 51 +++++++++++++------------------------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 802794db63..4b0c9da0dc 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -31,7 +31,6 @@ struct image_info { abi_ulong end_data; abi_ulong start_brk; abi_ulong brk; - abi_ulong reserve_brk; abi_ulong start_mmap; abi_ulong start_stack; abi_ulong stack_limit; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fef9a0bc8f..bf747a15b5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3120,27 +3120,6 @@ static void load_elf_image(const char *image_name, int image_fd, load_map_flags = 0; } if (pinterp_name != NULL) { - /* - * This is the main executable. - * - * Reserve extra space for brk. - * We hold on to this space while placing the interpreter - * and the stack, lest they be placed immediately after - * the data segment and block allocation from the brk. - * - * 16MB is chosen as "large enough" without being so large as - * to allow the result to not fit with a 32-bit guest on a - * 32-bit host. However some 64 bit guests (e.g. s390x) - * attempt to place their heap further ahead and currently - * nothing stops them smashing into QEMUs address space. - */ -#if TARGET_LONG_BITS == 64 - info->reserve_brk = 32 * MiB; -#else - info->reserve_brk = 16 * MiB; -#endif - hiaddr += info->reserve_brk; - if (ehdr->e_type == ET_EXEC) { /* * Make sure that the low address does not conflict with @@ -3229,7 +3208,8 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_code = 0; info->start_data = -1; info->end_data = 0; - info->brk = 0; + /* Usual start for brk is after all sections of the main executable. */ + info->brk = TARGET_PAGE_ALIGN(hiaddr); info->elf_flags = ehdr->e_flags; prot_exec = PROT_EXEC; @@ -3323,9 +3303,6 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_data = vaddr_ef; } } - if (vaddr_em > info->brk) { - info->brk = vaddr_em; - } #ifdef TARGET_MIPS } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -3654,6 +3631,19 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) if (elf_interpreter) { load_elf_interp(elf_interpreter, &interp_info, bprm->buf); + /* + * While unusual because of ELF_ET_DYN_BASE, if we are unlucky + * with the mappings the interpreter can be loaded above but + * near the main executable, which can leave very little room + * for the heap. + * If the current brk has less than 16MB, use the end of the + * interpreter. + */ + if (interp_info.brk > info->brk && + interp_info.load_bias - info->brk < 16 * MiB) { + info->brk = interp_info.brk; + } + /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ @@ -3707,17 +3697,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) bprm->core_dump = &elf_core_dump; #endif - /* - * If we reserved extra space for brk, release it now. - * The implementation of do_brk in syscalls.c expects to be able - * to mmap pages in this space. - */ - if (info->reserve_brk) { - abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); - abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); - target_munmap(start_brk, end_brk - start_brk); - } - return 0; } From patchwork Thu Aug 3 01:53:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709583 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354233ltf; Wed, 2 Aug 2023 18:54:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlFy7QCC8IDG8lDwZlQEJHFvztMUVtFNKTunul4jOD39xFRp6/evseqFs5s0M7uhGcVtt8tC X-Received: by 2002:a05:620a:2155:b0:76c:b29a:eeee with SMTP id m21-20020a05620a215500b0076cb29aeeeemr8730956qkm.64.1691027697317; Wed, 02 Aug 2023 18:54:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027697; cv=none; d=google.com; s=arc-20160816; b=rptMQW/WHwQk87/82F62D9rV12KATaYD9A946AUFuopT1J8v9o1Lb/pqt0fGWbolwd Q9+j8JYk1FgXUS2uIlFWzSP9A5RmJHTCU5DU8Zro/R0YpxFkjyQxUyYm9oA0EhdYoUtj MiQaWfd+oVk72zZPi+VfeCZ25M6sD9Imzk7jyis/HphuhVaAKZzeUIAzjbq/081QET4A F0zpeCBBEb+uvVGMYuqQRRxLlSNa/26bF5RIQdKii3YkZgrK+B5yLwxQ/umAgaqQ16bX 0vRofTHBEH9eGeyRM32I7HHY+os1/S7HNZVXWuNTDXOdO4hp7ZGTMThxwT4z83crbtJa igLw== 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=on5r7f0kRrvLwtEMgkqNRJQnFQG3tYk+wVcG6tCyF5I=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=bRTIjIp+u0UXVOeVSscajMKz3TZSyCqCqbIoctY64Vty/5E6eZhmFoszlANxkbXMCN yVl33RA1APPWBAA/MqSYu5WeR6FecPNWnf0s9fN5pZFn9qR4ZtE+08MqST2GyU289qy5 4m9OR2I9oV93hm17lHvAPdeQwp5NcRBnbSXie6VeT04LQ1dhpW73vymhbNAspNcaaRyz ffq7j5qUOmIdHr6ULN45g0AHyDaPzCJi1odDYe82XSEpB0xiPTlg3PkrtN8q62rBgKcB Tbq6xu9atCyeKw6++GlTCvZIRHhB2Tog5Wbfr+Jfd5Pt8apsrdVOkRfna9Roa32GpNVT +10w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q7hy9xAm; 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 g65-20020a37b644000000b00767da13c9c2si8775645qkf.6.2023.08.02.18.54.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:54:57 -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=Q7hy9xAm; 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 1qRNWj-0000jL-ON; Wed, 02 Aug 2023 21:53:22 -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 1qRNWg-0000iF-Dw for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:18 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWe-0000pD-Q9 for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:18 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3a6f3ef3155so316372b6e.1 for ; Wed, 02 Aug 2023 18:53:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027596; x=1691632396; 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=on5r7f0kRrvLwtEMgkqNRJQnFQG3tYk+wVcG6tCyF5I=; b=Q7hy9xAmmOJ2EIbmxpBQ/PQ3gPWXju5XalvqnJ3Hc1HT+3FphegfRcS969Nm7CyWWV Pv84H4x594rxD/Ua0NGeqtsEzsb1YeW7CcB9DqvQ7Z2L11plqVqVDB284u1x6XRaxwQD RaDd4QQ4/+lKBtiRYwHTAqoZRUwc4SyW7gBaTmdGWRR9x14771PH4cSKg0l5jI1wp+w9 97KXWZDNN4D44FCyAoVwkgOapXIr4d0tz9vlpXMIROcC3UpSkEjXs6SP+W+B+MWC/Jpc JanPdwzHKfiNYfWxa+OC8HqLr0+vhzpOTUAFrOvbuhVRCUrYWH3N6rUMBYGy4kGSlYea cKFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027596; x=1691632396; 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=on5r7f0kRrvLwtEMgkqNRJQnFQG3tYk+wVcG6tCyF5I=; b=X7ihU2lwCCQXv84P1z44SHRj9GuU21CX7kqXgUb15KcI3rIwOoJScgQ8A0u/HJ/uqe jcpqNBv2PMg61yLqkmcKiXfdIojyh7/KFx4Mkvg971MtLc8bgzzl2oRVgzoh9kv/9CCH HcarmB9VB38vcW4dex/3ZHrw0Z0sjvQHviHuOPXtbbfrfm5NLv+XekA170A54mo0U0fm 01OqF4FTiiAUNY5Ub975GNdKHoKLjsUldURic3xq3Uul1VUImMj36I8QTJ+bxyuREpm5 mA1TcbZH5+9T4OV/2cMAwCiNzSlPA/Oe4T9wv9ubHcZip/sNfY7QA4UyAlqMcNquzD67 GFKg== X-Gm-Message-State: ABy/qLajDU15gXHdq5qoLW+/a35UWb0XjTScIxybXkZReJDd9t0k36O4 3DisTt1DFweOtGNK3QeqHfe3BkybL8a7J++TClc= X-Received: by 2002:a05:6808:1493:b0:3a7:4b9a:43ca with SMTP id e19-20020a056808149300b003a74b9a43camr8655437oiw.53.1691027595849; Wed, 02 Aug 2023 18:53:15 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:15 -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 14/14] linux-user: Properly set image_info.brk in flatload Date: Wed, 2 Aug 2023 18:53:02 -0700 Message-Id: <20230803015302.407219-15-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::22a; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22a.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 The heap starts at "brk" not "start_brk". With this fixed, image_info.start_brk is unused and may be removed. Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/flatload.c | 2 +- linux-user/main.c | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 4b0c9da0dc..4f8b55e2fb 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -29,7 +29,6 @@ struct image_info { abi_ulong end_code; abi_ulong start_data; abi_ulong end_data; - abi_ulong start_brk; abi_ulong brk; abi_ulong start_mmap; abi_ulong start_stack; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 5efec2630e..8f5e9f489b 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -811,7 +811,7 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) info->end_code = libinfo[0].start_code + libinfo[0].text_len; info->start_data = libinfo[0].start_data; info->end_data = libinfo[0].end_data; - info->start_brk = libinfo[0].start_brk; + info->brk = libinfo[0].start_brk; info->start_stack = sp; info->stack_limit = libinfo[0].start_brk; info->entry = start_addr; diff --git a/linux-user/main.c b/linux-user/main.c index 2b6f3f22c7..c393a2ceb6 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -961,8 +961,6 @@ int main(int argc, char **argv, char **envp) fprintf(f, "page layout changed following binary load\n"); page_dump(f); - fprintf(f, "start_brk 0x" TARGET_ABI_FMT_lx "\n", - info->start_brk); fprintf(f, "end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); fprintf(f, "start_code 0x" TARGET_ABI_FMT_lx "\n",