habanalabs: add prefetch flag to the MAP operation
authorOhad Sharabi <osharabi@habana.ai>
Sun, 10 Apr 2022 08:19:42 +0000 (11:19 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 22 May 2022 19:01:18 +0000 (21:01 +0200)
This patch let the user decide whether the translations done in the
page tables will be fetched directly to the STLB right after the map.

We want to let the user control whether to perform prefetch upon map
operation.

To do so a memory flag was added, to be used in the MAP ioctl, called
HL_MEM_PREFETCH and if set- the mappings will be fetched directly to
the STLB after map operation.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/habanalabs/common/memory.c
include/uapi/misc/habanalabs.h

index 326c217..6face45 100644 (file)
@@ -1250,11 +1250,12 @@ static int map_device_va(struct hl_ctx *ctx, struct hl_mem_in *args,
        if (rc)
                goto map_err;
 
-       /* already prefetch the relevant translations to the cache */
-       rc = hl_mmu_prefetch_cache_range(hdev, *vm_type, ctx->asid, ret_vaddr,
-                                               phys_pg_pack->total_size);
-       if (rc)
-               goto map_err;
+       if (args->flags & HL_MEM_PREFETCH) {
+               rc = hl_mmu_prefetch_cache_range(hdev, *vm_type, ctx->asid, ret_vaddr,
+                                                       phys_pg_pack->total_size);
+               if (rc)
+                       goto map_err;
+       }
 
        mutex_unlock(&ctx->mmu_lock);
 
index ca2af5f..3576bf2 100644 (file)
@@ -1134,6 +1134,7 @@ union hl_wait_cs_args {
 #define HL_MEM_SHARED          0x2
 #define HL_MEM_USERPTR         0x4
 #define HL_MEM_FORCE_HINT      0x8
+#define HL_MEM_PREFETCH                0x40
 
 /**
  * structure hl_mem_in - structure that handle input args for memory IOCTL