From patchwork Wed Jan 30 17:36:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 1033680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="R449p6Ec"; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 43qVv55zflz9sDX for ; Thu, 31 Jan 2019 04:37:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:41792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goto7-0004i2-Pk for incoming@patchwork.ozlabs.org; Wed, 30 Jan 2019 12:37:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gotn3-0004gK-H5 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 12:36:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gotn2-00005z-9C for qemu-devel@nongnu.org; Wed, 30 Jan 2019 12:36:45 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:46701) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gotmx-0008Vx-L9 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 12:36:42 -0500 Received: by mail-pf1-x444.google.com with SMTP id c73so115490pfe.13 for ; Wed, 30 Jan 2019 09:36:37 -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=R449p6EcZcCe8qKKd7DGx7lrvGNikJO4wdRMj/7q5B9//qefFps5qbHhbNPCiazAT1 WZXZrR3NBBoPH8Kg/vlp0LVAeHLKvPlFUZdxI+I5mG03sXHtgAleraV5tTTtumoHObYY J3YujLsMrwkixsj9t+/DFY8qsLI1y5k2lQuDFAEyWLxnUtKqS3wFc/ygUyhBCut+78rb cY+k75+xr8hDPJEGRAoDv4wMNxyVXc4PG5UgQ0LgQfw1wVaBkfr0jBd5qpocBFRFtzFj 3Xjke0lxzJ3VUwaxCmnR1wKkctB5dvnejxcIvlTzEkxNk1s65ReVP8Lj534ukBfEkA7u 6eVg== 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=iHYKBCL8zyWiJDrnHO66aYyMRWn7fUI5t2JpHJeRYUd03yFJHDWvgwgQuFFvOHwWr+ Za1RRdQwZBnNGHIhFzQQ9YSrBePB4hnZeFx1pCOyWMSFFg97c9QO/8xxTHFV5nysvLpu tDqgWWWiBnGY7xR7qVmmDoUBCZ1zDm67QoiH1Ajee7VaYORhe0WQY4UrsGyhD4etN9oA 4rvDpzcru8LbIgoTtt3uuXUT9rWSDzPXNJBARzOUj9Lom4PnfoHS6J1VZnzp068AmDaz iEzjYIjturZMNASA/04A5XBKAGhalEnfg1rfvMFafgVgJbty/PafCJ7S6zhQgaNQM8rQ +xzQ== X-Gm-Message-State: AJcUuke8bwOAuw0REhlB0dplb3R71iUf13JmfvIvQzgBCfjV8tghKVEM k7bh2l+48AvrLoeRr8HBo0jvT96GKSk= X-Google-Smtp-Source: ALg8bN7amQjZQsD7uwpMSmxsxVmqiflR5+kV131L7e5L8cCKmsiyShbtkbCrrdMvce2uJDGAdx2Q6g== X-Received: by 2002:aa7:824f:: with SMTP id e15mr30697190pfn.192.1548869796254; Wed, 30 Jan 2019 09:36:36 -0800 (PST) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id v89sm3574305pfj.164.2019.01.30.09.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 09:36:35 -0800 (PST) Date: Wed, 30 Jan 2019 09:36:01 -0800 Message-Id: <20190130173601.3268-11-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20190130173601.3268-1-palmer@sifive.com> References: <20190130173601.3268-1-palmer@sifive.com> From: Palmer Dabbelt To: qemu-riscv@nongnu.org X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 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-devel@nongnu.org, Xi Wang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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