driver inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IDBQ74 ---------------------------------------------------------------------- During walking pages, if the memory region assigned is within a pmd, the page offset will be reserved, but if multiple pmds are involved, the offset will not be reserved, causing incorrect failure of page range check and the required range. Fix this by align the requested memory region to PAGE_SIZE, and eliminate the unnecessary check. Fixes: e6ecc3b028b8 ("soc cache: Add framework driver for HiSilicon SoC cache") Signed-off-by: Yushan Wang <wangyushan12@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- .../soc/hisilicon/hisi_soc_cache_framework.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/soc/hisilicon/hisi_soc_cache_framework.c b/drivers/soc/hisilicon/hisi_soc_cache_framework.c index 1247d5aac333..d003bb3ac632 100644 --- a/drivers/soc/hisilicon/hisi_soc_cache_framework.c +++ b/drivers/soc/hisilicon/hisi_soc_cache_framework.c @@ -154,23 +154,17 @@ static int hisi_soc_cache_maint_pte_entry(pte_t *pte, unsigned long addr, unsigned long next, struct mm_walk *walk) { #ifdef HISI_SOC_CACHE_LLT - struct hisi_soc_cache_ioctl_param *param = - (struct hisi_soc_cache_ioctl_param *)walk->priv; + struct hisi_soc_cache_ioctl_param *param = walk->priv; #else - struct hisi_soc_cache_ioctl_param *param = - (struct hisi_soc_cache_ioctl_param *)walk->private; + struct hisi_soc_cache_ioctl_param *param = walk->private; #endif - size_t size = next - addr; - phys_addr_t paddr; - - if (next > param->addr + param->size) - return -EINVAL; + size_t size = min(next - addr, param->size + param->addr - addr); + unsigned long offset = offset_in_page(max(addr, param->addr)); + phys_addr_t paddr = PFN_PHYS(pte_pfn(*pte)) + offset; if (!pte_present(ptep_get(pte))) return -EINVAL; - paddr = PFN_PHYS(pte_pfn(*pte)) + offset_in_page(addr); - return hisi_soc_cache_maintain(paddr, size, param->op_type); } @@ -491,9 +485,9 @@ static int __hisi_soc_cache_maintain(struct hisi_soc_cache_ioctl_param *param) goto out; } - ret = walk_page_range(current->mm, start, start + param->size, + ret = walk_page_range(current->mm, PAGE_ALIGN_DOWN(start), + PAGE_ALIGN(start + param->size), &hisi_soc_cache_maint_walk, param); - out: mmap_read_unlock(current->mm); return ret; -- 2.33.0