From nobody Fri May 3 14:59:11 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; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1569413187; cv=none; d=zoho.com; s=zohoarc; b=Qh2PkAO6Sx1UkiMeDWivmL18uJkNj5CzrlPAwlw3HI6PiqX1JW6FE7Kr+zdZ4hTCmZSj/+v7GEqAqoV5BQa2Doy6sLBukNDX3js43qTpBcovsB0mTyiSkSfDDzzAs7olUh3AGuVUh+bdr645FtkxHThO5kq9M9c5vhUYuWHBplE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569413187; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=5zL/sH4Ajpd8YJOnDLOPbkoz4X+zIrxMdd/qewXlBTg=; b=HTx0oIf+1I61Xv650P6NSbXPhyS8xE80fAZfq/2DrVn4Y5ulpkipnENrCJI5MBBMBRRyNeLmLrCXgzMh330duB6jFUzFOblE4Z976/B6R3aZ9BjxCuO38fb9sxm+V5277tnTGLxHuMOas8jurVqMwLenwslcGGeQaxWrcYuQ8w4= 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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 156941318742677.42110432121376; Wed, 25 Sep 2019 05:06:27 -0700 (PDT) Received: from localhost ([::1]:49126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iD63n-0003la-1j for importer@patchew.org; Wed, 25 Sep 2019 08:06:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52109) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iD62z-0003GZ-HE for qemu-devel@nongnu.org; Wed, 25 Sep 2019 08:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iD62y-0004Ef-Bs for qemu-devel@nongnu.org; Wed, 25 Sep 2019 08:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:37566) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iD62y-0004EX-6q; Wed, 25 Sep 2019 08:05:28 -0400 Received: from guoren-Inspiron-7460.lan (unknown [223.93.147.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C756F21D7E; Wed, 25 Sep 2019 12:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569413127; bh=RymcLTzDRHd3IS+crgKJC/SWyf0bAdWMAU14Lt5SOxw=; h=From:To:Cc:Subject:Date:From; b=fs8BMP7nlVaML+AjwfP8XJ+pfFhGPbOXjnF97ksMBn+FRnwT9jfXKnFIgpvqc/hm7 KXs94LEhS5sy6QReB9oqrQNREolOvK3NgGvbxf0DENV7okpp72gLlPobgtYAV2IvWc w7xnS4LW8+eoJwF5KsKvcrr/njO5RwjIHEC0Oeik= From: guoren@kernel.org To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH V5] target/riscv: Ignore reserved bits in PTE for RV64 Date: Wed, 25 Sep 2019 20:04:59 +0800 Message-Id: <1569413099-6859-1-git-send-email-guoren@kernel.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 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: alistair23@gmail.com, palmer@sifive.com, alistair.francis@wdc.com, Guo Ren , bmeng.cn@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Guo Ren Highest 10 bits of PTE are reserved in riscv-privileged, ref: [1], so we need to ignore them. They cannot be a part of ppn. 1: The RISC-V Instruction Set Manual, Volume II: Privileged Architecture 4.4 Sv39: Page-Based 39-bit Virtual-Memory System 4.5 Sv48: Page-Based 48-bit Virtual-Memory System Signed-off-by: Guo Ren Tested-by: Bin Meng Reviewed-by: Liu Zhiwei Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 7 +++++++ target/riscv/cpu_helper.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) Changelog V5: - Update Reviewer and Tester. Changelog V4: - Change title to Ignore not Bugfix - Use PTE_PPN_MASK for RV32 and RV64 Changelog V3: - Use UUL define for PTE_RESERVED - Keep ppn >> PTE_PPN_SHIFT Changelog V2: - Bugfix pte destroyed cause boot fail - Change to AND with a mask instead of shifting both directions diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index e998348..399c2c6 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -473,6 +473,13 @@ /* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10 =20 +/* Page table PPN mask */ +#if defined(TARGET_RISCV32) +#define PTE_PPN_MASK 0xffffffffUL +#elif defined(TARGET_RISCV64) +#define PTE_PPN_MASK 0x3fffffffffffffULL +#endif + /* Leaf page shift amount */ #define PGSHIFT 12 =20 diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 87dd6a6..9961b37 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -261,7 +261,7 @@ restart: #elif defined(TARGET_RISCV64) target_ulong pte =3D ldq_phys(cs->as, pte_addr); #endif - hwaddr ppn =3D pte >> PTE_PPN_SHIFT; + hwaddr ppn =3D (pte & PTE_PPN_MASK) >> PTE_PPN_SHIFT; =20 if (!(pte & PTE_V)) { /* Invalid PTE */ --=20 2.7.4