diff mbox series

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

Message ID 20240814094303.23611-2-michal.orzel@amd.com (mailing list archive)
State New
Headers show
Series xen/arm: drop {boot_}phys_offset | expand

Commit Message

Michal Orzel Aug. 14, 2024, 9:43 a.m. UTC
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.

Signed-off-by: Michal Orzel <michal.orzel@amd.com>
---
It should also simplify the LLC coloring last patch:
https://lore.kernel.org/xen-devel/20240502165533.319988-14-carlo.nonato@minervasys.tech/
---
 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(-)

Comments

Julien Grall Aug. 22, 2024, 10:16 a.m. UTC | #1
Hi Michal,

On 14/08/2024 10:43, Michal Orzel wrote:
> 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...

> 
> Signed-off-by: Michal Orzel <michal.orzel@amd.com>

...

Acked-by: Julien Grall <jgrall@amazon.com>

Cheers,
diff mbox series

Patch

diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index f6ba611f01f7..5abd4b0d1c73 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -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 */
diff --git a/xen/arch/arm/mmu/setup.c b/xen/arch/arm/mmu/setup.c
index 57042ed57b4a..9664e85ee6c0 100644
--- a/xen/arch/arm/mmu/setup.c
+++ b/xen/arch/arm/mmu/setup.c
@@ -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);
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index cb2c0a16b824..cfe19e15b0be 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -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();