From nobody Sun May 19 05:00:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1595581977; cv=none; d=zohomail.com; s=zohoarc; b=dpTGUog/tDl45D5tsMgPpbDIeDjW27esNMync7GsZcNMM0xdqSoVVjsk1se1Gyxc0CWYeKzS+Vx3oD+CEI89JMGQNtJvAV8txrezBpaX88Jj1ZbkV+p63zlgCjxTt8No3djySAzOxia5altWGLZMDaY+RBLhb+C1DMa60qREChA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595581977; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=W9alUim2NScoKewf8vVRphcseP9RDIaK8xQN1I3tCFA=; b=BaO3xiRstyNyHQkw/yVCBo6bXAKc225TnyHaHkHmGUMheqXrGDR5TX7TmOgiMFzfXFRvV3M0EWVuWLlDIy/xQmqpwsK/kFOEHOhdCE3OmidfgVOPDcsYqKoPIscJ0uwKzY8kJCSkxMjmQATRA133tEhNZjMxTzEQ8mcUUuvZTjk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1595581977029756.8290333530806; Fri, 24 Jul 2020 02:12:57 -0700 (PDT) Received: from localhost ([::1]:34792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jytl9-0008FT-NJ for importer@patchew.org; Fri, 24 Jul 2020 05:12:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jytgp-0002yX-LU for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:27 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:36500) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jytgn-0003qq-Ft for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:27 -0400 Received: by mail-pg1-x541.google.com with SMTP id p3so4885982pgh.3 for ; Fri, 24 Jul 2020 02:08:25 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id z10sm5751282pfr.90.2020.07.24.02.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 02:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W9alUim2NScoKewf8vVRphcseP9RDIaK8xQN1I3tCFA=; b=NEuAo0+FPdLDYXnqNg2JpoCkCtxOHsPVUUinDR/thsTlX5v2qoEUMqOPeTExwFGJxw XxfgSBGBvcWjjgA6P7U8MRkZIke9QHs+9+jNXUdC09WOe/MKOFgLJVCBaP5cz4OhNZsx 9+dAlJ4BYtpMQajUFi7Ht5L1SHAxTyL6veI/gDb7FPSXrOuzCBI2sYWzPtMsWd6fsUo7 Vl8curui8/4MBqDqtJTO4kFqnHZdUUR8P2Cuu+yp+Fv82tHzlYB5L6G3Z1VSrLOdehis loQ6+3iQgXSJjtcNvL15UodQyMrNrYVRxZPxVpsXYyAoLZYKFI1Z7aoQv11wDpoEjfM2 FyXg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=W9alUim2NScoKewf8vVRphcseP9RDIaK8xQN1I3tCFA=; b=rDxle+zWd0pwGH1tEdUbPFwdgtUqGd5IZ2SSNvr/69eHnhQQYfWJ+fPL9BidSPZA+J wQfvVqLDt6p3adKBMA9gLSN5whTS6DgA7ycjo23ISIOijPZLiV0cI5DyU7HI+idAiuiL +Znt7xKqmqUOHI+Iufa6fkcfFR+ImlAAvBdaJiuD+CiGpF3zg/zAioD6r/2txqF8ggaj E+AsVIfNxWOiauSAKmEc4RIQqTkPMBn+VOZMHDXeex7hO/5u7U3AtFk2BzF43s5v7/GF mLuOcgrIFnJk55QkQY0eSzGb2xib48PfQulOWnBz3pBKenEs5KmrZQbc6JAKjURp3l8E 7bNw== X-Gm-Message-State: AOAM530myZQtNoG+ZWWBRONRLCFg7BiIA5bAfrorrYLJQTG6zMAznnZ+ geoYghXc2LJ8lgoEFJivxjAMlw== X-Google-Smtp-Source: ABdhPJyWoUlFygsaKpwg+z2Gkym6Ac9gM4lNkND+/hYhFE/ORlNbu9SXFBatzp1DJEA/YGI+AnICXQ== X-Received: by 2002:a05:6a00:228e:: with SMTP id f14mr5789407pfe.122.1595581704218; Fri, 24 Jul 2020 02:08:24 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v4 1/4] target/riscv: Fix the range of pmpcfg of CSR funcion table Date: Fri, 24 Jul 2020 17:08:14 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=zong.li@sifive.com; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Bin Meng , Alistair Francis , Zong Li 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" The range of Physical Memory Protection should be from CSR_PMPCFG0 to CSR_PMPCFG3, not to CSR_PMPADDR9. Signed-off-by: Zong Li Reviewed-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ac01c835e1..6a96a01b1c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1353,7 +1353,7 @@ static riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = =3D { [CSR_MTINST] =3D { hmode, read_mtinst, write_mtins= t }, =20 /* Physical Memory Protection */ - [CSR_PMPCFG0 ... CSR_PMPADDR9] =3D { pmp, read_pmpcfg, write_pmpc= fg }, + [CSR_PMPCFG0 ... CSR_PMPCFG3] =3D { pmp, read_pmpcfg, write_pmpc= fg }, [CSR_PMPADDR0 ... CSR_PMPADDR15] =3D { pmp, read_pmpaddr, write_pmpa= ddr }, =20 /* Performance Counters */ --=20 2.27.0 From nobody Sun May 19 05:00:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.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=1595581760; cv=none; d=zohomail.com; s=zohoarc; b=VNa3dxGHR9mOsfUznUm6sM5zvVs0FK1hfZyfcQNZNeLWLruIiBludAjAsxnaX9c+fTYoeJDv/UQdyoCVpkwcW4sqH/IhYUmtV8Du8vCzXxlAiyzZvj4JVdExbyckHncoPSFU0/uyE61qCwynKNMBaVeSwDCnWg5o9dTeWpzG5M0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595581760; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OLjpUO1DCpJGaYWJ7mKFZ69DXAIjGwURbGFioJmjOJw=; b=jsW55aJgNrtXg0Jkv3yO/tkSDHegdjGV2dgDOHa6zCLLS1XylxZjIlNGSOBFNJ4/0Ylz2X/NlTT7OoB+gTocZqnADvx/HAeclRyZgLisU/ucAA99x4+LcMIWdt+DC2ovDDxN+k7U+58A7CCjeQymaOSSQTbPAs6ulfBAbCy8Nw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1595581760708271.948687883924; Fri, 24 Jul 2020 02:09:20 -0700 (PDT) Received: from localhost ([::1]:53020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jythf-00044M-Hw for importer@patchew.org; Fri, 24 Jul 2020 05:09:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jytgq-00030j-Rk for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:28 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:41623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jytgp-0003rg-74 for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:28 -0400 Received: by mail-pf1-x441.google.com with SMTP id w126so4567253pfw.8 for ; Fri, 24 Jul 2020 02:08:26 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id z10sm5751282pfr.90.2020.07.24.02.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 02:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OLjpUO1DCpJGaYWJ7mKFZ69DXAIjGwURbGFioJmjOJw=; b=R/UOv6qlQ+C3HE3ZKdhNC+cQy3FfLS3Fvll8g9nJ/HuymK0zNj1gV0AiGfDU0ggIVr gJdvdOF+BJimcfL475OdA3+BP1CUAi+POXo/OqdHJVU9RN+bymbbzvycj/d9LpHvT3RX /QPS2ag9/U/aY+WK9NddSZgbcyt2mhRE96QfCqgQ/QtfZWo/i0i1HAJatuHsItTdGLpY byhbZW1gdh1iVC/QxWk/e0msENz03QBIkzJfy2RDtY+2pmULJ9zIyTZ8F7cmpcFpmBUL v06O+b24XklRCKuAIajxYndtNpoLfnsNgj+NSaKx7SXoUJZu5zudmuZKrQZjFkOJ+oPT SFAA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=OLjpUO1DCpJGaYWJ7mKFZ69DXAIjGwURbGFioJmjOJw=; b=F+bT3/uB12ujDDFCekIL/DE/dS+y3F1RBykBCDa52pzvEOGxSx08VCYDJDqW8fMUOt yHu2pZLihSj/lcITDKMRQry4zJCtXQLPL6m1hU13mbtX/wpr92MfnGZZhWtxLTWl12kD x9bGO0fQDaa7mwRovhU6tPt850if0vSOhoB31L1rYRMDyu+DVRk8es5fXKKsOi7Z/K+8 k1D31v1JlT15Cjjh/XIeG5FNq3Oh0TZmL48r1IK2djc8LD2EYvuK08q3EZ+39LIgn3/K mbUAOv2s6dbXaPwgDUV8zj3mJspUDMhSJZQ6hqXAE1I48DBuFKt8cOWMjct26Xyush0/ v+Eg== X-Gm-Message-State: AOAM5334J4PZejEgpEzKaPuk0B7vSBllGmV88nSZLXpI1nWXdQ7imyl5 EqRuXRyy/Q9xwKmf2Q9EEICUPQ== X-Google-Smtp-Source: ABdhPJyIp37GphfZvP1b6Kvk+cCJSeiZluNPkxcu8cvXqQDq5xyHbFKPfyAinSoUDoXWJ8bVb8uCfA== X-Received: by 2002:a62:2546:: with SMTP id l67mr8364222pfl.154.1595581706092; Fri, 24 Jul 2020 02:08:26 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v4 2/4] target/riscv/pmp.c: Fix the index offset on RV64 Date: Fri, 24 Jul 2020 17:08:15 +0800 Message-Id: <56c2770fc75e1e0c833248ea5d9faa038b69e328.1595581140.git.zong.li@sifive.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=zong.li@sifive.com; helo=mail-pf1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Zong Li Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @sifive.com) Content-Type: text/plain; charset="utf-8" On RV64, the reg_index is 2 (pmpcfg2 CSR) after the seventh pmp entry, it is not 1 (pmpcfg1 CSR) like RV32. In the original implementation, the second parameter of pmp_write_cfg is "reg_index * sizeof(target_ulong)", and we get the the result which is started from 16 if reg_index is 2, but we expect that it should be started from 8. Separate the implementation for RV32 and RV64 respectively. Signed-off-by: Zong Li --- target/riscv/pmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 2a2b9f5363..e0161d6aab 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -310,6 +310,10 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg= _index, int i; uint8_t cfg_val; =20 +#if defined(TARGET_RISCV64) + reg_index >>=3D 1; +#endif + trace_pmpcfg_csr_write(env->mhartid, reg_index, val); =20 if ((reg_index & 1) && (sizeof(target_ulong) =3D=3D 8)) { @@ -335,6 +339,10 @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint3= 2_t reg_index) target_ulong cfg_val =3D 0; target_ulong val =3D 0; =20 +#if defined(TARGET_RISCV64) + reg_index >>=3D 1; +#endif + for (i =3D 0; i < sizeof(target_ulong); i++) { val =3D pmp_read_cfg(env, (reg_index * sizeof(target_ulong)) + i); cfg_val |=3D (val << (i * 8)); --=20 2.27.0 From nobody Sun May 19 05:00:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.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=1595581887; cv=none; d=zohomail.com; s=zohoarc; b=GBjEgNAB0p+sj7/R7tWsosHZ+T0kR7YO0kjT5bFZ7n9d/UW5y6PS1PQfglTslMXLXl1t6YLOALejwFI8C7d02zG4B0qkz4dGWNsJcRFpB+D/fGlcFHAUaoe/PJhniaJjPHC4GyYMc/MFXsnAy6iX//8cXfKTQxnwas1TAkUwBZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595581887; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4QaCAi9itYTAEWQbQQ1orCya0omL343c9jLTjKapu5Y=; b=k124Xk6hwPjz63reXfybrGG9Pv96/G7asg2qBhc3heK6tXdzL61lKufRGXgcOXoRLTHBk0FOytWNz55HdSLNMJ3PBO0g1SPAMvL/k1yhrQBClymHQJBhp1iRfdpbtun5nvawSXFeaj1voSLgdzvxXNOmrG3q7/raHPOM3LIriwM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1595581887695403.9729065828984; Fri, 24 Jul 2020 02:11:27 -0700 (PDT) Received: from localhost ([::1]:60330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jytji-00077J-HG for importer@patchew.org; Fri, 24 Jul 2020 05:11:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45738) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jytgx-0003Ew-SL for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:35 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:42406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jytgr-0003sG-9A for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:35 -0400 Received: by mail-pf1-x441.google.com with SMTP id 1so4730797pfn.9 for ; Fri, 24 Jul 2020 02:08:28 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id z10sm5751282pfr.90.2020.07.24.02.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 02:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4QaCAi9itYTAEWQbQQ1orCya0omL343c9jLTjKapu5Y=; b=eA4tkyEBCbQQuS+oqF1SxXFy+0RTxdJMDioXy0vYLE27UgnFMzbobCwc6IpJROm2VP AU8pN/RSysIQG1hajcsx0yxB4MxVpdYi60IgG1wXoKabBnnCsU/5LPxkXfYCb43V3lex ZZqZ4xlByEWwtBPq1aF9giXcGlp6WibmtgezP3Jx/AYCYo4/Sj8FhUoxqJSVwwse4B4H SIliwF4Pxw+AS2MMjrnXkQhWmg9KGGXJQ+s//BSOAzV7juVdafNhb9oX14mA6vZ0PJcG 2kAVb8D5BtQ5pn3lmK/tVomUA7StyhJ1mPrDaX3LNjhilKdNXlONXtBmDLrEDfrJHOuD JLwA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=4QaCAi9itYTAEWQbQQ1orCya0omL343c9jLTjKapu5Y=; b=qoAs7kYDzJmic/KC1tt7J+3E9RFAOV3m5IZ5X2tymkWyDf91hUFvrMc5rwcALQmaLn 25ubvuJ83eZunNrHO4KlEZ6iWOEDJWD1flrBGEe1Rgg0IlE1DWU4Hl9IZUBdPuuEqRl6 CRJGJOjMQwNVI3a9dCaB4Arj/Pwu1y+z6vrhyZy2aTNpDB2n7lxj6vBBazX7jmh497Fs Fy5h4YoKU7v3Tf1rKcxHdxiI+Lnb+j3qJo/rXzw9fv9fgbmQmiELJg6lDnLAJJPs0yd3 qKyl82SB62Cc9ETcBMn8qbjizWGtX1AO99P4Mz1T+uaPHBfnIWMyKGVoHFDVbtG9LBDp weaw== X-Gm-Message-State: AOAM532oBCHCLupFZCPP0w2ALrNGFhMbWOfr8aK/mbSKWx0d5GPUjgO/ CoOSuBzUNQOk7tulVO7yo9lnIVZ/d+U= X-Google-Smtp-Source: ABdhPJzm3Z2+Z3Mx0Im4J7zoNuXbRnryFhcJQ8Tv6/+a/HEKWtTFogn8wumdprZtnQFfnos6uualTw== X-Received: by 2002:aa7:91cd:: with SMTP id z13mr8309698pfa.133.1595581708000; Fri, 24 Jul 2020 02:08:28 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v4 3/4] target/riscv: Fix the translation of physical address Date: Fri, 24 Jul 2020 17:08:16 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=zong.li@sifive.com; helo=mail-pf1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Zong Li Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @sifive.com) Content-Type: text/plain; charset="utf-8" The real physical address should add the 12 bits page offset. It also causes the PMP wrong checking due to the minimum granularity of PMP is 4 byte, but we always get the physical address which is 4KB alignment, that means, we always use the start address of the page to check PMP for all addresses which in the same page. Signed-off-by: Zong Li --- target/riscv/cpu_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 75d2ae3434..08b069f0c9 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -543,7 +543,8 @@ restart: /* for superpage mappings, make a fake leaf PTE for the TLB's benefit. */ target_ulong vpn =3D addr >> PGSHIFT; - *physical =3D (ppn | (vpn & ((1L << ptshift) - 1))) << PGSHIFT; + *physical =3D ((ppn | (vpn & ((1L << ptshift) - 1))) << PGSHIF= T) | + (addr & ~TARGET_PAGE_MASK); =20 /* set permissions on the TLB entry */ if ((pte & PTE_R) || ((pte & PTE_X) && mxr)) { --=20 2.27.0 From nobody Sun May 19 05:00:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.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=1595581827; cv=none; d=zohomail.com; s=zohoarc; b=JE5kPXKyqSUNFnnyCLFhlF1u/wbL745akf9osNSWaw1qXjVpWhCXVTHFfqXrTNuA1FIhQPlPQ9LK2TkKfIcAraoyW2kPuB6wTG8oTdRid04IIPSZg9bRAd23N5pNkYs3bDZC2yZ2/w0fQ2KTdZAV8vN2hzBND7+RBBUywjMLjL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595581827; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Pc71QwKUTxcdbbb2mF5Hfr3ZbnXpr9ERBcMcGfZrI00=; b=U33p8AMAQEdMkqSkYtr58O4mRG/wqvrFPJAfudjiYZmAYbhiF+CwnEocnmjBRPAMq02QnGxSKzOa+Hggx2lk5NHph1YLezpHafzQVxuTPtSNqRgR2ydCAyXBOG11GpXNCZG/QCDWZ85kzs8Zd8n6xAsxmBFtOnz7pyGLE3Cd+Tg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.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 1595581827866339.66370598582034; Fri, 24 Jul 2020 02:10:27 -0700 (PDT) Received: from localhost ([::1]:57630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jytij-0005v3-LU for importer@patchew.org; Fri, 24 Jul 2020 05:10:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jytgv-000394-FN for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:33 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:40462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jytgt-0003si-5j for qemu-devel@nongnu.org; Fri, 24 Jul 2020 05:08:33 -0400 Received: by mail-pg1-x542.google.com with SMTP id n5so4880196pgf.7 for ; Fri, 24 Jul 2020 02:08:30 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id z10sm5751282pfr.90.2020.07.24.02.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 02:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pc71QwKUTxcdbbb2mF5Hfr3ZbnXpr9ERBcMcGfZrI00=; b=MX87ge4yURs1x2t1f/TigdUPhHB7zTe3UYnWD/41nbnxwjYposVkmVN/kHLKDXbW2P ZC0H5oNIj0DxeWIsytaoyrPe9k8/J0FfVJUgjDZa+NOdO5KwgNU32BsODRfowBIw3ogJ Hs0lfcAU7rlCYy9c3Slw9rldES32TdCHZ/mQ46IzKu4Tss3k91WWwt1kH75TmRo/+FHC bK16Ixc+AHt4YageiaWueQSVf2WsRne0gzISSkacCQuCvxMe5u1i3ZxxtnVEdc51PkSC txhKUW78+0Q54WGP8lkA1MOmj3GdkxDkqUMraaaetUGwIPeb+uIyH0wh9gKREmlC8OWj AISA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pc71QwKUTxcdbbb2mF5Hfr3ZbnXpr9ERBcMcGfZrI00=; b=DZ5x41uZSFUqqs9NnUrne5m9ZgO9EHT79GEPTPZJ/tsY0MXX/AlOAy74jSHGIqMSJi GDzCXpkVbhWx/5N23tbtRLiSqlJpiytm1978AaRN0gedX6wAVlQ6Nme2wAfLgPTrSxgn 2LhxEVSD54oVSofgb+2sSYU4u7LuW3r8eAP2AuPEZuuQSfWgp6ypxyo1W2Qtbf4P38Em W4vIdgtjfQePZk+alpXlM1uzJ/QyP2QG4JBOZRgHtIbi+vvHlcOwZcBRkeY+G8k4evid 7/ziGpPLJ0JR8HvuMGxZZFo00o+ZcJRvs0AaJoSKtHlFClEP6WHzQSyFWICptqJIwuzD MsQg== X-Gm-Message-State: AOAM532Upe2VFYSeryeplBOux+JcbKaRpgii9imfIscC9kpPoxHa/986 H1/i+uXN8Q+xg3lQ38akOpOtNQ== X-Google-Smtp-Source: ABdhPJzE76Ie2N+kBXXB4nvSEW7/ZTwW4Gl7KZgvf5uDi1tJV5dVrc/8mhYPbyDH+tb8ze/eCZNzaQ== X-Received: by 2002:a62:b409:: with SMTP id h9mr7806369pfn.305.1595581709859; Fri, 24 Jul 2020 02:08:29 -0700 (PDT) From: Zong Li To: palmer@dabbelt.com, Alistair.Francis@wdc.com, bmeng.cn@gmail.com, sagark@eecs.berkeley.edu, kbastian@mail.uni-paderborn.de, qemu-riscv@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v4 4/4] target/riscv: Change the TLB page size depends on PMP entries. Date: Fri, 24 Jul 2020 17:08:17 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::542; envelope-from=zong.li@sifive.com; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Zong Li Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @sifive.com) Content-Type: text/plain; charset="utf-8" The minimum granularity of PMP is 4 bytes, it is small than 4KB page size, therefore, the pmp checking would be ignored if its range doesn't start from the alignment of one page. This patch detects the pmp entries and sets the small page size to TLB if there is a PMP entry which cover the page size. Signed-off-by: Zong Li --- target/riscv/cpu_helper.c | 10 ++++++-- target/riscv/pmp.c | 52 +++++++++++++++++++++++++++++++++++++++ target/riscv/pmp.h | 2 ++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 08b069f0c9..b3013bc91e 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -693,6 +693,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, bool first_stage_error =3D true; int ret =3D TRANSLATE_FAIL; int mode =3D mmu_idx; + target_ulong tlb_size =3D 0; =20 env->guest_phys_fault_addr =3D 0; =20 @@ -784,8 +785,13 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, i= nt size, } =20 if (ret =3D=3D TRANSLATE_SUCCESS) { - tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK, - prot, mmu_idx, TARGET_PAGE_SIZE); + if (pmp_is_range_in_tlb(env, pa & TARGET_PAGE_MASK, &tlb_size)) { + tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - = 1), + prot, mmu_idx, tlb_size); + } else { + tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_= MASK, + prot, mmu_idx, TARGET_PAGE_SIZE); + } return true; } else if (probe) { return false; diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index e0161d6aab..a040cdd285 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -392,3 +392,55 @@ target_ulong pmpaddr_csr_read(CPURISCVState *env, uint= 32_t addr_index) =20 return val; } + +/* + * Calculate the TLB size if the start address or the end address of + * PMP entry is presented in thie TLB page. + */ +static target_ulong pmp_get_tlb_size(CPURISCVState *env, int pmp_index, + target_ulong tlb_sa, target_ulong tlb_ea) +{ + target_ulong pmp_sa =3D env->pmp_state.addr[pmp_index].sa; + target_ulong pmp_ea =3D env->pmp_state.addr[pmp_index].ea; + + if (pmp_sa >=3D tlb_sa && pmp_ea <=3D tlb_ea) { + return pmp_ea - pmp_sa + 1; + } + + if (pmp_sa >=3D tlb_sa && pmp_sa <=3D tlb_ea && pmp_ea >=3D tlb_ea) { + return tlb_ea - pmp_sa + 1; + } + + if (pmp_ea <=3D tlb_ea && pmp_ea >=3D tlb_sa && pmp_sa <=3D tlb_sa) { + return pmp_ea - tlb_sa + 1; + } + + return 0; +} + +/* + * Check is there a PMP entry whcih range covers this page. If so, + * try to find the minimum granularity for the TLB size. + */ +bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, + target_ulong *tlb_size) +{ + int i; + target_ulong val; + target_ulong tlb_ea =3D (tlb_sa + TARGET_PAGE_SIZE - 1); + + for (i =3D 0; i < MAX_RISCV_PMPS; i++) { + val =3D pmp_get_tlb_size(env, i, tlb_sa, tlb_ea); + if (val) { + if (*tlb_size =3D=3D 0 || *tlb_size > val) { + *tlb_size =3D val; + } + } + } + + if (*tlb_size !=3D 0) { + return true; + } + + return false; +} diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h index 8e19793132..c70f2ea4c4 100644 --- a/target/riscv/pmp.h +++ b/target/riscv/pmp.h @@ -60,5 +60,7 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_= index, target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, target_ulong size, pmp_priv_t priv, target_ulong mode); +bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, + target_ulong *tlb_size); =20 #endif --=20 2.27.0