From patchwork Wed Dec 26 17:20:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 10743261 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 BCBEA746 for ; Wed, 26 Dec 2018 17:35:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A39A0286C0 for ; Wed, 26 Dec 2018 17:35:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96122286EB; Wed, 26 Dec 2018 17:35:05 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 316F8286C0 for ; Wed, 26 Dec 2018 17:35:05 +0000 (UTC) Received: from localhost ([127.0.0.1]:47551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gcD5E-000516-Fj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Dec 2018 12:35:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:48197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gcCrZ-0004YD-GG for qemu-devel@nongnu.org; Wed, 26 Dec 2018 12:20:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gcCrX-0007zY-Dj for qemu-devel@nongnu.org; Wed, 26 Dec 2018 12:20:57 -0500 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]:45293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gcCrX-0007r5-4W for qemu-devel@nongnu.org; Wed, 26 Dec 2018 12:20:55 -0500 Received: by mail-qt1-x843.google.com with SMTP id e5so17803252qtr.12 for ; Wed, 26 Dec 2018 09:20:36 -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=pGdFvWxsyK+082c4RANqehx4XfGix5v1XjwMetfsyZg=; b=hCb9bHcUTmosQZTdPc3pFChUYVni85WHzug2suAPBTGMJ4D112hj1lXqcOfqHKtdvE 7fRxpz0MPb+UWizmvK1Z/CM9tDxoatvH6wZRbUUDIPmUMtkVK2FZ+U0oVgAuDsJb1O9K 6MdyxngPQy9X2uG1oEor85NRmOT64PAQqzHBWmDSbcjeBIp/5n4KW/Cem1ZefnakhQPr UilnaVsZlrPrSyVBHRL0y7DSTF6h2a+rv3XBIo+AXMKWUBM5S7hbMt0G26nx2yMfi85e 90WSlutqsKsKEeY+3pNmK1F0+0WhADnOBgaTIUbM1Z3SIlDfJ4KjbYNgbnp3mUaFmLpY I+3Q== 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=pGdFvWxsyK+082c4RANqehx4XfGix5v1XjwMetfsyZg=; b=BOZnTC2S6hm17tUEsyjXSfkT4/8RQNlheStnSryVB229+IbmFjbrlrez8YbwUqV1fm wTEWXd4g62YlH1Ox52E/mp5+HGC9YNm8RixV7wUd9b/mKnvD5SXomP6xCg7cLvcpWdLM VOKXFg4cL0TZ8VtDoj3wztxRrQZxkNvRO78jPewx+QVpGdttms8fm2FoBu0nrkaZ0IJ4 pBiic0tBy1ne8W24U2Gclt8ZF9X7o8ZAtY/8R6XGl24/3ScR5wglZXEpqkKAG414cG2Y KHW24xiSWcrpl07wfYFPaE6nmxMpVZsmToYwByKy+1oK9fvwAfP4P23fSs+a6dT/Xb92 dRtQ== X-Gm-Message-State: AA+aEWameLh+ER9JA42MwkCpkQOBBcR2kd1+EW8gQwmaMJSB1/ff3x/P fRYvRC/zI9jYxPs9YD6G79d2gg== X-Google-Smtp-Source: ALg8bN7KXaWbXl1EW4Ym+K3KKr5R+aTJB554/eBfVrYg0PjhyLkP113A1d2FG3tlcG7zMaRMFeevYw== X-Received: by 2002:ac8:1779:: with SMTP id u54mr18928970qtk.285.1545844835755; Wed, 26 Dec 2018 09:20:35 -0800 (PST) Received: from localhost ([2601:182:c980:96c:8dd:4488:90b1:59d1]) by smtp.gmail.com with ESMTPSA id o65sm13313201qkl.11.2018.12.26.09.20.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Dec 2018 09:20:35 -0800 (PST) Date: Wed, 26 Dec 2018 09:20:03 -0800 Message-Id: <20181226172005.26990-13-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181226172005.26990-1-palmer@sifive.com> References: <20181226172005.26990-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: 2607:f8b0:4864:20::843 Subject: [Qemu-devel] [PULL 12/14] target/riscv/pmp.c: Fix pmp_decode_napot() 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, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Alistair Francis Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Anup Patel Currently, start and end address of a PMP region are not decoded correctly by pmp_decode_napot(). Let's say we have a 128KB PMP region with base address as 0x80000000. Now, the PMPADDRx CSR value for this region will be 0x20003fff. The current pmp_decode_napot() implementation will decode PMPADDRx CSR as t1=14, base=0x100000000, and range=0x1ffff whereas it should have decoded PMPADDRx CSR as t1=14, base=0x80000000, and range=0x1fff. This patch fixes the base value decoding in pmp_decode_napot() when PMPADDRx CSR is not -1 (i.e. 0xffffffffffffffff). Signed-off-by: Anup Patel Signed-off-by: Anup Patel Signed-off-by: Alistair Francis Reviewed-by: Palmer Dabbelt Signed-off-by: Palmer Dabbelt --- target/riscv/pmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 03abd8fe5eb7..15a5366616bd 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -138,7 +138,7 @@ static void pmp_decode_napot(target_ulong a, target_ulong *sa, target_ulong *ea) return; } else { target_ulong t1 = ctz64(~a); - target_ulong base = (a & ~(((target_ulong)1 << t1) - 1)) << 3; + target_ulong base = (a & ~(((target_ulong)1 << t1) - 1)) << 2; target_ulong range = ((target_ulong)1 << (t1 + 3)) - 1; *sa = base; *ea = base + range;