From patchwork Sun Oct 10 17:43:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 515602 Delivered-To: patch@linaro.org Received: by 2002:ac0:b5cc:0:0:0:0:0 with SMTP id x12csp3819095ime; Sun, 10 Oct 2021 10:53:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8Wr95wcizVUvZrK+4cx0He9LnUqZ9LpToqk+3sj4ADc5QO72N8Kosc9EPPvMwAC5Me+EU X-Received: by 2002:ac8:7c92:: with SMTP id y18mr10504063qtv.215.1633888407166; Sun, 10 Oct 2021 10:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633888407; cv=none; d=google.com; s=arc-20160816; b=xh4h+B2DsAr+6tkdj1DZI6Zz6RQdj7hR4WczQIwaJM3ghH5V4hh8dot2Hmp0yMZiFj LOBmEU3bSiZnW6BYEfPQ1xmsG2GkvCRv5hD1aCQqsdwKuRDrGcxgMYr6Qj6Oy140rcx1 5l1yx5ayLkF58731rTH5MBa/4TzwxQJfnGEH5PR2e3xu/6frojiKndpyoceTQ/e3Qm1f /Z06iLj8lmbQQUNWO2j0NUc7h/CDMApy0PhEq1HTuPHCPmXOnrNu3fea1xtWr0If4ADp 2cvELbgAYsNeD6Dj6uLMorp3kef0NZfJtFaqWkKQfrpV0/HGVH4FfHGDJIL1jqTK57SA IjwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=OA5lVsCVexffj4tJ1okwj2NEN/znxpIAZbVY6q21rhk=; b=Et+zrdSCHqADAxnENeW/Yw5AcG5JbsaXr1Ci17c2SvymBhfk5W5FruyVmGc6Kx9moG 94/c1sOtbXF3axMbUqsQfKjNsbcKMdNVCLHvXtfKHKKvr+ZCipNacJwt/pgN/0JI5m46 Z608JlbllPdyTZHk0fWWmSQ6YRX2QqJhLnJ1AeNBdHw/RBoJVkSzCihG5+sDffDPJ+9n QxIPAYz+Ri1VKsoVuW3YYHvuR7PcUcmyLeAW58n4iQxyExlZb0v2yhYMCabZEATcmcPC TxyPN2smt0P0yGLzfK6WdxX7SzwdraGoov4MNqn8jMMkuabDTHg5w5jb+hykuI30KZnH 8h/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yLhsQCd3; 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=fail (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 s9si3780265qtw.364.2021.10.10.10.53.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Oct 2021 10:53: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=fail header.i=@linaro.org header.s=google header.b=yLhsQCd3; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZd0o-0003h4-LY for patch@linaro.org; Sun, 10 Oct 2021 13:53:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZcrw-0000U0-0b for qemu-devel@nongnu.org; Sun, 10 Oct 2021 13:44:18 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:37499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mZcrt-0005pr-Sv for qemu-devel@nongnu.org; Sun, 10 Oct 2021 13:44:15 -0400 Received: by mail-pg1-x533.google.com with SMTP id r201so8619306pgr.4 for ; Sun, 10 Oct 2021 10:44:13 -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 :mime-version:content-transfer-encoding; bh=OA5lVsCVexffj4tJ1okwj2NEN/znxpIAZbVY6q21rhk=; b=yLhsQCd3YmmYfayNnkAeAZUSSqnntpP+6pSpKb1VFfSA6qGFG0d0JftU4Nir+ZUxn/ oPuqPfsNTERSbxFh13LviYPLwLCbteVmP4YQ+kbp1dEKG0AxArn33bKVgD9ta3M/7CWh +xmfX7KJf0wN1PyCS6VlBzqSM3PGnAfoZ6z0eAXlr2SFx+fsaNKH4ZeXk6cURhdAeNt0 fIC2jkKyzNAPyrOID0WuqzsaoAuxUh87njofjU7fgKnjZpLVVMk1/znlLyBlzjcYEdSm YQ9FIuDpN4jO6qgGh7ruo7cUdi5nPyf9e1un1hm4c7zvoZpt2jEbSxfpED/XIc472rIQ slMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OA5lVsCVexffj4tJ1okwj2NEN/znxpIAZbVY6q21rhk=; b=JtsdRnkM10x5RVGzuRjTjmRB+2h/NruL/WB0xFr0x9BINCQeiXXGhcujd091cZy8P9 I81TgcIDiESeZyRh7MC5D4x91Vv29JlvDfdQJ9F4XtaQzKBwDMYWacjgGyJspxSj++3q rhwCiRYXxWEqw97w4vGLHa3I2PuWZt4ebZJSzvZeflTepblnwyVpxAyB9Bs1F/tcoMC2 fVYLtHGpYUKGuSHyTcQhzdw7UKVDyy+WhPEA+O94V2Y4k+eQNV8LOUEz59LqB2YAIgu4 hqO4Il7F4JIotgBjMwGwiEQYvE+mkiY+ZWlK8eyiGgzDYtFTvCyceCiQY41A5l4C1zlN k6iQ== X-Gm-Message-State: AOAM533MaVr3uFv5dCpmDacAkmSvUrjQkkzP5CRQSHfU7enDX3olmXZf QqAgb+SXkSJ0SALbRdaNcFKCzr7hDGjaedp6 X-Received: by 2002:a62:6206:0:b0:44c:bc1f:aa5a with SMTP id w6-20020a626206000000b0044cbc1faa5amr20852668pfb.5.1633887852598; Sun, 10 Oct 2021 10:44:12 -0700 (PDT) Received: from localhost.localdomain (068-185-026-038.biz.spectrum.com. [68.185.26.38]) by smtp.gmail.com with ESMTPSA id 18sm5095391pfh.115.2021.10.10.10.44.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Oct 2021 10:44:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 4/8] accel/tcg: Add guest_base_signed_addr32 for user-only Date: Sun, 10 Oct 2021 10:43:57 -0700 Message-Id: <20211010174401.141339-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211010174401.141339-1-richard.henderson@linaro.org> References: <20211010174401.141339-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: git@xen0n.name, Alistair.Francis@wdc.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While the host may prefer to treat 32-bit addresses as signed, there are edge cases of guests that cannot be implemented with addresses 0x7fff_ffff and 0x8000_0000 being non-consecutive. Therefore, default to guest_base_signed_addr32 false, and allow probe_guest_base to determine whether it is possible to set it to true. A tcg backend which sets TCG_TARGET_SIGNED_ADDR32 will have to cope with either setting for user-only. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- include/exec/cpu-all.h | 16 ++++++++++++++++ include/exec/cpu_ldst.h | 3 ++- bsd-user/main.c | 4 ++++ linux-user/main.c | 3 +++ 4 files changed, 25 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 32cfb634c6..80b5e17329 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -146,6 +146,7 @@ static inline void tswap64s(uint64_t *s) #if defined(CONFIG_USER_ONLY) #include "exec/user/abitypes.h" +#include "tcg-target-sa32.h" /* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. @@ -154,6 +155,21 @@ extern uintptr_t guest_base; extern bool have_guest_base; extern unsigned long reserved_va; +#if TCG_TARGET_SIGNED_ADDR32 && TARGET_LONG_BITS == 32 +extern bool guest_base_signed_addr32; +#else +#define guest_base_signed_addr32 false +#endif + +static inline void set_guest_base_signed_addr32(void) +{ +#ifdef guest_base_signed_addr32 + qemu_build_not_reached(); +#else + guest_base_signed_addr32 = true; +#endif +} + /* * Limit the guest addresses as best we can. * diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index ce6ce82618..db760ff5c2 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -79,7 +79,8 @@ static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x) /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ static inline void *g2h_untagged(abi_ptr x) { - return (void *)((uintptr_t)(x) + guest_base); + uintptr_t hx = guest_base_signed_addr32 ? (int32_t)x : (uintptr_t)x; + return (void *)(guest_base + hx); } static inline void *g2h(CPUState *cs, abi_ptr x) diff --git a/bsd-user/main.c b/bsd-user/main.c index 48643eeabc..4fef0520da 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -54,6 +54,10 @@ int singlestep; uintptr_t guest_base; bool have_guest_base; +#ifndef guest_base_signed_addr32 +bool guest_base_signed_addr32; +#endif + /* * When running 32-on-64 we should make sure we can fit all of the possible * guest address space into a contiguous chunk of virtual host memory. diff --git a/linux-user/main.c b/linux-user/main.c index 16def5215d..ed7a88c195 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -72,6 +72,9 @@ static const char *seed_optarg; unsigned long mmap_min_addr; uintptr_t guest_base; bool have_guest_base; +#ifndef guest_base_signed_addr32 +bool guest_base_signed_addr32; +#endif /* * Used to implement backwards-compatibility for the `-strace`, and