From nobody Thu Nov 28 14:52:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1691293151; cv=none; d=zohomail.com; s=zohoarc; b=nZXMwaN7hCEifxrSQexS7LsoNlXXlawlpslj/8wl9oDmGcnitdbH4crPn9aLu3K8yqkNZw744lcC0cK78/JZ/z7HO4au6Uu4vaGK3zGejnV5UP3Kld68t+xJ+NC1yLMe2lEZFfvNSCfq65pi6LlLfdQaZ2D5ald1BLPSjlXwDYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691293151; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; b=PB3+AyvpT1D39YioY00GDv6v4LZr528zd3MKGDhtEuo9hyZfH5uwlQWsFl3MZThgdPaMwj6uDlUnm94VY1e1EC+rcv60j7rxs9wIbzlOac5gBkVKuO9inRZn+RWUngk6nYPEImJ9lOEuMPRSZvoLHPHpVVEDXY2tLmC5v80+eFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691293151759159.9355539414306; Sat, 5 Aug 2023 20:39:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaB-0003gB-9f; Sat, 05 Aug 2023 23:37:31 -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 1qSUaA-0003g2-2v for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:30 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa8-0007Yp-G8 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:29 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bc3d94d40fso30158215ad.3 for ; Sat, 05 Aug 2023 20:37:28 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293047; x=1691897847; 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=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; b=ohQkimh57o+3PKRomccxlomjCdTC6totXVlv6tBnj8BvfSwzF2il2G/KD6W9RCNK9q iI2/Itua2PKXspsBthWC/FzgVeCd7naWWN1Um72XQjTn+fb0DSyJRdAMV1C3QO9wbTny oL+kHdZ657fMLk3Pn87yuaILm4LxtpJCWckGP3uzZzN9NTZG5lZkLQLsGxURtHarLQ/R L39cNlZW+KRrsNn0c0hyXfU5h1blMXSGWTpN9ePM5JqDD1bsTi0I4P9vR9I5TmrrCGJ+ 3udYT5BzZlHEvwPZxf5AeAl8UardeaBPdwGAmjyzHzAFQf4dw+PyC4WnAEw7Wr/A2Kmh J3Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293047; x=1691897847; 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=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; b=X5bS+gniVvq4r1kg5C92slDO6tJ6PneJc4kDU2B0WTXQ7bmHXUGlCf3KLqUtJ0YkSq IRx+8ht96lKrpff6ttkrCKuFJV8bsi6OxRXIfg8A/7JvZ8mEZjoX/A1eCmeAaTH/BKe9 4P3ReO40ITF4nxWb+3R56KbIUj7PM8axwsxS3Pn8CpAZMfRWfRGVPHw6QiO3RgkU+Y1m B8i6BzPhVkJR7PL8HvO1mVslDE+CR1VorJTIFLtFiS+YyWy/dqrqS8P0FKrQy4Q68Lav GaAvI+Kf9Pf28GuPAaCSwT1pcQrTMqmJNis2JSRHrPUFtEvK8KYl6wxYYrQhIx40ns0o 0Frg== X-Gm-Message-State: AOJu0YwMKapJH3mbkCU0ZomNxFUcgk9qqzod8OF+Sb/of/kd2SLJ+4uN C9yacnMhX7nRRqMgJ6uW/WEgm6qQ1u7RDdeC2kQ= X-Google-Smtp-Source: AGHT+IFXJ6kiOAsJJmCfySyJIcQnWxkGs6tDar6xrmyMqUyrI3ZEg7HXfXs99sm/uvIF7dxOAZISRQ== X-Received: by 2002:a17:902:db10:b0:1b8:b41a:d4be with SMTP id m16-20020a170902db1000b001b8b41ad4bemr8439770plx.10.1691293046944; Sat, 05 Aug 2023 20:37:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 13/24] linux-user: Adjust task_unmapped_base for reserved_va Date: Sat, 5 Aug 2023 20:37:04 -0700 Message-Id: <20230806033715.244648-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1691293153973100003 Content-Type: text/plain; charset="utf-8" Ensure that the chosen values for mmap_next_start and task_unmapped_base are within the guest address space. Tested-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 18 +++++++++++++++++- linux-user/main.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..fd456e024e 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,23 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H =20 +#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 64 +#ifdef TARGET_AARCH64 +# define TASK_UNMAPPED_BASE 0x5500000000 +#else +# define TASK_UNMAPPED_BASE (1ul << 38) +#endif +#else +#ifdef TARGET_HPPA +# define TASK_UNMAPPED_BASE 0xfa000000 +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +#endif + +extern abi_ulong task_unmapped_base; +extern abi_ulong mmap_next_start; + int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset); @@ -26,7 +43,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_= size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..7ba7039988 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 =3D max_reserved_va; } =20 + /* + * 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 =3D TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base =3D TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (TASK_UNMAPPED_BASE < UINTPTR_MAX) { + task_unmapped_base =3D TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base =3D 0x10000000; + } + mmap_next_start =3D task_unmapped_base; + +#pragma GCC diagnostic pop + { Error *err =3D NULL; if (seed_optarg !=3D NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index eb04fab8ab..84436d45c8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -299,20 +299,8 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong = start, abi_ulong last, return true; } =20 -#if HOST_LONG_BITS =3D=3D 64 && TARGET_ABI_BITS =3D=3D 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif -abi_ulong mmap_next_start =3D TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; =20 /* * Subroutine of mmap_find_vma, used when we have pre-allocated @@ -391,7 +379,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size= , abi_ulong align) =20 if ((addr & (align - 1)) =3D=3D 0) { /* Success. */ - if (start =3D=3D mmap_next_start && addr >=3D TASK_UNMAPPE= D_BASE) { + if (start =3D=3D mmap_next_start && addr >=3D task_unmappe= d_base) { mmap_next_start =3D addr + size; } return addr; --=20 2.34.1