From nobody Fri May 3 20:07:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1566500537; cv=none; d=zoho.com; s=zohoarc; b=FeK0SdA3SHmMxFBM3CcI5zjXICcIfxzRAMjUJfz08Gmz5bFQmQHh5qE6IOlpZI6PEmmDKxqkO9wgR8VIYcddTsYywdd02IJp80un/WvCkZ7tNoQH4h6SOqSBX36k/iHHUYvOUWVEv0s1SowsmvxD4KnXpsozrMSgzE933vDvXAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566500537; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JEmEzPFUR0isRb5JQ5Z7wSqHYLVLETQrUR8Yc9g4NhM=; b=Om/1oVce8KQ09f6S3/5HRTnriyX+PK2wngxCFaBvsjgwlTJcqrdxkonw5auzpyfyRQc7cuexwV3r3BJLQzXD8i9RCcRPh9l/679tLpooKuxikfcF8Zf6COZtxsQRliC6UJMLaJyKB3zwsl8oSHhTcAEUfBR63evx0V3VeqPztoc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566500537059486.49066473668904; Thu, 22 Aug 2019 12:02:17 -0700 (PDT) Received: from localhost ([::1]:47232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0sLa-0006rQ-Ga for importer@patchew.org; Thu, 22 Aug 2019 15:02:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36945) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0sJ6-0005Ps-9o for qemu-devel@nongnu.org; Thu, 22 Aug 2019 14:59:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0sJ5-0004Q2-3O for qemu-devel@nongnu.org; Thu, 22 Aug 2019 14:59:36 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:39599) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i0sJ4-0004PB-Gm for qemu-devel@nongnu.org; Thu, 22 Aug 2019 14:59:34 -0400 Received: by mail-pf1-x442.google.com with SMTP id f17so4559603pfn.6 for ; Thu, 22 Aug 2019 11:59:34 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id z14sm287172pjr.23.2019.08.22.11.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2019 11:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JEmEzPFUR0isRb5JQ5Z7wSqHYLVLETQrUR8Yc9g4NhM=; b=abEnu8CkM/9kBWuTfT9N7ZLJPePRAqPsXyr3fG9kz5XWj6F33cXwt8kaf+k5b8yx/g V/bu2G08j5BX/U9GkdzUKamffjAdOB92eL5pW/gyPjmYzUkTgGxKqDsotWuSxyw/tPEB 6QbHHzqpzzEMob27e3qTMIqufm9y2znOHnlISWdin1LTuqcgnNjtZyGc/gUhoYp68KtL BtdP4k2pIJR5Cw287fskR+AjvdWYEBKAW3gVEKbf+SvNhI210rVFJnyCBbqp2vmHMnZG CWn5s9Xx5kk50xuRxQI1nXw///uP5szjMX3VIKyRRRkQMVu0kR4uJMxloVGqPtc2o1f+ k5BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JEmEzPFUR0isRb5JQ5Z7wSqHYLVLETQrUR8Yc9g4NhM=; b=ll8qJ56VSN9W2FCb5x5yPd0e7yQMLsoKUpR+J2uzhc1ckvCMGKRfjzMpK26uJzglot pqQDZHPN5oAqYk2QAqkjCkg0jnk9jX9a1jfFUyw8tP/NLeba4bxyW515kpwKJmQ2/Jij gsKi3t/aoZkb+49c0Tl+ZgoNk4ChrGbBINHh/MeSRlSgEVQjuJeIZQJibDL+PMNKug3Y NCjaC6o4l2ymDiXd+2/C0W9QXki4TiDyTSQBtZwiZ53j0j20ASJQoLFMKxZrxpc1t8VK Yg+ErWXf621UbYEG/GrbCT+wa2nMTSaz8DSK0s5yl/lp61JCagAn7JKceGusarBosvZ5 FHUQ== X-Gm-Message-State: APjAAAVHZtrN6isIIQWgaRR+IkEh5muqh+G/sVCtY1hbopo7IccjPMCr KfuLNcrDMtwwWz6wkf8q90fHy8gVjsc= X-Google-Smtp-Source: APXvYqwavJBOjWP/EV4LuDA1nZQNXi56nZQoLFd4TgdI7DhhfKlhThe/X4fcAymZkiE59Xe6DZy7hA== X-Received: by 2002:a63:4e05:: with SMTP id c5mr597564pgb.396.1566500372874; Thu, 22 Aug 2019 11:59:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 11:59:28 -0700 Message-Id: <20190822185929.16891-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190822185929.16891-1-richard.henderson@linaro.org> References: <20190822185929.16891-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH 1/2] linux-user: Pass CPUState to MAX_RESERVED_VA X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Turn the scalar macro into a functional macro. Move the creation of the cpu up a bit within main() so that we can pass it to the invocation of MAX_RESERVED_VA. Delay the validation of the -R parameter until MAX_RESERVED_VA is computed. So far no changes to any of the MAX_RESERVED_VA macros to actually use the cpu in any way, but ARM will need it. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- linux-user/arm/target_cpu.h | 2 +- linux-user/main.c | 43 +++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h index 8a3764919a..279ea532d5 100644 --- a/linux-user/arm/target_cpu.h +++ b/linux-user/arm/target_cpu.h @@ -21,7 +21,7 @@ =20 /* We need to be able to map the commpage. See validate_guest_space in linux-user/elfload.c. */ -#define MAX_RESERVED_VA 0xffff0000ul +#define MAX_RESERVED_VA(CPU) 0xffff0000ul =20 static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp) { diff --git a/linux-user/main.c b/linux-user/main.c index 47917bbb20..35da3bf14c 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -78,12 +78,12 @@ int have_guest_base; (TARGET_LONG_BITS =3D=3D 32 || defined(TARGET_ABI32)) /* There are a number of places where we assign reserved_va to a variable of type abi_ulong and expect it to fit. Avoid the last page. */ -# define MAX_RESERVED_VA (0xfffffffful & TARGET_PAGE_MASK) +# define MAX_RESERVED_VA(CPU) (0xfffffffful & TARGET_PAGE_MASK) # else -# define MAX_RESERVED_VA (1ul << TARGET_VIRT_ADDR_SPACE_BITS) +# define MAX_RESERVED_VA(CPU) (1ul << TARGET_VIRT_ADDR_SPACE_BITS) # endif # else -# define MAX_RESERVED_VA 0 +# define MAX_RESERVED_VA(CPU) 0 # endif #endif =20 @@ -357,8 +357,7 @@ static void handle_arg_reserved_va(const char *arg) unsigned long unshifted =3D reserved_va; p++; reserved_va <<=3D shift; - if (reserved_va >> shift !=3D unshifted - || (MAX_RESERVED_VA && reserved_va > MAX_RESERVED_VA)) { + if (reserved_va >> shift !=3D unshifted) { fprintf(stderr, "Reserved virtual address too big\n"); exit(EXIT_FAILURE); } @@ -607,6 +606,7 @@ int main(int argc, char **argv, char **envp) int i; int ret; int execfd; + unsigned long max_reserved_va; =20 error_init(argv[0]); module_call_init(MODULE_INIT_TRACE); @@ -672,24 +672,31 @@ int main(int argc, char **argv, char **envp) /* init tcg before creating CPUs and to get qemu_host_page_size */ tcg_exec_init(0); =20 - /* Reserving *too* much vm space via mmap can run into problems - with rlimits, oom due to page table creation, etc. We will still t= ry it, - if directed by the command-line option, but not by default. */ - if (HOST_LONG_BITS =3D=3D 64 && - TARGET_VIRT_ADDR_SPACE_BITS <=3D 32 && - reserved_va =3D=3D 0) { - /* reserved_va must be aligned with the host page size - * as it is used with mmap() - */ - reserved_va =3D MAX_RESERVED_VA & qemu_host_page_mask; - } - cpu =3D cpu_create(cpu_type); env =3D cpu->env_ptr; cpu_reset(cpu); - thread_cpu =3D cpu; =20 + /* + * Reserving too much vm space via mmap can run into problems + * with rlimits, oom due to page table creation, etc. We will + * still try it, if directed by the command-line option, but + * not by default. + */ + max_reserved_va =3D MAX_RESERVED_VA(cpu); + if (reserved_va !=3D 0) { + if (max_reserved_va && reserved_va > max_reserved_va) { + fprintf(stderr, "Reserved virtual address too big\n"); + exit(EXIT_FAILURE); + } + } else if (HOST_LONG_BITS =3D=3D 64 && TARGET_VIRT_ADDR_SPACE_BITS <= =3D 32) { + /* + * reserved_va must be aligned with the host page size + * as it is used with mmap() + */ + reserved_va =3D max_reserved_va & qemu_host_page_mask; + } + if (getenv("QEMU_STRACE")) { do_strace =3D 1; } --=20 2.17.1 From nobody Fri May 3 20:07:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1566500542; cv=none; d=zoho.com; s=zohoarc; b=GQFANzyW9r0huLSnGp0iw3NDNrrUUnaoFo1bv6LzVSFznZkojElMN+k7+hT7QMeEdrhVV0MBayeVhBx4pe/oPOW18+HuG65dOfr5L7pFHbjsnQx12mlQ1I0ejiZReRfsOGB/bimQaD+bv1zJjnZhpurSxOyfu80Ti0F3FCxqPMU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566500542; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1Ly/U6ykcHLVzGazIt39CUi/LITjT+MWMWABpH7UFOY=; b=mPb0wCn0vzFhbFvfpNmgtUw3UfFgDnnu0WIiHgqSuzRP2msUPEVgK4H33gIVf8+PysAjLYsz82dkx+60q6xoHSDSPpHkd0+3gOcMSIZUnnA0NOU/nx9ARE68/L40Ki5i2fPrVkalSonj2gmUkscnUSbIyYTv08iu978xSzswLFk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566500542221159.6838437063535; Thu, 22 Aug 2019 12:02:22 -0700 (PDT) Received: from localhost ([::1]:47236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0sLc-0006sd-6A for importer@patchew.org; Thu, 22 Aug 2019 15:02:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36957) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0sJ6-0005Pt-T1 for qemu-devel@nongnu.org; Thu, 22 Aug 2019 14:59:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0sJ5-0004Qm-SQ for qemu-devel@nongnu.org; Thu, 22 Aug 2019 14:59:36 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:44764) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i0sJ5-0004Pz-Mt for qemu-devel@nongnu.org; Thu, 22 Aug 2019 14:59:35 -0400 Received: by mail-pg1-x542.google.com with SMTP id i18so4182225pgl.11 for ; Thu, 22 Aug 2019 11:59:35 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id z14sm287172pjr.23.2019.08.22.11.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2019 11:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1Ly/U6ykcHLVzGazIt39CUi/LITjT+MWMWABpH7UFOY=; b=brt0UGnHo1XONAee1WLeKYbX6nr1rx5j7oiFXVVvG1sBHfuG2ubLZTcyb+R/7Zs1nL scsmqpP2YtZt1Hjqpi/u/z6Hz9DvNUffYn4b3XBy12E5fxKHO4jv6fNAx2Or8QFX2NT6 Jg4jBZmfkrRAy4pd9Km/Y/Kb/czEGTHZBfyxfkuHRdY7kieI80oQhBVY8/M4RnxX2h/2 0d20VOY6sJZ8Uk71Xte7XRQgDY0qHUSfmA0xfhyPRUdLcYiTjWbBqbEgue0/3w3/lSfp +hm1Y15pJed1J8tt4IGzF8wftb1maP0qcWOTm5bCW6sbAF3eVLHtuNarGmJ4il9HYPeq WYMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1Ly/U6ykcHLVzGazIt39CUi/LITjT+MWMWABpH7UFOY=; b=Ly3XPBEcSF7r8MQ8TO/AIHFPqDK6WX1q6jdgwdTWlh7xZ6UPGAWlWQ+/Bu5DTSpgsT wiMwsQLZ0CVvjSkoghmy39g3EEpdd8mORbShCQdySqf8cQStjXyCbF+XnlPehDdz9I+I rrdm9Q9BF2X9YRnjrcTsVnNDvv4BlWa9hwPRRqwF8PJZQuKgQWTmRhYOqdo9KEiqI3ob 0PmyU74/BRDqLWLnVgm8yG5j82c9bf/CEx1NR4l62v5fQJeNWKX7fhW18HC3pXZiychh egaLy83l55Zpxivax/+HLvY3UqQhPm9I0gtB31WZWfos87Vyh0AF7y+XGPuR0PN/TCgf lhSw== X-Gm-Message-State: APjAAAWqeUUOr23YNVR8ZtpZnTRsJts8RHH0MBawdeoOhar9qA7otiH7 Y5OV5VHxePn9ppVzotprdgam/s/NjjM= X-Google-Smtp-Source: APXvYqyriG6fhxD/YfLbPZ2IZPOVfzGu/eSropSX2vjv6GxGlxM+CdlmD+rRQbg2PPuBaZPjl8bApw== X-Received: by 2002:a62:1858:: with SMTP id 85mr761268pfy.120.1566500374282; Thu, 22 Aug 2019 11:59:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 11:59:29 -0700 Message-Id: <20190822185929.16891-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190822185929.16891-1-richard.henderson@linaro.org> References: <20190822185929.16891-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH 2/2] linux-user/arm: Adjust MAX_RESERVED_VA for M-profile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Limit the virtual address space for M-profile cpus to 2GB, so that we avoid all of the magic addresses in the top half of the M-profile system map. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- linux-user/arm/target_cpu.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h index 279ea532d5..3f79356a07 100644 --- a/linux-user/arm/target_cpu.h +++ b/linux-user/arm/target_cpu.h @@ -19,9 +19,27 @@ #ifndef ARM_TARGET_CPU_H #define ARM_TARGET_CPU_H =20 -/* We need to be able to map the commpage. - See validate_guest_space in linux-user/elfload.c. */ -#define MAX_RESERVED_VA(CPU) 0xffff0000ul +static inline unsigned long arm_max_reserved_va(CPUState *cs) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + + if (arm_feature(&cpu->env, ARM_FEATURE_M)) { + /* + * There are magic return addresses above 0xfe000000, + * and in general a lot of M-profile system stuff in + * the high addresses. Restrict linux-user to the + * cached write-back RAM in the system map. + */ + return 0x80000000ul; + } else { + /* + * We need to be able to map the commpage. + * See validate_guest_space in linux-user/elfload.c. + */ + return 0xffff0000ul; + } +} +#define MAX_RESERVED_VA arm_max_reserved_va =20 static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp) { --=20 2.17.1