From: Matthew Auld <matthew.auld@intel.com>
To: Anshuman Gupta <anshuman.gupta@intel.com>,
intel-gfx@lists.freedesktop.org
Cc: chris@chris-wilson.co.uk, rodrigo.vivi@intel.com
Subject: Re: [Intel-gfx] [RFC 2/2] drm/i915/dgfx: Runtime resume the dgpu on user fault
Date: Wed, 17 Aug 2022 19:11:06 +0100 [thread overview]
Message-ID: <8d5d0839-b8cf-6e27-1de0-38ed326149a5@intel.com> (raw)
In-Reply-To: <20220817150941.25447-3-anshuman.gupta@intel.com>
On 17/08/2022 16:09, Anshuman Gupta wrote:
> Runtime resume the dgpu(when gem object lies in lmem).
> This will transition the dgpu graphics function to D0
> state if it was in D3 in order to access the mmap memory
> mappings.
>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: Anshuman Gupta <anshuman.gupta@intel.com>
> ---
> drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 25 +++++++++++++++++++------
> 1 file changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> index b49823d599e7..1e9b07473a8f 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
> @@ -1020,6 +1020,7 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
> struct ttm_buffer_object *bo = area->vm_private_data;
> struct drm_device *dev = bo->base.dev;
> struct drm_i915_gem_object *obj;
> + intel_wakeref_t wakeref = 0;
> vm_fault_t ret;
> int idx;
>
> @@ -1027,18 +1028,24 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
> if (!obj)
> return VM_FAULT_SIGBUS;
>
> + if (i915_gem_object_is_lmem(obj))
We shouldn't call this without first locking the object (see
bo_vm_reserve below), since it could be in the process of being moved to
system memory or vice versa. For example, below we check is_lmem() again
(this time with the lock held), which might return true, even though
here it returned false, which means we can now race against the
i915_gem_runtime_suspend() modifying the list as we add something.
We ofc still need to audit all the kernel internal users that are
touching lmem though a CPU mapping, and making sure we have the right
pm_get/put wrapping those accesses.
> + wakeref = intel_runtime_pm_get(&to_i915(obj->base.dev)->runtime_pm);
> +
> /* Sanity check that we allow writing into this object */
> if (unlikely(i915_gem_object_is_readonly(obj) &&
> - area->vm_flags & VM_WRITE))
> - return VM_FAULT_SIGBUS;
> + area->vm_flags & VM_WRITE)) {
> + ret = VM_FAULT_SIGBUS;
> + goto out_rpm;
> + }
>
> ret = ttm_bo_vm_reserve(bo, vmf);
> if (ret)
> - return ret;
> + goto out_rpm;
>
> if (obj->mm.madv != I915_MADV_WILLNEED) {
> dma_resv_unlock(bo->base.resv);
> - return VM_FAULT_SIGBUS;
> + ret = VM_FAULT_SIGBUS;
> + goto out_rpm;
> }
>
> if (!i915_ttm_resource_mappable(bo->resource)) {
> @@ -1062,7 +1069,8 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
> if (err) {
> drm_dbg(dev, "Unable to make resource CPU accessible\n");
> dma_resv_unlock(bo->base.resv);
> - return VM_FAULT_SIGBUS;
> + ret = VM_FAULT_SIGBUS;
> + goto out_rpm;
> }
> }
>
> @@ -1078,11 +1086,16 @@ static vm_fault_t vm_fault_ttm(struct vm_fault *vmf)
> list_add(&obj->userfault_link, &to_gt(to_i915(obj->base.dev))->lmem_userfault_list);
>
> if (ret == VM_FAULT_RETRY && !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT))
> - return ret;
> + goto out_rpm;
>
> i915_ttm_adjust_lru(obj);
>
> dma_resv_unlock(bo->base.resv);
> +
> +out_rpm:
> + if (wakeref)
> + intel_runtime_pm_put(&to_i915(obj->base.dev)->runtime_pm, wakeref);
Do we need something like DRM_I915_USERFAULT_AUTOSUSPEND here?
> +
> return ret;
> }
>
next prev parent reply other threads:[~2022-08-17 18:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 15:09 [Intel-gfx] [RFC 0/2] DGFX mmap with rpm Anshuman Gupta
2022-08-17 15:09 ` [Intel-gfx] [RFC 1/2] drm/i915/dgfx: Release mmap on rpm suspend Anshuman Gupta
2022-08-17 17:34 ` Matthew Auld
2022-08-17 15:09 ` [Intel-gfx] [RFC 2/2] drm/i915/dgfx: Runtime resume the dgpu on user fault Anshuman Gupta
2022-08-17 18:11 ` Matthew Auld [this message]
2022-08-18 9:46 ` Gupta, Anshuman
2022-08-17 15:32 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for DGFX mmap with rpm Patchwork
2022-08-17 15:42 ` [Intel-gfx] ✗ Fi.CI.BAT: 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=8d5d0839-b8cf-6e27-1de0-38ed326149a5@intel.com \
--to=matthew.auld@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=intel-gfx@lists.freedesktop.org \
--cc=rodrigo.vivi@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