of/kexec: save pa of initial_boot_params for arm64 and use it at kexec
Subsystems (4)
PATCH 1/1 of/kexec: save pa of initial_boot_params for arm64 and use it at kexec
__pa() is only intended to be used for linear map addresses and using
it for initial_boot_params which is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using __pa().
--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)
arch/arm64/kernel/setup.c +8 -0
@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys); + name =of_flat_dt_get_machine_name ();if (!name)return ;
drivers/of/fdt.c +6 -0
@@ -457,6 +457,7 @@ int __initdata dt_root_addr_cells;int __initdata dt_root_size_cells;void *initial_boot_params__ro_after_init ; +phys_addr_t initial_boot_params_pa__ro_after_init ;#ifdef CONFIG_OF_EARLY_FLATTREE
@@ -1185,6 +1186,11 @@ bool __init early_init_dt_scan(void *params)return true; } +void __init set_initial_boot_params_pa (phys_addr_t params) +{ + initial_boot_params_pa = params; +} +static void *__init copy_device_tree (void *fdt) {int size;
drivers/of/kexec.c +6 -2
@@ -300,8 +300,12 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, goto out; } -/* Remove memory reservation for the current device tree. */ - ret =fdt_find_and_del_mem_rsv (fdt,__pa (initial_boot_params), +/* Remove memory reservation for the current device tree. +* For arm64, initial_boot_params is a fixmap address, hence __pa(), +* can't be used to get the physical address. +*/ + ret =fdt_find_and_del_mem_rsv (fdt,IS_ENABLED (CONFIG_ARM64 ) ? + initial_boot_params_pa :__pa (initial_boot_params),fdt_totalsize (initial_boot_params));if (ret == -EINVAL ) {pr_err ("Error removing memory reservation.\n" );
include/linux/of_fdt.h +2 -0
@@ -31,6 +31,7 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob,extern int __initdata dt_root_addr_cells;extern int __initdata dt_root_size_cells;extern void *initial_boot_params; +extern phys_addr_t initial_boot_params_pa;extern char __dtb_start[];extern char __dtb_end[];
@@ -73,6 +74,7 @@ extern int early_init_dt_scan_root(void);extern bool early_init_dt_scan (void *params);extern bool early_init_dt_verify (void *params);extern void early_init_dt_scan_nodes (void ); +extern void set_initial_boot_params_pa (phys_addr_t params);extern const char *of_flat_dt_get_machine_name (void ); extern const void *of_flat_dt_match_machine(const void *default_match,
Signature · 1 line
2.43.5
Quoted 68 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +8
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys); + name =of_flat_dt_get_machine_name ();if (!name)return ;drivers/of/fdt.c +6
-0@@ -457,6 +457,7 @@ int __initdata dt_root_addr_cells;int __initdata dt_root_size_cells;void *initial_boot_params__ro_after_init ; +phys_addr_t initial_boot_params_pa__ro_after_init ;#ifdef CONFIG_OF_EARLY_FLATTREE @@ -1185,6 +1186,11 @@ bool __init early_init_dt_scan(void *params)return true; } +void __init set_initial_boot_params_pa (phys_addr_t params) +{ + initial_boot_params_pa = params; +} +static void *__init copy_device_tree (void *fdt) {int size;drivers/of/kexec.c +0
-0@@ -300,8 +300,12 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, goto out; }
drivers/of/kexec.c void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, · line 309
Quoted 10 lines
drivers/of/kexec.c +6
-2-/* Remove memory reservation for the current device tree. */ - ret =fdt_find_and_del_mem_rsv (fdt,__pa (initial_boot_params), +/* Remove memory reservation for the current device tree. +* For arm64, initial_boot_params is a fixmap address, hence __pa(), +* can't be used to get the physical address. +*/ + ret =fdt_find_and_del_mem_rsv (fdt,IS_ENABLED (CONFIG_ARM64 ) ? + initial_boot_params_pa :__pa (initial_boot_params),fdt_totalsize (initial_boot_params));
Not sure about the correctness of the patch (not a kexec expert) but no need to do all of this inside a function parameter. Just create a variable and use it here.
-Saravana
Quoted 25 lines
drivers/of/kexec.c +0
-0if (ret == -EINVAL ) {pr_err ("Error removing memory reservation.\n" );include/linux/of_fdt.h +2
-1@@ -31,6 +31,7 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob,extern int __initdata dt_root_addr_cells;extern int __initdata dt_root_size_cells;extern void *initial_boot_params; +extern phys_addr_t initial_boot_params_pa;extern char __dtb_start[];extern char __dtb_end[];@@ -73,6 +74,7 @@ extern int early_init_dt_scan_root(void);extern bool early_init_dt_scan (void *params);extern bool early_init_dt_verify (void *params);extern void early_init_dt_scan_nodes (void ); +extern void set_initial_boot_params_pa (phys_addr_t params);extern const char *of_flat_dt_get_machine_name (void ); extern const void *of_flat_dt_match_machine(const void *default_match, --2.43.5
Quoted 84 lines · Saravana Kannan
Quoted 68 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +8
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys); + name =of_flat_dt_get_machine_name ();if (!name)return ;drivers/of/fdt.c +6
-0@@ -457,6 +457,7 @@ int __initdata dt_root_addr_cells;int __initdata dt_root_size_cells;void *initial_boot_params__ro_after_init ; +phys_addr_t initial_boot_params_pa__ro_after_init ;#ifdef CONFIG_OF_EARLY_FLATTREE @@ -1185,6 +1186,11 @@ bool __init early_init_dt_scan(void *params)return true; } +void __init set_initial_boot_params_pa (phys_addr_t params) +{ + initial_boot_params_pa = params; +} +static void *__init copy_device_tree (void *fdt) {int size;drivers/of/kexec.c +0
-0@@ -300,8 +300,12 @@ void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, goto out; }drivers/of/kexec.c void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, · line 309
Quoted 10 lines
drivers/of/kexec.c +6
-2-/* Remove memory reservation for the current device tree. */ - ret =fdt_find_and_del_mem_rsv (fdt,__pa (initial_boot_params), +/* Remove memory reservation for the current device tree. +* For arm64, initial_boot_params is a fixmap address, hence __pa(), +* can't be used to get the physical address. +*/ + ret =fdt_find_and_del_mem_rsv (fdt,IS_ENABLED (CONFIG_ARM64 ) ? + initial_boot_params_pa :__pa (initial_boot_params),fdt_totalsize (initial_boot_params));Not sure about the correctness of the patch (not a kexec expert) but no need to do all of this inside a function parameter. Just create a variable and use it here.
Quoted 2 lines
-Saravana
Thanks, will do in the next revision.
Rob Herring
maintainerQuoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0
arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);
No new arch->dt functions please. If we need to save off the PA, then do that when we set initial_boot_params.
Rob
Quoted 37 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.
Quoted 1 line
Rob
initial_boot_params is set in early_init_dt_verify, called by early_init_dt_scan. This is done in setup_machine_fdt in arm64 where the PA is available, but in other functions in other architectures, where the PA is not available. So it makes it quite messy to set it in the same place as initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?
Any reason to not add a new function to make arch -> of/fdt call?
Thanks,
Usama
Rob Herring
maintainerQuoted 41 lines · Usama Arif
Quoted 37 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.
Quoted 6 lines
Quoted 1 line
Rob
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.
Doesn't __pa() work for all the other architectures? That's what your patch indicates.
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Another option is to make arm64 copy the DT as some arches do.
Rob
Quoted 45 lines · Rob Herring
Quoted 44 lines · Usama Arif
Quoted 38 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.Rob
Quoted 7 lines
Quoted 3 lines
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.Doesn't
__pa()work for all the other architectures? That's what your patch indicates.
Yes, __pa() works for all other architectures.
But we would need to add initial_boot_params_pa of type phys_addr_t as an argument for early_init_dt_scan, which is called by all other archs, and we technically cant use 0 as an invalid value.
We could convert initial_boot_params_pa to void *, and pass NULL for all other archs. But again, I don't really think we should be changing the early_init_dt_scan(dt_virt) call in all other archs to early_init_dt_scan(dt_virt, NULL) just to save initial_boot_params_pa in arm64?
Quoted 5 lines
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Quoted 8 lines
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Another option is to make arm64 copy the DT as some arches do.
Rob
Ah maybe I didn't understand this properly, but isnt early_init_dt_scan an arch -> of/fdt interfaces. set_initial_boot_params_pa is a similar interface to early_init_dt_scan?
Quoted 78 lines · Usama Arif
Quoted 45 lines · Rob Herring
Quoted 44 lines · Usama Arif
Quoted 38 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.Rob
Quoted 7 lines
Quoted 3 lines
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.Doesn't
__pa()work for all the other architectures? That's what your patch indicates.Yes,
__pa()works for all other architectures.But we would need to add
initial_boot_params_paof typephys_addr_tas an argument forearly_init_dt_scan, which is called by all other archs, and we technically cant use 0 as an invalid value.We could convert
initial_boot_params_pato void *, and pass NULL for all other archs. But again, I don't really think we should be changing theearly_init_dt_scan(dt_virt)call in all other archs toearly_init_dt_scan(dt_virt, NULL)just to saveinitial_boot_params_pain arm64?Quoted 10 lines
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Quoted 7 lines
Quoted 3 lines
Another option is to make arm64 copy the DT as some arches do.
Rob
Ah maybe I didn't understand this properly, but isnt
early_init_dt_scanan arch -> of/fdt interfaces.set_initial_boot_params_pais a similar interface toearly_init_dt_scan?
Hi,
Just wanted to check in on above. I feel what I am doing here is similar to early_init_dt_scan so should be ok? There is just a small comment from Saravana that I need to address which I can in v2, but wanted to check on above before sending it.
Thanks,
Usama
Rob Herring
maintainerQuoted 79 lines · Usama Arif
Quoted 45 lines · Rob Herring
Quoted 44 lines · Usama Arif
Quoted 38 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.Rob
Quoted 7 lines
Quoted 3 lines
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.Doesn't
__pa()work for all the other architectures? That's what your patch indicates.Yes,
__pa()works for all other architectures.But we would need to add
initial_boot_params_paof typephys_addr_tas an argument forearly_init_dt_scan, which is called by all other archs, and we technically cant use 0 as an invalid value.We could convert
initial_boot_params_pato void *, and pass NULL for all other archs. But again, I don't really think we should be changing theearly_init_dt_scan(dt_virt)call in all other archs toearly_init_dt_scan(dt_virt, NULL)just to saveinitial_boot_params_pain arm64?Quoted 10 lines
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Quoted 7 lines
Quoted 3 lines
Another option is to make arm64 copy the DT as some arches do.
Rob
Ah maybe I didn't understand this properly, but isnt
early_init_dt_scanan arch -> of/fdt interfaces.set_initial_boot_params_pais a similar interface toearly_init_dt_scan?
Yes, and I don't want more APIs if they can be avoided. When is set_initial_boot_params_pa() supposed to be called? Is it before or after early_init_dt_scan()? Can subsequent OF functions assume the PA is valid? If an arch doesn't call set_initial_boot_params_pa() is __pa() valid or did they just forget to call it? Requiring the PA to be set at the same time as initial_boot_params avoids all those issues with any period of time having the PA incorrect.
Rob
Quoted 84 lines · Rob Herring
Quoted 83 lines · Usama Arif
Quoted 45 lines · Rob Herring
Quoted 44 lines · Usama Arif
Quoted 38 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.Rob
Quoted 7 lines
Quoted 3 lines
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.Doesn't
__pa()work for all the other architectures? That's what your patch indicates.Yes,
__pa()works for all other architectures.But we would need to add
initial_boot_params_paof typephys_addr_tas an argument forearly_init_dt_scan, which is called by all other archs, and we technically cant use 0 as an invalid value.We could convert
initial_boot_params_pato void *, and pass NULL for all other archs. But again, I don't really think we should be changing theearly_init_dt_scan(dt_virt)call in all other archs toearly_init_dt_scan(dt_virt, NULL)just to saveinitial_boot_params_pain arm64?Quoted 13 lines
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Another option is to make arm64 copy the DT as some arches do.
Rob
Quoted 7 lines
Quoted 3 lines
Ah maybe I didn't understand this properly, but isnt
early_init_dt_scanan arch -> of/fdt interfaces.set_initial_boot_params_pais a similar interface toearly_init_dt_scan?Yes, and I don't want more APIs if they can be avoided. When is
set_initial_boot_params_pa()supposed to be called? Is it before or afterearly_init_dt_scan()?
Its only needed in arm64, and can be either before or after, as long as its somewhere in setup_machine_fdt, where dt_phys is available.
Quoted 2 lines
Can subsequent OF functions assume the PA
is valid?
After set_initial_boot_params_pa has been called, yes.
Quoted 2 lines
If an arch doesn't call
set_initial_boot_params_pa()is__pa()valid or did they just forget to call it?
Only arm64 seems to do the fixmap as discussed in
https://lore.kernel.org/all/[email protected]/,
so __pa should work in others.
Requiring the PA to
Quoted 3 lines
be set at the same time as
initial_boot_paramsavoids all those issues with any period of time having the PA incorrect.
Are you recommending I send a patch which changes all archs to call early_init_dt_scan(dt_virt, NULL)?
or maybe early_init_dt_scan(dt_virt, __pa(dt_virt))?
and arm to call early_init_dt_scan(dt_virt, dt_phys).
Happy to do send a v2 with that if its the way forward, although I feel set_initial_boot_params_pa() in just one arch might be better than changing this for all archs.
Thanks
Usama
Quoted 1 line
Rob
Rob Herring
maintainerQuoted 92 lines · Usama Arif
Quoted 88 lines · Rob Herring
Quoted 86 lines · Usama Arif
Quoted 45 lines · Rob Herring
Quoted 44 lines · Usama Arif
Quoted 38 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.Rob
Quoted 7 lines
Quoted 3 lines
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.Doesn't
__pa()work for all the other architectures? That's what your patch indicates.Yes,
__pa()works for all other architectures.But we would need to add
initial_boot_params_paof typephys_addr_tas an argument forearly_init_dt_scan, which is called by all other archs, and we technically cant use 0 as an invalid value.We could convert
initial_boot_params_pato void *, and pass NULL for all other archs. But again, I don't really think we should be changing theearly_init_dt_scan(dt_virt)call in all other archs toearly_init_dt_scan(dt_virt, NULL)just to saveinitial_boot_params_pain arm64?Quoted 5 lines
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Quoted 8 lines
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Another option is to make arm64 copy the DT as some arches do.
Rob
Ah maybe I didn't understand this properly, but isnt
early_init_dt_scanan arch -> of/fdt interfaces.set_initial_boot_params_pais a similar interface toearly_init_dt_scan?
Quoted 6 lines
Quoted 3 lines
Yes, and I don't want more APIs if they can be avoided. When is
set_initial_boot_params_pa()supposed to be called? Is it before or afterearly_init_dt_scan()?Its only needed in arm64, and can be either before or after, as long as its somewhere in
setup_machine_fdt, wheredt_physis available.
Maybe only arm64 today. What happens when riscv decides they too want to support the DT anywhere in memory including outside the linear address map and then they need the same thing.
Quoted 4 lines
Quoted 2 lines
Can subsequent OF functions assume the PA
is valid?After
set_initial_boot_params_pahas been called, yes.
How do I know it has been called? Do I have to go wade thru every arch to see? You could document the requirement to be immediately after early_init_dt_scan(), but then how do you enforce that? You can't unless you design the interface to just avoid the problem in the first place.
Quoted 8 lines
Quoted 2 lines
If an arch doesn't call
set_initial_boot_params_pa()is__pa()valid or did they just forget to call it?Only arm64 seems to do the fixmap as discussed in
https://lore.kernel.org/all/[email protected]/,
so__pashould work in others.Requiring the PA to
Quoted 8 lines
Quoted 3 lines
be set at the same time as
initial_boot_paramsavoids all those issues with any period of time having the PA incorrect.Are you recommending I send a patch which changes all archs to call
early_init_dt_scan(dt_virt, NULL)?
or maybeearly_init_dt_scan(dt_virt, __pa(dt_virt))?
and arm to callearly_init_dt_scan(dt_virt, dt_phys).
I believe that's what I suggested already, so yes. Whether NULL or __pa(dt_virt))? __pa() would be better because then the arch has to think about whether that is right or not.
Quoted 3 lines
Happy to do send a v2 with that if its the way forward, although I feel
set_initial_boot_params_pa()in just one arch might be better than changing this for all archs.
We don't work around kernel APIs if they don't meet changing needs. We change them.
Rob
Quoted 127 lines · Rob Herring
Quoted 92 lines · Usama Arif
Quoted 88 lines · Rob Herring
Quoted 86 lines · Usama Arif
Quoted 45 lines · Rob Herring
Quoted 44 lines · Usama Arif
Quoted 38 lines · Rob Herring
Quoted 22 lines · Usama Arif
__pa()is only intended to be used for linear map addresses and using
it forinitial_boot_paramswhich is in fixmap for arm64 will give an incorrect value. Hence stash the physical address when it is known at boot time and use it at kexec time instead of converting the virtual address using__pa().Reported-by Breno Leitao <[email protected]>Suggested-by Mark Rutland <[email protected]>Signed-off-by Usama Arif <[email protected]>Fixes ac10be5cdbfa ("arm64: Use common of_kexec_alloc_and_setup_fdt()")--- arch/arm64/kernel/setup.c | 8 ++++++++ drivers/of/fdt.c | 6 ++++++ drivers/of/kexec.c | 8 ++++++-- include/linux/of_fdt.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)arch/arm64/kernel/setup.c +0
-0arch/arm64/kernel/setup.c static void __init setup_machine_fdt(phys_addr_t dt_phys) · line 203
Quoted 10 lines
arch/arm64/kernel/setup.c +7
-0@@ -194,6 +194,14 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)/* Early fixups are done, map the FDT as read-only now */ fixmap_remap_fdt (dt_phys, &size,PAGE_KERNEL_RO ); +/* +* Save dt_phys address so that it can be used later for kexec. This +* is done as __pa() is only intended to be used for linear map addresses +* and using it for initial_boot_params which is in fixmap will give an +* incorrect value. +*/ +set_initial_boot_params_pa (dt_phys);No new
arch->dtfunctions please. If we need to save off the PA, then do that when we setinitial_boot_params.Rob
Quoted 7 lines
Quoted 3 lines
initial_boot_paramsis set inearly_init_dt_verify, called byearly_init_dt_scan. This is done insetup_machine_fdtin arm64 where the PA is available, but in other functions in other architectures, where the PA is not available.Doesn't
__pa()work for all the other architectures? That's what your patch indicates.Yes,
__pa()works for all other architectures.But we would need to add
initial_boot_params_paof typephys_addr_tas an argument forearly_init_dt_scan, which is called by all other archs, and we technically cant use 0 as an invalid value.We could convert
initial_boot_params_pato void *, and pass NULL for all other archs. But again, I don't really think we should be changing theearly_init_dt_scan(dt_virt)call in all other archs toearly_init_dt_scan(dt_virt, NULL)just to saveinitial_boot_params_pain arm64?Quoted 5 lines
Quoted 4 lines
So it makes it quite messy to set it in the same place as
initial_boot_params. Its only needed for arm64 and making a change in all archs probably isnt a good idea?Any reason to not add a new function to make arch -> of/fdt call?
Quoted 8 lines
Yes. It is the opposite direction I have reworked the interfaces to. We don't want each arch calling various early DT functions at random times and order. That's fragile when the DT functions make assumptions about when they are called or what's been initialized already.
Another option is to make arm64 copy the DT as some arches do.
Rob
Ah maybe I didn't understand this properly, but isnt
early_init_dt_scanan arch -> of/fdt interfaces.set_initial_boot_params_pais a similar interface toearly_init_dt_scan?Quoted 6 lines
Quoted 3 lines
Yes, and I don't want more APIs if they can be avoided. When is
set_initial_boot_params_pa()supposed to be called? Is it before or afterearly_init_dt_scan()?Its only needed in arm64, and can be either before or after, as long as its somewhere in
setup_machine_fdt, wheredt_physis available.Maybe only arm64 today. What happens when riscv decides they too want to support the DT anywhere in memory including outside the linear address map and then they need the same thing.
Quoted 4 lines
Quoted 2 lines
Can subsequent OF functions assume the PA
is valid?After
set_initial_boot_params_pahas been called, yes.How do I know it has been called? Do I have to go wade thru every arch to see? You could document the requirement to be immediately after
early_init_dt_scan(), but then how do you enforce that? You can't unless you design the interface to just avoid the problem in the first place.Quoted 12 lines
Quoted 2 lines
If an arch doesn't call
set_initial_boot_params_pa()is__pa()valid or did they just forget to call it?Only arm64 seems to do the fixmap as discussed in
https://lore.kernel.org/all/[email protected]/,
so__pashould work in others.Requiring the PA to
Quoted 3 lines
be set at the same time as
initial_boot_paramsavoids all those issues with any period of time having the PA incorrect.
Quoted 8 lines
Quoted 4 lines
Are you recommending I send a patch which changes all archs to call
early_init_dt_scan(dt_virt, NULL)?
or maybeearly_init_dt_scan(dt_virt, __pa(dt_virt))?
and arm to callearly_init_dt_scan(dt_virt, dt_phys).I believe that's what I suggested already, so yes. Whether NULL or
__pa(dt_virt))?__pa()would be better because then the arch has to think about whether that is right or not.
Sounds good! Will send a v2 with the change.
Thanks
Quoted 9 lines
Quoted 4 lines
Happy to do send a v2 with that if its the way forward, although I feel
set_initial_boot_params_pa()in just one arch might be better than changing this for all archs.We don't work around kernel APIs if they don't meet changing needs. We change them.
Rob