From patchwork Thu Nov 27 13:48:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 5396421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 92828C11AC for ; Thu, 27 Nov 2014 13:49:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 403F2201E4 for ; Thu, 27 Nov 2014 13:49:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CDBAC20145 for ; Thu, 27 Nov 2014 13:49:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D806A6E985; Thu, 27 Nov 2014 05:49:07 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from pegasos-out.vodafone.de (pegasos-out.vodafone.de [80.84.1.38]) by gabe.freedesktop.org (Postfix) with ESMTP id F377D6E167 for ; Thu, 27 Nov 2014 05:49:00 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by pegasos-out.vodafone.de (Rohrpostix1 Daemon) with ESMTP id 569B2261423; Thu, 27 Nov 2014 14:49:00 +0100 (CET) X-Virus-Scanned: amavisd-new at vodafone.de X-Spam-Score: -0.053 X-Spam-Level: X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Authentication-Results: rohrpostix1.prod.vfnet.de (amavisd-new); dkim=pass header.i=@vodafone.de Received: from pegasos-out.vodafone.de ([127.0.0.1]) by localhost (rohrpostix1.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QdnTvHiHdHmr; Thu, 27 Nov 2014 14:48:58 +0100 (CET) Received: from smtp-05.vodafone.de (smtp-05.vodafone.de [10.215.254.32]) by pegasos-out.vodafone.de (Rohrpostix1 Daemon) with ESMTP id 114A926094F; Thu, 27 Nov 2014 14:48:58 +0100 (CET) X-DKIM: OpenDKIM Filter v2.6.8 pegasos-out.vodafone.de 114A926094F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vodafone.de; s=mail; t=1417096138; bh=tjQiYQFDTrA3sxi0UyPa+RiZldCpR4RNv38JW9RtUtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zlaC3iWNTVvHU5/ejCN3009rBqz8hUo1BX7vW/S1aY0tMhL1q7thNMSZaf7HwFHaL Eqb/MelnxbueHGB0Lj/vGFdmyaVlgYQDzz5L0bEb3G9eJCf1VCExh9H5TP+mZw/S9f AhozCoZWUuD/ekqbFT3LxBsvliFc7REi8zhBCVXI= X-DKIM: OpenDKIM Filter v2.0.2 smtp-05.vodafone.de 85CA2E55C5 X-Virus-Scanned: amavisd-new at vodafone.de Received: from smtp-05.vodafone.de ([127.0.0.1]) by localhost (xsmail-dmz1.prod.vfnet.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0toiHD5aLHHA; Thu, 27 Nov 2014 14:48:52 +0100 (CET) From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: alexdeucher@gmail.com Subject: [PATCH 6/7] drm/radeon: take VM lock before BO locks Date: Thu, 27 Nov 2014 14:48:45 +0100 Message-Id: <1417096126-14859-6-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417096126-14859-1-git-send-email-deathsimple@vodafone.de> References: <1417096126-14859-1-git-send-email-deathsimple@vodafone.de> MIME-Version: 1.0 Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König Signed-off-by: Christian König --- drivers/gpu/drm/radeon/radeon.h | 2 +- drivers/gpu/drm/radeon/radeon_cs.c | 9 +++++-- drivers/gpu/drm/radeon/radeon_gem.c | 17 ++++++++++---- drivers/gpu/drm/radeon/radeon_kms.c | 5 ++++ drivers/gpu/drm/radeon/radeon_vm.c | 47 +++++++++---------------------------- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 3680cf0..699446a 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -925,7 +925,7 @@ struct radeon_vm_id { }; struct radeon_vm { - struct mutex mutex; + struct mutex lock; struct rb_root va; diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c index fb776cb..7a90378 100644 --- a/drivers/gpu/drm/radeon/radeon_cs.c +++ b/drivers/gpu/drm/radeon/radeon_cs.c @@ -195,6 +195,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p) if (p->cs_flags & RADEON_CS_USE_VM) p->vm_bos = radeon_vm_get_bos(p->rdev, p->ib.vm, &p->validated); + if (need_mmap_lock) down_read(¤t->mm->mmap_sem); @@ -571,7 +572,6 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev, if (parser->ring == R600_RING_TYPE_UVD_INDEX) radeon_uvd_note_usage(rdev); - mutex_lock(&vm->mutex); r = radeon_bo_vm_update_pte(parser, vm); if (r) { goto out; @@ -592,7 +592,6 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev, } out: - mutex_unlock(&vm->mutex); return r; } @@ -696,6 +695,8 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) } r = radeon_cs_ib_fill(rdev, &parser); + if (parser.cs_flags & RADEON_CS_USE_VM) + mutex_lock(&parser.ib.vm->lock); if (!r) { r = radeon_cs_parser_relocs(&parser); if (r && r != -ERESTARTSYS) @@ -704,6 +705,8 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) if (r) { radeon_cs_parser_fini(&parser, r, false); + if (parser.cs_flags & RADEON_CS_USE_VM) + mutex_unlock(&parser.ib.vm->lock); up_read(&rdev->exclusive_lock); r = radeon_cs_handle_lockup(rdev, r); return r; @@ -721,6 +724,8 @@ int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) } out: radeon_cs_parser_fini(&parser, r, true); + if (parser.cs_flags & RADEON_CS_USE_VM) + mutex_unlock(&parser.ib.vm->lock); up_read(&rdev->exclusive_lock); r = radeon_cs_handle_lockup(rdev, r); return r; diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c index 6162bd2..4eafec6 100644 --- a/drivers/gpu/drm/radeon/radeon_gem.c +++ b/drivers/gpu/drm/radeon/radeon_gem.c @@ -150,8 +150,10 @@ int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_pri return 0; } + mutex_lock(&vm->lock); r = radeon_bo_reserve(rbo, false); if (r) { + mutex_unlock(&vm->lock); return r; } @@ -162,6 +164,7 @@ int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_pri ++bo_va->ref_count; } radeon_bo_unreserve(rbo); + mutex_unlock(&vm->lock); return 0; } @@ -180,8 +183,10 @@ void radeon_gem_object_close(struct drm_gem_object *obj, return; } + mutex_lock(&vm->lock); r = radeon_bo_reserve(rbo, true); if (r) { + mutex_unlock(&vm->lock); dev_err(rdev->dev, "leaking bo va because " "we fail to reserve bo (%d)\n", r); return; @@ -193,6 +198,7 @@ void radeon_gem_object_close(struct drm_gem_object *obj, } } radeon_bo_unreserve(rbo); + mutex_unlock(&vm->lock); } static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r) @@ -576,17 +582,13 @@ static void radeon_gem_va_update_vm(struct radeon_device *rdev, goto error_unreserve; } - mutex_lock(&bo_va->vm->mutex); r = radeon_vm_clear_freed(rdev, bo_va->vm); if (r) - goto error_unlock; + goto error_unreserve; if (bo_va->it.start) r = radeon_vm_bo_update(rdev, bo_va, &bo_va->bo->tbo.mem); -error_unlock: - mutex_unlock(&bo_va->vm->mutex); - error_unreserve: ttm_eu_backoff_reservation(&ticket, &list); @@ -662,14 +664,18 @@ int radeon_gem_va_ioctl(struct drm_device *dev, void *data, return -ENOENT; } rbo = gem_to_radeon_bo(gobj); + mutex_lock(&fpriv->vm.lock); r = radeon_bo_reserve(rbo, false); if (r) { + mutex_unlock(&fpriv->vm.lock); args->operation = RADEON_VA_RESULT_ERROR; drm_gem_object_unreference_unlocked(gobj); return r; } bo_va = radeon_vm_bo_find(&fpriv->vm, rbo); if (!bo_va) { + radeon_bo_unreserve(rbo); + mutex_unlock(&fpriv->vm.lock); args->operation = RADEON_VA_RESULT_ERROR; drm_gem_object_unreference_unlocked(gobj); return -ENOENT; @@ -698,6 +704,7 @@ int radeon_gem_va_ioctl(struct drm_device *dev, void *data, args->operation = RADEON_VA_RESULT_ERROR; } out: + mutex_unlock(&fpriv->vm.lock); drm_gem_object_unreference_unlocked(gobj); return r; } diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c index f4dd26a..d994006 100644 --- a/drivers/gpu/drm/radeon/radeon_kms.c +++ b/drivers/gpu/drm/radeon/radeon_kms.c @@ -613,8 +613,10 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) } if (rdev->accel_working) { + mutex_lock(&vm->lock); r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); if (r) { + mutex_unlock(&vm->lock); radeon_vm_fini(rdev, vm); kfree(fpriv); return r; @@ -628,6 +630,7 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) RADEON_VA_IB_OFFSET, RADEON_VM_PAGE_READABLE | RADEON_VM_PAGE_SNOOPED); + mutex_unlock(&vm->lock); if (r) { radeon_vm_fini(rdev, vm); kfree(fpriv); @@ -662,12 +665,14 @@ void radeon_driver_postclose_kms(struct drm_device *dev, int r; if (rdev->accel_working) { + mutex_lock(&vm->lock); r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); if (!r) { if (vm->ib_bo_va) radeon_vm_bo_rmv(rdev, vm->ib_bo_va); radeon_bo_unreserve(rdev->ring_tmp_bo.bo); } + mutex_unlock(&vm->lock); } radeon_vm_fini(rdev, vm); diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c index cde48c4..658183f 100644 --- a/drivers/gpu/drm/radeon/radeon_vm.c +++ b/drivers/gpu/drm/radeon/radeon_vm.c @@ -172,7 +172,7 @@ struct radeon_bo_list *radeon_vm_get_bos(struct radeon_device *rdev, * Allocate an id for the vm (cayman+). * Returns the fence we need to sync to (if any). * - * Global and local mutex must be locked! + * Mutex must be locked! */ struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev, struct radeon_vm *vm, int ring) @@ -231,7 +231,7 @@ struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev, * * Flush the vm (cayman+). * - * Global and local mutex must be locked! + * Mutex must be locked! */ void radeon_vm_flush(struct radeon_device *rdev, struct radeon_vm *vm, @@ -263,7 +263,7 @@ void radeon_vm_flush(struct radeon_device *rdev, * Fence the vm (cayman+). * Set the fence used to protect page table and id. * - * Global and local mutex must be locked! + * Mutex must be locked! */ void radeon_vm_fence(struct radeon_device *rdev, struct radeon_vm *vm, @@ -314,7 +314,7 @@ struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm, * Add @bo to the list of bos associated with the vm * Returns newly added bo_va or NULL for failure * - * Object has to be reserved! + * Mutex must be locked and object has to be reserved! */ struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev, struct radeon_vm *vm, @@ -336,9 +336,7 @@ struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev, INIT_LIST_HEAD(&bo_va->bo_list); INIT_LIST_HEAD(&bo_va->vm_status); - mutex_lock(&vm->mutex); list_add_tail(&bo_va->bo_list, &bo->va); - mutex_unlock(&vm->mutex); return bo_va; } @@ -441,7 +439,8 @@ error_unreserve: * Validate and set the offset requested within the vm address space. * Returns 0 for success, error for failure. * - * Object has to be reserved and gets unreserved by this function! + * Mutex must be locked and object has to be reserved and gets + * unreserved by this function! */ int radeon_vm_bo_set_addr(struct radeon_device *rdev, struct radeon_bo_va *bo_va, @@ -472,14 +471,12 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, eoffset = last_pfn = 0; } - mutex_lock(&vm->mutex); if (bo_va->it.start || bo_va->it.last) { if (bo_va->addr) { /* add a clone of the bo_va to clear the old address */ struct radeon_bo_va *tmp; tmp = kzalloc(sizeof(struct radeon_bo_va), GFP_KERNEL); if (!tmp) { - mutex_unlock(&vm->mutex); return -ENOMEM; } tmp->it.start = bo_va->it.start; @@ -509,7 +506,6 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, dev_err(rdev->dev, "bo %p va 0x%010Lx conflict with " "(bo %p 0x%010lx 0x%010lx)\n", bo_va->bo, soffset, tmp->bo, tmp->it.start, tmp->it.last); - mutex_unlock(&vm->mutex); return -EINVAL; } bo_va->it.start = soffset; @@ -537,9 +533,6 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, if (vm->page_tables[pt_idx].bo) continue; - /* drop mutex to allocate and clear page table */ - mutex_unlock(&vm->mutex); - r = radeon_bo_create(rdev, RADEON_VM_PTE_COUNT * 8, RADEON_GPU_PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM, 0, @@ -554,21 +547,10 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev, return r; } - /* aquire mutex again */ - mutex_lock(&vm->mutex); - if (vm->page_tables[pt_idx].bo) { - /* someone else allocated the pt in the meantime */ - mutex_unlock(&vm->mutex); - radeon_bo_unref(&pt); - mutex_lock(&vm->mutex); - continue; - } - vm->page_tables[pt_idx].addr = 0; vm->page_tables[pt_idx].bo = pt; } - mutex_unlock(&vm->mutex); return 0; } @@ -627,7 +609,7 @@ static uint32_t radeon_vm_page_flags(uint32_t flags) * and updates the page directory (cayman+). * Returns 0 for success, error for failure. * - * Global and local mutex must be locked! + * Mutex must be locked! */ int radeon_vm_update_page_directory(struct radeon_device *rdev, struct radeon_vm *vm) @@ -717,8 +699,6 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev, * @pe_end: last PTE to handle * @addr: addr those PTEs should point to * @flags: hw mapping flags - * - * Global and local mutex must be locked! */ static void radeon_vm_frag_ptes(struct radeon_device *rdev, struct radeon_ib *ib, @@ -798,7 +778,6 @@ static void radeon_vm_frag_ptes(struct radeon_device *rdev, * * Update the page tables in the range @start - @end (cayman+). * - * Global and local mutex must be locked! */ static int radeon_vm_update_ptes(struct radeon_device *rdev, struct radeon_vm *vm, @@ -870,7 +849,6 @@ static int radeon_vm_update_ptes(struct radeon_device *rdev, * * Fence the page tables in the range @start - @end (cayman+). * - * Global and local mutex must be locked! */ static void radeon_vm_fence_pts(struct radeon_vm *vm, uint64_t start, uint64_t end, @@ -896,7 +874,7 @@ static void radeon_vm_fence_pts(struct radeon_vm *vm, * Fill in the page table entries for @bo (cayman+). * Returns 0 for success, -EINVAL for failure. * - * Object have to be reserved and mutex must be locked! + * Mutex must be locked and BOs have to be reserved! */ int radeon_vm_bo_update(struct radeon_device *rdev, struct radeon_bo_va *bo_va, @@ -1097,7 +1075,7 @@ int radeon_vm_clear_invalids(struct radeon_device *rdev, * * Remove @bo_va->bo from the requested vm (cayman+). * - * Object have to be reserved! + * Mutex must be locked and object has to be reserved! */ void radeon_vm_bo_rmv(struct radeon_device *rdev, struct radeon_bo_va *bo_va) @@ -1106,7 +1084,6 @@ void radeon_vm_bo_rmv(struct radeon_device *rdev, list_del(&bo_va->bo_list); - mutex_lock(&vm->mutex); interval_tree_remove(&bo_va->it, &vm->va); spin_lock(&vm->status_lock); list_del(&bo_va->vm_status); @@ -1119,8 +1096,6 @@ void radeon_vm_bo_rmv(struct radeon_device *rdev, kfree(bo_va); } spin_unlock(&vm->status_lock); - - mutex_unlock(&vm->mutex); } /** @@ -1168,7 +1143,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm) vm->ids[i].flushed_updates = NULL; vm->ids[i].last_id_use = NULL; } - mutex_init(&vm->mutex); + mutex_init(&vm->lock); vm->va = RB_ROOT; spin_lock_init(&vm->status_lock); INIT_LIST_HEAD(&vm->invalidated); @@ -1245,5 +1220,5 @@ void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm) radeon_fence_unref(&vm->ids[i].last_id_use); } - mutex_destroy(&vm->mutex); + mutex_destroy(&vm->lock); }