From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585561884; cv=none; d=zohomail.com; s=zohoarc; b=VnNTbVK4aexr5l3whDq9q0qFWuYGgMKKDyoAaSZcvgNwWlj09AoDEGFLuuzfcBGlw48kkifiSHgP2zuyYaE+PoITVbosjwEa6SOY335XuqNza41ZwGXaxFQYnbWTOtVXVfTbFcaZyv+RkujeY6K/xJXZim043KrtyPms7LuI1oM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585561884; h=Content-Type: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=o6vxDz2prFDagIogES5n5y7dnXQM96Utcey8nRaF0jI=; b=e0v4pICuuJbbOdOQzL/2ZKnWfdIjMPm04yOIfydK3yNJgrdSHRM1BppG3TDjjL41re0LEj6gfri6jsJWLH5IFhZPx+4axZLUOX1z2DWVtAVt7LaueNvrEwJW3YHQRh6ErxJSA5SsXhFssuczNvXjCPI83S2JYE/20ufO3q6WBnc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585561884788176.19476540279493; Mon, 30 Mar 2020 02:51:24 -0700 (PDT) Received: from localhost ([::1]:47180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr4l-0002Fx-Ei for importer@patchew.org; Mon, 30 Mar 2020 05:51:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42753) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr3d-0000Sy-D6 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr3b-0005Z0-Sh for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:13 -0400 Received: from 2.mo3.mail-out.ovh.net ([46.105.75.36]:36731) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr3b-0005Y6-Nf for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:11 -0400 Received: from player729.ha.ovh.net (unknown [10.108.57.95]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 76AEB2492BB for ; Mon, 30 Mar 2020 11:50:09 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id D6378110F506B; Mon, 30 Mar 2020 09:49:58 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 1/7] target/ppc: Enforce that the root page directory size must be at least 5 Date: Mon, 30 Mar 2020 11:49:40 +0200 Message-Id: <20200330094946.24678-2-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13893886326575696870 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.75.36 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Suraj Jitindar Singh According to the ISA the root page directory size of a radix tree for either process- or partition-scoped translation must be >=3D 5. Thus add this to the list of conditions checked when validating the partition table entry in validate_pate(); Signed-off-by: Suraj Jitindar Singh Reviewed-by: David Gibson Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- target/ppc/mmu-radix64.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 224e646c5094..99678570581b 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -212,6 +212,9 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpi= d, ppc_v3_pate_t *pate) if (lpid =3D=3D 0 && !msr_hv) { return false; } + if ((pate->dw0 & PATE1_R_PRTS) < 5) { + return false; + } /* More checks ... */ return true; } --=20 2.21.1 From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585561887; cv=none; d=zohomail.com; s=zohoarc; b=j+qmEvpV/+x40rr2wsINfg4mOPOUmd1fjfN8GH1EL80Pjd7zCOJfy2GaMDprGIezZusVcBUqeDFBeuWqA86zvSjNBRZhMk6tStgGNCz9YTMOnrfbiiqy7ZndL435ziGWD/khlozPP5BhPT5+x2cJC1jLYj/S6eMXdX2ZGeQhLso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585561887; h=Content-Type: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=K1uoixSjIXU3DdLhuj0uhfhBG5fr4BsL3AvCdVn/Qbo=; b=NL0O1ogTlcDxoLOhhBIkTHpLFNgkIKmwM9pyPpemJOt6Gok27uzw39uxaiFSAc3vmumIRjYu4PtmeM5m+dchm18jX3yr30azEt8XoGv8pcvaMp8beT0+nGyQE7Gmy1ojfEaCg7J4l7GiqmwBUc6AbA+WdcKtmLpLP7dF9XqOOmY= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585561887629816.4101651927855; Mon, 30 Mar 2020 02:51:27 -0700 (PDT) Received: from localhost ([::1]:47182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr4o-0002Ov-Bz for importer@patchew.org; Mon, 30 Mar 2020 05:51:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42792) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr3m-0000ko-2j for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr3l-0005dy-1X for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:21 -0400 Received: from 1.mo1.mail-out.ovh.net ([178.32.127.22]:57492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr3k-0005d3-Rh for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:20 -0400 Received: from player729.ha.ovh.net (unknown [10.108.54.59]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id CA37C1B866A for ; Mon, 30 Mar 2020 11:50:18 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id 1A727110F5181; Mon, 30 Mar 2020 09:50:09 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 2/7] target/ppc: Introduce a relocation bool in ppc_radix64_handle_mmu_fault() Date: Mon, 30 Mar 2020 11:49:41 +0200 Message-Id: <20200330094946.24678-3-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13896419601875373030 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.32.127.22 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It will ease the introduction of new routines for partition-scoped Radix translation. Signed-off-by: Suraj Jitindar Singh Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- target/ppc/mmu-radix64.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 99678570581b..f6007e956569 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -229,12 +229,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vad= dr eaddr, int rwx, uint64_t lpid =3D 0, pid =3D 0, offset, size, prtbe0, pte; int page_size, prot, fault_cause =3D 0; ppc_v3_pate_t pate; + bool relocation; =20 assert((rwx =3D=3D 0) || (rwx =3D=3D 1) || (rwx =3D=3D 2)); =20 + relocation =3D ((rwx =3D=3D 2) && (msr_ir =3D=3D 1)) || ((rwx !=3D 2) = && (msr_dr =3D=3D 1)); /* HV or virtual hypervisor Real Mode Access */ - if ((msr_hv || cpu->vhyp) && - (((rwx =3D=3D 2) && (msr_ir =3D=3D 0)) || ((rwx !=3D 2) && (msr_dr= =3D=3D 0)))) { + if (!relocation && (msr_hv || cpu->vhyp)) { /* In real mode top 4 effective addr bits (mostly) ignored */ raddr =3D eaddr & 0x0FFFFFFFFFFFFFFFULL; =20 --=20 2.21.1 From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585562003; cv=none; d=zohomail.com; s=zohoarc; b=coJiq9it2eGenXIvqceX0bfSPrLuZq/Ty1rMrd2Sxkz2pW+OnGbrqBHGCQzpS7oLVov1N81X15vvE1KXg29RvlISESLUETB0mWzloUBtz1FPFGLbFRNrjJu7C0bF7osDx1k7KBN7tewYUpQ76DQ/tlv8qm50Q7qtelYXWwgTWfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585562003; h=Content-Type: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=QynI+3srlfFChyrsqm2tLXECY8UH689xis9WJ2c98RU=; b=cb4KRTYWF1b1cnL7CisTm2a6DFxe07EmnbYvJAqosAQ2DN/6oaWOoMXyTBk3spZvghd168VZRhMRk9kUHYhEYOSTGyq79Qou5mdImpwA0kwN0owot7wHRA++JGBZ2W9Jb8hQFwW7U55tyww9ESkG3/3NOeV5tc+eX9JyWKrrbhQ= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585562003494689.7914160712412; Mon, 30 Mar 2020 02:53:23 -0700 (PDT) Received: from localhost ([::1]:47212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr6g-0005h7-4m for importer@patchew.org; Mon, 30 Mar 2020 05:53:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42821) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr3t-00010u-Ad for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr3s-0005iC-Cj for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:29 -0400 Received: from 9.mo173.mail-out.ovh.net ([46.105.72.44]:47441) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr3s-0005hR-6s for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:28 -0400 Received: from player729.ha.ovh.net (unknown [10.108.42.167]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id 0F08A13439E for ; Mon, 30 Mar 2020 11:50:25 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id 6830B110F51FD; Mon, 30 Mar 2020 09:50:18 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 3/7] target/ppc: Assert if HV mode is set when running under a pseries machine Date: Mon, 30 Mar 2020 11:49:42 +0200 Message-Id: <20200330094946.24678-4-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13898389928626523110 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.72.44 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Suraj Jitindar Singh Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- target/ppc/mmu-radix64.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index f6007e956569..d2422d1c54c9 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -231,6 +231,7 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr= eaddr, int rwx, ppc_v3_pate_t pate; bool relocation; =20 + assert(!(msr_hv && cpu->vhyp)); assert((rwx =3D=3D 0) || (rwx =3D=3D 1) || (rwx =3D=3D 2)); =20 relocation =3D ((rwx =3D=3D 2) && (msr_ir =3D=3D 1)) || ((rwx !=3D 2) = && (msr_dr =3D=3D 1)); --=20 2.21.1 From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585561926; cv=none; d=zohomail.com; s=zohoarc; b=boEAkC/+O1D+HoFB96Y9KleXfuh39EucHjOpWUu8Pai7oJ1UPvRRaixYr9lkvLhcUeroY4lW9VW6iger+nxkdg1H8hsGPpPBr3zPkgOePEGaxYzxWxASUg+njznITqdT+fBCMrDFTK3dGencoT1fcRPZ+PiKf1hpR0kWR9PHLQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585561926; h=Content-Type: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=uy+q3G193vHOqlzIiVrfZdUC9dCyPBF3s93FpG/Hjus=; b=a+Cizp2hAY08SAKNQEbbccixji5XTD6x3g+cq7EwlIZkwSU4+EOgvRPzHbNcBJbsMTgnGqIDE1NqP03VQ1Ke/2C4fRenYLcil7yCSw1oKGNZcoCgnaHd3gqqmW5lQTPSFSFgsapwd001ZaUiFvaeM8024SJCRmLfnCQ29NjGrlE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585561926194600.7153657674578; Mon, 30 Mar 2020 02:52:06 -0700 (PDT) Received: from localhost ([::1]:47184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr5Q-0003A8-Qv for importer@patchew.org; Mon, 30 Mar 2020 05:52:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42857) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr43-0001Ow-He for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr41-0005p7-N9 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:39 -0400 Received: from 2.mo179.mail-out.ovh.net ([178.33.250.45]:42545) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr41-0005oN-GX for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:37 -0400 Received: from player729.ha.ovh.net (unknown [10.110.103.18]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id C3982157BAB for ; Mon, 30 Mar 2020 11:50:35 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id BB836110F524E; Mon, 30 Mar 2020 09:50:25 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 4/7] target/ppc: Introduce ppc_radix64_xlate() for Radix tree translation Date: Mon, 30 Mar 2020 11:49:43 +0200 Message-Id: <20200330094946.24678-5-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13901204675824749542 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.33.250.45 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This is moving code under a new ppc_radix64_xlate() routine shared by the MMU Radix page fault handler and the get_phys_page_debug PPC callback. The difference being that get_phys_page_debug does not generate exceptions. The specific part of process-scoped Radix translation is moved under ppc_radix64_process_scoped_xlate() in preparation of the future support for partition-scoped Radix translation. It should be functionally equivalent. Signed-off-by: Suraj Jitindar Singh Signed-off-by: C=C3=A9dric Le Goater --- target/ppc/mmu-radix64.c | 201 ++++++++++++++++++++++----------------- 1 file changed, 116 insertions(+), 85 deletions(-) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index d2422d1c54c9..b4e6abcd2d35 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -219,17 +219,119 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t = lpid, ppc_v3_pate_t *pate) return true; } =20 +static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, + vaddr eaddr, uint64_t lpid, uint64_t= pid, + ppc_v3_pate_t pate, hwaddr *g_raddr, + int *g_prot, int *g_page_size, + bool cause_excp) +{ + CPUState *cs =3D CPU(cpu); + uint64_t offset, size, prtbe_addr, prtbe0, pte; + int fault_cause =3D 0; + hwaddr pte_addr; + + /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ + offset =3D pid * sizeof(struct prtb_entry); + size =3D 1ULL << ((pate.dw1 & PATE1_R_PRTS) + 12); + if (offset >=3D size) { + /* offset exceeds size of the process table */ + if (cause_excp) { + ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); + } + return 1; + } + prtbe_addr =3D (pate.dw1 & PATE1_R_PRTB) + offset; + prtbe0 =3D ldq_phys(cs->as, prtbe_addr); + + /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ + *g_page_size =3D PRTBE_R_GET_RTS(prtbe0); + pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, + prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, + g_raddr, g_page_size, &fault_cause, &pte_a= ddr); + + if (!(pte & R_PTE_VALID) || + ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, g_prot)) { + /* No valid pte or access denied due to protection */ + if (cause_excp) { + ppc_radix64_raise_si(cpu, rwx, eaddr, fault_cause); + } + return 1; + } + + ppc_radix64_set_rc(cpu, rwx, pte, pte_addr, g_prot); + + return 0; +} + +static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, + uint64_t lpid, uint64_t pid, bool relocation, + hwaddr *raddr, int *psizep, int *protp, + bool cause_excp) +{ + ppc_v3_pate_t pate; + int psize, prot; + hwaddr g_raddr; + + *psizep =3D INT_MAX; + *protp =3D PAGE_READ | PAGE_WRITE | PAGE_EXEC; + + /* Get Process Table */ + if (cpu->vhyp && lpid =3D=3D 0) { + PPCVirtualHypervisorClass *vhc; + vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + vhc->get_pate(cpu->vhyp, &pate); + } else { + if (!ppc64_v3_get_pate(cpu, lpid, &pate)) { + if (cause_excp) { + ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); + } + return 1; + } + if (!validate_pate(cpu, lpid, &pate)) { + if (cause_excp) { + ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_R_BADCONFIG); + } + return 1; + } + /* We don't support guest mode yet */ + if (lpid !=3D 0) { + error_report("PowerNV guest support Unimplemented"); + exit(1); + } + } + + /* + * Perform process-scoped translation if relocation enabled. + * + * - Translates an effective address to a host real address in + * quadrants 0 and 3 when HV=3D1. + */ + if (relocation) { + int ret =3D ppc_radix64_process_scoped_xlate(cpu, rwx, eaddr, lpid= , pid, + pate, &g_raddr, &prot, + &psize, cause_excp); + if (ret) { + return ret; + } + *psizep =3D MIN(*psizep, psize); + *protp &=3D prot; + } else { + g_raddr =3D eaddr & R_EADDR_MASK; + } + + *raddr =3D g_raddr; + return 0; +} + int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr eaddr, int rwx, int mmu_idx) { CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; - PPCVirtualHypervisorClass *vhc; - hwaddr raddr, pte_addr; - uint64_t lpid =3D 0, pid =3D 0, offset, size, prtbe0, pte; - int page_size, prot, fault_cause =3D 0; - ppc_v3_pate_t pate; + uint64_t lpid =3D 0, pid =3D 0; + int page_size, prot; bool relocation; + hwaddr raddr; =20 assert(!(msr_hv && cpu->vhyp)); assert((rwx =3D=3D 0) || (rwx =3D=3D 1) || (rwx =3D=3D 2)); @@ -268,48 +370,11 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vad= dr eaddr, int rwx, return 1; } =20 - /* Get Process Table */ - if (cpu->vhyp) { - vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); - vhc->get_pate(cpu->vhyp, &pate); - } else { - if (!ppc64_v3_get_pate(cpu, lpid, &pate)) { - ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); - return 1; - } - if (!validate_pate(cpu, lpid, &pate)) { - ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_R_BADCONFIG); - } - /* We don't support guest mode yet */ - if (lpid !=3D 0) { - error_report("PowerNV guest support Unimplemented"); - exit(1); - } - } - - /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ - offset =3D pid * sizeof(struct prtb_entry); - size =3D 1ULL << ((pate.dw1 & PATE1_R_PRTS) + 12); - if (offset >=3D size) { - /* offset exceeds size of the process table */ - ppc_radix64_raise_si(cpu, rwx, eaddr, DSISR_NOPTE); + /* Translate eaddr to raddr (where raddr is addr qemu needs for access= ) */ + if (ppc_radix64_xlate(cpu, eaddr, rwx, lpid, pid, relocation, &raddr, + &page_size, &prot, 1)) { return 1; } - prtbe0 =3D ldq_phys(cs->as, (pate.dw1 & PATE1_R_PRTB) + offset); - - /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =3D PRTBE_R_GET_RTS(prtbe0); - pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, - prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, - &raddr, &page_size, &fault_cause, &pte_add= r); - if (!pte || ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, &prot)= ) { - /* Couldn't get pte or access denied due to protection */ - ppc_radix64_raise_si(cpu, rwx, eaddr, fault_cause); - return 1; - } - - /* Update Reference and Change Bits */ - ppc_radix64_set_rc(cpu, rwx, pte, pte_addr, &prot); =20 tlb_set_page(cs, eaddr & TARGET_PAGE_MASK, raddr & TARGET_PAGE_MASK, prot, mmu_idx, 1UL << page_size); @@ -318,16 +383,13 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vad= dr eaddr, int rwx, =20 hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu, target_ulong eaddr) { - CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; - PPCVirtualHypervisorClass *vhc; - hwaddr raddr, pte_addr; - uint64_t lpid =3D 0, pid =3D 0, offset, size, prtbe0, pte; - int page_size, fault_cause =3D 0; - ppc_v3_pate_t pate; + uint64_t lpid =3D 0, pid =3D 0; + int psize, prot; + hwaddr raddr; =20 /* Handle Real Mode */ - if (msr_dr =3D=3D 0) { + if ((msr_dr =3D=3D 0) && (msr_hv || (cpu->vhyp && lpid =3D=3D 0))) { /* In real mode top 4 effective addr bits (mostly) ignored */ return eaddr & 0x0FFFFFFFFFFFFFFFULL; } @@ -337,39 +399,8 @@ hwaddr ppc_radix64_get_phys_page_debug(PowerPCCPU *cpu= , target_ulong eaddr) return -1; } =20 - /* Get Process Table */ - if (cpu->vhyp) { - vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); - vhc->get_pate(cpu->vhyp, &pate); - } else { - if (!ppc64_v3_get_pate(cpu, lpid, &pate)) { - return -1; - } - if (!validate_pate(cpu, lpid, &pate)) { - return -1; - } - /* We don't support guest mode yet */ - if (lpid !=3D 0) { - error_report("PowerNV guest support Unimplemented"); - exit(1); - } - } - - /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ - offset =3D pid * sizeof(struct prtb_entry); - size =3D 1ULL << ((pate.dw1 & PATE1_R_PRTS) + 12); - if (offset >=3D size) { - /* offset exceeds size of the process table */ - return -1; - } - prtbe0 =3D ldq_phys(cs->as, (pate.dw1 & PATE1_R_PRTB) + offset); - - /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ - page_size =3D PRTBE_R_GET_RTS(prtbe0); - pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, - prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, - &raddr, &page_size, &fault_cause, &pte_add= r); - if (!pte) { + if (ppc_radix64_xlate(cpu, eaddr, 0, lpid, pid, msr_dr, &raddr, &psize, + &prot, 0)) { return -1; } =20 --=20 2.21.1 From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585562021; cv=none; d=zohomail.com; s=zohoarc; b=WI81gqJh/IKmPdTASwrFkJGCjry1D/dlyZm8zULxRx9FWNA1tPa9R0sF72Hr32hjl4Ilqmj55BFxSU9CdVISrX11pd1tU1fyxrfLBmXElMJCx8lqA9kQ+vadHNu0nN8kZfAPLYNNGyGKE+6H8NajQqLSdCLStyrZ2+Hp6/PLLas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585562021; h=Content-Type: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=yn0q6VpvqyLSRZIypfF2fuRzI35FvKG2uNtON+GyuTY=; b=nZDacivd5YCg5RRwLx2IRMTMBLZfY49euMs7+o5Uo36GXrCj5XZkjoenR/UmsvleJlfu4RrvPWEO1AkK8XfHrDRRb9vAQD4IDxO6FGqKa73bEj7U1BpjK/C1vbo+IAuhF/HhTF05BeSDN17dqyZODmNfTw+sBd7WDWCaCCzPv1E= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585562021810126.48735158500688; Mon, 30 Mar 2020 02:53:41 -0700 (PDT) Received: from localhost ([::1]:47216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr6y-0006Ky-Hr for importer@patchew.org; Mon, 30 Mar 2020 05:53:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42898) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr4C-0001jY-CO for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr4B-0005yA-4O for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:48 -0400 Received: from 10.mo173.mail-out.ovh.net ([46.105.74.148]:55439) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr4A-0005xK-UR for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:47 -0400 Received: from player729.ha.ovh.net (unknown [10.110.115.229]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id 318621362F6 for ; Mon, 30 Mar 2020 11:50:45 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id 5F365110F5312; Mon, 30 Mar 2020 09:50:35 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 5/7] target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation Date: Mon, 30 Mar 2020 11:49:44 +0200 Message-Id: <20200330094946.24678-6-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13904019426076888038 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.74.148 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The ppc_radix64_walk_tree() routine walks through the nested radix tables to look for a PTE. Split it two and introduce a new routine ppc_radix64_next_level() which we will use for partition-scoped Radix translation when translating the process tree addresses. Signed-off-by: Suraj Jitindar Singh Signed-off-by: C=C3=A9dric Le Goater --- target/ppc/mmu-radix64.c | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index b4e6abcd2d35..136498111f60 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -162,44 +162,60 @@ static void ppc_radix64_set_rc(PowerPCCPU *cpu, int r= wx, uint64_t pte, } } =20 -static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr, - uint64_t base_addr, uint64_t nls, - hwaddr *raddr, int *psize, - int *fault_cause, hwaddr *pte_addr) +static uint64_t ppc_radix64_next_level(PowerPCCPU *cpu, vaddr eaddr, + uint64_t *pte_addr, uint64_t *nls, + int *psize, int *fault_cause) { CPUState *cs =3D CPU(cpu); uint64_t index, pde; =20 - if (nls < 5) { /* Directory maps less than 2**5 entries */ + if (*nls < 5) { /* Directory maps less than 2**5 entries */ *fault_cause |=3D DSISR_R_BADCONFIG; return 0; } =20 /* Read page entry from guest address space */ - index =3D eaddr >> (*psize - nls); /* Shift */ - index &=3D ((1UL << nls) - 1); /* Mask */ - pde =3D ldq_phys(cs->as, base_addr + (index * sizeof(pde))); - if (!(pde & R_PTE_VALID)) { /* Invalid Entry */ + pde =3D ldq_phys(cs->as, *pte_addr); + if (!(pde & R_PTE_VALID)) { /* Invalid Entry */ *fault_cause |=3D DSISR_NOPTE; return 0; } =20 - *psize -=3D nls; + *psize -=3D *nls; + if (!(pde & R_PTE_LEAF)) { /* Prepare for next iteration */ + *nls =3D pde & R_PDE_NLS; + index =3D eaddr >> (*psize - *nls); /* Shift */ + index &=3D ((1UL << *nls) - 1); /* Mask */ + *pte_addr =3D (pde & R_PDE_NLB) + (index * sizeof(pde)); + } + return pde; +} + +static uint64_t ppc_radix64_walk_tree(PowerPCCPU *cpu, vaddr eaddr, + uint64_t base_addr, uint64_t nls, + hwaddr *raddr, int *psize, + int *fault_cause, hwaddr *pte_addr) +{ + uint64_t index, pde; + + index =3D eaddr >> (*psize - nls); /* Shift */ + index &=3D ((1UL << nls) - 1); /* Mask */ + *pte_addr =3D base_addr + (index * sizeof(pde)); + do { + pde =3D ppc_radix64_next_level(cpu, eaddr, pte_addr, &nls, psize, + fault_cause); + } while ((pde & R_PTE_VALID) && !(pde & R_PTE_LEAF)); =20 - /* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ - if (pde & R_PTE_LEAF) { + /* Did we find a valid leaf? */ + if ((pde & R_PTE_VALID) && (pde & R_PTE_LEAF)) { uint64_t rpn =3D pde & R_PTE_RPN; uint64_t mask =3D (1UL << *psize) - 1; =20 /* Or high bits of rpn and low bits to ea to form whole real addr = */ *raddr =3D (rpn & ~mask) | (eaddr & mask); - *pte_addr =3D base_addr + (index * sizeof(pde)); - return pde; } =20 - /* Next Level of Radix Tree */ - return ppc_radix64_walk_tree(cpu, eaddr, pde & R_PDE_NLB, pde & R_PDE_= NLS, - raddr, psize, fault_cause, pte_addr); + return pde; } =20 static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *p= ate) --=20 2.21.1 From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585562104; cv=none; d=zohomail.com; s=zohoarc; b=N2Cmf3c9ovIpsCb6TbwVxdLb7RCNKqqqT3ftNjXAVMxxH7qn2T8M7Eg/iJbDaMciwF4mDgQLCAJ+aqFue5HjDtvZWqrWV5UjahBMOhvKuDwOrv4P1oPKoosAY5RnmUUJAnaUHDWCAm6oIIp9ulpZn0daO4IayX52nQFXOyvgkcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585562104; h=Content-Type: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=luAt5mDb+6nfliE+d45Ree2bhHkM04Z91PfIH3F2yX0=; b=iHJ6+kDBa0dT+z7odQGyVZz19VUBjzEQjSVrF2X6dqZVOXI4SaShCFak/Z9iNrdXgSoc9GdEcSnj3CPN1fmeAsyHF2Z23HPgb08n9Q26YK9yNKr//noxsyTVVMeao533/Etuw1m+B7wPGp1nq8gb22SBftljXUgRF8vY9DbAwM8= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585562104143375.76059804768533; Mon, 30 Mar 2020 02:55:04 -0700 (PDT) Received: from localhost ([::1]:47262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr8I-0008G5-UE for importer@patchew.org; Mon, 30 Mar 2020 05:55:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42935) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr4L-00027Q-P7 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr4K-00062r-Ma for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:57 -0400 Received: from 2.mo173.mail-out.ovh.net ([178.33.251.49]:50479) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr4K-00062B-Gp for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:50:56 -0400 Received: from player729.ha.ovh.net (unknown [10.110.115.233]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id DF7EE1369B5 for ; Mon, 30 Mar 2020 11:50:54 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id 230D0110F53DC; Mon, 30 Mar 2020 09:50:45 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 6/7] target/ppc: Extend ppc_radix64_check_prot() with a 'partition_scoped' bool Date: Mon, 30 Mar 2020 11:49:45 +0200 Message-Id: <20200330094946.24678-7-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13906552701059697638 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.33.251.49 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This prepares ground for partition-scoped Radix translation. Signed-off-by: Suraj Jitindar Singh Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- target/ppc/mmu-radix64.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 136498111f60..3ae29ed90d49 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -105,7 +105,8 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int r= wx, vaddr eaddr, =20 =20 static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, - int *fault_cause, int *prot) + int *fault_cause, int *prot, + bool partition_scoped) { CPUPPCState *env =3D &cpu->env; const int need_prot[] =3D { PAGE_READ, PAGE_WRITE, PAGE_EXEC }; @@ -121,11 +122,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, i= nt rwx, uint64_t pte, } =20 /* Determine permissions allowed by Encoded Access Authority */ - if ((pte & R_PTE_EAA_PRIV) && msr_pr) { /* Insufficient Privilege */ + if (!partition_scoped && (pte & R_PTE_EAA_PRIV) && msr_pr) { *prot =3D 0; - } else if (msr_pr || (pte & R_PTE_EAA_PRIV)) { + } else if (msr_pr || (pte & R_PTE_EAA_PRIV) || partition_scoped) { *prot =3D ppc_radix64_get_prot_eaa(pte); - } else { /* !msr_pr && !(pte & R_PTE_EAA_PRIV) */ + } else { /* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */ *prot =3D ppc_radix64_get_prot_eaa(pte); *prot &=3D ppc_radix64_get_prot_amr(cpu); /* Least combined permis= sions */ } @@ -266,7 +267,7 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU = *cpu, int rwx, g_raddr, g_page_size, &fault_cause, &pte_a= ddr); =20 if (!(pte & R_PTE_VALID) || - ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, g_prot)) { + ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, g_prot, 0)) { /* No valid pte or access denied due to protection */ if (cause_excp) { ppc_radix64_raise_si(cpu, rwx, eaddr, fault_cause); --=20 2.21.1 From nobody Sun May 5 04:55:40 2024 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; 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=1585562008; cv=none; d=zohomail.com; s=zohoarc; b=K8wf3I6KdoIbkPJ6003NbDLvKXzxEJDg9ZTS+kq1pnz+/VhyTrBwADawNYX4xh+tEf7avRFUTyjVmKW/FRXWuaB5ruhsWLAaRhDKnzb18b7knMbbTreS4azctau3XTKT3djCctqO/DRQlG0LUgLRBHe+6u21WrWOiEMUbfysgHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585562008; h=Content-Type: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=+9nFKJB4vtjEdeLWrOHksYxZjwIO22HOcu66HtqWnZw=; b=OZ0uDxJcjNUSPrVRqrxEh5MusFkcOswlOXFCf9oh4D1TTtGjFVNag+NZK7sQzVoHb4aEK8PBLLNO7xI5a1iBSpL2M8B46ziwBXW0/mghSrbIpMMpwMI61nfWqOUaGvWzzL2DW4Q9MzB3YLn11KYUxprEyI3ngDNLWRgZ6T0ytrE= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1585562008739504.89536826684946; Mon, 30 Mar 2020 02:53:28 -0700 (PDT) Received: from localhost ([::1]:47214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr6k-0005rF-9U for importer@patchew.org; Mon, 30 Mar 2020 05:53:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIr4U-0002Qd-09 for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIr4R-00067P-Vq for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:51:05 -0400 Received: from 16.mo1.mail-out.ovh.net ([178.33.104.224]:57899) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jIr4R-00066E-Me for qemu-devel@nongnu.org; Mon, 30 Mar 2020 05:51:03 -0400 Received: from player729.ha.ovh.net (unknown [10.110.208.245]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 229301B867B for ; Mon, 30 Mar 2020 11:51:02 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id A528C110F546A; Mon, 30 Mar 2020 09:50:54 +0000 (UTC) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Subject: [PATCH 7/7] target/ppc: Add support for Radix partition-scoped translation Date: Mon, 30 Mar 2020 11:49:46 +0200 Message-Id: <20200330094946.24678-8-clg@kaod.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200330094946.24678-1-clg@kaod.org> References: <20200330094946.24678-1-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13908804501273283558 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepveorughrihgtucfnvgcuifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucfkpheptddrtddrtddrtddpkedvrdeigedrvdehtddrudejtdenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejvdelrdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrgh Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 178.33.104.224 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: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Suraj Jitindar Singh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The Radix tree translation model currently supports process-scoped translation for the PowerNV machine (Hypervisor mode) and for the pSeries machine (Guest mode). Guests running under an emulated Hypervisor (PowerNV machine) require a new type of Radix translation, called partition-scoped, which is missing today. The Radix tree translation is a 2 steps process. The first step, process-scoped translation, converts an effective Address to a guest real address, and the second step, partition-scoped translation, converts a guest real address to a host real address. There are difference cases to covers : * Hypervisor real mode access: no Radix translation. * Hypervisor or host application access (quadrant 0 and 3) with relocation on: process-scoped translation. * Guest OS real mode access: only partition-scoped translation. * Guest OS real or guest application access (quadrant 0 and 3) with relocation on: both process-scoped translation and partition-scoped translations. * Hypervisor access in quadrant 1 and 2 with relocation on: both process-scoped translation and partition-scoped translations. The radix tree partition-scoped translation is performed using tables pointed to by the first double-word of the Partition Table Entries and process-scoped translation uses tables pointed to by the Process Table Entries (second double-word of the Partition Table Entries). Both partition-scoped and process-scoped translations process are identical and thus the radix tree traversing code is largely reused. However, errors in partition-scoped translations generate hypervisor exceptions. Signed-off-by: Suraj Jitindar Singh Signed-off-by: C=C3=A9dric Le Goater --- target/ppc/cpu.h | 3 + target/ppc/excp_helper.c | 3 +- target/ppc/mmu-radix64.c | 172 +++++++++++++++++++++++++++++++++++---- 3 files changed, 162 insertions(+), 16 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index bca4169f8062..74f0524f4fea 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -464,6 +464,9 @@ typedef struct ppc_v3_pate_t { #define DSISR_AMR 0x00200000 /* Unsupported Radix Tree Configuration */ #define DSISR_R_BADCONFIG 0x00080000 +#define DSISR_ATOMIC_RC 0x00040000 +/* Unable to translate address of (guest) pde or process/page table entry = */ +#define DSISR_PRTABLE_FAULT 0x00020000 =20 /* SRR1 error code fields */ =20 diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 73b5c28d0375..e77572fab86e 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -525,9 +525,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int e= xcp_model, int excp) case POWERPC_EXCP_ISEG: /* Instruction segment exception = */ case POWERPC_EXCP_TRACE: /* Trace exception = */ break; + case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excepti= on */ + msr |=3D env->error_code; case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception = */ case POWERPC_EXCP_HDSI: /* Hypervisor data storage exception = */ - case POWERPC_EXCP_HISI: /* Hypervisor instruction storage excepti= on */ case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception = */ case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment excepti= on */ case POWERPC_EXCP_SDOOR_HV: /* Hypervisor Doorbell interrupt = */ diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 3ae29ed90d49..049527f40071 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -103,6 +103,27 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int = rwx, vaddr eaddr, } } =20 +static void ppc_radix64_raise_hsi(PowerPCCPU *cpu, int rwx, vaddr eaddr, + hwaddr g_raddr, uint32_t cause) +{ + CPUState *cs =3D CPU(cpu); + CPUPPCState *env =3D &cpu->env; + + if (rwx =3D=3D 2) { /* H Instruction Storage Interrupt */ + cs->exception_index =3D POWERPC_EXCP_HISI; + env->spr[SPR_ASDR] =3D g_raddr; + env->error_code =3D cause; + } else { /* H Data Storage Interrupt */ + cs->exception_index =3D POWERPC_EXCP_HDSI; + if (rwx =3D=3D 1) { /* Write -> Store */ + cause |=3D DSISR_ISSTORE; + } + env->spr[SPR_HDSISR] =3D cause; + env->spr[SPR_HDAR] =3D eaddr; + env->spr[SPR_ASDR] =3D g_raddr; + env->error_code =3D 0; + } +} =20 static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte, int *fault_cause, int *prot, @@ -236,6 +257,38 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lp= id, ppc_v3_pate_t *pate) return true; } =20 +static int ppc_radix64_partition_scoped_xlate(PowerPCCPU *cpu, int rwx, + vaddr eaddr, hwaddr g_raddr, + ppc_v3_pate_t pate, + hwaddr *h_raddr, int *h_prot, + int *h_page_size, bool pde_a= ddr, + bool cause_excp) +{ + int fault_cause =3D 0; + hwaddr pte_addr; + uint64_t pte; + + *h_page_size =3D PRTBE_R_GET_RTS(pate.dw0); + pte =3D ppc_radix64_walk_tree(cpu, g_raddr, pate.dw0 & PRTBE_R_RPDB, + pate.dw0 & PRTBE_R_RPDS, h_raddr, h_page_s= ize, + &fault_cause, &pte_addr); + /* No valid pte or access denied due to protection */ + if (!(pte & R_PTE_VALID) || + ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, h_prot, 1)= ) { + if (pde_addr) /* address being translated was that of a guest pde = */ + fault_cause |=3D DSISR_PRTABLE_FAULT; + if (cause_excp) { + ppc_radix64_raise_hsi(cpu, rwx, eaddr, g_raddr, fault_cause); + } + return 1; + } + + /* Update Reference and Change Bits */ + ppc_radix64_set_rc(cpu, rwx, pte, pte_addr, h_prot); + + return 0; +} + static int ppc_radix64_process_scoped_xlate(PowerPCCPU *cpu, int rwx, vaddr eaddr, uint64_t lpid, uint64_t= pid, ppc_v3_pate_t pate, hwaddr *g_raddr, @@ -243,9 +296,10 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU= *cpu, int rwx, bool cause_excp) { CPUState *cs =3D CPU(cpu); - uint64_t offset, size, prtbe_addr, prtbe0, pte; - int fault_cause =3D 0; - hwaddr pte_addr; + CPUPPCState *env =3D &cpu->env; + uint64_t offset, size, prtbe_addr, prtbe0, base_addr, nls, index, pte; + int fault_cause =3D 0, h_page_size, h_prot, ret; + hwaddr h_raddr, pte_addr; =20 /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ offset =3D pid * sizeof(struct prtb_entry); @@ -258,13 +312,69 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCP= U *cpu, int rwx, return 1; } prtbe_addr =3D (pate.dw1 & PATE1_R_PRTB) + offset; - prtbe0 =3D ldq_phys(cs->as, prtbe_addr); + + if (cpu->vhyp && lpid =3D=3D 0) { + prtbe0 =3D ldq_phys(cs->as, prtbe_addr); + } else { + /* + * Process table addresses are subject to partition-scoped + * translation + * + * On a Radix host, the partition-scoped page table for LPID=3D0 + * is only used to translate the effective addresses of the + * process table entries. + */ + ret =3D ppc_radix64_partition_scoped_xlate(cpu, 0, eaddr, prtbe_ad= dr, + pate, &h_raddr, &h_prot, + &h_page_size, 1, 1); + if (ret) { + return ret; + } + prtbe0 =3D ldq_phys(cs->as, h_raddr); + } =20 /* Walk Radix Tree from Process Table Entry to Convert EA to RA */ *g_page_size =3D PRTBE_R_GET_RTS(prtbe0); - pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, - prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, - g_raddr, g_page_size, &fault_cause, &pte_a= ddr); + base_addr =3D prtbe0 & PRTBE_R_RPDB; + nls =3D prtbe0 & PRTBE_R_RPDS; + if (msr_hv || (cpu->vhyp && lpid =3D=3D 0)) { + /* + * Can treat process table addresses as real addresses + */ + pte =3D ppc_radix64_walk_tree(cpu, eaddr & R_EADDR_MASK, base_addr= , nls, + g_raddr, g_page_size, &fault_cause, + &pte_addr); + } else { + index =3D (eaddr & R_EADDR_MASK) >> (*g_page_size - nls); /* Shift= */ + index &=3D ((1UL << nls) - 1); /* Mask = */ + pte_addr =3D base_addr + (index * sizeof(pte)); + + /* + * Each process table address is subject to a partition-scoped + * translation + */ + do { + ret =3D ppc_radix64_partition_scoped_xlate(cpu, 0, eaddr, pte_= addr, + pate, &h_raddr, &h_pr= ot, + &h_page_size, 1, 1); + if (ret) { + return ret; + } + + pte =3D ppc_radix64_next_level(cpu, eaddr & R_EADDR_MASK, &h_r= addr, + &nls, g_page_size, &fault_cause); + pte_addr =3D h_raddr; + } while ((pte & R_PTE_VALID) && !(pte & R_PTE_LEAF)); + + /* Did we find a valid leaf? */ + if ((pte & R_PTE_VALID) && (pte & R_PTE_LEAF)) { + uint64_t rpn =3D pte & R_PTE_RPN; + uint64_t mask =3D (1UL << *g_page_size) - 1; + + /* Or high bits of rpn and low bits to ea to form whole real a= ddr */ + *g_raddr =3D (rpn & ~mask) | (eaddr & mask); + } + } =20 if (!(pte & R_PTE_VALID) || ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, g_prot, 0)) { @@ -280,11 +390,29 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCP= U *cpu, int rwx, return 0; } =20 +/* + * Radix tree translation is a 2 steps translation process: + * + * 1. Process-scoped translation: Guest Eff Addr -> Guest Real Addr + * 2. Partition-scoped translation: Guest Real Addr -> Host Real Addr + * + * MSR[HV] + * +-------------+----------------+---------------+ + * | | HV =3D 0 | HV =3D 1 | + * +-------------+----------------+---------------+ + * | Relocation | Partition | No | + * | =3D Off | Scoped | Translation | + * Relocation +-------------+----------------+---------------+ + * | Relocation | Partition & | Process | + * | =3D On | Process Scoped | Scoped | + * +-------------+----------------+---------------+ + */ static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, uint64_t lpid, uint64_t pid, bool relocation, hwaddr *raddr, int *psizep, int *protp, bool cause_excp) { + CPUPPCState *env =3D &cpu->env; ppc_v3_pate_t pate; int psize, prot; hwaddr g_raddr; @@ -310,11 +438,6 @@ static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr ea= ddr, int rwx, } return 1; } - /* We don't support guest mode yet */ - if (lpid !=3D 0) { - error_report("PowerNV guest support Unimplemented"); - exit(1); - } } =20 /* @@ -322,6 +445,8 @@ static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr ead= dr, int rwx, * * - Translates an effective address to a host real address in * quadrants 0 and 3 when HV=3D1. + * + * - Translates an effective address to a guest real address. */ if (relocation) { int ret =3D ppc_radix64_process_scoped_xlate(cpu, rwx, eaddr, lpid= , pid, @@ -336,7 +461,24 @@ static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr ea= ddr, int rwx, g_raddr =3D eaddr & R_EADDR_MASK; } =20 - *raddr =3D g_raddr; + /* + * Perform partition-scoped translation if !HV or HV access to + * quadrants 1 or 2. Translates a guest real address to a host + * real address. + */ + if ((lpid !=3D 0) || (!cpu->vhyp && !msr_hv)) { + int ret =3D ppc_radix64_partition_scoped_xlate(cpu, rwx, eaddr, g_= raddr, + pate, raddr, &prot, &= psize, + 0, cause_excp); + if (ret) { + return ret; + } + *psizep =3D MIN(*psizep, psize); + *protp &=3D prot; + } else { + *raddr =3D g_raddr; + } + return 0; } =20 @@ -345,7 +487,7 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr= eaddr, int rwx, { CPUState *cs =3D CPU(cpu); CPUPPCState *env =3D &cpu->env; - uint64_t lpid =3D 0, pid =3D 0; + uint64_t pid, lpid =3D env->spr[SPR_LPIDR]; int page_size, prot; bool relocation; hwaddr raddr; @@ -355,7 +497,7 @@ int ppc_radix64_handle_mmu_fault(PowerPCCPU *cpu, vaddr= eaddr, int rwx, =20 relocation =3D ((rwx =3D=3D 2) && (msr_ir =3D=3D 1)) || ((rwx !=3D 2) = && (msr_dr =3D=3D 1)); /* HV or virtual hypervisor Real Mode Access */ - if (!relocation && (msr_hv || cpu->vhyp)) { + if (!relocation && (msr_hv || (cpu->vhyp && lpid =3D=3D 0))) { /* In real mode top 4 effective addr bits (mostly) ignored */ raddr =3D eaddr & 0x0FFFFFFFFFFFFFFFULL; =20 --=20 2.21.1