KVM: arm64: Use consistent type for pool size
PATCH v3 1/1 KVM: arm64: Use consistent type for pool size
All the pool sizes in the hypervisor are "unsigned long" but when they get passed to hyp_early_alloc_contig() or hyp_pool_init() they get truncated to 32-bits.
That is not a big problem at the moment as to overflow this we need 4G bytes of carveout (2 TB of host or guest system memory).
However when new users are added (as IOMMU) it is hard to reason about the carveout size anymore.
--- arch/arm64/kvm/hyp/include/nvhe/early_alloc.h | 2 +- arch/arm64/kvm/hyp/include/nvhe/gfp.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/early_alloc.c | 2 +- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-)
arch/arm64/kvm/hyp/include/nvhe/early_alloc.h +1 -1
@@ -7,7 +7,7 @@void hyp_early_alloc_init (void *virt,unsigned long size);unsigned long hyp_early_alloc_nr_used_pages (void );void *hyp_early_alloc_page (void *arg); -void *hyp_early_alloc_contig (unsigned int nr_pages); +void *hyp_early_alloc_contig (unsigned long nr_pages);extern struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops;
arch/arm64/kvm/hyp/include/nvhe/gfp.h +2 -2
@@ -29,6 +29,6 @@ void hyp_get_page(struct hyp_pool *pool, void *addr);void hyp_put_page (struct hyp_pool *pool,void *addr);/* Used pages cannot be freed */ -int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned int nr_pages, -unsigned int reserved_pages); +int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned long nr_pages, +unsigned long reserved_pages);#endif /* __KVM_HYP_GFP_H */
arch/arm64/kvm/hyp/nvhe/early_alloc.c +1 -1
@@ -21,7 +21,7 @@ unsigned long hyp_early_alloc_nr_used_pages(void)return (cur - base) >>PAGE_SHIFT ; } -void *hyp_early_alloc_contig (unsigned int nr_pages) +void *hyp_early_alloc_contig (unsigned long nr_pages) {unsigned long size = (nr_pages <<PAGE_SHIFT );void *ret = (void *)cur;
arch/arm64/kvm/hyp/nvhe/page_alloc.c +3 -3
@@ -229,12 +229,12 @@ void *hyp_alloc_pages(struct hyp_pool *pool, u8 order)return hyp_page_to_virt (p); } -int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned int nr_pages, -unsigned int reserved_pages) +int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned long nr_pages, +unsigned long reserved_pages) {phys_addr_t phys =hyp_pfn_to_phys (pfn);struct hyp_page *p; -int i; +unsigned long i;hyp_spin_lock_init (&pool->lock); pool->max_order = min(MAX_PAGE_ORDER,
Signature · 1 line
2.56.0.455.g6c5a503b38-goog
Quoted 7 lines · Mostafa Saleh
All the pool sizes in the hypervisor are "unsigned long" but when they get passed to
hyp_early_alloc_contig()orhyp_pool_init()they get truncated to 32-bits.That is not a big problem at the moment as to overflow this we need 4G bytes of carveout (2 TB of host or guest system memory).
Quoted 8 lines
However when new users are added (as IOMMU) it is hard to reason about the carveout size anymore.
Fixes e75960408723 ("KVM: arm64: Introduce an early Hyp page allocator")Fixes 8e17c66249e9 ("KVM: arm64: Introduce a Hyp buddy page allocator")Reviewed-by Fuad Tabba <[email protected]>Acked-by Will Deacon <[email protected]>Signed-off-by Mostafa Saleh <[email protected]>
Thanks,
Oliver
Quoted 69 lines
--- arch/arm64/kvm/hyp/include/nvhe/early_alloc.h | 2 +- arch/arm64/kvm/hyp/include/nvhe/gfp.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/early_alloc.c | 2 +- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-)arch/arm64/kvm/hyp/include/nvhe/early_alloc.h +1
-1@@ -7,7 +7,7 @@void hyp_early_alloc_init (void *virt,unsigned long size);unsigned long hyp_early_alloc_nr_used_pages (void );void *hyp_early_alloc_page (void *arg); -void *hyp_early_alloc_contig (unsigned int nr_pages); +void *hyp_early_alloc_contig (unsigned long nr_pages);extern struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops;arch/arm64/kvm/hyp/include/nvhe/gfp.h +2
-2@@ -29,6 +29,6 @@ void hyp_get_page(struct hyp_pool *pool, void *addr);void hyp_put_page (struct hyp_pool *pool,void *addr);/* Used pages cannot be freed */ -int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned int nr_pages, -unsigned int reserved_pages); +int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned long nr_pages, +unsigned long reserved_pages);#endif /* __KVM_HYP_GFP_H */ arch/arm64/kvm/hyp/nvhe/early_alloc.c +1
-1@@ -21,7 +21,7 @@ unsigned long hyp_early_alloc_nr_used_pages(void)return (cur - base) >>PAGE_SHIFT ; } -void *hyp_early_alloc_contig (unsigned int nr_pages) +void *hyp_early_alloc_contig (unsigned long nr_pages) {unsigned long size = (nr_pages <<PAGE_SHIFT );void *ret = (void *)cur;arch/arm64/kvm/hyp/nvhe/page_alloc.c +3
-3@@ -229,12 +229,12 @@ void *hyp_alloc_pages(struct hyp_pool *pool, u8 order)return hyp_page_to_virt (p); } -int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned int nr_pages, -unsigned int reserved_pages) +int hyp_pool_init (struct hyp_pool *pool,u64 pfn,unsigned long nr_pages, +unsigned long reserved_pages) {phys_addr_t phys =hyp_pfn_to_phys (pfn);struct hyp_page *p; -int i; +unsigned long i;hyp_spin_lock_init (&pool->lock); pool->max_order = min(MAX_PAGE_ORDER,Signature · 1 line
2.56.0.455.g6c5a503b38-goog