From 6f63516c0a3b933ce48720741b27eedac14c3fbf Mon Sep 17 00:00:00 2001 From: jsg Date: Thu, 15 Aug 2024 03:04:18 +0000 Subject: [PATCH] drm/amdgpu: Add lock around VF RLCG interface 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 | 1 + sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.c | 6 ++++++ sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.h | 2 ++ 3 files changed, 9 insertions(+) diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c index 81464ea3ab3..948b0fe0765 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_device.c @@ -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"); diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.c index f43b5ca1bc9..2be313e5f4b 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.c @@ -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; } diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.h b/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.h index b62bfd895d3..4362955f648 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.h +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_virt.h @@ -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; -- 2.20.1