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

Re: [PATCH 2/7] xen/arm64: 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:45:51 +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=d62Xc10U3aJgHrw0e6DkBNlQOHGwnvrIKRW/ha3zXGY=; b=ik7XXHCADDkcbOjR7OAmPwr5tTGA0g2oQhbk5pOnCUrLbg2rcznBcKtATbYLdGL5Y64ToqBsvX4K4NIUFpCNHz6ceCjWEeZ2QKMTweRqNecx81RNAyKCE69APOagDl5kKd5midiH+QhMFoihkKRiiNIjlp7lEHeeaBJc/9HZZr7qFKb+2xdL/wouVrc1EmSF+kNKbORYL+Bsg62sHBf2OrpbVFffYYo0xrVBuZ9hEUVxecltGXlsU+tKQHWNXCy8oH/zaaQcXKpCan0Q28E/+1l9mXs0sGYOFBESaBqpZlu85NuGiRpFwsxkyGLANO0+LGcPI0xIg2HxUqIvJ6Zqcw==
  • 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=d62Xc10U3aJgHrw0e6DkBNlQOHGwnvrIKRW/ha3zXGY=; b=JH3z3dE5pFPiOLgS421wlqurwjLEKcE+8gsEKbGLGWdSiYkRgXvc4qj44MY+ijhkmAYhFidVKs2Jv4Oip9ar4cOd19Oo4CY7HmZxlCaYql0+oG9i5TGAzVdKMmKCGBRFJ4O0dnvbmoob/8lVckx2kstUnJUVTm/0DuhXKV8QTsAw2EORaG2yvdna/kdvIuaFnuLarXyob9xyXbFi0WH03Qo9/e7cbb4iWBKdYkim9QoKzVpkpH5WZK2Krj9cQe/fFMIWHH9UiHQkpqw+2AmWhMoiz9aUB0RF8wASbCrUXLXGjKmfuR/VHDqLmiATsTCTqQFXghrtLnOD2fGp4pT6Sg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=WiFgt3Pt2ZJ/0VIZ9lE+TvSKQyBHIbEhbESoeh3Dbj1tMTU5liky3Y+A7VlQybXmhWYVeYQ/Cgyn0qm8rodVAc2Osq0ISf+BzBmf5FGXUjHd2ZKkJufHb6lm9LPsLkE/k1urCGb+ko5F2o1ak3BmijE+OdrvROQEqxhCuly+uz7ZQz7jXEWRCxhdMGOODTKQv2PkKAS5SVaXVZynzkPoquMUwzxtmQuJrz4urVuC78N6uthi/hgz0KsZoZBJQBHzipayz5vCRDGpA7BJ8RiMLTUDHOBjEOet1WJXbT6XcWBEiBbaBRtm6PvE5IZH/HYyTAWtwFINgjkry/Y/pNmKHg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QxxstXXxok/KlmVDzP2PxamstLif3ABbCzFMW+fWX0JNegiHxyYIexrWGK40hJN8s/oMd2+3YPIixjuAubmpvl/5y5cxF63fCfdXPvpARhZIsFytZbQQ68nb+ynnaNLDHlPUZfmdXMwQ9VVd0es3l0gMDkO3ZvX3nXmdWbokNA3tVui5WTeDwgISteAKHRoD+h0uPQtW2ZGdJOJ1TpS7pWthjiPcnfeJ+IwerOcPkl2o/IEAoR5VhamSnqwsReOFgyNDrgkcOs6XGvWk2aRXeEBn/zVmfDvKh1JRoEPvK4L0hKbGwo4ZW10wBxnn77wVFucbL80C9hPS9R8WfMNazA==
  • 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:46:20 +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.

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 <jgrall@xxxxxxxxxx>

----

     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)
+/*
+ * 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 := slot in \tlb */
+.macro create_table_entry, ptbl, tbl, virt, lvl, tmp1, tmp2, tmp3
+        get_table_slot \tmp1, \virt, \lvl   /* \tmp1 := slot in \tlb */
load_paddr \tmp2, \tbl
          mov   \tmp3, #PT_PT                 /* \tmp3 := right for linear PT */
@@ -544,8 +554,7 @@ ENDPROC(cpu_init)
  .macro create_mapping_entry, ptbl, virt, phys, tmp1, tmp2, tmp3, 
type=PT_MEM_L3
          and   \tmp3, \phys, #THIRD_MASK     /* \tmp3 := PAGE_ALIGNED(phys) */
- lsr \tmp1, \virt, #THIRD_SHIFT
-        and   \tmp1, \tmp1, #XEN_PT_LPAE_ENTRY_MASK/* \tmp1 := slot in \tlb */
+        get_table_slot \tmp1, \virt, 3      /* \tmp1 := slot in \tlb */
mov \tmp2, #\type /* \tmp2 := right for section PT */
          orr   \tmp2, \tmp2, \tmp3           /*          + PAGE_ALIGNED(phys) 
*/
@@ -573,9 +582,9 @@ ENDPROC(cpu_init)
  create_page_tables:
          /* Prepare the page-tables for mapping Xen */
          ldr   x0, =XEN_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, x2, 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
/* 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 := zeroeth slot */
+        get_table_slot x0, x19, 0       /* x0 := 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
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 := first slot */
+        get_table_slot x0, x19, 1      /* x0 := first slot */
          cmp   x0, #XEN_FIRST_SLOT
          beq   1f
-        create_table_entry boot_first, boot_second_id, x19, FIRST_SHIFT, x0, 
x1, x2
+        create_table_entry boot_first, boot_second_id, x19, 1, x0, x1, x2
          b     link_from_second_id
1:
@@ -638,17 +646,16 @@ create_page_tables:
           * third level. For slot XEN_SECOND_SLOT, Xen is not yet able to 
handle
           * it.
           */
-        lsr   x0, x19, #SECOND_SHIFT
-        and   x0, x0, #XEN_PT_LPAE_ENTRY_MASK  /* x0 := first slot */
+        get_table_slot x0, x19, 2     /* x0 := 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
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_SHIFT, 
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 := zeroeth slot */
+        get_table_slot x1, x19, 0       /* x1 := 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 := first slot */
+        get_table_slot x1, x19, 1       /* x1 := 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 := first slot */
+        get_table_slot x1, x19, 2       /* x1 := 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, =FIXMAP_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

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®.