drm/amdgpu: Add lock around VF RLCG interface
authorjsg <jsg@openbsd.org>
Thu, 15 Aug 2024 03:04:18 +0000 (03:04 +0000)
committerjsg <jsg@openbsd.org>
Thu, 15 Aug 2024 03:04:18 +0000 (03:04 +0000)
From Victor Skvortsov
1adb5ebe205e96af77a93512e2d5b8c437548787 in linux-6.6.y/6.6.46
e864180ee49b4d30e640fd1e1d852b86411420c9 in mainline linux

sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c
sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.c
sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.h

index 81464ea..948b0fe 100644 (file)
@@ -3593,6 +3593,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
        rw_init(&adev->grbm_idx_mutex, "grbmidx");
        rw_init(&adev->mn_lock, "agpumn");
        rw_init(&adev->virt.vf_errors.lock, "vferr");
+       rw_init(&adev->virt.rlcg_reg_lock, "vrlcg");
        hash_init(adev->mn_hash);
        rw_init(&adev->psp.mutex, "agpsp");
        rw_init(&adev->notifier_lock, "agnf");
index f43b5ca..2be313e 100644 (file)
@@ -1004,6 +1004,9 @@ static u32 amdgpu_virt_rlcg_reg_rw(struct amdgpu_device *adev, u32 offset, u32 v
        scratch_reg1 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg1;
        scratch_reg2 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg2;
        scratch_reg3 = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->scratch_reg3;
+
+       mutex_lock(&adev->virt.rlcg_reg_lock);
+
        if (reg_access_ctrl->spare_int)
                spare_int = (void __iomem *)adev->rmmio + 4 * reg_access_ctrl->spare_int;
 
@@ -1059,6 +1062,9 @@ static u32 amdgpu_virt_rlcg_reg_rw(struct amdgpu_device *adev, u32 offset, u32 v
        }
 
        ret = readl(scratch_reg0);
+
+       mutex_unlock(&adev->virt.rlcg_reg_lock);
+
        return ret;
 }
 
index b62bfd8..4362955 100644 (file)
@@ -263,6 +263,8 @@ struct amdgpu_virt {
 
        /* the ucode id to signal the autoload */
        uint32_t autoload_ucode_id;
+
+       struct rwlock rlcg_reg_lock;
 };
 
 struct amdgpu_video_codec_info;