From patchwork Thu Nov 21 16:58:05 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: 844706 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:8b:b0:382:43a8:7b94 with SMTP id m11csp2392831wrx; Thu, 21 Nov 2024 09:13:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCULa4hIIh6iG8f4QbJMqMkBdr51TTrGM3I/Ux9Z7VT17To2CaI6UHHcWbX1YAht7CF5qEBaUQ==@linaro.org X-Google-Smtp-Source: AGHT+IH95nvo8/kfORWs653wU3skgZBXqQ5MVEQu3qVguuix5hbTDv2IqYkGnSRrmkxpotnSf4N5 X-Received: by 2002:a05:600c:350f:b0:42c:ba83:3f0e with SMTP id 5b1f17b1804b1-4334899569fmr64749715e9.7.1732209189388; Thu, 21 Nov 2024 09:13:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732209189; cv=none; d=google.com; s=arc-20240605; b=TrYbuILkuwJDlh89KqrtM5GRmk5aZmcGVoTOGIZdvvQ/4Vj8i/dkbneWVzdxV3koYY 2xwE8pI55WGVAQD7aUKhfvskKhOeIMJcVmRRfp1TWQIeRleoNzop0uGRaNIcmjRJIx73 2Iku+2VA/20LpmTuWI7MV9zjSfBzC29yzvWmrrEGW/LgphEcwWVJv/TlZ2g1YzWDTSRI XDqyhSH6H6hxOqnnRYvhkH15E3iTuQEQTAorKCSDAfHnnXVZA4Rr6mtxPbFG1PJggHH9 fFvQmIpyMjU24Zb6i2+vQ3z15Paxdc0WQjIJiZtEekZMlAz1JTZ9UritLx7msIw0i9jF SyBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=ZYyjcmwGZcc7NttBsBYoWNTe7fj51f/J/c4PbwCrSW0=; fh=g4dVLcEyCQGa799W2N9jX8RvEftJjxygyM0FCqM/qkw=; b=KOJXl+CwHTabt0d90WMcsKXT5smh5mY1UyGjBZTxkTO0X3STy9Bn5MBpnNmNp9M6GF 6ITOBMsz/YEH+ztBAD1vabceI7/yBDFIK941RUWmnnEVESna/doojDFWxSpJ8UWs92oo kfLbvOp+8U8FTf5xBevXdjlhbdPiNlnVbnVX3Ml6S0oUE63hwWPvQCOy+5KUmRMIbw00 7Q1hDXcbMf2nzBtha22lFrJNcm9Raab8qobLX2VeYyEeX7wNBe+PBszWfxV76hwqMdrn 7fOFz5v158bqbbv5ccYpNbicvnBqRJE4wqDVg41cNCGdcBWb3uWyAxbvVpXiRJVRhfe/ abuA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PejqfVPo; 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=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ffacd0b85a97d-3825fd28281si34423f8f.435.2024.11.21.09.13.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Nov 2024 09:13:09 -0800 (PST) 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=@linaro.org header.s=google header.b=PejqfVPo; 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=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEAg5-0005Rs-PS; Thu, 21 Nov 2024 12:09:13 -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 1tEAe1-00012r-3y for qemu-devel@nongnu.org; Thu, 21 Nov 2024 12:07:09 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tEAdY-0001iS-NN for qemu-devel@nongnu.org; Thu, 21 Nov 2024 12:07:04 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-38248b810ffso805676f8f.0 for ; Thu, 21 Nov 2024 09:06:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732208795; x=1732813595; 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=ZYyjcmwGZcc7NttBsBYoWNTe7fj51f/J/c4PbwCrSW0=; b=PejqfVPoBL4glanT7r79oYFDkwi83yLvILxohLx52bggyI+zXGpqzjtgwTjhKhpp4e F/JqLn5dCkHIGKnc05ZbvulOxcj/Z6KEu7CHypxrUAyytEkoxBcHfEkpvE4Yf0vZ/vE9 QM18a9JuEce3i8Jr6E5QiPVxNLpI3Zrr7grkJK2Tw2HO6ia4jqOMDbG/ujGd79iEDOUQ H1wHM8tj9erRBAiJvClN7nncj9uudY6UqMioSqhahUT1yci3jVScS5eAPT8nYvKsk7tL 8V97O2n0mFEy+UQolA09RFwcwjCFeZGM6lXx+22qRv+cGF0InEml8WNlRRcWQm8bnfiK lnQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732208795; x=1732813595; 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=ZYyjcmwGZcc7NttBsBYoWNTe7fj51f/J/c4PbwCrSW0=; b=XrQfdUNoiHunzl82qOPQTucQttFLUohn3h0Y+YcnS+Z34a66r4ghJ2lLE+hFaUbjlO 9Tx6pOpRZrQWLXMFYnppujxWs2waM9mT2ppcqqmJKKqwZQgQHdPl7s9LP7DcvQdC79lV kQL6wmhat1mbRIYqtyqo0TfjmYPyjmEOoRjaEznvktyxXoWkNNT8pBxXH/KOFsf80Uoc zHt5c+awaNQSBmebIst9QTj5t/QZl2OygBoPgGl4F/5oi4DDmFGYVgQF7fHBTBvPWsva aVlMLdE+m81xKAWrdZDRhzGGFD3ay2o6fO7huphfK65d2xnZ+DV8ehWupfbUzpNOAqTs AEWQ== X-Gm-Message-State: AOJu0YwclQDg3mGCc+AoCOLM7pu26EjR/7jmhiY6SXIhFVTfvbvQsxCB CYuroa1802n6yahKMpRNN/rjT+ffsqT90MOOa7+R2URBUVfyhVuFC769HDTx3wI= X-Gm-Gg: ASbGncuO00Cb0/FmVvVD2nd3WkOR3qZrFWpirhCdFXjj8qGZhTG1yRjigiR5cdkHI2d i7NO57WkoWpEJ42t1XAFFPjICtsGQt4GdE22Iky8CNPVyrWPjmSEuqchiWW9HAMrwcuNiSWmKCz u9wQHujzBjI/U1kvD1FAMxNNjExl3Vjv7qusibQc4Kd9RXz4nDbN7U3l73hBuSsXSUKk6jTPTAg LnludLe3iqljd1bdiGX9nKDXgR5b/7ztYSrlZBSr0edRvUe X-Received: by 2002:a05:6000:2a7:b0:382:4b69:9c75 with SMTP id ffacd0b85a97d-38254b17f80mr6364450f8f.43.1732208793832; Thu, 21 Nov 2024 09:06:33 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fafeceesm53837f8f.37.2024.11.21.09.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 09:06:30 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id DDBC660500; Thu, 21 Nov 2024 16:58:09 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= , "Michael S. Tsirkin" , Daniel Henrique Barboza , Pierrick Bouvier , Harsh Prateek Bora , Marcel Apfelbaum , Jiaxun Yang , Halil Pasic , Christian Borntraeger , qemu-ppc@nongnu.org, Daniel Henrique Barboza , Alexandre Iooss , qemu-riscv@nongnu.org, Thomas Huth , Bernhard Beschow , Thomas Huth , Eric Farman , Bin Meng , qemu-s390x@nongnu.org, Niek Linnenbank , qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , John Snow , Wainer dos Santos Moschetta , Cleber Rosa , qemu-rust@nongnu.org, Nicholas Piggin , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Palmer Dabbelt , Markus Armbruster , Weiwei Li , Mahmoud Mandour , Mark Cave-Ayland , Liu Zhiwei , Aurelien Jarno , Ani Sinha , Alistair Francis , Junjie Mao , Manos Pitsidianakis Subject: [PATCH 38/39] rust/pl011: Fix range checks for device ID accesses Date: Thu, 21 Nov 2024 16:58:05 +0000 Message-Id: <20241121165806.476008-39-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241121165806.476008-1-alex.bennee@linaro.org> References: <20241121165806.476008-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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 --- 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(_) => {