From: Nirmoy Das <nirmoy.das@linux.intel.com>
To: Matthew Auld <matthew.auld@intel.com>, intel-xe@lists.freedesktop.org
Cc: Matthew Brost <matthew.brost@intel.com>,
Nirmoy Das <nirmoy.das@intel.com>
Subject: Re: [PATCH v2 1/2] drm/xe: fix unbalanced rpm put() with fence_fini()
Date: Wed, 9 Oct 2024 10:50:39 +0200 [thread overview]
Message-ID: <88a39de3-9168-442e-b96d-93fdfa7af0ea@linux.intel.com> (raw)
In-Reply-To: <20241009084808.204432-3-matthew.auld@intel.com>
On 10/9/2024 10:48 AM, Matthew Auld wrote:
> Currently we can call fence_fini() twice if something goes wrong when
> sending the GuC CT for the tlb request, since we signal the fence and
> return an error, leading to the caller also calling fini() on the error
> path in the case of stack version of the flow, which leads to an extra
> rpm put() which might later cause device to enter suspend when it
> shouldn't. It looks like we can just drop the fini() call since the
> fence signaller side will already call this for us.
>
> There are known mysterious splats with device going to sleep even with
> an rpm ref, and this could be one candidate.
>
> v2 (Matt B):
> - Prefer warning if we detect double fini()
>
> Fixes: 0a382f9bc5dc ("drm/xe: Hold a PM ref when GT TLB invalidations are inflight")
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Nirmoy Das <nirmoy.das@intel.com>
> Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Nirmoy Das <nirmoy.das@intel.com>
> ---
> drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 29 +++++++++------------
> drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h | 1 -
> drivers/gpu/drm/xe/xe_vm.c | 8 ++----
> 3 files changed, 15 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c b/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c
> index 98616de0c5bb..a530a933eedc 100644
> --- a/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c
> +++ b/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c
> @@ -37,6 +37,15 @@ static long tlb_timeout_jiffies(struct xe_gt *gt)
> return hw_tlb_timeout + 2 * delay;
> }
>
> +static void xe_gt_tlb_invalidation_fence_fini(struct xe_gt_tlb_invalidation_fence *fence)
> +{
> + if (WARN_ON_ONCE(!fence->gt))
> + return;
> +
> + xe_pm_runtime_put(gt_to_xe(fence->gt));
> + fence->gt = NULL; /* fini() should be called once */
> +}
> +
> static void
> __invalidation_fence_signal(struct xe_device *xe, struct xe_gt_tlb_invalidation_fence *fence)
> {
> @@ -204,7 +213,7 @@ static int send_tlb_invalidation(struct xe_guc *guc,
> tlb_timeout_jiffies(gt));
> }
> spin_unlock_irq(>->tlb_invalidation.pending_lock);
> - } else if (ret < 0) {
> + } else {
> __invalidation_fence_signal(xe, fence);
> }
> if (!ret) {
> @@ -267,10 +276,8 @@ int xe_gt_tlb_invalidation_ggtt(struct xe_gt *gt)
>
> xe_gt_tlb_invalidation_fence_init(gt, &fence, true);
> ret = xe_gt_tlb_invalidation_guc(gt, &fence);
> - if (ret < 0) {
> - xe_gt_tlb_invalidation_fence_fini(&fence);
> + if (ret)
> return ret;
> - }
>
> xe_gt_tlb_invalidation_fence_wait(&fence);
> } else if (xe_device_uc_enabled(xe) && !xe_device_wedged(xe)) {
> @@ -498,7 +505,8 @@ static const struct dma_fence_ops invalidation_fence_ops = {
> * @stack: fence is stack variable
> *
> * Initialize TLB invalidation fence for use. xe_gt_tlb_invalidation_fence_fini
> - * must be called if fence is not signaled.
> + * will be automatically called when fence is signalled (all fences must signal),
> + * even on error.
> */
> void xe_gt_tlb_invalidation_fence_init(struct xe_gt *gt,
> struct xe_gt_tlb_invalidation_fence *fence,
> @@ -518,14 +526,3 @@ void xe_gt_tlb_invalidation_fence_init(struct xe_gt *gt,
> dma_fence_get(&fence->base);
> fence->gt = gt;
> }
> -
> -/**
> - * xe_gt_tlb_invalidation_fence_fini - Finalize TLB invalidation fence
> - * @fence: TLB invalidation fence to finalize
> - *
> - * Drop PM ref which fence took durinig init.
> - */
> -void xe_gt_tlb_invalidation_fence_fini(struct xe_gt_tlb_invalidation_fence *fence)
> -{
> - xe_pm_runtime_put(gt_to_xe(fence->gt));
> -}
> diff --git a/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h b/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h
> index a84065fa324c..f430d5797af7 100644
> --- a/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h
> +++ b/drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h
> @@ -28,7 +28,6 @@ int xe_guc_tlb_invalidation_done_handler(struct xe_guc *guc, u32 *msg, u32 len);
> void xe_gt_tlb_invalidation_fence_init(struct xe_gt *gt,
> struct xe_gt_tlb_invalidation_fence *fence,
> bool stack);
> -void xe_gt_tlb_invalidation_fence_fini(struct xe_gt_tlb_invalidation_fence *fence);
>
> static inline void
> xe_gt_tlb_invalidation_fence_wait(struct xe_gt_tlb_invalidation_fence *fence)
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index ce9dca4d4e87..c99380271de6 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -3199,10 +3199,8 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
>
> ret = xe_gt_tlb_invalidation_vma(tile->primary_gt,
> &fence[fence_id], vma);
> - if (ret < 0) {
> - xe_gt_tlb_invalidation_fence_fini(&fence[fence_id]);
> + if (ret)
> goto wait;
> - }
> ++fence_id;
>
> if (!tile->media_gt)
> @@ -3214,10 +3212,8 @@ int xe_vm_invalidate_vma(struct xe_vma *vma)
>
> ret = xe_gt_tlb_invalidation_vma(tile->media_gt,
> &fence[fence_id], vma);
> - if (ret < 0) {
> - xe_gt_tlb_invalidation_fence_fini(&fence[fence_id]);
> + if (ret)
> goto wait;
> - }
> ++fence_id;
> }
> }
next prev parent reply other threads:[~2024-10-09 8:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 8:48 [PATCH v2 1/2] drm/xe: fix unbalanced rpm put() with fence_fini() Matthew Auld
2024-10-09 8:48 ` [PATCH v2 2/2] drm/xe: fix unbalanced rpm put() with declare_wedged() Matthew Auld
2024-10-09 8:57 ` Nirmoy Das
2024-10-09 8:50 ` Nirmoy Das [this message]
2024-10-09 10:45 ` ✓ CI.Patch_applied: success for series starting with [v2,1/2] drm/xe: fix unbalanced rpm put() with fence_fini() Patchwork
2024-10-09 10:45 ` ✓ CI.checkpatch: " Patchwork
2024-10-09 10:46 ` ✓ CI.KUnit: " Patchwork
2024-10-09 10:58 ` ✓ CI.Build: " Patchwork
2024-10-09 11:00 ` ✓ CI.Hooks: " Patchwork
2024-10-09 11:02 ` ✓ CI.checksparse: " Patchwork
2024-10-09 11:28 ` ✓ CI.BAT: " Patchwork
2024-10-09 17:22 ` ✗ CI.FULL: failure " Patchwork
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=88a39de3-9168-442e-b96d-93fdfa7af0ea@linux.intel.com \
--to=nirmoy.das@linux.intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=matthew.brost@intel.com \
--cc=nirmoy.das@intel.com \
/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