On 2024-03-14 09:31, Jan Beulich wrote:
On 13.03.2024 20:30, Jason Andryuk wrote:
--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -537,6 +537,108 @@ static paddr_t __init find_memory(
return INVALID_PADDR;
}
+static bool __init check_load_address(
+ const struct domain *d, const struct elf_binary *elf)
+{
+ paddr_t kernel_start = (paddr_t)elf->dest_base & PAGE_MASK;
+ paddr_t kernel_end = PAGE_ALIGN((paddr_t)elf->dest_base + elf->dest_size);
Both casts act on a pointer value. Such cannot legitimately be converted
to paddr_t; it only so happens that paddr_t is effectively the same as
uintptr_t right now. (Same issue again further down.) That said, I notice
we have pre-existing examples of this ...
Yes, I followed existing code. Do you want dest_base to be switched to
a uintptr_t?
+/* Check the kernel load address, and adjust if necessary and possible. */
+static bool __init check_and_adjust_load_address(
+ const struct domain *d, struct elf_binary *elf, struct elf_dom_parms
*parms)
+{
+ paddr_t reloc_base;
+
+ if ( check_load_address(d, elf) )
+ return true;
+
+ if ( parms->phys_align == UNSET_ADDR )
+ {
+ printk("Address conflict and %pd kernel is not relocatable\n", d);
+ return false;
+ }
+
+ reloc_base = find_kernel_memory(d, elf, parms);
+ if ( reloc_base == 0 )
+ {
+ printk("Failed find a load address for the kernel\n");
+ return false;
+ }
+
+ if ( opt_dom0_verbose )
+ printk("Relocating kernel from [%lx, %lx] -> [%lx, %lx]\n",
+ (paddr_t)elf->dest_base,
+ (paddr_t)elf->dest_base + elf->dest_size,
By using %p you clearly can avoid the casts here.
Ok.
+ reloc_base, reloc_base + elf->dest_size);
I'm not convinced %lx is really appropriate for paddr_t.
PRIpaddr exists. It's "016lx" for x86. Using that and %p add lots of 0s:
(XEN) Relocating kernel from [0000000001000000, 000000000202ffff] ->
[0000000002200000, 000000000322ffff]
Regards,
Jason