Message ID | 20220429205732.2030094-2-sstabellini@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | dom0less PV drivers | expand |
> On 29 Apr 2022, at 21:57, Stefano Stabellini <sstabellini@kernel.org> wrote: > > From: Stefano Stabellini <stefano.stabellini@xilinx.com> > > Implement extended regions for dom0less domUs. The implementation is > based on the libxl implementation. > > Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> > --- > Changes in v5: > - print the domain > - coding style > - simplify the code in find_domU_holes > - return error if no regions allocated in find_domU_holes > - use ROUNDUP > - uint64_t/paddr_t > --- > xen/arch/arm/domain_build.c | 56 +++++++++++++++++++++++++++++++------ > 1 file changed, 48 insertions(+), 8 deletions(-) > > diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c > index 8be01678de..34d3e5ce30 100644 > --- a/xen/arch/arm/domain_build.c > +++ b/xen/arch/arm/domain_build.c > @@ -1324,6 +1324,37 @@ out: > return res; > } > > +static int __init find_domU_holes(const struct kernel_info *kinfo, > + struct meminfo *ext_regions) > +{ > + unsigned int i; > + paddr_t bankend; > + const paddr_t bankbase[] = GUEST_RAM_BANK_BASES; > + const paddr_t banksize[] = GUEST_RAM_BANK_SIZES; > + int res = -ENOENT; > + > + for ( i = 0; i < GUEST_RAM_BANKS; i++ ) > + { > + struct membank *ext_bank = &(ext_regions->bank[ext_regions->nr_banks]); > + > + ext_bank->start = ROUNDUP(bankbase[i] + kinfo->mem.bank[i].size, > + SZ_2M); NIT: there is no need anymore to break the line as SZ_2M will fit in the line length > + > + bankend = ~0ULL >> (64 - p2m_ipa_bits); > + bankend = min(bankend, bankbase[i] + banksize[i] - 1); > + if ( bankend > ext_bank->start ) > + ext_bank->size = bankend - ext_bank->start + 1; > + > + /* 64MB is the minimum size of an extended region */ > + if ( ext_bank->size < MB(64) ) > + continue; > + ext_regions->nr_banks++; > + res = 0; > + } > + > + return res; > +} > + > static int __init make_hypervisor_node(struct domain *d, > const struct kernel_info *kinfo, > int addrcells, int sizecells) > @@ -1360,12 +1391,13 @@ static int __init make_hypervisor_node(struct domain *d, > > if ( !opt_ext_regions ) > { > - printk(XENLOG_INFO "The extended regions support is disabled\n"); > + printk(XENLOG_INFO "%pd: extended regions support is disabled\n", d); > nr_ext_regions = 0; > } > else if ( is_32bit_domain(d) ) > { > - printk(XENLOG_WARNING "The extended regions are only supported for 64-bit guest currently\n"); > + printk(XENLOG_WARNING "%pd: extended regions are only supported for 64-bit guest currently\n", > + d); NIT: Something like that won’t exceed 80 chars: printk(XENLOG_WARNING "%pd: extended regions not supported for 32-bit guests\n", d); Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
On Fri, Apr 29, 2022 at 11:58 PM Stefano Stabellini <sstabellini@kernel.org> wrote: > From: Stefano Stabellini <stefano.stabellini@xilinx.com> > Hello Stefano [Sorry for the possible format issues] > > Implement extended regions for dom0less domUs. The implementation is > based on the libxl implementation. > > Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> > --- > Changes in v5: > - print the domain > - coding style > - simplify the code in find_domU_holes > - return error if no regions allocated in find_domU_holes > - use ROUNDUP > - uint64_t/paddr_t > --- > xen/arch/arm/domain_build.c | 56 +++++++++++++++++++++++++++++++------ > 1 file changed, 48 insertions(+), 8 deletions(-) > > diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c > index 8be01678de..34d3e5ce30 100644 > --- a/xen/arch/arm/domain_build.c > +++ b/xen/arch/arm/domain_build.c > @@ -1324,6 +1324,37 @@ out: > return res; > } > > +static int __init find_domU_holes(const struct kernel_info *kinfo, > + struct meminfo *ext_regions) > +{ > + unsigned int i; > + paddr_t bankend; > + const paddr_t bankbase[] = GUEST_RAM_BANK_BASES; > + const paddr_t banksize[] = GUEST_RAM_BANK_SIZES; > + int res = -ENOENT; > + > + for ( i = 0; i < GUEST_RAM_BANKS; i++ ) > + { > + struct membank *ext_bank = > &(ext_regions->bank[ext_regions->nr_banks]); > + > + ext_bank->start = ROUNDUP(bankbase[i] + kinfo->mem.bank[i].size, > + SZ_2M); > + > + bankend = ~0ULL >> (64 - p2m_ipa_bits); > + bankend = min(bankend, bankbase[i] + banksize[i] - 1); > + if ( bankend > ext_bank->start ) > + ext_bank->size = bankend - ext_bank->start + 1; > + > + /* 64MB is the minimum size of an extended region */ > + if ( ext_bank->size < MB(64) ) > + continue; > + ext_regions->nr_banks++; > + res = 0; > + } > + > + return res; > +} > + > static int __init make_hypervisor_node(struct domain *d, > const struct kernel_info *kinfo, > int addrcells, int sizecells) > @@ -1360,12 +1391,13 @@ static int __init make_hypervisor_node(struct > domain *d, > > if ( !opt_ext_regions ) > ok, I think, the comment for *opt_ext_regions* at the beginning of this file and the description for *ext_regions* in xen-command-line.pandoc need to be updated, as they both mention Dom0 only. > { > - printk(XENLOG_INFO "The extended regions support is disabled\n"); > + printk(XENLOG_INFO "%pd: extended regions support is disabled\n", > d); > nr_ext_regions = 0; > } > else if ( is_32bit_domain(d) ) > { > - printk(XENLOG_WARNING "The extended regions are only supported > for 64-bit guest currently\n"); > + printk(XENLOG_WARNING "%pd: extended regions are only supported > for 64-bit guest currently\n", > + d); > nr_ext_regions = 0; > } > else > @@ -1374,13 +1406,21 @@ static int __init make_hypervisor_node(struct > domain *d, > if ( !ext_regions ) > return -ENOMEM; > > - if ( !is_iommu_enabled(d) ) > - res = find_unallocated_memory(kinfo, ext_regions); > + if ( is_domain_direct_mapped(d) ) > + { > + if ( !is_iommu_enabled(d) ) > + res = find_unallocated_memory(kinfo, ext_regions); > + else > + res = find_memory_holes(kinfo, ext_regions); > + } > else > - res = find_memory_holes(kinfo, ext_regions); > + { > + res = find_domU_holes(kinfo, ext_regions); > + } > > if ( res ) > - printk(XENLOG_WARNING "Failed to allocate extended > regions\n"); > + printk(XENLOG_WARNING "%pd: failed to allocate extended > regions\n", > + d); > nr_ext_regions = ext_regions->nr_banks; > } > > @@ -1401,8 +1441,8 @@ static int __init make_hypervisor_node(struct domain > *d, > u64 start = ext_regions->bank[i].start; > u64 size = ext_regions->bank[i].size; > > - printk("Extended region %d: %#"PRIx64"->%#"PRIx64"\n", > - i, start, start + size); > + printk("%pd: extended region %d: %#"PRIx64"->%#"PRIx64"\n", > + d, i, start, start + size); > > dt_child_set_range(&cells, addrcells, sizecells, start, size); > } > -- > 2.25.1 > > >
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 8be01678de..34d3e5ce30 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1324,6 +1324,37 @@ out: return res; } +static int __init find_domU_holes(const struct kernel_info *kinfo, + struct meminfo *ext_regions) +{ + unsigned int i; + paddr_t bankend; + const paddr_t bankbase[] = GUEST_RAM_BANK_BASES; + const paddr_t banksize[] = GUEST_RAM_BANK_SIZES; + int res = -ENOENT; + + for ( i = 0; i < GUEST_RAM_BANKS; i++ ) + { + struct membank *ext_bank = &(ext_regions->bank[ext_regions->nr_banks]); + + ext_bank->start = ROUNDUP(bankbase[i] + kinfo->mem.bank[i].size, + SZ_2M); + + bankend = ~0ULL >> (64 - p2m_ipa_bits); + bankend = min(bankend, bankbase[i] + banksize[i] - 1); + if ( bankend > ext_bank->start ) + ext_bank->size = bankend - ext_bank->start + 1; + + /* 64MB is the minimum size of an extended region */ + if ( ext_bank->size < MB(64) ) + continue; + ext_regions->nr_banks++; + res = 0; + } + + return res; +} + static int __init make_hypervisor_node(struct domain *d, const struct kernel_info *kinfo, int addrcells, int sizecells) @@ -1360,12 +1391,13 @@ static int __init make_hypervisor_node(struct domain *d, if ( !opt_ext_regions ) { - printk(XENLOG_INFO "The extended regions support is disabled\n"); + printk(XENLOG_INFO "%pd: extended regions support is disabled\n", d); nr_ext_regions = 0; } else if ( is_32bit_domain(d) ) { - printk(XENLOG_WARNING "The extended regions are only supported for 64-bit guest currently\n"); + printk(XENLOG_WARNING "%pd: extended regions are only supported for 64-bit guest currently\n", + d); nr_ext_regions = 0; } else @@ -1374,13 +1406,21 @@ static int __init make_hypervisor_node(struct domain *d, if ( !ext_regions ) return -ENOMEM; - if ( !is_iommu_enabled(d) ) - res = find_unallocated_memory(kinfo, ext_regions); + if ( is_domain_direct_mapped(d) ) + { + if ( !is_iommu_enabled(d) ) + res = find_unallocated_memory(kinfo, ext_regions); + else + res = find_memory_holes(kinfo, ext_regions); + } else - res = find_memory_holes(kinfo, ext_regions); + { + res = find_domU_holes(kinfo, ext_regions); + } if ( res ) - printk(XENLOG_WARNING "Failed to allocate extended regions\n"); + printk(XENLOG_WARNING "%pd: failed to allocate extended regions\n", + d); nr_ext_regions = ext_regions->nr_banks; } @@ -1401,8 +1441,8 @@ static int __init make_hypervisor_node(struct domain *d, u64 start = ext_regions->bank[i].start; u64 size = ext_regions->bank[i].size; - printk("Extended region %d: %#"PRIx64"->%#"PRIx64"\n", - i, start, start + size); + printk("%pd: extended region %d: %#"PRIx64"->%#"PRIx64"\n", + d, i, start, start + size); dt_child_set_range(&cells, addrcells, sizecells, start, size); }