drm/amdgpu: check if vram is lost
Subsystems (2)
PATCH 1/3 drm/amdgpu: check if vram is lost
bakup first 64 byte of gart table as reset magic, check if magic is same after gpu hw reset.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -1502,6 +1502,7 @@ struct amdgpu_ssg {#endif }; +#define AMDGPU_RESET_MAGIC_NUM 64struct amdgpu_device {struct device *dev;struct drm_device *ddev;
@@ -1705,6 +1706,7 @@ struct amdgpu_device {/* record hw reset is performed */ bool has_hw_reset; +u8 reset_magic[AMDGPU_RESET_MAGIC_NUM ]; };
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +25 -1
@@ -1685,6 +1685,23 @@ static int amdgpu_init(struct amdgpu_device *adev)return 0 ; } +static void amdgpu_fill_reset_magic (struct amdgpu_device *adev) +{ +memcpy (adev->reset_magic, adev->gart.ptr,AMDGPU_RESET_MAGIC_NUM ); +} + +static bool amdgpu_check_vram_lost (struct amdgpu_device *adev) +{ +int i; + +for (i =0 ; i <AMDGPU_RESET_MAGIC_NUM ; i++) { +if (*((u8 *)(adev->gart.ptr + i)) != adev->reset_magic[i]) +return true; + } + +return false; +} +static int amdgpu_late_init (struct amdgpu_device *adev) {int i =0 , r;
@@ -1715,6 +1732,8 @@ static int amdgpu_late_init(struct amdgpu_device *adev) } } +amdgpu_fill_reset_magic (adev); +return 0 ; }
@@ -2830,7 +2849,7 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)struct drm_atomic_state *state =NULL ;int i, r;int resched; -bool need_full_reset; +bool need_full_reset, vram_lost = false;if (amdgpu_sriov_vf (adev))return amdgpu_sriov_gpu_reset (adev, true);
@@ -2899,12 +2918,17 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev) r =amdgpu_resume_phase1 (adev);if (r) goto out; + vram_lost =amdgpu_check_vram_lost (adev); +if (vram_lost) +DRM_ERROR ("VRAM is lost!\n" ); r =amdgpu_ttm_recover_gart (adev);if (r) goto out; r =amdgpu_resume_phase2 (adev);if (r) goto out; +if (vram_lost) +amdgpu_fill_reset_magic (adev); } } out:
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1494917069-29054-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
PATCH 2/3 drm/amdgpu: return -ENODEV to user space when vram is lost
below ioctl will return -ENODEV:amdgpu_cs_ioctlamdgpu_cs_wait_ioctlamdgpu_cs_wait_fences_ioctlamdgpu_gem_va_ioctlamdgpu_info_ioctl
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 10 ++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -855,6 +855,7 @@ struct amdgpu_fpriv {struct amdgpu_ctx_mgr ctx_mgr;spinlock_t sem_handles_lock;struct idr sem_handles; +u32 vram_lost_counter; };/*
@@ -1607,6 +1608,7 @@ struct amdgpu_device {atomic64_t num_bytes_moved;atomic64_t num_evictions;atomic_t gpu_reset_counter; +atomic_t vram_lost_counter;/* data for buffer migration throttling */ struct {
@@ -2005,6 +2007,8 @@ static inline void amdgpu_unregister_atpx_handler(void) {}extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];extern const int amdgpu_max_kms_ioctl; +bool amdgpu_kms_vram_lost (struct amdgpu_device *adev, +struct amdgpu_fpriv *fpriv);int amdgpu_driver_load_kms (struct drm_device *dev,unsigned long flags);int amdgpu_driver_unload_kms (struct drm_device *dev);void amdgpu_driver_lastclose_kms (struct drm_device *dev);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9 -0
@@ -1097,6 +1097,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,int amdgpu_cs_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;union drm_amdgpu_cs *cs = data;struct amdgpu_cs_parser parser = {};bool reserved_buffers = false;
@@ -1104,6 +1105,8 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)if (!adev->accel_working)return -EBUSY ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ; parser.adev = adev; parser.filp = filp;
@@ -1165,12 +1168,15 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, {union drm_amdgpu_wait_cs *wait = data;struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout);struct amdgpu_ring *ring =NULL ;struct amdgpu_ctx *ctx;struct fence *fence;long r; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ; r =amdgpu_cs_get_ring (adev, wait->in.ip_type, wait->in.ip_instance, wait->in.ring, &ring);if (r)
@@ -1344,12 +1350,15 @@ int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;union drm_amdgpu_wait_fences *wait = data;uint32_t fence_count = wait->in.fence_count;struct drm_amdgpu_fence *fences_user;struct drm_amdgpu_fence *fences;int r; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;/* Get the fences from userspace */ fences =kmalloc_array (fence_count,sizeof (struct drm_amdgpu_fence ),GFP_KERNEL );
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
@@ -2919,8 +2919,10 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)if (r) goto out; vram_lost =amdgpu_check_vram_lost (adev); -if (vram_lost) +if (vram_lost) {DRM_ERROR ("VRAM is lost!\n" ); +atomic_inc (&adev->vram_lost_counter); + } r =amdgpu_ttm_recover_gart (adev);if (r) goto out;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -0
@@ -776,6 +776,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,if (!adev->vm_manager.enabled)return -ENOTTY ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;if (args->va_address <AMDGPU_VA_RESERVED_SIZE ) { dev_err(&dev->pdev->dev,
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
@@ -235,6 +235,7 @@ static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,static int amdgpu_info_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;struct drm_amdgpu_info *info = data;struct amdgpu_mode_info *minfo = &adev->mode_info;void __user *out = (void __user *)(uintptr_t )info->return_pointer;
@@ -247,6 +248,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_fileif (!info->return_size || !info->return_pointer)return -EINVAL ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;switch (info->query) {case AMDGPU_INFO_VIRTUAL_RANGE : {
@@ -779,6 +782,12 @@ void amdgpu_driver_lastclose_kms(struct drm_device *dev)vga_switcheroo_process_delayed_switch (); } +bool amdgpu_kms_vram_lost (struct amdgpu_device *adev, +struct amdgpu_fpriv *fpriv) +{ +return fpriv->vram_lost_counter !=atomic_read (&adev->vram_lost_counter); +} +/** * amdgpu_driver_open_kms - drm callback for open *
@@ -833,6 +842,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)amdgpu_ctx_mgr_init (&fpriv->ctx_mgr); + fpriv->vram_lost_counter =atomic_read (&adev->vram_lost_counter); file_priv->driver_priv = fpriv; out_suspend:
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1494917069-29054-2-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/3] drm/amdgpu: return -ENODEV to user space when vram is lost
Am 16.05.2017 um 08:44 schrieb Chunming Zhou:
Quoted 120 lines
below ioctl will return
-ENODEV:amdgpu_cs_ioctlamdgpu_cs_wait_ioctlamdgpu_cs_wait_fences_ioctlamdgpu_gem_va_ioctlamdgpu_info_ioctlChange-Id I8970cde3301b7cfeb4263cc0f0e54aece215c98eSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 10 ++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -855,6 +855,7 @@ struct amdgpu_fpriv {struct amdgpu_ctx_mgr ctx_mgr;spinlock_t sem_handles_lock;struct idr sem_handles; +u32 vram_lost_counter; };/* @@ -1607,6 +1608,7 @@ struct amdgpu_device {atomic64_t num_bytes_moved;atomic64_t num_evictions;atomic_t gpu_reset_counter; +atomic_t vram_lost_counter;/* data for buffer migration throttling */ struct {@@ -2005,6 +2007,8 @@ static inline void amdgpu_unregister_atpx_handler(void) {}extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];extern const int amdgpu_max_kms_ioctl; +bool amdgpu_kms_vram_lost (struct amdgpu_device *adev, +struct amdgpu_fpriv *fpriv);int amdgpu_driver_load_kms (struct drm_device *dev,unsigned long flags);int amdgpu_driver_unload_kms (struct drm_device *dev);void amdgpu_driver_lastclose_kms (struct drm_device *dev);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +9
-0@@ -1097,6 +1097,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,int amdgpu_cs_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;union drm_amdgpu_cs *cs = data;struct amdgpu_cs_parser parser = {};bool reserved_buffers = false;@@ -1104,6 +1105,8 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)if (!adev->accel_working)return -EBUSY ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ; parser.adev = adev; parser.filp = filp;@@ -1165,12 +1168,15 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, {union drm_amdgpu_wait_cs *wait = data;struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout);struct amdgpu_ring *ring =NULL ;struct amdgpu_ctx *ctx;struct fence *fence;long r; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ; r =amdgpu_cs_get_ring (adev, wait->in.ip_type, wait->in.ip_instance, wait->in.ring, &ring);if (r)@@ -1344,12 +1350,15 @@ int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;union drm_amdgpu_wait_fences *wait = data;uint32_t fence_count = wait->in.fence_count;struct drm_amdgpu_fence *fences_user;struct drm_amdgpu_fence *fences;int r; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;/* Get the fences from userspace */ fences =kmalloc_array (fence_count,sizeof (struct drm_amdgpu_fence ),GFP_KERNEL );drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-1@@ -2919,8 +2919,10 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)if (r) goto out; vram_lost =amdgpu_check_vram_lost (adev); -if (vram_lost) +if (vram_lost) {DRM_ERROR ("VRAM is lost!\n" ); +atomic_inc (&adev->vram_lost_counter); + } r =amdgpu_ttm_recover_gart (adev);if (r) goto out;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 780
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -776,6 +776,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,if (!adev->vm_manager.enabled)return -ENOTTY ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;
We should only block AMDGPU_VA_OP_MAP and AMDGPU_VA_OP_REPLACE here and still allow AMDGPU_VA_OP_UNMAP and AMDGPU_VA_OP_CLEAR.
BTW: How should the UMD recover from that situation? Completely close the fd and recreate it?
That might be tricky for processes like X or the Compositor. Should we have an IOCTL to reset the vram_lost counter for an fd?
Christian.
Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0if (args->va_address <AMDGPU_VA_RESERVED_SIZE ) { dev_err(&dev->pdev->dev,drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9
-0@@ -235,6 +235,7 @@ static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,static int amdgpu_info_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;struct drm_amdgpu_info *info = data;struct amdgpu_mode_info *minfo = &adev->mode_info;void __user *out = (void __user *)(uintptr_t )info->return_pointer;@@ -247,6 +248,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_fileif (!info->return_size || !info->return_pointer)return -EINVAL ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;switch (info->query) {case AMDGPU_INFO_VIRTUAL_RANGE : {@@ -779,6 +782,12 @@ void amdgpu_driver_lastclose_kms(struct drm_device *dev)vga_switcheroo_process_delayed_switch (); } +bool amdgpu_kms_vram_lost (struct amdgpu_device *adev, +struct amdgpu_fpriv *fpriv) +{ +return fpriv->vram_lost_counter !=atomic_read (&adev->vram_lost_counter); +} +/** * amdgpu_driver_open_kms - drm callback for open *
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) · line 848
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-0@@ -833,6 +842,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)amdgpu_ctx_mgr_init (&fpriv->ctx_mgr); + fpriv->vram_lost_counter =atomic_read (&adev->vram_lost_counter); file_priv->driver_priv = fpriv; out_suspend:
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 0383ac20-28f1-0ec3-97f9-7268328d619b-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 2/3] drm/amdgpu: return -ENODEV to user space when vram is lost
Quoted 131 lines · Christian König
Am 16.05.2017 um 08:44 schrieb Chunming Zhou:
Quoted 122 lines
below ioctl will return
-ENODEV:amdgpu_cs_ioctlamdgpu_cs_wait_ioctlamdgpu_cs_wait_fences_ioctlamdgpu_gem_va_ioctlamdgpu_info_ioctlChange-Id I8970cde3301b7cfeb4263cc0f0e54aece215c98eSigned-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 10 ++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -855,6 +855,7 @@ struct amdgpu_fpriv {struct amdgpu_ctx_mgr ctx_mgr;spinlock_t sem_handles_lock;struct idr sem_handles; +u32 vram_lost_counter; };/* @@ -1607,6 +1608,7 @@ struct amdgpu_device {atomic64_t num_bytes_moved;atomic64_t num_evictions;atomic_t gpu_reset_counter; +atomic_t vram_lost_counter;/* data for buffer migration throttling */ struct {@@ -2005,6 +2007,8 @@ static inline voidamdgpu_unregister_atpx_handler (void) {}extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];extern const int amdgpu_max_kms_ioctl; +bool amdgpu_kms_vram_lost(struct amdgpu_device *adev, + struct amdgpu_fpriv *fpriv);int amdgpu_driver_load_kms (struct drm_device *dev,unsigned long flags);int amdgpu_driver_unload_kms (struct drm_device *dev);void amdgpu_driver_lastclose_kms (struct drm_device *dev);drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-0@@ -1097,6 +1097,7 @@ static int amdgpu_cs_submit(structamdgpu_cs_parser *p, int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;union drm_amdgpu_cs *cs = data;struct amdgpu_cs_parser parser = {}; bool reserved_buffers = false;drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6
-0@@ -1104,6 +1105,8 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)if (!adev->accel_working)return -EBUSY ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ; parser.adev = adev; parser.filp = filp;@@ -1165,12 +1168,15 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, {union drm_amdgpu_wait_cs *wait = data;struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;unsigned long timeout =amdgpu_gem_timeout (wait->in.timeout);struct amdgpu_ring *ring =NULL ;struct amdgpu_ctx *ctx;struct fence *fence;long r; + if (amdgpu_kms_vram_lost(adev, fpriv)) + return -ENODEV; r =amdgpu_cs_get_ring (adev, wait->in.ip_type, wait->in.ip_instance, wait->in.ring, &ring);if (r)@@ -1344,12 +1350,15 @@ int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) {struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;union drm_amdgpu_wait_fences *wait = data;uint32_t fence_count = wait->in.fence_count;struct drm_amdgpu_fence *fences_user;struct drm_amdgpu_fence *fences;int r; + if (amdgpu_kms_vram_lost(adev, fpriv)) + return -ENODEV;/* Get the fences from userspace */ fences = kmalloc_array(fence_count, sizeof(struct
drm_amdgpu_fence),GFP_KERNEL);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-1@@ -2919,8 +2919,10 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)if (r) goto out; vram_lost =amdgpu_check_vram_lost (adev); -if (vram_lost) +if (vram_lost) {DRM_ERROR ("VRAM is lost!\n" ); +atomic_inc (&adev->vram_lost_counter); + } r =amdgpu_ttm_recover_gart (adev);if (r) goto out;drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, · line 780
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -776,6 +776,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, if (!adev->vm_manager.enabled) return -ENOTTY; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;We should only block
AMDGPU_VA_OP_MAPandAMDGPU_VA_OP_REPLACEhere and still allowAMDGPU_VA_OP_UNMAPandAMDGPU_VA_OP_CLEAR.
Quoted 3 lines
BTW: How should the UMD recover from that situation? Completely close the fd and recreate it?
That might be tricky for processes like X or the Compositor. Should we have an IOCTL to reset the
vram_lostcounter for an fd?
if no NAK, I can add it.
Regards,
David Zhou
Quoted 39 lines
Christian.
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0if (args->va_address <AMDGPU_VA_RESERVED_SIZE ) { dev_err(&dev->pdev->dev,drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-0@@ -235,6 +235,7 @@ static int amdgpu_firmware_info(structdrm_amdgpu_info_firmware *fw_info, static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { struct amdgpu_device *adev = dev->dev_private; +struct amdgpu_fpriv *fpriv = filp->driver_priv;struct drm_amdgpu_info *info = data;struct amdgpu_mode_info *minfo = &adev->mode_info; void __user *out = (void __user *)(uintptr_t)info->return_pointer;drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7
-0@@ -247,6 +248,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_fileif (!info->return_size || !info->return_pointer)return -EINVAL ; +if (amdgpu_kms_vram_lost (adev, fpriv)) +return -ENODEV ;switch (info->query) {case AMDGPU_INFO_VIRTUAL_RANGE : {@@ -779,6 +782,12 @@ void amdgpu_driver_lastclose_kms(struct drm_device *dev)vga_switcheroo_process_delayed_switch (); } +bool amdgpu_kms_vram_lost(struct amdgpu_device *adev, + struct amdgpu_fpriv *fpriv) +{ + return fpriv->vram_lost_counter != atomic_read(&adev->vram_lost_counter); +} +/**
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device · line 846
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0
-0* amdgpu_driver_open_kms - drm callback for open * @@ -833,6 +842,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)amdgpu_ctx_mgr_init (&fpriv->ctx_mgr); + fpriv->vram_lost_counter =atomic_read (&adev->vram_lost_counter); file_priv->driver_priv = fpriv; out_suspend:
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: skip all jobs of guilty vm
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +11 -4
@@ -167,6 +167,7 @@ static struct fence *amdgpu_job_run(struct amd_sched_job *sched_job) {struct fence *fence =NULL ;struct amdgpu_job *job; +struct amdgpu_fpriv *fpriv =NULL ;int r;if (!sched_job) {
@@ -178,10 +179,16 @@ static struct fence *amdgpu_job_run(struct amd_sched_job *sched_job)BUG_ON (amdgpu_sync_peek_fence (&job->sync,NULL ));trace_amdgpu_sched_run_job (job); - r =amdgpu_ib_schedule (job->ring, job->num_ibs, job->ibs, job, &fence); -if (r) -DRM_ERROR ("Error scheduling IBs (%d)\n" , r); - +if (job->vm) + fpriv = container_of(job->vm, struct amdgpu_fpriv, vm); +/* skip ib schedule when vram is lost */ +if (fpriv &&amdgpu_kms_vram_lost (job->adev, fpriv)) +DRM_ERROR ("Skip scheduling IBs!\n" ); +else { + r =amdgpu_ib_schedule (job->ring, job->num_ibs, job->ibs, job, &fence); +if (r) +DRM_ERROR ("Error scheduling IBs (%d)\n" , r); + }/* if gpu reset, hw fence will be replaced here */ fence_put (job->fence); job->fence =fence_get (fence);
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 16.05.2017 um 08:44 schrieb Chunming Zhou:
Quoted 41 lines
bakup first 64 byte of gart table as reset magic, check if magic is same after gpu hw reset.
Change-Id I9a73720da4084ea8677c3031dfb62e8157ee5704Signed-off-by Chunming Zhou <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -1502,6 +1502,7 @@ struct amdgpu_ssg {#endif }; +#define AMDGPU_RESET_MAGIC_NUM 64struct amdgpu_device {struct device *dev;struct drm_device *ddev;@@ -1705,6 +1706,7 @@ struct amdgpu_device {/* record hw reset is performed */ bool has_hw_reset; +u8 reset_magic[AMDGPU_RESET_MAGIC_NUM ]; };drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -1685,6 +1685,23 @@ static int amdgpu_init(struct amdgpu_device *adev)return 0 ; } +static void amdgpu_fill_reset_magic (struct amdgpu_device *adev) +{ +memcpy (adev->reset_magic, adev->gart.ptr,AMDGPU_RESET_MAGIC_NUM );
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static int amdgpu_init(struct amdgpu_device *adev) · line 1700
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-0+} + +static bool amdgpu_check_vram_lost (struct amdgpu_device *adev) +{ +int i; + +for (i =0 ; i <AMDGPU_RESET_MAGIC_NUM ; i++) { +if (*((u8 *)(adev->gart.ptr + i)) != adev->reset_magic[i]) +return true; + }
How about using memcmp() here?
Apart from that the patch looks good to me.
Christian.
Quoted 33 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-1+ +return false; +} +static int amdgpu_late_init (struct amdgpu_device *adev) {int i =0 , r;@@ -1715,6 +1732,8 @@ static int amdgpu_late_init(struct amdgpu_device *adev) } } +amdgpu_fill_reset_magic (adev); +return 0 ; }@@ -2830,7 +2849,7 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)struct drm_atomic_state *state =NULL ;int i, r;int resched; -bool need_full_reset; +bool need_full_reset, vram_lost = false;if (amdgpu_sriov_vf (adev))return amdgpu_sriov_gpu_reset (adev, true);@@ -2899,12 +2918,17 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev) r =amdgpu_resume_phase1 (adev);if (r) goto out; + vram_lost =amdgpu_check_vram_lost (adev); +if (vram_lost) +DRM_ERROR ("VRAM is lost!\n" ); r =amdgpu_ttm_recover_gart (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_gpu_reset(struct amdgpu_device *adev) · line 2934
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0if (r) goto out; r =amdgpu_resume_phase2 (adev);if (r) goto out; +if (vram_lost) +amdgpu_fill_reset_magic (adev); } } out:
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx