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;