From patchwork Wed Dec 15 10:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 524267 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp244072imb; Wed, 15 Dec 2021 03:30:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVR9DUVTF+8R8PVsq7dsIaafdWd839esWBQWarITDv+qcmgRKPt1jiYgRGW5fm7j/6dOlL X-Received: by 2002:a25:db8e:: with SMTP id g136mr5168399ybf.301.1639567826017; Wed, 15 Dec 2021 03:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639567826; cv=none; d=google.com; s=arc-20160816; b=BVi1JAXYZXELbPkRjeOUqdF+6ae/W06JCBDDeY0jcJzE6oaAlN1FBZ6ApGHWBbDame h7Oq7f8L8CkOMRwCgFGiB/TstZ6XFhld68/N/147VzYt0F5ikrygBdPwD0uG31TP20B5 NYf6ePW+z7qlT0Z9/UYPM4V32VIKf34ugzW1FhU72J+rDQO5w9gu/+67hUzNCvX7wTAz P7XQX3hbupgfI9VBXJxaSWINfFynOLeQb8DjB01nmutN+BGLCm3clSuJKh0SaHNOLn7t ca3nmyqET2weT55csfJjqJyqkZ44mieUFMzsUxD5tvjF7tPxAgwahUWyht72lfTB3QFb R9lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:to:from :dkim-signature; bh=jRMpMS/CyWONQSCDvYHRycsqwdxA5hg+1aajGuji4ZE=; b=FjW0CMrqEanr334t3/iRDJLpplmoZ09aVHOzp0CJLb0pxUnJcZfTU7ZGl/Wf3EfDKV XxAL1kKgD5Mcd8hpgHYmKgWhGMqGnac5FEnaFWTiJdks83xywr4Y5W1Vl3+sL5WjWcAe IOr1sAGFpMPfIyE1OMJLzFkL4I+PCFfypcJJQYxk5vzIUlDmDAo7ro1hG+39HIo2dzl1 wydsZ2T6jbttQC2DsQTuBUSDsuc9z0Ea5DP89vaFd6JU6UhPSUUOolN8kP0bBezdubYa GGTH0q/ysDXkeb59w3XkBOcEC8pM4+eKGaBmkPsXk2hJJIuAjJ4ccDb56P5l9AjjzOUz mo8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Dj2nkxX/"; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n81si1988125ybf.0.2021.12.15.03.30.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Dec 2021 03:30:26 -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="Dj2nkxX/"; 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 Received: from localhost ([::1]:58022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mxSUL-00064V-FQ for patch@linaro.org; Wed, 15 Dec 2021 06:30:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mxRih-0007Id-UC for qemu-devel@nongnu.org; Wed, 15 Dec 2021 05:41:11 -0500 Received: from [2a00:1450:4864:20::32f] (port=54817 helo=mail-wm1-x32f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mxRib-0008WT-NB for qemu-devel@nongnu.org; Wed, 15 Dec 2021 05:41:11 -0500 Received: by mail-wm1-x32f.google.com with SMTP id i12so16260237wmq.4 for ; Wed, 15 Dec 2021 02:41:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jRMpMS/CyWONQSCDvYHRycsqwdxA5hg+1aajGuji4ZE=; b=Dj2nkxX/sfvbRz0hW4cokfHkIzo4FlsKY7EIO5XgNxkE9zQqyCoTLH9jSHCDCHYZuz /YD39vL3My2VzIxfpbmIHnDgOMFydO0QQiSb7zMSmaLJyvXc1oAiPN+3tzHAFI2vT4uC n1v3RqT/PFhwhwgROlSPf9ynEwF5nrDts9frqCHhqr7JNPQp9GF3ebqb+VzAgLNMi94l hVJbN8dQJeDGYp/vc8Mcf1YFPs0HOKZ4jAhjOuoSZq27QgYvA8ZMhsgnsRBkDmShKO8w pDArb7cYcO9faBeUDsp6xHYULjq8uBysNYEV3s/b2DFNCtzWynCHat2gDlYXIaFsDpIs Em8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jRMpMS/CyWONQSCDvYHRycsqwdxA5hg+1aajGuji4ZE=; b=HamSOM2xwlL84rU0SNwSNQeXknLTG4XNrgwb/I/g0XwaAZggUlXHQSEXxuoa/uV8Qb Q3YTKjDOnBwM12IiNdtWT3u9uz/XFcgvz3NOqy/jBwKn5xPZ5Id9w2ZiGXWQR2WjmI/n AXiVGX2cWDqQN7x+YBGz7rv+rPL+ABDpkRbCgvRfkRmOUKuAjZFa+RNvcBMYU8UGnMH8 Q/Etbn38E/aDRVH4p7HxugufojkEdOU8PNiT6tG1XLIAIxT+VML7K4/kWa5Fn4YtM76c cdK5WAbh+3ssz7HdJCBXLVEESwKDHSEdpb0t3iz2y+14/cakd2sXgi2PXzEAs1c+wWiE t4Fg== X-Gm-Message-State: AOAM530o4GLOCkCnoA+J0Q/J3DrA6laKcZwyLETkHNvqKRVAuqY8o1aQ hPqRfuYPVA8HoGkETn6EOly30TLfBCbwkg== X-Received: by 2002:a05:600c:220a:: with SMTP id z10mr4163776wml.20.1639564864415; Wed, 15 Dec 2021 02:41:04 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id e18sm1600815wrs.48.2021.12.15.02.41.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Dec 2021 02:41:04 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 24/33] target/arm: Correct calculation of tlb range invalidate length Date: Wed, 15 Dec 2021 10:40:40 +0000 Message-Id: <20211215104049.2030475-25-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211215104049.2030475-1-peter.maydell@linaro.org> References: <20211215104049.2030475-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32f (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.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, 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: , 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 ("target/arm: Add support for FEAT_TLBIRANGE") 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é Message-id: 20211130173257.1274194-1-peter.maydell@linaro.org --- 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);