From patchwork Thu Aug 3 01:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 709591 Delivered-To: patch@linaro.org Received: by 2002:ab3:5b92:0:b0:238:c968:2573 with SMTP id j18csp1354461ltf; Wed, 2 Aug 2023 18:55:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHyt5Im/d1D9Q4gwbOnU7FRW9xMhzE/MzEsncIRbfnOHCVMBr32zKnA3LFxXU4zhtkL+DCh X-Received: by 2002:a05:620a:1a1f:b0:76c:e027:2c1f with SMTP id bk31-20020a05620a1a1f00b0076ce0272c1fmr489274qkb.14.1691027754626; Wed, 02 Aug 2023 18:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691027754; cv=none; d=google.com; s=arc-20160816; b=gpXUGwm8NiaUbqxyJu/E+nXoJvL8off5sukdkF5ZMmxXUuw7MXw+662VKkv1vGuEF9 7zZvFFId7DzqPR1K+ja6XlbXtUYuPIFer5ZRaKVnb4vwm6HRhVzJRMUy+iePfKzkrBKO +qCdFGUrCNIf9fk6eNmrUScbm/OEd74ncCqIVG2lOGOZ6mNh2/eCTumQRzN3QQ3SyolV RutrQxJ6nNrbm7uAm1p3BHZDujzRXTEhEEl6q3ZODxqiF66lOnpHBDeLYOqX5Yvhw9PN b0Pu+fEyAiEhZrgFekyrac83Csx8Fc0LmjiHUoVpcHGVZabnC+pFM0io/2sa3dAJ+PMv at/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; fh=fmVFRXV+XPDbp8+eafcQB359/x6dDRQDsVzPMZJ0Hao=; b=J1FH1zdYJjFFvRyOnXX2YGY1J1amvvKPaNlAwHC9DnD1x/X1595QNIP9aeSRrhjsoQ 4Xi5+0DXn/l1kDVuGsWZu+EYO2tEJMReRteEPNgKcgcvt/ENtd5k5CzCvvykNFa4uxiz ucyq61zQJtpBldfgo43stbtSnevUqyIxhrrR51CwPdM3JkUJCc7Tlt2LoaIqEXuCMbKz xlsSYNk5xAZalyt/iUd9RT+awFcK2h+lxziTy8Rc04K6FZeiu3EU9gwJ0txSI75VZrf8 gN5IFRLp6CvVPFHWJUqNVDTrq3wKYU2aAY8+ig5j+1LtJ8XD7kSuSKLVyCAy954NblXt R96w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h6AXkEcX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h12-20020ac8584c000000b00406848f568dsi9703687qth.671.2023.08.02.18.55.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Aug 2023 18:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h6AXkEcX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRNWe-0000hG-FV; Wed, 02 Aug 2023 21:53:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRNWc-0000gE-ES for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:14 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qRNWa-0000mf-Na for qemu-devel@nongnu.org; Wed, 02 Aug 2023 21:53:14 -0400 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3a5ad4477a7so316351b6e.1 for ; Wed, 02 Aug 2023 18:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691027591; x=1691632391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; b=h6AXkEcXy7q7Gfjm4SNKw3qfW/GGsR9sEiJZ+T5/0Xswp18ItRzQerWj6Nqh93quF+ vfVm9jQm2XBmrOTarB35619JSQfot6YxNGNrMDhOrvX/fzDmE35+EIpC5/iAa9AJNbuT 4nHC9T+RGEXZbOYcQOW2pYnc/uZB3nXEfyYryg6k3dFYB0d+ji94xkhGYni426WEWZXF 9NxouIJttx+E1Uc2pqXZMDljCkQx1mgB+0bBygyUP+HM8Rqvyao6M/EWE6sVzE+prQX5 G69F1z+Jq6VnKcJF2+vf++wDLAEkmXj8u+plTK7XVnDNWxvz3SE2FEmIIj8mL9QqlSs5 xbcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691027591; x=1691632391; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aEyLi7PRVP/zH4T2EImkSfY8Qlh6o6YBBN9cdFqzGtY=; b=Da4XLQbmvQKNP77nSUyAfa6dxvnTOCebcA8faef3dHFywkw5Zjqo16N8L1HMh5Yykw 9mVvI48M0tybzT1wqYnos9JqNVbZxs9HF84brJxdF2gvtdkuOysAWanAsWXVSMda77ak abAVUVL40Pp4UOQ7o8lH8mSQXxMRwZTmHr6SbIa8/ayTweFSkVF0YCrtWH1mHGt1y+X3 0eWJMYKi+2El93hIEJ80rTdgfbSpsI1VVfLT5ihMWz73veOsAf1g+IgSKKcDZqJp3eIo SAm1u33TvZ4Msn2X8fz92hGBJrpTFTh09TcLg0jeHdf1VrTyC+EQaSH77JCiCdMPK+F3 kGfg== X-Gm-Message-State: ABy/qLZKggRfaTasEjcJ+pL67kWCZTl54ztauU8GdX44o4GwUPpqM9iv GpwcXhd4mA+JLtuuW6Fd6Cy5CiHJM0am97JJs/g= X-Received: by 2002:a05:6808:93:b0:3a7:5075:b0b8 with SMTP id s19-20020a056808009300b003a75075b0b8mr5699447oic.4.1691027591680; Wed, 02 Aug 2023 18:53:11 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:b659:bbad:1a22:7ef9]) by smtp.gmail.com with ESMTPSA id s25-20020a63a319000000b005649cee408fsm157123pge.0.2023.08.02.18.53.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 18:53:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de, laurent@vivier.eu, akihiko.odaki@daynix.com, joel@jms.id.au Subject: [PATCH v7 09/14] linux-user: Adjust task_unmapped_base for reserved_va Date: Wed, 2 Aug 2023 18:52:57 -0700 Message-Id: <20230803015302.407219-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230803015302.407219-1-richard.henderson@linaro.org> References: <20230803015302.407219-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22a; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Ensure that the chosen values for mmap_next_start and task_unmapped_base are within the guest address space. Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 18 +++++++++++++++++- linux-user/main.c | 26 ++++++++++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..fd456e024e 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,23 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H +#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 +#ifdef TARGET_AARCH64 +# define TASK_UNMAPPED_BASE 0x5500000000 +#else +# define TASK_UNMAPPED_BASE (1ul << 38) +#endif +#else +#ifdef TARGET_HPPA +# define TASK_UNMAPPED_BASE 0xfa000000 +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +#endif + +extern abi_ulong task_unmapped_base; +extern abi_ulong mmap_next_start; + int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset); @@ -26,7 +43,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..c207b783d5 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -821,6 +821,32 @@ int main(int argc, char **argv, char **envp) reserved_va = max_reserved_va; } + /* + * Promote X and Y to a common type and compare. + * ??? Perhaps better to locally disable -Werror=type-limits. + */ +#define LESS(X, Y) ((1 ? X : Y) < (1 ? Y : X)) + + /* + * Select an initial value for task_unmapped_base that is in range. + */ + if (reserved_va) { + if (LESS(TASK_UNMAPPED_BASE, reserved_va)) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base = TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (LESS(TASK_UNMAPPED_BASE, UINTPTR_MAX)) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base = 0x10000000; + } + mmap_next_start = task_unmapped_base; + +#undef LESS + { Error *err = NULL; if (seed_optarg != NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index eb04fab8ab..84436d45c8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -299,20 +299,8 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, return true; } -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif -abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; /* * Subroutine of mmap_find_vma, used when we have pre-allocated @@ -391,7 +379,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) if ((addr & (align - 1)) == 0) { /* Success. */ - if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) { + if (start == mmap_next_start && addr >= task_unmapped_base) { mmap_next_start = addr + size; } return addr;