[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 3/3] x86/PVH: Support relocatable dom0 kernels


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Mon, 18 Mar 2024 17:21:18 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=n8V58abC6y7/v0VQJ//5e3QNkh8LLiiWKHsc9lSKePQ=; b=Yl1vujwS4ZSImBMAJnp5DA0hCv1kbk5H3ttj2ug/+CY6sFU5eSmuRoRmmaYvy7zzgmD3cK4TxO15Iy+j5Z8S8NcPQKyNxpHpaMlEk1TTF3SqClMUW+218X57k2ylqIpX0j0hgfghYSckzc13fckfLvMD0fbpnpbxBSmUSJcFCZh7vfP7lQPvoKi8ThQpb9Hktq/nG3luTolSK1F6QiinkzajoksjN8BeUgqXLRjkncPfHV2F0bLDXKx0T+BaLpN+HDcgwDXpiCOCA1FddHgOu3Ltp86fdQyPDvQfeNsHmGTQhZTUfMwvN8gKUG+kY2qDiUsdCckAAzmrY7zhELA3ww==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lfrd8JjV1yiilTqaZKSklb4zq3t65y4/cFE+L4VWjP4ya01F4PYRIC3N9xeNK0NT0OU7CpTba2VoaY5JS0d8jqxJptU8gwa9Azj8c10/m6j6iO+h5c+F+VYpci1tir4R93a82m7fB8PFs0Wwg57ptKuAvlm1tsIa68B90sQMOI+yXPv9yaLGKi7DffhWLTgbArbscf9AVUeMLwZY+j51fpc5VvcICiO2l+/o0TF5jnpR7Vo8PlZe1q27ndRzH9pxaSdTH58jdYybtzqKwFPQvu5FXIIwO1SgHaZhKPGWQ2Pb9s6qP82SuBKpuOyXqBreoI31Ssyyy9xix6sT6Sl/Zw==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 18 Mar 2024 21:21:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2024-03-15 05:48, Jan Beulich wrote:
On 14.03.2024 20:19, Jason Andryuk wrote:
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?

I think it was deliberately switched to being a pointer at some point,
maybe even in a security fix.

commit 65808a8ed41cc7c044f588bd6cab5af0fdc0e029 "libelf: check all pointer accesses", part of XSA-55, switched from a single dest pointer to dest_base & dest_size.

For libxenguest, it's a pointer to guest-mapped memory to copy in the kernel. For PV dom0 creation, it's a pointer - Xen switches to the dom0 page tables and performs the copy with it as-is. For PVH dom0, it's a guest physical address.

Are you looking for this to be addressed in this series?

+/* 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]

That's to be accepted, I guess.

Looking at it again, is "Relocating" in the log message perhaps misleading?
We don't relocate it, that's something the kernel itself has to do. We only
put it at other than the default position. Maybe "Moving" instead?

Yes, "Moving" sounds better. I guess I'll drop the "from" and insert a %pd for:

(XEN) Moving d0 kernel [0000000001000000, 000000000202ffff] -> [0000000002200000, 000000000322ffff]

Regards,
Jason



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.