From patchwork Tue Nov 30 17:32:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 519734 Delivered-To: patch@linaro.org Received: by 2002:ac0:c605:0:0:0:0:0 with SMTP id p5csp7787449imj; Tue, 30 Nov 2021 09:34:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+kQywo9oHbIBQlKlmCfjFy30HevralREzClxLc90GBcCgNapG5HOPundaa1brV9eTAfNM X-Received: by 2002:a05:620a:131b:: with SMTP id o27mr762903qkj.330.1638293692715; Tue, 30 Nov 2021 09:34:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638293692; cv=none; d=google.com; s=arc-20160816; b=PtIV4u0UzOzJvdUolgrrY42j65Uc5OqUnduFoUl8m5y7a03VOIRa0qrgXu6NXPTg5m iLoNWVczK2Jad4oapo+eCX79DqSzhtuxAA+K4ASzxehtGhhPGgw37327mebuDtnDmSkt 7aUVUA29uN16nbGnPOphkLea/eXvR/2OcIi22Vm9TPXU3q6vYNoxuALAQuOty26Dy5UO JuaQDZwqBrKFlCiJ4G8Rdjcx+rngUsKVv1WOoelVL4HTLtIoRqBnYXLf05rpN15SGsR9 SCAcoBK9yACl1w1Z2Uf/+Nj2oAE3C5QnTNI5xcFXxlDsA4OvHsdTxZaSGllIQKVpQYov V3uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=rfQ+RiViECLNtr/c9/my/pnagCNTFLLUTJEjsLwzVUY=; b=JNunkFTj5Z3AuNZF06r8AIaJpGhe+A6Bl4Kok3+d8j3RXPVo7VcTIG8Ma4oV5XNSjf v8hon146N2LK0iLP6oTc8T4w4hgb182Xj68GM3aVd+RTIr+n0TLL76zk1b5mI3hNpb3C pijIo+j9Ktp3nCBh2pWH1oGL/LHL5SMiP7hMlnKrsWP9Tknh8C4C3gtH8OyBzs7Rz5pv eSMcYIH+prd3uGU+rMNXkgpDkeaQPLQAUQeVBaRemZcVcJArJPRVxhaO4ZU1IFjJKspq biRXDK24lClNx1vZmGFzZwGzltSGLnf9zxl6VKRFmn0Ftt5Yj00IVND+cCUSB2WbM4Vk NYRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uFz57qVY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k9si7372435vst.249.2021.11.30.09.34.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Nov 2021 09:34:52 -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=fail header.i=@linaro.org header.s=google header.b=uFz57qVY; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ms71o-0007kh-6O for patch@linaro.org; Tue, 30 Nov 2021 12:34:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ms705-000658-RE for qemu-devel@nongnu.org; Tue, 30 Nov 2021 12:33:05 -0500 Received: from [2a00:1450:4864:20::430] (port=44726 helo=mail-wr1-x430.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ms702-0006Z6-6a for qemu-devel@nongnu.org; Tue, 30 Nov 2021 12:33:04 -0500 Received: by mail-wr1-x430.google.com with SMTP id l16so46101853wrp.11 for ; Tue, 30 Nov 2021 09:33:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rfQ+RiViECLNtr/c9/my/pnagCNTFLLUTJEjsLwzVUY=; b=uFz57qVY2nGIQxKRDHFsX5iWPlQRq4UCCXirYYe+qmq2XlygKjwUqUJDBYrrMXBWL5 D8TUWimoGiu7VmsTQuqeGeQ0MYUaG9/UJxU3SQ8uzOGw0HWNp1hLaKDlseccRMukxxir E5GIVyepQveIIw9jvu5OVI7T+8baLEUCILqiviBxa/rlYK8Zl0A09lobAAeNt72fstQ5 h5i/9g47E7AKcsx/xhddrJYwMxy4vMHxckzsfPEo5emYYzmvpdZS05O4xtxDtoHc+ad3 SQYGDi+XXx3pK3+Ofy5APUbWR5T2RMzP/RI7bH1MrpQ1cbvqs2JCrPtXYQEtrzS5w3uz FIdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rfQ+RiViECLNtr/c9/my/pnagCNTFLLUTJEjsLwzVUY=; b=VzVZLyvfd3BrKJDldiFISgy2uyTjemGDLQGoAJ1B2/ncSJdKiiV0MkCeu293dSvh0t 9LwRjvRX0L2leP1rbUzP9YPmssTr35LrmieY5knJ85IsUU6G7apGZLftX2kNurLa0yzv ngE7Q5o8iBZpIY/TSy/7+QYRvKL9e+ddRPJQVCsZKmDVY9g5J9/NEuqR1rHlEi5uP41C FisAi7KzIYM9CPs1mAgWfCr6T7PGP1XpLP9o/fWKCdfAiZS93IPd0nqz+EG419JgEv8j qs1V9B54RvHl2EFAiVmJh+fSbTk3Cs+dH2/L9CFD4razSiT19lNld6D7t5wgC3p+38Qs 4Ssg== X-Gm-Message-State: AOAM531qbpGddsU2Yr7yW8BCyZibV/w0rVrgk+SXkYc9zpvC/+9YhQC0 PngW9XU/0TA9X1JXVbispTUP8g== X-Received: by 2002:adf:c605:: with SMTP id n5mr365321wrg.564.1638293580202; Tue, 30 Nov 2021 09:33:00 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r8sm21583972wrz.43.2021.11.30.09.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 09:32:59 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH] target/arm: Correct calculation of tlb range invalidate length Date: Tue, 30 Nov 2021 17:32:57 +0000 Message-Id: <20211130173257.1274194-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::430 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Rebecca Cran , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The calculation of the length of TLB range invalidate operations in tlbi_aa64_range_get_length() is incorrect in two ways: * the NUM field is 5 bits, but we read only 4 bits * we miscalculate the page_shift value, because of an off-by-one error: TG 0b00 is invalid TG 0b01 is 4K granule size == 4096 == 2^12 TG 0b10 is 16K granule size == 16384 == 2^14 TG 0b11 is 64K granule size == 65536 == 2^16 so page_shift should be (TG - 1) * 2 + 12 Thanks to the bug report submitter Cha HyunSoo for identifying both these errors. Fixes: 84940ed82552d3c Resolves: https://gitlab.com/qemu-project/qemu/-/issues/734 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- Not marked for-6.2 because this isn't a regression: we shipped the TLBI range invalidate support in 6.1. I have no repro case for this issue, but this doesn't break booting an aarch64 kernel, at least. --- target/arm/helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 9b317899a66..db837d53bd9 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -4519,18 +4519,18 @@ static uint64_t tlbi_aa64_range_get_length(CPUARMState *env, uint64_t exponent; uint64_t length; - num = extract64(value, 39, 4); + num = extract64(value, 39, 5); scale = extract64(value, 44, 2); page_size_granule = extract64(value, 46, 2); - page_shift = page_size_granule * 2 + 12; - if (page_size_granule == 0) { qemu_log_mask(LOG_GUEST_ERROR, "Invalid page size granule %d\n", page_size_granule); return 0; } + page_shift = (page_size_granule - 1) * 2 + 12; + exponent = (5 * scale) + 1; length = (num + 1) << (exponent + page_shift);