[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>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Mon, 15 Aug 2022 14:45:15 +0000
  • Accept-language: en-GB, en-US
  • 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=X499eUT4J2rTCNAIsrSj1W+XPj0roleTYhXsYG1D7Iw=; b=TiWz0L3Hwg/1lZcEl43zqDsNvOWgfnwOOqoaGds4TcocpkQEOCYHhDZMAMS7RV+Q/p9yv5rqWDWP/32eawMXw70Tc9iZP+ypyN/Em9ztsaOfk1v+XQj71VpP6jG6aRC27kCvF0CR5NcEd/43asotq3ZP01ZEdbTBpxta39bfqzlt9LW0keOl9MQwR4kNviPOz69c7VSfc5vY9xjsjPTYTEQSQ0WnlC1nrzxo5BENr0KAkC/11GQhcpzwH3mKbXHupGzBdjJ0IOJkrc2u8buqG08LSTQg7xl0P3g3gQwHmoShTQTwzWzd4ONzYsACKMb/YGu4cM9I6UTVl609M7m0Zg==
  • 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=X499eUT4J2rTCNAIsrSj1W+XPj0roleTYhXsYG1D7Iw=; b=cNjNxY3nUg1WTtASm5ejVcKPhMRAVuM/cmlXJBFS/j2yrSzpQIlNW3VF8Ngh0JeSDc2unM2wdqR2beVA9tYz5wciGdwbilVk9sbCuwEw7ZtuU9CbS+htPbWL3BxrehkDdtp8FKjhHZ5BD7JdVg1cD4V8A4gYDfCIx02jIT76iUj36owYtuEAX1jLULiepQcHMXpImf5mO/Kc0c3ETJZ6IQgxw6v4bueYwfJZQPsVDplpo31irzwV/A4dVHJowwFyaEHFp4mUGK69BBAQbPTtei1WmjDLBSKTNRV85iZUv2YSJ4uWy8cjCn4JYKNAI2Jgk3HTrS1sIIVgHmbKgkUvUQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=OX6dowWxtsCHTrqGYpJIlp8IqrMxpXlFY9mW3JcTxatSasP9hpj/OhaWCeZ7bGLEaaBVOqF6M1SjTGP7xzYaN1O08CyQBWsSmEJlWwLlmwuy3vnzri3/eXyKrxVmcL6K/voIetx+aQyxDOAKhp7Ebmq9iAbeRISACG35mpS9vpIkSS1Cq8UuZbCR/Aef4LL26lgdqzV8H5gsr5pvfWbj0Pusjgz5i9TrUjasEk/x/kSO5j2a9CqSH9mFjsPqBwVYg6p636LBvjDFIBT1TWG92Qh1qdRh3CqAkSPGSCCIm39onZfiv9bgrTq4b3tAVQb8YIfZKI+W7hNMI5gImYPBtQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VTNkwerYi4ZgaCl+onntLspgtATDZLgG7vIRLSNVl1bIoryRzUY4Wn0s7tuCamOUNeA+KpWZqsy55nMqja2PZgMtxKD6lZuvmZXJSexoTzYrBS4dIGLzLA8KQisLEgsn5zNyQpA5JVvo/z6ads6EYH04rSI+dQJt7lcLqMHNEWYn64W6WdJ6wGhRfzRPevl0G3EQaa2R/8u1du3mBDdTrNTiHRBjYFGQEh1iPP/j9RxrxGMINn7TuHVwk3MItaURbXGSR0m8CptqxQTARXgUZFNnbbhD7m3u3AqJLGXSDtxAE4HqOgrIEVC4Gc5eFijwI+xMLVZSOlkDADN4eMwCZQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Julien Grall <jgrall@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 15 Aug 2022 14:45:41 +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;
  • Thread-index: AQHYroFCs26JN7h8TUSY3teW0vzrLK2wDkCA
  • Thread-topic: [PATCH 2/7] xen/arm64: head: Introduce get_table_slot() and use it

Hi Julien,

> On 12 Aug 2022, at 20:24, Julien Grall <julien@xxxxxxx> 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>
Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

> 
> ----
> 
>    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
> +

Crawling through the macros to verify the code was not that easy.
This is not related to this patch but XEN_PT_* macros could really do with more 
comments.

Cheers
Bertrand

> /*
>  * 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
> 
> -- 
> 2.37.1
> 




 


Rackspace

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