drm/amdkfd: Fix double release compute pasid
authorjsg <jsg@openbsd.org>
Fri, 13 Jan 2023 01:40:51 +0000 (01:40 +0000)
committerjsg <jsg@openbsd.org>
Fri, 13 Jan 2023 01:40:51 +0000 (01:40 +0000)
From Philip Yang
a02c07b619899179384fde06f951530438a3512d in linux-6.1.y/6.1.5
1a799c4c190ea9f0e81028e3eb3037ed0ab17ff5 in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu_amdkfd.h
sys/dev/pci/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
sys/dev/pci/drm/amd/amdkfd/kfd_process.c

index e6ab19b..5e0a071 100644 (file)
@@ -265,8 +265,10 @@ int amdgpu_amdkfd_get_pcie_bandwidth_mbytes(struct amdgpu_device *adev, bool is_
        (&((struct amdgpu_fpriv *)                                      \
                ((struct drm_file *)(drm_priv))->driver_priv)->vm)
 
+int amdgpu_amdkfd_gpuvm_set_vm_pasid(struct amdgpu_device *adev,
+                                    struct file *filp, u32 pasid);
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
-                                       struct file *filp, u32 pasid,
+                                       struct file *filp,
                                        void **process_info,
                                        struct dma_fence **ef);
 void amdgpu_amdkfd_gpuvm_release_process_vm(struct amdgpu_device *adev,
index 279db18..417c08a 100644 (file)
@@ -1473,10 +1473,9 @@ static void amdgpu_amdkfd_gpuvm_unpin_bo(struct amdgpu_bo *bo)
        amdgpu_bo_unreserve(bo);
 }
 
-int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
-                                          struct file *filp, u32 pasid,
-                                          void **process_info,
-                                          struct dma_fence **ef)
+int amdgpu_amdkfd_gpuvm_set_vm_pasid(struct amdgpu_device *adev,
+                                    struct file *filp, u32 pasid)
+
 {
        struct amdgpu_fpriv *drv_priv;
        struct amdgpu_vm *avm;
@@ -1487,10 +1486,6 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
                return ret;
        avm = &drv_priv->vm;
 
-       /* Already a compute VM? */
-       if (avm->process_info)
-               return -EINVAL;
-
        /* Free the original amdgpu allocated pasid,
         * will be replaced with kfd allocated pasid.
         */
@@ -1499,14 +1494,36 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
                amdgpu_vm_set_pasid(adev, avm, 0);
        }
 
-       /* Convert VM into a compute VM */
-       ret = amdgpu_vm_make_compute(adev, avm);
+       ret = amdgpu_vm_set_pasid(adev, avm, pasid);
        if (ret)
                return ret;
 
-       ret = amdgpu_vm_set_pasid(adev, avm, pasid);
+       return 0;
+}
+
+int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct amdgpu_device *adev,
+                                          struct file *filp,
+                                          void **process_info,
+                                          struct dma_fence **ef)
+{
+       struct amdgpu_fpriv *drv_priv;
+       struct amdgpu_vm *avm;
+       int ret;
+
+       ret = amdgpu_file_to_fpriv(filp, &drv_priv);
        if (ret)
                return ret;
+       avm = &drv_priv->vm;
+
+       /* Already a compute VM? */
+       if (avm->process_info)
+               return -EINVAL;
+
+       /* Convert VM into a compute VM */
+       ret = amdgpu_vm_make_compute(adev, avm);
+       if (ret)
+               return ret;
+
        /* Initialize KFD part of the VM and process info */
        ret = init_kfd_vm(avm, process_info, ef);
        if (ret)
index 9821fa9..dd35110 100644 (file)
@@ -1576,9 +1576,9 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
        p = pdd->process;
        dev = pdd->dev;
 
-       ret = amdgpu_amdkfd_gpuvm_acquire_process_vm(
-               dev->adev, drm_file, p->pasid,
-               &p->kgd_process_info, &p->ef);
+       ret = amdgpu_amdkfd_gpuvm_acquire_process_vm(dev->adev, drm_file,
+                                                    &p->kgd_process_info,
+                                                    &p->ef);
        if (ret) {
                pr_err("Failed to create process VM object\n");
                return ret;
@@ -1593,10 +1593,16 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
        if (ret)
                goto err_init_cwsr;
 
+       ret = amdgpu_amdkfd_gpuvm_set_vm_pasid(dev->adev, drm_file, p->pasid);
+       if (ret)
+               goto err_set_pasid;
+
        pdd->drm_file = drm_file;
 
        return 0;
 
+err_set_pasid:
+       kfd_process_device_destroy_cwsr_dgpu(pdd);
 err_init_cwsr:
        kfd_process_device_destroy_ib_mem(pdd);
 err_reserve_ib_mem: