[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/7] xen/arm32: head: Introduce get_table_slot() and use it


  • To: Julien Grall <julien@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Wei Chen <Wei.Chen@xxxxxxx>
  • Date: Mon, 15 Aug 2022 09:48:22 +0800
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JLaUDDBt+qDLXQNdIhVktfakXm4x/ZrQ29rSP9MNex4=; b=OPIxwDxZQDy/eBNuWM5KUGly7FzpQeMjSpTjimjCBO9cFp6Bl5UtlZoARkCmdybYYb54TzWtuZV1nItn8Oduz2L4tORuaWK7j9NyEaE+qoJUwsQwocAyCXFUtXGhVgb7J+ewpI1O3XQH5pqTQlxBEVsLdHdLXJ/wr61YseEI1sJLxvqMbInDPmroNmRtwrrU7y2iOnaImOUt9f0sWn7nh8r2wWZs8uI7w+xinyzhqEonfQPGafvYHPNN5/YxxYzRQgEPqusKIylOKUy5RLi99nn9SZeo+/yRnBbEFra9JjYmKSvxv009OxKeacmeqGz1sR3D3VXpynxvxlW8WNe/vQ==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JLaUDDBt+qDLXQNdIhVktfakXm4x/ZrQ29rSP9MNex4=; b=HhlkTHwiygQL+12ojXqUAue0YsVavWEVY1MOAisGpOeFji1BoCVcFsiOZpRBWeiQniVL84CSRbowNUSA1nhPLZOT1N7aIMBR8lukfa82amvhx348WavoOUjnpwi7VTQlBEY/ypmzqdXMhjKrhRUO5VQKi4bP91oe4igNXHOwF4PVmlLBKQCjrtpj5ilQ+k8OclPCJQD417606jZaLA00yazXvi3+Ckb6DX7Rh8nx5R/2uhU/syo1u3uqq66Gk3QWdVe4+AagY025pFtdvDhmCw92A4AV/xa+tDa2gM6gV+4By/tbG/Ag0iefOAMegPVrDanfkfmPjF5akPjcWZGh4Q==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=D+edypbl5EfioR+XGu8THKbn0EV363QYs2uI87eZXd4Kff+3o6EdWPPpZHpEhcGJv//PR5Neu197WhRs+5WXKgYHw3dwyXnO1F4yP9A0rGNtKUOl3q/p5Um0JlHkoD07M/fiGEQU6u6iKp12Le3dLFJz9CrjPN8AKz+En7HXzPPHqRcRQuXnIS/iLs4VvmAgVw6iJUsbdavQ2NaznDB6L6CtIrXRRBPe6cC0UyK/AGI/TMhfF0NT2xCxyUA/VnE0hJn61HwrQBv5EzPdSpuLkdDD1LKd67XlX9hX/EgL1p7qkDfI+2Z3Rr05MaHs6FN6MZVeUXJZtaqlK/+mms2rTw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CvaKkiozXtH5cdFe+9coV3sJDpYU72kyjx78r3rrgq6O2aiKJ3582ZxwBjsoSx0tIxTbQ2nqKTLRRVfAyKsVbst1FvWdGpxkKRv2XdoIMoGcoOdBHWw0ZoSxALc6XG12vjCM4dNxBGQtdoEKGzlqppPA7NaJWakpyeJSYkxWeAzOAy33E9r0IVkIo7bo55HnEkELW/6/7zYEYIV8TQLuqGqlKvlaGkMf+bDPR1vmOyMqLeHuBlnBsgEOfXIcTqkB3jU2pGd7emf2OPsBetmgB7Q8VZItTdlDmZbVh4J6icO7QuQ+Z3MAMZuHOaB2A8sKn9SwhyksDLF1PE7IIALsMQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Julien Grall <jgrall@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 15 Aug 2022 01:48:48 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;

Hi Julien,

On 2022/8/13 3:24, Julien Grall wrote:
From: Julien Grall <jgrall@xxxxxxxxxx>

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.

The new macro is using 'ubfx' (or 'lsr' for the first level) rather
than the existing sequence (mov_w, lsr, and) because it doesn't require
a scratch register and reduce the number of instructions (4 -> 1).

Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
---
  xen/arch/arm/arm32/head.S | 56 ++++++++++++++++++++++-----------------
  1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S
index 46d93bebbabe..50f6fa4eb38d 100644
--- a/xen/arch/arm/arm32/head.S
+++ b/xen/arch/arm/arm32/head.S
@@ -358,13 +358,31 @@ cpu_init_done:
          mov   pc, r5                        /* Return address is in r5 */
  ENDPROC(cpu_init)
+/*
+ * Macro to find the slot number at a given page-table level
+ *
+ * slot:     slot computed
+ * virt:     virtual address
+ * lvl:      page-table level
+ *
+ * Note that ubxf is unpredictable when the end bit is above 32-bit. So we
+ * can't use it for first level offset.
+ */
+.macro get_table_slot, slot, virt, lvl
+    .if \lvl == 1
+        lsr   \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl)
+    .else
+        ubfx  \slot, \virt, #XEN_PT_LEVEL_SHIFT(\lvl), #XEN_PT_LPAE_SHIFT
+    .endif
+.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
   * mmu:     Is the MMU turned on/off. If not specified it will be off
   *
   * Preserves \virt
@@ -374,11 +392,9 @@ ENDPROC(cpu_init)
   *
   * Note that \virt should be in a register other than r1 - r4
   */
-.macro create_table_entry, ptbl, tbl, virt, shift, mmu=0
-        lsr   r1, \virt, #\shift
-        mov_w r2, XEN_PT_LPAE_ENTRY_MASK
-        and   r1, r1, r2             /* r1 := slot in \tlb */
-        lsl   r1, r1, #3             /* r1 := slot offset in \tlb */
+.macro create_table_entry, ptbl, tbl, virt, lvl, mmu=0
+        get_table_slot r1, \virt, \lvl  /* r1 := slot in \tlb */
+        lsl   r1, r1, #3                /* r1 := slot offset in \tlb */
load_paddr r4, \tbl @@ -448,8 +464,8 @@ ENDPROC(cpu_init)
  create_page_tables:
          /* Prepare the page-tables for mapping Xen */
          ldr   r0, =XEN_VIRT_START
-        create_table_entry boot_pgtable, boot_second, r0, FIRST_SHIFT
-        create_table_entry boot_second, boot_third, r0, SECOND_SHIFT
+        create_table_entry boot_pgtable, boot_second, r0, 1
+        create_table_entry boot_second, boot_third, r0, 2
/* Setup boot_third: */
          adr_l r4, boot_third, mmu=0
@@ -486,12 +502,10 @@ create_page_tables:
           * then the 1:1 mapping will use its own set of page-tables from
           * the second level.
           */
-        lsr   r1, r9, #FIRST_SHIFT
-        mov_w r0, XEN_PT_LPAE_ENTRY_MASK
-        and   r1, r1, r0              /* r1 := first slot */
+        get_table_slot r1, r9, 1     /* r1 := first slot */
          cmp   r1, #XEN_FIRST_SLOT
          beq   1f
-        create_table_entry boot_pgtable, boot_second_id, r9, FIRST_SHIFT
+        create_table_entry boot_pgtable, boot_second_id, r9, 1
          b     link_from_second_id
1:
@@ -501,16 +515,14 @@ create_page_tables:
           * third level. For slot XEN_SECOND_SLOT, Xen is not yet able to 
handle
           * it.
           */
-        lsr   r1, r9, #SECOND_SHIFT
-        mov_w r0, XEN_PT_LPAE_ENTRY_MASK
-        and   r1, r1, r0             /* r1 := second slot */
+        get_table_slot r1, r9, 2     /* r1 := second slot */
          cmp   r1, #XEN_SECOND_SLOT
          beq   virtphys_clash
-        create_table_entry boot_second, boot_third_id, r9, SECOND_SHIFT
+        create_table_entry boot_second, boot_third_id, r9, 2
          b     link_from_third_id
link_from_second_id:
-        create_table_entry boot_second_id, boot_third_id, r9, SECOND_SHIFT
+        create_table_entry boot_second_id, boot_third_id, r9, 2
  link_from_third_id:
          create_mapping_entry boot_third_id, r9, r9
          mov   pc, lr
@@ -571,9 +583,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   r1, r9, #FIRST_SHIFT
-        mov_w r0, XEN_PT_LPAE_ENTRY_MASK
-        and   r1, r1, r0              /* r1 := first slot */
+        get_table_slot r1, r9, 1     /* r1 := first slot */
          cmp   r1, #XEN_FIRST_SLOT
          beq   1f
          /* It is not in slot 0, remove the entry */
@@ -587,9 +597,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   r1, r9, #SECOND_SHIFT
-        mov_w r0, XEN_PT_LPAE_ENTRY_MASK
-        and   r1, r1, r0             /* r1 := second slot */
+        get_table_slot r1, r9, 2     /* r1 := second slot */
          cmp   r1, #XEN_SECOND_SLOT
          beq   identity_mapping_removed
          /* It is not in slot 1, remove the entry */
@@ -628,7 +636,7 @@ setup_fixmap:
  #endif
          /* Map fixmap into boot_second */
          mov_w r0, FIXMAP_ADDR(0)
-        create_table_entry boot_second, xen_fixmap, r0, SECOND_SHIFT, mmu=1
+        create_table_entry boot_second, xen_fixmap, r0, 2, mmu=1
          /* Ensure any page table updates made above have occurred. */
          dsb   nshst

Reviewed-by: Wei Chen <Wei.Chen@xxxxxxx>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.