]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
amdkfd: process USERPTR allocation only on the primary kfd process
authorZhu Lingshan <lingshan.zhu@amd.com>
Mon, 30 Jun 2025 03:00:29 +0000 (11:00 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 8 Dec 2025 18:56:42 +0000 (13:56 -0500)
The lifecycle of the primary kfd process is tied to
the user space program, all secondary kfd process
would be destroyed when fd close. Thus only the primary
kfd process should process USERPTR memory allocation.

Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

index 2226281e8146c3fca61dae5a6090538c71321ea5..ff1a6a90346331feba35637ba20897149a0eb91b 100644 (file)
@@ -1062,6 +1062,12 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
        if (args->size == 0)
                return -EINVAL;
 
+       if (p->context_id != KFD_CONTEXT_ID_PRIMARY && (flags & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR)) {
+               pr_debug("USERPTR is not supported on non-primary kfd_process\n");
+
+               return -EOPNOTSUPP;
+       }
+
 #if IS_ENABLED(CONFIG_HSA_AMD_SVM)
        /* Flush pending deferred work to avoid racing with deferred actions
         * from previous memory map changes (e.g. munmap).