Skip to contentSkip to conversation

xen/arm: drop {boot_}phys_offset

PATCH In review Michal Orzel 2 participants 6 messages Aug 14, 2024 – Aug 22, 2024

lore
Share & tools
lore
#0 lore raw

cover xen/arm: drop {boot_}phys_offset

This has been on a TODO list for quite some time now. There is no real need for these variables since we can ask the MMU to do the virt->maddr translation.

Michal Orzel (2):
xen/arm: Drop {boot_}phys_offset usage xen/arm: head: Do not pass physical offset to start_xen

 xen/arch/arm/arm32/head.S     | 12 +++++-------
 xen/arch/arm/arm64/head.S     | 12 +++++-------
 xen/arch/arm/include/asm/mm.h |  2 +-
 xen/arch/arm/mmu/setup.c      | 16 ++++++----------
 xen/arch/arm/setup.c          |  5 ++---
 5 files changed, 19 insertions(+), 28 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 xen/arm: Drop {boot_}phys_offset usage

boot_phys_offset stores the physical offset (PA-VA), is calculated in the startup head.S code and passed to start_xen() as a first argument. There is no point in using it given that we can ask MMU to translate a VA for us using e.g. virt_to_{mfn,maddr}. Drop usage of these variables from the C world.

---
It should also simplify the LLC coloring last patch:
https://lore.kernel.org/xen-devel/[email protected]/

---
 xen/arch/arm/include/asm/mm.h |  2 +-
 xen/arch/arm/mmu/setup.c      | 16 ++++++----------
 xen/arch/arm/setup.c          |  2 +-
 3 files changed, 8 insertions(+), 12 deletions(-)
xen/arch/arm/include/asm/mm.h +1 -1
index f6ba611f01f7..5abd4b0d1c73 100644
@@ -199,7 +199,7 @@ extern unsigned long frametable_base_pdx;
 #define PDX_GROUP_SHIFT SECOND_SHIFT
 
 /* Boot-time pagetable setup */
-extern void setup_pagetables(unsigned long boot_phys_offset);
+extern void setup_pagetables(void);
 /* Map FDT in boot pagetable */
 extern void *early_fdt_map(paddr_t fdt_paddr);
 /* Remove early mappings */
xen/arch/arm/mmu/setup.c +6 -10
index 57042ed57b4a..9664e85ee6c0 100644
@@ -17,6 +17,8 @@
 /* Override macros from asm/page.h to make them work with mfn_t */
 #undef mfn_to_virt
 #define mfn_to_virt(mfn) __mfn_to_virt(mfn_x(mfn))
+#undef virt_to_mfn
+#define virt_to_mfn(va) _mfn(__virt_to_mfn(va))
 
 /* Main runtime page tables */
 
@@ -52,8 +54,6 @@ DEFINE_BOOT_PAGE_TABLE(xen_fixmap);
  */
 static DEFINE_PAGE_TABLES(xen_xenmap, XEN_NR_ENTRIES(2));
 
-static paddr_t phys_offset;
-
 /* Limits of the Xen heap */
 mfn_t directmap_mfn_start __read_mostly = INVALID_MFN_INITIALIZER;
 mfn_t directmap_mfn_end __read_mostly;
@@ -138,9 +138,7 @@ static void __init __maybe_unused build_assertions(void)
 
 lpae_t __init pte_of_xenaddr(vaddr_t va)
 {
-    paddr_t ma = va + phys_offset;
-
-    return mfn_to_xen_entry(maddr_to_mfn(ma), MT_NORMAL);
+    return mfn_to_xen_entry(virt_to_mfn(va), MT_NORMAL);
 }
 
 void * __init early_fdt_map(paddr_t fdt_paddr)
@@ -228,14 +226,12 @@ static void xen_pt_enforce_wnx(void)
  * Boot-time pagetable setup.
  * Changes here may need matching changes in head.S
  */
-void __init setup_pagetables(unsigned long boot_phys_offset)
+void __init setup_pagetables(void)
 {
     uint64_t ttbr;
     lpae_t pte, *p;
     int i;
 
-    phys_offset = boot_phys_offset;
-
     arch_setup_page_tables();
 
 #ifdef CONFIG_ARM_64
@@ -290,9 +286,9 @@ void __init setup_pagetables(unsigned long boot_phys_offset)
     xen_second[second_table_offset(FIXMAP_ADDR(0))] = pte;
 
 #ifdef CONFIG_ARM_64
-    ttbr = (uintptr_t) xen_pgtable + phys_offset;
+    ttbr = virt_to_maddr(xen_pgtable);
 #else
-    ttbr = (uintptr_t) cpu0_pgtable + phys_offset;
+    ttbr = virt_to_maddr(cpu0_pgtable);
 #endif
 
     switch_ttbr(ttbr);
xen/arch/arm/setup.c +1 -1
index cb2c0a16b824..cfe19e15b0be 100644
@@ -304,7 +304,7 @@ void asmlinkage __init start_xen(unsigned long boot_phys_offset,
     /* Initialize traps early allow us to get backtrace when an error occurred */
     init_traps();
 
-    setup_pagetables(boot_phys_offset);
+    setup_pagetables();
 
     smp_clear_cpu_maps();
 
Signature · 1 line
2.25.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xen/arm: Drop {boot_}phys_offset usage

Hi Michal,

Quoted 5 lines · Michal Orzel

boot_phys_offset stores the physical offset (PA-VA), is calculated in the startup head.S code and passed to start_xen() as a first argument. There is no point in using it given that we can ask MMU to translate a VA for us using e.g. virt_to_{mfn,maddr}. Drop usage of these variables from the C world.

I think the code is a remanant of when Xen would be relocated to the top of the RAM. In this case, virt_to_mfn() would not have worked.

This was removed by f60658c6ae47 ("xen/arm: Stop relocating Xen") and I don't expect the relocation code to be re-introduced. So...

Quoted 2 lines

...

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

PATCH 2/2 xen/arm: head: Do not pass physical offset to start_xen

In reply to Michal Orzel

Given no further use in C world of boot_phys_offset, drop it from the argument list of start_xen() and do the necessary changes in the startup code head.S (most notably modifying launch not to expect 2 arguments to pass to C entry point).

Both on arm64 and arm32, phys offset (stored in x20 or r10 respectively) is still needed, so that it can be used in e.g. create_table_entry, therefore keep it on the list of common register usage.

---
 xen/arch/arm/arm32/head.S | 12 +++++-------
 xen/arch/arm/arm64/head.S | 12 +++++-------
 xen/arch/arm/setup.c      |  3 +--
 3 files changed, 11 insertions(+), 16 deletions(-)
xen/arch/arm/arm32/head.S +5 -7
index b488a21a71ba..a96d5d35038f 100644
@@ -101,9 +101,8 @@ primary_switched:
         bl    zero_bss
         PRINT("- Ready -\r\n")
         /* Setup the arguments for start_xen and jump to C world */
-        mov   r0, r10                /* r0 := Physical offset */
-        mov   r1, r8                 /* r1 := paddr(FDT) */
-        mov_w r2, start_xen
+        mov   r0, r8                 /* r0 := paddr(FDT) */
+        mov_w r1, start_xen
         b     launch
 ENDPROC(start)
 
@@ -141,7 +140,7 @@ GLOBAL(init_secondary)
 secondary_switched:
         PRINT("- Ready -\r\n")
         /* Jump to C world */
-        mov_w r2, start_secondary
+        mov_w r1, start_secondary
         b     launch
 ENDPROC(init_secondary)
 
@@ -243,8 +242,7 @@ ENDPROC(cpu_init)
  *
  * Inputs:
  *   r0 : Argument 0 of the C function to call
- *   r1 : Argument 1 of the C function to call
- *   r2 : C entry point
+ *   r1 : C entry point
  *
  * Clobbers r3
  */
@@ -256,7 +254,7 @@ launch:
         sub   sp, #CPUINFO_sizeof    /* Make room for CPU save record */
 
         /* Jump to C world */
-       bx    r2
+       bx    r1
 ENDPROC(launch)
 
 /* Fail-stop */
xen/arch/arm/arm64/head.S +5 -7
index 2fa07dc3a04b..14c3720d80f8 100644
@@ -260,9 +260,8 @@ primary_switched:
         bl    zero_bss
         PRINT("- Ready -\r\n")
         /* Setup the arguments for start_xen and jump to C world */
-        mov   x0, x20                /* x0 := Physical offset */
-        mov   x1, x21                /* x1 := paddr(FDT) */
-        ldr   x2, =start_xen
+        mov   x0, x21                /* x0 := paddr(FDT) */
+        ldr   x1, =start_xen
         b     launch
 END(real_start)
 
@@ -303,7 +302,7 @@ FUNC(init_secondary)
 secondary_switched:
         PRINT("- Ready -\r\n")
         /* Jump to C world */
-        ldr   x2, =start_secondary
+        ldr   x1, =start_secondary
         b     launch
 END(init_secondary)
 
@@ -407,8 +406,7 @@ END(cpu_init)
  *
  * Inputs:
  *   x0 : Argument 0 of the C function to call
- *   x1 : Argument 1 of the C function to call
- *   x2 : C entry point
+ *   x1 : C entry point
  *
  * Clobbers x3
  */
@@ -421,7 +419,7 @@ FUNC_LOCAL(launch)
         mov   sp, x3
 
         /* Jump to C world */
-        br    x2
+        br    x1
 END(launch)
 
 /* Fail-stop */
xen/arch/arm/setup.c +1 -2
index cfe19e15b0be..961d3ea6700b 100644
@@ -287,8 +287,7 @@ void __init init_pdx(void)
 size_t __read_mostly dcache_line_bytes;
 
 /* C entry point for boot CPU */
-void asmlinkage __init start_xen(unsigned long boot_phys_offset,
-                                 unsigned long fdt_paddr)
+void asmlinkage __init start_xen(unsigned long fdt_paddr)
 {
     size_t fdt_size;
     const char *cmdline;
Signature · 1 line
2.25.1
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] xen/arm: head: Do not pass physical offset to start_xen

Quoted 10 lines · Michal Orzel

Given no further use in C world of boot_phys_offset, drop it from the argument list of start_xen() and do the necessary changes in the startup code head.S (most notably modifying launch not to expect 2 arguments to pass to C entry point).

Both on arm64 and arm32, phys offset (stored in x20 or r10 respectively) is still needed, so that it can be used in e.g. create_table_entry, therefore keep it on the list of common register usage.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
In reply to Michal Orzel

Hi Michal,

Quoted 6 lines · Michal Orzel

This has been on a TODO list for quite some time now. There is no real need for these variables since we can ask the MMU to do the virt->maddr translation.

Michal Orzel (2):
xen/arm: Drop {boot_}phys_offset usage xen/arm: head: Do not pass physical offset to start_xen

I have committed the series.

Cheers,

Quoted 8 lines
  xen/arch/arm/arm32/head.S     | 12 +++++-------
  xen/arch/arm/arm64/head.S     | 12 +++++-------
  xen/arch/arm/include/asm/mm.h |  2 +-
  xen/arch/arm/mmu/setup.c      | 16 ++++++----------
  xen/arch/arm/setup.c          |  5 ++---
  5 files changed, 19 insertions(+), 28 deletions(-)
Signature · 1 line
Julien Grall