From patchwork Sat Feb 2 09:43:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 10794243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A750B746 for ; Sat, 2 Feb 2019 09:57:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9826A3154F for ; Sat, 2 Feb 2019 09:57:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C908315C6; Sat, 2 Feb 2019 09:57:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 420443154F for ; Sat, 2 Feb 2019 09:57:56 +0000 (UTC) Received: from localhost ([127.0.0.1]:40097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gps3f-0002QC-Jh for patchwork-qemu-devel@patchwork.kernel.org; Sat, 02 Feb 2019 04:57:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gprz9-000700-JP for qemu-devel@nongnu.org; Sat, 02 Feb 2019 04:53:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gprqF-0005rc-RU for qemu-devel@nongnu.org; Sat, 02 Feb 2019 04:44:04 -0500 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:45145) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gprqD-0005fJ-P3 for qemu-devel@nongnu.org; Sat, 02 Feb 2019 04:44:03 -0500 Received: by mail-ed1-x544.google.com with SMTP id d39so7433967edb.12 for ; Sat, 02 Feb 2019 01:43:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:in-reply-to:references:cc:from:to; bh=1TwFMTdrijbYHJcqilfA4QcaYI5N+IsK6t29hHJjQM8=; b=jWBNFlIVUxSieGn9yNzTnZEDPVPQ3Ks0r0SgzxEXpIyvwLHqdBH6g0d4jYsypX09Yy gOshzZBYNQanbq5t5Hobhke3RWgUsPU8noExHPscxrJR/SdBReEEhfcjcC8zeRALXNzL RUkLt1I08BQ2uFMrpkn07sMTONPf2Z/+F84YRpQebpdhxovFfpIF6MPaW7So5pHk3sp9 bpmMWBEu5v7UBCQtN6Me42sfy7CPUv39Nm1aPKmRz6pEoLg65DEn/FIfIv652/vYYiA9 awUJIYSmke7fCwOg7fknUYXqclle1Lw+wk6eCpcgA0n1Gysw2rIKvKhoMFqZx845QlYH IWYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :cc:from:to; bh=1TwFMTdrijbYHJcqilfA4QcaYI5N+IsK6t29hHJjQM8=; b=Mr7JDCVIEzmD3lbBZ4jRVkG8YO/B6hks0Pc+pE2OMhkAcz/zMuezg4B5QtNtxvC0h9 /ke0JQvZLBFb2sbcaeCwNrzBY47qT8e6Z8d4L91KWJ/n6MSAXQh2O9wmJIHhjttvldV4 q/T7oEIJln3e+0Yt4LU+omJoios5UI0rpjNs6531ino/634oMpbFtlK1ttZH3tXQo5sS E/YIIf/xLGjjq4+VJhiuZ0DEnkVJ3UO4BC3ySLzJRbxpYK1D04fA+LuuqM9paYHc98Oc AgfK7/F2u1Qnf9eCwgnxF3n8ZXGII1bMitMDmS365U0N4/ktc1v6lfofet0W0R4IBQGN uOZw== X-Gm-Message-State: AHQUAuYYjd5bKPQ7WYycn++C9YKTXr4jVGdIth0qbYMq8z14hDWVVXAY WxQbhmE8yhhMYxFYxQ4FFa0n9A== X-Google-Smtp-Source: AHgI3IZDqO6NitwchuKzB4GZC46FAm5XWCX43ElSO7el/ed2OYCx5YQ0ZGBJXsbE7kKykjFTBJDEwg== X-Received: by 2002:a50:d753:: with SMTP id i19mr18349810edj.75.1549100633570; Sat, 02 Feb 2019 01:43:53 -0800 (PST) Received: from localhost ([2001:67c:1810:f051:fd32:55e2:f60b:183b]) by smtp.gmail.com with ESMTPSA id r51sm2682281eda.64.2019.02.02.01.43.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 01:43:52 -0800 (PST) Date: Sat, 2 Feb 2019 01:43:29 -0800 Message-Id: <20190202094329.22874-11-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190202094329.22874-1-palmer@sifive.com> References: <20190202094329.22874-1-palmer@sifive.com> From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::544 Subject: [Qemu-devel] [PULL 10/10] target/riscv: fix counter-enable checks in ctr() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Palmer Dabbelt , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Xi Wang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Xi Wang Access to a counter in U-mode is permitted only if the corresponding bit is set in both mcounteren and scounteren. The current code ignores mcounteren and checks scounteren only for U-mode access. Signed-off-by: Xi Wang Reviewed-by: Palmer Dabbelt Signed-off-by: Palmer Dabbelt --- target/riscv/csr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index e72fcf1265d4..960d2b0aa951 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -56,9 +56,15 @@ static int fs(CPURISCVState *env, int csrno) static int ctr(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) - target_ulong ctr_en = env->priv == PRV_U ? env->scounteren : - env->priv == PRV_S ? env->mcounteren : -1U; - if (!(ctr_en & (1 << (csrno & 31)))) { + uint32_t ctr_en = ~0u; + + if (env->priv < PRV_M) { + ctr_en &= env->mcounteren; + } + if (env->priv < PRV_S) { + ctr_en &= env->scounteren; + } + if (!(ctr_en & (1u << (csrno & 31)))) { return -1; } #endif