From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Christian_K=c3=b6nig?= Subject: Re: [PATCH] drm/amdgpu: guard ib scheduling while in reset Date: Thu, 24 Oct 2019 18:30:05 +0200 Message-ID: References: <1571914692-9430-1-git-send-email-shirish.s@amd.com> <23ea615d-5ef4-d0b3-a0ec-6fae67b102f2@gmail.com> Reply-To: christian.koenig-5C7GfCeVMHo@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1920156788==" Return-path: In-Reply-To: Content-Language: en-US List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org Sender: "amd-gfx" To: "Grodzovsky, Andrey" , "Koenig, Christian" , "S, Shirish" , "Deucher, Alexander" Cc: "amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org" This is a multi-part message in MIME format. --===============1920156788== Content-Type: multipart/alternative; boundary="------------622BFDAF81EADBEC8F7B1A70" Content-Language: en-US This is a multi-part message in MIME format. --------------622BFDAF81EADBEC8F7B1A70 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Am 24.10.19 um 17:06 schrieb Grodzovsky, Andrey: > > > On 10/24/19 7:01 AM, Christian König wrote: >> Am 24.10.19 um 12:58 schrieb S, Shirish: >>> [Why] >>> Upon GPU reset, kernel cleans up already submitted jobs >>> via drm_sched_cleanup_jobs. >>> This schedules ib's via drm_sched_main()->run_job, leading to >>> race condition of rings being ready or not, since during reset >>> rings may be suspended. >> >> NAK, exactly that's what should not happen. >> >> The scheduler should be suspend while a GPU reset is in progress. >> >> So you are running into a completely different race here. >> >> Please sync up with Andrey how this was able to happen. >> >> Regards, >> Christian. > > > Shirish - Christian makes a good point - note that in > amdgpu_device_gpu_recover drm_sched_stop which stop all the scheduler > threads is called way before we suspend the HW in > amdgpu_device_pre_asic_reset->amdgpu_device_ip_suspend where SDMA > suspension is happening and where the HW ring marked as not ready - > please provide call stack for when you hit [drm:amdgpu_job_run] > *ERROR* Error scheduling IBs (-22) to identify the code path which > tried to submit the SDMA IB > Well the most likely cause of this is that the hardware failed to resume after the reset. Christian. > Andrey > > >> >>> >>> [How] >>> make GPU reset's amdgpu_device_ip_resume_phase2() & >>> amdgpu_ib_schedule() in amdgpu_job_run() mutually exclusive. >>> >>> Signed-off-by: Shirish S >>> --- >>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 1 + >>>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ >>>   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c    | 2 ++ >>>   3 files changed, 6 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> index f4d9041..7b07a47b 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> @@ -973,6 +973,7 @@ struct amdgpu_device { >>>       bool                            in_gpu_reset; >>>       enum pp_mp1_state               mp1_state; >>>       struct mutex  lock_reset; >>> +    struct mutex  lock_ib_sched; >>>       struct amdgpu_doorbell_index doorbell_index; >>>         int asic_reset_res; >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> index 676cad1..63cad74 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> @@ -2759,6 +2759,7 @@ int amdgpu_device_init(struct amdgpu_device >>> *adev, >>>       mutex_init(&adev->virt.vf_errors.lock); >>>       hash_init(adev->mn_hash); >>>       mutex_init(&adev->lock_reset); >>> +    mutex_init(&adev->lock_ib_sched); >>>       mutex_init(&adev->virt.dpm_mutex); >>>       mutex_init(&adev->psp.mutex); >>>   @@ -3795,7 +3796,9 @@ static int amdgpu_do_asic_reset(struct >>> amdgpu_hive_info *hive, >>>                   if (r) >>>                       return r; >>>   + mutex_lock(&tmp_adev->lock_ib_sched); >>>                   r = amdgpu_device_ip_resume_phase2(tmp_adev); >>> + mutex_unlock(&tmp_adev->lock_ib_sched); >>>                   if (r) >>>                       goto out; >>>   diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> index e1bad99..cd6082d 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> @@ -233,8 +233,10 @@ static struct dma_fence *amdgpu_job_run(struct >>> drm_sched_job *sched_job) >>>       if (finished->error < 0) { >>>           DRM_INFO("Skip scheduling IBs!\n"); >>>       } else { >>> +        mutex_lock(&ring->adev->lock_ib_sched); >>>           r = amdgpu_ib_schedule(ring, job->num_ibs, job->ibs, job, >>>                          &fence); >>> +        mutex_unlock(&ring->adev->lock_ib_sched); >>>           if (r) >>>               DRM_ERROR("Error scheduling IBs (%d)\n", r); >>>       } >> > > _______________________________________________ > amd-gfx mailing list > amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx --------------622BFDAF81EADBEC8F7B1A70 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Am 24.10.19 um 17:06 schrieb Grodzovsky, Andrey:


On 10/24/19 7:01 AM, Christian König wrote:
Am 24.10.19 um 12:58 schrieb S, Shirish:
[Why]
Upon GPU reset, kernel cleans up already submitted jobs
via drm_sched_cleanup_jobs.
This schedules ib's via drm_sched_main()->run_job, leading to
race condition of rings being ready or not, since during reset
rings may be suspended.

NAK, exactly that's what should not happen.

The scheduler should be suspend while a GPU reset is in progress.

So you are running into a completely different race here.

Please sync up with Andrey how this was able to happen.

Regards,
Christian.


Shirish - Christian makes a good point - note that in amdgpu_device_gpu_recover drm_sched_stop which stop all the scheduler threads is called way before we suspend the HW in amdgpu_device_pre_asic_reset->amdgpu_device_ip_suspend where SDMA suspension is happening and where the HW ring marked as not ready - please provide call stack for when you hit [drm:amdgpu_job_run] *ERROR* Error scheduling IBs (-22) to identify the code path which tried to submit the SDMA IB


Well the most likely cause of this is that the hardware failed to resume after the reset.

Christian.

Andrey




[How]
make GPU reset's amdgpu_device_ip_resume_phase2() &
amdgpu_ib_schedule() in amdgpu_job_run() mutually exclusive.

Signed-off-by: Shirish S <shirish.s-5C7GfCeVMHo@public.gmane.org>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c    | 2 ++
  3 files changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index f4d9041..7b07a47b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -973,6 +973,7 @@ struct amdgpu_device {
      bool                            in_gpu_reset;
      enum pp_mp1_state               mp1_state;
      struct mutex  lock_reset;
+    struct mutex  lock_ib_sched;
      struct amdgpu_doorbell_index doorbell_index;
        int asic_reset_res;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 676cad1..63cad74 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2759,6 +2759,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
      mutex_init(&adev->virt.vf_errors.lock);
      hash_init(adev->mn_hash);
      mutex_init(&adev->lock_reset);
+    mutex_init(&adev->lock_ib_sched);
      mutex_init(&adev->virt.dpm_mutex);
      mutex_init(&adev->psp.mutex);
  @@ -3795,7 +3796,9 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info *hive,
                  if (r)
                      return r;
  +                mutex_lock(&tmp_adev->lock_ib_sched);
                  r = amdgpu_device_ip_resume_phase2(tmp_adev);
+                mutex_unlock(&tmp_adev->lock_ib_sched);
                  if (r)
                      goto out;
  diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index e1bad99..cd6082d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -233,8 +233,10 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)
      if (finished->error < 0) {
          DRM_INFO("Skip scheduling IBs!\n");
      } else {
+        mutex_lock(&ring->adev->lock_ib_sched);
          r = amdgpu_ib_schedule(ring, job->num_ibs, job->ibs, job,
                         &fence);
+        mutex_unlock(&ring->adev->lock_ib_sched);
          if (r)
              DRM_ERROR("Error scheduling IBs (%d)\n", r);
      }


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

--------------622BFDAF81EADBEC8F7B1A70-- --===============1920156788== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KYW1kLWdmeCBt YWlsaW5nIGxpc3QKYW1kLWdmeEBsaXN0cy5mcmVlZGVza3RvcC5vcmcKaHR0cHM6Ly9saXN0cy5m cmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9hbWQtZ2Z4 --===============1920156788==-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C64CA9EAF for ; Thu, 24 Oct 2019 16:30:12 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80B9D20650 for ; Thu, 24 Oct 2019 16:30:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80B9D20650 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 39DC06E488; Thu, 24 Oct 2019 16:30:12 +0000 (UTC) Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id A28596E488 for ; Thu, 24 Oct 2019 16:30:10 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id n15so16017207wrw.13 for ; Thu, 24 Oct 2019 09:30:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=c7PSbSORHY5ZBBhplN3aw7fhAR9ipfgT874mndiNylE=; b=S8Wy7ANbzJX3mIVFfYHbqL7UklJouMxUhQNmD9AEKyvul8XllEiBoVB39u4yrnhNFO 7uurBDwdYscgJtGgeFtgHLKjyCQNR/i0duDbJ+QUOaTjPgGt4Ku/JZTopXoxxhRhLhr9 74ffC8ussNGEen7UKEK4+rmv8tNDjYYw4zejhUdCuShlzBRqrhFFDj7ENfFjuNoaoA8C Sg9uVEeYC2lEafRmD5G/NxNlVXzJyLdKhN96qQV3wi2p3/Vto4EbCdpyxII2RdE452qC oyyIrVg39zy/xAVwnKpj+eN/DTdJ2jJCx+C9OKUkVDrFFkemAtqBMVftMXMxafE7Uqgk sGUw== X-Gm-Message-State: APjAAAUharCCu2hqOl7tVMgEg57TN3EgMXRN4lYAWiwSExsPk0sRPAiJ jmo96tuqu+ucOVgRyWAzcCa62VXa X-Google-Smtp-Source: APXvYqzAt/VAvh4+AJOzn49bT371TYmNN6uzxetViDUjzeYDeQcCSA7R3FUtx+hOHRKj9L5KJpJf6A== X-Received: by 2002:a5d:6747:: with SMTP id l7mr4486309wrw.328.1571934609017; Thu, 24 Oct 2019 09:30:09 -0700 (PDT) Received: from ?IPv6:2a02:908:1252:fb60:be8a:bd56:1f94:86e7? ([2a02:908:1252:fb60:be8a:bd56:1f94:86e7]) by smtp.gmail.com with ESMTPSA id h3sm11589793wrt.88.2019.10.24.09.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Oct 2019 09:30:07 -0700 (PDT) Subject: Re: [PATCH] drm/amdgpu: guard ib scheduling while in reset To: "Grodzovsky, Andrey" , "Koenig, Christian" , "S, Shirish" , "Deucher, Alexander" References: <1571914692-9430-1-git-send-email-shirish.s@amd.com> <23ea615d-5ef4-d0b3-a0ec-6fae67b102f2@gmail.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Thu, 24 Oct 2019 18:30:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=c7PSbSORHY5ZBBhplN3aw7fhAR9ipfgT874mndiNylE=; b=BhGMHxqkYucR/DoqK8Ii7pPOWo1+hEg8o0zVUuufqe88qb2RhZwnkDIxmfOOUQLIgN iKJJRDAk/MsecDkduDiCAJ6OaX4+qp1X7IQ/pOZWfUJWIXCf+uyLT5oYmFMjDKoHa9E4 BWgTJRKZGtq0n7MJUV3bjcLwveIU5i/lkTp7sB2W/R0YuquAPhPaJxdvGfB5LMx2QYRC ChYLvB5qL5RTku63Rx28E827w9axqmobELxxI3p5fcE1TPkAifdCcT8TN58BYRN4BSgs 1qlht63oTfwLeij9Edjogcjm3nW9unQOdikq+Huyd8oIF7W72SLi6AFQvUhJmPfncyEs +JrA== X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: christian.koenig@amd.com Cc: "amd-gfx@lists.freedesktop.org" Content-Type: multipart/mixed; boundary="===============1920156788==" Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" Message-ID: <20191024163005.L3zTkN0x0I_u9UwEekM5JfQo753lcpAi9_1s6aaOcUk@z> This is a multi-part message in MIME format. --===============1920156788== Content-Type: multipart/alternative; boundary="------------622BFDAF81EADBEC8F7B1A70" Content-Language: en-US This is a multi-part message in MIME format. --------------622BFDAF81EADBEC8F7B1A70 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Am 24.10.19 um 17:06 schrieb Grodzovsky, Andrey: > > > On 10/24/19 7:01 AM, Christian König wrote: >> Am 24.10.19 um 12:58 schrieb S, Shirish: >>> [Why] >>> Upon GPU reset, kernel cleans up already submitted jobs >>> via drm_sched_cleanup_jobs. >>> This schedules ib's via drm_sched_main()->run_job, leading to >>> race condition of rings being ready or not, since during reset >>> rings may be suspended. >> >> NAK, exactly that's what should not happen. >> >> The scheduler should be suspend while a GPU reset is in progress. >> >> So you are running into a completely different race here. >> >> Please sync up with Andrey how this was able to happen. >> >> Regards, >> Christian. > > > Shirish - Christian makes a good point - note that in > amdgpu_device_gpu_recover drm_sched_stop which stop all the scheduler > threads is called way before we suspend the HW in > amdgpu_device_pre_asic_reset->amdgpu_device_ip_suspend where SDMA > suspension is happening and where the HW ring marked as not ready - > please provide call stack for when you hit [drm:amdgpu_job_run] > *ERROR* Error scheduling IBs (-22) to identify the code path which > tried to submit the SDMA IB > Well the most likely cause of this is that the hardware failed to resume after the reset. Christian. > Andrey > > >> >>> >>> [How] >>> make GPU reset's amdgpu_device_ip_resume_phase2() & >>> amdgpu_ib_schedule() in amdgpu_job_run() mutually exclusive. >>> >>> Signed-off-by: Shirish S >>> --- >>>   drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 1 + >>>   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++ >>>   drivers/gpu/drm/amd/amdgpu/amdgpu_job.c    | 2 ++ >>>   3 files changed, 6 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> index f4d9041..7b07a47b 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h >>> @@ -973,6 +973,7 @@ struct amdgpu_device { >>>       bool                            in_gpu_reset; >>>       enum pp_mp1_state               mp1_state; >>>       struct mutex  lock_reset; >>> +    struct mutex  lock_ib_sched; >>>       struct amdgpu_doorbell_index doorbell_index; >>>         int asic_reset_res; >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> index 676cad1..63cad74 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c >>> @@ -2759,6 +2759,7 @@ int amdgpu_device_init(struct amdgpu_device >>> *adev, >>>       mutex_init(&adev->virt.vf_errors.lock); >>>       hash_init(adev->mn_hash); >>>       mutex_init(&adev->lock_reset); >>> +    mutex_init(&adev->lock_ib_sched); >>>       mutex_init(&adev->virt.dpm_mutex); >>>       mutex_init(&adev->psp.mutex); >>>   @@ -3795,7 +3796,9 @@ static int amdgpu_do_asic_reset(struct >>> amdgpu_hive_info *hive, >>>                   if (r) >>>                       return r; >>>   + mutex_lock(&tmp_adev->lock_ib_sched); >>>                   r = amdgpu_device_ip_resume_phase2(tmp_adev); >>> + mutex_unlock(&tmp_adev->lock_ib_sched); >>>                   if (r) >>>                       goto out; >>>   diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> index e1bad99..cd6082d 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c >>> @@ -233,8 +233,10 @@ static struct dma_fence *amdgpu_job_run(struct >>> drm_sched_job *sched_job) >>>       if (finished->error < 0) { >>>           DRM_INFO("Skip scheduling IBs!\n"); >>>       } else { >>> +        mutex_lock(&ring->adev->lock_ib_sched); >>>           r = amdgpu_ib_schedule(ring, job->num_ibs, job->ibs, job, >>>                          &fence); >>> +        mutex_unlock(&ring->adev->lock_ib_sched); >>>           if (r) >>>               DRM_ERROR("Error scheduling IBs (%d)\n", r); >>>       } >> > > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx --------------622BFDAF81EADBEC8F7B1A70 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
Am 24.10.19 um 17:06 schrieb Grodzovsky, Andrey:


On 10/24/19 7:01 AM, Christian König wrote:
Am 24.10.19 um 12:58 schrieb S, Shirish:
[Why]
Upon GPU reset, kernel cleans up already submitted jobs
via drm_sched_cleanup_jobs.
This schedules ib's via drm_sched_main()->run_job, leading to
race condition of rings being ready or not, since during reset
rings may be suspended.

NAK, exactly that's what should not happen.

The scheduler should be suspend while a GPU reset is in progress.

So you are running into a completely different race here.

Please sync up with Andrey how this was able to happen.

Regards,
Christian.


Shirish - Christian makes a good point - note that in amdgpu_device_gpu_recover drm_sched_stop which stop all the scheduler threads is called way before we suspend the HW in amdgpu_device_pre_asic_reset->amdgpu_device_ip_suspend where SDMA suspension is happening and where the HW ring marked as not ready - please provide call stack for when you hit [drm:amdgpu_job_run] *ERROR* Error scheduling IBs (-22) to identify the code path which tried to submit the SDMA IB


Well the most likely cause of this is that the hardware failed to resume after the reset.

Christian.

Andrey




[How]
make GPU reset's amdgpu_device_ip_resume_phase2() &
amdgpu_ib_schedule() in amdgpu_job_run() mutually exclusive.

Signed-off-by: Shirish S <shirish.s@amd.com>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c    | 2 ++
  3 files changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index f4d9041..7b07a47b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -973,6 +973,7 @@ struct amdgpu_device {
      bool                            in_gpu_reset;
      enum pp_mp1_state               mp1_state;
      struct mutex  lock_reset;
+    struct mutex  lock_ib_sched;
      struct amdgpu_doorbell_index doorbell_index;
        int asic_reset_res;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 676cad1..63cad74 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2759,6 +2759,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
      mutex_init(&adev->virt.vf_errors.lock);
      hash_init(adev->mn_hash);
      mutex_init(&adev->lock_reset);
+    mutex_init(&adev->lock_ib_sched);
      mutex_init(&adev->virt.dpm_mutex);
      mutex_init(&adev->psp.mutex);
  @@ -3795,7 +3796,9 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info *hive,
                  if (r)
                      return r;
  +                mutex_lock(&tmp_adev->lock_ib_sched);
                  r = amdgpu_device_ip_resume_phase2(tmp_adev);
+                mutex_unlock(&tmp_adev->lock_ib_sched);
                  if (r)
                      goto out;
  diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index e1bad99..cd6082d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -233,8 +233,10 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)
      if (finished->error < 0) {
          DRM_INFO("Skip scheduling IBs!\n");
      } else {
+        mutex_lock(&ring->adev->lock_ib_sched);
          r = amdgpu_ib_schedule(ring, job->num_ibs, job->ibs, job,
                         &fence);
+        mutex_unlock(&ring->adev->lock_ib_sched);
          if (r)
              DRM_ERROR("Error scheduling IBs (%d)\n", r);
      }


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

--------------622BFDAF81EADBEC8F7B1A70-- --===============1920156788== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KYW1kLWdmeCBt YWlsaW5nIGxpc3QKYW1kLWdmeEBsaXN0cy5mcmVlZGVza3RvcC5vcmcKaHR0cHM6Ly9saXN0cy5m cmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9hbWQtZ2Z4 --===============1920156788==--