From nobody Tue Oct 14 10:40:26 2025 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=1588828260; cv=none; d=zohomail.com; s=zohoarc; b=GuI03eXCxFMo6YkFGdde/p/8QKr8pN95sz3C0Q4XsiK4X0N+qdJWm9X2bkZ6s5VmUjfWwjGel59hyl4ytgyz7AAaob+0++CH/6fSsVdoQm3PGy7qMBYgHFnUBNXZtbO/EeqpXfiQ8RurJcPRBID37Jssw8ZC4vB6NCvNdvkFn+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588828260; 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=pvqVBCtslcXvUm8TzjibkRiaLcwNFF99CjQlACmGXYE=; b=NrMn4CujSLw4YieBHOGBzd/zAAwBuBxOMEdmIeYByCRPYz1k2swTJ2YhCmYAD5esAYMCd5nl0I/2TDt4f+VRLuV0Hcv+W0t5kBC0mzlu+5USs/ro73kfmb9Lhy8+vnlmwTqUShlUIGRET56GyEi50uNUC+5KTv2TWYpK2OEaekY= 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 1588828260277511.52021898465694; Wed, 6 May 2020 22:11:00 -0700 (PDT) Received: from localhost ([::1]:40426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWYoF-00042Q-0E for importer@patchew.org; Thu, 07 May 2020 01:10:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWYi1-0007nO-5z; Thu, 07 May 2020 01:04:33 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:40939 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWYi0-0007ug-0W; Thu, 07 May 2020 01:04:32 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49HhFq0gz2z9sTL; Thu, 7 May 2020 15:04:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1588827855; bh=tZ3Kasifk++2rxl06Eg2Balz4fv0k7E9uAoNZry82So=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dJ8UJ0UOx+FNyk+RbO0TRt1G/2b387BEGnGmc+EwlSj47FyNojxol0+fJfwA7MNj4 hO97rxfO0lHewY3I0BjEGoEaGiqncHONUxkXOQ4NmuwBVVYGg3GH2cp3w3gKgoxGl2 dLe8/ZgvkCtkVoaqKfcCK5E1fUl2iWocFjlN6PvU= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 14/18] target/ppc: Rework ppc_radix64_walk_tree() for partition-scoped translation Date: Thu, 7 May 2020 15:02:24 +1000 Message-Id: <20200507050228.802395-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200507050228.802395-1-david@gibson.dropbear.id.au> References: <20200507050228.802395-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/07 01:04:14 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: aik@ozlabs.ru, qemu-devel@nongnu.org, npiggin@gmail.com, groug@kaod.org, qemu-ppc@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: C=C3=A9dric Le Goater The ppc_radix64_walk_tree() routine walks through the nested radix tables to look for a PTE. Split it in 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. The prototypes are slightly change to use a 'AddressSpace *' parameter, instead of a 'PowerPCCPU *' which is not required, and to return an error code instead of a PTE value. It clarifies error handling in the callers. Signed-off-by: Suraj Jitindar Singh Signed-off-by: Greg Kurz Signed-off-by: C=C3=A9dric Le Goater Message-Id: <20200403140056.59465-4-clg@kaod.org> Signed-off-by: David Gibson --- target/ppc/mmu-radix64.c | 79 ++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c index 11b3c6d48c..2400da41e0 100644 --- a/target/ppc/mmu-radix64.c +++ b/target/ppc/mmu-radix64.c @@ -163,44 +163,67 @@ 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 int ppc_radix64_next_level(AddressSpace *as, vaddr eaddr, + uint64_t *pte_addr, uint64_t *nls, + int *psize, uint64_t *pte, int *fault_ca= use) { - 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; + return 1; } =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(as, *pte_addr); + if (!(pde & R_PTE_VALID)) { /* Invalid Entry */ *fault_cause |=3D DSISR_NOPTE; - return 0; + return 1; } =20 - *psize -=3D nls; + *pte =3D pde; + *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 0; +} =20 - /* Check if Leaf Entry -> Page Table Entry -> Stop the Search */ - if (pde & R_PTE_LEAF) { - uint64_t rpn =3D pde & R_PTE_RPN; - uint64_t mask =3D (1UL << *psize) - 1; +static int ppc_radix64_walk_tree(AddressSpace *as, vaddr eaddr, + uint64_t base_addr, uint64_t nls, + hwaddr *raddr, int *psize, uint64_t *pte, + int *fault_cause, hwaddr *pte_addr) +{ + uint64_t index, pde, rpn , mask; =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; + if (nls < 5) { /* Directory maps less than 2**5 entries */ + *fault_cause |=3D DSISR_R_BADCONFIG; + return 1; } =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); + index =3D eaddr >> (*psize - nls); /* Shift */ + index &=3D ((1UL << nls) - 1); /* Mask */ + *pte_addr =3D base_addr + (index * sizeof(pde)); + do { + int ret; + + ret =3D ppc_radix64_next_level(as, eaddr, pte_addr, &nls, psize, &= pde, + fault_cause); + if (ret) { + return ret; + } + } while (!(pde & R_PTE_LEAF)); + + *pte =3D pde; + rpn =3D pde & R_PTE_RPN; + mask =3D (1UL << *psize) - 1; + + /* Or high bits of rpn and low bits to ea to form whole real addr */ + *raddr =3D (rpn & ~mask) | (eaddr & mask); + return 0; } =20 static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, ppc_v3_pate_t *p= ate) @@ -230,6 +253,7 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCPU = *cpu, int rwx, uint64_t offset, size, prtbe_addr, prtbe0, pte; int fault_cause =3D 0; hwaddr pte_addr; + int ret; =20 /* Index Process Table by PID to Find Corresponding Process Table Entr= y */ offset =3D pid * sizeof(struct prtb_entry); @@ -246,11 +270,12 @@ static int ppc_radix64_process_scoped_xlate(PowerPCCP= U *cpu, int rwx, =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, + ret =3D ppc_radix64_walk_tree(cs->as, eaddr & R_EADDR_MASK, prtbe0 & PRTBE_R_RPDB, prtbe0 & PRTBE_R_RP= DS, - g_raddr, g_page_size, &fault_cause, &pte_a= ddr); + g_raddr, g_page_size, &pte, &fault_cause, + &pte_addr); =20 - if (!(pte & R_PTE_VALID) || + if (ret || ppc_radix64_check_prot(cpu, rwx, pte, &fault_cause, g_prot, false)= ) { /* No valid pte or access denied due to protection */ if (cause_excp) { --=20 2.26.2