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

[Minios-devel] [UNIKRAFT PATCHv4 22/23] plat/kvm: arm64: Ensure there is no stall data in cache when boot



From: Wei Chen <wei.chen@xxxxxxx>

We will disable MMU and CACHE before pagetable is ready. This
means we will change memory with cache disabled, so we need to
invalidate the cache to ensure there is no stall data in it.
But we don't know the size of the RAM either. And it would be
expensive to invalidate the whole cache. In this case, just
just need to invalidate what we are going to use:
DTB, TEXT, DATA, BSS, pagetables and bootstack.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Signed-off-by: Jia He <justin.he@xxxxxxx>
Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
Reviewed-by: Julien Grall <julien.grall@xxxxxxx>
---
 plat/kvm/arm/entry64.S | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/plat/kvm/arm/entry64.S b/plat/kvm/arm/entry64.S
index 12201a9..ff63ee0 100644
--- a/plat/kvm/arm/entry64.S
+++ b/plat/kvm/arm/entry64.S
@@ -72,14 +72,34 @@ ENTRY(_libkvmplat_entry)
        add x17, x17, #L1_TABLE_SIZE
        add x17, x17, #L2_TABLE_SIZE
 
+       /*
+        * We will disable MMU and CACHE before pagetable is ready. This
+        * means we will change memory with cache disabled, so we need to
+        * invalidate the cache to ensure there is no stall data in it.
+        * But we don't know the size of the RAM either. And it would be
+        * expensive to invalidate the whole cache. In this case, just
+        * just need to invalidate what we are going to use:
+        * DTB, TEXT, DATA, BSS, pagetables and bootstack.
+        */
+       add x27, x26, x17
+       add x27, x27, #__STACK_SIZE
+       sub x1, x27, x25
+       bl clean_and_invalidate_dcache_range
+
+       /* Disable the MMU and D-Cache. */
+       dsb sy
+       mrs x2, sctlr_el1
+       mov x3, #SCTLR_M|SCTLR_C
+       bic x2, x2, x3
+       msr sctlr_el1, x2
+       isb
+
        /*
         * Clean the boot stack and page table. As _end, PAGE_TABLE_SIZE and
         * BOOT_STACK_SIZE are page_size alignment, the boot stack can be
         * 64-bytes alignment too. Execute 4 stp consecutively without boundary
         * check would be safe here.
         */
-       add x27, x26, x17
-       add x27, x27, #__STACK_SIZE
 1:
        stp xzr, xzr, [x26], #16
        stp xzr, xzr, [x26], #16
@@ -90,19 +110,6 @@ ENTRY(_libkvmplat_entry)
 
        mov sp, x27
 
-       /*
-        * Disable the MMU. We may have entered the kernel with it on and
-        * will need to update the tables later. If this has been set up
-        * with anything other than a VA == PA map then this will fail,
-        * but in this case the code to find where we are running from
-        * would have also failed.
-        */
-       dsb sy
-       mrs x2, sctlr_el1
-       bic x2, x2, #SCTLR_M
-       msr sctlr_el1, x2
-       isb
-
        /* Set the context id */
        msr contextidr_el1, xzr
 
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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