From patchwork Thu Jul 10 21:50:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 4528671 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1ECB19F4BC for ; Thu, 10 Jul 2014 23:34:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DF9720204 for ; Thu, 10 Jul 2014 23:34:19 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 39241201DE for ; Thu, 10 Jul 2014 23:34:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CD9556E7BA; Thu, 10 Jul 2014 16:33:25 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com [74.125.82.41]) by gabe.freedesktop.org (Postfix) with ESMTP id C56CA6E01B for ; Thu, 10 Jul 2014 14:52:29 -0700 (PDT) Received: by mail-wg0-f41.google.com with SMTP id z12so188214wgg.24 for ; Thu, 10 Jul 2014 14:52:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nZunSKCH1+2mzOAFvT314NEYYxxne9H8SBSdxwtLemU=; b=ociIve4ttVbqXPcOC/w5jqA2lhl4imXCg0Wqh+heJvoETXp/Ni73WP48gSX5qTbOxh XDqHbQtJbyVB8VgQNKkeG9uDROX4NxAdpTxhHr0CSiHvWo6QiGgwYYJjfyETG5u8zWRn j7+qppkRLg51bfpAlPHctiyof6YBGH096swCbcJbjuSGJawNOU8AhzX+hsrRR92FMsyx 2x0fbmGs2Qz5/MXHXH3ea5u9IlitP7TypEcGFR9w0ARsMoENqX/VswDJivcKUcaTXUTy eqVUq+52C4XcojaT6o9x9G3CiPFBJkXI9JlUZsf+cAK0/mKXfgWxJmOTZOPP1aDHzXvV Oe/A== X-Received: by 10.180.89.193 with SMTP id bq1mr21982207wib.81.1405029145683; Thu, 10 Jul 2014 14:52:25 -0700 (PDT) Received: from localhost.localdomain ([77.127.59.49]) by mx.google.com with ESMTPSA id n2sm805353wjf.40.2014.07.10.14.52.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Jul 2014 14:52:24 -0700 (PDT) From: Oded Gabbay X-Google-Original-From: Oded Gabbay To: David Airlie , Alex Deucher , Jerome Glisse Subject: [PATCH 26/83] hsa/radeon: Make binding of process to device permanent Date: Fri, 11 Jul 2014 00:50:26 +0300 Message-Id: <1405029027-6085-25-git-send-email-oded.gabbay@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405029027-6085-1-git-send-email-oded.gabbay@amd.com> References: <1405029027-6085-1-git-send-email-oded.gabbay@amd.com> X-Mailman-Approved-At: Thu, 10 Jul 2014 16:33:12 -0700 Cc: Andrew Lewycky , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Lewycky Permanently bind the process to the device. The binding survives even when all queues are destroyed. Process exit and device removal terminate the binding. Signed-off-by: Andrew Lewycky Signed-off-by: Oded Gabbay --- drivers/gpu/hsa/radeon/kfd_chardev.c | 27 +++------------------------ drivers/gpu/hsa/radeon/kfd_priv.h | 3 --- drivers/gpu/hsa/radeon/kfd_process.c | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/hsa/radeon/kfd_chardev.c b/drivers/gpu/hsa/radeon/kfd_chardev.c index 4e7d5d0..e0b276d 100644 --- a/drivers/gpu/hsa/radeon/kfd_chardev.c +++ b/drivers/gpu/hsa/radeon/kfd_chardev.c @@ -141,20 +141,13 @@ kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, void __user *a pdd = radeon_kfd_bind_process_to_device(dev, p); if (IS_ERR(pdd) < 0) { err = PTR_ERR(pdd); - goto err_bind_pasid; + goto err_bind_process; } - pr_debug("kfd: creating queue number %d for PASID %d on GPU 0x%x\n", - pdd->queue_count, + pr_debug("kfd: creating queue for PASID %d on GPU 0x%x\n", p->pasid, dev->id); - if (pdd->queue_count++ == 0) { - err = dev->device_info->scheduler_class->register_process(dev->scheduler, p, &pdd->scheduler_process); - if (err < 0) - goto err_register_process; - } - if (!radeon_kfd_allocate_queue_id(p, &queue_id)) goto err_allocate_queue_id; @@ -198,12 +191,7 @@ err_copy_args_out: err_create_queue: radeon_kfd_remove_queue(p, queue_id); err_allocate_queue_id: - if (--pdd->queue_count == 0) { - dev->device_info->scheduler_class->deregister_process(dev->scheduler, pdd->scheduler_process); - pdd->scheduler_process = NULL; - } -err_register_process: -err_bind_pasid: +err_bind_process: kfree(queue); mutex_unlock(&p->mutex); return err; @@ -215,7 +203,6 @@ kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p, void __user *a struct kfd_ioctl_destroy_queue_args args; struct kfd_queue *queue; struct kfd_dev *dev; - struct kfd_process_device *pdd; if (copy_from_user(&args, arg, sizeof(args))) return -EFAULT; @@ -239,14 +226,6 @@ kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p, void __user *a kfree(queue); - pdd = radeon_kfd_get_process_device_data(dev, p); - BUG_ON(pdd == NULL); /* Because a queue exists. */ - - if (--pdd->queue_count == 0) { - dev->device_info->scheduler_class->deregister_process(dev->scheduler, pdd->scheduler_process); - pdd->scheduler_process = NULL; - } - mutex_unlock(&p->mutex); return 0; } diff --git a/drivers/gpu/hsa/radeon/kfd_priv.h b/drivers/gpu/hsa/radeon/kfd_priv.h index 630d690..bca9cce 100644 --- a/drivers/gpu/hsa/radeon/kfd_priv.h +++ b/drivers/gpu/hsa/radeon/kfd_priv.h @@ -166,9 +166,6 @@ struct kfd_process_device { /* The user-mode address of the doorbell mapping for this device. */ doorbell_t __user *doorbell_mapping; - /* The number of queues created by this process for this device. */ - uint32_t queue_count; - /* Scheduler process data for this device. */ struct kfd_scheduler_process *scheduler_process; diff --git a/drivers/gpu/hsa/radeon/kfd_process.c b/drivers/gpu/hsa/radeon/kfd_process.c index 145ee38..f89f855 100644 --- a/drivers/gpu/hsa/radeon/kfd_process.c +++ b/drivers/gpu/hsa/radeon/kfd_process.c @@ -120,15 +120,6 @@ destroy_queues(struct kfd_process *p, struct kfd_dev *dev_filter) dev->device_info->scheduler_class->destroy_queue(dev->scheduler, &queue->scheduler_queue); kfree(queue); - - BUG_ON(pdd->queue_count == 0); - BUG_ON(pdd->scheduler_process == NULL); - - if (--pdd->queue_count == 0) { - dev->device_info->scheduler_class->deregister_process(dev->scheduler, - pdd->scheduler_process); - pdd->scheduler_process = NULL; - } } } } @@ -144,6 +135,8 @@ static void free_process(struct kfd_process *p) /* doorbell mappings: automatic */ list_for_each_entry_safe(pdd, temp, &p->per_device_data, per_device_list) { + pdd->dev->device_info->scheduler_class->deregister_process(pdd->dev->scheduler, pdd->scheduler_process); + pdd->scheduler_process = NULL; amd_iommu_unbind_pasid(pdd->dev->pdev, p->pasid); list_del(&pdd->per_device_list); kfree(pdd); @@ -255,6 +248,12 @@ struct kfd_process_device *radeon_kfd_bind_process_to_device(struct kfd_dev *dev if (err < 0) return ERR_PTR(err); + err = dev->device_info->scheduler_class->register_process(dev->scheduler, p, &pdd->scheduler_process); + if (err < 0) { + amd_iommu_unbind_pasid(dev->pdev, p->pasid); + return ERR_PTR(err); + } + pdd->bound = true; return pdd; @@ -285,8 +284,8 @@ void radeon_kfd_unbind_process_from_device(struct kfd_dev *dev, pasid_t pasid) destroy_queues(p, dev); - /* All queues just got destroyed so this should be gone. */ - BUG_ON(pdd->scheduler_process != NULL); + dev->device_info->scheduler_class->deregister_process(dev->scheduler, pdd->scheduler_process); + pdd->scheduler_process = NULL; /* * Just mark pdd as unbound, because we still need it to call