From patchwork Fri Jan 24 08:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69989138C for ; Fri, 24 Jan 2020 09:06:30 +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 51A652075D for ; Fri, 24 Jan 2020 09:06:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51A652075D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B4D246FF9E; Fri, 24 Jan 2020 09:06:29 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id CA3EC6FF9E for ; Fri, 24 Jan 2020 09:06:28 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655135" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:48 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:53:55 -0800 Message-Id: <20200124085402.11644-2-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 1/8] drm/i915/svm: Support partial binding in ppgtt X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add support to partially bind objects in ppgtt. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- drivers/gpu/drm/i915/gt/gen8_ppgtt.c | 37 +++++++++++++++++----------- drivers/gpu/drm/i915/gt/intel_gtt.h | 21 +++++++++++++--- drivers/gpu/drm/i915/i915_vma.c | 1 - drivers/gpu/drm/i915/i915_vma.h | 2 -- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c index 077b8f7cf6cb..d1f18b150600 100644 --- a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c +++ b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c @@ -382,15 +382,20 @@ gen8_ppgtt_insert_pte(struct i915_ppgtt *ppgtt, vaddr[gen8_pd_index(idx, 0)] = pte_encode | iter->dma; iter->dma += I915_GTT_PAGE_SIZE; + iter->rem -= I915_GTT_PAGE_SIZE; + if (!iter->rem) { + idx = 0; + break; + } + if (iter->dma >= iter->max) { iter->sg = __sg_next(iter->sg); - if (!iter->sg) { - idx = 0; - break; - } + GEM_BUG_ON(!iter->sg); iter->dma = sg_dma_address(iter->sg); - iter->max = iter->dma + iter->sg->length; + iter->max = iter->dma + + min_t(u64, (u64)iter->sg->length, + iter->rem); } if (gen8_pd_index(++idx, 0) == 0) { @@ -418,7 +423,7 @@ static void gen8_ppgtt_insert_huge(struct i915_vma *vma, { const gen8_pte_t pte_encode = gen8_pte_encode(0, cache_level, flags); u64 start = vma->node.start; - dma_addr_t rem = iter->sg->length; + dma_addr_t rem = min_t(u64, (u64)iter->sg->length, iter->rem); GEM_BUG_ON(!i915_vm_is_4lvl(vma->vm)); @@ -460,18 +465,22 @@ static void gen8_ppgtt_insert_huge(struct i915_vma *vma, } do { - GEM_BUG_ON(iter->sg->length < page_size); + GEM_BUG_ON(rem < page_size); vaddr[index++] = encode | iter->dma; start += page_size; iter->dma += page_size; + iter->rem -= page_size; + if (!iter->rem) + break; + rem -= page_size; if (iter->dma >= iter->max) { iter->sg = __sg_next(iter->sg); - if (!iter->sg) - break; + GEM_BUG_ON(!iter->sg); - rem = iter->sg->length; + rem = min_t(u64, (u64)iter->sg->length, + iter->rem); iter->dma = sg_dma_address(iter->sg); iter->max = iter->dma + rem; @@ -497,9 +506,9 @@ static void gen8_ppgtt_insert_huge(struct i915_vma *vma, if (maybe_64K != -1 && (index == I915_PDES || (i915_vm_has_scratch_64K(vma->vm) && - !iter->sg && IS_ALIGNED(vma->node.start + - vma->node.size, - I915_GTT_PAGE_SIZE_2M)))) { + !iter->rem && IS_ALIGNED(vma->node.start + + vma->node.size, + I915_GTT_PAGE_SIZE_2M)))) { vaddr = kmap_atomic_px(pd); vaddr[maybe_64K] |= GEN8_PDE_IPS_64K; kunmap_atomic(vaddr); @@ -528,7 +537,7 @@ static void gen8_ppgtt_insert_huge(struct i915_vma *vma, } vma->page_sizes.gtt |= page_size; - } while (iter->sg); + } while (iter->rem); } static void gen8_ppgtt_insert(struct i915_address_space *vm, diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index 7da7681c20b1..bb59f57b88e1 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -27,6 +27,7 @@ #include "gt/intel_reset.h" #include "i915_gem_fence_reg.h" +#include "i915_scatterlist.h" #include "i915_selftest.h" #include "i915_vma_types.h" @@ -577,11 +578,25 @@ void setup_private_pat(struct intel_uncore *uncore); static inline struct sgt_dma { struct scatterlist *sg; dma_addr_t dma, max; + u64 rem; } sgt_dma(struct i915_vma *vma) { struct scatterlist *sg = vma->pages->sgl; - dma_addr_t addr = sg_dma_address(sg); - - return (struct sgt_dma){ sg, addr, addr + sg->length }; + dma_addr_t addr; + u64 offset = 0; + + /* For partial binding, skip until specified offset */ + if (vma->ggtt_view.type == I915_GGTT_VIEW_PARTIAL) { + offset = vma->ggtt_view.partial.offset << PAGE_SHIFT; + while (offset >= sg->length) { + offset -= sg->length; + sg = __sg_next(sg); + } + } + + addr = sg_dma_address(sg); + return (struct sgt_dma) { sg, addr + offset, + addr + min_t(u64, (u64)sg->length, vma->size), + vma->size }; } #endif diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c index 17d7c525ea5c..48af37355371 100644 --- a/drivers/gpu/drm/i915/i915_vma.c +++ b/drivers/gpu/drm/i915/i915_vma.c @@ -275,7 +275,6 @@ i915_vma_instance(struct drm_i915_gem_object *obj, { struct i915_vma *vma; - GEM_BUG_ON(view && !i915_is_ggtt(vm)); GEM_BUG_ON(!atomic_read(&vm->open)); spin_lock(&obj->vma.lock); diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h index 02b31a62951e..044f3400575c 100644 --- a/drivers/gpu/drm/i915/i915_vma.h +++ b/drivers/gpu/drm/i915/i915_vma.h @@ -155,8 +155,6 @@ i915_vma_compare(struct i915_vma *vma, { ptrdiff_t cmp; - GEM_BUG_ON(view && !i915_is_ggtt(vm)); - cmp = ptrdiff(vma->vm, vm); if (cmp) return cmp; From patchwork Fri Jan 24 08:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349897 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B111924 for ; Fri, 24 Jan 2020 09:06:38 +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 538D82071A for ; Fri, 24 Jan 2020 09:06:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 538D82071A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FD7D6FFA8; Fri, 24 Jan 2020 09:06:34 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9A9E86FF9F for ; Fri, 24 Jan 2020 09:06:28 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655138" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:48 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:53:56 -0800 Message-Id: <20200124085402.11644-3-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 2/8] drm/i915/svm: Add support to mark VMs as active X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add support to determine if an address space (VM) is active. ie., are there any active requests using the address space. This allows us to wait for VM to be idle before carrying out some operations. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 5 +++ drivers/gpu/drm/i915/gt/intel_gtt.c | 32 +++++++++++++++++++ drivers/gpu/drm/i915/gt/intel_gtt.h | 13 ++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 14 ++++++++ 4 files changed, 64 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 60c984e10c4a..b3d9a4a02568 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -1880,6 +1880,11 @@ static int eb_move_to_gpu(struct i915_execbuffer *eb) if (unlikely(err)) goto err_skip; + /* XXX: Should probably be done first */ + err = i915_vm_move_to_active(eb->context->vm, eb->request); + if (err) + goto err_skip; + eb->exec = NULL; /* Unconditionally flush any chipset caches (for streaming writes). */ diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c index 16acdc5d6734..ad5bf7fc851a 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.c +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c @@ -191,6 +191,7 @@ void __i915_vm_close(struct i915_address_space *vm) void i915_address_space_fini(struct i915_address_space *vm) { + i915_active_fini(&vm->active); spin_lock(&vm->free_pages.lock); if (pagevec_count(&vm->free_pages.pvec)) vm_free_pages_release(vm, true); @@ -200,6 +201,7 @@ void i915_address_space_fini(struct i915_address_space *vm) drm_mm_takedown(&vm->mm); mutex_destroy(&vm->mutex); + mutex_destroy(&vm->svm_mutex); } static void __i915_vm_release(struct work_struct *work) @@ -224,6 +226,33 @@ void i915_vm_release(struct kref *kref) queue_rcu_work(vm->i915->wq, &vm->rcu); } +static inline struct i915_address_space *active_to_vm(struct i915_active *ref) +{ + return container_of(ref, typeof(struct i915_address_space), active); +} + +int i915_vm_move_to_active(struct i915_address_space *vm, + struct i915_request *rq) +{ + int ret = 0; + + mutex_lock(&vm->svm_mutex); + ret = i915_active_add_request(&vm->active, rq); + mutex_unlock(&vm->svm_mutex); + return ret; +} + +static int __i915_vm_active(struct i915_active *ref) +{ + return i915_vm_tryget(active_to_vm(ref)) ? 0 : -ENOENT; +} + +__i915_active_call +static void __i915_vm_retire(struct i915_active *ref) +{ + i915_vm_put(active_to_vm(ref)); +} + void i915_address_space_init(struct i915_address_space *vm, int subclass) { kref_init(&vm->ref); @@ -246,6 +275,9 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass) stash_init(&vm->free_pages); INIT_LIST_HEAD(&vm->bound_list); + + mutex_init(&vm->svm_mutex); + i915_active_init(&vm->active, __i915_vm_active, __i915_vm_retire); } void clear_pages(struct i915_vma *vma) diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index bb59f57b88e1..f3e5469c4dc6 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -263,6 +263,8 @@ struct i915_address_space { */ struct list_head bound_list; + struct mutex svm_mutex; /* protects svm operations */ + struct pagestash free_pages; /* Global GTT */ @@ -298,6 +300,8 @@ struct i915_address_space { I915_SELFTEST_DECLARE(struct fault_attr fault_attr); I915_SELFTEST_DECLARE(bool scrub_64K); + + struct i915_active active; }; /* @@ -400,6 +404,15 @@ i915_vm_get(struct i915_address_space *vm) return vm; } +static inline struct i915_address_space * +i915_vm_tryget(struct i915_address_space *vm) +{ + if (likely(kref_get_unless_zero(&vm->ref))) + return vm; + + return NULL; +} + void i915_vm_release(struct kref *kref); static inline void i915_vm_put(struct i915_address_space *vm) diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index f6226df9f972..3e46fd119a42 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -48,4 +48,18 @@ int i915_gem_gtt_insert(struct i915_address_space *vm, #define PIN_OFFSET_MASK I915_GTT_PAGE_MASK +int i915_vm_move_to_active(struct i915_address_space *vm, + struct i915_request *rq); + +static inline int i915_vm_sync(struct i915_address_space *vm) +{ + /* Wait for all requests under this vm to finish */ + return i915_active_wait(&vm->active); +} + +static inline bool i915_vm_is_active(const struct i915_address_space *vm) +{ + return !i915_active_is_idle(&vm->active); +} + #endif From patchwork Fri Jan 24 08:53:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E421D138C for ; Fri, 24 Jan 2020 09:06:31 +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 CC65920709 for ; Fri, 24 Jan 2020 09:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC65920709 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4FC056FFA1; Fri, 24 Jan 2020 09:06:30 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id EE5546FF9F for ; Fri, 24 Jan 2020 09:06:28 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655142" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:48 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:53:57 -0800 Message-Id: <20200124085402.11644-4-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 3/8] drm/i915/svm: Introduce VM_BIND ioctl X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add VM_BIND ioctl to bind/unbind an array of gem buffer objects at specified virtual addresses. Support partial binding with offset and length fields. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- drivers/gpu/drm/i915/i915_drv.c | 40 +++++++++++++++++++++++++ drivers/gpu/drm/i915/i915_drv.h | 22 ++++++++++++++ include/uapi/drm/i915_drm.h | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index f7385abdd74b..64ba02c55282 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -2688,6 +2688,45 @@ i915_gem_reject_pin_ioctl(struct drm_device *dev, void *data, return -ENODEV; } +static int i915_gem_vm_bind_ioctl(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct drm_i915_gem_vm_bind_va __user *vas; + struct drm_i915_gem_vm_bind *args = data; + struct i915_address_space *vm; + int i, ret = 0; + + vm = i915_gem_address_space_lookup(file->driver_priv, args->vm_id); + if (unlikely(!vm)) + return -ENOENT; + + if (!args->num_vas) + goto bind_done; + + vas = u64_to_user_ptr(args->vas_ptr); + if (!access_ok(vas, args->num_vas * sizeof(*vas))) { + ret = -EFAULT; + goto bind_done; + } + + for (i = 0; !ret && i < args->num_vas; i++) { + struct drm_i915_gem_vm_bind_va va; + + if (__copy_from_user(&va, vas++, sizeof(va))) { + ret = -EFAULT; + goto bind_done; + } + + switch (va.type) { + default: + ret = -EINVAL; + } + } +bind_done: + i915_vm_put(vm); + return ret; +} + static const struct drm_ioctl_desc i915_ioctls[] = { DRM_IOCTL_DEF_DRV(I915_INIT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), DRM_IOCTL_DEF_DRV(I915_FLUSH, drm_noop, DRM_AUTH), @@ -2747,6 +2786,7 @@ static const struct drm_ioctl_desc i915_ioctls[] = { DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(I915_GEM_VM_BIND, i915_gem_vm_bind_ioctl, DRM_RENDER_ALLOW), }; static struct drm_driver driver = { diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 077af22b8340..7be87bc37cc0 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -1919,6 +1919,28 @@ i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id) return ctx; } +static inline struct i915_address_space * +__i915_gem_address_space_lookup_rcu(struct drm_i915_file_private *file_priv, + u32 id) +{ + return idr_find(&file_priv->vm_idr, id); +} + +static inline struct i915_address_space * +i915_gem_address_space_lookup(struct drm_i915_file_private *file_priv, + u32 id) +{ + struct i915_address_space *vm; + + rcu_read_lock(); + vm = __i915_gem_address_space_lookup_rcu(file_priv, id); + if (vm) + vm = i915_vm_get(vm); + rcu_read_unlock(); + + return vm; +} + /* i915_gem_evict.c */ int __must_check i915_gem_evict_something(struct i915_address_space *vm, u64 min_size, u64 alignment, diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 829c0a48577f..e696854829ab 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -359,6 +359,7 @@ typedef struct _drm_i915_sarea { #define DRM_I915_QUERY 0x39 #define DRM_I915_GEM_VM_CREATE 0x3a #define DRM_I915_GEM_VM_DESTROY 0x3b +#define DRM_I915_GEM_VM_BIND 0x3c /* Must be kept compact -- no holes */ #define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) @@ -422,6 +423,7 @@ typedef struct _drm_i915_sarea { #define DRM_IOCTL_I915_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_QUERY, struct drm_i915_query) #define DRM_IOCTL_I915_GEM_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_CREATE, struct drm_i915_gem_vm_control) #define DRM_IOCTL_I915_GEM_VM_DESTROY DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_VM_DESTROY, struct drm_i915_gem_vm_control) +#define DRM_IOCTL_I915_GEM_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_BIND, struct drm_i915_gem_vm_bind) /* Allow drivers to submit batchbuffers directly to hardware, relying * on the security mechanisms provided by hardware. @@ -2277,6 +2279,57 @@ struct drm_i915_query_perf_config { __u8 data[]; }; +/** + * struct drm_i915_gem_vm_bind_va + * + * VA to object mapping to [un]bind. + */ +struct drm_i915_gem_vm_bind_va { + /** VA start to [un]bind **/ + __u64 start; + + /** Offset in Object to [un]bind for I915_GEM_VM_BIND_SVM_OBJ type **/ + __u64 offset; + + /** VA length to [un]bind **/ + __u64 length; + + /** Type of memory to [un]bind **/ + __u32 type; +#define I915_GEM_VM_BIND_SVM_OBJ 0 + + /** Object handle to [un]bind for I915_GEM_VM_BIND_SVM_OBJ type **/ + __u32 handle; + + /** Flags **/ + __u32 flags; +#define I915_GEM_VM_BIND_UNBIND (1 << 0) +#define I915_GEM_VM_BIND_READONLY (1 << 1) +}; + +/** + * struct drm_i915_gem_vm_bind + * + * [Un]Bind an array of objects in a vm's page table. + */ +struct drm_i915_gem_vm_bind { + /** vm to [un]bind **/ + __u32 vm_id; + + /** number of VAs to [un]bind **/ + __u32 num_vas; + + /** Array of VAs to [un]bind **/ + __u64 vas_ptr; + + /** + * Zero-terminated chain of extensions. + * + * No current extensions defined; mbz. + */ + __u64 extensions; +}; + #if defined(__cplusplus) } #endif From patchwork Fri Jan 24 08:53:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349891 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AAE2924 for ; Fri, 24 Jan 2020 09:06:34 +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 6360A2075D for ; Fri, 24 Jan 2020 09:06:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6360A2075D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B5A5B6FF9F; Fri, 24 Jan 2020 09:06:33 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 092F66FFA1 for ; Fri, 24 Jan 2020 09:06:28 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655145" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:49 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:53:58 -0800 Message-Id: <20200124085402.11644-5-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 4/8] drm/i915/svm: Manage SVM bindings added using VM_BIND X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Maintain all VM_BIND bindings in an list. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- drivers/gpu/drm/i915/Kconfig | 11 ++++ drivers/gpu/drm/i915/Makefile | 3 + drivers/gpu/drm/i915/gem/i915_gem_svm.c | 82 +++++++++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_svm.h | 22 +++++++ drivers/gpu/drm/i915/gt/intel_gtt.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.h | 4 ++ drivers/gpu/drm/i915/i915_drv.c | 4 ++ drivers/gpu/drm/i915/i915_vma.c | 5 ++ drivers/gpu/drm/i915/i915_vma_types.h | 3 + 9 files changed, 135 insertions(+) create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_svm.c create mode 100644 drivers/gpu/drm/i915/gem/i915_gem_svm.h diff --git a/drivers/gpu/drm/i915/Kconfig b/drivers/gpu/drm/i915/Kconfig index ba9595960bbe..c2e48710eec8 100644 --- a/drivers/gpu/drm/i915/Kconfig +++ b/drivers/gpu/drm/i915/Kconfig @@ -137,6 +137,17 @@ config DRM_I915_GVT_KVMGT Choose this option if you want to enable KVMGT support for Intel GVT-g. +config DRM_I915_SVM + bool "Enable Shared Virtual Memory support in i915" + depends on STAGING + depends on DRM_I915 + default n + help + Choose this option if you want Shared Virtual Memory (SVM) + support in i915. With SVM support, one can share the virtual + address space between a process and the GPU. SVM is supported + on both integrated and discrete Intel GPUs. + menu "drm/i915 Debugging" depends on DRM_I915 depends on EXPERT diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index b8c5f8934dbd..dbdbe85790f6 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -156,6 +156,9 @@ i915-y += \ intel_region_lmem.o \ intel_wopcm.o +# SVM code +i915-$(CONFIG_DRM_I915_SVM) += gem/i915_gem_svm.o + # general-purpose microcontroller (GuC) support i915-y += gt/uc/intel_uc.o \ gt/uc/intel_uc_fw.o \ diff --git a/drivers/gpu/drm/i915/gem/i915_gem_svm.c b/drivers/gpu/drm/i915/gem/i915_gem_svm.c new file mode 100644 index 000000000000..f26567ea0e3a --- /dev/null +++ b/drivers/gpu/drm/i915/gem/i915_gem_svm.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2019 Intel Corporation + */ + +#include "i915_drv.h" +#include "i915_gem_gtt.h" +#include "i915_gem_lmem.h" + +static struct i915_vma * +i915_gem_vm_lookup_svm_vma(struct i915_address_space *vm, + struct drm_i915_gem_object *obj, + struct drm_i915_gem_vm_bind_va *va) +{ + struct i915_vma *vma, *tmp; + + /* FIXME: Optimize lookup (use hashtable or tree) */ + mutex_lock(&vm->svm_mutex); + list_for_each_entry_safe(vma, tmp, &vm->svm_list, svm_link) { + if (vma->obj != obj || + vma->node.start != va->start || + vma->node.size != va->length) + continue; + + list_del_init(&vma->svm_link); + mutex_unlock(&vm->svm_mutex); + return vma; + } + mutex_unlock(&vm->svm_mutex); + return NULL; +} + +int i915_gem_vm_bind_svm_obj(struct i915_address_space *vm, + struct drm_i915_gem_vm_bind_va *va, + struct drm_file *file) +{ + struct drm_i915_gem_object *obj; + struct i915_vma *vma; + int ret = 0; + + obj = i915_gem_object_lookup(file, va->handle); + if (!obj) + return -ENOENT; + + /* For dgfx, ensure the obj is in device local memory only */ + if (IS_DGFX(vm->i915) && !i915_gem_object_is_lmem(obj)) + return -EINVAL; + + if (!(va->flags & I915_GEM_VM_BIND_UNBIND)) { + struct i915_ggtt_view view; + + view.type = I915_GGTT_VIEW_PARTIAL; + view.partial.offset = va->offset >> PAGE_SHIFT; + view.partial.size = va->length >> PAGE_SHIFT; + vma = i915_vma_instance(obj, vm, &view); + if (IS_ERR(vma)) { + ret = PTR_ERR(vma); + goto put_obj; + } + vma->va_start = va->start; + /* Disable eviction for now */ + __i915_vma_pin(vma); + + /* + * FIXME: Reserve VA here and bind only if the vm is active. + * This ensures any overlapping binding is rejected here itself. + * and we don't need to store va_start. + */ + mutex_lock(&vm->svm_mutex); + list_add(&vma->svm_link, &vm->svm_list); + mutex_unlock(&vm->svm_mutex); + } else { + vma = i915_gem_vm_lookup_svm_vma(vm, obj, va); + if (vma) { + __i915_vma_unpin(vma); + __i915_vma_put(vma); + } + } +put_obj: + i915_gem_object_put(obj); + return ret; +} diff --git a/drivers/gpu/drm/i915/gem/i915_gem_svm.h b/drivers/gpu/drm/i915/gem/i915_gem_svm.h new file mode 100644 index 000000000000..e1ad125e86cc --- /dev/null +++ b/drivers/gpu/drm/i915/gem/i915_gem_svm.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2019 Intel Corporation + */ + +#ifndef __I915_GEM_SVM_H +#define __I915_GEM_SVM_H + +#include "i915_drv.h" + +#if defined(CONFIG_DRM_I915_SVM) +int i915_gem_vm_bind_svm_obj(struct i915_address_space *vm, + struct drm_i915_gem_vm_bind_va *va, + struct drm_file *file); +#else +static inline int i915_gem_vm_bind_svm_obj(struct i915_address_space *vm, + struct drm_i915_gem_vm_bind_va *va, + struct drm_file *file) +{ return -ENOTSUPP; } +#endif + +#endif /* __I915_GEM_SVM_H */ diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c index ad5bf7fc851a..897aad1f7c08 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.c +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c @@ -276,6 +276,7 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass) INIT_LIST_HEAD(&vm->bound_list); + INIT_LIST_HEAD(&vm->svm_list); mutex_init(&vm->svm_mutex); i915_active_init(&vm->active, __i915_vm_active, __i915_vm_retire); } diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index f3e5469c4dc6..800c062a4b0e 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -263,6 +263,10 @@ struct i915_address_space { */ struct list_head bound_list; + /** + * List of SVM bind objects. + */ + struct list_head svm_list; struct mutex svm_mutex; /* protects svm operations */ struct pagestash free_pages; diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 64ba02c55282..5631fa82bfed 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -62,6 +62,7 @@ #include "gem/i915_gem_context.h" #include "gem/i915_gem_ioctls.h" #include "gem/i915_gem_mman.h" +#include "gem/i915_gem_svm.h" #include "gt/intel_gt.h" #include "gt/intel_gt_pm.h" #include "gt/intel_rc6.h" @@ -2718,6 +2719,9 @@ static int i915_gem_vm_bind_ioctl(struct drm_device *dev, void *data, } switch (va.type) { + case I915_GEM_VM_BIND_SVM_OBJ: + ret = i915_gem_vm_bind_svm_obj(vm, &va, file); + break; default: ret = -EINVAL; } diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c index 48af37355371..3e16b291f806 100644 --- a/drivers/gpu/drm/i915/i915_vma.c +++ b/drivers/gpu/drm/i915/i915_vma.c @@ -223,6 +223,7 @@ vma_create(struct drm_i915_gem_object *obj, spin_unlock(&obj->vma.lock); + INIT_LIST_HEAD(&vma->svm_link); return vma; err_vma: @@ -1047,6 +1048,10 @@ void i915_vma_release(struct kref *ref) list_del(&vma->obj_link); rb_erase(&vma->obj_node, &obj->vma.tree); spin_unlock(&obj->vma.lock); + + mutex_lock(&vma->vm->svm_mutex); + list_del_init(&vma->svm_link); + mutex_unlock(&vma->vm->svm_mutex); } __i915_vma_remove_closed(vma); diff --git a/drivers/gpu/drm/i915/i915_vma_types.h b/drivers/gpu/drm/i915/i915_vma_types.h index e0942efd5236..d5a4fb4e43a4 100644 --- a/drivers/gpu/drm/i915/i915_vma_types.h +++ b/drivers/gpu/drm/i915/i915_vma_types.h @@ -269,6 +269,9 @@ struct i915_vma { /** This object's place on the active/inactive lists */ struct list_head vm_link; + u64 va_start; + struct list_head svm_link; /* Link in persistent VMA list */ + struct list_head obj_link; /* Link in the object's VMA list */ struct rb_node obj_node; struct hlist_node obj_hash; From patchwork Fri Jan 24 08:53:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70E25138C for ; Fri, 24 Jan 2020 09:06:36 +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 586C22071A for ; Fri, 24 Jan 2020 09:06:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 586C22071A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1B49F6FFA5; Fri, 24 Jan 2020 09:06:34 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 40C506FF9F for ; Fri, 24 Jan 2020 09:06:29 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655148" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:49 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:53:59 -0800 Message-Id: <20200124085402.11644-6-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 5/8] drm/i915/svm: Handle persistent vmas X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Treat VM_BIND vmas as persistent and handle them during the request submission in the execbuff path. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 26 +++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_svm.c | 1 + drivers/gpu/drm/i915/gt/intel_gtt.c | 10 +++++++ drivers/gpu/drm/i915/i915_vma.h | 15 ++++++++++- drivers/gpu/drm/i915/i915_vma_types.h | 4 +++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index b3d9a4a02568..6aaffb9a817f 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -723,6 +723,26 @@ static int eb_select_context(struct i915_execbuffer *eb) return 0; } +static int eb_lookup_persistent_vmas(struct i915_address_space *vm) +{ + struct i915_vma *vma; + int ret = 0; + + mutex_lock(&vm->svm_mutex); + list_for_each_entry(vma, &vm->svm_list, svm_link) { + u64 pin_flags = vma->va_start | PIN_OFFSET_FIXED | PIN_USER; + + if (drm_mm_node_allocated(&vma->node)) + continue; + + ret = i915_vma_pin(vma, 0, 0, pin_flags); + if (ret) + break; + } + mutex_unlock(&vm->svm_mutex); + return ret; +} + static int eb_lookup_vmas(struct i915_execbuffer *eb) { struct radix_tree_root *handles_vma = &eb->gem_context->handles_vma; @@ -1765,6 +1785,12 @@ static noinline int eb_relocate_slow(struct i915_execbuffer *eb) static int eb_relocate(struct i915_execbuffer *eb) { + int ret; + + ret = eb_lookup_persistent_vmas(eb->context->vm); + if (ret) + return ret; + if (eb_lookup_vmas(eb)) goto slow; diff --git a/drivers/gpu/drm/i915/gem/i915_gem_svm.c b/drivers/gpu/drm/i915/gem/i915_gem_svm.c index f26567ea0e3a..e5e45ccc4262 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_svm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_svm.c @@ -58,6 +58,7 @@ int i915_gem_vm_bind_svm_obj(struct i915_address_space *vm, goto put_obj; } vma->va_start = va->start; + i915_vma_set_persistent(vma); /* Disable eviction for now */ __i915_vma_pin(vma); diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c index 897aad1f7c08..e0195906de20 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.c +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c @@ -234,9 +234,19 @@ static inline struct i915_address_space *active_to_vm(struct i915_active *ref) int i915_vm_move_to_active(struct i915_address_space *vm, struct i915_request *rq) { + struct i915_vma *vma; int ret = 0; mutex_lock(&vm->svm_mutex); + list_for_each_entry(vma, &vm->svm_list, svm_link) { + /* Wait for the vma to be bound before we start! */ + ret = i915_request_await_active(rq, &vma->active); + if (ret) + break; + + if (!ret) + ret = i915_active_add_request(&vm->active, rq); + } ret = i915_active_add_request(&vm->active, rq); mutex_unlock(&vm->svm_mutex); return ret; diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h index 044f3400575c..56cff222e7ca 100644 --- a/drivers/gpu/drm/i915/i915_vma.h +++ b/drivers/gpu/drm/i915/i915_vma.h @@ -124,6 +124,16 @@ static inline u32 i915_ggtt_pin_bias(struct i915_vma *vma) return i915_vm_to_ggtt(vma->vm)->pin_bias; } +static inline bool i915_vma_is_persistent(const struct i915_vma *vma) +{ + return test_bit(I915_VMA_PERSISTENT_BIT, __i915_vma_flags(vma)); +} + +static inline void i915_vma_set_persistent(struct i915_vma *vma) +{ + set_bit(I915_VMA_PERSISTENT_BIT, __i915_vma_flags(vma)); +} + static inline struct i915_vma *i915_vma_get(struct i915_vma *vma) { i915_gem_object_get(vma->obj); @@ -376,7 +386,10 @@ void i915_vma_make_purgeable(struct i915_vma *vma); static inline int i915_vma_sync(struct i915_vma *vma) { /* Wait for the asynchronous bindings and pending GPU reads */ - return i915_active_wait(&vma->active); + if (i915_vma_is_persistent(vma)) + return i915_vm_sync(vma->vm); + else + return i915_active_wait(&vma->active); } #endif diff --git a/drivers/gpu/drm/i915/i915_vma_types.h b/drivers/gpu/drm/i915/i915_vma_types.h index d5a4fb4e43a4..8a270280a5ca 100644 --- a/drivers/gpu/drm/i915/i915_vma_types.h +++ b/drivers/gpu/drm/i915/i915_vma_types.h @@ -250,6 +250,10 @@ struct i915_vma { #define I915_VMA_USERFAULT ((int)BIT(I915_VMA_USERFAULT_BIT)) #define I915_VMA_GGTT_WRITE ((int)BIT(I915_VMA_GGTT_WRITE_BIT)) +#define I915_VMA_PERSISTENT_BIT 18 + +#define I915_VMA_PERSISTENT ((int)BIT(I915_VMA_PERSISTENT_BIT)) + struct i915_active active; #define I915_VMA_PAGES_BIAS 24 From patchwork Fri Jan 24 08:54:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349903 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1612D924 for ; Fri, 24 Jan 2020 09:06:48 +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 F2BD72075D for ; Fri, 24 Jan 2020 09:06:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2BD72075D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 645E16FFA6; Fri, 24 Jan 2020 09:06:47 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2E2A06FF9E for ; Fri, 24 Jan 2020 09:06:29 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655154" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:50 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:54:00 -0800 Message-Id: <20200124085402.11644-7-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 6/8] drm/i915/svm: Skip vma_lookup for persistent vmas X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" vma_lookup is tied to segment of the object instead of section of VA space. Hence, it do not support aliasing (ie., multiple bindings to the same section of the object). Hence skip vma_lookup for persistent vmas which should support aliasing. This needs proper solution. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- drivers/gpu/drm/i915/i915_vma.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c index 3e16b291f806..9e2d0dbd308c 100644 --- a/drivers/gpu/drm/i915/i915_vma.c +++ b/drivers/gpu/drm/i915/i915_vma.c @@ -181,6 +181,10 @@ vma_create(struct drm_i915_gem_object *obj, spin_lock(&obj->vma.lock); + if (!i915_vma_is_ggtt(vma) && + (view && view->type == I915_GGTT_VIEW_PARTIAL)) + goto skip_rb_insert; + rb = NULL; p = &obj->vma.tree.rb_node; while (*p) { @@ -210,6 +214,7 @@ vma_create(struct drm_i915_gem_object *obj, rb_link_node(&vma->obj_node, rb, p); rb_insert_color(&vma->obj_node, &obj->vma.tree); +skip_rb_insert: if (i915_vma_is_ggtt(vma)) /* * We put the GGTT vma at the start of the vma-list, followed @@ -274,13 +279,16 @@ i915_vma_instance(struct drm_i915_gem_object *obj, struct i915_address_space *vm, const struct i915_ggtt_view *view) { - struct i915_vma *vma; + struct i915_vma *vma = NULL; GEM_BUG_ON(!atomic_read(&vm->open)); - spin_lock(&obj->vma.lock); - vma = vma_lookup(obj, vm, view); - spin_unlock(&obj->vma.lock); + if (i915_is_ggtt(vm) || !view || + view->type != I915_GGTT_VIEW_PARTIAL) { + spin_lock(&obj->vma.lock); + vma = vma_lookup(obj, vm, view); + spin_unlock(&obj->vma.lock); + } /* vma_create() will resolve the race if another creates the vma */ if (unlikely(!vma)) @@ -1046,7 +1054,10 @@ void i915_vma_release(struct kref *ref) spin_lock(&obj->vma.lock); list_del(&vma->obj_link); - rb_erase(&vma->obj_node, &obj->vma.tree); + + if (!i915_vma_is_persistent(vma)) + rb_erase(&vma->obj_node, &obj->vma.tree); + spin_unlock(&obj->vma.lock); mutex_lock(&vma->vm->svm_mutex); From patchwork Fri Jan 24 08:54:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349901 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BED8138C for ; Fri, 24 Jan 2020 09:06:40 +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 511382071A for ; Fri, 24 Jan 2020 09:06:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 511382071A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C6396FFAB; Fri, 24 Jan 2020 09:06:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D1DA6FFA1 for ; Fri, 24 Jan 2020 09:06:29 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655157" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:50 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:54:01 -0800 Message-Id: <20200124085402.11644-8-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 7/8] drm/i915/svm: Add support to en/disable SVM X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add SVM as a capability and allow user to enable/disable SVM functionality on a per context basis. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura Signed-off-by: Venkata Sandeep Dhanalakota --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 100 ++++++++++++++++++ drivers/gpu/drm/i915/gem/i915_gem_context.h | 4 + .../gpu/drm/i915/gem/i915_gem_execbuffer.c | 5 + drivers/gpu/drm/i915/gt/intel_gtt.h | 3 + drivers/gpu/drm/i915/i915_drv.c | 6 +- drivers/gpu/drm/i915/i915_drv.h | 10 ++ drivers/gpu/drm/i915/i915_getparam.c | 3 + include/uapi/drm/i915_drm.h | 17 +++ 8 files changed, 146 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index a2e57e62af30..fcbe5ff5c762 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -931,6 +931,76 @@ int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data, return 0; } +static int i915_gem_vm_setparam_ioctl(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct drm_i915_file_private *file_priv = file->driver_priv; + struct drm_i915_gem_vm_param *args = data; + struct i915_address_space *vm; + int err = 0; + u32 id; + + id = args->vm_id; + if (!id) + return -ENOENT; + + err = mutex_lock_interruptible(&file_priv->vm_idr_lock); + if (err) + return err; + + vm = idr_find(&file_priv->vm_idr, id); + + mutex_unlock(&file_priv->vm_idr_lock); + if (!vm) + return -ENOENT; + + switch (lower_32_bits(args->param)) { + case I915_GEM_VM_PARAM_SVM: + /* FIXME: Ensure ppgtt is empty and VM idle before switching */ + if (!i915_has_svm(file_priv->dev_priv)) + err = -ENOTSUPP; + else + vm->svm_enabled = !!args->value; + break; + default: + err = -EINVAL; + } + return err; +} + +static int i915_gem_vm_getparam_ioctl(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct drm_i915_file_private *file_priv = file->driver_priv; + struct drm_i915_gem_vm_param *args = data; + struct i915_address_space *vm; + int err = 0; + u32 id; + + id = args->vm_id; + if (!id) + return -ENOENT; + + err = mutex_lock_interruptible(&file_priv->vm_idr_lock); + if (err) + return err; + + vm = idr_find(&file_priv->vm_idr, id); + + mutex_unlock(&file_priv->vm_idr_lock); + if (!vm) + return -ENOENT; + + switch (lower_32_bits(args->param)) { + case I915_GEM_VM_PARAM_SVM: + args->value = i915_vm_is_svm_enabled(vm); + break; + default: + err = -EINVAL; + } + return err; +} + struct context_barrier_task { struct i915_active base; void (*task)(void *data); @@ -2380,6 +2450,21 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, return ret; } +int i915_gem_getparam_ioctl(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct drm_i915_gem_context_param *args = data; + u32 class = upper_32_bits(args->param); + + switch (class) { + case 0: + return i915_gem_context_getparam_ioctl(dev, data, file); + case 2: + return i915_gem_vm_getparam_ioctl(dev, data, file); + } + return -EINVAL; +} + int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { @@ -2398,6 +2483,21 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, return ret; } +int i915_gem_setparam_ioctl(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct drm_i915_gem_context_param *args = data; + u32 class = upper_32_bits(args->param); + + switch (class) { + case 0: + return i915_gem_context_setparam_ioctl(dev, data, file); + case 2: + return i915_gem_vm_setparam_ioctl(dev, data, file); + } + return -EINVAL; +} + int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.h b/drivers/gpu/drm/i915/gem/i915_gem_context.h index 3ae61a355d87..59ebe90b8cd5 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.h @@ -131,6 +131,10 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); +int i915_gem_getparam_ioctl(struct drm_device *dev, void *data, + struct drm_file *file); +int i915_gem_setparam_ioctl(struct drm_device *dev, void *data, + struct drm_file *file); int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data, struct drm_file *file); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c index 6aaffb9a817f..6dce8a42fd0c 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c @@ -426,6 +426,11 @@ eb_validate_vma(struct i915_execbuffer *eb, if (unlikely(entry->alignment && !is_power_of_2(entry->alignment))) return -EINVAL; + /* Only allow user PINNED addresses for SVM enabled contexts */ + if (unlikely(i915_vm_is_svm_enabled(eb->gem_context->vm) && + !(entry->flags & EXEC_OBJECT_PINNED))) + return -EINVAL; + /* * Offset can be used as input (EXEC_OBJECT_PINNED), reject * any non-page-aligned or non-canonical addresses. diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index 800c062a4b0e..8581503a0a6e 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -268,6 +268,7 @@ struct i915_address_space { */ struct list_head svm_list; struct mutex svm_mutex; /* protects svm operations */ + bool svm_enabled; struct pagestash free_pages; @@ -367,6 +368,8 @@ struct i915_ppgtt { #define i915_is_ggtt(vm) ((vm)->is_ggtt) +#define i915_vm_is_svm_enabled(vm) ((vm)->svm_enabled) + static inline bool i915_vm_is_4lvl(const struct i915_address_space *vm) { diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 5631fa82bfed..2023a82ad594 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -2700,6 +2700,8 @@ static int i915_gem_vm_bind_ioctl(struct drm_device *dev, void *data, vm = i915_gem_address_space_lookup(file->driver_priv, args->vm_id); if (unlikely(!vm)) return -ENOENT; + if (unlikely(!i915_vm_is_svm_enabled(vm))) + return -ENOTSUPP; if (!args->num_vas) goto bind_done; @@ -2782,8 +2784,8 @@ static const struct drm_ioctl_desc i915_ioctls[] = { DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_gem_context_reset_stats_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, DRM_RENDER_ALLOW), - DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_context_getparam_ioctl, DRM_RENDER_ALLOW), - DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_context_setparam_ioctl, DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, i915_gem_getparam_ioctl, DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, i915_gem_setparam_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_PERF_OPEN, i915_perf_open_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_PERF_ADD_CONFIG, i915_perf_add_config_ioctl, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(I915_PERF_REMOVE_CONFIG, i915_perf_remove_config_ioctl, DRM_RENDER_ALLOW), diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 7be87bc37cc0..9f2407cee28e 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -1746,6 +1747,15 @@ IS_SUBPLATFORM(const struct drm_i915_private *i915, /* Only valid when HAS_DISPLAY() is true */ #define INTEL_DISPLAY_ENABLED(dev_priv) (WARN_ON(!HAS_DISPLAY(dev_priv)), !i915_modparams.disable_display) +static inline bool i915_has_svm(struct drm_i915_private *dev_priv) +{ +#ifdef CONFIG_DRM_I915_SVM + return INTEL_GEN(dev_priv) >= 8; +#else + return false; +#endif +} + static inline bool intel_vtd_active(void) { #ifdef CONFIG_INTEL_IOMMU diff --git a/drivers/gpu/drm/i915/i915_getparam.c b/drivers/gpu/drm/i915/i915_getparam.c index 54fce81d5724..c35402103e0f 100644 --- a/drivers/gpu/drm/i915/i915_getparam.c +++ b/drivers/gpu/drm/i915/i915_getparam.c @@ -161,6 +161,9 @@ int i915_getparam_ioctl(struct drm_device *dev, void *data, case I915_PARAM_PERF_REVISION: value = i915_perf_ioctl_version(); break; + case I915_PARAM_HAS_SVM: + value = i915_has_svm(i915); + break; default: DRM_DEBUG("Unknown parameter %d\n", param->param); return -EINVAL; diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index e696854829ab..a29f9ea203f0 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -359,6 +359,8 @@ typedef struct _drm_i915_sarea { #define DRM_I915_QUERY 0x39 #define DRM_I915_GEM_VM_CREATE 0x3a #define DRM_I915_GEM_VM_DESTROY 0x3b +#define DRM_I915_GEM_VM_GETPARAM DRM_I915_GEM_CONTEXT_GETPARAM +#define DRM_I915_GEM_VM_SETPARAM DRM_I915_GEM_CONTEXT_SETPARAM #define DRM_I915_GEM_VM_BIND 0x3c /* Must be kept compact -- no holes */ @@ -423,6 +425,8 @@ typedef struct _drm_i915_sarea { #define DRM_IOCTL_I915_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_QUERY, struct drm_i915_query) #define DRM_IOCTL_I915_GEM_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_CREATE, struct drm_i915_gem_vm_control) #define DRM_IOCTL_I915_GEM_VM_DESTROY DRM_IOW (DRM_COMMAND_BASE + DRM_I915_GEM_VM_DESTROY, struct drm_i915_gem_vm_control) +#define DRM_IOCTL_I915_GEM_VM_GETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_GETPARAM, struct drm_i915_gem_vm_param) +#define DRM_IOCTL_I915_GEM_VM_SETPARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_SETPARAM, struct drm_i915_gem_vm_param) #define DRM_IOCTL_I915_GEM_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_VM_BIND, struct drm_i915_gem_vm_bind) /* Allow drivers to submit batchbuffers directly to hardware, relying @@ -621,6 +625,8 @@ typedef struct drm_i915_irq_wait { */ #define I915_PARAM_PERF_REVISION 54 +/* Shared Virtual Memory (SVM) support capability */ +#define I915_PARAM_HAS_SVM 55 /* Must be kept compact -- no holes and well documented */ typedef struct drm_i915_getparam { @@ -1826,6 +1832,17 @@ struct drm_i915_gem_vm_control { __u32 vm_id; }; +struct drm_i915_gem_vm_param { + __u32 vm_id; + __u32 rsvd; + +#define I915_VM_PARAM (2ull << 32) +#define I915_GEM_VM_PARAM_SVM 0x1 + __u64 param; + + __u64 value; +}; + struct drm_i915_reg_read { /* * Register offset. From patchwork Fri Jan 24 08:54:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niranjana Vishwanathapura X-Patchwork-Id: 11349899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B713138C for ; Fri, 24 Jan 2020 09:06:39 +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 43DD82071A for ; Fri, 24 Jan 2020 09:06:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43DD82071A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 081A66FFAD; Fri, 24 Jan 2020 09:06:35 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A2F56FF9E for ; Fri, 24 Jan 2020 09:06:29 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2020 01:04:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,357,1574150400"; d="scan'208";a="245655161" Received: from nvishwa1-desk.sc.intel.com ([10.3.160.185]) by orsmga002.jf.intel.com with ESMTP; 24 Jan 2020 01:04:50 -0800 From: Niranjana Vishwanathapura To: intel-gfx@lists.freedesktop.org Date: Fri, 24 Jan 2020 00:54:02 -0800 Message-Id: <20200124085402.11644-9-niranjana.vishwanathapura@intel.com> X-Mailer: git-send-email 2.21.0.rc0.32.g243a4c7e27 In-Reply-To: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> References: <20200124085402.11644-1-niranjana.vishwanathapura@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC 8/8] drm/i915/svm: VM_BIND for endless batch buffer X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chris.p.wilson@intel.com, jason.ekstrand@intel.com, daniel.vetter@intel.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Initial attempt at supporting VM_BIND for endless batch buffer. Not tested. Cc: Joonas Lahtinen Cc: Jon Bloomfield Cc: Daniel Vetter Cc: Chris P Wilson Cc: Sudeep Dutt Cc: Stuart Summers Signed-off-by: Niranjana Vishwanathapura --- drivers/gpu/drm/i915/gem/i915_gem_svm.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_svm.c b/drivers/gpu/drm/i915/gem/i915_gem_svm.c index e5e45ccc4262..dd12c2c46aa8 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_svm.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_svm.c @@ -68,9 +68,20 @@ int i915_gem_vm_bind_svm_obj(struct i915_address_space *vm, * and we don't need to store va_start. */ mutex_lock(&vm->svm_mutex); + if (i915_vm_is_active(vm)) { + u64 pin_flags = vma->va_start | + PIN_OFFSET_FIXED | PIN_USER; + + ret = i915_vma_pin(vma, 0, 0, pin_flags); + if (ret) { + mutex_unlock(&vm->mutex); + goto put_obj; + } + } list_add(&vma->svm_link, &vm->svm_list); mutex_unlock(&vm->svm_mutex); } else { + /* FIXME: Do async unbind if vm is active */ vma = i915_gem_vm_lookup_svm_vma(vm, obj, va); if (vma) { __i915_vma_unpin(vma);