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

[PATCH 12/15] x86/PVH: heed the kernel in pvh_steal_ram()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 12 Oct 2026 10:25:40 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>
  • Delivery-date: Mon, 12 Oct 2026 08:25:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

While the function working downwards will typically result in no conflict
with the kernel range, there's no guarantee of that.

Fixes: 1d74282c455f ("x86: setup PVHv2 Dom0 ACPI tables")
Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/hvm/dom0_build.c
+++ b/xen/arch/x86/hvm/dom0_build.c
@@ -186,8 +186,12 @@ static int __init pvh_populate_memory_ra
 /* Steal RAM from the end of a memory region. */
 static int __init pvh_steal_ram(struct domain *d, unsigned long size,
                                 unsigned long align, paddr_t limit,
+                                const struct elf_binary *elf,
                                 paddr_t *addr)
 {
+    paddr_t kernel_start = (paddr_t)elf->dest_base & PAGE_MASK;
+    paddr_t kernel_end = ROUNDUP((paddr_t)elf->dest_base + elf->dest_size,
+                                 PAGE_SIZE);
     unsigned int i = d->arch.nr_e820;
 
     /*
@@ -203,6 +207,11 @@ static int __init pvh_steal_ram(struct d
             continue;
 
         *addr = (entry->addr + entry->size - size) & ~(align - 1);
+
+        /* Avoid kernel range, if this is the region it lives in. */
+        if ( *addr < kernel_end && *addr + size > kernel_start )
+            *addr = (kernel_start - size) & ~(align - 1);
+
         if ( *addr < entry->addr ||
              /* Don't steal from the low 1MB due to the copying done there. */
              *addr < MB(1) )
@@ -275,6 +284,7 @@ struct vmx_info {
 
 static int __init pvh_place_vmx_realmode_helpers(
     struct domain *d,
+    const struct elf_binary *elf,
     struct vmx_info *info)
 {
     paddr_t gaddr;
@@ -285,7 +295,7 @@ static int __init pvh_place_vmx_realmode
      * structure (which accounts for the first 104b) doesn't cross a page
      * boundary.
      */
-    if ( !pvh_steal_ram(d, HVM_VM86_TSS_SIZE, 128, GB(4), &gaddr) )
+    if ( !pvh_steal_ram(d, HVM_VM86_TSS_SIZE, 128, GB(4), elf, &gaddr) )
     {
         d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED] =
             VM86_TSS_UPDATED | ((uint64_t)HVM_VM86_TSS_SIZE << 32) | gaddr;
@@ -300,7 +310,7 @@ static int __init pvh_place_vmx_realmode
         printk("Unable to allocate VM86 TSS area\n");
 
     /* Steal some more RAM for the identity page tables. */
-    if ( pvh_steal_ram(d, PAGE_SIZE, PAGE_SIZE, GB(4), &gaddr) )
+    if ( pvh_steal_ram(d, PAGE_SIZE, PAGE_SIZE, GB(4), elf, &gaddr) )
     {
         printk("Unable to find memory to stash the identity page tables\n");
         return -ENOMEM;
@@ -1157,7 +1167,10 @@ static int __init cf_check acpi_set_intr
     return 0;
 }
 
-static int __init pvh_setup_acpi_madt(struct domain *d, paddr_t *addr)
+static int __init pvh_setup_acpi_madt(
+    struct domain *d,
+    const struct elf_binary *elf,
+    paddr_t *addr)
 {
     struct acpi_table_madt *madt;
     struct acpi_table_header *table;
@@ -1182,7 +1195,7 @@ static int __init pvh_setup_acpi_madt(st
     if ( !*addr )
     {
         /* Reserve space to place the new MADT in guest memory space. */
-        if ( pvh_steal_ram(d, size, 0, GB(4), addr) )
+        if ( pvh_steal_ram(d, size, 0, GB(4), elf, addr) )
         {
             printk("Unable to steal guest RAM for MADT\n");
             return -ENOMEM;
@@ -1337,8 +1350,11 @@ static bool __init pvh_acpi_xsdt_table_a
             strncmp(sig, ACPI_SIG_FACS, ACPI_NAME_SIZE));
 }
 
-static int __init pvh_setup_acpi_xsdt(struct domain *d, paddr_t madt_addr,
-                                      paddr_t *addr)
+static int __init pvh_setup_acpi_xsdt(
+    struct domain *d,
+    paddr_t madt_addr,
+    const struct elf_binary *elf,
+    paddr_t *addr)
 {
     struct acpi_table_xsdt *xsdt;
     struct acpi_table_header *table;
@@ -1374,7 +1390,7 @@ static int __init pvh_setup_acpi_xsdt(st
     if ( !*addr )
     {
         /* Reserve space to place the new XSDT in guest memory space. */
-        if ( pvh_steal_ram(d, size, 0, GB(4), addr) )
+        if ( pvh_steal_ram(d, size, 0, GB(4), elf, addr) )
         {
             printk("Unable to find guest RAM for XSDT\n");
             return -ENOMEM;
@@ -1473,6 +1489,7 @@ struct acpi_info {
 
 static int __init pvh_place_acpi(
     struct domain *d,
+    const struct elf_binary *elf,
     struct acpi_info *info)
 {
     unsigned int i;
@@ -1529,15 +1546,15 @@ static int __init pvh_place_acpi(
         }
     }
 
-    rc = pvh_setup_acpi_madt(d, &info->madt);
+    rc = pvh_setup_acpi_madt(d, elf, &info->madt);
     if ( rc )
         return rc;
 
-    rc = pvh_setup_acpi_xsdt(d, info->madt, &info->xsdt);
+    rc = pvh_setup_acpi_xsdt(d, info->madt, elf, &info->xsdt);
     if ( rc )
         return rc;
 
-    if ( pvh_steal_ram(d, sizeof(struct acpi_table_rsdp), 0, GB(4),
+    if ( pvh_steal_ram(d, sizeof(struct acpi_table_rsdp), 0, GB(4), elf,
                        &info->rsdp) )
     {
         printk("Unable to allocate guest RAM for RSDP\n");
@@ -1565,11 +1582,11 @@ static int __init pvh_setup_acpi(
         .length = sizeof(rsdp),
     };
 
-    rc = pvh_setup_acpi_madt(d, &info->madt);
+    rc = pvh_setup_acpi_madt(d, NULL, &info->madt);
     if ( rc )
         return rc;
 
-    rc = pvh_setup_acpi_xsdt(d, info->madt, &info->xsdt);
+    rc = pvh_setup_acpi_xsdt(d, info->madt, NULL, &info->xsdt);
     if ( rc )
         return rc;
 
@@ -1707,7 +1724,7 @@ int __init dom0_construct_pvh(const stru
         return rc;
     }
 
-    rc = pvh_place_acpi(d, &acpi);
+    rc = pvh_place_acpi(d, &elf, &acpi);
     if ( rc )
     {
         printk("Failed to place Dom0 ACPI tables: %d\n", rc);
@@ -1725,7 +1742,7 @@ int __init dom0_construct_pvh(const stru
           */
          !vmx_unrestricted_guest(d->vcpu[0]) )
     {
-        rc = pvh_place_vmx_realmode_helpers(d, &vmx);
+        rc = pvh_place_vmx_realmode_helpers(d, &elf, &vmx);
         if ( rc )
             return rc;
     }




 


Rackspace

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