From patchwork Thu Aug 11 17:16:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 596662 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp926615maz; Thu, 11 Aug 2022 10:24:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR510vbkiWgjEEaFhK0VMpTfx9aSOUbHZyqYokgldVCgiqDwV6v/ey+1PagrvSKD6FSXY6O9 X-Received: by 2002:ad4:5d69:0:b0:474:8b29:b257 with SMTP id fn9-20020ad45d69000000b004748b29b257mr29345105qvb.80.1660238682878; Thu, 11 Aug 2022 10:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660238682; cv=none; d=google.com; s=arc-20160816; b=E6ahq3CMH/FewVNSQKsmhBTRgp3dgs8u+ZK4WDHMLElNAg92D6+iouL+ypPAybA2gw ZGimP607sGgO2CHHjELgIYZeUwI2spQfTML4ZvpfQnrXrIGCdaOTZAm/ZWUjOVhMpD18 +bMqJUV7A1AqhkGecoJBcDJyyiW5wccsCu3CoC+i7E3CffXB2fDWt2/yni2rtiovMg0d gUnb7BpAIIKgEilu6kCOuk+755plGZfkQfobpVyUNlrIBkTK3txkbmBgm+jVAz5DiPqa Imb7E/dGKTxKIX0HtK10+V9SBzmGI39kHeqEJQG/JXPBSnaxuD+bgrBL0mHzYru7bnW0 X0mw== 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=uwBdsBVOiqHy9AjYw9A5odDA4xVS3sjfOA/XRmbIZCE=; b=ngpgMoovhUQIZwTA7RlwmVjN3z7e3dirWQ0dLs0Ca4I26xu1ZmJAFJgKL/TwJ+wNA1 7jPH20Mv8YW8L44oGP4ug/cI6aYZ6IJfOq7x/cijxb8huPFeRm+ONjOIA9I1V2zPj8/t dg+PMwDPvb/2fLUgva9LUeOyH4GqaNzTYSvxflqGbphKopbbXwjOA5tNYDh9koUMonpl OY29/rZHSeoO4LK0nHmZaNZE3AlOENYun8HJkxO2YN1vU8Y629b7uUwV48bkPrx6Q4kZ ZrolTc+PCUMmMmhsFNkHI/Wp/iH1WgVk0fxb2jm6kXyJxiD6ukn1r6dY1Cp3OgHelEJL oMXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rEJMdqsn; 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 n1-20020a05622a11c100b003435fb8889bsi12159qtk.499.2022.08.11.10.24.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Aug 2022 10:24:42 -0700 (PDT) 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=rEJMdqsn; 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]:48484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMBvF-000566-F5 for patch@linaro.org; Thu, 11 Aug 2022 13:24:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMBnH-0006m1-4A for qemu-devel@nongnu.org; Thu, 11 Aug 2022 13:16:27 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:43780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oMBnE-0000tk-Ct for qemu-devel@nongnu.org; Thu, 11 Aug 2022 13:16:26 -0400 Received: by mail-wr1-x42a.google.com with SMTP id n4so20286704wrp.10 for ; Thu, 11 Aug 2022 10:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc; bh=uwBdsBVOiqHy9AjYw9A5odDA4xVS3sjfOA/XRmbIZCE=; b=rEJMdqsnNliLGyfMkICr/W2ZAH/nxPja8LLc0i1FlkAaZ9nzUiXa7JPe+vKOkYMpo3 Xus2pLl7avB5dESdr0e9i2mZOg2wL8XqUgiLy5wAd/KolVfkL85csUE97WP1GE26j8Ws T2+M2mmaLjmMx+ih0g1y4TWsPNw6S7iwYns+6xjzcmkjS58IxS9T1VJs2dVqPdr2x45n yrO81dsBSJ8FBDMVSnuArVhyU6EIMvuhtI//DSK21Ui8h5058Ly2FbfBWBZ2epjuzOYu YZ3+iQ9yy+4Na/2elu7k+DsY51bkt/banKLIWMxTxH9Vg8DkVjdKYoLx54AMF50T/urD VjLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=uwBdsBVOiqHy9AjYw9A5odDA4xVS3sjfOA/XRmbIZCE=; b=daKxvMVaFSP1PYer4k55NuRMnG5MV8lZT7tjmSkD+J9N/FuBOdFimV6W8yhWwtVeql LEbC4K7sfF/rtLmiCNv9pM4R0HOe03NpRJD8i5HIa5yM20t+zA96TJgQ9DAPaZwtY+tE WjjCx4dY7eqt4vmsVvWFqEhnclYGA5QzU0nyVbXfDSIwBgkIH3h1yalnG7+tgZFZL7vA IRjviYMREFKSyrnuXNWfQ1OzVBjeJhf6fygPfgSRMG+cjEYP12K+LCoYERAu1mYMki4K uwZagORpH8EzFLSeh0V6mbp72N+Cn/W8NePCvDj4mud1WI6D3zdUR/G5xL61NLZ7dpch Kxcw== X-Gm-Message-State: ACgBeo38m11VQgkEdUoUP4rfF8Rz8sL6oRwPTxB2AeOfJ3ItDrQoXL3H j8UxVDoeVo5rupt98V7zbp3u3w== X-Received: by 2002:a05:6000:993:b0:222:d509:4b5b with SMTP id by19-20020a056000099300b00222d5094b5bmr42242wrb.52.1660238182759; Thu, 11 Aug 2022 10:16:22 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b1-20020a05600c4e0100b003a2f6367049sm6633918wmq.48.2022.08.11.10.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 10:16:22 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 02/10] target/arm: Correct value returned by pmu_counter_mask() Date: Thu, 11 Aug 2022 18:16:11 +0100 Message-Id: <20220811171619.1154755-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220811171619.1154755-1-peter.maydell@linaro.org> References: <20220811171619.1154755-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" pmu_counter_mask() accidentally returns a value with bits [63:32] set, because the expression it returns is evaluated as a signed value that gets sign-extended to 64 bits. Force the whole expression to be evaluated with 64-bit arithmetic with ULL suffixes. The main effect of this bug was that a guest could write to the bits in the high half of registers like PMCNTENSET_EL0 that are supposed to be RES0. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/arm/internals.h b/target/arm/internals.h index b8fefdff675..83526166de0 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -1296,7 +1296,7 @@ static inline uint32_t pmu_num_counters(CPUARMState *env) /* Bits allowed to be set/cleared for PMCNTEN* and PMINTEN* */ static inline uint64_t pmu_counter_mask(CPUARMState *env) { - return (1 << 31) | ((1 << pmu_num_counters(env)) - 1); + return (1ULL << 31) | ((1ULL << pmu_num_counters(env)) - 1); } #ifdef TARGET_AARCH64