From nobody Sun Feb 8 21:22:48 2026 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=1570426336; cv=none; d=zoho.com; s=zohoarc; b=eoXSSCi0pJIXJKCvgfTa91aL5SeuUqCk8fHQ5hD/stqrbAJfEH8fCPJFu5dp0kN9IFoE90fx7bioShobxZ4zSuOuZ8F2KsfQkhF24237j7Jp7rfOphRDOX72QtXsetbe0vylfxeF0XbjJN2gjrqjsQX95z0qhrj39gi9n9lAXJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570426336; 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:ARC-Authentication-Results; bh=Rr3IprOX7AO10O0bgWlRAZKUNbbkrLFaHkwJpmsGJ1g=; b=YgnjgEb9V63AsDrBZ5/V0OH7PwwO7dZddCwMprSL9PsBux83ohg5NGA5gHntfaXWI4jZWDnxwHzV2xHFNhtJz/CuLnhRqEtLonYGDKrmD3xKC951f10zvPr+btipvwZxLJqzAts4uXcCBKewLPXIy6J2Zc8ebUyOLWrhsSIHYAs= 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 1570426336153717.2744430603643; Sun, 6 Oct 2019 22:32:16 -0700 (PDT) Received: from localhost ([::1]:40778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHLcx-0006Zx-JP for importer@patchew.org; Mon, 07 Oct 2019 01:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58549) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHLZK-0004TB-P6 for qemu-devel@nongnu.org; Mon, 07 Oct 2019 01:28:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHLZI-0001DZ-9p for qemu-devel@nongnu.org; Mon, 07 Oct 2019 01:28:26 -0400 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]:43410) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHLZI-00018c-0f for qemu-devel@nongnu.org; Mon, 07 Oct 2019 01:28:24 -0400 Received: by mail-qt1-x844.google.com with SMTP id c4so4815467qtn.10 for ; Sun, 06 Oct 2019 22:28:22 -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 p7sm7188080qkc.21.2019.10.06.22.28.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 06 Oct 2019 22:28:20 -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=Rr3IprOX7AO10O0bgWlRAZKUNbbkrLFaHkwJpmsGJ1g=; b=yUzZV1ZZonu0IV2QjRwfg62rBkuA5fykVYUIG5pgA1My17z4dvaXCC6ZEKuKX6+0SJ lFzKoT9PIOITxYuTSSSU6bORNIioAk8cgR2U85p6IGo3YQXAaCwCR94bD8u253XAu5Xb nTW7oR/rHWwwGSK1mPB8sDhjR3AH8g/eqg4QRvKnVc6Y5jvWQ23jPjqLn6akHZSFvuA2 +UH3UTKBvOZWMC5XFrCizjJMQ2CK1kItRiMIwmDTpI4XCGNEyse58Ut6wM6AtV8XxhnP NuM3qYbUECEVC3TMmpeGqnYwOortKmoAXnHQyQv0ie7ju43N20Jmik9puYHTe75ehNdn 0F3A== 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=Rr3IprOX7AO10O0bgWlRAZKUNbbkrLFaHkwJpmsGJ1g=; b=hqccjC6X6v8r4tfReoFiGL+sFk/ZT9TODHmSTI0MjpZxm0NXNU7sKX4lCapKEDnkfF hGMMEpbWPZQ+b72rcaPoKKez32PLfO4nCrIcN98TDweJUBanTd9enfIPhM0sQay6U3Rb d6Nf5NksMUQXSln+Ylhd0ErEgvEkSPU3wKsDMmfZl2AlCqO9FVd3qJUVIdvebqaUb0gs 7MdYN3BpB3MCX0hrFmU6whGaRkgkcnwAUG/C4fBumd+vBSw2qdPjElna110YGS6EYrhQ dsZBdnKl4pIojugxWXjWlWsUtgGvOb7gyehoSKhAOGc7BBB4dQscOMpfQKCtUwAE6bKh yHGw== X-Gm-Message-State: APjAAAVdNFiTMi8msQALTJsmGAZfLf40KGpM/vBmJK5o03RtV41PPoEB oL50yD3IwCbk6i4qgIVAco526SeDrzA= X-Google-Smtp-Source: APXvYqz7oompv1PkWuor1GOd0uwy3WSIQk59nDPqLP94kJKcHzyyKBOKp6d9IAfYtcJnf61rEHh1Ng== X-Received: by 2002:ac8:f1c:: with SMTP id e28mr27645328qtk.161.1570426101169; Sun, 06 Oct 2019 22:28:21 -0700 (PDT) From: Dayeol Lee To: qemu-devel@nongnu.org Subject: [PATCH] target/riscv: PMP violation due to wrong size parameter Date: Mon, 7 Oct 2019 05:28:13 +0000 Message-Id: <20191007052813.25814-1-dayeol@berkeley.edu> X-Mailer: git-send-email 2.20.1 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::844 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 , Alistair Francis 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, the size passed from tlb_fill(), which is called by get_page_addr_code(), is always a hard-coded value 0. This causes a false PMP violation if the instruction presents on a PMP boundary. In order to fix, simply correct the size to 4 if the access_type is MMU_INST_FETCH. Signed-off-by: Dayeol Lee --- target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0adb307f32..386c80e764 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -88,6 +88,7 @@ enum { #define MMU_USER_IDX 3 =20 #define MAX_RISCV_PMPS (16) +#define RISCV_INSN_LENGTH 4 =20 typedef struct CPURISCVState CPURISCVState; =20 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index e32b6126af..877e89dbf2 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -441,6 +441,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, CPURISCVState *env =3D &cpu->env; hwaddr pa =3D 0; int prot; + int pmp_size =3D 0; bool pmp_violation =3D false; int ret =3D TRANSLATE_FAIL; int mode =3D mmu_idx; @@ -460,9 +461,15 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, i= nt size, "%s address=3D%" VADDR_PRIx " ret %d physical " TARGET_F= MT_plx " prot %d\n", __func__, address, ret, pa, prot); =20 + if (access_type =3D=3D MMU_INST_FETCH) { + pmp_size =3D RISCV_INSN_LENGTH; + } else { + pmp_size =3D size; + } + if (riscv_feature(env, RISCV_FEATURE_PMP) && (ret =3D=3D TRANSLATE_SUCCESS) && - !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) { + !pmp_hart_has_privs(env, pa, pmp_size, 1 << access_type, mode)) { ret =3D TRANSLATE_PMP_FAIL; } if (ret =3D=3D TRANSLATE_PMP_FAIL) { --=20 2.20.1