drm/amdgpu: Fix MMIO access page fault
Subsystems (2)
PATCH 1/2 drm/amdgpu: Fix MMIO access page fault
Add more guards to MMIO access post device
unbind/unplug
--- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 8 ++++++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 17 +++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +6 -2
@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h"
@@ -194,11 +195,14 @@ static int vcn_v2_0_sw_init(void *handle)*/ static int vcn_v2_0_sw_fini (void *handle) { -int r; +int r, idx;struct amdgpu_device *adev = (struct amdgpu_device *)handle;volatile struct amdgpu_fw_shared *fw_shared = adev->vcn.inst->fw_shared_cpu_addr; - fw_shared->present_flag_0 =0 ; +if (drm_dev_enter (&adev->ddev, &idx)) { + fw_shared->present_flag_0 =0 ; +drm_dev_exit (idx); + }amdgpu_virt_free_mm_table (adev);
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +11 -6
@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h"
@@ -235,17 +236,21 @@ static int vcn_v2_5_sw_init(void *handle)*/ static int vcn_v2_5_sw_fini (void *handle) { -int i, r; +int i, r, idx;struct amdgpu_device *adev = (struct amdgpu_device *)handle;volatile struct amdgpu_fw_shared *fw_shared; -for (i =0 ; i < adev->vcn.num_vcn_inst; i++) { -if (adev->vcn.harvest_config & (1 << i)) -continue ; - fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; - fw_shared->present_flag_0 =0 ; +if (drm_dev_enter (&adev->ddev, &idx)) { +for (i =0 ; i < adev->vcn.num_vcn_inst; i++) { +if (adev->vcn.harvest_config & (1 << i)) +continue ; + fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; + fw_shared->present_flag_0 =0 ; + } +drm_dev_exit (idx); } +if (amdgpu_sriov_vf (adev))amdgpu_virt_free_mm_table (adev);
Signature · 1 line
2.25.1
PATCH 2/2 drm/amdgpu: Fix resume failures when device is gone
Problem:
When device goes into suspend and unplugged during it then all HW programming during resume fails leading to a bad SW during pci remove handling which follows. Because device is first resumed and only later removed we cannot rely on drm_dev_enter/exit here.
Fix:
Use a flag we use for PCIe error recovery to avoid accessing registres. This allows to successfully complete pm resume sequence and finish pci remove.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4 -0
@@ -1522,6 +1522,10 @@ static int amdgpu_pmops_resume(struct device *dev)struct amdgpu_device *adev =drm_to_adev (drm_dev);int r; +/* Avoids registers access if device is physically gone */ +if (!pci_device_is_present (adev->pdev)) + adev->no_hw_access = true; + r =amdgpu_device_resume (drm_dev, true);if (amdgpu_acpi_is_s0ix_active (adev)) adev->in_s0ix = false;
Signature · 1 line
2.25.1
Re: [PATCH 2/2] drm/amdgpu: Fix resume failures when device is gone
Ping
Andrey
Quoted 32 lines · Andrey Grodzovsky
Problem:
When device goes into suspend and unplugged during it then all HW programming during resume fails leading to a bad SW during pci remove handling which follows. Because device is first resumed and only later removed we cannot rely on drm_dev_enter/exit here.Fix:
Use a flag we use for PCIe error recovery to avoid accessing registres. This allows to successfully complete pm resume sequence and finish pci remove.Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-0@@ -1522,6 +1522,10 @@ static int amdgpu_pmops_resume(struct device *dev)struct amdgpu_device *adev =drm_to_adev (drm_dev);int r; +/* Avoids registers access if device is physically gone */ +if (!pci_device_is_present (adev->pdev)) + adev->no_hw_access = true; + r =amdgpu_device_resume (drm_dev, true);if (amdgpu_acpi_is_s0ix_active (adev)) adev->in_s0ix = false;
Re: [PATCH 2/2] drm/amdgpu: Fix resume failures when device is gone
In reply to Andrey GrodzovskySeries is:
Quoted 36 lines · Andrey Grodzovsky
Problem:
When device goes into suspend and unplugged during it then all HW programming during resume fails leading to a bad SW during pci remove handling which follows. Because device is first resumed and only later removed we cannot rely on drm_dev_enter/exit here.Fix:
Use a flag we use for PCIe error recovery to avoid accessing registres. This allows to successfully complete pm resume sequence and finish pci remove.Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-1@@ -1522,6 +1522,10 @@ static int amdgpu_pmops_resume(struct device *dev)struct amdgpu_device *adev =drm_to_adev (drm_dev);int r; +/* Avoids registers access if device is physically gone */ +if (!pci_device_is_present (adev->pdev)) + adev->no_hw_access = true; + r =amdgpu_device_resume (drm_dev, true);if (amdgpu_acpi_is_s0ix_active (adev)) adev->in_s0ix = false; --2.25.1
Hi Andrey
Can you apply this improvement on vcn_v3_0_sw_init also?
With this adding, This patch is Reviewed-by: James Zhu <[email protected]>
Thanks & Best Regards!
James
Quoted 79 lines · Andrey Grodzovsky
Add more guards to MMIO access post device
unbind/unplugSigned-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 8 ++++++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 17 +++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +6
-2@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h" @@ -194,11 +195,14 @@ static int vcn_v2_0_sw_init(void *handle)*/ static int vcn_v2_0_sw_fini (void *handle) { -int r; +int r, idx;struct amdgpu_device *adev = (struct amdgpu_device *)handle;volatile struct amdgpu_fw_shared *fw_shared = adev->vcn.inst->fw_shared_cpu_addr; - fw_shared->present_flag_0 =0 ; +if (drm_dev_enter (&adev->ddev, &idx)) { + fw_shared->present_flag_0 =0 ; +drm_dev_exit (idx); + }amdgpu_virt_free_mm_table (adev);drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +11
-6@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h" @@ -235,17 +236,21 @@ static int vcn_v2_5_sw_init(void *handle)*/ static int vcn_v2_5_sw_fini (void *handle) { -int i, r; +int i, r, idx;struct amdgpu_device *adev = (struct amdgpu_device *)handle;volatile struct amdgpu_fw_shared *fw_shared; -for (i =0 ; i < adev->vcn.num_vcn_inst; i++) { -if (adev->vcn.harvest_config & (1 << i)) -continue ; - fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; - fw_shared->present_flag_0 =0 ; +if (drm_dev_enter (&adev->ddev, &idx)) { +for (i =0 ; i < adev->vcn.num_vcn_inst; i++) { +if (adev->vcn.harvest_config & (1 << i)) +continue ; + fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; + fw_shared->present_flag_0 =0 ; + } +drm_dev_exit (idx); } +if (amdgpu_sriov_vf (adev))amdgpu_virt_free_mm_table (adev);
typo. vcn_v3_0_sw_init --> vcn_v3_0_sw_fini
Quoted 81 lines · James Zhu
Hi Andrey
Can you apply this improvement on
vcn_v3_0_sw_initalso?With this adding, This patch is Reviewed-by: James Zhu <[email protected]>
Thanks & Best Regards!
James
Quoted 70 lines · Andrey Grodzovsky
Add more guards to MMIO access post device
unbind/unplugSigned-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c| 8 ++++++--drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c| 17 +++++++++++------2 files changed, 17 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +6
-1@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h"@@ -194,11 +195,14 @@ static int vcn_v2_0_sw_init(void *handle)*/ static int vcn_v2_0_sw_fini(void *handle) { - int r; + int r, idx; struct amdgpu_device *adev = (struct amdgpu_device *)handle; volatile struct amdgpu_fw_shared *fw_shared = adev->vcn.inst->fw_shared_cpu_addr; - fw_shared->present_flag_0 = 0; + if (drm_dev_enter(&adev->ddev, &idx)) { + fw_shared->present_flag_0 = 0; + drm_dev_exit(idx); + } amdgpu_virt_free_mm_table(adev);diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cindex2e6b7913bf6c..1780ad1eacd6100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +10
-5@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h"@@ -235,17 +236,21 @@ static int vcn_v2_5_sw_init(void *handle)*/ static int vcn_v2_5_sw_fini(void *handle) { - int i, r; + int i, r, idx; struct amdgpu_device *adev = (struct amdgpu_device *)handle; volatile struct amdgpu_fw_shared *fw_shared; - for (i = 0; i < adev->vcn.num_vcn_inst; i++) { - if (adev->vcn.harvest_config & (1 << i)) - continue; - fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; - fw_shared->present_flag_0 = 0; + if (drm_dev_enter(&adev->ddev, &idx)) { + for (i = 0; i < adev->vcn.num_vcn_inst; i++) { + if (adev->vcn.harvest_config & (1 << i)) + continue; + fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; + fw_shared->present_flag_0 = 0; + } + drm_dev_exit(idx); }+
if (amdgpu_sriov_vf(adev))
amdgpu_virt_free_mm_table(adev);
Note that it already has this protection.
Andrey
Quoted 84 lines · James Zhu
typo. vcn_v3_0_sw_init -->
vcn_v3_0_sw_finiQuoted 81 lines · James Zhu
Hi Andrey
Can you apply this improvement on
vcn_v3_0_sw_initalso?With this adding, This patch is Reviewed-by: James Zhu <[email protected]>
Thanks & Best Regards!
James
Quoted 70 lines · Andrey Grodzovsky
Add more guards to MMIO access post device
unbind/unplugSigned-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c| 8 ++++++--drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c| 17 +++++++++++------2 files changed, 17 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +6
-1@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h"@@ -194,11 +195,14 @@ static int vcn_v2_0_sw_init(void *handle)*/ static int vcn_v2_0_sw_fini(void *handle) { - int r; + int r, idx; struct amdgpu_device *adev = (struct amdgpu_device *)handle; volatile struct amdgpu_fw_shared *fw_shared = adev->vcn.inst->fw_shared_cpu_addr; - fw_shared->present_flag_0 = 0; + if (drm_dev_enter(&adev->ddev, &idx)) { + fw_shared->present_flag_0 = 0; + drm_dev_exit(idx); + } amdgpu_virt_free_mm_table(adev);diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cindex2e6b7913bf6c..1780ad1eacd6100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +10
-5@@ -22,6 +22,7 @@*/ #include <linux/firmware.h> +#include <drm/drm_drv.h> #include "amdgpu.h" #include "amdgpu_vcn.h"@@ -235,17 +236,21 @@ static int vcn_v2_5_sw_init(void *handle)*/ static int vcn_v2_5_sw_fini(void *handle) { - int i, r; + int i, r, idx; struct amdgpu_device *adev = (struct amdgpu_device *)handle; volatile struct amdgpu_fw_shared *fw_shared; - for (i = 0; i < adev->vcn.num_vcn_inst; i++) { - if (adev->vcn.harvest_config & (1 << i)) - continue; - fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; - fw_shared->present_flag_0 = 0; + if (drm_dev_enter(&adev->ddev, &idx)) { + for (i = 0; i < adev->vcn.num_vcn_inst; i++) { + if (adev->vcn.harvest_config & (1 << i)) + continue; + fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr; + fw_shared->present_flag_0 = 0; + } + drm_dev_exit(idx); }+
if (amdgpu_sriov_vf(adev))
amdgpu_virt_free_mm_table(adev);