AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: zhoucm1 <david1.zhou-5C7GfCeVMHo@public.gmane.org>
To: "Christian König"
	<deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>,
	"Deucher,
	Alexander" <Alexander.Deucher-5C7GfCeVMHo@public.gmane.org>,
	"amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
	<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Subject: Re: [PATCH 2/4] drm/amdgpu: return -ENODEV to user space when vram is lost v2
Date: Wed, 24 May 2017 10:20:46 +0800	[thread overview]
Message-ID: <5924EDFE.4010102@amd.com> (raw)
In-Reply-To: <69717c0b-b2c1-589a-c466-5d6be9518eda-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>



On 2017年05月23日 23:16, Christian König wrote:
> Am 23.05.2017 um 17:08 schrieb Deucher, Alexander:
>>> -----Original Message-----
>>> From: amd-gfx [mailto:amd-gfx-bounces@lists.freedesktop.org] On Behalf
>>> Of Chunming Zhou
>>> Sent: Tuesday, May 16, 2017 5:26 AM
>>> To: amd-gfx@lists.freedesktop.org
>>> Cc: Zhou, David(ChunMing)
>>> Subject: [PATCH 2/4] drm/amdgpu: return -ENODEV to user space when
>>> vram is lost v2
>>>
>>> below ioctl will return -ENODEV:
>>> amdgpu_cs_ioctl
>>> amdgpu_cs_wait_ioctl
>>> amdgpu_cs_wait_fences_ioctl
>>> amdgpu_gem_va_ioctl
>>> amdgpu_info_ioctl
>> Do we want to block the info ioctl?  Isn't that where the lost 
>> context query is?
>
> No, that's amdgpu_ctx_ioctl.
>
> But I think the conclusion is that we want to move the vram_lost 
> counter to be per CTX and not per device.
Yes, Monk is working on it for virt case, after it, I think we can reuse it.

Regards,
David zhou
>
> Christian.
>
>>
>> Alex
>>
>>> v2: only for map and replace cases in amdgpu_gem_va_ioctl
>>>
>>> Change-Id: I8970cde3301b7cfeb4263cc0f0e54aece215c98e
>>> Signed-off-by: Chunming Zhou <David1.Zhou@amd.com>
>>> ---
>>>   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    |  5 +++++
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 10 ++++++++++
>>>   5 files changed, 31 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>> index f9da215..dcd6203 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>>> @@ -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);
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> index b803412..911aa02 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>>> @@ -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);
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> index c56ae4a..2f0fcf8 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>>> @@ -2913,8 +2913,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;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> index d8275ef..83bc94c 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> @@ -802,6 +802,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev,
>>> void *data,
>>>               args->operation);
>>>           return -EINVAL;
>>>       }
>>> +    if ((args->operation == AMDGPU_VA_OP_MAP) ||
>>> +        (args->operation == AMDGPU_VA_OP_REPLACE)) {
>>> +        if (amdgpu_kms_vram_lost(adev, fpriv))
>>> +            return -ENODEV;
>>> +    }
>>>
>>>       INIT_LIST_HEAD(&list);
>>>       if ((args->operation != AMDGPU_VA_OP_CLEAR) &&
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> index 368829a..a231aa1 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
>>> @@ -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_file
>>>
>>>       if (!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:
>>> -- 
>>> 1.9.1
>>>
>>> _______________________________________________
>>> amd-gfx mailing list
>>> amd-gfx@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-05-24  2:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-16  9:25 [PATCH 1/4] drm/amdgpu: check if vram is lost v2 Chunming Zhou
     [not found] ` <1494926750-1081-1-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2017-05-16  9:25   ` [PATCH 2/4] drm/amdgpu: return -ENODEV to user space when " Chunming Zhou
     [not found]     ` <1494926750-1081-2-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2017-05-23 15:08       ` Deucher, Alexander
     [not found]         ` <BN6PR12MB1652E1AFF691F58C92FC2CD7F7F90-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-05-23 15:16           ` Christian König
     [not found]             ` <69717c0b-b2c1-589a-c466-5d6be9518eda-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-05-24  2:20               ` zhoucm1 [this message]
2017-05-16  9:25   ` [PATCH 3/4] drm/amdgpu: skip all jobs of guilty vm Chunming Zhou
2017-05-16  9:25   ` [PATCH 4/4] drm/amdgpu: reset fpriv vram_lost_counter Chunming Zhou
     [not found]     ` <1494926750-1081-4-git-send-email-David1.Zhou-5C7GfCeVMHo@public.gmane.org>
2017-05-17  1:18       ` Michel Dänzer
     [not found]         ` <58988726-543a-535a-3011-860d29b9f2da-otUistvHUpPR7s880joybQ@public.gmane.org>
2017-05-17  3:04           ` zhoucm1
     [not found]             ` <591BBDA2.1070900-5C7GfCeVMHo@public.gmane.org>
2017-05-17  3:15               ` Michel Dänzer
     [not found]                 ` <29fe2142-7fd1-e23a-49d9-c38dc685db92-otUistvHUpPR7s880joybQ@public.gmane.org>
2017-05-17  4:28                   ` zhoucm1
     [not found]                     ` <591BD17C.8050903-5C7GfCeVMHo@public.gmane.org>
2017-05-17  6:57                       ` Michel Dänzer
     [not found]                         ` <7d87bc8e-9c09-ad25-de6e-dfbd8116bf6e-otUistvHUpPR7s880joybQ@public.gmane.org>
2017-05-17  7:13                           ` zhoucm1
     [not found]                             ` <591BF825.6090505-5C7GfCeVMHo@public.gmane.org>
2017-05-17  8:01                               ` Michel Dänzer
     [not found]                                 ` <31db7a30-dd98-5cb2-4125-187d3d0e2a49-otUistvHUpPR7s880joybQ@public.gmane.org>
2017-05-17  8:40                                   ` Christian König
     [not found]                                     ` <7a302ebe-1de1-734f-fb21-aadcc7904d37-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-05-17  8:46                                       ` zhoucm1
     [not found]                                         ` <591C0DFB.8030604-5C7GfCeVMHo@public.gmane.org>
2017-05-17  8:55                                           ` Michel Dänzer
2017-05-17  8:56                                           ` Christian König
     [not found]                                             ` <46582a1e-e019-34ac-1913-ed4a2a992e4c-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-05-17  9:49                                               ` Marek Olšák
     [not found]                                                 ` <CAAxE2A7sRZXx3MnRSO76DW=61X06nfVs2AHe_a-r+K+46tfJPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-05-17 10:15                                                   ` Zhou, David(ChunMing)
2017-05-16 10:49   ` [PATCH 1/4] drm/amdgpu: check if vram is lost v2 Christian König
     [not found]     ` <0c1d89c5-65ea-cdad-100a-80d0377b865c-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-05-17  4:37       ` zhoucm1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5924EDFE.4010102@amd.com \
    --to=david1.zhou-5c7gfcevmho@public.gmane.org \
    --cc=Alexander.Deucher-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox