From patchwork Fri Aug 4 01:45:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710224 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233375rwb; Thu, 3 Aug 2023 18:48:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxwE0fiMJyagfZINv1DQCwvC/TP6gwmkWKbvdHQa2AVFKqtnm5UNO9FpCTsqGLzGZKEWN3 X-Received: by 2002:ac8:5bc1:0:b0:403:97e7:e1a1 with SMTP id b1-20020ac85bc1000000b0040397e7e1a1mr610145qtb.54.1691113694089; Thu, 03 Aug 2023 18:48:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113694; cv=none; d=google.com; s=arc-20160816; b=X6UKNEedOs4u73LduyNUbGWO52okOu4GK9K9OswPzhuEsR7+NjFlV/VBwwds7pu7TA QA1fVeYHXPE8ONkOjZfDAGMv3aVPNGL+fDcqUIO+MJhtrLwJrKp7X1FEPZyNIZGYFlkE Zk1xOFPmarpNcqMII+U/XMon2qk5AlapJDsaPF44FUJ9338kJDmYhtVk5HuAfUHnmkg7 iUXK7zIDxKXwDQN8py9RshNOKU7bbKdq8TmAX/tV2U8uNYF0kpbbOkgGoKVS9eml3ot3 HMLBaz9b9wnNYYerqJQ5rSmLY5ZUn7+3fJ8Qf/M9zHNE8UNlTh/J2Riymnt7QTzahp9G 4lDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rcpamkfhLDMnz/NSh+jJyfv46fJPLLdBfB4ohxEUnGI=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=yb6mv0K0U3eCEYntadT2ZQ/F5QtRMWCMgy6xqL2qJNZrNHXVEhdr2zfd6PPBHasNRZ eCVwXG9MVpGSeCY5yS9yBh7iCEl6roLBC3JzOKLbiKeJfWt63jl7O3+VKmc/raOXRtFi XYFpBVaru6f/vVo1umBPGTaWqTxa1m+6vfznMQfkLZMybBNorNfxqm6U5fhEmYDYTFol qBF1i/SsISuOBpxhxP001aUtEgmLui2ioDPZbEqN8fhGxgZzzLxFKdRPEovpT1GjIN8d uKld7k/tjvfxRG9/F5l3MXdXjjY/b+pxx/QNT8tW6HEGZDB99TkdcvwpnfxnvAP+tp91 t7FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/CFoL3f"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w17-20020ac87e91000000b00403e7bd5b1dsi616599qtj.121.2023.08.03.18.48.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:48:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/CFoL3f"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsv-0002gn-6A; Thu, 03 Aug 2023 21:45:45 -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 1qRjsY-0002cb-LR for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:30 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsW-00056i-Rd for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:22 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-564b6276941so353181a12.3 for ; Thu, 03 Aug 2023 18:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113519; x=1691718319; 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=w/CFoL3fiGS+wcGcDzl1NFRwUN99aU+rTAbbef7rHt2IfcrWgiwdfmLtRNBAWXOeTd p9aPXsj8R8kBcNhnYdu+LnrLJ9DTaW72ruso0Ijc2/MgQFuL7A8hdBy2+dLXCxQJ8ymj AdldVj3kV9dbOUkrM+DiWpMcDHLcufVaqKlTMxOj1pQqVNKH+teb7hDMAKAzs4DuscBZ VWmol1d2RRgxZ5o/ehSESlk+J8/jaJzv6ASFUUA12Uk9p8lTY0oqw/1ugJpX3tehX/se 6oXPUQ6sJY29c9DIPijN38BMDcM/oOFP8IZYPjgJYoFJJ1ypl2zMtVg1HRcNubdZc/j9 ZdBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113519; x=1691718319; 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=gpOpuX1m9/K0wP6ZqpiBOk7QoMqZw5dfF0hE7/FX6ez2wM1LTrpl4cNdsGcnAkyD6h J5vh1zLJ0yEnOBhM9HF6/0GF1OlRIi13uquzEAsDnbDgqYIrxFs7405+NqlHaJGyX1Ix q1WyPN+MXYgPk8wSEEoktll1Rsopt+stgnpDL9MwP6YVRkyfe0EfhZRDQoZoftgCrALR S1osiTGtTRt3O1pSX83PyqtSg5ZRaEg4QDYJPMIOIOV/iYdEi1UkiRH5JNVXvzG4kr92 6FJDLI2+pMYKaoSQnmg2O4vIsJqwr6oFHznGdrL8dhagj84w41Fkz0XqDL8U+7WIB9dX OZMw== X-Gm-Message-State: AOJu0Yx85lgOSYnn+283yc3gfv0TJt9RiQMQRGM+f0oH0koyWMqaVIpG ihSkb8gE/ZukmbZp8iUKJ2mtrnMLtbzCtryrOFU= X-Received: by 2002:a05:6a20:7495:b0:130:f6bc:9146 with SMTP id p21-20020a056a20749500b00130f6bc9146mr408826pzd.14.1691113519344; Thu, 03 Aug 2023 18:45:19 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 01/17] linux-user: Unset MAP_FIXED_NOREPLACE for host Date: Thu, 3 Aug 2023 18:45:01 -0700 Message-Id: <20230804014517.6361-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because the address space is reserved with mmap. Replace it with MAP_FIXED in that case. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-2-akihiko.odaki@daynix.com> [rth: Expand inline commentary.] Signed-off-by: Richard Henderson --- linux-user/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a5dfb56545..a11c630a7b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno = EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno = EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something else. + * We have just checked that the guest address is not mapped + * within the guest, but need to replace the host reservation. + * + * Without reserved_va, despite the guest address check above, + * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite + * any host address mappings. + */ + if (reserved_va) { + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } /* From patchwork Fri Aug 4 01:45:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710222 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233264rwb; Thu, 3 Aug 2023 18:47:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLBEyov7NEn7P2we1lmMI8DeK7RPOD2hO2qPdB227e1VMwVira2AQczkUEcV5O869a+0Kq X-Received: by 2002:a05:620a:2a11:b0:76c:7d2a:2dbf with SMTP id o17-20020a05620a2a1100b0076c7d2a2dbfmr743100qkp.57.1691113677334; Thu, 03 Aug 2023 18:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113677; cv=none; d=google.com; s=arc-20160816; b=W3GBzgihx8qiElbYbVXuQE4A4qRliJJyTQIevpj6u1U1wce6XAzivWoRFtbL70v/pK WTzeDn6+wgs+MER7gY7hDa5dsFopp1Nu3PXpEfhjNeJibOiEQYaLz1G+Kitm5DGEwFMi Kush4JsXMu79O5TKS+f1Y6g0JJkEFLbi/v9DLflKkaXT2U5cFhPY4sjw6IK1I8gsoQJO iF5iV3zPWvrAC+Ddm8E+EL4O50lSKR91aUUSkLayOZGy4kv0PycyVM18HErBydFKBsp2 4z1JLldIVRAE6c2TO1YeHTW2oBx8aqpARBMxaLDImRwWRRQRcb5/KCRJro2PgHp1jmcV sQUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/eOGiWVqZ8Y4POmSjtXETDABSVmvc7JlojTPUk6j1vw=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=sQ30a9YYxiHaM0QOv+LmumOR7yCaMdykknEFnYLBkQ4gC4kc8w/py1+Hqs+BrAZRMu AadGs+XNeRfn2JQivMmcuX9ZB6zBOl6jrvW4nfX7U6LaLa4pxd0SxWUVc3tplXLbQunL hRbpzu3F9gau6Uqb9sskq5Lq+e9b+umF/b2zN0+1i/mgbesYYPRz9Rn7bcVr86enw4ml eByEyEzPph9lP/1+M+r/aUs+c7uY7KzxnKdAOf5h/R+cCDK94TR0ajn7ChKqGMrcGOOz kslK6T5oC2+5oQqKOgYC7Jam10enM2J0Ei7uSmMHWUNYR23z9H9D69GGDhYhmFwAZ5fB VCNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kvL3PYYC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r18-20020a05620a299200b0076ca010259asi655495qkp.263.2023.08.03.18.47.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kvL3PYYC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsy-0002jk-Ow; Thu, 03 Aug 2023 21:45:48 -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 1qRjsZ-0002cc-PO for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:30 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsX-000570-Fd for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:23 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686fc0d3c92so1164024b3a.0 for ; Thu, 03 Aug 2023 18:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113520; x=1691718320; 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=kvL3PYYCNqPm2kdtbooz9RzzOkPGr5fnNUK05uskyW30BoIPIRc0KjNoY/I/l6vIsZ +8z7v/QcuomaO3/jGb8LiKkhXwId6j5GmHVZjIEPpktD6Jx8YB9xZ2d+bNj5PfSNysw5 25LeZeBdPRnjIsmTTFbH+VjPknyB+u33dxS51ORqY7AxzXxHAOlo3V5dm5PI7w9KB499 9702KVBD7hTvjrCqDp8he3ienJXCMJ9x7GNgsibtsNXsk6RH1FhEE669o/4LBbXFVMPZ y6hG6UMd6wkgrWJVdkMRfy66h6aNE+Wbgw/L3z3G/RNR8HfUNa3X76eoVmtBTs2jJL9k k8og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113520; x=1691718320; 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=QTbSapqu89jF/mr2DtE9+0uWK2y11gNlaADLw4UpnYs06gM9fIoGD7NObJpMbEi/68 MFsmWkdhWSt4IZHw3io2QL7YSKMj86BVChsOxFCin/Z+5f+yHugmih8KuDwKm+jfrTeS E0Vy9AjyhDunsL/6ZqnIOaQudJqbtBDOtX0J34VSq+0aY2BnC+qzur4AkVCY81VBkDo7 aqRr47Vfznlp/cJqkvMUWOgallg+KVO/RHC85/6eGwNp7osFautUay2qDg0XViqQk5MT BnREJu3+0KNz9n4k+xy6t+jGo07LejkBHyL/CYTuU9C+m8wA0TpXmxDRsB3mTPcLqM1K l46A== X-Gm-Message-State: AOJu0YzfwDDqTDMPtidj1iiG7bHJ6UHo9QAHdGx7NErFUtQMwkHy2euv azY93Pt5hrNkRU8O8+DQfRrWGeCsX8RwKx5lEmw= X-Received: by 2002:a05:6a21:4889:b0:137:9622:17d0 with SMTP id av9-20020a056a21488900b00137962217d0mr231190pzc.58.1691113520189; Thu, 03 Aug 2023 18:45:20 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 02/17] linux-user: Fix MAP_FIXED_NOREPLACE on old kernels Date: Thu, 3 Aug 2023 18:45:02 -0700 Message-Id: <20230804014517.6361-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki The man page states: > Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE > flag will typically (upon detecting a collision with a preexisting > mapping) fall back to a “non-MAP_FIXED” type of behavior: they will > return an address that is different from the requested address. > Therefore, backward-compatible software should check the returned > address against the requested address. https://man7.org/linux/man-pages/man2/mmap.2.html Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-3-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/mmap.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a11c630a7b..90b3ef2140 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -263,7 +263,11 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, void *p = mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { + if (p != host_start) { + if (p != MAP_FAILED) { + munmap(p, qemu_host_page_size); + errno = EEXIST; + } return false; } prot_old = prot; @@ -687,17 +691,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_last) { - void *p; + void *p, *want_p; off_t offset1; + size_t len1; if (flags & MAP_ANONYMOUS) { offset1 = 0; } else { offset1 = offset + real_start - start; } - p = mmap(g2h_untagged(real_start), real_last - real_start + 1, - target_to_host_prot(target_prot), flags, fd, offset1); - if (p == MAP_FAILED) { + len1 = real_last - real_start + 1; + want_p = g2h_untagged(real_start); + + p = mmap(want_p, len1, target_to_host_prot(target_prot), + flags, fd, offset1); + if (p != want_p) { + if (p != MAP_FAILED) { + munmap(p, len1); + errno = EEXIST; + } goto fail; } passthrough_start = real_start; From patchwork Fri Aug 4 01:45:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710225 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233377rwb; Thu, 3 Aug 2023 18:48:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFs34xYYbGIRKCWsUHmOJnLHTu27QNzoDVsJFsFR7P+rp0bofbPJ9AEM4TDdjRoP+dLLHFs X-Received: by 2002:a05:620a:4045:b0:76c:c10a:a1bd with SMTP id i5-20020a05620a404500b0076cc10aa1bdmr743545qko.4.1691113694350; Thu, 03 Aug 2023 18:48:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113694; cv=none; d=google.com; s=arc-20160816; b=IzfP40yZ8rDIc5KhZZHTodEsqw4soAMoPVHykyctqfXysXsnpHhLvfaK/K0CNh2xAj CLACSa90ELb2pSIGu8Y7VswHGNIjCToC4bigD5gKuEp4tXQb39dgXHfT7gPjfMMqzCrD /hwLDVmhLhz3J/oj+fmjD5KLQDf6uyi7Un/T+YpGKgru6nET3Akv+Kmx74XvjxmT9zS8 Ev6yP1QEVXqwAsNT1OHMQYgSnuhLhJTav5LOrNlim75V4b12u7R7wXetvxmrI3v8rErB 4z8h5jbB7LXGMpjGd5sfcGmhpkDEUWVBX+x5lxmS/KpZBpcOtxCcvpNfujKrnozhHj4U mZIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=wsZkFLtHiXLmiWh2ce2ZWenbXX33x1T56ulO8HSOGrJ+29p+hLbeuH4NIY+0ngjSba hCrPe9qUgA4MCExfHn0fs9Qgp8ESsCUE5Q1UBkZcIC00dYcmwo0lchg9GwLD6Dl+R594 8MrYzZDWdTTpyxiX3yPENsuBks6nbMaSrjGj3l20umFKy8IjZYG3Vle8LURCLSwxOO0U HubadTKOENcMIc98YklMqnJJdLGNL4sha9ph0SO8Cqn1k3gKqqj/4AnzGIUYWg9fyKcs 91XmfYjaZmRMjYupJqIz3cANHKEE5Jx6fODEh4pW4eLn/QgFEp0K3Cx/rICNFquf1MLz MWzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kcZtU3Yx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v6-20020a05620a0f0600b00765b0dc5ef0si610624qkl.510.2023.08.03.18.48.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:48:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kcZtU3Yx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsv-0002h7-MM; Thu, 03 Aug 2023 21:45:45 -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 1qRjsc-0002cn-Be for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsY-000574-Iv for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:24 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-564af0ac494so477455a12.0 for ; Thu, 03 Aug 2023 18:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113521; x=1691718321; 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=kcZtU3YxWpNkprmQXiWiLFO8ck28BThWvw9h+/g8UXdewLliVapiIV2LON3nN0xARz D9WWqZZ3mlsbi1cYQEOfrOb6fi78v5riypqLG9zlqPEL19hFb4AxpHqjQw9gVSz9Ij2V c4AarmcsMUWDQGtR44gq8i9Unf9hqOE1Az608HKWZvP9pQdSenhWUbtwQnnAxr4OWQlo EsA2VenyWIfhcf+X4d/vFrb7b5ZQIkh3vEcXeJiZ41IXOPKkbdX1gRJFqygDQZfN2zke nrojJyhVMUvbkUz5jStEd2to8ISsEDtk3OrpOEtrDd+fP6VbTlKgiFbMzFLB5aNaE6gU GDEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113521; x=1691718321; 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=IDCOIQoIPFJbA//K2K5mJAS9Km8YEmtYVh8gkBKSlwfMyoGhYjU2CS7h95/AhxrhRY +/Dt02ebFpyQKHq9GmPh8rQ7xJDwyHr9VW/ObhZQCPHQlzDvz+LTlJrZnzNUgUFWq1yQ wRQKet55AsCSC8BC6A/W1DvcQNzV/o11R3s9cO6Mz0DbDd6mYb8i0tlkkWuVt5YO2nms 5RK8Q6gKgf7EAT+QAU+PdZdUYwR1Yb2oTI9ZWi/EZUK1nU9fhCdiWa2sIohAhZRvGXWQ so49XY9qqgU2IgUt8Hv8TXKuaQcb8BGROqmY7Wwz7m0vuvS9UCy1izK2tTKvmgblvsrh B20w== X-Gm-Message-State: AOJu0YzNGwpawzTOJ04cu7nMIH6gBDjigpBr32VGBvmTZsjUUqhxctF8 NR908qU6ZJ1IXDUdAzf7nue62aMwekHARUPT9yo= X-Received: by 2002:a05:6a20:139a:b0:13e:f5b5:48f5 with SMTP id hn26-20020a056a20139a00b0013ef5b548f5mr206361pzc.27.1691113520936; Thu, 03 Aug 2023 18:45:20 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 03/17] linux-user: Do not call get_errno() in do_brk() Date: Thu, 3 Aug 2023 18:45:03 -0700 Message-Id: <20230804014517.6361-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Later the returned value is compared with -1, and negated errno is not expected. Fixes: 00faf08c95 ("linux-user: Don't use MAP_FIXED in do_brk()") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-4-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95727a816a..b9d2ec02f9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -862,9 +862,9 @@ abi_long do_brk(abi_ulong brk_val) */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0)); + mapped_addr = target_mmap(brk_page, new_alloc_size, + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, 0, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; From patchwork Fri Aug 4 01:45:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710215 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233134rwb; Thu, 3 Aug 2023 18:47:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+7QMslC/qHsRkIquUI5VhTsTf11LWT/lz0N28nBd0YyNTIyPA91DoB17WaEyRLqvMUtZ+ X-Received: by 2002:a05:622a:1822:b0:40f:e09d:3743 with SMTP id t34-20020a05622a182200b0040fe09d3743mr504689qtc.15.1691113654161; Thu, 03 Aug 2023 18:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113654; cv=none; d=google.com; s=arc-20160816; b=wTlJjy30mJaMkcbK27g41EzvFeR1rKzCWmVHIX91MpEH0WELKmoNi8GrqA52W1c1Oy EpOapGbXZR4eBHmzGwr2YnQuwiLEpNIubakZ8ktSKfPGBAuGbIIKTjFNSPsc3p+urann PVoz8ndz/KH/A45O/kUOHJ2bmD/nBYI3p8H3gXf6A9qkdMHWN9iozp7U+l1ugZnB3d4L cYmSpAYgchz5O6yptBrK0aiFAEdYpPamwH8bbZcomNi8rzZvHBQgrSvy1un1ykFXqvOC UAULTOa0vV4d7RL0JnXflMzdokhjmVwNZSIpv0sHjZSgjFkoMDzldJhiX4/MxargN704 avEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZjeFygd6IIkR9M2DIG513e5CPYAFIDSvTnL6qX1fRv4=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=VwUrJu+g83zNx3DJtzglg+glfF8BZ/7upYbLnofwtH6bRytF9xvelkbktL1VTvcHVz 4zRF3tebgsFTKyWdzzDJdTIFmcPNWkzwNEPn37HShelByG/KbdR8DlZZ1BW8BbodIO0I jufMuGDKlcuifoj8Til3JZSOg1jDs+rwuYP8BdAOYW7fXxYdiZTr7pHSEtUkYhquZHdp EBE59WESWdQ8E0vKvpBkfda3yCsT88ZcDZ4vnE68tLYAWdqzdtrvjPs5L5f3lRtTIF5C K4Va68yO/WE4rx0rqMnvZUe3f0zKrD+WFDZfOv1vz6Eta4KTV2enNdIMuGyKRA1gKbQ2 G0uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aWD5SYAO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o18-20020a05622a045200b00403e72e49f0si596644qtx.783.2023.08.03.18.47.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aWD5SYAO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsr-0002fa-HZ; Thu, 03 Aug 2023 21:45:41 -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 1qRjsc-0002co-CK for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsY-00058m-VB for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:24 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686f19b6dd2so1183660b3a.2 for ; Thu, 03 Aug 2023 18:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113522; x=1691718322; 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=aWD5SYAOqOrW8KVpkC/8GTDCWzxvrXTEJiXrbjpavdfbS6fsurSzd66YcblmUd8aq9 0F2Jrne0Aczwlw7LVR/8ddOKk0p8NYhcw60AJV6jNywdoAepPRSkG/+FyMBC+iGRDwtt QqNPKFjO5xsShxXE3aSWnTOuqK1gfzQRTStySWnc6MlPvb8cDO55R1wMdWzWp25x4O9Q 3k9GDji0nJMulTihAN/z8xrZnnE3goZgAxUYpGJWoRjgXSAlAgA98D3LBEybJ0WIplZO 1jfPbjEElSoscC7F2eAsbG1BiZxcDXT5O2R3ra6DwMtaS78EMXv2S1T+9ykGXm38N1n+ 27lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113522; x=1691718322; 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=gUspSzCZhL20zM3A5ZqxIBoGdCwtIuWt5EEvgYlMgR3i2BBR9wSM2+8AEW4RpgXfIW xv9Q1eYHnakyrEL+B6968HiM+pqs5CLdjOSFfJG6pMuERE+hUPyaBJJQrpbeffr7mD+2 Q9TxVZaiIIrIOPm9v22KZSzhSCUv8b12c7+V00zfNZAxIRrLyQDeK16doSFClx1Uz5RO rQNOdNl//9wu1MyZi9pKDYVNRTkECsG0guEnqH2VvafBim3375w1HqkfIHQET+0yapmX E5Gveua2vB5MtlKLrb/j3Z/jw4U4VmCx/DXGQsD7B2uiY1tvsT99Bf4RZAHFvsCuCkXq rODg== X-Gm-Message-State: AOJu0YzAX2LisuSLIQKlIHgOo5e3oS4FhOiigCUZOWtJXjvtdlg+6Rph bnkED2OOU/5kE42PbmVS5XpJMIrOBiHeSq8VKQg= X-Received: by 2002:a05:6a20:9191:b0:12c:f124:5b72 with SMTP id v17-20020a056a20919100b0012cf1245b72mr278850pzd.43.1691113521699; Thu, 03 Aug 2023 18:45:21 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 04/17] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() Date: Thu, 3 Aug 2023 18:45:04 -0700 Message-Id: <20230804014517.6361-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki MAP_FIXED_NOREPLACE can ensure the mapped address is fixed without concerning that the new mapping overwrites something else. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-5-akihiko.odaki@daynix.com> [rth: Pass -1 as fd for MAP_ANON] Signed-off-by: Richard Henderson --- linux-user/syscall.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b9d2ec02f9..f64024273f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -854,17 +854,12 @@ abi_long do_brk(abi_ulong brk_val) return target_brk; } - /* We need to allocate more memory after the brk... Note that - * we don't use MAP_FIXED because that will map over the top of - * any existing mapping (like the one with the host libc or qemu - * itself); instead we treat "mapped but at wrong address" as - * a failure and unmap again. - */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0); + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; @@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val) target_brk = brk_val; brk_page = new_host_brk_page; return target_brk; - } else if (mapped_addr != -1) { - /* Mapped but at wrong address, meaning there wasn't actually - * enough space for this brk. - */ - target_munmap(mapped_addr, new_alloc_size); - mapped_addr = -1; } #if defined(TARGET_ALPHA) From patchwork Fri Aug 4 01:45:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710216 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233170rwb; Thu, 3 Aug 2023 18:47:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXl7z3JhdP7y4sO+tQYA/MU9EltQSYmC9T285zDPPYfmLHty7EAwpUU0C1qRVoS2Yb/cH4 X-Received: by 2002:a05:622a:15ce:b0:401:e1e7:a2a4 with SMTP id d14-20020a05622a15ce00b00401e1e7a2a4mr664051qty.35.1691113662423; Thu, 03 Aug 2023 18:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113662; cv=none; d=google.com; s=arc-20160816; b=WMmOpieGTOCGxuXklfxioYYSU6FmyamTF4I5sGW40QHY6L1Yd+VvuLsee44+8Yp1wu uGYkaoxkRJBunoOqFuzJ19jw9NbKMr2NDgWp3P6C1IJ4fyxxs24Fe6U3rqwwmi5RcAcx i6dXLFw0qEcWelY8nuvZWvjJTIVwIRPF4LnmOv3Fct8cIMV1cfQonJOV+wyofulkOpbF GP456yACrQv2HlFGXRxJCxjgkTO8xqmaYJBFbJ9cCsQs5tGicBMlA+d5q/wg1THnT7Hp cfN0lIjfNzDdLkYPQ2zpMHHcaGy6PggIAFl5H2avUFnBuunmM1lZXjpuKGKMd/fhLZgB goWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=bepbjg0n78I7FjvJdguklKoyDUxs0/bORYokGV3d1h1hrwaHTLhb4/62pQIScaV3eI 32RQjLvuy4f4i1LJP33RoHLbFBDz/zVAtrNVgbCckt3k6Kl6EGqIfRjHTEkduH49jvEO Tb0C9V+baHIueMSIXHygtvzaMwK7oDsgroqsXkOxB2oWEusU099yNprQx8CbT/3k0dyV CP9BLyQPZ6WshxYdkjKipLKIG2lAMfhkHVYjUwDfj99Xu4Px8wjVcEEurFYsOpQsL3Du sdWoc38hByaTJhhpZh4gerIpOIfYNwJxZYwSKssVlDhthEMRuKiEAkm5oqjm4CxjjAwJ E+Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hezjGjvI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v13-20020a05622a188d00b00405435d6c52si632294qtc.393.2023.08.03.18.47.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hezjGjvI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsy-0002jQ-2D; Thu, 03 Aug 2023 21:45:48 -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 1qRjsc-0002cp-Ch for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsZ-000596-OF for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:25 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686e0213c0bso1190384b3a.1 for ; Thu, 03 Aug 2023 18:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113522; x=1691718322; 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=hezjGjvIUwn7VHvPnCOepORUiXejBF9owFMLMPDqZjEmKd+mZlZvDkYFVnBRdqzirF C1KRCpqdpxAxQQZ55NFTDMtPAbIShopqEUbcwzqZO8qfR5tHtH3hwvSzZioXG8z2cRBS BUjFKelcz05tuJI3VmR5nTOfzrIp1845yJgZKCwo8bZEBz20rHpXPgB4ucVjulqlzZBz PpTUOATIcsLpF3LfBpJMKtws8m7UIKeo6hyHGanEzJOglUZqw+DoYgc7gan4PU8jEeMf hkAVoFNwWcl3q1OK87RI9DbVP3nrum2RoLmIzkN58Q/aZ6NhC4rIcBqZZAN8UFGWnqFM PmlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113522; x=1691718322; 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=c9ItJdfNX+/IdnndqINKN9Kn5Bug34xGq9x5wf2e6dqlRbjfnX8cBnu3QYCsaxWTO8 mCv+ECDiaBwhDveFBa2GLMbU0fgTeZTpsfC+NSg2+8E3QYhwsRg/PCfEtENupY3XDXhn cc50n0nWn2tT+29xpsktRfhQcBydfFCPrg3YVWv15DkdGQGBhzsgGhurwKNOrLMBXT2G cYMQt7gtdXo+N+rqikUqxd9IycRjjS18Y3eAQXI71/saFCc2me1ek6tLBZXZ1c6d0gTL UTKdCy3MPdDujTSQ0NWbj148NFW2kdw3Z8i1BGQOx9pCYL0Sx+FX/OirT+YAoDtWQjKb +zbA== X-Gm-Message-State: AOJu0YwMXqKPy8NFfwPWep+yL2AtfUR3T9wkuv2kRnPrr3m/Br1t1KRj UgRg1TvEyqY4lAqU1dLzs0CFTMjzhGL28bcYXzo= X-Received: by 2002:a05:6a00:2301:b0:686:efda:76a2 with SMTP id h1-20020a056a00230100b00686efda76a2mr356858pfh.29.1691113522489; Thu, 03 Aug 2023 18:45:22 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 05/17] linux-user: Do nothing if too small brk is specified Date: Thu, 3 Aug 2023 18:45:05 -0700 Message-Id: <20230804014517.6361-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Linux 6.4.7 does nothing when a value smaller than the initial brk is specified. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-6-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f64024273f..e1436a3962 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -820,14 +820,14 @@ abi_long do_brk(abi_ulong brk_val) /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged or zero */ - if (!brk_val || brk_val == target_brk) { + /* return old brk value if brk_val unchanged */ + if (brk_val == target_brk) { return target_brk; } /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { - brk_val = initial_target_brk; + return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); From patchwork Fri Aug 4 01:45:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710212 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233042rwb; Thu, 3 Aug 2023 18:47:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpxFcdH3XQIhd0G0YHKTZSBYw1zhkITonahsE3+nYN04Lfq6hRgje9qdn9h/6bUUadLZLM X-Received: by 2002:a05:6214:4589:b0:63f:5ef6:df5f with SMTP id op9-20020a056214458900b0063f5ef6df5fmr353975qvb.43.1691113635488; Thu, 03 Aug 2023 18:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113635; cv=none; d=google.com; s=arc-20160816; b=P07BqDbNqMfaSYA/mSgFzpoG1ylOhe9HtXvGR8h3fcIElEwk6PYMSMG9vBgjuGAlSt ClA4NkywGOcbQXOyhUuf/C//V3IR25T1EhQDdB+6hGzSiPGaiWtolTCCOtXyxdm407Wr 4tyYbyuKDKOr7WJ13fyGdmsg6dSLdReQepOcJYBcJzz1sFWDnJQe9Zzi3eeldPj1kOb1 Vz2srg/VQAjDrFsXvMeG20jDRjFM8ZPuktqG/n7sHTJXjKrzeQLMqYn0NjM0UI8Uc/e0 m0qIu9C8A/NzI5HlGvugULcQyPo7jgnw5OaJ+kQQUJ55kDqA3VDHCOAs+YONBxAPOPu+ d+AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=0AXFia4nls+o5yicXp6Qi/gfG3KTSSCxo2SiZlqxH++f/eFPOhDQVsAIiR5+k2nCsD 9MwaMvcy/G3QaCaSmDuJI2K92DSClWvzHQ44/mM6qVgg0gqgZulxl6BUYV4D6KT8L2Ew GUuX5ZhKQMZs2wbgY2fl0QVr4uXbi0KhQme5+KMjh1zdPN6jTS10Xc/D8zBQJaVc1zcl eFsBplIiFh5gHF6pIKFPwdxU+ffoxKyFfqo8mKXbcZRZPcFNfYxSX07hg6EMOAhifsTM wrnVdop1Dxoi5vQuaM4TSlVvlqrhmk+ZFDG8uRsIXE7zV/toudH9CRNaTOcF4THTwhdB gNYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LCG536Fo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fi16-20020a0562141a5000b0063d1008687bsi589083qvb.361.2023.08.03.18.47.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LCG536Fo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsr-0002fZ-GV; Thu, 03 Aug 2023 21:45:41 -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 1qRjse-0002cs-5h for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -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 1qRjsb-00059L-PB for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:27 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68783004143so1183949b3a.2 for ; Thu, 03 Aug 2023 18:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113523; x=1691718323; 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=LCG536Fo/ZExLeWs9+9pBb8QjiKTqKx5mSsSx0AFTbVAZ8+9fVqWQjpp/IXXCSBH+D KXBjM6LuvcyREks6cc8wJsxdl46AiVDOrBG3VMXMXPqznODfQ6zYPo0RSPDobzlo66wR P/Z9LwiNTNYBpUFeTNsxgsUtDdIE+pIqexlFfBxMrBI6J0TeyLSBIkyDy0FySQ46ByoC f+tZZbCeDWGPuAD0WV5CfIrYwoZXJ9dOPrzItYEJy7cSGytwoWX2Nv2R+y7oAyBmW0GF MxttHZAztyD9Qmhp84R6O22o8jYWLF2DYh4Cko5ZsmKsOj6neqXSfrC+sWZ5hWOugTGj eH4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113523; x=1691718323; 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=XhoPpNwDIOm+q+MizJpYvkjCrB7yz+B2+WbgXtRSWZvSS7UdO2/ZUZwk+Y3mHXmVxe Sn+qX3dct6KxasG8Iz/+c7ftXb90w4qtQ5kr15VpZyE/dQIwzNS3vt/qp/GgW+MFVUCp +et3+/m8UfbzfYn9QB79l0L97ttSajCPFn6I0RFlp/+clBKNP1KZBc89+zaOt02rveZ6 2/QNRyz1f8QjgYonhlpEziLHmEegVPhvBQrS/kXxPfCbgkG998ruUgJC5VkAJpOW//Jq qfzlZUksIZErqz3gqC1YKSvjuMeE57buNjAkmtUQmTbQ7p2eVf5CONwJjFOxl5R6tyvU zANw== X-Gm-Message-State: AOJu0YxbF58GOvnTy6PLWhef9lv9+n+tivruPb9z9leqEQ6dWRcmGp/n 67XpZ0qqPC9k5wpcnPX3S8SY1OcyBHunxUyeefQ= X-Received: by 2002:a05:6a20:8f24:b0:12f:c0c1:d70 with SMTP id b36-20020a056a208f2400b0012fc0c10d70mr240094pzk.40.1691113523238; Thu, 03 Aug 2023 18:45:23 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 06/17] linux-user: Do not align brk with host page size Date: Thu, 3 Aug 2023 18:45:06 -0700 Message-Id: <20230804014517.6361-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki do_brk() minimizes calls into target_mmap() by aligning the address with host page size, which is potentially larger than the target page size. However, the current implementation of this optimization has two bugs: - The start of brk is rounded up with the host page size while brk advertises an address aligned with the target page size as the beginning of brk. This makes the beginning of brk unmapped. - Content clearing after mapping is flawed. The size to clear is specified as HOST_PAGE_ALIGN(brk_page) - brk_page, but brk_page is aligned with the host page size so it is always zero. This optimization actually has no practical benefit. It makes difference when brk() is called multiple times with values in a range of the host page size. However, sophisticated memory allocators try to avoid to make such frequent brk() calls. For example, glibc 2.37 calls brk() to shrink the heap only when there is a room more than 128 KiB. It is rare to have a page size larger than 128 KiB if it happens. Let's remove the optimization to fix the bugs and make the code simpler. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1616 Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-7-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++-- linux-user/syscall.c | 54 ++++++++++---------------------------------- 2 files changed, 14 insertions(+), 44 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 861ec07abc..2aee2298ec 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3678,8 +3678,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * to mmap pages in this space. */ if (info->reserve_brk) { - abi_ulong start_brk = HOST_PAGE_ALIGN(info->brk); - abi_ulong end_brk = HOST_PAGE_ALIGN(info->brk + info->reserve_brk); + abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); + abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); target_munmap(start_brk, end_brk - start_brk); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e1436a3962..7c2c2f6e2f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -802,81 +802,51 @@ static inline int host_to_target_sock_type(int host_type) } static abi_ulong target_brk, initial_target_brk; -static abi_ulong brk_page; void target_set_brk(abi_ulong new_brk) { target_brk = TARGET_PAGE_ALIGN(new_brk); initial_target_brk = target_brk; - brk_page = HOST_PAGE_ALIGN(target_brk); } /* do_brk() must return target values and target errnos. */ abi_long do_brk(abi_ulong brk_val) { abi_long mapped_addr; - abi_ulong new_alloc_size; - abi_ulong new_brk, new_host_brk_page; + abi_ulong new_brk; + abi_ulong old_brk; /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged */ - if (brk_val == target_brk) { - return target_brk; - } - /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); - new_host_brk_page = HOST_PAGE_ALIGN(brk_val); + old_brk = TARGET_PAGE_ALIGN(target_brk); - /* brk_val and old target_brk might be on the same page */ - if (new_brk == TARGET_PAGE_ALIGN(target_brk)) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); + /* new and old target_brk might be on the same page */ + if (new_brk == old_brk) { target_brk = brk_val; return target_brk; } /* Release heap if necesary */ - if (new_brk < target_brk) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); - - /* free unused host pages and set new brk_page */ - target_munmap(new_host_brk_page, brk_page - new_host_brk_page); - brk_page = new_host_brk_page; + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); target_brk = brk_val; return target_brk; } - if (new_host_brk_page > brk_page) { - new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, - -1, 0); - } else { - new_alloc_size = 0; - mapped_addr = brk_page; - } - - if (mapped_addr == brk_page) { - /* Heap contents are initialized to zero, as for anonymous - * mapped pages. Technically the new pages are already - * initialized to zero since they *are* anonymous mapped - * pages, however we have to take care with the contents that - * come from the remaining part of the previous page: it may - * contains garbage data due to a previous heap usage (grown - * then shrunken). */ - memset(g2h_untagged(brk_page), 0, HOST_PAGE_ALIGN(brk_page) - brk_page); + mapped_addr = target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); + if (mapped_addr == old_brk) { target_brk = brk_val; - brk_page = new_host_brk_page; return target_brk; } From patchwork Fri Aug 4 01:45:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710226 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233408rwb; Thu, 3 Aug 2023 18:48:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFX3f6ZUwRAtFcRLypHL2Qnpk6dU5B6R0cirkdWQy823KQtmWRpctlORpvhLCN0/KK2ggch X-Received: by 2002:a05:620a:44c6:b0:76c:af3e:3c14 with SMTP id y6-20020a05620a44c600b0076caf3e3c14mr534095qkp.71.1691113698200; Thu, 03 Aug 2023 18:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113698; cv=none; d=google.com; s=arc-20160816; b=jwHWF7PMab42l5+zdg4OogdoqbiSZcSwswcx8wra825fv/YHCndfQM1pR5DPSBETHo JycVKoRw2C8687gnIViF4YUBQ+cDY4OOWxtnnEvDdiovaW/qfHofqw/v9zLwC5XvqQ3t 7VcFNbslzOIWpAq2ObOOFkYtMBydAmTHmO55dUuFRxJJgOZk9u4ONkv7+5gNL+/ko3bM umkP4POhLWqa/ToSzi8W9vqAIDQFl6xfnvPrQJe9dnDfSz7wzd6vTKtplevcZ/wGVNML dO9NHeEUKuROrsiyWOIHA4vuHHlyP3w0S/+/7Ut3aLmxUswG7NR6RIyH+4TELI2w9Eg0 styQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S4pOOuQWmq0xrR9pkY2S2VlYgAJ/fJTzo6NDmQNEUSw=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=c8PQ+bC4bNAeojqKSpRFsiZR1BA9S2KtU4OtB2qKlwoK1NiULm1M5jiuT0dZeuc2KQ mCqg982dIWKMU86v6R83w9Nsws0Fapo9wZngNtM4JnrqopZVfm4l/s/FnCgFzzFmB00E v7DQGX+K2qUEccs72TbG+03fsBF8saZi2unYQmdEJJpNl/fwUiBl0CYegEWJ/Q9ocO9d C4gEc7oo5B9nd2BHydg0bI9NxFaUiwi2Qsft+ETzqmz86SM0+UqUx5ahrnGQpEAWB2TV AzQ81HRRZ61SPCqH9slSvu/Y491y22p61JX8JLDe/4u56bweE/GV8/EFVnVdkbhEF72Q gc2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xSyIUOh+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v17-20020a05620a091100b00767dd1e967dsi587605qkv.195.2023.08.03.18.48.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:48:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xSyIUOh+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjst-0002gc-Nm; Thu, 03 Aug 2023 21:45:43 -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 1qRjsg-0002cu-E3 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsc-00059e-4K for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:28 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686ed1d2594so1418022b3a.2 for ; Thu, 03 Aug 2023 18:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113524; x=1691718324; 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=xSyIUOh+RoJWrDmmPodBqLoqx556ANRBFz+nXQdmCxz/lT1UWXv3vVAGdVe7/EFDx1 wiAlw+hs9gYZOmmRAO8TsPQnapiPF0CRlQ7qEuitVZa3EaPvQyW+7qRKxqnzqDAuWI8m ErH3r4RybOmwCI5fFPnDGPQ2H82c4exx8GcaO573w8MxNuxuCCgJywAibAPdU9n95Q04 9n+oc9SSv9aRh5IHiZLX+C39sYOFcf4Jmh8pyr8q2x5MUhvZmx9+cShNaMOCrTyoxa/H 3E3aq/1BkPHnt7l/QmJ0fpVygReT/cPhrwbf3kAjNCZDoR2vdqReIfiv+fTMXhSJqMtj styA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113524; x=1691718324; 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=leVwbRIMJ+JL7Njdmuf+ULX/fl71KivrRp2yfbQpphN71t7qVj52sI/bo2DbhtmOA7 1v7PjjVtY/09f5Ymyhg22iL4B0JrMpyqj9L789SUa9HdfLkOPAeUKppo8i70lCadneoh OluRvtMvKB/bAahAXkU5qQL+7bVK4KVy+0ySTLenzM0F4zt5ImeOGKoWEi4mkmVZy2np 5sAzzpjg9UEIx1AcUxBKHjnfnDbmscLlDBcODwGGxjBBYV+sKMr0V9Jf4RyAmNcGSJoa 0svgp4g3QcWowwrdHlYF+xvIiW8Jbs6B5vBX9s1POhPRGxKrpJ6HmcipEyCOwLtkxzLp sqEA== X-Gm-Message-State: AOJu0Yy3LDiUS7JzSjhh0+W8CGpcdpvfNljNtr0ejvP1NFYji+kqDCCK gCoIlQ6vr9ajL62NoPi7URromx6XmYMQggoAXUQ= X-Received: by 2002:a05:6a00:23d6:b0:67a:b045:e290 with SMTP id g22-20020a056a0023d600b0067ab045e290mr554874pfc.4.1691113524043; Thu, 03 Aug 2023 18:45:24 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 07/17] linux-user: Remove last_brk Date: Thu, 3 Aug 2023 18:45:07 -0700 Message-Id: <20230804014517.6361-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This variable is unused. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/user-mmap.h | 1 - linux-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 3fc986f92f..7265c2c116 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -26,7 +26,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 90b3ef2140..eb04fab8ab 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -314,8 +314,6 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated * a chunk of guest address space. From patchwork Fri Aug 4 01:45:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710220 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233193rwb; Thu, 3 Aug 2023 18:47:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDtQl65DKZnEJuxxKkCdXvAgfvLf142Pi2rV06drw+NYcm+UX3lpWndpUIROB3l3I/T1DK X-Received: by 2002:a05:620a:24c2:b0:767:f176:cf4a with SMTP id m2-20020a05620a24c200b00767f176cf4amr531610qkn.5.1691113665813; Thu, 03 Aug 2023 18:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113665; cv=none; d=google.com; s=arc-20160816; b=odROPHu3JKF3PZJYaYCix1jVQzrLhXmZUPEEN4m+DsvPIwjhRc8MLUqXrj/vC4KDrm a20s7KSZspXmCUwcfvH9vJEVQmQH8wqJEueNpD6m1yFjUttROmtgNoFO0QQwmX8NXtFq YLVT9I7n0h9Z728+Nftn9r5NSdpvFDF30NuEJAtKrDzjdKuf7zDO5alN30RM16Lpw8EU 30KS3i0mHJR8apog+C/qGAEI4J6ScVqmz/6iPWWrEJjSDxg8F7hP0ENpi2+p8GHedJ+w nM8FCC2nSgbm7BHHYoFxQ8tgi5Px9yemCEmqglM6th6s7CtOio54wg571ttWAnTWF63r TKGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ajXblRNOLmGzYCRdBPDfu5XFCjkZKrMYV7fUiMfyjRU=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=TaOoDojRVRqjusb9M/Z/7lPOudkW+5pnySziqsFCTIfH3FMablU6fxNRrbW43rf1lU i8Ov9mNORhIr5ZCQRSaOQY+O55RYVQKqrmFw7MsPEP119sQhacxOJ8FBWlIVBA7fplSR sqAvXURe7juwFnCDTd0exTVkWoXy75jXrnJHk+7JnVblGZcAirXCYgMPQ4cr8S2I0cL0 JJU9pMHzEr1L/KOlRsHQL0k/MJegAdRXPHydbWjCwlTKt9C71v2+qnGucXMnOHy/14Y2 8IgZKG5RqPF2MuhPyQtQ3f+objdy20R972xz1PugKxFU+YGLWRjtXdmUuUCYOrwaJjOx TxYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cFlRFObx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c4-20020a37e104000000b007671b1e36f0si566584qkm.702.2023.08.03.18.47.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cFlRFObx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsw-0002hx-7i; Thu, 03 Aug 2023 21:45:46 -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 1qRjsg-0002cv-Ef for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsc-00059m-Gi for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:28 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686f94328a4so1114192b3a.0 for ; Thu, 03 Aug 2023 18:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113525; x=1691718325; 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=ajXblRNOLmGzYCRdBPDfu5XFCjkZKrMYV7fUiMfyjRU=; b=cFlRFObxx0RS+dEMOrfkxSuaIZUEISaYT+OQlLG2Cl9GiXEsl0YE7Tftyj1Jiel3Gw F2ex/5ZE6bd9OERcGgjY1YYLcMS/RhNQiq1cBiAf6wik6FsQqxWp+SsY1yRmLcMf02sJ zRdkfEBNcvceLWZdXxXZPdllQd3BvDcvXEbgyoDkPEvJugLh23ev7ODuZ5XvX4Bhopiu clETY9Jc8aCye8oEKlS7mZR9Ft0odbrV/lzWWvMfuF4fGrn0sq5gbJoP1+JMv0C10ZUK sIlcohCRSccWRMwrfRFpZMnwZx3TwznoOecYEYy1AAMKUYufr2xRJDS8Y/AdDc152g76 oKXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113525; x=1691718325; 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=ajXblRNOLmGzYCRdBPDfu5XFCjkZKrMYV7fUiMfyjRU=; b=IxOXF+Gs/SgJZ/sTQMp39DjkgSLHI5YUfA6xFlruaRw+v7zsedywtZAaRGScHKuc/B IJ2kvV7x7N0oxy0yVcpe5a3aEPrSy3GKeLPSW5Vp3/7jdmelqD4bjbhWjjxam7DiEBZU w4usfTH+D/WvLmdpRslbhvEF6J0Vu4gqCxbWrl44Q+yPj3o25pM4317hSxrDgE/P+j2U dIAua4uWCEOYrQVV37kM+dp/GaaHbsxiffRds9cmZ1S8IDrr1m9RvyafCmojK0oKCLMw iwPIMm9VogMWyNaPIYecbkVp3/HINTyMRMDugsRFheEes6oiZi8OYtu6sqn8yyJbOmZR hIBQ== X-Gm-Message-State: AOJu0YxOzRG1p5U6HnQo7nQR6sop7Lu0JTNU4fjsV4rMYjRTxzqoHuuz T2d/c2Ae09ecUO1bKi2apWHpQfwg8sQODt+/eyc= X-Received: by 2002:a05:6a00:2d0c:b0:666:c1ab:d6e5 with SMTP id fa12-20020a056a002d0c00b00666c1abd6e5mr541447pfb.16.1691113524823; Thu, 03 Aug 2023 18:45:24 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 08/17] linux-user: Adjust task_unmapped_base for reserved_va Date: Thu, 3 Aug 2023 18:45:08 -0700 Message-Id: <20230804014517.6361-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Ensure that the chosen values for mmap_next_start and task_unmapped_base are within the guest address space. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki --- linux-user/user-mmap.h | 18 +++++++++++++++++- linux-user/main.c | 18 ++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..fd456e024e 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,23 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H +#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 +#ifdef TARGET_AARCH64 +# define TASK_UNMAPPED_BASE 0x5500000000 +#else +# define TASK_UNMAPPED_BASE (1ul << 38) +#endif +#else +#ifdef TARGET_HPPA +# define TASK_UNMAPPED_BASE 0xfa000000 +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +#endif + +extern abi_ulong task_unmapped_base; +extern abi_ulong mmap_next_start; + int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset); @@ -26,7 +43,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..52809c260a 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -821,6 +821,24 @@ int main(int argc, char **argv, char **envp) reserved_va = max_reserved_va; } + /* + * Select an initial value for task_unmapped_base that is in range. + */ + if (reserved_va) { + if (TASK_UNMAPPED_BASE < reserved_va) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base = TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (TASK_UNMAPPED_BASE < UINTPTR_MAX) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base = 0x10000000; + } + mmap_next_start = task_unmapped_base; + { Error *err = NULL; if (seed_optarg != NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index eb04fab8ab..84436d45c8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -299,20 +299,8 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, return true; } -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif -abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; /* * Subroutine of mmap_find_vma, used when we have pre-allocated @@ -391,7 +379,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) if ((addr & (align - 1)) == 0) { /* Success. */ - if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) { + if (start == mmap_next_start && addr >= task_unmapped_base) { mmap_next_start = addr + size; } return addr; From patchwork Fri Aug 4 01:45:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710218 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233184rwb; Thu, 3 Aug 2023 18:47:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIyK+eDhXuuDBnLhPCaeeyqvDM6JSd7bkmJgmk+vJAMYc0uKW85e0tBWPMLB95pHugNeT6 X-Received: by 2002:ac8:5910:0:b0:403:e853:17c3 with SMTP id 16-20020ac85910000000b00403e85317c3mr696112qty.38.1691113665176; Thu, 03 Aug 2023 18:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113665; cv=none; d=google.com; s=arc-20160816; b=y6kw3fGZLHOiOk2PGLfp4d1Jt6eoeLI3a9FcvdZTUM19xUz2ml8UALWkbAzbEYEEed QKXMt5XxWnMDONbNPoKeyKPxgGGyFdNey5vJU5VwyScxX4kSGoB48qVZ6gj7LUXtJmWF peuHiZ/fwPh7pDu/BNkOkj16+WCaTJsptLS9M8luht9KYWAaYvlBPFNo+LxPIKPCxmMs 8rx4u5mvLux27XYTZZYuNduy1wa5KnzPhO93i+YKa5CernVTBll0KxAlbRix7eYJceCt N8tVZDmaUhYgN+h+aZO/fzDEJQAnNEmYDgW+uIwi769TxnpL8RAjyvibCAjTHBjoNoqb Hgpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0g0cVRguWw0x7PzF0MB98ECj4OyJgpksU9rKzq3J1ck=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=Ra+tH+YLMlvTwjCtIWJiDoyQxyfwFcNfMtZmq9Sl4bUAHNBOWjTD/iBySz8az5Q658 4FNU1PPm2f0JhFM+Hqg0udrryAL13tt5nK1VNNrgdkPG+LEKi/2+JHCtksSCjP+XXTxR Zx6VxjHZzr/sKasbceswkIPnlH3JiWIpwy1g9oxmp/7bJx2rTG++ETaSMrq2MsKpJCuQ HsA32D/XDNR97HXzASg1Dav9WKKK9o6QMZVcb9kZ67AiqOwDMLkrS7AfxKUUIGCjK6pn 3FFxvUprGhXi5oKUyIcd53wsARekbyezNg9j50n9knEzL43CWIGuHsH2J0DbEyPvfT4E xHIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xD16yKRL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f5-20020a37ad05000000b0076ca78be09asi560191qkm.162.2023.08.03.18.47.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xD16yKRL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsw-0002hw-7B; Thu, 03 Aug 2023 21:45:46 -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 1qRjsg-0002cw-En for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsd-00059s-M4 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:29 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-56401f1da3dso882491a12.0 for ; Thu, 03 Aug 2023 18:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113525; x=1691718325; 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=xD16yKRLJKOZkhdaSNyGqROsi7ezpbhWcuvRlbZ34gL2PGlefq1LUkP5dDCRf+b0ZU wYavlDW+P27ng96ESDukJoedQE6hYOKIyWY/nf1V+qut/vWs6c2kSYthR99gxYvux5Hm uAzJTwer6qU+IDV94pA+m4zHIVm68t2kArLTZy1wnWTz0GpeEUdZiiVn7qDiKW2G5hNH Y+PqCLYftogUpOAOTqXUimRmhLCEolwsBOXc80AKihQ+OQxTtRWvvqHydXeRFWYIsf6B 2h0KM/PAIoyK/GThICoTCvkJJ5pH3Xt/oGFu2fLi7HnebD3OF8ktuR2j1w+hdBrzY4Jj 7yww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113525; x=1691718325; 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=SQ252sKzwKjm9rqwP3EeErT0KhBI7KvSCXOD3h6YrPTJyfCB4LoLY6TFlBJ1aITyjP fy2C+ZHEPT4BK3SIAgUsKiwZRTozOeCH5O+qPIawvWJOZC2EIzywBEt+9CVFTXriG4X4 N8nGljtIE4yj96n7n+ZcK1isostbecSyBWWpQrHXGtV7Igr/Z+tNGFRVO9Qf4sfmqTgE PHohlFmxcMHFVQJZtmIVT/8DRQfq7DiXznPcJ4WQIBqDfkdEM78PLqAbsenSoXGLemOI DQcVkGCco1YP4tpWbyw7+/DGsy5iVwx2QvbDb1BCyWPPEXDBQSOhg+OZXWKe5X7Fc35L BzIg== X-Gm-Message-State: AOJu0YwUrK6ZIfPZoTgQNhm0aHQThHIDdUBotbmRmML8C/HpzSX0P6fE x/Tksec4IeBEfygaz2KUlrfr/DiZF94UzIAgzko= X-Received: by 2002:a05:6a20:7289:b0:131:dd92:4805 with SMTP id o9-20020a056a20728900b00131dd924805mr285989pzk.57.1691113525644; Thu, 03 Aug 2023 18:45:25 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 09/17] linux-user: Define TASK_UNMAPPED_BASE in $guest/target_mman.h Date: Thu, 3 Aug 2023 18:45:09 -0700 Message-Id: <20230804014517.6361-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Provide default values that are as close as possible to the values used by the guest's kernel. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/aarch64/target_mman.h | 10 ++++++++++ linux-user/alpha/target_mman.h | 8 ++++++++ linux-user/arm/target_mman.h | 8 ++++++++ linux-user/cris/target_mman.h | 9 +++++++++ linux-user/hexagon/target_mman.h | 10 ++++++++++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 13 +++++++++++++ linux-user/loongarch64/target_mman.h | 8 ++++++++ linux-user/m68k/target_mman.h | 3 +++ linux-user/microblaze/target_mman.h | 8 ++++++++ linux-user/mips/target_mman.h | 7 +++++++ linux-user/nios2/target_mman.h | 7 +++++++ linux-user/openrisc/target_mman.h | 7 +++++++ linux-user/ppc/target_mman.h | 13 +++++++++++++ linux-user/riscv/target_mman.h | 7 +++++++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 4 ++++ linux-user/sparc/target_mman.h | 14 ++++++++++++++ linux-user/user-mmap.h | 14 -------------- linux-user/x86_64/target_mman.h | 12 ++++++++++++ linux-user/xtensa/target_mman.h | 6 ++++++ 21 files changed, 167 insertions(+), 14 deletions(-) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index f721295fe1..4d3eecfb26 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -4,6 +4,16 @@ #define TARGET_PROT_BTI 0x10 #define TARGET_PROT_MTE 0x20 +/* + * arch/arm64/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE DEFAULT_MAP_WINDOW / 4 + * DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 + * DEFAULT_MAP_WINDOW_64 UL(1) << VA_BITS_MIN + * VA_BITS_MIN 48 (unless explicitly configured smaller) + */ +#define TASK_UNMAPPED_BASE (1ull << (48 - 2)) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index 6bb03e7336..c90b493711 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -20,6 +20,14 @@ #define TARGET_MS_SYNC 2 #define TARGET_MS_INVALIDATE 4 +/* + * arch/alpha/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE TASK_SIZE / 2 + * TASK_SIZE 0x40000000000UL + */ +#define TASK_UNMAPPED_BASE 0x20000000000ull + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index e7ba6070fe..76275b2c7e 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -1 +1,9 @@ +/* + * arch/arm/include/asm/memory.h + * TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) + * TASK_SIZE CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xC0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index e7ba6070fe..9df7b1eda5 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -1 +1,10 @@ +/* + * arch/cris/include/asm/processor.h: + * TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) + * + * arch/cris/include/arch-v32/arch/processor.h + * TASK_SIZE 0xb0000000 + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index e7ba6070fe..c5ae336e07 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -1 +1,11 @@ +/* + * arch/hexgon/include/asm/processor.h + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * + * arch/hexagon/include/asm/mem-layout.h + * TASK_SIZE PAGE_OFFSET + * PAGE_OFFSET 0xc0000000 + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 97f87d042a..6459e7dbdd 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -24,6 +24,9 @@ #define TARGET_MS_ASYNC 2 #define TARGET_MS_INVALIDATE 4 +/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index e7ba6070fe..cc3382007f 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -1 +1,14 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_32_types.h: + * TASK_SIZE_LOW TASK_SIZE + * TASK_SIZE __PAGE_OFFSET + * __PAGE_OFFSET CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index e7ba6070fe..d70e44d44c 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -1 +1,9 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE64 0x1UL << (... ? VA_BITS : ...) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index e7ba6070fe..d3eceb663b 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1 +1,4 @@ +/* arch/m68k/include/asm/processor.h */ +#define TASK_UNMAPPED_BASE 0xC0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index e7ba6070fe..ffee869db4 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -1 +1,9 @@ +/* + * arch/microblaze/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE CONFIG_KERNEL_START + * CONFIG_KERNEL_START 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x48000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index e97694aa4e..fe1eec2d0b 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -14,6 +14,13 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/mips/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index e7ba6070fe..ce18f4f871 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -1 +1,8 @@ +/* + * arch/nios2/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE 0x7FFF0000UL + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index e7ba6070fe..f1aaad809d 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -1 +1,8 @@ +/* + * arch/openrisc/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE (0x80000000UL) + */ +#define TASK_UNMAPPED_BASE 0x30000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 67cc218f2e..04f99c6077 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -4,6 +4,19 @@ #define TARGET_MAP_NORESERVE 0x40 #define TARGET_MAP_LOCKED 0x80 +/* + * arch/powerpc/include/asm/task_size_64.h + * TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4)) + * TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(DEFAULT_MAP_WINDOW_USER64 / 4)) + * TASK_SIZE_USER32 (0x0000000100000000UL - (1 * PAGE_SIZE)) + * DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB (with 4k pages) + */ +#ifdef TARGET_PPC64 +#define TASK_UNMAPPED_BASE 0x0000100000000000ull +#else +#define TASK_UNMAPPED_BASE 0x40000000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index e7ba6070fe..0f06dadbd4 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -1 +1,8 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index e7ba6070fe..40d149b329 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -1 +1,11 @@ +/* + * arch/s390/include/asm/processor.h: + * TASK_UNMAPPED_BASE (... : (_REGION2_SIZE >> 1)) + * + * arch/s390/include/asm/pgtable.h: + * _REGION2_SIZE (1UL << _REGION2_SHIFT) + * _REGION2_SHIFT 42 + */ +#define TASK_UNMAPPED_BASE (1ull << 41) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index e7ba6070fe..bbbc223398 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -1 +1,5 @@ +/* arch/sh/include/asm/processor_32.h */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 9bad99c852..692ebf9dd7 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -5,6 +5,20 @@ #define TARGET_MAP_LOCKED 0x100 #define TARGET_MAP_GROWSDOWN 0x0200 +/* + * arch/sparc/include/asm/page_64.h: + * TASK_UNMAPPED_BASE (test_thread_flag(TIF_32BIT) ? \ + * _AC(0x0000000070000000,UL) : \ + * VA_EXCLUDE_END) + * But VA_EXCLUDE_END is > 0xffff800000000000UL which doesn't work + * in userland emulation. + */ +#ifdef TARGET_ABI32 +#define TASK_UNMAPPED_BASE 0x70000000 +#else +#define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index fd456e024e..bae49059e0 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,20 +18,6 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif - extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index e7ba6070fe..f9ff652b37 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -1 +1,13 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_64_types.h: + * TASK_SIZE_LOW DEFAULT_MAP_WINDOW + * DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index 3933771b5b..c4f671adb7 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -14,6 +14,12 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/xtensa/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 2) + */ +#define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) + #include "../generic/target_mman.h" #endif From patchwork Fri Aug 4 01:45:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710214 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233084rwb; Thu, 3 Aug 2023 18:47:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGSNLttc6zJLiYW9s6Jsk3pP2lqyLeBm95rwV9eQG2wZ5P/zZB/lWVeDeq8blVogwI4xYl X-Received: by 2002:ac8:5a85:0:b0:40f:dc70:fdda with SMTP id c5-20020ac85a85000000b0040fdc70fddamr384727qtc.25.1691113645963; Thu, 03 Aug 2023 18:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113645; cv=none; d=google.com; s=arc-20160816; b=cUZmuixCZiP0gWJxxAVbCQ/sFHDLzxWkj0mLvcfY+P6V9dF6wdQEn2gmBQCXeuXjXZ G1+6sqB1S9WTB6e2DnOr1aGppYyNO1n3JXBqcwNtNpqbwKRuprXOsWlyJXxgEpaNrS3p zze5CIWMapy+8ktYVKH6qLVWnP8D+NSTEzZivWS9b2B/7mJCyinURp0VSTjdQF1J63SE pBgMgfkczbhBj/neBobBLVJ1rb8vT3zAsU75Gu6h5MCPNs/PolxLlDLMinxefp5+/j/M Gd9wKI0/+dH1gUvIt8HzMTnn1VAixDAy6SUTr9/igEsKQAqgacX3GGLnriGJH7nvhX9l usMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8gh7c1XytnUMSd/SWhDW0HpjsmcYKJxURTFPb3cRSho=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=ibBl+ClXPtgn0oAYz/QUDdxS67+GKvQRLWX0tbSKxNTMLLZJMQC90aKljiexDDtr9A OmYvL7al8DHr14un2bzg/IY911qPD+57RfSeX7lMP0So1sbSQfbEw/d9nIdf9PUBUosa 8BJznPeOiPg9O0w8AyK6xuhvpQXvu85unq2SS82BkTSuJ6RdGI8W4UUVRRDhvVuGdBxi ZScqWINFHlqaYx6uda6RHR/xZwzQhWxqUljs3S7uFX6C5vVmRG4lgsvKTI4Fr3Z5LuGM t40zAJrIpPz6BDkRRFE4zU1u8gFuD3bcF0a6mghP3lyiw4A1eVppmv5qMfWqhN6/RiDz +5xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dEy/NgVC"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t7-20020a05622a01c700b0040fddae7b20si625684qtw.663.2023.08.03.18.47.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dEy/NgVC"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsz-0002jz-9U; Thu, 03 Aug 2023 21:45:49 -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 1qRjsk-0002d6-Nz for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -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 1qRjsg-0005AV-6M for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:33 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686ba29ccb1so1099303b3a.1 for ; Thu, 03 Aug 2023 18:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113526; x=1691718326; 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=8gh7c1XytnUMSd/SWhDW0HpjsmcYKJxURTFPb3cRSho=; b=dEy/NgVCqwS7fxbbKODzpRHgZ6GnRCKjjel+GvBm8J+BjYUxHV5jrnBPu0DoU1qwUJ DF9RaLJJ7jbnyWVDZ9Cev92gXQrIw8aSTy4yyn664AlVjdfwLqLFpV022T2YHWFCft8z bHadccaeWa7ddBCYrb6RMMKXhvSSuq3ToNEZFRGWb0tw64B9TavDRdbRUp3c/OKYUYPx n+sxZ19gUuS/6bAKvnX/YeQJZM66h7rGFV0C71D/huA3Q/CmvsfpIlxtXxw8EL1HwsHr xvshZaKNxVcTGD4rfnpoE++AOQ6+ugFKoJfNLSi8uTS6GKyMe4a+BU8gW9MP8kZuHRPH IEQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113526; x=1691718326; 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=8gh7c1XytnUMSd/SWhDW0HpjsmcYKJxURTFPb3cRSho=; b=G8QZFn9x9xxDh0+ColBdTnMj3qbwyxYGekD2WOJbDDLRlmS6EtQXVDQdJfkqzsTHjd jp9nCoAjRU49RPZxTRgxZ/IkjG32uddGC90dyQ1aUmBTg42UnZHIA0DBkQEXPiS7JJqZ 9gh/e3juTMGd+COODsZsEFkUOVFre0ktPjdjcrIplNRLeBqDE7V3Xg8w66IDpFNrAE4/ FyOkql+DD3whsDAFoE7qghOUSGBw/0SoBFUVe8qNZlL0EePynUZisaLkQ11g+uTbMV9C q5iruGEU5vRuqf/6n4IUDyVzUQ4ZuMarQBpFoGOTxhLHRtCcogCMcSbT3uQDtjm2dpJ/ AR8A== X-Gm-Message-State: AOJu0Yxmk3neTHTXI6g85e89ZDAwqmUQlGKWK9LRr2eDOSXdbfrosdXX icynz5C+yqzstbMFtTgDkkOR6c/URXoLJI7C+y4= X-Received: by 2002:a05:6a21:6d8e:b0:130:a400:1d65 with SMTP id wl14-20020a056a216d8e00b00130a4001d65mr612907pzb.14.1691113526502; Thu, 03 Aug 2023 18:45:26 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 10/17] linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h Date: Thu, 3 Aug 2023 18:45:10 -0700 Message-Id: <20230804014517.6361-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Copy each guest kernel's default value, then bound it against reserved_va or the host address space. Signed-off-by: Richard Henderson Tested-by: Helge Deller Reviewed-by: Helge Deller --- linux-user/aarch64/target_mman.h | 3 +++ linux-user/alpha/target_mman.h | 3 +++ linux-user/arm/target_mman.h | 3 +++ linux-user/cris/target_mman.h | 3 +++ linux-user/hexagon/target_mman.h | 3 +++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 3 +++ linux-user/loongarch64/target_mman.h | 3 +++ linux-user/m68k/target_mman.h | 2 ++ linux-user/microblaze/target_mman.h | 3 +++ linux-user/mips/target_mman.h | 3 +++ linux-user/nios2/target_mman.h | 3 +++ linux-user/openrisc/target_mman.h | 3 +++ linux-user/ppc/target_mman.h | 7 +++++++ linux-user/riscv/target_mman.h | 3 +++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 3 +++ linux-user/sparc/target_mman.h | 11 +++++++++++ linux-user/user-mmap.h | 1 + linux-user/x86_64/target_mman.h | 3 +++ linux-user/xtensa/target_mman.h | 4 ++++ linux-user/main.c | 15 +++++++++++++++ linux-user/mmap.c | 1 + 23 files changed, 96 insertions(+) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index 4d3eecfb26..69ec5d5739 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -14,6 +14,9 @@ */ #define TASK_UNMAPPED_BASE (1ull << (48 - 2)) +/* arch/arm64/include/asm/elf.h */ +#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index c90b493711..8edfe2b88c 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -28,6 +28,9 @@ */ #define TASK_UNMAPPED_BASE 0x20000000000ull +/* arch/alpha/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index 76275b2c7e..51005da869 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/arm/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index 9df7b1eda5..9ace8ac292 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -7,4 +7,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) +/* arch/cris/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index c5ae336e07..e6b5e2ca36 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -8,4 +8,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/hexagon/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 6459e7dbdd..ccda46e842 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -27,6 +27,9 @@ /* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/parisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index cc3382007f..e3b8e1eaa6 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -11,4 +11,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index d70e44d44c..8c2a3d5596 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -6,4 +6,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/loongarch/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index d3eceb663b..20cfe750c5 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1,4 +1,6 @@ /* arch/m68k/include/asm/processor.h */ #define TASK_UNMAPPED_BASE 0xC0000000 +/* arch/m68k/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index ffee869db4..6b3dd54f89 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x48000000 +/* arch/microblaze/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index fe1eec2d0b..b84fe1e8a8 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -21,6 +21,9 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/mips/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index ce18f4f871..ab16ad4f03 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) +/* arch/nios2/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index f1aaad809d..243c1d5f26 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE 0x30000000 +/* arch/openrisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 04f99c6077..646d1ccae7 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -17,6 +17,13 @@ #define TASK_UNMAPPED_BASE 0x40000000 #endif +/* arch/powerpc/include/asm/elf.h */ +#ifdef TARGET_PPC64 +#define ELF_ET_DYN_BASE 0x100000000ull +#else +#define ELF_ET_DYN_BASE 0x000400000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index 0f06dadbd4..3049bcc67d 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -5,4 +5,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) +/* arch/riscv/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index 40d149b329..c82435e381 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -8,4 +8,14 @@ */ #define TASK_UNMAPPED_BASE (1ull << 41) +/* + * arch/s390/include/asm/elf.h: + * ELF_ET_DYN_BASE (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1) + * + * arch/s390/include/asm/processor.h: + * STACK_TOP VDSO_LIMIT - VDSO_SIZE - PAGE_SIZE + * VDSO_LIMIT _REGION2_SIZE + */ +#define ELF_ET_DYN_BASE (((1ull << 42) / 3 * 2) & ~0xffffffffull) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index bbbc223398..dd9016081e 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -2,4 +2,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/sh/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 692ebf9dd7..696ca73fe4 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -19,6 +19,17 @@ #define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) #endif +/* + * arch/sparc/include/asm/elf_64.h + * Except that COMPAT_ELF_ET_DYN_BASE exactly matches TASK_UNMAPPED_BASE, + * so move it up a bit. + */ +#ifdef TARGET_ABI32 +#define ELF_ET_DYN_BASE 0x78000000 +#else +#define ELF_ET_DYN_BASE 0x0000010000000000ull +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index bae49059e0..5dd48a458d 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,6 +20,7 @@ extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; +extern abi_ulong elf_et_dyn_base; int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index f9ff652b37..48fbf20b42 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -10,4 +10,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index c4f671adb7..8fa6337a97 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -20,6 +20,10 @@ */ #define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) +/* arch/xtensa/include/asm/elf.h */ +#define ELF_ET_DYN_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/main.c b/linux-user/main.c index 52809c260a..e089123cfa 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -839,6 +839,21 @@ int main(int argc, char **argv, char **envp) } mmap_next_start = task_unmapped_base; + /* Similarly for elf_et_dyn_base. */ + if (reserved_va) { + if (ELF_ET_DYN_BASE < reserved_va) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3 * 2. */ + task_unmapped_base = TARGET_PAGE_ALIGN(reserved_va / 3) * 2; + } + } else if (ELF_ET_DYN_BASE < UINTPTR_MAX) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base = 0x18000000; + } + { Error *err = NULL; if (seed_optarg != NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 84436d45c8..949c4090f3 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -301,6 +301,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, abi_ulong task_unmapped_base; abi_ulong mmap_next_start; +abi_ulong elf_et_dyn_base; /* * Subroutine of mmap_find_vma, used when we have pre-allocated From patchwork Fri Aug 4 01:45:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710211 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233040rwb; Thu, 3 Aug 2023 18:47:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBt43VNE3kVewzOPQpkm7xVupHcMOVXDr/Uz0RohImTugs7xFyeOS7bqhgpZCaVBPRLrSF X-Received: by 2002:a05:622a:2d2:b0:403:f60d:49e5 with SMTP id a18-20020a05622a02d200b00403f60d49e5mr645973qtx.33.1691113635158; Thu, 03 Aug 2023 18:47:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113635; cv=none; d=google.com; s=arc-20160816; b=ZD5ZYbPBNnPb7ghilnc9zuSQszeAuOWZWkxj+qhaDZRMKyHiIL0VCHwD2I8iWgpXRw ulbgYvKHiPasp5JGXEQkeAoJhvfIGU0cRN4G74aQsw9d65EOLUimCOhjpCSaNww8O4u3 lHSaBDVCg/83NGiZs1eyYYFyufjf108RjpFK6eglFYVCjZpuWHITGYfV/mQ5prsRbA8t VJ1CiCuBW5zEUilmiG5qPXFa0MYFllDgXzd2YQTvE1cyOJWTiis2Nw27lI4X4bPrntMW 4y6S9cvDP/I0MzExZYsnriblBDiQQtR0jak9nk8/DmncqLEICT+94O9zXVB4gYhdNOme Uw+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FxH9JelEzWgR3VpEL1pKK9zkkgodDw/Fd0rqiGsNBAw=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=J6JoW3lUMsNqC6gBgkmRZynvEBNhErHh+TSxxY2nE5dQ//SEccEkbXOKgE+oPsXf5v 5FhXxsez+YdZinc9wP/yTsivT3V1JYsQt6GwUamRwXDnY4pZnX9YTO7egdBvHq2DkLUf NRIoToB7cm1b9NDlqQXl44kqU9g6LSUm+4PphcERWlwhSmp/0n7XjfxTSJa3zffATMH/ mpekFRTdQGxtaryvJ4qdV49ckVy5qSGaXr7/BUtUA9gX/f1lauOH1rmn223qQMlBEloY K1wLeet2wijQJ1gF+diqvaeLm4aHcxTdm9lOLysmUKin3gQnaCuMnIhTfOlngB4jShJN e/fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="neI4/4mv"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h11-20020a05622a170b00b00403ab0d6550si638679qtk.213.2023.08.03.18.47.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="neI4/4mv"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsu-0002ge-Dp; Thu, 03 Aug 2023 21:45:44 -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 1qRjsk-0002d4-NS for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -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 1qRjsg-0005AM-6U for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:31 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686bea20652so1482059b3a.1 for ; Thu, 03 Aug 2023 18:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113527; x=1691718327; 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=FxH9JelEzWgR3VpEL1pKK9zkkgodDw/Fd0rqiGsNBAw=; b=neI4/4mvMMR0VnMfQV0bAnJSbvlGD+LsbynocbJ03KmUnK2t3ydsOfZwYkqLUzhR0N lEPD3XzPUpVAaeIePwDi1AuQh3PXEUUGnUo8blipjwM4h2XM6gZPAuIKVjGWuNmzm4U1 bLZtawp/gktRad9YLFzNGPLs0d91r+1hfAgNiDw525wWCIWccWGM4o7MS7sKeRePS4n+ IBJy0CrYkA4RxLVL0yjaXXjiECXMSDBKzcDZVVz4ivdklZZI8IG5gnu1WqZWWyu+CTE6 GE0o7o3VoZjnkmVPRcZtL9Noea/I/XpwqM3bUnxL8YJZJzHQRAxgMotHHr2JoHGeOZL5 MofA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113527; x=1691718327; 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=FxH9JelEzWgR3VpEL1pKK9zkkgodDw/Fd0rqiGsNBAw=; b=GGDWEtAukcOUuRuosfuKvfw+oRvam9wRKZQpFHiiFbpz1MedS7Uq0E1Qf31iF6rgmB 7GOD/VNLK6q+BRSjM2/OwgB0k5Z05J3xZAP4lHtwDi+kSNMITXS7iAE/Zk/cUWerDGEd 8YPqBPd88McWtXkBCl6yyO8SpRIuAmhbTFLZ5KqkS5yamguchU8qf4gGCx886jgNFt42 G1KIY3LwQykec3SNvbraMoKqRL03YEQoejA24RvfNa/cpz9s++R3XYXeHuEcPIwHlVMB NbwiGAUkKst7XaGo0pAZD+ohK/lo6NODyzs97qOIBtvDaSYw7Mi1sPr3vH0A7XoR6UEi ALJA== X-Gm-Message-State: AOJu0YwxUSX6Fjhqc8+INfTRDwP0sn3Jhf1HV34I37CFx6/O4d/D49Kq RmoMT2ZePvLtoQdR//e5LjCKQTYMHtS9WEAfRtY= X-Received: by 2002:a05:6a21:7795:b0:126:a80d:4960 with SMTP id bd21-20020a056a21779500b00126a80d4960mr316688pzc.30.1691113527293; Thu, 03 Aug 2023 18:45:27 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 11/17] linux-user: Use MAP_FIXED_NOREPLACE for initial image mmap Date: Thu, 3 Aug 2023 18:45:11 -0700 Message-Id: <20230804014517.6361-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use this as extra protection for the guest mapping over any qemu host mappings. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/elfload.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2aee2298ec..0c64aad8a5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3146,8 +3146,11 @@ static void load_elf_image(const char *image_name, int image_fd, /* * Reserve address space for all of this. * - * In the case of ET_EXEC, we supply MAP_FIXED so that we get - * exactly the address range that is required. + * In the case of ET_EXEC, we supply MAP_FIXED_NOREPLACE so that we get + * exactly the address range that is required. Without reserved_va, + * the guest address space is not isolated. We have attempted to avoid + * conflict with the host program itself via probe_guest_base, but using + * MAP_FIXED_NOREPLACE instead of MAP_FIXED provides an extra check. * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is @@ -3159,7 +3162,7 @@ static void load_elf_image(const char *image_name, int image_fd, */ load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), + (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); if (load_addr == -1) { goto exit_mmap; From patchwork Fri Aug 4 01:45:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710223 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233362rwb; Thu, 3 Aug 2023 18:48:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEIGS9bEia1UaPefj7SpXtJsVaHnPQT3lZMhckUYXq8C1JDCSMTfCepGFiNlqTL6eXGzbt X-Received: by 2002:a37:93c4:0:b0:76c:cac4:5560 with SMTP id v187-20020a3793c4000000b0076ccac45560mr358673qkd.52.1691113692406; Thu, 03 Aug 2023 18:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113692; cv=none; d=google.com; s=arc-20160816; b=ZlVPK1UdPoepR2wD9evfcr4+8u5OkNwc7ccJQEU0A/l5BmTTuF0Kyu0Iodndppt9CI rhuafy3HjUg96P39s/VSpNuTBB9j6VG4pDTliCZ7Yv3MRMzi6gkMj3ZGaLY8s0cS8DFO b9cXJFL+Uur4VdA5OzWo0sMTw4Iq1BAFPlmxzfVKXFS4sKGj9F7hHKZTeaDjgoB1Ct7I TTm4224hkwOPw/clzOf8YXUoPl3RjzXdFkx1yyIB3VyuMdLBOkpfkNmmZF3FpvQs+O8K X7PUuZ2FnSThppr55RDciqqu46Xbzbi8ekzHPDvUg5tVC8ao5TBPzmlXBY7bIKhIhpMQ si+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SHlFA2vEENUlTkxsWGE73YfmKuW2ikvOlFn8aOT1vJk=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=EE9y5YeTVWq6iJ2pmVeuxdNHLbckkzUmBiISPEx70FNoVrdlSIH74P8YHwkK8KDCAp faerRYIirA1B6LchDNkBuCXy/tq6CZ7GFwPaWDYav5S/fhiS2M9N9EQ63G4uQaMWHgEy dA5rsSzhx+tjUYgJ/5C4rcttJbJLcVB6bmwYIY1ToyjW244IlTtvZtsa8RHT2t0UJpQh sMHK1JGy2bLMxCby1STn4wbzu2XKdp3lvvX5Q9ItAqMcgGj8KaLxfxhpfa8dNsHVN7qA DaFbqWP7OZUkIk8Iz3F8B8m6H0HiG9EzrG+++qkIEzVKBGqFbJ9Op3shcvMt1CgN2Yc9 hkng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nCZYn1C3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bk35-20020a05620a1a2300b0076ce5b9f0f6si603336qkb.472.2023.08.03.18.48.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nCZYn1C3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjst-0002ga-Jp; Thu, 03 Aug 2023 21:45:43 -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 1qRjsk-0002d3-NS for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsg-0005Aj-6v for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:31 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686b643df5dso1190679b3a.1 for ; Thu, 03 Aug 2023 18:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113528; x=1691718328; 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=SHlFA2vEENUlTkxsWGE73YfmKuW2ikvOlFn8aOT1vJk=; b=nCZYn1C3NhI2n5o28vX8ZWHhYzmqp00AbepRBHDyp3W52uqlaPIn982+3Ejaiqx+aK S1m5bWXDZPvZqYjfNckLCZrOjSwE7gpAkVrUg8eCrg1AC2qcKnD9FfZaTWq+h7M8BVHQ GU3fZ/0CNnprDeU3OglKGJP5E278xqh6aGKEkj8iNETcSZyWKNx2RQD0nLcVKl3Fd4mf vFTv/3bHiwzq+ufxKEQeWjUr7KCH+59Ahgm0EPkrGi8XrBDrK6e+weS5fjoXpWlkpHer Q71653k35/ZZZnFFvtrjPaLVmwEp5LWSrje0jYtlmK6583KcVped5WSfpsoqYhbL2aPZ 0m8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113528; x=1691718328; 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=SHlFA2vEENUlTkxsWGE73YfmKuW2ikvOlFn8aOT1vJk=; b=khzWLTiRqyRpNZWoGcDRIkLl1azeeClMoHkn4+gvGV0G71p7kLfhGtB9Za1QL4ndCv lycoR7l2woiDCOZqNsRyJ4KqVDfpPk1lk9jh9m1BcPkrPARsPwWt7b8/my23h6IFjVrX Z3jh9RQud6aJhyVd6mjrRSNycigDuEyVlTyCGLwTs15QTxcOLn80u9lN1V1T5CG8roY5 jepf0RKvR1sxMD1UTOkBMPu+9h2RlaXmsHsjGQVpo39VW6O20TL7+RWYkJAdByQrn01j dwX6XOYhdBIBNYJtpIH6B5C19Ar1ZXZloF2b1UugQppVedsR8pdPisMluUMe//JdtrIp 5RiQ== X-Gm-Message-State: AOJu0Yx3yTN9UYsSwKoaQA+hBQIhkYSBcSrwBGiz67UuZL/pu8UX39ZM 7c1+z3KdvYAAv3z+XiebPou3iD92sSWCsLuG+HY= X-Received: by 2002:a05:6a00:2da7:b0:687:596e:fa72 with SMTP id fb39-20020a056a002da700b00687596efa72mr402303pfb.5.1691113528068; Thu, 03 Aug 2023 18:45:28 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 12/17] linux-user: Use elf_et_dyn_base for ET_DYN with interpreter Date: Thu, 3 Aug 2023 18:45:12 -0700 Message-Id: <20230804014517.6361-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Follow the lead of the linux kernel in fs/binfmt_elf.c, in which an ET_DYN executable which uses an interpreter (usually a PIE executable) is loaded away from where the interpreter itself will be loaded. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/elfload.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0c64aad8a5..a3aa08a13e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3106,6 +3106,8 @@ static void load_elf_image(const char *image_name, int image_fd, } } + load_addr = loaddr; + if (pinterp_name != NULL) { /* * This is the main executable. @@ -3135,11 +3137,32 @@ 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 += elf_et_dyn_base; + + /* + * TODO: Better support for mmap alignment is desirable. + * Since we do not have complete control over the guest + * address space, we prefer the kernel to choose some address + * rather than force the use of LOAD_ADDR via MAP_FIXED. + * But without MAP_FIXED we cannot guarantee alignment, + * only suggest it. + */ + align = pow2ceil(info->alignment); + if (align) { + load_addr &= -align; + } } } @@ -3154,13 +3177,13 @@ static void load_elf_image(const char *image_name, int image_fd, * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is - * pre-linked, LOADDR will be non-zero, and the kernel should + * pre-linked, LOAD_ADDR will be non-zero, and the kernel should * honor that address if it happens to be free. * * In both cases, we will overwrite pages in this range with mappings * from the executable. */ - load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, + load_addr = target_mmap(load_addr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); From patchwork Fri Aug 4 01:45:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710210 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp232980rwb; Thu, 3 Aug 2023 18:47:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYb5hxeH/cXV2eSR7JVw73lDmUokY7+WJRI2sY/2wE6wapFPB/qdwujiD1khRaprHcqBsb X-Received: by 2002:a0c:e448:0:b0:63f:638e:9775 with SMTP id d8-20020a0ce448000000b0063f638e9775mr287324qvm.61.1691113626408; Thu, 03 Aug 2023 18:47:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113626; cv=none; d=google.com; s=arc-20160816; b=GflLXI22ynK1H/Quwpzb3auFX3va8uWlMEz+zp+NdCPPaWLMQWgepdZiC5M6g/m+9j V2rUZXy9d2KUCGaEP7RBl16mftV1iogLT3vjXomgmDwFffRcHpVURw7lOGQ1jJDo1g5Y gU1x6pWgO1GIWFCdVdI6aC7jXlQkx1tItv8UMvrgLDJlNqzWB4YicgTyjM5KvTQP8F/j zeg5H9z+LYWla6z3MZMjQgCDJiW0u2n/wi5ibzgeQsobHzo78/ddGnjrijLXqcXH0z9t A8ArYwfvixWkUE5kivTRRzGPxxbgrVbPzKEgKlVGeBxt05gonb+BEG4Dt6prYTYqeP13 nOhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zoqVtIseH/7+h+x9Mh/eU2yO3E/u9HrfskNPfqLGr/0=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=lFYPKULp0uv1v6Pr05Fe7/zUgkQ53lCPp49vcuq0HmPWIMpO+ugSuxWIrZseSabkmo +nuKYT49d520uixa1rWG4TaWVkdVSUxWsT7QAbZJgrlhDCF0KbrwobNIUFfjLYmOlwq2 BamJDtNAX6J5aGc9gzNrv6TP1erGtx73Tg/YrCG+hOJl0oro2XOfwtWT6BveJW67qqFm s3Q1UdlgaZhXpvQnAF8FlesPj+sJY754aoiz5jc/GHgSlZAraukrYQ7WZWyIdFnV9nve Zou7ceXOTZNHbTllKkZPPKLNfOSu/Yg5nvDAeopAS3IGi48Q5/cKcQteDtMCI8REPxgN lKpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cwhUUg4t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r11-20020a0cb28b000000b0063cfae40190si565084qve.487.2023.08.03.18.47.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cwhUUg4t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsy-0002jl-RI; Thu, 03 Aug 2023 21:45:48 -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 1qRjsk-0002d7-Of for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsg-0005As-75 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:33 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686efb9ee0cso1410877b3a.3 for ; Thu, 03 Aug 2023 18:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113529; x=1691718329; 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=zoqVtIseH/7+h+x9Mh/eU2yO3E/u9HrfskNPfqLGr/0=; b=cwhUUg4tuWB2g+6VOaAYdkg9kvUPYx5HvnMguVsBkFcbTa9RX2jqTHuhQO1bz4htdl t0hWVhW6VDnOr4B4JfTfGEnVrZjLce6RDMAbYEbdRsXh2uirf6nH4aAfWAv4Hid4AeSc olfEHZoXyyMEEozhzffoj1RMSfSUesTYhCCxsG34SRDkehdUGXczZ/LWBhf+Vyc+sL9p R8qAusskL8rmO7J8HB+Bt+gWfgiOO+qd223GL+TE8qlXaCsgPor8Op62V5+RQUx38mSA qP61c/H+DIqiOLLVacm5xOmK6DYZ8SRlTlGqK5FYwi2Fy9ZHIKaO9SQ/0b5lBKkyrhZ2 xF2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113529; x=1691718329; 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=zoqVtIseH/7+h+x9Mh/eU2yO3E/u9HrfskNPfqLGr/0=; b=AqkuefQY/cAqIb9CtUE9epeYWKM3XQgJtZkkrbGX+l/CSQ61Dun6DaSE/p9HMl26dD E1l4GYHgQAuoLnuplz8fmsbqDJ9UowfCNo1GOFNLLLVyvhuntjAQV1t5OWIwICjRqICS ZYce5ovqe+elkqxxqwngWmntcNFF+DTPt2mU4cgtSxTlzWyKLROe05o27g5KlRqRXOd+ X765ZaNGeQdVQMdEyjsfz0cXEjAFcQWqiR20ytYMa/ovwloFy+pdM2essz4n0CsWr00+ kVNvIZVZfWp5z7fYQbYVONbPQk3A0MLKpuP17SXd8Ql6IEEWRVla5NbGAwpHOt2yJoJz 3Big== X-Gm-Message-State: AOJu0YybuWu5zsihcumZfjln+Zo3vMi0y1rcS+3k5GE3tHzRD52UJWNZ RMs88CwJGCcYbYkM0AQ2JyFInP4g08OZaG3wARI= X-Received: by 2002:a05:6a21:4843:b0:13f:bc16:c360 with SMTP id au3-20020a056a21484300b0013fbc16c360mr312017pzc.32.1691113528944; Thu, 03 Aug 2023 18:45:28 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 13/17] linux-user: Adjust initial brk when interpreter is close to executable Date: Thu, 3 Aug 2023 18:45:13 -0700 Message-Id: <20230804014517.6361-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller While we attempt to load a ET_DYN executable far away from TASK_UNMAPPED_BASE, we are not completely in control of the address space layout. If the interpreter lands close to the executable, leaving insufficient heap space, move brk. Signed-off-by: Helge Deller [rth: Re-order after ELF_ET_DYN_BASE patch so that we do not "temporarily break" tsan, and also to minimize the changes required. Remove image_info.reserve_brk as unused.] Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki --- 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 a3aa08a13e..fa0c9ace8e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3109,27 +3109,6 @@ static void load_elf_image(const char *image_name, int image_fd, load_addr = loaddr; if (pinterp_name != NULL) { - /* - * This is the main executable. - * - * Reserve extra space for brk. - * We hold on to this space while placing the interpreter - * and the stack, lest they be placed immediately after - * the data segment and block allocation from the brk. - * - * 16MB is chosen as "large enough" without being so large as - * to allow the result to not fit with a 32-bit guest on a - * 32-bit host. However some 64 bit guests (e.g. s390x) - * attempt to place their heap further ahead and currently - * nothing stops them smashing into QEMUs address space. - */ -#if TARGET_LONG_BITS == 64 - info->reserve_brk = 32 * MiB; -#else - info->reserve_brk = 16 * MiB; -#endif - hiaddr += info->reserve_brk; - if (ehdr->e_type == ET_EXEC) { /* * Make sure that the low address does not conflict with @@ -3220,7 +3199,8 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_code = 0; info->start_data = -1; info->end_data = 0; - info->brk = 0; + /* Usual start for brk is after all sections of the main executable. */ + info->brk = TARGET_PAGE_ALIGN(hiaddr); info->elf_flags = ehdr->e_flags; prot_exec = PROT_EXEC; @@ -3314,9 +3294,6 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_data = vaddr_ef; } } - if (vaddr_em > info->brk) { - info->brk = vaddr_em; - } #ifdef TARGET_MIPS } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -3645,6 +3622,19 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) if (elf_interpreter) { load_elf_interp(elf_interpreter, &interp_info, bprm->buf); + /* + * While unusual because of ELF_ET_DYN_BASE, if we are unlucky + * with the mappings the interpreter can be loaded above but + * near the main executable, which can leave very little room + * for the heap. + * If the current brk has less than 16MB, use the end of the + * interpreter. + */ + if (interp_info.brk > info->brk && + interp_info.load_bias - info->brk < 16 * MiB) { + info->brk = interp_info.brk; + } + /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ @@ -3698,17 +3688,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) bprm->core_dump = &elf_core_dump; #endif - /* - * If we reserved extra space for brk, release it now. - * The implementation of do_brk in syscalls.c expects to be able - * to mmap pages in this space. - */ - if (info->reserve_brk) { - abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); - abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); - target_munmap(start_brk, end_brk - start_brk); - } - return 0; } From patchwork Fri Aug 4 01:45:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710213 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233082rwb; Thu, 3 Aug 2023 18:47:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPizE63YzEpaPjXyIUY1sCSsvMEL6xsbfFqhtwICCQcUnDFa6kgjyDcdMoFggRqYuAmCQn X-Received: by 2002:a0c:edca:0:b0:63d:31a7:6809 with SMTP id i10-20020a0cedca000000b0063d31a76809mr278104qvr.13.1691113645781; Thu, 03 Aug 2023 18:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113645; cv=none; d=google.com; s=arc-20160816; b=WFfzHHPc7GzuBLsyeT2jWPQIJ4QapuftucPl31ES09b4UFkM2L+gnRba4lSr6oTNEG U3ADgQ9aTKPLiP2ijCpodeGle1ogFVyqGw5A03t4bnxAj0y9YF3+kI+SlE5uM7xD+c57 qWyqxvghF59QX9KGgq3VfxsskQd+XAde7c3xZEdsqGDIDy6nBp0KJC8vszhOksQtV5nz AxJ5ITJO2/hLjSRnAOiv2MUCQLi40QeWWmAB9V9k0hMAxLUnQwPbUNOAoLr4fmDCRWEg TfUqXLUtt2bxgpRDimmoyvXes12xECnRw+TD8g1FOtkUcdgLEz3OQoJXLsW79UdkQ3RH FgSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yKCV0XRiqzz/Bbo5CE3ioXvHDRvgwqgKDuyImywiLU0=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=eYfRltqfTNS1Y6u6ZnmHwgKkfYp7qJtAngnSE8ypDVGY57spIqicIteidNxYpL2j59 dXPVKHO0LrG3h0/gaUS9ktHZZKxNKHy+qAGW3BB3DbVJhaInjS5x99Me5+iFqqxRfF4w zEskLhkXHTlZem1UlhptoxL4sATBMoBTgZvPIpwzMpx4Pgjz64wP0BbDmqxGjSbz9JlY E7FTBDkFxc8GkSl68GkZVeMB6cpPHPZQ8b/WsDY2NgOhitjGXx+Uo3NVzr+4M4gJ13E1 sNwZqZahhRcMureaWOD74/O5rSG+BTLR1V2HbGlkX7KdWb5aDRY0BS6Jv7Fe+3wUJzkC nCZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RXCM1bWv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v8-20020a0ce1c8000000b0063d32e11802si572124qvl.9.2023.08.03.18.47.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RXCM1bWv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsv-0002hM-Q3; Thu, 03 Aug 2023 21:45:45 -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 1qRjsk-0002d5-NX for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsh-0005BH-2S for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:33 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-686ed1d2594so1418087b3a.2 for ; Thu, 03 Aug 2023 18:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113530; x=1691718330; 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=yKCV0XRiqzz/Bbo5CE3ioXvHDRvgwqgKDuyImywiLU0=; b=RXCM1bWvgGAyowHopprbFDQXe/0eKIuxZEvZezXoijdcr3VVhoe7HpLXHcUHFVXkhG rsLp+pnyT1udQdFsd+qSIUblau2v/rIUvtm8Zr6eHlLY1Lrj2A72fseqSpoSEJ2PLZgS AQaUjcJmSIbFw3UCZStutXCFmpVCh7z7kFPhV8TBqWgOTMoURROvQghFsvNAzl7OdOcx UOx9UDmNTI/JSTFXpFXAu33aZnxDYstXkhEitAFTkx5rP5Q8xpMFwvGTO4ajN/9xd2Oh Yz1YGkgDlEhq7rVANe60nkZ8avq0SZmMdq/rGasbVx/TW0cNjSRzIYUBv5qTvi01YCQH TFqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113530; x=1691718330; 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=yKCV0XRiqzz/Bbo5CE3ioXvHDRvgwqgKDuyImywiLU0=; b=k0CVNb4MsHCaPnooKfyem404hc6vVjX4P5b4JXp/K1YC1YW4HmBzjqcZ7fi9np4zQm c4cnhDDcotSzvtbIu2uGIXogbAvKfb1FJKkaNZYt6HB4tcPK+nDepUClKvqSzn2LGifS 6nwgXFjgVZXd9TPHeYKEXBtMHP7Qc3rGq6JUjICZ/o34MZ+NMD8SVi1EnCc6dW37RSJE 5To1PlgZ8oVXw8aU/a0BIli8W1vVMxavCT4Vd8UntN6pituPGZd0MAfMB65yZIBnj/zK I7h5Oep31YcOoOccBkGgkIY2oMF4H7mHPsWJ9WpFkOOWGYuVPG2qhdx/3DHXgILoVG+G TC7w== X-Gm-Message-State: AOJu0YxKZdNkoQg6AwXRHnBBtuwtauulZf6reF6PbOsHTMHGubfqNB1A GdQlmR529Dlw1eBEZqOK8jhT067CYFD2DSpgxQY= X-Received: by 2002:a05:6a00:b90:b0:681:50fd:2b98 with SMTP id g16-20020a056a000b9000b0068150fd2b98mr516508pfj.31.1691113529917; Thu, 03 Aug 2023 18:45:29 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 14/17] linux-user: Properly set image_info.brk in flatload Date: Thu, 3 Aug 2023 18:45:14 -0700 Message-Id: <20230804014517.6361-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The heap starts at "brk" not "start_brk". With this fixed, image_info.start_brk is unused and may be removed. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/qemu.h | 1 - linux-user/flatload.c | 2 +- linux-user/main.c | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 4b0c9da0dc..4f8b55e2fb 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -29,7 +29,6 @@ struct image_info { abi_ulong end_code; abi_ulong start_data; abi_ulong end_data; - abi_ulong start_brk; abi_ulong brk; abi_ulong start_mmap; abi_ulong start_stack; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 5efec2630e..8f5e9f489b 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -811,7 +811,7 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) info->end_code = libinfo[0].start_code + libinfo[0].text_len; info->start_data = libinfo[0].start_data; info->end_data = libinfo[0].end_data; - info->start_brk = libinfo[0].start_brk; + info->brk = libinfo[0].start_brk; info->start_stack = sp; info->stack_limit = libinfo[0].start_brk; info->entry = start_addr; diff --git a/linux-user/main.c b/linux-user/main.c index e089123cfa..51ee8649e2 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -953,8 +953,6 @@ int main(int argc, char **argv, char **envp) fprintf(f, "page layout changed following binary load\n"); page_dump(f); - fprintf(f, "start_brk 0x" TARGET_ABI_FMT_lx "\n", - info->start_brk); fprintf(f, "end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); fprintf(f, "start_code 0x" TARGET_ABI_FMT_lx "\n", From patchwork Fri Aug 4 01:45:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710209 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp232812rwb; Thu, 3 Aug 2023 18:46:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4g5wvLXkPJg7PUidTCPylxtP0WG22lwN9sEnz7l9Lu/if65AIKj7uuFPHD+opvnbsld+H X-Received: by 2002:a0c:f50c:0:b0:63c:efcf:6001 with SMTP id j12-20020a0cf50c000000b0063cefcf6001mr313037qvm.2.1691113585083; Thu, 03 Aug 2023 18:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113585; cv=none; d=google.com; s=arc-20160816; b=xIXrWpbIhjMwC231bGAVKal/5yML1N5NNCXQy/owWtV41sKdqIZq1gHuo97npTk7SW i4X8fB5NccPvfe1ogAdxI1nJVp7sjRr22dF/M/kF7FSxC84HPvB5Y1JkkIEooGC3b7ix SlO3WQQMED3RuAjsLfa4sylbIXRiF3Ln/Ow2cM62DuQRgOt8KRfgnMfkQosLBsGaC5ZH /URVPIB+kxsfm3J6Y1eQlcgmTVFk4ANQ6b/7vCYwKCHZVESWAoy4vMR9EA1j5CkWb7Zp iI9GCmZ5rxP+233IbdPnQiBNGzCM5fgyEZbM/46HGY3Lkg8PJ3JSKvjntIQwy1I3Xlb/ uh3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ELcQtbKVbBoHF9FWDbse8cJpBmtrHN0KISCq9awCB6k=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=u/Jmx1ndD2kdH5clAm4YnSEPvXQAVKtb5V/Yt1hvUUJIroEWU0SkbgXDsnd49Uvr5j gb22UDbpnpZYmRpS4md+X99bMqw1AFIIhKYUUwjio/ECUEncV928tyLs18gPZaV8Xpvy AOemanhh90oE30+JUOT00JEqoUp818TVK/YLbqT+LkAE5s/FF6OzyDTiBBcj1uUt/4hO lzByGkRhqny/NOWWsxHvvjb4qRRMToPL4dEDx94nMCGhQAMxHISahXuGMecd4H4Q8T2f XeGQquzJMxEaJKBLbHVJdX9L89SGQyeyH5miYjZ41Ql2bnCelYzd1CLTx2RrSczEFiQ6 6jnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3i6fetW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f1-20020a05620a280100b0076af62a09d3si608008qkp.537.2023.08.03.18.46.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:46:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3i6fetW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjss-0002fs-Vt; Thu, 03 Aug 2023 21:45:43 -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 1qRjsm-0002dD-5K for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -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 1qRjsk-0005BR-Ev for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:35 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-68783004143so1184002b3a.2 for ; Thu, 03 Aug 2023 18:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113530; x=1691718330; 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=ELcQtbKVbBoHF9FWDbse8cJpBmtrHN0KISCq9awCB6k=; b=Q3i6fetWC9GtJWvlWnBCG1HHMIRj9nh6S0XQND9lV6pi1IAcSgjMu+7IFOPi6xIZOe ON+dOSUGcliUomuvB/6yA7S/8wSHA3J8iq0Cq5iGQxDeSo+0HBmcUaNfCNNXSZpOoGkr Jwm/Z+iqhJPymw5GGjyF3A42T+HJcp5DD7qv1iIKUsHkkPmpL0iAdjtLtQa8I0OWZsiP ZYuZoTK7Tbl4g4Z4Tc5KrPRUT4WHEqR3vqug+WwK4/eb2J/lMoZLa6YFFEkHftihcMwu aINsxwOEEyzJPWZq7qJ1t69ILaisb4PCcEJ7qPoOGJ491JeIoqjj9PonR1naWe93bhwJ N3pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113530; x=1691718330; 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=ELcQtbKVbBoHF9FWDbse8cJpBmtrHN0KISCq9awCB6k=; b=RqVPp5s+93q1ngiEyG3QS2+MOO1xElxpgWOISRW3t0wChz6lLAkK5rvA/Jr3db3Ek0 /5rNjqKEEEbuOKs0NxcwRv24/zcVs0RnF9O2HhzNb6x3GdobuOfF/3Lgbim/v44+n1ys odvlg28W8LmZ5FNss/WCt0s1JLBMPrsAds27nFkshMlQScS6U2a8qRtFxAaIqTjKDOwI nTwpOFPPLwaCPM5Qm49Z8m493iCnHNPH2tvlvgKbZ513c7LOytAQ+SM0FZ/fU5mb28E9 6OYZpv3p5BNyAQ3M0LEqyCv05R7YF7ZQH1fC4tJzFzOKjol2vNqwg1XBSLarhjA8+E+F L55w== X-Gm-Message-State: AOJu0YzGQsnhnVWzdH+w7W2UrFYq9qbJlpP2ji4trAtRNuVH4VootREL QhrNVZBsYzZnMVQY0jU1bRhavNSEHBCMNSC/Eq8= X-Received: by 2002:a05:6a20:3ca3:b0:131:6fd:8f5a with SMTP id b35-20020a056a203ca300b0013106fd8f5amr341004pzj.32.1691113530688; Thu, 03 Aug 2023 18:45:30 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 15/17] linux-user: Do not adjust image mapping for host page size Date: Thu, 3 Aug 2023 18:45:15 -0700 Message-Id: <20230804014517.6361-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Remove TARGET_ELF_EXEC_PAGESIZE, and 3 other TARGET_ELF_PAGE* macros based off of that. Rely on target_mmap to handle guest vs host page size mismatch. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/elfload.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fa0c9ace8e..e853a4ab33 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1959,15 +1959,6 @@ struct exec #define ZMAGIC 0413 #define QMAGIC 0314 -/* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE \ - (((eppnt->p_align & ~qemu_host_page_mask) != 0) ? \ - TARGET_PAGE_SIZE : MAX(qemu_host_page_size, TARGET_PAGE_SIZE)) -#define TARGET_ELF_PAGELENGTH(_v) ROUND_UP((_v), TARGET_ELF_EXEC_PAGESIZE) -#define TARGET_ELF_PAGESTART(_v) ((_v) & \ - ~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1)) -#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1)) - #define DLINFO_ITEMS 16 static inline void memcpy_fromfs(void * to, const void * from, unsigned long n) @@ -3240,8 +3231,8 @@ static void load_elf_image(const char *image_name, int image_fd, } vaddr = load_bias + eppnt->p_vaddr; - vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); - vaddr_ps = TARGET_ELF_PAGESTART(vaddr); + vaddr_po = vaddr & ~TARGET_PAGE_MASK; + vaddr_ps = vaddr & TARGET_PAGE_MASK; vaddr_ef = vaddr + eppnt->p_filesz; vaddr_em = vaddr + eppnt->p_memsz; @@ -3251,7 +3242,7 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); + vaddr_len = eppnt->p_filesz + vaddr_po; error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); @@ -3267,7 +3258,7 @@ static void load_elf_image(const char *image_name, int image_fd, zero_bss(vaddr_ef, vaddr_em, elf_prot); } } else if (eppnt->p_memsz != 0) { - vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_memsz + vaddr_po); + vaddr_len = eppnt->p_memsz + vaddr_po; error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0); From patchwork Fri Aug 4 01:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710219 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233192rwb; Thu, 3 Aug 2023 18:47:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0z7PdD8h99dnDYB0dGKjl8b3XcE72ybRcll0VZAVKY150imwX4KMJdtogXeYX5tykM98q X-Received: by 2002:a05:622a:1449:b0:40f:f3df:b1bd with SMTP id v9-20020a05622a144900b0040ff3dfb1bdmr592413qtx.63.1691113665629; Thu, 03 Aug 2023 18:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113665; cv=none; d=google.com; s=arc-20160816; b=fl2Csq9hGItC6SPCA5EqY5cP9h9z30MV+9RkdyKLNNchbm+tK30zkIiFWud1Cy32Ca 8G70Nt+1omE6Uox7LRkerwWekgR3vBuluzzxHjSaq+83ikLe3yZSiJsds6M5LvvMpbrd o6ldLdtYCQTs60diqO2gLXxKA8UXjhcJFlIlg1hlBkMUWv1uW3nxuzu+/+9ZeIjYq45W Hp3zJN3mMH+F43HB9FWBK/BmqiN8J0i76cr2bCEbOBI5N3qR82vSZhae9ywDqvhOzS6T B8MvfAgWjXssCl8gTDzdmqNLSMWHYUGKVJhMYelIbACqRc43WlcZkhvtEYy7a9pnxM51 XVEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y2R1cWGHzOEOxowvH71/O+CgU7805zY7DZl/vbJ8Gvs=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=tq4wofeAbCK7mg7hrHIw9kYuhC5dpJJDI3Ga1uXAQj36p0u01BzimcpEkZvvvUkecr BfN5CG5MkmPMoPCSSFGXebhrOaHIArCfixHpHRxwUu4PeOiMAXkD3nF4JJLPXWSmwU3F wkeOXumzbggkVbzkEvMLHd61I3QVK2WnLjWt3Q+D9JvqeTub0Hof577Xou47KuL2VfXk NMgpBURSxIPTEwEuoifEh7IB27fMHfK3U5/LuyomEVTfJorqLymjRbVQG8hfVUNxVZMs 3cMaVrcKmFLHSjHgYmzhJZc9+J8hKXUN7vKJ0SPoDSiW7yPLaO1LgNAOjvlkJzvClQTo JV3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m80fb8dL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c20-20020a0ce154000000b0063d310284absi593099qvl.53.2023.08.03.18.47.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m80fb8dL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsv-0002h6-Le; Thu, 03 Aug 2023 21:45:45 -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 1qRjsn-0002dG-64 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRjsk-0005Bf-FU for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:36 -0400 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-55b0e7efb1cso875202a12.1 for ; Thu, 03 Aug 2023 18:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113531; x=1691718331; 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=Y2R1cWGHzOEOxowvH71/O+CgU7805zY7DZl/vbJ8Gvs=; b=m80fb8dLDr1hdEZwEmmPn0fPBLiihleBFqrPr36GSeEC4/7v18DX97Y7XB2gG8HwNm XhLFtw+wCntq23OHNUX4jjtHegXj3WXbloht1pjg4LPM77RdJXjIKwoJWG4wPYGhWLx0 BwuopLLKAq5r3rtbhykR5dTFYnG73Qetw2CPH2d9HseCEsSez4vy3UpV9EKqPL4wCg0y JbEX31D5IuJjcy+z0w68zx5tp6OcoOmPzgMvPK8uHj4i2UQX97q62e4HDrSnr3zQQvbE k6KLFI+t5j/WIX2EMqU0qiWRNYcPAMOTWpAHl5tHoF0ORN0GAphEYLbqQRhJG8vbDb1K tNNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113531; x=1691718331; 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=Y2R1cWGHzOEOxowvH71/O+CgU7805zY7DZl/vbJ8Gvs=; b=YUEXTg2mx1XvHsxfjBl2InvjNgPc81eXRKvnX17w6ochaegXsdKzgLOw5DRVRF5hOk LQ+mkDL+NsvKh1VCGdfF1LejvzckSeUnPu4JbdTvRijGlBxRlYWl4HLwTEz9WbOCGqvy dD3DkZnJqI7kBCrkPtgHiMKFX+cN/1unT1J9XfX04wCQLlbhMDXwzTgrj0D2pAiKjGSJ yrylN/GjbibQuDIApmSmO95qBxq7zuDrg2WiyWn1PlgnDwnWnaoI8xxTy2lrQcl8F6r7 F58iEci1w9BpKR36FFf7sqSpwXglTFWiHCgL0URDny8r2BSLMhEneGE9rZnayphtw4FG qj/g== X-Gm-Message-State: AOJu0Yw3Nwr5vyib5DpQtitVcj9fjvyyC80C2QevmQtiFyxAevaXVnBJ IDjnCmNsckABSVWkn19VWbVAU4ethpbBNF331Fg= X-Received: by 2002:a05:6300:8002:b0:13c:3b5e:a12a with SMTP id an2-20020a056300800200b0013c3b5ea12amr243297pzc.34.1691113531701; Thu, 03 Aug 2023 18:45:31 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 16/17] linux-user: Do not adjust zero_bss for host page size Date: Thu, 3 Aug 2023 18:45:16 -0700 Message-Id: <20230804014517.6361-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Rely on target_mmap to handle guest vs host page size mismatch. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/elfload.c | 54 +++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e853a4ab33..66ab617bd1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2212,44 +2212,36 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, /* Map and zero the bss. We need to explicitly zero any fractional pages after the data section (i.e. bss). */ -static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) +static void zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot) { - uintptr_t host_start, host_map_start, host_end; + abi_ulong align_bss; - last_bss = TARGET_PAGE_ALIGN(last_bss); + align_bss = TARGET_PAGE_ALIGN(start_bss); + end_bss = TARGET_PAGE_ALIGN(end_bss); - /* ??? There is confusion between qemu_real_host_page_size and - qemu_host_page_size here and elsewhere in target_mmap, which - may lead to the end of the data section mapping from the file - not being mapped. At least there was an explicit test and - comment for that here, suggesting that "the file size must - be known". The comment probably pre-dates the introduction - of the fstat system call in target_mmap which does in fact - find out the size. What isn't clear is if the workaround - here is still actually needed. For now, continue with it, - but merge it with the "normal" mmap that would allocate the bss. */ + if (start_bss < align_bss) { + int flags = page_get_flags(start_bss); - host_start = (uintptr_t) g2h_untagged(elf_bss); - host_end = (uintptr_t) g2h_untagged(last_bss); - host_map_start = REAL_HOST_PAGE_ALIGN(host_start); - - if (host_map_start < host_end) { - void *p = mmap((void *)host_map_start, host_end - host_map_start, - prot, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { - perror("cannot mmap brk"); - exit(-1); + if (!(flags & PAGE_VALID)) { + /* Map the start of the bss. */ + align_bss -= TARGET_PAGE_SIZE; + } else if (flags & PAGE_WRITE) { + /* The page is already mapped writable. */ + memset(g2h_untagged(start_bss), 0, align_bss - start_bss); + } else { + /* Read-only zeros? */ + g_assert_not_reached(); } } - /* Ensure that the bss page(s) are valid */ - if ((page_get_flags(last_bss-1) & prot) != prot) { - page_set_flags(elf_bss & TARGET_PAGE_MASK, last_bss - 1, - prot | PAGE_VALID); - } - - if (host_start < host_map_start) { - memset((void *)host_start, 0, host_map_start - host_start); + if (align_bss < end_bss) { + abi_long err = target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (err == -1) { + perror("cannot mmap brk"); + exit(-1); + } } } From patchwork Fri Aug 4 01:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710221 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:606:b0:129:c516:61db with SMTP id eh6csp233227rwb; Thu, 3 Aug 2023 18:47:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9+z6KckDrCDt7vUtwEk/NvI0pwmGZw/Bq8KSRvXgloCEipcgqggMWxGxY6JycJH+3MJ+R X-Received: by 2002:a05:620a:38c:b0:76c:cd44:bba6 with SMTP id q12-20020a05620a038c00b0076ccd44bba6mr446080qkm.78.1691113671846; Thu, 03 Aug 2023 18:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691113671; cv=none; d=google.com; s=arc-20160816; b=k29gURY1Q5VpCmr1YYOd5wPWw8xcbzEwbSVKwHxzudCaDpyhhAHJU525E6G8vJkTDw I5pTESBE5Cugdj0rNWMbkA03Dvm7EoVUi2dmuLDXkboBQoY6lUW19FXqdKPrh0pBihDb Hku9Flqi6dKN3zNxfzPKRB1LuljgCSzgLo6k8K7s2Kt2S4BX3vz7mNHQC/24dkZEriAU LcsRH80vLnLcI8J8kqA1vx3YtcmfEYIR9XsnBURnRzf+KUbc275JyHiSzmbqflATt0RM TIRsE8azZvwO05ntvv4x+aaCfp0XsqGzDb26cBJ8hUWRzX/Rxqc2FlJfpWWmw8hRiNoK xr3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IRkEwFCl346jg7Z07dyeTmyC7RNqDmLWj3eYDwe5avk=; fh=oY0Hqs0mb1Sbw8XbQT7Frqsb6/GXc1LASz4nvWEMVJQ=; b=mit3MaUfSrY8LQKQh7hRlTTeD962vTqIyICmoibDk4upfSFnI7WDHc2tpxzcWEiZA5 zJDXA2Kec7rqEzOBMrTyYvjZ2oCKWx56EE9131Wjrs3m2Es8jZB16DxksjnEBCBBLGRy FXQkZv7GdsaL1//sR9omFHD0p6ip3a/TVKfj5YJpXSrHEdkW8BRTt8XR3nUDbNbN47wv f9gVFZOh0sK8tgoxBTK70CJ3Ka+XC16wX+QfzB1X339nNocQuZ8nmPzvJb9dAG8ijF9l 7/5/OFBHGcwiFMQND9OCLNI2+5mufzalGZ3v2AYnEGV4L52AV1GLeNkbOSB32xSh7+I4 0Iwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uzAWbFQx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id dt31-20020a05620a479f00b0076830120ce7si580930qkb.576.2023.08.03.18.47.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2023 18:47:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uzAWbFQx; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRjsw-0002iE-Dk; Thu, 03 Aug 2023 21:45:46 -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 1qRjsn-0002dF-62 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:38 -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 1qRjsk-0005Bq-FC for qemu-devel@nongnu.org; Thu, 03 Aug 2023 21:45:36 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686efa1804eso1152687b3a.3 for ; Thu, 03 Aug 2023 18:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691113532; x=1691718332; 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=IRkEwFCl346jg7Z07dyeTmyC7RNqDmLWj3eYDwe5avk=; b=uzAWbFQxcONuMkzKWaiuUmH/7ekp96n/cDLcA4CSHQ9wLFOuAxMYRMzMnle9lGHItt 4HPUEBZnmAWkp2/YWxBhFC43xvQxSBN0d8WAp0B7nOtVfrT+Z3q6gAeepEuergoVaPiu HGBym0ebEqK3SzJebQsgQdSAa9n0EfG5QpwfFDjyaP4jjQ+xmq1MfIn9TyiP15YTSQ7p rl+dedNVu7ZI4PFQLC2Vt7G8qZ+PbwvIWyW5mxRv2koHObtPlVI9xGid3GmMSBN0idqj hJYJruO1mPSdVp/jDz3QpIgnZ2w18KOlENSKmQdx0M0lcWQO0Mmiku4oP5Cub9Y+W2Pe 1OHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691113532; x=1691718332; 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=IRkEwFCl346jg7Z07dyeTmyC7RNqDmLWj3eYDwe5avk=; b=gDnNvTS2m6LdN5GDbSIhLe0EHeXM6loi3bY/2HLys+rqCto+7MVfTeev5/DIQBdv/w w0ukThwA6uwvec9+OZY2HhRDxV0G7/bxwr7kdvkpi7hHMYXqE3rXiKlVDmoZnxVVHLrL FZCm0dt0xYr3qn63n2yI42rlrA3/+hOfuCUgJfQN1rLlOT6oeL5Wn9u0f9ADXeilmkMC mfYlXdEaA6p5HzW7LkCZP0261CebXoGU4v7jmY7taMpau/xb5HQSqjfmcvFdC6T5vBKR 5UjKJTplKVkbQGnJvbwbLNnkwrch8I0evFfwg5NeiQgxPLKR3sjgb7G2KQ9u6Zqdtjsf RocQ== X-Gm-Message-State: AOJu0YzbK2tt1ZPPFKYXEbnm8n2dqgLq9DCvlMkqYJd7pDEB6b+dMWFo hfulX18LOjshP3SHP1BzHgU49TMoy3o6fL3fQrA= X-Received: by 2002:a05:6a21:7906:b0:135:2f12:7662 with SMTP id bg6-20020a056a21790600b001352f127662mr291638pzc.33.1691113532696; Thu, 03 Aug 2023 18:45:32 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9d52:4fe8:10ce:5c3]) by smtp.gmail.com with ESMTPSA id c5-20020aa78c05000000b0066f37665a63sm456138pfd.73.2023.08.03.18.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 18:45:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: joel@jms.id.au, akihiko.odaki@daynix.com, laurent@vivier.eu, deller@gmx.de Subject: [PATCH v8 17/17] linux-user: Use zero_bss for PT_LOAD with no file contents too Date: Thu, 3 Aug 2023 18:45:17 -0700 Message-Id: <20230804014517.6361-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230804014517.6361-1-richard.henderson@linaro.org> References: <20230804014517.6361-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If p_filesz == 0, then vaddr_ef == vaddr. We can reuse the code in zero_bss rather than incompletely duplicating it in load_elf_image. Signed-off-by: Richard Henderson Reviewed-by: Akihiko Odaki Reviewed-by: Helge Deller --- linux-user/elfload.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 66ab617bd1..51591a1d94 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3209,7 +3209,7 @@ static void load_elf_image(const char *image_name, int image_fd, for (i = 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt = phdr + i; if (eppnt->p_type == PT_LOAD) { - abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; + abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em; int elf_prot = 0; if (eppnt->p_flags & PF_R) { @@ -3234,30 +3234,17 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = eppnt->p_filesz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED, + error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); - if (error == -1) { goto exit_mmap; } + } - /* - * If the load segment requests extra zeros (e.g. bss), map it. - */ - if (eppnt->p_filesz < eppnt->p_memsz) { - zero_bss(vaddr_ef, vaddr_em, elf_prot); - } - } else if (eppnt->p_memsz != 0) { - vaddr_len = eppnt->p_memsz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, - -1, 0); - - if (error == -1) { - goto exit_mmap; - } + /* If the load segment requests extra zeros (e.g. bss), map it. */ + if (vaddr_ef < vaddr_em) { + zero_bss(vaddr_ef, vaddr_em, elf_prot); } /* Find the full program boundaries. */