From patchwork Fri Jun 28 17:31:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 11023321 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 83ED6331B for ; Fri, 28 Jun 2019 18:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F37A628A17 for ; Fri, 28 Jun 2019 17:39:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4A7728A1A; Fri, 28 Jun 2019 17:39:18 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B93B28A17 for ; Fri, 28 Jun 2019 17:39:18 +0000 (UTC) Received: from localhost ([::1]:34938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hguqB-0005h5-Bv for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Jun 2019 13:39:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54394) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hguk1-000870-Pc for qemu-devel@nongnu.org; Fri, 28 Jun 2019 13:33:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hgujy-0008Jr-Gp for qemu-devel@nongnu.org; Fri, 28 Jun 2019 13:32:53 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39109) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hgujy-0008Ie-AV for qemu-devel@nongnu.org; Fri, 28 Jun 2019 13:32:50 -0400 Received: by mail-pf1-f194.google.com with SMTP id j2so3324306pfe.6 for ; Fri, 28 Jun 2019 10:32:49 -0700 (PDT) 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 :mime-version:content-transfer-encoding:cc:from:to; bh=TZ7LklPK8UvVtDwbEWjV8Myyoa+ER/F09z/DtS5QZ9Q=; b=DkDbZkNNguKJfuYivrINOHKLw6mvhgumg4IDUwtTKbooqF2BR3HjSykM5SZ929LS/C Rzlwct7WSgjFc47vr0Seub9wcOkG5iFeZ0qFULKh+GcQ0ti87Qhm9wm+NebOUNYqXBAD VNkb19G2x8K3D//U2DeBqKTeQrwU27xY2hInxRmrmuVEhUuwcRYeKemE0w78WVvVvA7V wNGYBB8LXT++pP7Y0tF2V6MGwe+yIRZEyk7ucu3eSRthNEIA0XgNU3N7zM75gFN0SCqF Nmv+uz4MsLEl+oWL4988tZqyd3CKzZjNaPJlamQEEnuIPJRZGYRKQx43veziBNhbTkFy iOyA== X-Gm-Message-State: APjAAAU8TST+hqj+yPDjJ6UvHHpCdZkMNTQyU1YyavXg2KBsmk/nbUY9 hS8d0Vih8A/8tkunAFSpil/kiOizEDh1lQZ3 X-Google-Smtp-Source: APXvYqyBk/LvGledl175O03URpiHsSPfbfOFMkN0vi4VWr760Ic+394LA9kH6FhvOrn0cTEqymnTLA== X-Received: by 2002:a63:221f:: with SMTP id i31mr3722713pgi.251.1561743168142; Fri, 28 Jun 2019 10:32:48 -0700 (PDT) Received: from localhost (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id x6sm2514807pjp.18.2019.06.28.10.32.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 28 Jun 2019 10:32:47 -0700 (PDT) Date: Fri, 28 Jun 2019 10:31:56 -0700 Message-Id: <20190628173227.31925-4-palmer@sifive.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190628173227.31925-1-palmer@sifive.com> References: <20190628173227.31925-1-palmer@sifive.com> MIME-Version: 1.0 From: Palmer Dabbelt To: Peter Maydell X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.210.194 Subject: [Qemu-devel] [PULL 03/34] target/riscv: Fix PMP range boundary address bug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Dayeol Lee , Palmer Dabbelt , qemu-devel@nongnu.org, Michael Clark , 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: Dayeol Lee A wrong address is passed to `pmp_is_in_range` while checking if a memory access is within a PMP range. Since the ending address of the pmp range (i.e., pmp_state.addr[i].ea) is set to the last address in the range (i.e., pmp base + pmp size - 1), memory accesses containg the last address in the range will always fail. For example, assume that a PMP range is 4KB from 0x87654000 such that the last address within the range is 0x87654fff. 1-byte access to 0x87654fff should be considered to be fully inside the PMP range. However the access now fails and complains partial inclusion because pmp_is_in_range(env, i, addr + size) returns 0 whereas pmp_is_in_range(env, i, addr) returns 1. Signed-off-by: Dayeol Lee Reviewed-by: Alistair Francis Reviewed-by: Michael Clark Signed-off-by: Alistair Francis 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 fed1c3c0301b..e0fe2064074a 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -245,7 +245,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, from low to high */ for (i = 0; i < MAX_RISCV_PMPS; i++) { s = pmp_is_in_range(env, i, addr); - e = pmp_is_in_range(env, i, addr + size); + e = pmp_is_in_range(env, i, addr + size - 1); /* partially inside */ if ((s + e) == 1) {