Skip to contentSkip to conversation

xen/arm: Add some missing ISBs after updating the PTEs

PATCH In review Julien Grall 5 participants 31 messages Jun 19, 2023 – Jul 4, 2023

lore
Share & tools
lore
#0 lore raw

cover xen/arm: Add some missing ISBs after updating the PTEs

From: Julien Grall <[email protected]>

Hi all,

The main goal of this series is to add some missing ISBs after update the PTEs.

The last patch is re-ingesting a patch that was reverted due to a boot failure on the Arndale. This has now been fixed by patch #2.

Cheers,

Julien Grall (7):
xen/arm32: head: Add missing isb in setup_fixmap() xen/arm32: head: Add mising isb in switch_to_runtime_mapping() xen/arm64: head: Add missing isb in setup_fixmap() xen/arm: page: Consolidate write_pte() and clarify the documentation xen/arm: pmap: Add missing ISB in arch_pmap_map() xen/arm: mm: Add missing ISB in xen_pt_update() xen/arm32: head: Widen the use of the temporary mapping

 xen/arch/arm/arm32/head.S             | 96 ++++++++-------------------
 xen/arch/arm/arm64/head.S             |  5 ++
 xen/arch/arm/include/asm/arm32/page.h | 16 -----
 xen/arch/arm/include/asm/arm64/page.h | 11 ---
 xen/arch/arm/include/asm/page.h       | 17 +++++
 xen/arch/arm/include/asm/pmap.h       |  5 ++
 xen/arch/arm/mm.c                     | 14 ++++
 7 files changed, 67 insertions(+), 97 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/7 xen/arm32: head: Add missing isb in setup_fixmap()

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes e79999e587d7 ("xen/arm32: head: Remove 1:1 mapping as soon as it is not used")
---
 xen/arch/arm/arm32/head.S | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/arm/arm32/head.S +5 -0
index f9f7be9588b1..6ca3329138e3 100644
@@ -751,6 +751,11 @@ setup_fixmap:
         create_table_entry boot_second, xen_fixmap, r0, 2
         /* Ensure any page table updates made above have occurred. */
         dsb   nshst
+        /*
+         * The fixmap area will be used soon after. So ensure no hardware
+         * translation happens before the dsb completes.
+         */
+        isb
 
         mov   pc, lr
 ENDPROC(setup_fixmap)
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 1/7
#2 lore raw

RE: [PATCH 1/7] xen/arm32: head: Add missing isb in setup_fixmap()

Hi Julien,

Quoted 13 lines

-----Original Message-----
Subject: [PATCH 1/7] xen/arm32: head: Add missing isb in setup_fixmap()

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Quoted 8 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes e79999e587d7 ("xen/arm32: head: Remove 1:1 mapping as soon as it is

not used")

I've also tested this patch on top of today's staging by our internal CI, which includes the FVP arm32 mode and qemu-arm32. Our CI says this patch looks good, so:

Kind regards,
Henry

Reviewed-by on v1 1/7
#3 lore raw

Re: [PATCH 1/7] xen/arm32: head: Add missing isb in setup_fixmap()

In reply to Julien Grall
Quoted 14 lines · Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Quoted 8 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes e79999e587d7 ("xen/arm32: head: Remove 1:1 mapping as soon as it is not used")

---

Hi Julien,

Yeah makes sense!

Reviewed-by on v1 1/7
#4 lore raw

Re: [PATCH 1/7] xen/arm32: head: Add missing isb in setup_fixmap()

In reply to Julien Grall

Hi Julien,

Quoted 12 lines · Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Quoted 7 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes e79999e587d7 ("xen/arm32: head: Remove 1:1 mapping as soon as it is not used")

Cheers
Bertrand

Quoted 23 lines

---
xen/arch/arm/arm32/head.S | 5 +++++

1 file changed, 5 insertions(+)
xen/arch/arm/arm32/head.S +5 -0
index f9f7be9588b1..6ca3329138e3 100644
@@ -751,6 +751,11 @@ setup_fixmap:
        create_table_entry boot_second, xen_fixmap, r0, 2
        /* Ensure any page table updates made above have occurred. */
        dsb   nshst
+        /*
+         * The fixmap area will be used soon after. So ensure no hardware
+         * translation happens before the dsb completes.
+         */
+        isb
 
        mov   pc, lr
 ENDPROC(setup_fixmap)
Signature · 1 line
2.40.1
#5 lore raw

PATCH 2/7 xen/arm32: head: Add mising isb in switch_to_runtime_mapping()

In reply to Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

The function switch_to_runtime_mapping() is responsible to map the Xen at its runtime address if we were using the temporary area before jumping returning using a runtime address. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes fbd9b5fb4c26 ("xen/arm32: head: Remove restriction where to load Xen")
---
 xen/arch/arm/arm32/head.S | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/arm/arm32/head.S +5 -0
index 6ca3329138e3..b942e7e54d08 100644
@@ -656,6 +656,11 @@ switch_to_runtime_mapping:
 
         /* Ensure any page table updates are visible before continuing */
         dsb   nsh
+        /*
+         * The function will return on the runtime mapping. So we want
+         * to prevent instruction fetch before the dsb completes.
+         */
+        isb
 
 ready_to_switch:
         mov   pc, lr
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 2/7
#6 lore raw

RE: [PATCH 2/7] xen/arm32: head: Add mising isb in switch_to_runtime_mapping()

Hi Julien,

Quoted 14 lines

-----Original Message-----
Subject: [PATCH 2/7] xen/arm32: head: Add mising isb in switch_to_runtime_mapping()

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Quoted 8 lines

The function switch_to_runtime_mapping() is responsible to map the Xen at its runtime address if we were using the temporary area before jumping returning using a runtime address. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes fbd9b5fb4c26 ("xen/arm32: head: Remove restriction where to load

Xen")

I've also tested this patch on top of today's staging by our internal CI, and this patch looks good, so:

Kind regards,
Henry

Reviewed-by on v1 2/7
#7 lore raw

Re: [PATCH 2/7] xen/arm32: head: Add mising isb in switch_to_runtime_mapping()

In reply to Julien Grall
Quoted 14 lines · Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Quoted 7 lines

The function switch_to_runtime_mapping() is responsible to map the Xen at its runtime address if we were using the temporary area before jumping returning using a runtime address. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes fbd9b5fb4c26 ("xen/arm32: head: Remove restriction where to load Xen")
Reviewed-by on v1 2/7
#8 lore raw

Re: [PATCH 2/7] xen/arm32: head: Add mising isb in switch_to_runtime_mapping()

In reply to Julien Grall

Hi Julien,

Quoted 12 lines · Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm (ARM DDI 0406C.d A3.8.3):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Quoted 7 lines

The function switch_to_runtime_mapping() is responsible to map the Xen at its runtime address if we were using the temporary area before jumping returning using a runtime address. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes fbd9b5fb4c26 ("xen/arm32: head: Remove restriction where to load Xen")

Cheers
Bertrand

Quoted 23 lines

---
xen/arch/arm/arm32/head.S | 5 +++++

1 file changed, 5 insertions(+)
xen/arch/arm/arm32/head.S +5 -0
index 6ca3329138e3..b942e7e54d08 100644
@@ -656,6 +656,11 @@ switch_to_runtime_mapping:
 
        /* Ensure any page table updates are visible before continuing */
        dsb   nsh
+        /*
+         * The function will return on the runtime mapping. So we want
+         * to prevent instruction fetch before the dsb completes.
+         */
+        isb
 

ready_to_switch:
mov pc, lr

Signature · 1 line
2.40.1
#9 lore raw

PATCH 3/7 xen/arm64: head: Add missing isb in setup_fixmap()

In reply to Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")
---
 xen/arch/arm/arm64/head.S | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/arm/arm64/head.S +5 -0
index f37133cf7ccd..4ea64e70997b 100644
@@ -769,6 +769,11 @@ setup_fixmap:
         create_table_entry boot_second, xen_fixmap, x0, 2, x1, x2, x3
         /* Ensure any page table updates made above have occurred. */
         dsb   nshst
+        /*
+         * The fixmap area will be used soon after. So ensure no hardware
+         * translation happens before the dsb completes.
+         */
+        isb
 
         ret
 ENDPROC(setup_fixmap)
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 3/7
#10 lore raw

RE: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

Hi Julien,

Quoted 18 lines

-----Original Message-----
Subject: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

Quoted 8 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is

not used")

I've also tested this patch on top of today's staging by our internal CI, which includes some arm64 emulated platforms and also real hardware, and this patch looks good, so:

Kind regards,
Henry

Reviewed-by on v1 3/7
#11 lore raw

Re: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

In reply to Julien Grall
Quoted 19 lines · Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

Quoted 7 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")
Reviewed-by on v1 3/7
#12 lore raw

Re: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

In reply to Julien Grall
Quoted 17 lines · Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

Quoted 7 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")

I'm happy with the whole series but I do not see a point in flooding each patch with my tag since you already got two (from Henry and Luca).

When it comes to essential isb() after dsb() in arm64 head.S, I can see that we are missing one in enable_mmu() after TLB invalidation. On HW without FEAT_ETS the TLB is "guaranteed to be complete after the execution of DSB by that PE, followed by a Context synchronization event", so I view isb as necessary there. We could also introduce (just like for arm32) flush_xen_tlb_local macro and use it there + remove opencoding it.

~Michal

#13 lore raw

Re: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

Hi,

Quoted 25 lines · Michal Orzel
Quoted 22 lines · Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Quoted 6 lines
Quoted 2 lines
Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")

I'm happy with the whole series but I do not see a point in flooding each patch with my tag since you already got two (from Henry and Luca).

Thanks. To clarify, shall I add it in each patch or only this one?

Quoted 4 lines

When it comes to essential isb() after dsb() in arm64 head.S, I can see that we are missing one in enable_mmu() after TLB invalidation. On HW without FEAT_ETS the TLB is "guaranteed to be complete after the execution of DSB by that PE, followed by a Context synchronization event", so I view isb as necessary there.

While there is no ISB directly after DSB NSH, there are one right after MSR. I don't think we need one before because nothing will use the TLBs between before the ISB.

/*
* The state of the TLBs is unknown before turning on the MMU.
* Flush them to avoid stale one.
*/
tlbi alle2 /* Flush hypervisor TLBs */
dsb nsh

/* Write Xen's PT's paddr into TTBR0_EL2 */ load_paddr x0, boot_pgtable
msr TTBR0_EL2, x0
isb

Quoted 2 lines

We could also
introduce (just like for arm32) flush_xen_tlb_local macro and use it there + remove opencoding it.

That would be good. But I don't think this is necessary here (see above).

Cheers,

Signature · 1 line
Julien Grall
#14 lore raw

Re: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

Quoted 30 lines · Julien Grall

Hi,

Quoted 25 lines · Michal Orzel
Quoted 22 lines · Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")

I'm happy with the whole series but I do not see a point in flooding each patch with my tag since you already got two (from Henry and Luca).

Thanks. To clarify, shall I add it in each patch or only this one?

Whatever you prefer. If you care about my tag and want to have more than two, feel free to add it to all the patches.

Quoted 17 lines
Quoted 5 lines

When it comes to essential isb() after dsb() in arm64 head.S, I can see that we are missing one in enable_mmu() after TLB invalidation. On HW without FEAT_ETS the TLB is "guaranteed to be complete after the execution of DSB by that PE, followed by a Context synchronization event", so I view isb as necessary there.

While there is no ISB directly after DSB NSH, there are one right after MSR. I don't think we need one before because nothing will use the TLBs between before the ISB.

/*
* The state of the TLBs is unknown before turning on the MMU.
* Flush them to avoid stale one.
*/
tlbi alle2 /* Flush hypervisor TLBs */
dsb nsh

Quoted 5 lines

/* Write Xen's PT's paddr into TTBR0_EL2 */ load_paddr x0, boot_pgtable
msr TTBR0_EL2, x0
isb

Although having isb after dsb would be clearer to the user and consistent with other TBL invalidations, the one after msr can do the job for now, I agree.

~Michal

#15 lore raw

Re: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

Hi,

Quoted 35 lines · Michal Orzel
Quoted 32 lines · Julien Grall

Hi,

Quoted 27 lines · Michal Orzel
Quoted 24 lines · Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I'm happy with the whole series but I do not see a point in flooding each patch with my tag since you already got two (from Henry and Luca).

Thanks. To clarify, shall I add it in each patch or only this one?

Whatever you prefer. If you care about my tag and want to have more than two, feel free to add it to all the patches.

Ok. I will not then because I need to add the ack manually.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v1 3/7
#16 lore raw

Re: [PATCH 3/7] xen/arm64: head: Add missing isb in setup_fixmap()

In reply to Julien Grall

Hi Julien,

Quoted 17 lines · Julien Grall

From: Julien Grall <[email protected]>

On older version of the Arm Arm (ARM DDI 0487E.a, B2-125) there were the following paragraph:

"DMB and DSB instructions affect reads and writes to the memory system generated by Load/Store instructions and data or unified cache maintenance instructions being executed by the PE. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Newer revision (e.g. ARM DDI 0487J.a) doesn't have the second sentence (it might be somewhere else in the Arm Arm). But the interpretation is not much different.

Quoted 7 lines

In setup_fixmap(), we write the fixmap area and may be used soon after, for instance, to write to the UART. IOW, there could be hardware translation table access. So we need to ensure the 'dsb' has completed before continuing. Therefore add an 'isb'.

Fixes 2b11c3646105 ("xen/arm64: head: Remove 1:1 mapping as soon as it is not used")

Cheers
Bertrand

Quoted 23 lines

---
xen/arch/arm/arm64/head.S | 5 +++++

1 file changed, 5 insertions(+)
xen/arch/arm/arm64/head.S +5 -0
index f37133cf7ccd..4ea64e70997b 100644
@@ -769,6 +769,11 @@ setup_fixmap:
        create_table_entry boot_second, xen_fixmap, x0, 2, x1, x2, x3
        /* Ensure any page table updates made above have occurred. */
        dsb   nshst
+        /*
+         * The fixmap area will be used soon after. So ensure no hardware
+         * translation happens before the dsb completes.
+         */
+        isb
 
        ret
 ENDPROC(setup_fixmap)
Signature · 1 line
2.40.1
#17 lore raw

PATCH 4/7 xen/arm: page: Consolidate write_pte() and clarify the documentation

In reply to Julien Grall

From: Julien Grall <[email protected]>

The implementation of write_pte() is pretty much the same on arm32 and arm64. So it would be good to consolidate it as this would help to clarify the requirements when using the helper.

Take the opportunity to switch from assembly to call macros. Note there is a difference on arm32 because the option was not specified. But this meant 'sy' (system wide).

Futhermore, the requirements for the ISB is incomplete. Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12), DSB will only affect explicit accesses. So an ISB is necessary after DSB to ensure the completion. Having an ISB after each update to the page-tables is probably too much, so let the caller add the instruction when it is convenient.

Lastly, the barrier in write_pte() may be too restrictive but I haven't yet find the proper section(s) in the Arm Arm.

----

I am a bit split on whether we should add an ISB in write_pte(). It would make easier for the developper, but would likely force a pipeline flush too often.

It might also be possible to drop the ISB (and even DSB) when updating stage-2 PTE (Linux already does it, see 120798d2e7d1). But I am not sure this is worth it in Xen.

---
 xen/arch/arm/include/asm/arm32/page.h | 16 ----------------
 xen/arch/arm/include/asm/arm64/page.h | 11 -----------
 xen/arch/arm/include/asm/page.h       | 17 +++++++++++++++++
 3 files changed, 17 insertions(+), 27 deletions(-)
xen/arch/arm/include/asm/arm32/page.h +0 -16
index 715a9e4fef48..6d1ff0636ce3 100644
@@ -3,22 +3,6 @@
 
 #ifndef __ASSEMBLY__
 
-/* Write a pagetable entry.
- *
- * If the table entry is changing a text mapping, it is responsibility
- * of the caller to issue an ISB after write_pte.
- */
-static inline void write_pte(lpae_t *p, lpae_t pte)
-{
-    asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb;"
-        /* Safely write the entry (STRD is atomic on CPUs that support LPAE) */
-        "strd %0, %H0, [%1];"
-        "dsb;"
-        : : "r" (pte.bits), "r" (p) : "memory");
-}
-
 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
 #define __invalidate_dcache_one(R) STORE_CP32(R, DCIMVAC)
 
xen/arch/arm/include/asm/arm64/page.h +0 -11
index 0cba2663733b..4f58c0382adc 100644
@@ -5,17 +5,6 @@
 
 #include <asm/alternative.h>
 
-/* Write a pagetable entry */
-static inline void write_pte(lpae_t *p, lpae_t pte)
-{
-    asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb sy;"
-        "str %0, [%1];"         /* Write the entry */
-        "dsb sy;"
-        : : "r" (pte.bits), "r" (p) : "memory");
-}
-
 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
 #define __invalidate_dcache_one(R) "dc ivac, %" #R ";"
 
xen/arch/arm/include/asm/page.h +17 -0
index e7cd62190c7f..ea96983ab976 100644
@@ -126,6 +126,7 @@
 #include <xen/errno.h>
 #include <xen/types.h>
 #include <xen/lib.h>
+#include <asm/atomic.h>
 #include <asm/system.h>
 
 #if defined(CONFIG_ARM_32)
@@ -237,6 +238,22 @@ static inline int clean_and_invalidate_dcache_va_range
             : : "r" (_p), "m" (*_p));                                   \
 } while (0)
 
+/*
+ * Write a pagetable entry.
+ *
+ * It is the responsibility of the caller to issue an ISB (if a new entry)
+ * or a TLB flush (if modified or removed) after write_pte().
+ */
+static inline void write_pte(lpae_t *p, lpae_t pte)
+{
+    /* Ensure any writes have completed with the old mappings. */
+    dsb(sy);
+    /* Safely write the entry. This should always be an atomic write. */
+    write_atomic(p, pte);
+    dsb(sy);
+}
+
+
 /* Flush the dcache for an entire page. */
 void flush_page_to_ram(unsigned long mfn, bool sync_icache);
 
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 4/7
#18 lore raw

RE: [PATCH 4/7] xen/arm: page: Consolidate write_pte() and clarify the documentation

Hi Julien,

Quoted 21 lines

-----Original Message-----
Subject: [PATCH 4/7] xen/arm: page: Consolidate write_pte() and clarify the documentation

From: Julien Grall <[email protected]>

The implementation of write_pte() is pretty much the same on arm32 and arm64. So it would be good to consolidate it as this would help to clarify the requirements when using the helper.

Take the opportunity to switch from assembly to call macros. Note there is a difference on arm32 because the option was not specified. But this meant 'sy' (system wide).

Futhermore, the requirements for the ISB is incomplete. Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12), DSB will only affect explicit accesses. So an ISB is necessary after DSB to ensure the completion. Having an ISB after each update to the page-tables is probably too much, so let the caller add the instruction when it is convenient.

Quoted 4 lines

Lastly, the barrier in write_pte() may be too restrictive but I haven't yet find the proper section(s) in the Arm Arm.

I've also tested this patch on top of today's staging by our internal CI, and this patch looks good, so:

Kind regards,
Henry

Reviewed-by on v1 4/7
#19 lore raw

Re: [PATCH 4/7] xen/arm: page: Consolidate write_pte() and clarify the documentation

In reply to Julien Grall

Hi Julien,

Quoted 19 lines · Julien Grall

From: Julien Grall <[email protected]>

The implementation of write_pte() is pretty much the same on arm32 and arm64. So it would be good to consolidate it as this would help to clarify the requirements when using the helper.

Take the opportunity to switch from assembly to call macros. Note there is a difference on arm32 because the option was not specified. But this meant 'sy' (system wide).

Futhermore, the requirements for the ISB is incomplete. Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12), DSB will only affect explicit accesses. So an ISB is necessary after DSB to ensure the completion. Having an ISB after each update to the page-tables is probably too much, so let the caller add the instruction when it is convenient.

Quoted 2 lines

Lastly, the barrier in write_pte() may be too restrictive but I haven't yet find the proper section(s) in the Arm Arm.

I do not think we will find any proper section for that in the Arm Arm as it depends on use cases.
In ours we might have the page table shared among cores so I think system is the way to go.

Quoted 2 lines

Cheers
Bertrand

Quoted 102 lines

----

I am a bit split on whether we should add an ISB in write_pte(). It would make easier for the developper, but would likely force a pipeline flush too often.

It might also be possible to drop the ISB (and even DSB) when updating stage-2 PTE (Linux already does it, see 120798d2e7d1). But I am not sure this is worth it in Xen.
---

xen/arch/arm/include/asm/arm32/page.h | 16 ----------------
xen/arch/arm/include/asm/arm64/page.h | 11 -----------
xen/arch/arm/include/asm/page.h       | 17 +++++++++++++++++
3 files changed, 17 insertions(+), 27 deletions(-)
xen/arch/arm/include/asm/arm32/page.h +0 -16
index 715a9e4fef48..6d1ff0636ce3 100644
@@ -3,22 +3,6 @@
 
 #ifndef __ASSEMBLY__
 
-/* Write a pagetable entry.
- *
- * If the table entry is changing a text mapping, it is responsibility
- * of the caller to issue an ISB after write_pte.
- */
-static inline void write_pte(lpae_t *p, lpae_t pte)
-{
-    asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb;"
-        /* Safely write the entry (STRD is atomic on CPUs that support LPAE) */
-        "strd %0, %H0, [%1];"
-        "dsb;"
-        : : "r" (pte.bits), "r" (p) : "memory");
-}
-
 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
 #define __invalidate_dcache_one(R) STORE_CP32(R, DCIMVAC)
 
xen/arch/arm/include/asm/arm64/page.h +0 -11
index 0cba2663733b..4f58c0382adc 100644
@@ -5,17 +5,6 @@
 
 #include <asm/alternative.h>
 
-/* Write a pagetable entry */
-static inline void write_pte(lpae_t *p, lpae_t pte)
-{
-    asm volatile (
-        /* Ensure any writes have completed with the old mappings. */
-        "dsb sy;"
-        "str %0, [%1];"         /* Write the entry */
-        "dsb sy;"
-        : : "r" (pte.bits), "r" (p) : "memory");
-}
-
 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
 #define __invalidate_dcache_one(R) "dc ivac, %" #R ";"
 
xen/arch/arm/include/asm/page.h +17 -0
index e7cd62190c7f..ea96983ab976 100644
@@ -126,6 +126,7 @@
 #include <xen/errno.h>
 #include <xen/types.h>
 #include <xen/lib.h>
+#include <asm/atomic.h>
 #include <asm/system.h>
 
 #if defined(CONFIG_ARM_32)
@@ -237,6 +238,22 @@ static inline int clean_and_invalidate_dcache_va_range
            : : "r" (_p), "m" (*_p));                                   \
 } while (0)
 
+/*
+ * Write a pagetable entry.
+ *
+ * It is the responsibility of the caller to issue an ISB (if a new entry)
+ * or a TLB flush (if modified or removed) after write_pte().
+ */
+static inline void write_pte(lpae_t *p, lpae_t pte)
+{
+    /* Ensure any writes have completed with the old mappings. */
+    dsb(sy);
+    /* Safely write the entry. This should always be an atomic write. */
+    write_atomic(p, pte);
+    dsb(sy);
+}
+
+
 /* Flush the dcache for an entire page. */
 void flush_page_to_ram(unsigned long mfn, bool sync_icache);
 
Signature · 1 line
2.40.1
#20 lore raw

Re: [PATCH 4/7] xen/arm: page: Consolidate write_pte() and clarify the documentation

Hi Bertrand,

Quoted 19 lines · Bertrand Marquis
Quoted 19 lines · Julien Grall

From: Julien Grall <[email protected]>

The implementation of write_pte() is pretty much the same on arm32 and arm64. So it would be good to consolidate it as this would help to clarify the requirements when using the helper.

Take the opportunity to switch from assembly to call macros. Note there is a difference on arm32 because the option was not specified. But this meant 'sy' (system wide).

Futhermore, the requirements for the ISB is incomplete. Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12), DSB will only affect explicit accesses. So an ISB is necessary after DSB to ensure the completion. Having an ISB after each update to the page-tables is probably too much, so let the caller add the instruction when it is convenient.

Quoted 7 lines
Quoted 2 lines

Lastly, the barrier in write_pte() may be too restrictive but I haven't yet find the proper section(s) in the Arm Arm.

I do not think we will find any proper section for that in the Arm Arm as it depends on use cases.
In ours we might have the page table shared among cores so I think system is the way to go.

For SMP systems, like Linux, Xen is assuming that all the cores are in the same inner-shareable domain. So 'ish' would be sufficient based on just that.

However, I haven't made the change because I am not sure about the interaction when the modified entry modified to device memory and we have an access after/before.

Quoted 5 lines
Quoted 3 lines

Thanks!

Cheers,

Signature · 1 line
Julien Grall
#21 lore raw

PATCH 5/7 xen/arm: pmap: Add missing ISB in arch_pmap_map()

In reply to Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Note that second sentence is not part of the newer Armv8 spec. But the interpretation is not much different.

As the entry created by arch_pmap_map() will be used soon after pmap_map() returns, we want to ensure the DSB in write_pte() has completed. So add an ISB.

Fixes 4f17357b52f6 ("xen/arm: add Persistent Map (PMAP) infrastructure")
---
 xen/arch/arm/include/asm/pmap.h | 5 +++++
 1 file changed, 5 insertions(+)
xen/arch/arm/include/asm/pmap.h +5 -0
index e094d13dd282..bca3381796f3 100644
@@ -15,6 +15,11 @@ static inline void arch_pmap_map(unsigned int slot, mfn_t mfn)
     pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW);
     pte.pt.table = 1;
     write_pte(entry, pte);
+    /*
+     * The new entry will be used very soon after arch_pmap_map() returns.
+     * So ensure the DSB in write_pte() has completed before continuing.
+     */
+    isb();
 }
 
 static inline void arch_pmap_unmap(unsigned int slot)
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 5/7
#22 lore raw

RE: [PATCH 5/7] xen/arm: pmap: Add missing ISB in arch_pmap_map()

Hi Julien,

Quoted 16 lines

-----Original Message-----
Subject: [PATCH 5/7] xen/arm: pmap: Add missing ISB in arch_pmap_map()

From: Julien Grall <[email protected]>

Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Note that second sentence is not part of the newer Armv8 spec. But the interpretation is not much different.

Quoted 6 lines

As the entry created by arch_pmap_map() will be used soon after pmap_map() returns, we want to ensure the DSB in write_pte() has completed. So add an ISB.

Fixes 4f17357b52f6 ("xen/arm: add Persistent Map (PMAP) infrastructure")

I've also tested this patch on top of today's staging by our internal CI, and this patch looks good, so:

Kind regards,
Henry

Reviewed-by on v1 5/7
#23 lore raw

Re: [PATCH 5/7] xen/arm: pmap: Add missing ISB in arch_pmap_map()

In reply to Julien Grall

Hi Julien,

Quoted 15 lines · Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Note that second sentence is not part of the newer Armv8 spec. But the interpretation is not much different.

Quoted 6 lines

As the entry created by arch_pmap_map() will be used soon after pmap_map() returns, we want to ensure the DSB in write_pte() has completed. So add an ISB.

Fixes 4f17357b52f6 ("xen/arm: add Persistent Map (PMAP) infrastructure")

Cheers
Bertrand

Quoted 23 lines

---
xen/arch/arm/include/asm/pmap.h | 5 +++++

1 file changed, 5 insertions(+)
xen/arch/arm/include/asm/pmap.h +5 -0
index e094d13dd282..bca3381796f3 100644
@@ -15,6 +15,11 @@ static inline void arch_pmap_map(unsigned int slot, mfn_t mfn)
    pte = mfn_to_xen_entry(mfn, PAGE_HYPERVISOR_RW);
    pte.pt.table = 1;
    write_pte(entry, pte);
+    /*
+     * The new entry will be used very soon after arch_pmap_map() returns.
+     * So ensure the DSB in write_pte() has completed before continuing.
+     */
+    isb();
 }
 
 static inline void arch_pmap_unmap(unsigned int slot)
Signature · 1 line
2.40.1
#24 lore raw

PATCH 6/7 xen/arm: mm: Add missing ISB in xen_pt_update()

In reply to Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Note that second sentence is not part of the newer Armv8 spec. But the interpretation is not much different.

The updated entry will not be used until xen_pt_update() completes. So rather than adding the ISB after write_pte() in create_xen_table() and xen_pt-update_entry(), add it in xen_pt_update().

Also document the reasoning of the deferral after each write_pte() calls.

Fixes 07d11f63d03e ("xen/arm: mm: Avoid flushing the TLBs when mapping are inserted")
---
 xen/arch/arm/mm.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
xen/arch/arm/mm.c +14 -0
index e460249736c3..84e652799dd2 100644
@@ -779,6 +779,11 @@ static int create_xen_table(lpae_t *entry)
     pte = mfn_to_xen_entry(mfn, MT_NORMAL);
     pte.pt.table = 1;
     write_pte(entry, pte);
+    /*
+     * No ISB here. It is deferred to xen_pt_update() as the new table
+     * will not be used for hardware translation table access as part of
+     * the mapping update.
+     */
 
     return 0;
 }
@@ -1017,6 +1022,10 @@ static int xen_pt_update_entry(mfn_t root, unsigned long virt,
     }
 
     write_pte(entry, pte);
+    /*
+     * No ISB or TLB flush here. They are deferred to xen_pt_update()
+     * as the entry will not be used as part of the mapping update.
+     */
 
     rc = 0;
 
@@ -1196,6 +1205,9 @@ static int xen_pt_update(unsigned long virt,
     /*
      * The TLBs flush can be safely skipped when a mapping is inserted
      * as we don't allow mapping replacement (see xen_pt_check_entry()).
+     * Although we still need an ISB to ensure any DSB in
+     * write_pte() will complete because the mapping may be used soon
+     * after.
      *
      * For all the other cases, the TLBs will be flushed unconditionally
      * even if the mapping has failed. This is because we may have
@@ -1204,6 +1216,8 @@ static int xen_pt_update(unsigned long virt,
      */
     if ( !((flags & _PAGE_PRESENT) && !mfn_eq(mfn, INVALID_MFN)) )
         flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns);
+    else
+        isb();
 
     spin_unlock(&xen_pt_lock);
 
Signature · 1 line
2.40.1
Reviewed-by Tested-by on v1 6/7
#25 lore raw

RE: [PATCH 6/7] xen/arm: mm: Add missing ISB in xen_pt_update()

Hi Julien,

Quoted 20 lines

-----Original Message-----
Subject: [PATCH 6/7] xen/arm: mm: Add missing ISB in xen_pt_update()

From: Julien Grall <[email protected]>

Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Note that second sentence is not part of the newer Armv8 spec. But the interpretation is not much different.

The updated entry will not be used until xen_pt_update() completes. So rather than adding the ISB after write_pte() in create_xen_table() and xen_pt-update_entry(), add it in xen_pt_update().

Quoted 5 lines

Also document the reasoning of the deferral after each write_pte() calls.

Fixes 07d11f63d03e ("xen/arm: mm: Avoid flushing the TLBs when mapping

are inserted")

I've also tested this patch on top of today's staging by our internal CI, and this patch looks good, so:

Kind regards,
Henry

Reviewed-by on v1 6/7
#26 lore raw

Re: [PATCH 6/7] xen/arm: mm: Add missing ISB in xen_pt_update()

In reply to Julien Grall

Hi Julien,

Quoted 15 lines · Julien Grall

From: Julien Grall <[email protected]>

Per the Arm Arm, (Armv7 DDI406C.d A3.8.3 and Armv8 DDI 0487J.a B2.3.12):

"The DMB and DSB memory barriers affect reads and writes to the memory system generated by load/store instructions and data or unified cache maintenance operations being executed by the processor. Instruction fetches or accesses caused by a hardware translation table access are not explicit accesses."

Note that second sentence is not part of the newer Armv8 spec. But the interpretation is not much different.

Quoted 8 lines

The updated entry will not be used until xen_pt_update() completes. So rather than adding the ISB after write_pte() in create_xen_table() and xen_pt-update_entry(), add it in xen_pt_update().

Also document the reasoning of the deferral after each write_pte() calls.

Fixes 07d11f63d03e ("xen/arm: mm: Avoid flushing the TLBs when mapping are inserted")

Cheers
Bertrand

Quoted 53 lines

---
xen/arch/arm/mm.c | 14 ++++++++++++++

1 file changed, 14 insertions(+)
xen/arch/arm/mm.c +14 -0
index e460249736c3..84e652799dd2 100644
@@ -779,6 +779,11 @@ static int create_xen_table(lpae_t *entry)
    pte = mfn_to_xen_entry(mfn, MT_NORMAL);
    pte.pt.table = 1;
    write_pte(entry, pte);
+    /*
+     * No ISB here. It is deferred to xen_pt_update() as the new table
+     * will not be used for hardware translation table access as part of
+     * the mapping update.
+     */
 
    return 0;
 }
@@ -1017,6 +1022,10 @@ static int xen_pt_update_entry(mfn_t root, unsigned long virt,
    }
 
    write_pte(entry, pte);
+    /*
+     * No ISB or TLB flush here. They are deferred to xen_pt_update()
+     * as the entry will not be used as part of the mapping update.
+     */
 
    rc = 0;
 
@@ -1196,6 +1205,9 @@ static int xen_pt_update(unsigned long virt,
    /*
     * The TLBs flush can be safely skipped when a mapping is inserted
     * as we don't allow mapping replacement (see xen_pt_check_entry()).
+     * Although we still need an ISB to ensure any DSB in
+     * write_pte() will complete because the mapping may be used soon
+     * after.
     *
     * For all the other cases, the TLBs will be flushed unconditionally
     * even if the mapping has failed. This is because we may have
@@ -1204,6 +1216,8 @@ static int xen_pt_update(unsigned long virt,
     */
    if ( !((flags & _PAGE_PRESENT) && !mfn_eq(mfn, INVALID_MFN)) )
        flush_xen_tlb_range_va(virt, PAGE_SIZE * nr_mfns);
+    else
+        isb();
 
    spin_unlock(&xen_pt_lock);
 
Signature · 1 line
2.40.1
#27 lore raw

PATCH 7/7 xen/arm32: head: Widen the use of the temporary mapping

In reply to Julien Grall

From: Julien Grall <[email protected]>

At the moment, the temporary mapping is only used when the virtual runtime region of Xen is clashing with the physical region.

In follow-up patches, we will rework how secondary CPU bring-up works and it will be convenient to use the fixmap area for accessing the root page-table (it is per-cpu).

Rework the code to use temporary mapping when the Xen physical address is not overlapping with the temporary mapping.

This also has the advantage to simplify the logic to identity map Xen.

----

This patch was originally part of [1] but it was reverted due to Xen not booting on the Arndale. The first patch of this series is fixing it (confirmed by booting on the Arndale). So I am including this patch. Also all the tags but the tested-by have been kept because the code has not changed. Happy to drop any if there are any concerns.

[1] https://lore.kernel.org/xen-devel/[email protected]/

Changelog from the previous series:

Changes in v6:
- Add Henry's reviewed-by and tested-by tag
- Add Michal's reviewed-by
- Add newline in remove_identity_mapping for clarity

Changes in v5:
- Fix typo in a comment
- No need to link boot_{second, third}_id again if we need to create a temporary area.

Changes in v3:
- Resolve conflicts after switching from "ldr rX, <label>" to "mov_w rX, <label>" in a previous patch

Changes in v2:
- Patch added

---
 xen/arch/arm/arm32/head.S | 86 ++++++++-------------------------------
 1 file changed, 16 insertions(+), 70 deletions(-)
xen/arch/arm/arm32/head.S +16 -70
index b942e7e54d08..d70e856ab7dd 100644
@@ -459,7 +459,6 @@ ENDPROC(cpu_init)
 create_page_tables:
         /* Prepare the page-tables for mapping Xen */
         mov_w r0, XEN_VIRT_START
-        create_table_entry boot_pgtable, boot_second, r0, 1
         create_table_entry boot_second, boot_third, r0, 2
 
         /* Setup boot_third: */
@@ -479,70 +478,37 @@ create_page_tables:
         cmp   r1, #(XEN_PT_LPAE_ENTRIES<<3) /* 512*8-byte entries per page */
         blo   1b
 
-        /*
-         * If Xen is loaded at exactly XEN_VIRT_START then we don't
-         * need an additional 1:1 mapping, the virtual mapping will
-         * suffice.
-         */
-        cmp   r9, #XEN_VIRT_START
-        moveq pc, lr
-
         /*
          * Setup the 1:1 mapping so we can turn the MMU on. Note that
          * only the first page of Xen will be part of the 1:1 mapping.
-         *
-         * In all the cases, we will link boot_third_id. So create the
-         * mapping in advance.
          */
+        create_table_entry boot_pgtable, boot_second_id, r9, 1
+        create_table_entry boot_second_id, boot_third_id, r9, 2
         create_mapping_entry boot_third_id, r9, r9
 
         /*
-         * Find the first slot used. If the slot is not XEN_FIRST_SLOT,
-         * then the 1:1 mapping will use its own set of page-tables from
-         * the second level.
+         * Find the first slot used. If the slot is not the same
+         * as TEMPORARY_AREA_FIRST_SLOT, then we will want to switch
+         * to the temporary mapping before jumping to the runtime
+         * virtual mapping.
          */
         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, 1
-        b     link_from_second_id
-
-1:
-        /*
-         * Find the second slot used. If the slot is XEN_SECOND_SLOT, then the
-         * 1:1 mapping will use its own set of page-tables from the
-         * third level.
-         */
-        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, 2
-        b     link_from_third_id
+        cmp   r1, #TEMPORARY_AREA_FIRST_SLOT
+        bne   use_temporary_mapping
 
-link_from_second_id:
-        create_table_entry boot_second_id, boot_third_id, r9, 2
-link_from_third_id:
-        /* Good news, we are not clashing with Xen virtual mapping */
+        mov_w r0, XEN_VIRT_START
+        create_table_entry boot_pgtable, boot_second, r0, 1
         mov   r12, #0                /* r12 := temporary mapping not created */
         mov   pc, lr
 
-virtphys_clash:
+use_temporary_mapping:
         /*
-         * The identity map clashes with boot_third. Link boot_first_id and
-         * map Xen to a temporary mapping. See switch_to_runtime_mapping
-         * for more details.
+         * The identity mapping is not using the first slot
+         * TEMPORARY_AREA_FIRST_SLOT. Create a temporary mapping.
+         * See switch_to_runtime_mapping for more details.
          */
-        PRINT("- Virt and Phys addresses clash  -\r\n")
         PRINT("- Create temporary mapping -\r\n")
 
-        /*
-         * This will override the link to boot_second in XEN_FIRST_SLOT.
-         * The page-tables are not live yet. So no need to use
-         * break-before-make.
-         */
-        create_table_entry boot_pgtable, boot_second_id, r9, 1
-        create_table_entry boot_second_id, boot_third_id, r9, 2
-
         /* Map boot_second (cover Xen mappings) to the temporary 1st slot */
         mov_w r0, TEMPORARY_XEN_VIRT_START
         create_table_entry boot_pgtable, boot_second, r0, 1
@@ -680,33 +646,13 @@ remove_identity_mapping:
         /* r2:r3 := invalid page-table entry */
         mov   r2, #0x0
         mov   r3, #0x0
-        /*
-         * Find the first slot used. Remove the entry for the first
-         * table if the slot is not XEN_FIRST_SLOT.
-         */
+
+        /* Find the first slot used and remove it */
         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 */
         mov_w r0, boot_pgtable       /* r0 := root table */
         lsl   r1, r1, #3             /* r1 := Slot offset */
         strd  r2, r3, [r0, r1]
-        b     identity_mapping_removed
-
-1:
-        /*
-         * Find the second slot used. Remove the entry for the first
-         * table if the slot is not XEN_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 */
-        mov_w r0, boot_second        /* r0 := second table */
-        lsl   r1, r1, #3             /* r1 := Slot offset */
-        strd  r2, r3, [r0, r1]
 
-identity_mapping_removed:
         flush_xen_tlb_local r0
         mov   pc, lr
 ENDPROC(remove_identity_mapping)
Signature · 1 line
2.40.1
Tested-by on v1 7/7
#28 lore raw

RE: [PATCH 7/7] xen/arm32: head: Widen the use of the temporary mapping

Hi Julien,

Quoted 16 lines

-----Original Message-----
Subject: [PATCH 7/7] xen/arm32: head: Widen the use of the temporary mapping

From: Julien Grall <[email protected]>

At the moment, the temporary mapping is only used when the virtual runtime region of Xen is clashing with the physical region.

In follow-up patches, we will rework how secondary CPU bring-up works and it will be convenient to use the fixmap area for accessing the root page-table (it is per-cpu).

Rework the code to use temporary mapping when the Xen physical address is not overlapping with the temporary mapping.

Quoted 6 lines

This also has the advantage to simplify the logic to identity map Xen.

I've tested this patch on top of today's staging by our internal CI, and this patch looks good, so:

Kind regards,
Henry

Acked-by on v1 7/7
#29 lore raw

Re: [PATCH 7/7] xen/arm32: head: Widen the use of the temporary mapping

In reply to Julien Grall

Hi Julien,

Quoted 14 lines · Julien Grall

From: Julien Grall <[email protected]>

At the moment, the temporary mapping is only used when the virtual runtime region of Xen is clashing with the physical region.

In follow-up patches, we will rework how secondary CPU bring-up works and it will be convenient to use the fixmap area for accessing the root page-table (it is per-cpu).

Rework the code to use temporary mapping when the Xen physical address is not overlapping with the temporary mapping.

Quoted 6 lines

This also has the advantage to simplify the logic to identity map Xen.

Cheers
Bertrand

Quoted 170 lines

----

This patch was originally part of [1] but it was reverted due to Xen not booting on the Arndale. The first patch of this series is fixing it (confirmed by booting on the Arndale). So I am including this patch. Also all the tags but the tested-by have been kept because the code has not changed. Happy to drop any if there are any concerns.

[1] https://lore.kernel.org/xen-devel/[email protected]/

Changelog from the previous series:

Changes in v6:
- Add Henry's reviewed-by and tested-by tag
- Add Michal's reviewed-by
- Add newline in remove_identity_mapping for clarity

Changes in v5:
- Fix typo in a comment
- No need to link boot_{second, third}_id again if we need to create a temporary area.

Changes in v3:
- Resolve conflicts after switching from "ldr rX, <label>" to "mov_w rX, <label>" in a previous patch

Changes in v2:
- Patch added
---
xen/arch/arm/arm32/head.S | 86 ++++++++-------------------------------

1 file changed, 16 insertions(+), 70 deletions(-)
xen/arch/arm/arm32/head.S +0 -0
index b942e7e54d08..d70e856ab7dd 100644
@@ -459,7 +459,6 @@ ENDPROC(cpu_init)

create_page_tables:
/* Prepare the page-tables for mapping Xen */ mov_w r0, XEN_VIRT_START

xen/arch/arm/arm32/head.S +16 -70
-        create_table_entry boot_pgtable, boot_second, r0, 1
        create_table_entry boot_second, boot_third, r0, 2
 
        /* Setup boot_third: */
@@ -479,70 +478,37 @@ create_page_tables:
        cmp   r1, #(XEN_PT_LPAE_ENTRIES<<3) /* 512*8-byte entries per page */
        blo   1b
 
-        /*
-         * If Xen is loaded at exactly XEN_VIRT_START then we don't
-         * need an additional 1:1 mapping, the virtual mapping will
-         * suffice.
-         */
-        cmp   r9, #XEN_VIRT_START
-        moveq pc, lr
-
        /*
         * Setup the 1:1 mapping so we can turn the MMU on. Note that
         * only the first page of Xen will be part of the 1:1 mapping.
-         *
-         * In all the cases, we will link boot_third_id. So create the
-         * mapping in advance.
         */
+        create_table_entry boot_pgtable, boot_second_id, r9, 1
+        create_table_entry boot_second_id, boot_third_id, r9, 2
        create_mapping_entry boot_third_id, r9, r9
 
        /*
-         * Find the first slot used. If the slot is not XEN_FIRST_SLOT,
-         * then the 1:1 mapping will use its own set of page-tables from
-         * the second level.
+         * Find the first slot used. If the slot is not the same
+         * as TEMPORARY_AREA_FIRST_SLOT, then we will want to switch
+         * to the temporary mapping before jumping to the runtime
+         * virtual mapping.
         */
        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, 1
-        b     link_from_second_id
-
-1:
-        /*
-         * Find the second slot used. If the slot is XEN_SECOND_SLOT, then the
-         * 1:1 mapping will use its own set of page-tables from the
-         * third level.
-         */
-        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, 2
-        b     link_from_third_id
+        cmp   r1, #TEMPORARY_AREA_FIRST_SLOT
+        bne   use_temporary_mapping
 
-link_from_second_id:
-        create_table_entry boot_second_id, boot_third_id, r9, 2
-link_from_third_id:
-        /* Good news, we are not clashing with Xen virtual mapping */
+        mov_w r0, XEN_VIRT_START
+        create_table_entry boot_pgtable, boot_second, r0, 1
        mov   r12, #0                /* r12 := temporary mapping not created */
        mov   pc, lr
 
-virtphys_clash:
+use_temporary_mapping:
        /*
-         * The identity map clashes with boot_third. Link boot_first_id and
-         * map Xen to a temporary mapping. See switch_to_runtime_mapping
-         * for more details.
+         * The identity mapping is not using the first slot
+         * TEMPORARY_AREA_FIRST_SLOT. Create a temporary mapping.
+         * See switch_to_runtime_mapping for more details.
         */
-        PRINT("- Virt and Phys addresses clash  -\r\n")
        PRINT("- Create temporary mapping -\r\n")
 
-        /*
-         * This will override the link to boot_second in XEN_FIRST_SLOT.
-         * The page-tables are not live yet. So no need to use
-         * break-before-make.
-         */
-        create_table_entry boot_pgtable, boot_second_id, r9, 1
-        create_table_entry boot_second_id, boot_third_id, r9, 2
-
        /* Map boot_second (cover Xen mappings) to the temporary 1st slot */
        mov_w r0, TEMPORARY_XEN_VIRT_START
        create_table_entry boot_pgtable, boot_second, r0, 1
@@ -680,33 +646,13 @@ remove_identity_mapping:
        /* r2:r3 := invalid page-table entry */
        mov   r2, #0x0
        mov   r3, #0x0
-        /*
-         * Find the first slot used. Remove the entry for the first
-         * table if the slot is not XEN_FIRST_SLOT.
-         */
+
+        /* Find the first slot used and remove it */
        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 */
        mov_w r0, boot_pgtable       /* r0 := root table */
        lsl   r1, r1, #3             /* r1 := Slot offset */
        strd  r2, r3, [r0, r1]
-        b     identity_mapping_removed
-
-1:
-        /*
-         * Find the second slot used. Remove the entry for the first
-         * table if the slot is not XEN_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 */
-        mov_w r0, boot_second        /* r0 := second table */
-        lsl   r1, r1, #3             /* r1 := Slot offset */
-        strd  r2, r3, [r0, r1]
 
-identity_mapping_removed:
        flush_xen_tlb_local r0
        mov   pc, lr
 ENDPROC(remove_identity_mapping)
Signature · 1 line
2.40.1
#30 lore raw
In reply to Julien Grall

Hi,

Quoted 13 lines · Julien Grall

From: Julien Grall <[email protected]>

Hi all,

The main goal of this series is to add some missing ISBs after update the PTEs.

The last patch is re-ingesting a patch that was reverted due to a boot failure on the Arndale. This has now been fixed by patch #2.

Cheers,

Quoted 7 lines

Julien Grall (7):
xen/arm32: head: Add missing isb in setup_fixmap() xen/arm32: head: Add mising isb in switch_to_runtime_mapping() xen/arm64: head: Add missing isb in setup_fixmap() xen/arm: page: Consolidate write_pte() and clarify the documentation xen/arm: pmap: Add missing ISB in arch_pmap_map() xen/arm: mm: Add missing ISB in xen_pt_update()

I have committed the first 6 patches.

Quoted 1 line

xen/arm32: head: Widen the use of the temporary mapping

This patch has non trivial clash with the USBAN series which has been recently committed. So I will send a new version.

Cheers,

Signature · 1 line
Julien Grall