driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10043 ---------------------------------------------------------------------- hisi_soc_cache_aligned_alloc was introduced to make sure that allocated memory has aligned address to its size. This is actually not needed since alloc_contig_pages already gurantees it. As we have changed from alloc_pages to alloc_contig_pages, no more tweaks need to be done for address alignness. So remove this function and switch back to native alloc_contig_pages. Fixes: c4e09ac64bc7 ("soc cache: support L3 cache lock in framework") Signed-off-by: Yushan Wang <wangyushan12@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- .../soc/hisilicon/hisi_soc_cache_framework.c | 123 +++++------------- 1 file changed, 32 insertions(+), 91 deletions(-) diff --git a/drivers/soc/hisilicon/hisi_soc_cache_framework.c b/drivers/soc/hisilicon/hisi_soc_cache_framework.c index d1c24a0ef828..c2dc8062ff86 100644 --- a/drivers/soc/hisilicon/hisi_soc_cache_framework.c +++ b/drivers/soc/hisilicon/hisi_soc_cache_framework.c @@ -27,8 +27,6 @@ #include "hisi_soc_cache_framework.h" struct hisi_soc_cache_lock_region { - /* physical address of the arena allocated for aligned address */ - unsigned long arena_start; /* VMA region of locked memory for future release */ unsigned long vm_start; unsigned long vm_end; @@ -212,69 +210,6 @@ int hisi_soc_comp_inst_del(struct hisi_soc_comp *comp) } EXPORT_SYMBOL_GPL(hisi_soc_comp_inst_del); -/** - * hisi_soc_cache_aligned_alloc - Allocate memory region to be locked and - * returns address that aligned to the requested - * size. - * @clr: The locked memory region to be allocated for. - * @size: Requested memory size. - * @addr: Pointer of the start physical address of the requested - * memory region. - * - * @return: - * - -ENOMEM: If allocation fails. - * - 0: If allocations succeeds. - * - * Physical address of allocated memory region is requested to be aligned to - * its size. In order to achieve that, add the order of requested memory size - * by 1 to double the size of allocated memory to ensure the existence of size- - * aligned address. After locating the aligned region, release the unused - * pages from both sides to avoid waste. - */ -static int hisi_soc_cache_aligned_alloc(struct hisi_soc_cache_lock_region *clr, - unsigned long size, - unsigned long *addr) -{ - int order = get_order(size) + 1; - unsigned long arena_start; - struct page *pg; - - pg = alloc_contig_pages(1UL << order, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, - cpu_to_node(smp_processor_id()), NULL); - if (!pg) - return -ENOMEM; - - arena_start = page_to_phys(pg); - - /* - * Align up the address by the requested size if the address is not - * naturally aligned to the size. - */ - *addr = arena_start % size == 0 - ? arena_start - : arena_start / size * size + size; - - clr->arena_start = arena_start; - - return 0; -} - -/** - * hisi_soc_cache_aligned_free - Free the aligned memory region allcated by - * hisi_soc_cache_aligned_alloc(). - * @clr: The allocated locked memory region. - * - * Since unused memory pages are release in hisi_soc_cache_aligned_alloc(), the - * memory region to be freed here may not be power of 2 numbers of pages. - * Thus split the memory by page order and release them accordingly. - */ -static void hisi_soc_cache_aligned_free(struct hisi_soc_cache_lock_region *clr) -{ - int order = get_order(clr->size) + 1; - - free_contig_range(PHYS_PFN(clr->arena_start), 1 << order); -} - static void hisi_soc_cache_vm_open(struct vm_area_struct *vma) { struct hisi_soc_cache_lock_region *clr = vma->vm_private_data; @@ -292,6 +227,7 @@ static void hisi_soc_cache_vm_open(struct vm_area_struct *vma) static void hisi_soc_cache_vm_close(struct vm_area_struct *vma) { struct hisi_soc_cache_lock_region *clr = vma->vm_private_data; + int order = get_order(clr->size); /* * Only perform cache unlock when the vma passed in is created @@ -302,7 +238,7 @@ static void hisi_soc_cache_vm_close(struct vm_area_struct *vma) hisi_soc_cache_unlock(clr->cpu, clr->addr); - hisi_soc_cache_aligned_free(clr); + free_contig_range(PHYS_PFN(clr->addr), 1 << order); kfree(clr); vma->vm_private_data = NULL; } @@ -342,50 +278,55 @@ static const struct vm_operations_struct hisi_soc_cache_vm_ops = { static int hisi_soc_cache_mmap(struct file *file, struct vm_area_struct *vma) { unsigned long size = vma->vm_end - vma->vm_start; - struct hisi_soc_cache_lock_region *clr; + int order = get_order(size); unsigned long addr; + struct page *pg; int ret; - clr = kzalloc(sizeof(*clr), GFP_KERNEL); + struct hisi_soc_cache_lock_region *clr __free(kfree) = + kzalloc(sizeof(struct hisi_soc_cache_lock_region), GFP_KERNEL); if (!clr) return -ENOMEM; - ret = hisi_soc_cache_aligned_alloc(clr, size, &addr); - if (ret) - goto out_clr; + /* Continuous physical memory is required for L3 cache lock. */ + pg = alloc_contig_pages(1 << order, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, + cpu_to_node(smp_processor_id()), NULL); + if (!pg) + return -ENOMEM; - ret = remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT, size, - vma->vm_page_prot); - if (ret) - goto out_page; + addr = page_to_phys(pg); + *clr = (struct hisi_soc_cache_lock_region) { + /* vma should not be moved, store here for validation */ + .vm_start = vma->vm_start, + .vm_end = vma->vm_end, + .addr = addr, + .size = size, + .cpu = smp_processor_id(), + }; - clr->addr = addr; - clr->size = size; - clr->cpu = smp_processor_id(); vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND); - - /* - * The vma should not be moved throughout its lifetime, store the - * region for verification. - */ - clr->vm_start = vma->vm_start; - clr->vm_end = vma->vm_end; - - vma->vm_private_data = clr; vma->vm_ops = &hisi_soc_cache_vm_ops; - hisi_soc_cache_vm_ops.open(vma); + vma->vm_private_data = clr; + hisi_soc_cache_vm_open(vma); if (clr->status) { ret = clr->status; goto out_page; } + ret = remap_pfn_range(vma, vma->vm_start, PFN_DOWN(addr), size, + vma->vm_page_prot); + if (ret) + goto out_page; + + /* Save clr from being freed when lock succeeds. */ + vma->vm_private_data = no_free_ptr(clr); + return 0; out_page: - hisi_soc_cache_aligned_free(clr); -out_clr: - kfree(clr); + + free_contig_range(PHYS_PFN(clr->addr), 1 << order); return ret; } -- 2.33.0