From nobody Tue Feb 10 13:18:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1660332332; cv=none; d=zohomail.com; s=zohoarc; b=cKmlHGSOcxMWNYDfYu13gy5RsU+C01wyRKl3lHEiq33K+h1OhnpY/f5jHS1Pyu8gvKjzfdQMF0S1D5yUPE+kMp9P5T04sS2Z9b1D+eH9AVie389cQ5jEwl1ikiUBYdZ9qz+aaWnMHzNdspdxp/JlGrNwi3ZwOpGzJHTxTAmuDus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660332332; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ngshIEE2EN6MEfw9zmbHPOq0MvbgTTFSHuQTBxj5Rkw=; b=bkDoITYiOUYjICvtgJuwIR6uNNOAB2Lw4i4KdZrWaI5bxxPck5mTnJR8aCJVAGWUZ2Y38zgt3JYBPFzzTV+fk/jPOvOUnNEHrvHND7z/cOF9SoiRPI7cT8rQcMTUbhL5mi7FnQmLMYeRs65O60dC5tk9eXdVPhXLDtil6a4OizY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1660332332959621.8053090935457; Fri, 12 Aug 2022 12:25:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.385856.621647 (Exim 4.92) (envelope-from ) id 1oMaHP-0000d8-JI; Fri, 12 Aug 2022 19:25:11 +0000 Received: by outflank-mailman (output) from mailman id 385856.621647; Fri, 12 Aug 2022 19:25:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oMaHP-0000bb-CI; Fri, 12 Aug 2022 19:25:11 +0000 Received: by outflank-mailman (input) for mailman id 385856; Fri, 12 Aug 2022 19:25:10 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oMaHO-0000OU-3A for xen-devel@lists.xenproject.org; Fri, 12 Aug 2022 19:25:10 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oMaHN-0000xo-TP; Fri, 12 Aug 2022 19:25:09 +0000 Received: from 54-240-197-224.amazon.com ([54.240.197.224] helo=dev-dsk-jgrall-1b-035652ec.eu-west-1.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oMaHN-0006n6-LI; Fri, 12 Aug 2022 19:25:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ngshIEE2EN6MEfw9zmbHPOq0MvbgTTFSHuQTBxj5Rkw=; b=6AOrZflQqxWt6ZUuxW+F80X5TW UkChC67IgilFd/Mv8haKA1DcebMlYmv7kYezggohNyTbySnsmPaTpFm+bsWk+RkYu01XIg9PCzByT e5e6SvFQz0NFelgVgSfpcKU/8vim9tSGvDSFS6WqnAl2WAJ7mZSvqTgxE+5FR5qXKcB4=; From: Julien Grall To: xen-devel@lists.xenproject.org Cc: julien@xen.org, Julien Grall , Stefano Stabellini , Bertrand Marquis , Volodymyr Babchuk Subject: [PATCH 2/7] xen/arm64: head: Introduce get_table_slot() and use it Date: Fri, 12 Aug 2022 20:24:41 +0100 Message-Id: <20220812192448.43016-3-julien@xen.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220812192448.43016-1-julien@xen.org> References: <20220812192448.43016-1-julien@xen.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) X-ZM-MESSAGEID: 1660332334639100006 Content-Type: text/plain; charset="utf-8" From: Julien Grall There are a few places in the code that need to find the slot at a given page-table level. So create a new macro get_table_slot() for that. This will reduce the effort to figure out whether the code is doing the right thing. Take the opportunity to use 'ubfx'. The only benefits is reducing the number of instructions from 2 to 1. The new macro is used everywhere we need to compute the slot. This requires to tweak the parameter of create_table_entry() to pass a level rather than shift. Note, for slot 0 the code is currently skipping the masking part. While this is fine, it is safer to mask it as technically slot 0 only covers bit 48 - 39 bit (assuming 4KB page granularity). Take the opportunity to correct the comment when finding the second slot for the identity mapping (we are computing the second slot rather than first). Signed-off-by: Julien Grall Reviewed-by: Bertrand Marquis Reviewed-by: Wei Chen ---- This patch also has the benefits to reduce the number of use of {ZEROETH, FIRST, SECOND, THIRD}_SHIFT. The next patch for arm32 will reduce further. --- xen/arch/arm/arm64/head.S | 55 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 26cc7705f556..ad014716db6f 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -493,13 +493,24 @@ cpu_init: ret ENDPROC(cpu_init) =20 +/* + * Macro to find the slot number at a given page-table level + * + * slot: slot computed + * virt: virtual address + * lvl: page-table level + */ +.macro get_table_slot, slot, virt, lvl + ubfx \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl), #XEN_PT_LPAE_SHIFT +.endm + /* * Macro to create a page table entry in \ptbl to \tbl * * ptbl: table symbol where the entry will be created * tbl: table symbol to point to * virt: virtual address - * shift: #imm page table shift + * lvl: page-table level * tmp1: scratch register * tmp2: scratch register * tmp3: scratch register @@ -511,9 +522,8 @@ ENDPROC(cpu_init) * * Note that all parameters using registers should be distinct. */ -.macro create_table_entry, ptbl, tbl, virt, shift, tmp1, tmp2, tmp3 - lsr \tmp1, \virt, #\shift - and \tmp1, \tmp1, #XEN_PT_LPAE_ENTRY_MASK/* \tmp1 :=3D slot in \= tlb */ +.macro create_table_entry, ptbl, tbl, virt, lvl, tmp1, tmp2, tmp3 + get_table_slot \tmp1, \virt, \lvl /* \tmp1 :=3D slot in \tlb */ =20 load_paddr \tmp2, \tbl mov \tmp3, #PT_PT /* \tmp3 :=3D right for linear= PT */ @@ -544,8 +554,7 @@ ENDPROC(cpu_init) .macro create_mapping_entry, ptbl, virt, phys, tmp1, tmp2, tmp3, type=3DPT= _MEM_L3 and \tmp3, \phys, #THIRD_MASK /* \tmp3 :=3D PAGE_ALIGNED(phy= s) */ =20 - lsr \tmp1, \virt, #THIRD_SHIFT - and \tmp1, \tmp1, #XEN_PT_LPAE_ENTRY_MASK/* \tmp1 :=3D slot in \= tlb */ + get_table_slot \tmp1, \virt, 3 /* \tmp1 :=3D slot in \tlb */ =20 mov \tmp2, #\type /* \tmp2 :=3D right for sectio= n PT */ orr \tmp2, \tmp2, \tmp3 /* + PAGE_ALIGNED(phy= s) */ @@ -573,9 +582,9 @@ ENDPROC(cpu_init) create_page_tables: /* Prepare the page-tables for mapping Xen */ ldr x0, =3DXEN_VIRT_START - create_table_entry boot_pgtable, boot_first, x0, ZEROETH_SHIFT, x1= , x2, x3 - create_table_entry boot_first, boot_second, x0, FIRST_SHIFT, x1, x= 2, x3 - create_table_entry boot_second, boot_third, x0, SECOND_SHIFT, x1, = x2, x3 + create_table_entry boot_pgtable, boot_first, x0, 0, x1, x2, x3 + create_table_entry boot_first, boot_second, x0, 1, x1, x2, x3 + create_table_entry boot_second, boot_third, x0, 2, x1, x2, x3 =20 /* Map Xen */ adr_l x4, boot_third @@ -612,10 +621,10 @@ create_page_tables: * XEN_ZEROETH_SLOT, then the 1:1 mapping will use its own set of * page-tables from the first level. */ - lsr x0, x19, #ZEROETH_SHIFT /* x0 :=3D zeroeth slot */ + get_table_slot x0, x19, 0 /* x0 :=3D zeroeth slot */ cmp x0, #XEN_ZEROETH_SLOT beq 1f - create_table_entry boot_pgtable, boot_first_id, x19, ZEROETH_SHIFT= , x0, x1, x2 + create_table_entry boot_pgtable, boot_first_id, x19, 0, x0, x1, x2 b link_from_first_id =20 1: @@ -624,11 +633,10 @@ create_page_tables: * then the 1:1 mapping will use its own set of page-tables from * the second level. */ - lsr x0, x19, #FIRST_SHIFT - and x0, x0, #XEN_PT_LPAE_ENTRY_MASK /* x0 :=3D first slot */ + get_table_slot x0, x19, 1 /* x0 :=3D first slot */ cmp x0, #XEN_FIRST_SLOT beq 1f - create_table_entry boot_first, boot_second_id, x19, FIRST_SHIFT, x= 0, x1, x2 + create_table_entry boot_first, boot_second_id, x19, 1, x0, x1, x2 b link_from_second_id =20 1: @@ -638,17 +646,16 @@ create_page_tables: * third level. For slot XEN_SECOND_SLOT, Xen is not yet able to h= andle * it. */ - lsr x0, x19, #SECOND_SHIFT - and x0, x0, #XEN_PT_LPAE_ENTRY_MASK /* x0 :=3D first slot */ + get_table_slot x0, x19, 2 /* x0 :=3D second slot */ cmp x0, #XEN_SECOND_SLOT beq virtphys_clash - create_table_entry boot_second, boot_third_id, x19, SECOND_SHIFT, = x0, x1, x2 + create_table_entry boot_second, boot_third_id, x19, 2, x0, x1, x2 b link_from_third_id =20 link_from_first_id: - create_table_entry boot_first_id, boot_second_id, x19, FIRST_SHIFT= , x0, x1, x2 + create_table_entry boot_first_id, boot_second_id, x19, 1, x0, x1, = x2 link_from_second_id: - create_table_entry boot_second_id, boot_third_id, x19, SECOND_SHIF= T, x0, x1, x2 + create_table_entry boot_second_id, boot_third_id, x19, 2, x0, x1, = x2 link_from_third_id: create_mapping_entry boot_third_id, x19, x19, x0, x1, x2 ret @@ -705,7 +712,7 @@ remove_identity_mapping: * Find the zeroeth slot used. Remove the entry from zeroeth * table if the slot is not XEN_ZEROETH_SLOT. */ - lsr x1, x19, #ZEROETH_SHIFT /* x1 :=3D zeroeth slot */ + get_table_slot x1, x19, 0 /* x1 :=3D zeroeth slot */ cmp x1, #XEN_ZEROETH_SLOT beq 1f /* It is not in slot XEN_ZEROETH_SLOT, remove the entry. */ @@ -718,8 +725,7 @@ remove_identity_mapping: * Find the first slot used. Remove the entry for the first * table if the slot is not XEN_FIRST_SLOT. */ - lsr x1, x19, #FIRST_SHIFT - and x1, x1, #XEN_PT_LPAE_ENTRY_MASK /* x1 :=3D first slot */ + get_table_slot x1, x19, 1 /* x1 :=3D first slot */ cmp x1, #XEN_FIRST_SLOT beq 1f /* It is not in slot XEN_FIRST_SLOT, remove the entry. */ @@ -732,8 +738,7 @@ remove_identity_mapping: * Find the second slot used. Remove the entry for the first * table if the slot is not XEN_SECOND_SLOT. */ - lsr x1, x19, #SECOND_SHIFT - and x1, x1, #XEN_PT_LPAE_ENTRY_MASK /* x1 :=3D first slot */ + get_table_slot x1, x19, 2 /* x1 :=3D second slot */ cmp x1, #XEN_SECOND_SLOT beq identity_mapping_removed /* It is not in slot 1, remove the entry */ @@ -771,7 +776,7 @@ setup_fixmap: #endif /* Map fixmap into boot_second */ ldr x0, =3DFIXMAP_ADDR(0) - create_table_entry boot_second, xen_fixmap, x0, SECOND_SHIFT, x1, = x2, x3 + create_table_entry boot_second, xen_fixmap, x0, 2, x1, x2, x3 /* Ensure any page table updates made above have occurred. */ dsb nshst =20 --=20 2.37.1