From patchwork Mon Nov 25 15:21:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 13885089 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 811B3D58D5A for ; Mon, 25 Nov 2024 15:22:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tFatu-000422-BF; Mon, 25 Nov 2024 10:21:22 -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 1tFats-00040r-Fy for qemu-devel@nongnu.org; Mon, 25 Nov 2024 10:21:20 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tFatq-0001nA-Bh for qemu-devel@nongnu.org; Mon, 25 Nov 2024 10:21:20 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43497839b80so14602035e9.2 for ; Mon, 25 Nov 2024 07:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732548077; x=1733152877; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DMELCxkOeEAQmSk+N63B9qvpt489uBLoYc1oFZtPpjQ=; b=pChjgK741wVwzfY7TnC/KMBlYHW7x6MktMDt4o39LYBILUSFMT1n8u6Bni1/FkIeR1 SbYDGmcT/qDxeLjG7RaHn5lQcH9l+GfxS0QieZhXgLCPNNkTWFBSfnRxJl6Pc9v6dsaJ A4ovCt9RhrsLdKYNMBMXaihw74FqWZaDE/tlED9XrCmer1WOBjHKlL1RjpSdyNipam9u tPJ79eg+/eCvideDudz0NOUf9GyhD6udUkBNdXg62Ibm1smvjihJgjVyJoMbi6+SxbGM aFSjcDKBFdg6rDMuXKLaqbYan3tK8nzreEfZY7c/QkY9Hd4kvlVYrj9dBlsLh5gREY1W ufrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732548077; x=1733152877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DMELCxkOeEAQmSk+N63B9qvpt489uBLoYc1oFZtPpjQ=; b=iGai/kxpwhMu+zsIBVgWFrN/92r1fhJbjM3xHeooU39oKPIxKbs0FNKLEeLVa8Ui7Z dFscRSlaaA1oSBeSosXlugM2VL9Tolw354+pOknI3MxYnAsiW0QNAivqbM5hXxxCL58W YPxFM9RWvu7Dh7urqLqMlXQXToUdH2fk+XKAnOubJijlk0CMfiD71C0DwNgXiVVUNV9O C/PqXsKSdHHtFWXUeHTdQInZ5eIS5qHtJR9HST5xExq+4B3QfoSqSmYRBlNFbqcm43+I 6TSNV9NJyfOcyFDkAjejkNuVMaAoS7uGzpEoGcRXZfoPMGjuFsIycceLVxhzGNDGF7vh USsg== X-Gm-Message-State: AOJu0YzCDjx7KcjZRETdu+70HkTpeRjqG69CsaoZTlYqi6DJLY0e1wZb kUT5gcWVHfgXUAHyHz58AdeDkHqJd9GcZRg7uxUMKYw8fWP6lN/1nLKmXWAFG/U= X-Gm-Gg: ASbGncukp/eIG4EJzvAtoTIPJl27bDNFwiHzcTlgclm7g8qFpmy7UGjZDSYOxwxC3yQ 71GnhZkhQKKLLD8TOTuPavyGd7FaWi8iuimCN1mPHKYmbwKN7xAyRz4zLoPqS+JsyomSBBb69OD 4tIMoy5oS5GfULslctRlmjyId50mxbOtWnCMLKs1olfpwKx7l9NaxtzcGcwpO0Aa2LolhKETIW3 gkkIRLIo7E+wOjyJ4rj/tPWtATZ2ODDQ9jZPN42w1MCpBRW X-Google-Smtp-Source: AGHT+IHpnTS6RQp+PRADd2JYlCHgAbWaolF6kyisKI/7HjbmaUXXA9ritrcshd9FtN1wv954DPWxlw== X-Received: by 2002:a05:600c:3aca:b0:431:680e:95ff with SMTP id 5b1f17b1804b1-433ce425617mr118928725e9.9.1732548076810; Mon, 25 Nov 2024 07:21:16 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4349fba472asm38343535e9.17.2024.11.25.07.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 07:21:15 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id F362D63331; Mon, 25 Nov 2024 15:21:07 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Junjie Mao , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Manos Pitsidianakis , qemu-rust@nongnu.org (open list:Rust-related patc...) Subject: [PULL 24/28] rust/pl011: Fix range checks for device ID accesses Date: Mon, 25 Nov 2024 15:21:01 +0000 Message-Id: <20241125152105.2100395-25-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241125152105.2100395-1-alex.bennee@linaro.org> References: <20241125152105.2100395-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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.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: Junjie Mao 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 Tested-by: Alex Bennée Reviewed-by: Alex Bennée Message-Id: Signed-off-by: Alex Bennée Message-Id: <20241121165806.476008-39-alex.bennee@linaro.org> 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(_) => {