|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 12/15] x86/PVH: heed the kernel in pvh_steal_ram()
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;
}
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |