From patchwork Wed Dec 11 21:19:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Konrad X-Patchwork-Id: 13904214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60011E7717D for ; Wed, 11 Dec 2024 21:21:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLU8M-0006rN-Bw; Wed, 11 Dec 2024 16:20:38 -0500 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 1tLU8G-0006pR-21; Wed, 11 Dec 2024 16:20:32 -0500 Received: from mail-bn8nam11on2060e.outbound.protection.outlook.com ([2a01:111:f403:2414::60e] helo=NAM11-BN8-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 1tLU8D-0003nY-BU; Wed, 11 Dec 2024 16:20:31 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bbumle3mnarAw5HA6IoS0sTdLGhBF+nFPFz6y+QPMuP3VwEjJQoSDrBdwyum172rgnRz/QiYsNcuKyxKI7bk58khoIfnMIJJ7veo+8xANlMJmbgGawJy3UyE1ZA92UShA4QXioGTxSW1FlnI9gGidHhO/sWAm5bHhXHuh5VQXY8/EEJTeO4hDqxqHFQQ98Or1eB0yX7BCy9Iye4frCXjvE/hu9tUBHpE72GPBC4Pnp6upUmPLLi6HmlSe8miLnV00L4uVRn/gFpI7GyCNiQ1c4xaVYIc335OaTbzmGSlsfvWFgc1CIRN4gRlV30Y/yrZcyFPFOk1JwybUz6y3Xj+0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=MFfVfuEbS53ZsmtkqBIgnSIACUThQbtV5T06M7f+tvk=; b=dD+2cuMsaeWEENYx0eJ57KrzVUNPo52h43byEQe1bQlSoZFPpxpi12Z6XtO95txGHnZJZfIBk53OKtJLjybDL4bB1LKeZSfy+qpw70WxZ1TDjFKqc3AGgmAG8qtauKvtHirzWS3j/uL2WAY6JliowLoHn7KxbrYn3IG2eDgKaad5JP1VPDK7Gh76Wwq6vCUNpMGgb8ndr9/UdXnE5Do7jmMXTliEUTT1bvAN9Cg5UNWqS5zNTVQjJ3HjnjCXyil4DPOdhHIm0vjzT1sDcChUXDUHY8yPLlBt5V6W9ZO9gc4CvOVLstaZXBY1ewskpgjSZHa1EZUcR70d/zrUF6Qatw== 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 (0) 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=MFfVfuEbS53ZsmtkqBIgnSIACUThQbtV5T06M7f+tvk=; b=etb/TsA9apU7BlaVQ+q1BWclOUFX44A9Jne88gDjfkI601t7x8MUyEYTscBGKGmaNi3a9lqWG6JYziKHz41kLf9P0A2lUxlFAoUJJbTA1xpWWl5uV4JNULgHDJtkQrlSqH4uXW3R3aH9xJW/YgRwBUPjNd9rLrjcBSj2Xawvl5Q= Received: from BN1PR10CA0014.namprd10.prod.outlook.com (2603:10b6:408:e0::19) by PH7PR12MB6538.namprd12.prod.outlook.com (2603:10b6:510:1f1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.15; Wed, 11 Dec 2024 21:20:23 +0000 Received: from BN3PEPF0000B06C.namprd21.prod.outlook.com (2603:10b6:408:e0:cafe::d6) by BN1PR10CA0014.outlook.office365.com (2603:10b6:408:e0::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.14 via Frontend Transport; Wed, 11 Dec 2024 21:20:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BN3PEPF0000B06C.mail.protection.outlook.com (10.167.243.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Wed, 11 Dec 2024 21:20:23 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Dec 2024 15:20:22 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Dec 2024 15:20:22 -0600 Received: from xfr-fkonrad-l1.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 11 Dec 2024 15:20:20 -0600 From: Frederic Konrad To: CC: , , , , , , , , , Frederic Konrad Subject: [PATCH 1/3] target/riscv: add a trap-misaligned-access property Date: Wed, 11 Dec 2024 22:19:31 +0100 Message-ID: <20241211211933.198792-2-fkonrad@amd.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241211211933.198792-1-fkonrad@amd.com> References: <20241211211933.198792-1-fkonrad@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: fkonrad@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06C:EE_|PH7PR12MB6538:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d587469-8d12-4685-c6bd-08dd1a299fb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: umf5xu8fPjbPy5cZ8GgflQrAnNIZY21qdRmZmcHfyaCoaEsxNlgUKqxtVJQCQKkWHMBmTEbk+XX677FJNW7gr6QZGXk6CxzPc25sZLMWeX4AbQA6QwJQXX/t1WLtyp0+h8ZK55BSeBuJgw4RGjuvkLV9E2UP33bq7xE6qT13qdu1JlroHRnRxqRukaSXtVdWG5NVfzr6ZZKDjF5QJvVga1M9yNZuik6B/23G+scvk/rdE+YqISgJoqFXZQF7evudBmQCRNzx710wP/PyFyywIjKuT0Vb2XwJXE/8zJXC6+R0o/f0WhAg5DvjvcJa0klVZiIEwKqc99LDWE97uRUcxUFbWPy9U1PJKVFr+k/iR4zLO3Me3eiZhlD/5iP5E8gpDdYoHUL4g44eiM4nL8gNq1l0T7RQk6g6HBihiUEhFyRZT3EWiTgS55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CL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 21:20:23.1168 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8d587469-8d12-4685-c6bd-08dd1a299fb5 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06C.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6538 Received-SPF: permerror client-ip=2a01:111:f403:2414::60e; envelope-from=Frederic.Konrad@amd.com; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On riscv target, misaligned accesses are either authorized and implemented in hardware, or unimplemented and generate a trap to be implemented in software. At the moment misaligned accesses for rvi just succeed, the intention of this new property is to let the user choose to have a trap when a misaligned access happens. Signed-off-by: Frederic Konrad --- target/riscv/cpu.c | 5 +++++ target/riscv/cpu_cfg.h | 1 + 2 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f219f0c3b5..1696d3db2a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2697,6 +2697,11 @@ static Property riscv_cpu_properties[] = { * it with -x and default to 'false'. */ DEFINE_PROP_BOOL("x-misa-w", RISCVCPU, cfg.misa_w, false), + /* + * when set, misaligned accesses will generate a trap. + */ + DEFINE_PROP_BOOL("trap-misaligned-access", RISCVCPU, + cfg.trap_misaligned_access, false), DEFINE_PROP_END_OF_LIST(), }; diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h index 59d6fc445d..cc560371a1 100644 --- a/target/riscv/cpu_cfg.h +++ b/target/riscv/cpu_cfg.h @@ -173,6 +173,7 @@ struct RISCVCPUConfig { bool pmp; bool debug; bool misa_w; + bool trap_misaligned_access; bool short_isa_string; From patchwork Wed Dec 11 21:19:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Konrad X-Patchwork-Id: 13904213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 645CBE77180 for ; Wed, 11 Dec 2024 21:21:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLU8V-0006sn-Sn; Wed, 11 Dec 2024 16:20:47 -0500 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 1tLU8O-0006rh-D5; Wed, 11 Dec 2024 16:20:41 -0500 Received: from mail-dm3nam02on20623.outbound.protection.outlook.com ([2a01:111:f403:2405::623] helo=NAM02-DM3-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 1tLU8M-0003ov-Ip; Wed, 11 Dec 2024 16:20:40 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b22NniYzQeuNsMsN8LogO/oJul5eaGOTEUHEC1lb3RSnbjmDsNF4j5csjDZurr9Y24qNXl4dsKCee2djTbKIs7Dj2P07QeXY21Nv7coAB25ik5ywavZ8UJwbdyOjuYlg1lmj1+LPS2Myfp4xzDNE68O5rIw+nlsdNCCD51hdOlLuUjjULcpZzU6IUfyYrxtSqX+r8Zq0/4MLHcw0FBcygLHYosb7nY58MPVVAqySIog4SHpmgTgxwqfzNjUJbGF7KpF84gmpctlvqiA8/5BrSkN04X//r2A6r7qzZ+8UVCuis5U6YXiYpJe3qVwgzD2T1oAx6WrHZN6tHP9XhOkgAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=4jlOtH5K/+On6zKCmG2lOMZt1X/u9RImAghe+h5nwXQ=; b=FgoSCiQA89z8dgVDvH6FnETsd4f7O+ElHWGHaLIaDVq5UujcGWr9vDtIZltPjhm6gRxb8BFWfv6zbG60V8SqTCdBuEdxr6h5HMOvxH/qTEWMb/j51+28O8y4vEfwJrhBXnjKSaU8uuvkOXFrdMJbIys3dsaTHy8nk6mgXmVCTNEzIWYc/115+HfbxI/cu9ivWhnOLTYIgE5HHiNXdU/gfxgB44vcPsCnB9bX8aIQM8/ZPfbfJA+HToW3oeaknGnv0f6GfNAtBsdKcaOmo+4+iA4/k0LifRLuDXUMB3U1VNKk5y9pO89SguUZMpmhKj9/68tUp/XhwPjboyRlbZgcmQ== 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 (0) 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=4jlOtH5K/+On6zKCmG2lOMZt1X/u9RImAghe+h5nwXQ=; b=OxwtZ8S/7fQVzafpsogyrBXZnIB2rymr0oCq7iGb2YdpzWuDJNnLXgnXf8QKqhFgSbaAf6nT8KP2DiEX/C4PwI7NuyF+lkojNnK95gbfgcLjnA3XXIE3MYfStT7YWbY0IaI2J6D/zRQtyGLHao1CAmyXpAfeqc7Mw63pW0OrNnA= Received: from SJ0PR13CA0096.namprd13.prod.outlook.com (2603:10b6:a03:2c5::11) by DS0PR12MB8070.namprd12.prod.outlook.com (2603:10b6:8:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Wed, 11 Dec 2024 21:20:31 +0000 Received: from SJ1PEPF000023D9.namprd21.prod.outlook.com (2603:10b6:a03:2c5:cafe::b) by SJ0PR13CA0096.outlook.office365.com (2603:10b6:a03:2c5::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.14 via Frontend Transport; Wed, 11 Dec 2024 21:20:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SJ1PEPF000023D9.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Wed, 11 Dec 2024 21:20:30 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.39; Wed, 11 Dec 2024 15:20:29 -0600 Received: from xfr-fkonrad-l1.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 11 Dec 2024 15:20:27 -0600 From: Frederic Konrad To: CC: , , , , , , , , , Frederic Konrad Subject: [PATCH 2/3] target/riscv: generate misaligned access trap for rvi insn Date: Wed, 11 Dec 2024 22:19:32 +0100 Message-ID: <20241211211933.198792-3-fkonrad@amd.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241211211933.198792-1-fkonrad@amd.com> References: <20241211211933.198792-1-fkonrad@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: fkonrad@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000023D9:EE_|DS0PR12MB8070:EE_ X-MS-Office365-Filtering-Correlation-Id: fe6f7896-283e-4855-5ee7-08dd1a29a408 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Micro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DvvlIk2n7mnYy3eeZ5Zn+/gea/rHBIE5MUk8udNzNkFHQiOq3UVA+SAT5MPJGx/DHHLucXKO5N+Ig4KTwOp+DSwXgRPan7fDo/HHK3CCJxVyZCtEm07TaihvBgZ9FqxDG3ZXsmutkM9QF9GcQSjmgq89qILDAONQN93jdyPziDuay//qfuyamrzO2R3RkIfHc9h1IMlTdlLMKjYb6J+QyYZBvFqA6YLWpRgRtSzlk+7WxoWvDmok5FaxnV4Bq85llo+jQ4+dHzIOpzesDAWbsqibua0krAw3HhKyYN//7150eTbALplgunTotXAOiDXp+t3vJqqxGtN66FSgHC5sPrMblJoiR7byzw15HMRhPd3aQ761S8qxfFVQU2V0pYTCj/nyGvILWL/7qdonhSL 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:(13230040)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 21:20:30.2909 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe6f7896-283e-4855-5ee7-08dd1a29a408 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: SJ1PEPF000023D9.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8070 Received-SPF: permerror client-ip=2a01:111:f403:2405::623; envelope-from=Frederic.Konrad@amd.com; helo=NAM02-DM3-obe.outbound.protection.outlook.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now there is an option to enable misaligned accesses traps, check the alignment during load and store for the RVI instructions. Do not generate them if the zama16b extension is there. Signed-off-by: Frederic Konrad --- target/riscv/insn_trans/trans_rvi.c.inc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc index 96c218a9d7..1283207fc7 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -323,6 +323,10 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop) { bool out; + if (ctx->cfg_ptr->trap_misaligned_access && !ctx->cfg_ptr->ext_zama16b) { + memop |= MO_ALIGN; + } + if (ctx->cfg_ptr->ext_zama16b) { memop |= MO_ATOM_WITHIN16; } @@ -424,6 +428,9 @@ static bool gen_store_i128(DisasContext *ctx, arg_sb *a, MemOp memop) static bool gen_store(DisasContext *ctx, arg_sb *a, MemOp memop) { + if (ctx->cfg_ptr->trap_misaligned_access && !ctx->cfg_ptr->ext_zama16b) { + memop |= MO_ALIGN; + } if (ctx->cfg_ptr->ext_zama16b) { memop |= MO_ATOM_WITHIN16; } From patchwork Wed Dec 11 21:19:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Konrad X-Patchwork-Id: 13904216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 093B2E7717D for ; Wed, 11 Dec 2024 21:21:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLU8Y-0006tY-3x; Wed, 11 Dec 2024 16:20:50 -0500 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 1tLU8W-0006so-64; Wed, 11 Dec 2024 16:20:48 -0500 Received: from mail-bn8nam12on20631.outbound.protection.outlook.com ([2a01:111:f403:2418::631] helo=NAM12-BN8-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 1tLU8U-0003pi-CC; Wed, 11 Dec 2024 16:20:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yDKXePh+Mr0DrnlTLEtJd9ikSpFLKRU3OnQqza40H+B/bcGk62wQwlHAJ2CWrxDWuoilFrFrGCBh7OBzCt8sTFUGzgKqmj5bpACbIOQ/HuEm2wjGfV0ymcr7vr5TURXw8rjkRGmZWUfYZ+/N9Ma/ognrc40MD+1ECZ70X5wwA4STYVEZwV4nOJYoTq3jIgobkxYBzklj/fS9XfumuKtMpwGhO8Ye8Nb3AjvFhnJySnekFJ+4HdWCQoPAL1TUJAzpzHMg0OVfYPq/6exJBjh1k9JzTXiYRi2dBsAtiIWjO3liOdZyfZMGHINNcHmqy2eR6y2pCP4aotS8XOFspE+9Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=xaAaRTi3NLHrA0ohGquj1DuS8rBISR27gG/q9lxfWLc=; b=auUyWGroqOYhpRcJB1KrvOggP4llbGBDq6wyuXiq6fjwAZxAC6aYcEx+hteQB3Gx9ng1NZUoaDGneCYxFTkxolXsL3Gd1jcrZlHG9vT/q6xOGOJiGU5K9owgroJ1fhd52ohQg1+n+sjZVdInX7bcrckyeTIgVinVNoK/IlfI//Vaw3upQX92j7U8SG0IkDSOjnYwA3Bc0jOqRCt72Go2fIYAmxL+mM3Vqus8kdAVxZkZ30u+KlPiUlb09fiQ5x2KbsRRmom9tgGTA7wC8a3EsI+rxI+NbDqwvnRk+g6KxQ58FgY3IFrMZNkn5qx+66RI7iftwZAK/qIDWh9U+PxYDg== 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 (0) 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=xaAaRTi3NLHrA0ohGquj1DuS8rBISR27gG/q9lxfWLc=; b=xgVpWTis7Msw1eNjWM0BTrej9n7167ih31451iYt9koKRR2F9jXN6Wl0buH+EtnwfnvCcMF1ITWcxSjgJNgmchKmoYlmNmJV4iBvO70cqZdnubfiFiB7QSRxxjQ1n9vxnxHmNY2oZ5Z8o+celJYgjtn++Hq6AOr1kLFzo0pnfRA= Received: from BN0PR03CA0028.namprd03.prod.outlook.com (2603:10b6:408:e6::33) by DM4PR12MB6614.namprd12.prod.outlook.com (2603:10b6:8:bb::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.18; Wed, 11 Dec 2024 21:20:38 +0000 Received: from BN3PEPF0000B06A.namprd21.prod.outlook.com (2603:10b6:408:e6:cafe::1e) by BN0PR03CA0028.outlook.office365.com (2603:10b6:408:e6::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.15 via Frontend Transport; Wed, 11 Dec 2024 21:20:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BN3PEPF0000B06A.mail.protection.outlook.com (10.167.243.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8272.0 via Frontend Transport; Wed, 11 Dec 2024 21:20:37 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 11 Dec 2024 15:20:35 -0600 Received: from xfr-fkonrad-l1.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 11 Dec 2024 15:20:33 -0600 From: Frederic Konrad To: CC: , , , , , , , , , Frederic Konrad Subject: [PATCH 3/3] target/riscv: fix the trap generation for conditional store Date: Wed, 11 Dec 2024 22:19:33 +0100 Message-ID: <20241211211933.198792-4-fkonrad@amd.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241211211933.198792-1-fkonrad@amd.com> References: <20241211211933.198792-1-fkonrad@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: fkonrad@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B06A:EE_|DM4PR12MB6614:EE_ X-MS-Office365-Filtering-Correlation-Id: bc21a525-fb35-48c4-6851-08dd1a29a88d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: JMLHe6A9iGBANo0UsVxynjXJYj7vYJegRw1zEb6NSMGdV9VwySxVpknUgZkJH9kaLbD4Y91iWvl8yb4afCQLj/lzQgi3RKjstCt9VLc6x72CayUsMj2+AKaU+yM4XEOTzbxK1KzdPCQNREvx9RY+45N3vJEFazR3JmTeLD1L3NF32EqFAuvUbS1X/VxA2KcVFn3+FQQorm5iOXurt6er3OCMNa5aT0rxWdm41iQiq8RzjU9Gld3TpG/OLR9GyJp6K5yYFLeXmW74dVK41shSLOLi3hSeb8/zBTn8t0Bo3KBEFxidkbxVbYVQqP8HR8ILZoQvmHdjdbXP8x1Ae7bg7w9ybQ8l9TdD80sZrDAdmryHbzv+ixzuQnR24hAKmomupiF7MQyhg0OvvaO9AsnHFiUdGDCTmoHd1q9mg0pyBYifp9S/aegYRbrOI1lwRun8bzCk5FI34qMc9so2zYbwOFITlV2rlnItHYbkPqszYC7xeST+BZgb7h99fQM5rPZkNFlN2lMBAI3Tp5UJpIFnAOI3U3MOR2xNqmxrd2lVSGZKsINyhBvA6yGEPoQ1BBKy92uBY36Ep2Fqhcleb133MrDyBukCwVZOIwcLY4AN5dCYYIyGpNd0eQNtXoNY/lk1/52JxvsU7yEhAIeHOiNVWGCHpWd6rc3QdZLbPNCT8FlIznIdJdkYeydrq/96vIURPU6XMbWRcREBAV1CTdWBndeyvk5HMaUEoSDMuItFmQAIXiZooatSasGvBwpxyGM4uVyMh5QjYs8AeewEKpiGs7SLwvLN6lZv7fZ6w+lIPteP4Wb+LwxVZQ6Ix1WuVGVIGZnHXvg0qqf0lAFIsbwcX9AI5Rb1PTnDxZiPMqjm2iLy8tDhHX/wMpFl+Ezt6LZhBaorAihwdZ0bv3R0LC+zw4wTjAUt/Okb/U2/lypL+Y7FvDYGqoriLoIaL1+SUrx12ZtF4Dol7M5Hy3lltwpYsDb93cDtm9ofTx1w/WyCLox5C/ZHRT2THvRq029dQbTAu8gOzCUOWqBd3iTz0pnvcbiUIwsjRKJ7Jcu3e8KoQB1lRzDSZDoqurjHCMvgPaFPb+mxes1zTz3Kkc9q/Ll9KWoKx13ygVn5m/5y57GX/NX5TIrRbVJ68V9S79/W7d5aygQIN3ULA8oE15Y88Z8BQ4OmYKYc2TovUCa2FVwTy/734nAWUJKUj4I1k18Ewb6Vu4S7VSaCjmgeZg9ihUNRrHDAor5jmno3YnrkiLIJh5CbCya6nwRVrA4TpEQ7I5bbtb48vGmBdKtTuh7ogDV4/oOkXZZNLylf4N2LlLdZNOkNBjGEp84bhH+IJy92vGYVQpaP4kWxL3SDPG2Nm0/kib7GtpotWmg6jMv1XYb7GA5f3MVsYtUwamjrnnEBK4CsgQmW+60bJNAL4hXSvUrszX9mbunuohvleibZhKF/fX9IxZ3rCZ3lvbUnSkcTvJph X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2024 21:20:37.9674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc21a525-fb35-48c4-6851-08dd1a29a88d 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B06A.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6614 Received-SPF: permerror client-ip=2a01:111:f403:2418::631; envelope-from=Frederic.Konrad@amd.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.472, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From Unpriviledged ISA manual: "For LR and SC, the Zalrsc extension requires that the address held in rs1 be naturally aligned to the size of the operand (i.e., eight-byte aligned for doublewords and four-byte aligned for words). If the address is not naturally aligned, an address-misaligned exception or an access-fault exception will be generated. The access-fault exception can be generated for a memory access that would otherwise be able to complete except for the misalignment, if the misaligned access should not be emulated." Here nothing checks that the address is naturally aligned, so this fixes that wrong behavior by raising address-misaligned exception if the address in rs1 is not naturally aligned. Signed-off-by: Frederic Konrad --- target/riscv/insn_trans/trans_rva.c.inc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/target/riscv/insn_trans/trans_rva.c.inc b/target/riscv/insn_trans/trans_rva.c.inc index 9cf3ae8019..30a047164c 100644 --- a/target/riscv/insn_trans/trans_rva.c.inc +++ b/target/riscv/insn_trans/trans_rva.c.inc @@ -58,11 +58,30 @@ static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop) static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemOp mop) { TCGv dest, src1, src2; + TCGv tmp = tcg_temp_new(); + TCGLabel *l3 = gen_new_label(); TCGLabel *l1 = gen_new_label(); TCGLabel *l2 = gen_new_label(); decode_save_opc(ctx, 0); src1 = get_address(ctx, a->rs1, 0); + /* + * A misaligned store trap should be triggered even if the store should + * fail due to the reservation. + */ + tcg_gen_andi_tl(tmp, src1, ~((uint64_t)0) << memop_alignment_bits(mop)); + tcg_gen_brcond_tl(TCG_COND_EQ, tmp, src1, l3); + + /* + * Store the faulty address, and the actual PC. Then generate the + * exception. + */ + tcg_gen_st_tl(src1, tcg_env, offsetof(CPURISCVState, badaddr)); + gen_pc_plus_diff(cpu_pc, ctx, 0); + gen_helper_raise_exception(tcg_env, + tcg_constant_i32(RISCV_EXCP_STORE_AMO_ADDR_MIS)); + + gen_set_label(l3); tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1); /*