From patchwork Tue Jul 17 21:25:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dayeol Lee X-Patchwork-Id: 945393 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=2001:4830:134:3::11; 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=berkeley.edu Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=berkeley-edu.20150623.gappssmtp.com header.i=@berkeley-edu.20150623.gappssmtp.com header.b="j82x2vmt"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41VZp91X4Qz9s21 for ; Wed, 18 Jul 2018 08:34:23 +1000 (AEST) Received: from localhost ([::1]:33688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffYXz-0000NM-Np for incoming@patchwork.ozlabs.org; Tue, 17 Jul 2018 18:34:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffXTn-0002CG-C1 for qemu-devel@nongnu.org; Tue, 17 Jul 2018 17:25:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffXTj-0000wm-Dl for qemu-devel@nongnu.org; Tue, 17 Jul 2018 17:25:55 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:42695) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ffXTj-0000we-76 for qemu-devel@nongnu.org; Tue, 17 Jul 2018 17:25:51 -0400 Received: by mail-qt0-x243.google.com with SMTP id z8-v6so2262006qto.9 for ; Tue, 17 Jul 2018 14:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berkeley-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=hc0/jb+svwcnqx29GuPeQPbJMqO769YdSwgAsyIPyP8=; b=j82x2vmt+km3h6O0rYH6/g8rMU7GHiP4ovfKQZIExdxl90CB7In0K3kS+pgOvKi+RC ONhlWPRMqRZOQdi3v/zn+FrtqKvtFqiHMJAmndwLYheO0LrdnsgLjZDDATtlOxKuF1pd 199SXP0eM0rtuNaJhP5I0ZtndTwOVjU4xVdA29Yv9jv+wTfnjah9IUB8L4AaXQ/ldvYG haEnHqFomWPH6ihVFr2fXveQbQCfoWnGoOJb+SLlzEPgXywctj/c9aqj2ixbEf12+Xbf Dh/gsk4qRqogewofBCfT6FWwykDx40K+xIeXsOXX+KH42RlaevDyTKQFYKtG1rKoK6rG oqRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hc0/jb+svwcnqx29GuPeQPbJMqO769YdSwgAsyIPyP8=; b=DXeIyjVYoGHPPsGrle61+y4MKBpCHfWYSdUP0xzhnBuMuEbpE2+FYArjP/FaYv8i+U a9CJt6cfPU6eyaYlqM9Wfed+N+FYmOVL2Mr/aGE29s6SFgzyPA8aMX4IXIBmCDivdsXO rF3hC+ka+/QwB0JnEFChiYriSSjYAtcJ55eZKejTK6wDmUFMq/CDMwERrJ3EwKalXSPE HqgeUI6fb/Z6QED9xZHRTlJMYfRCang+FLO5SADYPC+vBJB77xidbKQIYmLnO1fMmGJn BkxVEv0bg8p4glxLUIqriNSGySI5C9wPY39FpfBRSzw+2TIim3J8r0JI2IRjL6Y3r4B5 ufqQ== X-Gm-Message-State: AOUpUlElWYQ16pt1Hx7pVOCddWXcVd+8MiqYrU0y6OMEXVZEf2Kmbhox 9NyHdgROkDRSVzfK+Iy3ghRcph5VJCmrkS7A2Hg= X-Google-Smtp-Source: AAOMgpdhEMYJ3LFhHNyBqdH4uBafNTW7SjuzSSU/weh03dqIZD2VsIjvnTrRShd5FJtU7PstbjNgFw== X-Received: by 2002:a0c:e505:: with SMTP id l5-v6mr3700263qvm.128.1531862750303; Tue, 17 Jul 2018 14:25:50 -0700 (PDT) Received: from ip-172-31-33-50.ec2.internal (ec2-34-206-44-154.compute-1.amazonaws.com. [34.206.44.154]) by smtp.gmail.com with ESMTPSA id t16-v6sm1930481qth.43.2018.07.17.14.25.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jul 2018 14:25:49 -0700 (PDT) From: Dayeol Lee To: qemu-devel@nongnu.org Date: Tue, 17 Jul 2018 21:25:45 +0000 Message-Id: <1531862745-8394-1-git-send-email-dayeol@berkeley.edu> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 X-Mailman-Approved-At: Tue, 17 Jul 2018 18:33:53 -0400 Subject: [Qemu-devel] [PATCH] target/riscv/pmp.c: Fix PMP range boundary address bug 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: Sagar Karandikar , Dayeol Lee , Bastian Koppelmann , Palmer Dabbelt , Michael Clark , alistair.francis@wdc.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 c4c6b09..459e556 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) {