From patchwork Tue Aug 8 21:08:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711576 Delivered-To: patch@linaro.org Received: by 2002:ab3:63c7:0:b0:238:c968:2573 with SMTP id m7csp2881820ltf; Tue, 8 Aug 2023 14:10:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6ljFf02vCVnRUSwFgfmY7wkBRwsSHt7tVPv/HT3T8JaVaor2sQttV4r34UT1/6XtvzzTa X-Received: by 2002:ac8:5bcf:0:b0:40a:fc6a:e86e with SMTP id b15-20020ac85bcf000000b0040afc6ae86emr1442298qtb.62.1691529027118; Tue, 08 Aug 2023 14:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691529027; cv=none; d=google.com; s=arc-20160816; b=ArU9pibSRTzeo6njzquwS964jiSi3yls0CDWlXpzaun8a5dAd6U7ggnawzUNYUIYoU BO4Mb2a5LIy0KKioiGlR6x1nUEE1zlEmpNbpVBqe34Gkrls/vfSUTCr5cKjHHtjFSrnM AFaGPP42/eB++QiEe1elp/jU+9bFHHfKpdzuljmWZRUQsS2g5WMp+MFDEqgb/Yd0m2mx wEYFhcaqE2JE04B05b+panIQiuYZkyKWzs35kZqNqnKLA0ysbIzbadoW17lMF2Bq+2yc +mKRxs/+KGXzmwbOlKq1MSTkzEVtiHFCQZHpGCmLKHhLiGZDIxVbaKExlKJC+hytAqDw IvmA== 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=p1NLSIvorkQrsaaDKLyaBigg9Lde4sad1iqhAbZMlyw=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=0pc0P1bZxgAJWqVr0HH4N8ccHNQif+qyeeNFAOL5yGEFH5HIvV+WrQq/GlbTckpX92 anl20+HilLQnyIx59vIB6BgMuzt+NA3PKcsZBXIGydr97g0Gl4TCNvbo7EFhHW6udMaj yELuPsIfSdnvTdGeh0++FFGbI0uygTEeH6AGRabYcuHDfGeyXIbbMqaGF1KNl+eXwnZy qCTBmv0b5bO3qW79Q/Q66VfIcYoFyO3YGaWgel5WfWAupG4kBSAtKGZfJ2hoqs8PHoIn HjFiQL6thmXAWCixfR8c/XXg4b2ktbpCzQnB7xh575PzNK936Vu2mQvuc7Dq9whDP8Uz LYtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MDpP9kd7; 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 p11-20020a05622a048b00b00403489b9d8fsi6982709qtx.472.2023.08.08.14.10.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Aug 2023 14:10:27 -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=MDpP9kd7; 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 1qTTwt-0007ez-TR; Tue, 08 Aug 2023 17:09:03 -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 1qTTws-0007eP-44 for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:02 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTTwq-0005vF-BH for qemu-devel@nongnu.org; Tue, 08 Aug 2023 17:09:01 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bc3d94d40fso53342925ad.3 for ; Tue, 08 Aug 2023 14:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691528939; x=1692133739; 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=p1NLSIvorkQrsaaDKLyaBigg9Lde4sad1iqhAbZMlyw=; b=MDpP9kd7pBJnh2iFK0ctNMk5dSBef9/29x7WlX4pZnMuIP7GlBFsLMgqrvTrXk/koM JZ8k94EdoUwS+lkhgVwEZq5tYlbz8g03IhQcsiWa3BLywJAiU4TIDSO++1jUPnxMaqMi nHKv/1pLs3yyoaMxJw7Lgj1JATSHmKEYeubktBkZTru1i8v05dDiUANLbVyh4sU9PaJp whR5ud+QMwXONiItj3XyvnK0Vxi8Nye3WeWapifVDGuvOJsXBPnuDwk1JccqKap/W3QI IdhrbOPpcEF2cB5NSKdI1FwdUkwHuVHH6TSInc3VvzEiwEdUfIDHFai2TnWvMJ0gASRV TedQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691528939; x=1692133739; 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=p1NLSIvorkQrsaaDKLyaBigg9Lde4sad1iqhAbZMlyw=; b=MgymohYg/HfyyweHXShfUhkM7Zj5SOtnrwucTjzusr9QMNcQAPM8nsce3Lzbcge7sE zztObyRR+eETT4slrlZ/88Vv5cXTnOfLNRZVKnE+HY0fosDTgr3h4TQnM5I63zDcSKuX 4Z7V2IcQOstHEad22E6gu/iPeNQPQjvb/OH1jAw2o5Ewbn4zp2r9yN1fOdE3aRngS1Wc 2JolgOVO8LBwgwAomCRG9psIZU1SNGWfwA0NO5m9mxQojpA4hy8U0xDwwT+hGfny8vL+ mwsbtCX178rJnUG004GXb0Xpmd41tJ/rZ6Wzykxek9VTQvgfx972D9MOITsJX3P5Yg3D +h2g== X-Gm-Message-State: AOJu0Yx7WcInMwNxA+KnqDij5py8s+yHyIzPCHsXWiRvE+ZA3cf1/BXT b0iBrnqErPyxpqnaa0MaQUiIFYhhu6kEgPyPb4U= X-Received: by 2002:a17:902:dacf:b0:1bb:97d0:c628 with SMTP id q15-20020a170902dacf00b001bb97d0c628mr1038330plx.31.1691528938986; Tue, 08 Aug 2023 14:08:58 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:63dc:2a47:f4bc:4a95]) by smtp.gmail.com with ESMTPSA id k11-20020a170902694b00b001b3fb2f0296sm9437533plt.120.2023.08.08.14.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Aug 2023 14:08:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 01/14] linux-user: Adjust task_unmapped_base for reserved_va Date: Tue, 8 Aug 2023 14:08:43 -0700 Message-Id: <20230808210856.95568-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808210856.95568-1-richard.henderson@linaro.org> References: <20230808210856.95568-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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 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. Tested-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 34 +++++++++++++++++++++++++++++++++- linux-user/main.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..2c9d99ed6c 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,39 @@ #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 + +/* + * Guest parameters for the ADDR_COMPAT_LAYOUT personality + * (at present this is the only layout supported by QEMU). + * + * TASK_UNMAPPED_BASE: For mmap without hint (addr != 0), the search + * for unused virtual memory begins at TASK_UNMAPPED_BASE. + * + * task_unmapped_base: When the guest address space is limited via -R, + * the value of TASK_UNMAPPED_BASE is adjusted to fit. + */ +extern abi_ulong task_unmapped_base; + +/* + * mmap_next_start: The base address for the next mmap without hint, + * increased after each successful map, starting at task_unmapped_base. + * This is an optimization within QEMU and not part of ADDR_COMPAT_LAYOUT. + */ +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 +59,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 556956c363..be621dc792 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -821,6 +821,34 @@ int main(int argc, char **argv, char **envp) reserved_va = max_reserved_va; } + /* + * Temporarily disable + * "comparison is always false due to limited range of data type" + * due to comparison between (possible) uint64_t and uintptr_t. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + + /* + * 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; + +#pragma GCC diagnostic pop + { 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;