From nobody Sun May 19 00:47:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1571779524; cv=none; d=zoho.com; s=zohoarc; b=Pc4Y+l/iFSQqrK/Em/4DEFQd46F2TTIUrKSQnH84naCiVIIN6BDxMsoqHwnkDayeLjGmgVJXobGbutdve+dyRw39i9WXl7AuzKys2Euyl1g11LuxBipmdzYajhvFM+jx75kcWqDDGHz4qncIDSs7QB5fzpziSabADFYveTU5nH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571779524; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=4ciWYO+JQTfvwrYJqiccgIFokh0umLIjCGNk8VTvZkI=; b=WzWgYSCBtDa/bCGFeaghmHr6DQt5J1pnFZh5e0VgD0XFFe1/AKiNzpE+GrdeWBKoLnCTG39RVV9lpuj29gplTQ/CwZakyIPnJ/TNpBLkXPXo1br3t4/HfJyAfPOowjvHNarlLhmYatdjITfzxA+7zgPCXUGmOWAwK3tkWGjb43Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571779524069366.52017367888914; Tue, 22 Oct 2019 14:25:24 -0700 (PDT) Received: from localhost ([::1]:45508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iN1eb-0002XJ-Tw for importer@patchew.org; Tue, 22 Oct 2019 17:25:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51524) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iN1b1-0000bj-2m for qemu-devel@nongnu.org; Tue, 22 Oct 2019 17:21:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iN1az-0001ei-Fk for qemu-devel@nongnu.org; Tue, 22 Oct 2019 17:21:38 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:41024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iN1az-0001eN-5p for qemu-devel@nongnu.org; Tue, 22 Oct 2019 17:21:37 -0400 Received: by mail-qt1-x842.google.com with SMTP id c17so26077522qtn.8 for ; Tue, 22 Oct 2019 14:21:36 -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 z5sm9625014qkl.101.2019.10.22.14.21.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 14:21:34 -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:mime-version :content-transfer-encoding; bh=4ciWYO+JQTfvwrYJqiccgIFokh0umLIjCGNk8VTvZkI=; b=cVTdazFlt+E+xN+sUem5370SgcTGwyhjVxJXbzsYy5by9y4njNglJcHtu5y8/bCCo4 zH3mOFyd9FNKLwkhqVHzDkEi2P/yryiJ0of76nnqxTUFoAYWpXE5Mr1UZKzjez4E0BOd lqrlYqirqnyc1aXGMbQwsiTV85oPWafEVzjCedjHurVnBmPA8e6D4hOj5cekY2OmmJIQ 6nX9Xrfl3gFQ0hTlIQrK858UdOBWept0FA9qnCnIk3ZBCbaUjdMDAFBEC1mTK95Wh+42 +Ya05P/CM77DB3u9Cfg8tAQOUj+hC4FvIPbUJZ3CfO0RiU2TETaBiGXzc9Ri89HbP3vw kFxg== 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:mime-version :content-transfer-encoding; bh=4ciWYO+JQTfvwrYJqiccgIFokh0umLIjCGNk8VTvZkI=; b=Q6XbG/uOIZUEi7RvX691bNZzTcpJeUM+ZE7ojCcyYQnFRyT3j59GblN50yYogNUgV5 X/G4kKLwPLyGH4vvvmtxUoAyvElQCO4feYsE+luczfGPnM3QMY28qf/U6KiUMbyqJMv4 9hbP5yhqaVQejrje9egwNmQFpUnqoEoQWJImERehRpmGUuAhApLWMzA02RMSt8590dQS AshK9vtjRmuQOM1B87+14vpevBY1ptL12Zn640PclGF2kxHXPBoCs/n623Nwo0m4ioD7 sU2nGQcN/faeaUI7J9P0+YLe5zVAc7CTOLMwVdgrZmKcLhJNeZdnCmvgypLByIeDzEHq +h/Q== X-Gm-Message-State: APjAAAWC+TDcu1pEGzhhJlo7wkFHcY/dgtO7rSVB8JWATkOzChDfaH8N rxZrMB/8AVwPMJMCQ1xzc8AZXPh8Im1Zkw== X-Google-Smtp-Source: APXvYqwsdr6ZhYJ8iiAjz/Hg+tgGmCI7x+R7tbcmQgArv30Q09txhTI2OVFfcCfN2iRTQPqYmh99Lg== X-Received: by 2002:ac8:73cf:: with SMTP id v15mr1610041qtp.310.1571779295221; Tue, 22 Oct 2019 14:21:35 -0700 (PDT) From: Dayeol Lee To: qemu-devel@nongnu.org Subject: [PATCH] target/riscv: PMP violation due to wrong size parameter Date: Tue, 22 Oct 2019 21:21:29 +0000 Message-Id: <20191022212129.8452-1-dayeol@berkeley.edu> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::842 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: "open list:RISC-V TCG CPUs" , Sagar Karandikar , Dayeol Lee , Bastian Koppelmann , Palmer Dabbelt , Richard Henderson , Alistair Francis , diodesign@tuta.io Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" riscv_cpu_tlb_fill() uses the `size` parameter to check PMP violation using pmp_hart_has_privs(). However, if the size is unknown (=3D0), the ending address will be `addr - 1` as it is `addr + size - 1` in `pmp_hart_has_privs()`. This always causes a false PMP violation on the starting address of the range, as `addr - 1` is not in the range. In order to fix, we just assume that all bytes from addr to the end of the page will be accessed if the size is unknown. Signed-off-by: Dayeol Lee Reviewed-by: Richard Henderson --- target/riscv/pmp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 958c7502a0..7a9fd415ba 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -232,6 +232,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulon= g addr, { int i =3D 0; int ret =3D -1; + int pmp_size =3D 0; target_ulong s =3D 0; target_ulong e =3D 0; pmp_priv_t allowed_privs =3D 0; @@ -241,11 +242,21 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ul= ong addr, return true; } =20 + /* + * if size is unknown (0), assume that all bytes + * from addr to the end of the page will be accessed. + */ + if (size =3D=3D 0) { + pmp_size =3D -(addr | TARGET_PAGE_MASK); + } else { + pmp_size =3D size; + } + /* 1.10 draft priv spec states there is an implicit order from low to high */ for (i =3D 0; i < MAX_RISCV_PMPS; i++) { s =3D pmp_is_in_range(env, i, addr); - e =3D pmp_is_in_range(env, i, addr + size - 1); + e =3D pmp_is_in_range(env, i, addr + pmp_size - 1); =20 /* partially inside */ if ((s + e) =3D=3D 1) { --=20 2.23.0