From nobody Sat May 18 23:44:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027703; cv=none; d=zohomail.com; s=zohoarc; b=LrPu+TzymWSsAMToVBHu9xd+F7SpM9m9rVm24LhiBejb4yTJ/WiL1wHiOGl7Nqb/5/aFHsKp55QtZCBhGFzj6oTl4guStWmyqa08+0b7W6AnNRV+qX/utR9qaD5shGcxnnMP+QO1l4W/qIgULHGRx/48TCcoDaRxDg9K0xRycAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027703; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; b=IsX1BmS4veIU2X3YSQxQvdVfYZlPYFhGyztTlGjXjGks5Kn4YCWt/ei9JwQzv/7cfQA+KyvUWofagxfOIOGM1UF1DhkUxTVjxTaYQC6yWFCezuSSaV9jhtI/c3IV+CGngczmdBGGMGUp88hmswh5jrpvzcJ0RSf3fPqm3QMe1dQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027703070573.0959551485814; Wed, 2 Aug 2023 18:55:03 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlFJGIXRGNAiYdBULk8VUjAKJKlq7WdbB03RJfPFiK6Vc63uSnIw5jc7RQoEfaMvHvUA36qgKQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027703769100001 Content-Type: text/plain; charset="utf-8" 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; } =20 - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno =3D EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno =3D EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something els= e. + * 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 overwri= te + * any host address mappings. + */ + if (reserved_va) { + flags =3D (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } =20 /* --=20 2.34.1 From nobody Sat May 18 23:44:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027668; cv=none; d=zohomail.com; s=zohoarc; b=ir2PqAGDI1erF1BvYPnbG6Yi+aeDs3FnaebQESxUmGHHDA5e47vAr7divE7v9ZsJKKzRZxCVQ7s4tCIWeAXzn9mESa8y2faA+cQWpbx1p+SmNyWGL/978nmJTrfCETbDjT5syQympWtcS3wkmh3TgMV3nqUbPzGsHOTfkvPuk3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027668; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/eOGiWVqZ8Y4POmSjtXETDABSVmvc7JlojTPUk6j1vw=; b=KRUZ6cfoJ39WgTFtoTDTM6FA0Bekzh+UYKpjguMM8cCCKYZNDu1apYoEc++m4rn6Ha+zpgkUJem0W0I83ElQsAF4hooQyPd833w4QdGFtt0/npRfdU+IYg9N69/wTPszxRiI9aIMXTbMveAXlX9KL2DZ7UYs9MDGnEugXjmEEzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027668460815.2518495732962; Wed, 2 Aug 2023 18:54:28 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlE6UdGmwlRXt6kXZDSgbn9liXJ9DmM8xyL3X5G5StkI4k8Ix2DZ7D0bofv5EOKci4M6Sj0mYA== 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) 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027669551100003 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 =E2=80=9Cnon-MAP_FIXED=E2=80=9D 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 =3D mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); - if (p =3D=3D MAP_FAILED) { + if (p !=3D host_start) { + if (p !=3D MAP_FAILED) { + munmap(p, qemu_host_page_size); + errno =3D EEXIST; + } return false; } prot_old =3D prot; @@ -687,17 +691,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int target_prot, =20 /* map the middle (easier) */ if (real_start < real_last) { - void *p; + void *p, *want_p; off_t offset1; + size_t len1; =20 if (flags & MAP_ANONYMOUS) { offset1 =3D 0; } else { offset1 =3D offset + real_start - start; } - p =3D mmap(g2h_untagged(real_start), real_last - real_start + = 1, - target_to_host_prot(target_prot), flags, fd, offset1); - if (p =3D=3D MAP_FAILED) { + len1 =3D real_last - real_start + 1; + want_p =3D g2h_untagged(real_start); + + p =3D mmap(want_p, len1, target_to_host_prot(target_prot), + flags, fd, offset1); + if (p !=3D want_p) { + if (p !=3D MAP_FAILED) { + munmap(p, len1); + errno =3D EEXIST; + } goto fail; } passthrough_start =3D real_start; --=20 2.34.1 From nobody Sat May 18 23:44:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027714; cv=none; d=zohomail.com; s=zohoarc; b=YVcgUSeW7TWLN9c8l0tQO7lpH70PS15yCswItdF5KBOtbRqI0LUs/lxDbJTDWbsOOsbJeVTu5g1MeGXFzZOaXBV3cZF/9FUH0nLSeP8Pl1vNGg2oXQ4XP6g8Xi9u28Do3YjTj1iGs2i2JDBequWUzJ9bgIhf8ah4alx/5oRARNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; b=KT0Njwf9jL1TZXYpZYXX8sOeDLlbjq7wx/6w6BS1ctRULXkvS8qOe5qtXEi8tfPiEB3xptSGbJl1brue7Jzl6jMlNkKT7uCWyI91+dFeMDsoDfRTTDxtaBXsmPHDo4CfoivsFD6UATUd7fMLAm7xl8iKPmh0gdZvKRYRsZaXMhg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027714201173.8324989534234; Wed, 2 Aug 2023 18:55:14 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlHwRGjIljNiIMg2yeQjEJwtxyC83aHxMTlB0TjkYQ+DJNVrmVyQBVTqF5h8LSb98wZvq+2jDQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027715738100003 Content-Type: text/plain; charset="utf-8" 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 =3D new_host_brk_page - brk_page; - mapped_addr =3D get_errno(target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0)); + mapped_addr =3D target_mmap(brk_page, new_alloc_size, + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, 0, 0); } else { new_alloc_size =3D 0; mapped_addr =3D brk_page; --=20 2.34.1 From nobody Sat May 18 23:44:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027768; cv=none; d=zohomail.com; s=zohoarc; b=Gv08/Jtz2U0c3PJJ3Znf4l/JtXDCTFOrt9PJ+31pwpIc8noTVYcW1qdklnaDKeqA4L9FNQkTR+JT4E9e9BQ30lQ9kAdXVsa2SVA6HV9wJ8QgEgCTa+hqqA6HAIPnUQBgOgNrBnVGcr56UlpU0zs3JQPcGewlf6P2xNN8uk+IDME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027768; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZjeFygd6IIkR9M2DIG513e5CPYAFIDSvTnL6qX1fRv4=; b=Y1xgM2+VemLmrywHo4hjzbfLea0rGd/cK9M8GaiPVNXs5epNJMsSAp09B2V4v3tGscnQ/NLfxdAvG3+7Xrayua7ypVZ3tnY0qqBXICTOjCzxAqA9CSoc1x0LTh22UHYoVl4TooX/9/X9zbBjpc8QBoO4HeiBPi5A19PIEtSKDgY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027768303969.37100176205; Wed, 2 Aug 2023 18:56:08 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlH2iOQ7D9qdecxyJCtqEe2zwKmtfYJXOWOybcUWsFvxwoKCOa5ruCVzJNBc0K0E8S52/nLmNA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027770136100001 Content-Type: text/plain; charset="utf-8" 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; } =20 - /* 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 =3D new_host_brk_page - brk_page; mapped_addr =3D 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_PRI= VATE, + -1, 0); } else { new_alloc_size =3D 0; mapped_addr =3D brk_page; @@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val) target_brk =3D brk_val; brk_page =3D new_host_brk_page; return target_brk; - } else if (mapped_addr !=3D -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 =3D -1; } =20 #if defined(TARGET_ALPHA) --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027705; cv=none; d=zohomail.com; s=zohoarc; b=DZjDfPNNivMhIQjBYf7YEdG4M76dbgDHwMWt2nuk5mBJN1Gl1I3d5AUTsul5eZyX17oynO8Q/UBP+XQjMK9Tj8hkJCev+rws5+KrsIRANIdvRAZYv9nwnSuttX9QuapwBn7BU0qt70ahRUMoS0BN65kh6SAWxjFdX6vA9DrjB2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027705; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; b=e90CAzi+gZV/zkhoygSYNYqcEJkeoRS1BzQq5C0h1aXoXQiIJZfCtdDOSw+8hlumIl+xb+Ga/5+L7Im0TdWBcWn5kc1IMo+njKt8ooeMSyTlT/1pNm9qL3cj2C2ltkRsxTEGyokqyAQgjllVvBEI0PxJSt4+2nrx9aRvxFytkzg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027705682970.8367463478518; Wed, 2 Aug 2023 18:55:05 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlHRJhIzCrIepObEKJMpvW4jhaD7jUvDWnjt/WRTza1TaYBQips8yRKx1SxeloTS7wOAIxBlvQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027707781100007 Content-Type: text/plain; charset="utf-8" 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) =20 /* brk pointers are always untagged */ =20 - /* return old brk value if brk_val unchanged or zero */ - if (!brk_val || brk_val =3D=3D target_brk) { + /* return old brk value if brk_val unchanged */ + if (brk_val =3D=3D target_brk) { return target_brk; } =20 /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { - brk_val =3D initial_target_brk; + return target_brk; } =20 new_brk =3D TARGET_PAGE_ALIGN(brk_val); --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027740; cv=none; d=zohomail.com; s=zohoarc; b=FaPS7VcDDGCK5wkkq/OLYxW4FSfJH6Z/9XvwC8Xl5SXm/wAglbs0chuk9f/BFQESqi7iy6h135iUUP5Udsx/oYuhrE3i7OcCFCrJtc8MCAUl6xlUCXvfnMekbDg9SNQWqLUDJzByy9xZu/qyot2y2baZnKbOZpvcoXNc3VdhTlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027740; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; b=iSbokIGl0VrrNapw8nm9bwPLo+RO3xOh5FADFVdeoSeDgkPgyy54UIi5GAVbdHBIvmrq44+D6JOndFcTropN0L/1UdF2202I5j3GyqfbnbK3F/SlF4N0lwGR/xnxkrz2jb0EeR6ow5HHSBPvXt0lNQ+sHfN9ES4s9DXwRCtiHt4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027740207639.1985597007933; Wed, 2 Aug 2023 18:55:40 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlEGoP8WhRzNwOFp9KjokW+qudsAzzhPLz1uk9YxaEPL2KbxJF2S0W57Fk8s671TB1IP9SxXRQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027742420100007 Content-Type: text/plain; charset="utf-8" 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 =3D HOST_PAGE_ALIGN(info->brk); - abi_ulong end_brk =3D HOST_PAGE_ALIGN(info->brk + info->reserve_br= k); + abi_ulong start_brk =3D TARGET_PAGE_ALIGN(info->brk); + abi_ulong end_brk =3D TARGET_PAGE_ALIGN(info->brk + info->reserve_= brk); target_munmap(start_brk, end_brk - start_brk); } =20 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_t= ype) } =20 static abi_ulong target_brk, initial_target_brk; -static abi_ulong brk_page; =20 void target_set_brk(abi_ulong new_brk) { target_brk =3D TARGET_PAGE_ALIGN(new_brk); initial_target_brk =3D target_brk; - brk_page =3D HOST_PAGE_ALIGN(target_brk); } =20 /* 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; =20 /* brk pointers are always untagged */ =20 - /* return old brk value if brk_val unchanged */ - if (brk_val =3D=3D target_brk) { - return target_brk; - } - /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { return target_brk; } =20 new_brk =3D TARGET_PAGE_ALIGN(brk_val); - new_host_brk_page =3D HOST_PAGE_ALIGN(brk_val); + old_brk =3D TARGET_PAGE_ALIGN(target_brk); =20 - /* brk_val and old target_brk might be on the same page */ - if (new_brk =3D=3D 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 =3D=3D old_brk) { target_brk =3D brk_val; return target_brk; } =20 /* 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 =3D new_host_brk_page; + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); =20 target_brk =3D brk_val; return target_brk; } =20 - if (new_host_brk_page > brk_page) { - new_alloc_size =3D new_host_brk_page - brk_page; - mapped_addr =3D target_mmap(brk_page, new_alloc_size, - PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRI= VATE, - -1, 0); - } else { - new_alloc_size =3D 0; - mapped_addr =3D brk_page; - } - - if (mapped_addr =3D=3D 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 =3D target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); =20 + if (mapped_addr =3D=3D old_brk) { target_brk =3D brk_val; - brk_page =3D new_host_brk_page; return target_brk; } =20 --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027714; cv=none; d=zohomail.com; s=zohoarc; b=VNYDAIw7qC5xjaGcCgETKn/uxdQak9LlVGTwoB2XRAwQY0SyNyvF1RhDXuAOxSkURYTjRWvQj4DEPquPqMxI6hcTVw/IXbKWMpVO6lAnmjMM2oeDe7HkV3QZ5aOodUA+PtoR2QFFxcd31bB9/JG9eeuBl0TZUhMUar3f9qm2rmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=S4pOOuQWmq0xrR9pkY2S2VlYgAJ/fJTzo6NDmQNEUSw=; b=bDfZ5si3KePiuwtAFoDsJ8AU6kd0kYdb18WMFn6tMzq7yeSpkmnEoJm2CugXdAycYmnT8ZaLOsulNLdMzPTLJwcLEnIqM/NiWSOnnIioxeak4noYyzfswHwBCL1qq0zwJyMPSwV0a9QJkpwEw53pq/AHub0ArEzneqga9AkRt1c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027714253270.82192919721797; Wed, 2 Aug 2023 18:55:14 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlHV6mgELKGF8gGAhcP6/j8kRc/yMEUOPeiwX1GTV0r4HjHyhmn1cjJkRuEljlt2cWAtB+1dNQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027715887100005 Content-Type: text/plain; charset="utf-8" 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 s= tart, abi_ulong last, #endif abi_ulong mmap_next_start =3D TASK_UNMAPPED_BASE; =20 -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated * a chunk of guest address space. --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027772; cv=none; d=zohomail.com; s=zohoarc; b=FBYRcHRTf6NJr2cSbpMahVwS+9yxp4Q1UrTbmZ+6Kd9NBwKi87Jjxw2/M1vHzMofSxgk/59K1uWuS2YK0O8pcmfdkCFyBozLQ1BZl67aULiPt5aa6FH4YCXuPOJLQ+J6YaHUnamQddNnkky+uQgQalY58IB5kSqmucQF6GkFq2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027772; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; b=gm5GucmBmQY/af6GFGRrIuiByYzwzwQYGTSaC5T99exflUi345g+qj6jBWFV8P8C3RLJfPtIZD3JSbXsvgi/D+duxEIwe0ScO+jJB1KPZhsmWEIdZf4losOmNAaocb+tX7ez3i7zlG4kpp57ZFo6pgWmb6A3zdDXMyjCb/l8R9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169102777231580.64515991223936; Wed, 2 Aug 2023 18:56:12 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlHmElRa3ZYqa7wPJ4o6ymeDF7/XyAFwZ57T1pvx6DFftVauRcBdR0plyaVfUEuL4k0WgkYMzg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027774107100003 Content-Type: text/plain; charset="utf-8" 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 ol= d_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 =3D TASK_UNMAPPED_BASE; =20 -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated a chunk of= guest * address space. --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027754; cv=none; d=zohomail.com; s=zohoarc; b=l3egdYZ/WDe66HrGvlLnZ0wBx8W4SvJvEn8WXbSixfRNq1IXfFUUpiglr4R9t+E7LVeR+u+wObX9bYN8NvsmuiOKK4LI7vShv/uFlXPDKAx5nVe4mvh8s9SUQ4kfS2H3lgrFhR4VV/UiRXMpVz2A/yTylndsaV/u8BPz0yiTvoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027754; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; b=KhM67u4zQcYgmjfYZ+SsZbOvw9FsTPPB0jnKIqzr3hjY776KrqYHoDuapsl6rvHEf36RJLDsSqRQKdelodmLUXuQKV1/az4wf18Bnd/dvishPhYN3gvG2gqaAvDebwIsQfuS/iTv/syTUDv6gtKoCNwhQ+bJXegGZ7OLMJ8Hqsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027754921647.3183823223716; Wed, 2 Aug 2023 18:55:54 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlGedPsXXyNlzRgbJgDnBzNDDqeCqrUPk4wY4L6M5i79OxiL11wg2omhDK8/eVsTUCsqr3Ncyg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027756132100001 Content-Type: text/plain; charset="utf-8" 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 =20 +#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 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 =3D max_reserved_va; } =20 + /* + * Promote X and Y to a common type and compare. + * ??? Perhaps better to locally disable -Werror=3Dtype-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 =3D TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base =3D TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (LESS(TASK_UNMAPPED_BASE, UINTPTR_MAX)) { + task_unmapped_base =3D TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base =3D 0x10000000; + } + mmap_next_start =3D task_unmapped_base; + +#undef LESS + { Error *err =3D NULL; if (seed_optarg !=3D 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; } =20 -#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 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 =3D TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; =20 /* * 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) =20 if ((addr & (align - 1)) =3D=3D 0) { /* Success. */ - if (start =3D=3D mmap_next_start && addr >=3D TASK_UNMAPPE= D_BASE) { + if (start =3D=3D mmap_next_start && addr >=3D task_unmappe= d_base) { mmap_next_start =3D addr + size; } return addr; --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027678; cv=none; d=zohomail.com; s=zohoarc; b=HX2V+qNLKO3iK4zn4bHgopO6s9KfSjk+X5U0pPWbt8xceJBL+KbG2sbPg0b2BO+CJhm5oOi4tf9xdoJu8bq1EWqPQhg+jTIZ+L+WyK7XORoCrbUS1yHXzd3ggvEx4vGUv4cNsjssJuTd4JmBoLlf8t+jN44PbXbuw1anLrOYuxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027678; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0g0cVRguWw0x7PzF0MB98ECj4OyJgpksU9rKzq3J1ck=; b=HxjKvFAtsjuf6Rqf7EtXkCrM4EU9svFBJNRl0+hUSGwGIM28yq1YPTrF7Ba4SEQuFG0QcXuXx8eGeFO9YNUEqfsFyLPkbRz6aNm6DlV432GBGgsklFS5NZSlpa/6AJbsAa+UOyOZu/AAVF44H9sTEmuTSYwWWM6hfGuVu0XsA3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027678272941.5948266113985; Wed, 2 Aug 2023 18:54:38 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlEFH7shS5k9EHytp/ot0Vo925+d2wOh138+NGdg32eiqA9EFLDuvIVgOim8IXx9bpn16yoaQQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027679736100001 Content-Type: text/plain; charset="utf-8" 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_m= man.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 =20 +/* + * 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" =20 #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 =20 +/* + * 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" =20 #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_m= man.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 =20 +/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" =20 #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/ta= rget_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 =20 +/* + * 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" =20 #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 =20 +/* + * 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" =20 #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 =20 +/* + * 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" =20 #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 =20 -#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 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; =20 diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mma= n.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_mma= n.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 =20 +/* + * 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" =20 #endif --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027735; cv=none; d=zohomail.com; s=zohoarc; b=fXO3mRVZhCeINut02s5h/BQzNmD8Z9kIa98n7ikSCECvAQZgKh1Y3k7dfujDgiqdqXDCnBVXgJ03+ZfC14c49t0fAt3vzkIKETeMlcEPz/pvO51Mqdi2tTV5l6kfwUfbMu2D5/qDFncAehsnkr8XQAt49lMraQXNKmBQYkAjCho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027735; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p6THWkmOL3up/JWfXdBzKttFod82ENPWZNu0IzoE7Eg=; b=iNro5oLpcRbLVyYLSu6CrUG+JRSf67HDPIh0o4rjUm9TPL5rhPlKkqe97iMOHW7WtM92cGp6+/zBqx23g+9R/MrKgJncQ4ypuKWTzwMoOdPFw8VnrVmn6EMhGTZv2IgZre6otL2uhOyC1QgptRxZgNum4uJlJITbxl8F0TzvAXU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027735540756.2639923321; Wed, 2 Aug 2023 18:55:35 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlG9qHgBfjJYnlRLgvLqlhMzGff4b4nUTzYpPUCmV7EpddRfjPsES7K/IwPzm2JodAY4lr/aRQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027737059100003 Content-Type: text/plain; charset="utf-8" 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_m= man.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)) =20 +/* arch/arm64/include/asm/elf.h */ +#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2) + #include "../generic/target_mman.h" =20 #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 =20 +/* arch/alpha/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) + #include "../generic/target_mman.h" =20 #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 =20 +/* 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) =20 +/* 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_m= man.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 =20 +/* 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 =20 +/* arch/parisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) + #include "../generic/target_mman.h" =20 #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 =20 +/* 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) =20 +/* 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 =20 #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/ta= rget_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 =20 +/* 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) =20 +/* arch/mips/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" =20 #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) =20 +/* 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 =20 +/* 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 =20 +/* 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" =20 #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) =20 +/* 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) =20 +/* + * 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) =20 +/* 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 =20 +/* + * 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" =20 #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 @@ =20 extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; +extern abi_ulong elf_et_dyn_base; =20 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_mma= n.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) =20 +/* 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_mma= n.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)) =20 +/* 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" =20 #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 =3D task_unmapped_base; =20 + /* Similarly for elf_et_dyn_base. */ + if (reserved_va) { + if (LESS(ELF_ET_DYN_BASE, reserved_va)) { + elf_et_dyn_base =3D ELF_ET_DYN_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3 * 2. */ + elf_et_dyn_base =3D TARGET_PAGE_ALIGN(reserved_va / 3) * 2; + } + } else if (LESS(ELF_ET_DYN_BASE, UINTPTR_MAX)) { + elf_et_dyn_base =3D ELF_ET_DYN_BASE; + } else { + /* 32-bit host: pick something medium size. */ + elf_et_dyn_base =3D 0x18000000; + } + #undef LESS =20 { 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 s= tart, abi_ulong last, =20 abi_ulong task_unmapped_base; abi_ulong mmap_next_start; +abi_ulong elf_et_dyn_base; =20 /* * Subroutine of mmap_find_vma, used when we have pre-allocated --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027739; cv=none; d=zohomail.com; s=zohoarc; b=lbls2qU1ih1fkXzOEdHuC6Sy6XvzauGfwbhery5+ZxxsMzlX8I1jsG1ay6T2JIYaP6MwLZW1Xd2JQDnjJ45b6TGMhwAGoFOP+wrtGosfKbBLfyR1jzkwmlwI1W55p+uQEcvAh1M/wuFErxl5na2beLKNe01RY7aAwu9VA4aWOlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027739; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ChEUXUgAPSYhXU4GN1bgmHxBnAzewX2kPCgTDo1jgOA=; b=AuY5igNd7eO+Ej6Do6kjPHIcVc+6wCt1scRTzTfPy/wthJwOzUQsVm8217NCbrMcQglqdgeQynzauF28mPDCmw6F8ku7wYPkX4TLoiL3MRxJYA9PEOOeCwInfR5QWA60dAz93rb8oPCTAo3ZdBMVXxeqHwhwMIgwH3xVLgZYyXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027739143346.75593453403064; Wed, 2 Aug 2023 18:55:39 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlG1VS8EKLn8UdhaaIHjomgWPKMK2/uOHBeZ7LmPDijgsPnnZdLh09wdtAJ1PrZIylyKHPQDuA== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027739978100001 Content-Type: text/plain; charset="utf-8" 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, in= t image_fd, struct elfhdr *ehdr =3D (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 =3D NULL; =20 /* First of all, some simple consistency checks */ @@ -3106,6 +3106,19 @@ static void load_elf_image(const char *image_name, i= nt image_fd, } } =20 + load_addr =3D 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 =3D=3D ET_EXEC) { + load_map_flags =3D MAP_FIXED_NOREPLACE; + } else { + load_map_flags =3D 0; + } if (pinterp_name !=3D 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 =3D 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 =3D pow2ceil(info->alignment); + if (align) { + load_addr &=3D -align; + } + if (reserved_va) { + load_map_flags =3D MAP_FIXED_NOREPLACE; + } } } =20 @@ -3157,10 +3193,9 @@ static void load_elf_image(const char *image_name, i= nt image_fd, * In both cases, we will overwrite pages in this range with mappings * from the executable. */ - load_addr =3D target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NO= NE, + load_addr =3D target_mmap(load_addr, (size_t)hiaddr - loaddr + 1, PROT= _NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type =3D=3D ET_EXEC ? MAP_FIXED : 0), - -1, 0); + load_map_flags, -1, 0); if (load_addr =3D=3D -1) { goto exit_mmap; } --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027669; cv=none; d=zohomail.com; s=zohoarc; b=W5XdV1TGpYzaWLQK6WOxe7W+qKxt6W/sdtD9Ox1VbO7tjbLjIShkqBxQhWpwktp12IEu5pSnsl8MeQfsZipORoOXKATJr/grxW3Jl75IirBF6plAngGOecp0zn/3fo5DhF+XGH4gcjYlIDTaB5vugxIMBkjUWzixEK+4lse3d7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027669; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iTYiVzZgwnSBm2cJQnzOd6IorKWpOrXyW6rl98Yh7OU=; b=ZutJG9/2eHGDGEGZyMsoOwloFrjLgXpG+aguH8XgwopI2XOg245ESsdr4oWJa190pk0TZ96rXyfIy6HiCAMYkHOkpvwwmTNlXafQw7Q7Fl79mSFLnb2rAg593S5PFHtk7kiQXn9Jqs0vBgj+NCrF1Hsj8rUCfZIkpbPMVsWnzSs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16910276698509.781380113232785; Wed, 2 Aug 2023 18:54:29 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlGaiqy/UtRBX82ddqB39MCco4eenv9p0Fd1rhL1e8d7zmvX5AaIYMs5YzuzjXVJEZknmlf9pw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027670840100009 Content-Type: text/plain; charset="utf-8" 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, i= nt image_fd, load_map_flags =3D 0; } if (pinterp_name !=3D 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 =3D=3D 64 - info->reserve_brk =3D 32 * MiB; -#else - info->reserve_brk =3D 16 * MiB; -#endif - hiaddr +=3D info->reserve_brk; - if (ehdr->e_type =3D=3D 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, in= t image_fd, info->end_code =3D 0; info->start_data =3D -1; info->end_data =3D 0; - info->brk =3D 0; + /* Usual start for brk is after all sections of the main executable. */ + info->brk =3D TARGET_PAGE_ALIGN(hiaddr); info->elf_flags =3D ehdr->e_flags; =20 prot_exec =3D PROT_EXEC; @@ -3323,9 +3303,6 @@ static void load_elf_image(const char *image_name, in= t image_fd, info->end_data =3D vaddr_ef; } } - if (vaddr_em > info->brk) { - info->brk =3D vaddr_em; - } #ifdef TARGET_MIPS } else if (eppnt->p_type =3D=3D PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -3654,6 +3631,19 @@ int load_elf_binary(struct linux_binprm *bprm, struc= t image_info *info) if (elf_interpreter) { load_elf_interp(elf_interpreter, &interp_info, bprm->buf); =20 + /* + * 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 =3D interp_info.brk; + } + /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ =20 @@ -3707,17 +3697,6 @@ int load_elf_binary(struct linux_binprm *bprm, struc= t image_info *info) bprm->core_dump =3D &elf_core_dump; #endif =20 - /* - * 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 =3D TARGET_PAGE_ALIGN(info->brk); - abi_ulong end_brk =3D TARGET_PAGE_ALIGN(info->brk + info->reserve_= brk); - target_munmap(start_brk, end_brk - start_brk); - } - return 0; } =20 --=20 2.34.1 From nobody Sat May 18 23:44:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691027697; cv=none; d=zohomail.com; s=zohoarc; b=jEucI7aho0EIHh2MCVhRDoJeUZ+Y+Ztancpo+mn6el56lwn6La8u5Lpdzyv0Wlrdo6qMn5BXO7mkr9tkCeDDc3sRaZIPnBLp7XpfPut90vwr+U/C7CW4EWt+rJWJpU+E1aFxz3K4kr60hErldOLqdJLgUrCUVdXTHT9KTQ2ormc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691027697; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=on5r7f0kRrvLwtEMgkqNRJQnFQG3tYk+wVcG6tCyF5I=; b=GvrDHCKAR00++xXy1Sxa5XVO7hHmcGLf5iOErkiS5kaelaz3STMD/BkOyjzr0qoSo806+Tk/rTOxTZKr86iwdEcQBj+ekLep+pwiEkF0EEeGW6TmwQD00md1V99NWyEIOMElinudiAmrSrr9X4uMGhrhHT8F2ZB6+JpaMxFpAro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691027697451644.1512501083888; Wed, 2 Aug 2023 18:54:57 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlFmH+6sJ3azm6YpLj+ARnMtuWRn95EZsU3Y4k7Bjm32usbJ7r8FAhNe1okLgN0J86fZtDWwTg== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691027697714100001 Content-Type: text/plain; charset="utf-8" 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 i= mage_info *info) info->end_code =3D libinfo[0].start_code + libinfo[0].text_len; info->start_data =3D libinfo[0].start_data; info->end_data =3D libinfo[0].end_data; - info->start_brk =3D libinfo[0].start_brk; + info->brk =3D libinfo[0].start_brk; info->start_stack =3D sp; info->stack_limit =3D libinfo[0].start_brk; info->entry =3D 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); =20 - 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", --=20 2.34.1