From patchwork Thu Nov 7 06:13:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junjie Mao X-Patchwork-Id: 13865877 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 6702AD5AE67 for ; Thu, 7 Nov 2024 06:19:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8vrC-00030a-5I; Thu, 07 Nov 2024 01:19:03 -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 1t8vr4-00030G-NV for qemu-devel@nongnu.org; Thu, 07 Nov 2024 01:18:54 -0500 Received: from mail-me3aus01olkn2055.outbound.protection.outlook.com ([40.92.63.55] helo=AUS01-ME3-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 1t8vr3-0005pQ-3v for qemu-devel@nongnu.org; Thu, 07 Nov 2024 01:18:54 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rI3hIXeuZJ1uHoNe1wKqqKTx920Ru5CNgpf3ztvzbf29Vdh7Gc5DvAtJWowp6eIRJ39ZhLGgDFbfKXLavWItGMuqMNC9kBZG0IoqG/NFIAyBFDcFeeV0xAiuoaiZ2QESs//fvEfG1bZXXi2nT6xf7Vc7/fXg3fV8RgL4rAIRNCyUajiev8QoB6asF96Xetb/QCvqB4TeJM7EJcNC9nlHEypD1TZBG3tMxHrkZQpbwNe+QcOm4AogRY+LZynSz9QT3VQJdV7NXBui+m4YR5v0syO2vzjojfx8WVS6gPNSekCC0+nLxBMxSgs53lkQuBlSaN6GvQDaoqbgg1VvgP9noQ== 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=jZW6/8nAN+mVmljO7sMbKac8QVuSaZP+8nzheJNdr8A=; b=tE7edk7AHLC04E8XG1oJmfyIk7Z1orD2eEZNdtowOsz0x1jBFWpjcNEah0FK3BfNkcGUt5I4QOk1A1kraxwLR4hWIzdAtu0U+R/WlxcE2r/59Y9vLTgGtVqeH5uY31u1yfYnEcAU6lWN/UYSMNT51GY12CvESOQ7c41LqUh0eBGPsvbQdR4mVylwZj4QSZBOoqSVSaOwglnHwZ7nci+eK3EoE9rxZTfOqWQ4HGO5mklY2pE6FIz1iALIq1SbQw7E9MecxUFyHDa5JUN5ZDY0Z9R5LF7ensGWEWPYdomCmV4sBgDSrHIOq4RH2LSluMwEGDCCaKAtuJWWkkfhjWiKzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jZW6/8nAN+mVmljO7sMbKac8QVuSaZP+8nzheJNdr8A=; b=KWTV47EaqwrRggqmtaWly65XBfKKHK/R3+6GjDgFTJjRJCCniTydFRzbm2V+BVJu6PuHpolrR7U6sO9az/WtcA4Pu92EBXUQ4fVTczBddHes4Zz9D5+WVEHojISWbH3VWRJj6crsGlLNo6l1NK+hQb621FYe/zs7xpJkieRsnbwfDCA4OCnVUt61o/4Uc8idIYNWUrqLjui1fBGZvGG2uJ5FOqnC7l7KSOk2TgmjFBH74zLMhtXtOpq2iw6p54VC3sCwBPWg3iV83viCnp0kW1D6Ob80Akll6ldKDtHw13pFBfMyKxOJgpkY7F0zGUi3D4Y/uYCZ9ttD07nWik0hkw== Received: from SY0P300MB1026.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:282::22) by SY8P300MB0308.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:260::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19; Thu, 7 Nov 2024 06:13:41 +0000 Received: from SY0P300MB1026.AUSP300.PROD.OUTLOOK.COM ([fe80::aea3:2365:f9e8:5bd]) by SY0P300MB1026.AUSP300.PROD.OUTLOOK.COM ([fe80::aea3:2365:f9e8:5bd%2]) with mapi id 15.20.8137.019; Thu, 7 Nov 2024 06:13:40 +0000 From: Junjie Mao To: Manos Pitsidianakis , Paolo Bonzini Cc: qemu-devel@nongnu.org, Junjie Mao , Peter Maydell Subject: [PATCH] rust/pl011: Fix range checks for device ID accesses Date: Thu, 7 Nov 2024 14:13:07 +0800 Message-ID: X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0010.apcprd02.prod.outlook.com (2603:1096:4:1f7::17) To SY0P300MB1026.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:282::22) X-Microsoft-Original-Message-ID: <20241107061307.13276-1-junjie.mao@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY0P300MB1026:EE_|SY8P300MB0308:EE_ X-MS-Office365-Filtering-Correlation-Id: b64e253b-9851-4874-6fbe-08dcfef352ef X-Microsoft-Antispam: BCL:0; ARA:14566002|7092599003|8060799006|461199028|5062599005|5072599009|19110799003|15080799006|440099028|3412199025|1710799026; X-Microsoft-Antispam-Message-Info: UHEC4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CrYwNgJDsGDHulOcmA/gx+DmGKuivCjMA4z0vfvh2UxiAzHChTTBmrsNKaJAEBGZ1Uw60BKSO5tJyWxKVgnPSmiV+B5vOjEpqXMMk3+ivB0eF5Xg6dCtfIA2S5ZWKuUMoDv7w09yFf9jwmH2TZDdLALaiDRKr+f4NJ4eHIs2jVf1bGwDDY4QC0iHCoTxXjx6o+2XSJr91+5sjShJfz/muvu4Vkig/B+705eDTciPUKMhXv+QgKyLI+2lPgpzGLe4uFbX6nTmG3vg0sGD2+eXVww= X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-448bf.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: b64e253b-9851-4874-6fbe-08dcfef352ef X-MS-Exchange-CrossTenant-AuthSource: SY0P300MB1026.AUSP300.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 06:13:40.4255 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY8P300MB0308 Received-SPF: pass client-ip=40.92.63.55; envelope-from=junjie.mao@hotmail.com; helo=AUS01-ME3-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, FREEMAIL_FROM=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.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 The peripheral and PrimeCell identification registers of pl011 are located at offset 0xFE0 - 0xFFC. To check if a read falls to such registers, the C implementation checks if the offset-shifted-by-2 (not the offset itself) is in the range 0x3F8 - 0x3FF. Use the same check in the Rust implementation. This fixes the timeout of the following avocado tests: * tests/avocado/boot_linux_console.py:BootLinuxConsole.test_arm_virt * tests/avocado/replay_kernel.py:ReplayKernelNormal.test_arm_virt * tests/avocado/replay_kernel.py:ReplayKernelNormal.test_arm_vexpressa9 Reported-by: Peter Maydell Signed-off-by: Junjie Mao --- rust/hw/char/pl011/src/device.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 2a85960b81..476cacc844 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -182,7 +182,7 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow { + Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { u64::from(self.device_id[(offset - 0xfe0) >> 2]) } Err(_) => {