From patchwork Tue Oct 19 14:09:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 515958 Delivered-To: patch@linaro.org Received: by 2002:ac0:cd8c:0:0:0:0:0 with SMTP id d12csp761152imp; Tue, 19 Oct 2021 08:20:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKgPgwbXDdS20hHE+BefLzBxIiR2YbS1bbNkzcDKnKloKj+JUcEe8J55tdXvV0aTGNo0NB X-Received: by 2002:a05:6830:2429:: with SMTP id k9mr5874930ots.61.1634656853200; Tue, 19 Oct 2021 08:20:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1634656853; cv=pass; d=google.com; s=arc-20160816; b=m10j4XgLOTnAzfCk6QwqWDppHXzNg+rtUyzzvJmrLDWEDC8lucLvQx3Niy5rOYDTT8 GCpQ2/8DtWJtCX9eTJUs+1AaXpgBiON+UlwkRG6ARflChLE8MJFKvoCWTTZ+KS6DhMRh XAr9AyE5B3lcYiGWegzchDWt0519s/yI8tosXIDWss/OdW8Bo9upnVVu+jHUONgaIteU BXs9e8j+SxzSmQ3+GVolNkxY2DYfEFI3YeEWOevJlIHyeDbgd9KbWPkfJ8DgGmWIsAUG arH2HbBsnkh+6GZBGQTYgAHiTQgoBEg4LnmTGrU9kNdnDY43LssEH5KUtjWf4juPsRdL 3rBw== ARC-Message-Signature: i=2; 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=GfQ+H/xpPCSSJRn737zt7+p9SVApowO2Em6kFD/nCzA=; b=o3z/TwC8SqDm8oVa5b7MWt+6LEx061IsJr8Kpf7uQLerr4/+cWac3Os810gim+6M3q Tbm0K78HU5BgroeJmdLYrOTjd0TucNUFS9yXhDLk8JehHiups6wp3hA+4mbN1HbnZA2z mvQ4vYXqQ8s7I2Z56t0N7k9ZJwimaqyN0ECvgj/BXZ/lJz7CzmxxEpSzGAwcPm9GlfNi 81sXjKo7MvO+9NVZjQO4fy2Jq4G4VmI3AkJ7ea/P9iFn9o0BvmGP01xE06wBjSrMtzxS 8IIzZQn4hq/KrJJKQzbwil6Of+gBxjQGJeO6BqhHkCxqQ/sxIO2e3aYtXJ2Kode+0jXB 3eDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=nMkAPDPS; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e62si18829840ote.216.2021.10.19.08.20.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Oct 2021 08:20:53 -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=@amd.com header.s=selector1 header.b=nMkAPDPS; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from localhost ([::1]:36992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcqv6-0003HU-AS for patch@linaro.org; Tue, 19 Oct 2021 11:20:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcq7k-0005Gx-41; Tue, 19 Oct 2021 10:29:52 -0400 Received: from mail-mw2nam12on2046.outbound.protection.outlook.com ([40.107.244.46]:22968 helo=NAM12-MW2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcq7h-0007zC-W2; Tue, 19 Oct 2021 10:29:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZyJn9thatxHCu4nGUxdFgXcokbtz1zOBDguEdJeUbpPl4TwGFJxuNSjlc6cqpaeMGQd5hlkKwUdA27ZeyDEHSPJi3lhLZzG1Vbr1swuXEHbHq7/SBqPeagsj+K8uJxOM6yfpWqIZhqJGYr50jAkBl9ENeRKdo0QlGi/LvSmWSLP3pAQ8vNLDoG2Ng+RWNg5mMwtKa89VXkd5rqIOPVZDUNH++l1CmagNyAvLeEkmXOawHYDI7ofjnpPBJOkevS14MxdZw6M3lairNMfHsutCUJo/uzwbcXf1UAuHHQws2M19lGvloaFhm0g5TdaUNr32xY01ERs2TTJINPlk0wZmig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GfQ+H/xpPCSSJRn737zt7+p9SVApowO2Em6kFD/nCzA=; b=KJM22b83nXNL1N4nwPDrQXIVgONtES2EJre04BBKk0oRu2eCcsSh4mdvqjCpbm7QTJf8w0Ad30xnJxTvv5m5Jwzv7tqVYs0A+IZG8vaIi31e35LeCmhL/i+SczxgN1jofdriHwTRhdPnH3wCAGp3pDx765pZdJ+PSQxOy5VBjAnWBUEiNGAcx3COgsssDpQJz9tv/aT3vDcpakQdk8ebXSrPdE6jvkEtLwJcdsNdFkCCRfMVcfzhX1h0Mb49k3nP9N/0VSDvdwHQsooVn4Djrg04Ao0YhJuT93vRn4h2mGauQrp/zSFoIYX1vSa0mudspIOlzQs37nzHz1MNGRx3nA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=nongnu.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GfQ+H/xpPCSSJRn737zt7+p9SVApowO2Em6kFD/nCzA=; b=nMkAPDPSYl2b8h15+qpxdjwmvM46GSCKHsQucwLnmAYY44pj+cayRW7lVohYV5USbUzodGq+qN9J22BFvAp/5vHz1PYii7A3UDiPI40qFWkxg+GhhZdBsJO9eZotNnXt1HDpssc0Ecw+rTZ0bS/KnkTOUvWpn4wUrJImALVAaUs= Received: from DM5PR04CA0048.namprd04.prod.outlook.com (2603:10b6:3:12b::34) by MW2PR12MB2490.namprd12.prod.outlook.com (2603:10b6:907:9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 14:29:44 +0000 Received: from DM6NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:3:12b:cafe::cf) by DM5PR04CA0048.outlook.office365.com (2603:10b6:3:12b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 14:29:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT011.mail.protection.outlook.com (10.13.172.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 14:29:44 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Tue, 19 Oct 2021 09:29:40 -0500 From: Michael Roth To: CC: , Peter Maydell , Richard Henderson Subject: [PATCH 47/64] target/arm: Don't skip M-profile reset entirely in user mode Date: Tue, 19 Oct 2021 09:09:27 -0500 Message-ID: <20211019140944.152419-48-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019140944.152419-1-michael.roth@amd.com> References: <20211019140944.152419-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e082f2a-e587-4255-8e0a-08d9930ce544 X-MS-TrafficTypeDiagnostic: MW2PR12MB2490: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NvP2qrNq+mnUh8iMU7Nbq9USkTqhmAXiYHrO3TWyq6Ki/AR/8L9AgWzL7VTRsz7z+JKzf2GTFaRV8TtBBuJPLTJBpB41VEcm2/NK7J7ppe4hDkfW1oXEGiuoS7MdE8orF7zHWDwfGL/XCWwYf9Ui+O13drBXFS+LICGSVDR30l8BPzbXoP12GzH1fPNLoxax8RjkysfcG/D1LMiGqVv1i1bZnkCm+YiNGLPkZ9HPLqPlWF+zBPOd0G2uVUOXn+uB7sZL65i5hls4D8zkXqEW87TvVm8CJwcw1V1rO5uk4rqMu4a1OteVTGfoCYMpo2JajXZbj8eK/wgECefiIy3lKjdDNYoEe9hF2DmEOtXKAAGfNu2CaJRylZQBPrUCx+Irbyu3MIB8qlEyL5hPuuW6S7cnIxnS7CC2lzo6eHSEokus0ovZUQY2pOogCmIS8LUVf0rVJvnA7QE+sifqDPL99gy22NyEzy+W3FAF9dovGU9Q8udzWVumAAjUN7FEn5m1D/7wYu2oZa/9TJ+tMCn2u3VoarKqEF8AIqr1O4M8xgdEdE/bqmWo5eAb5W83HGa7YMcOKVsAggJbaIhIMpFJx4LGWgUPgPnRuRRrJ4zK1kZxFk+mkperPMM5Pqdv1/pn3Rji9w//49XJHkMbOCzQ5AGxelOcQfXLTSN/tnPjvozx/xlX4S2Uytrovkvznl5PksX+WXYRJAL64W4ZoJ7VyYMeqKDM436adILeQxkiKz6TmC8nul6IzDEbUIGLpieo02GjAGUNqN71PZdhap1ISMU2jHN+Gq/csF17nxgbJ8wyfei9xLfbI4a1umxf9mUW X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(8676002)(5660300002)(2616005)(2906002)(36860700001)(86362001)(16526019)(4326008)(44832011)(186003)(81166007)(966005)(70206006)(47076005)(1076003)(70586007)(26005)(426003)(6916009)(82310400003)(36756003)(6666004)(8936002)(356005)(54906003)(83380400001)(336012)(508600001)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 14:29:44.4123 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e082f2a-e587-4255-8e0a-08d9930ce544 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2490 Received-SPF: softfail client-ip=40.107.244.46; envelope-from=Michael.Roth@amd.com; helo=NAM12-MW2-obe.outbound.protection.outlook.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, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Currently all of the M-profile specific code in arm_cpu_reset() is inside a !defined(CONFIG_USER_ONLY) ifdef block. This is unintentional: it happened because originally the only M-profile-specific handling was the setup of the initial SP and PC from the vector table, which is system-emulation only. But then we added a lot of other M-profile setup to the same "if (ARM_FEATURE_M)" code block without noticing that it was all inside a not-user-mode ifdef. This has generally been harmless, but with the addition of v8.1M low-overhead-loop support we ran into a problem: the reset of FPSCR.LTPSIZE to 4 was only being done for system emulation mode, so if a user-mode guest tried to execute the LE instruction it would incorrectly take a UsageFault. Adjust the ifdefs so only the really system-emulation specific parts are covered. Because this means we now run some reset code that sets up initial values in the FPCCR and similar FPU related registers, explicitly set up the registers controlling FPU context handling in user-emulation mode so that the FPU works by design and not by chance. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/613 Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20210914120725.24992-2-peter.maydell@linaro.org (cherry picked from commit b62ceeaf8096fdbbbfdc6087da0028bc4a4dd77e) Signed-off-by: Michael Roth --- target/arm/cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.25.1 diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 0dd623e590..4f03e74664 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -265,12 +265,15 @@ static void arm_cpu_reset(DeviceState *dev) env->uncached_cpsr = ARM_CPU_MODE_SVC; } env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F; +#endif if (arm_feature(env, ARM_FEATURE_M)) { +#ifndef CONFIG_USER_ONLY uint32_t initial_msp; /* Loaded from 0x0 */ uint32_t initial_pc; /* Loaded from 0x4 */ uint8_t *rom; uint32_t vecbase; +#endif if (cpu_isar_feature(aa32_lob, cpu)) { /* @@ -324,6 +327,8 @@ static void arm_cpu_reset(DeviceState *dev) env->v7m.fpccr[M_REG_S] = R_V7M_FPCCR_ASPEN_MASK | R_V7M_FPCCR_LSPEN_MASK | R_V7M_FPCCR_S_MASK; } + +#ifndef CONFIG_USER_ONLY /* Unlike A/R profile, M profile defines the reset LR value */ env->regs[14] = 0xffffffff; @@ -351,8 +356,22 @@ static void arm_cpu_reset(DeviceState *dev) env->regs[13] = initial_msp & 0xFFFFFFFC; env->regs[15] = initial_pc & ~1; env->thumb = initial_pc & 1; +#else + /* + * For user mode we run non-secure and with access to the FPU. + * The FPU context is active (ie does not need further setup) + * and is owned by non-secure. + */ + env->v7m.secure = false; + env->v7m.nsacr = 0xcff; + env->v7m.cpacr[M_REG_NS] = 0xf0ffff; + env->v7m.fpccr[M_REG_S] &= + ~(R_V7M_FPCCR_LSPEN_MASK | R_V7M_FPCCR_S_MASK); + env->v7m.control[M_REG_S] |= R_V7M_CONTROL_FPCA_MASK; +#endif } +#ifndef CONFIG_USER_ONLY /* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently * executing as AArch32 then check if highvecs are enabled and * adjust the PC accordingly.