From: z00854902 <z00854902@huawei.com> driver inclusion category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/10043 ---------------------------------------------------------------------- use cpu_cache_invalidate_memregion to flush ub mem cache. Signed-off-by: Yuhao Zhang <yuhao.zhang@huawei.com> Signed-off-by: Yushan Wang <wangyushan12@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/ub/obmm/Kconfig | 2 +- drivers/ub/obmm/obmm_cache.c | 26 ++++++++++++-------------- drivers/ub/obmm/obmm_cache.h | 5 ----- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/ub/obmm/Kconfig b/drivers/ub/obmm/Kconfig index 8bbab40d094d..1d09f5d46b45 100644 --- a/drivers/ub/obmm/Kconfig +++ b/drivers/ub/obmm/Kconfig @@ -2,7 +2,7 @@ config OBMM default n tristate "OBMM(ownership based memory management) Support" - depends on UB_UMMU_CORE && UB_UBUS && HISI_SOC_CACHE && ARCH_HAS_COPY_MC + depends on UB_UMMU_CORE && UB_UBUS && ARCH_HAS_COPY_MC depends on NUMA && MEMORY_HOTPLUG && SPARSEMEM_VMEMMAP && ZONE_EXTMEM depends on ARM64_4K_PAGES || ARM64_64K_PAGES select NUMA_REMOTE diff --git a/drivers/ub/obmm/obmm_cache.c b/drivers/ub/obmm/obmm_cache.c index eab31a8df672..508e236fce14 100644 --- a/drivers/ub/obmm/obmm_cache.c +++ b/drivers/ub/obmm/obmm_cache.c @@ -9,9 +9,9 @@ #include <linux/pagewalk.h> #include <linux/hugetlb.h> #include <linux/jiffies.h> +#include <linux/memregion.h> #include <ub/ubus/ub-mem-decoder.h> - #include "obmm_core.h" #include "obmm_export_region_ops.h" #include "obmm_import.h" @@ -51,18 +51,9 @@ int ub_write_queue_flush(uint32_t scna) int flush_cache_by_pa(phys_addr_t addr, size_t size, unsigned long cache_ops) { static DEFINE_SEMAPHORE(sem, 1); - static const enum hisi_soc_cache_maint_type hisi_maint_type[] = { - /* OBMM_SHM_CACHE_NONE does not have a maintenance type */ - [OBMM_SHM_CACHE_NONE] = HISI_CACHE_MAINT_MAX, - [OBMM_SHM_CACHE_INVAL] = HISI_CACHE_MAINT_MAKEINVALID, - [OBMM_SHM_CACHE_WB_INVAL] = HISI_CACHE_MAINT_CLEANINVALID, - [OBMM_SHM_CACHE_WB_ONLY] = HISI_CACHE_MAINT_CLEANSHARED, - }; - phys_addr_t curr_addr = addr; size_t remain_size = size; int ret = 0, round_to_resched = MAX_RESCHED_ROUND; - enum hisi_soc_cache_maint_type maint_type = hisi_maint_type[cache_ops]; if (skip_cache_maintain) { pr_debug_ratelimited("cache maintenance request {cache_ops=%lu}.\n", cache_ops); @@ -72,6 +63,10 @@ int flush_cache_by_pa(phys_addr_t addr, size_t size, unsigned long cache_ops) if (!obmm_is_valid_cache_ops(cache_ops)) return -EINVAL; + if (!cpu_cache_has_invalidate_memregion()) { + pr_err("cpu cache invalidate is not supported.\n"); + return -EOPNOTSUPP; + } down(&sem); while (remain_size != 0) { size_t flush_size; @@ -80,10 +75,11 @@ int flush_cache_by_pa(phys_addr_t addr, size_t size, unsigned long cache_ops) /* retry if there is contention over hardware */ while (true) { - pr_debug("call external: hisi_soc_cache_maintain(0x%llx, 0x%zx, %u)\n", - curr_addr, flush_size, maint_type); - ret = hisi_soc_cache_maintain(curr_addr, flush_size, maint_type); - pr_debug("external called: hisi_soc_cache_maintain(), ret=%pe\n", + /* TOCTOU: cache opt instance is not protected */ + pr_debug("call external: cpu_cache_invalidate_memregion(0x%llx, 0x%zx)\n", + curr_addr, flush_size); + ret = cpu_cache_invalidate_memregion(curr_addr, flush_size); + pr_debug("external called: cpu_cache_invalidate_memregion(), ret=%pe\n", ERR_PTR(ret)); if (ret != -EBUSY) @@ -216,3 +212,5 @@ int modify_pgtable_prot(struct mm_struct *mm, void *va, size_t size, bool cachea return 0; } + +MODULE_IMPORT_NS(DEVMEM); \ No newline at end of file diff --git a/drivers/ub/obmm/obmm_cache.h b/drivers/ub/obmm/obmm_cache.h index a906d5d8f5e4..a4da91dd750b 100644 --- a/drivers/ub/obmm/obmm_cache.h +++ b/drivers/ub/obmm/obmm_cache.h @@ -5,7 +5,6 @@ #ifndef OBMM_CACHE_H #define OBMM_CACHE_H -#include <uapi/misc/hisi_soc_cache/hisi_soc_cache.h> #include "obmm_core.h" int ub_write_queue_flush(uint32_t scna); @@ -30,8 +29,4 @@ static inline bool obmm_is_valid_cache_ops(unsigned long cache_ops) int modify_pgtable_prot(struct mm_struct *mm, void *va, size_t size, bool cacheable); int obmm_cache_clear(void); -/* Defined in drivsers/soc/hisilicon, exported but not defined in their header file. */ -extern int hisi_soc_cache_maintain(phys_addr_t addr, size_t size, - enum hisi_soc_cache_maint_type maint_type); - #endif -- 2.33.0