From patchwork Fri Dec 21 16:03:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 10740661 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 96C8314DE for ; Fri, 21 Dec 2018 16:08:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87206284B9 for ; Fri, 21 Dec 2018 16:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B96E284D4; Fri, 21 Dec 2018 16:08:02 +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 73300284B9 for ; Fri, 21 Dec 2018 16:08:01 +0000 (UTC) Received: from localhost ([::1]:46417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaNLE-0003su-Lj for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Dec 2018 11:08:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gaNHO-0001fY-Vq for qemu-devel@nongnu.org; Fri, 21 Dec 2018 11:04:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gaNHO-0004Fc-2B for qemu-devel@nongnu.org; Fri, 21 Dec 2018 11:04:02 -0500 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:44348) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gaNHN-0004BA-LV for qemu-devel@nongnu.org; Fri, 21 Dec 2018 11:04:01 -0500 Received: by mail-qt1-x841.google.com with SMTP id n32so6162105qte.11 for ; Fri, 21 Dec 2018 08:03:55 -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=BFLxT6q9KDFCMRBUTi6o8oPwvKDwh+WJDvy1PvXZOXrgmkn4lqivhU6vuZOuHVPFrb LmHjWBJSBPmDmwU6FC9tAcwzXxstYH2KT0tGfIuYNQfJmp2A4sdgr9TRVGrY/z9pM1AN YnnLeXxJjo7XlIyHOrEwgUvt37uDJ5YDJIm9jF1UN80vE5SWHW/0BZH0EMVxHPbrcDEk TUvEzQrdhDl1NoXj+uhIUvvcAXQ7INx/WtKXFxlO0tuGs4o4EgYrXYa5QwOqCmzMOGum +0Hb0a7njE3gwdhAcFFjlS92xTuNkrYaRHfYXecTWK4vkoaZXAzRrZA40er5tRxGJVan dcoA== 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=tkROPMT8E94V9AGfiOTHLOQjFxsgoOZvtMhveFtbH5vo3Emr6Asi8UW0J0GAiJfT/k NhH9QnUmLerIVIW3Gk6VSRRXvRFn4oMEKbYcjMeJ+wXqDuBtNPXGDGexxmhZ5HdwoCOU EkGrOnPDRymLiL0xUIEoBboRnRRZP7O0i0q5NrQ31tvs4Cijis4tQOPHONqqfs5x1KPE eECieA9fkuGXdBJ41duXfmJMgOCynvUj4OTx5+L/6johXXTQu9XG4Aob4Y5GLlCLUPfn KPXxzyOl1VYDFFIlOuBhMO1O/USpcCw+UZOq/P92VMQQbqhF6+GYXS/J4Wg2Sd+RTmxI tS9g== X-Gm-Message-State: AJcUukcmVBEfRT1fNKqSH3jJV3ThFwmtfI4D8+HhRHcV7W2HDiL/rTpb gkmFqNY8GxzYShwDqM08LAuRspiU5ME= X-Google-Smtp-Source: ALg8bN7HDkHstcrzBb2D1EL2iZd9wYwALtAwVk5F7dj5Zd+ikIVsdvekOmaJkaezjpTpGeLN2J6RwA== X-Received: by 2002:a0c:b093:: with SMTP id o19mr2997013qvc.49.1545408234814; Fri, 21 Dec 2018 08:03:54 -0800 (PST) Received: from localhost ([2601:182:c980:96c:8dd:4488:90b1:59d1]) by smtp.gmail.com with ESMTPSA id 24sm6307676qkx.77.2018.12.21.08.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 08:03:54 -0800 (PST) Date: Fri, 21 Dec 2018 08:03:05 -0800 Message-Id: <20181221160307.14819-13-palmer@sifive.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181221160307.14819-1-palmer@sifive.com> References: <20181221160307.14819-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::841 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: Anup Patel , Anup Patel , Alistair Francis , qemu-devel@nongnu.org, Palmer Dabbelt 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;