From patchwork Wed Jan 30 01:53:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bas Nieuwenhuizen X-Patchwork-Id: 10787549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96B6D6C2 for ; Wed, 30 Jan 2019 01:54:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 880AB2C5FD for ; Wed, 30 Jan 2019 01:54:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BBF02D2C5; Wed, 30 Jan 2019 01:54:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B13E12C5FD for ; Wed, 30 Jan 2019 01:54:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E9E666E42C; Wed, 30 Jan 2019 01:54:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id CA57F6E42C for ; Wed, 30 Jan 2019 01:54:38 +0000 (UTC) Received: by mail-ed1-x542.google.com with SMTP id b14so17713880edt.6 for ; Tue, 29 Jan 2019 17:54:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5ZXcoHQyfOcVHBxNsVneAwZ0OoKNeF421o6wngqeARA=; b=PSvhA2SdXYbLcJ+uM0H6DxO3j9XtyGoyilZcOgC/H0mrGxwADbhR0ipJpqxeiNmOoZ WsoF1NlL8jhhmF/O7lLpD8Oq/6F2zi5kt+SVELpcHsaKwAxIP4Luk2kUZsMHeZ/9Qafy epBgrPx4aatK9ClN9fjpepQi95MS/qqwX/N/i559uVlM4ucLattf9ZB4bbhwTizpGRJj qeH/eiGJkCWiSKQOgutYTl6nqPE1sj7QxMjNMCWoYTnBjsCZsQIpuygJ2HEgAKCEjbmT q/abP/mDSLEFfxy24YdJgCS45M1jAM3hK278evrmtLv46AfxWlGIU5AAFzSzsfbqMmhv ARkw== X-Gm-Message-State: AJcUukfikcaKLl5CvYsoBxQWIDVF2OpIuoQbtKqnlQ7fpxCWS/5nlDtF 38mFg6FhFd+hn0+/nbqXWz4FeZKdfUE= X-Google-Smtp-Source: ALg8bN7xVwsDAaoQt159BXr/MGsI7MmBeytDHRmVOvmN2/stsLw5GGGQNTmJKVm4XSUzvopKw1swpA== X-Received: by 2002:a17:906:2ec6:: with SMTP id s6-v6mr24502537eji.93.1548813277310; Tue, 29 Jan 2019 17:54:37 -0800 (PST) Received: from localhost.localdomain ([2a02:aa12:a77f:2000:7285:c2ff:fe4e:b21b]) by smtp.gmail.com with ESMTPSA id l18sm117157edq.87.2019.01.29.17.54.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 17:54:36 -0800 (PST) From: Bas Nieuwenhuizen To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/4] drm/sched: Fix entities with 0 rqs. Date: Wed, 30 Jan 2019 02:53:19 +0100 Message-Id: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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-Virus-Scanned: ClamAV using ClamSMTP Some blocks in amdgpu can have 0 rqs. Job creation already fails with -ENOENT when entity->rq is NULL, so jobs cannot be pushed. Without a rq there is no scheduler to pop jobs, and rq selection already does the right thing with a list of length 0. So the operations we need to fix are: - Creation, do not set rq to rq_list[0] if the list can have length 0. - Do not flush any jobs when there is no rq. - On entity destruction handle the rq = NULL case. - on set_priority, do not try to change the rq if it is NULL. Signed-off-by: Bas Nieuwenhuizen Reviewed-by: Christian König . --- drivers/gpu/drm/scheduler/sched_entity.c | 39 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 4463d3826ecb..8e31b6628d09 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -52,12 +52,12 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, { int i; - if (!(entity && rq_list && num_rq_list > 0 && rq_list[0])) + if (!(entity && rq_list && (num_rq_list == 0 || rq_list[0]))) return -EINVAL; memset(entity, 0, sizeof(struct drm_sched_entity)); INIT_LIST_HEAD(&entity->list); - entity->rq = rq_list[0]; + entity->rq = NULL; entity->guilty = guilty; entity->num_rq_list = num_rq_list; entity->rq_list = kcalloc(num_rq_list, sizeof(struct drm_sched_rq *), @@ -67,6 +67,10 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, for (i = 0; i < num_rq_list; ++i) entity->rq_list[i] = rq_list[i]; + + if (num_rq_list) + entity->rq = rq_list[0]; + entity->last_scheduled = NULL; spin_lock_init(&entity->rq_lock); @@ -165,6 +169,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) struct task_struct *last_user; long ret = timeout; + if (!entity->rq) + return 0; + sched = entity->rq->sched; /** * The client will not queue more IBs during this fini, consume existing @@ -264,20 +271,24 @@ static void drm_sched_entity_kill_jobs(struct drm_sched_entity *entity) */ void drm_sched_entity_fini(struct drm_sched_entity *entity) { - struct drm_gpu_scheduler *sched; + struct drm_gpu_scheduler *sched = NULL; - sched = entity->rq->sched; - drm_sched_rq_remove_entity(entity->rq, entity); + if (entity->rq) { + sched = entity->rq->sched; + drm_sched_rq_remove_entity(entity->rq, entity); + } /* Consumption of existing IBs wasn't completed. Forcefully * remove them here. */ if (spsc_queue_peek(&entity->job_queue)) { - /* Park the kernel for a moment to make sure it isn't processing - * our enity. - */ - kthread_park(sched->thread); - kthread_unpark(sched->thread); + if (sched) { + /* Park the kernel for a moment to make sure it isn't processing + * our enity. + */ + kthread_park(sched->thread); + kthread_unpark(sched->thread); + } if (entity->dependency) { dma_fence_remove_callback(entity->dependency, &entity->cb); @@ -362,9 +373,11 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, for (i = 0; i < entity->num_rq_list; ++i) drm_sched_entity_set_rq_priority(&entity->rq_list[i], priority); - drm_sched_rq_remove_entity(entity->rq, entity); - drm_sched_entity_set_rq_priority(&entity->rq, priority); - drm_sched_rq_add_entity(entity->rq, entity); + if (entity->rq) { + drm_sched_rq_remove_entity(entity->rq, entity); + drm_sched_entity_set_rq_priority(&entity->rq, priority); + drm_sched_rq_add_entity(entity->rq, entity); + } spin_unlock(&entity->rq_lock); } From patchwork Wed Jan 30 01:53:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bas Nieuwenhuizen X-Patchwork-Id: 10787553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A26AE91E for ; Wed, 30 Jan 2019 01:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95DBC2C5FD for ; Wed, 30 Jan 2019 01:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A29C2D2C5; Wed, 30 Jan 2019 01:54:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C45D2C5FD for ; Wed, 30 Jan 2019 01:54:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BAF5E6EAAD; Wed, 30 Jan 2019 01:54:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 69C4E6E42C for ; Wed, 30 Jan 2019 01:54:39 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id y56so17685186edd.11 for ; Tue, 29 Jan 2019 17:54:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DmDioc5h76SBS6LL4Qm8dI3achc14EwSg+0OtelQiIA=; b=d7JTGNwEAznXYPU5taVUK319x/AuZ2DgNtbLscND900vyiGqXBNLdjYfVQnFIaWQSp UvQ8uyiwAqOCyhVDZ8GN9Su4+owlC4qGMgkKHX0EaibiBFeR2QJyhc6UptB76zAaMOwX PbCix95V/PGwKzC+nxT+5vzow06tCaAZ+ZVIzK2V1Xz19bckxhbpc47o5ijeEKgkEMY6 ttyoxScw407VNslJoEJiXB2BuuyqeqRMB++/eWOImelIYpcgOFJJaxTxXx4QLQz9LdUo psRJZ/hDD249VAb4IsnGIfh1RhotKRpVZyp1M18Q6Obuz5Bmeu7kepWoPUfMvmVprDGu JwKQ== X-Gm-Message-State: AJcUukf4bIHxRQkNNl7ImwLdW7WqfWjOLOsfa0r+BJCx9bXFkVW3sKFy 0xAmTYkwE87DO6eJcGrYYdkB7r93Ozk= X-Google-Smtp-Source: ALg8bN5q+2QgGR9jNIv29lfNTSYsLehPeRQfOXYAQMwG0ZMkUskupxxo07wfe+TdycCwaqrcWMtCeQ== X-Received: by 2002:a50:a844:: with SMTP id j62mr28683136edc.2.1548813277988; Tue, 29 Jan 2019 17:54:37 -0800 (PST) Received: from localhost.localdomain ([2a02:aa12:a77f:2000:7285:c2ff:fe4e:b21b]) by smtp.gmail.com with ESMTPSA id l18sm117157edq.87.2019.01.29.17.54.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 17:54:37 -0800 (PST) From: Bas Nieuwenhuizen To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/4] drm/amdgpu: Only add rqs for initialized rings. Date: Wed, 30 Jan 2019 02:53:20 +0100 Message-Id: <20190130015322.105870-2-bas@basnieuwenhuizen.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> References: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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-Virus-Scanned: ClamAV using ClamSMTP I don't see another way to figure out if a ring is initialized if the hardware block might not be initialized. Entities have been fixed up to handle num_rqs = 0. Signed-off-by: Bas Nieuwenhuizen --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index d85184b5b35c..30407e55593b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -124,6 +124,7 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; struct drm_sched_rq *rqs[AMDGPU_MAX_RINGS]; unsigned num_rings; + unsigned num_rqs = 0; switch (i) { case AMDGPU_HW_IP_GFX: @@ -166,12 +167,16 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, break; } - for (j = 0; j < num_rings; ++j) - rqs[j] = &rings[j]->sched.sched_rq[priority]; + for (j = 0; j < num_rings; ++j) { + if (rings[j]->adev) { + rqs[num_rqs++] = + &rings[j]->sched.sched_rq[priority]; + } + } for (j = 0; j < amdgpu_ctx_num_entities[i]; ++j) r = drm_sched_entity_init(&ctx->entities[i][j].entity, - rqs, num_rings, &ctx->guilty); + rqs, num_rqs, &ctx->guilty); if (r) goto error_cleanup_entities; } From patchwork Wed Jan 30 01:53:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bas Nieuwenhuizen X-Patchwork-Id: 10787551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E08C091E for ; Wed, 30 Jan 2019 01:54:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2E732C5FD for ; Wed, 30 Jan 2019 01:54:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C787F2D2C5; Wed, 30 Jan 2019 01:54:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C5F32C5FD for ; Wed, 30 Jan 2019 01:54:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D40B6E47F; Wed, 30 Jan 2019 01:54:41 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1DD936E47F for ; Wed, 30 Jan 2019 01:54:40 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id f9so17677660eds.10 for ; Tue, 29 Jan 2019 17:54:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PIw6dgX3wRq1l1eGAhYVCKLJx7A+VIHiKRZHh43QHw4=; b=l/2I+J/8EuUHgj1I7cPmYENVDI1JKfz8akUXJYJx/0z3y/hAFoKJ+gfgkS7Ozk9RIF tUDQ5t52ZKVkC7agSe5zOvJMWBcJml0zdKRYohHbd24TS633N0V0h1amrqi/eq/Bgu3Q whaQw7jp1tyOLPw04VGYdr+lKtCgJWjQteoh3Xm71CpFoXO+cdgSP6psHduFqELX3MRh ERCnkCa7wVuN9l2cFM41O9VEMkhmBxa5vGmmt71kwCszanC4vKuFZOphngPwToufLsxG B5ADTauoZExxSIiXVLcTYOfFbVoCWZFteP2rC4jNUXmZD4WCj7DpMZc0SrrN0LaBxWC7 q2dw== X-Gm-Message-State: AHQUAubWd7ElDOagDT0VCDsUejGwtFREciVwUCziG5B/2mNLYjYPrKyb G4CMGF3gwOz2hatpCcQCtgzV/Q== X-Google-Smtp-Source: AHgI3IaDgMH6bSBU3MAIUleu0s8LsLXKweDgwzWADcXNPn1iR0l9yada9FjlBVGuSknVTXhmeh2Wmg== X-Received: by 2002:a50:d753:: with SMTP id i19mr3652334edj.75.1548813278676; Tue, 29 Jan 2019 17:54:38 -0800 (PST) Received: from localhost.localdomain ([2a02:aa12:a77f:2000:7285:c2ff:fe4e:b21b]) by smtp.gmail.com with ESMTPSA id l18sm117157edq.87.2019.01.29.17.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 17:54:38 -0800 (PST) From: Bas Nieuwenhuizen To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/4] drm/amdgpu: Check if fd really is an amdgpu fd. Date: Wed, 30 Jan 2019 02:53:21 +0100 Message-Id: <20190130015322.105870-3-bas@basnieuwenhuizen.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> References: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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-Virus-Scanned: ClamAV using ClamSMTP Otherwise we interpret the file private data as drm & amdgpu data while it might not be, possibly allowing one to get memory corruption. Signed-off-by: Bas Nieuwenhuizen --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 16 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 10 +++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index d67f8b1dfe80..17290cdb8ed8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -411,6 +411,8 @@ struct amdgpu_fpriv { struct amdgpu_ctx_mgr ctx_mgr; }; +int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv); + int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm, unsigned size, struct amdgpu_ib *ib); void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index c806f984bcc5..90a520034c89 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -1176,6 +1176,22 @@ static const struct file_operations amdgpu_driver_kms_fops = { #endif }; +int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv) +{ + struct drm_file *file; + + if (!filp) + return -EINVAL; + + if (filp->f_op != &amdgpu_driver_kms_fops) { + return -EINVAL; + } + + file = filp->private_data; + *fpriv = file->driver_priv; + return 0; +} + static bool amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe, bool in_vblank_irq, int *vpos, int *hpos, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c index 1cafe8d83a4d..0b70410488b6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c @@ -54,16 +54,20 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, enum drm_sched_priority priority) { struct file *filp = fget(fd); - struct drm_file *file; struct amdgpu_fpriv *fpriv; struct amdgpu_ctx *ctx; uint32_t id; + int r; if (!filp) return -EINVAL; - file = filp->private_data; - fpriv = file->driver_priv; + r = amdgpu_file_to_fpriv(filp, &fpriv); + if (r) { + fput(filp); + return r; + } + idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id) amdgpu_ctx_priority_override(ctx, priority); From patchwork Wed Jan 30 01:53:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bas Nieuwenhuizen X-Patchwork-Id: 10787555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 616C66C2 for ; Wed, 30 Jan 2019 01:54:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 538962C5FD for ; Wed, 30 Jan 2019 01:54:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 482922D2C5; Wed, 30 Jan 2019 01:54:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9C882C5FD for ; Wed, 30 Jan 2019 01:54:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A6C06EAAA; Wed, 30 Jan 2019 01:54:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 05C206E432 for ; Wed, 30 Jan 2019 01:54:41 +0000 (UTC) Received: by mail-ed1-x544.google.com with SMTP id h50so17701096ede.5 for ; Tue, 29 Jan 2019 17:54:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VSArUE3K8LyhCs5G8IHNSpm9CCcNZPIPpKm9WXkM6r8=; b=XkUj0eDuUys4DQqAsxZIcyGKnXPN9EBPwKexnXYxbpoEm3RjSivpFSadIow7258C5j 5+ZEZ5AUksElefVXeXlVhZb/13zULYhSx272zN6a4/wNoGPfEmTgtCDtI3ioKGChldeI G7bgEfZVgM/SXQJW3n1MWGQ+F1UOOSCpSWb7HSOsP8CyLnnzRn+EiRTQPeQD98Y61Ptt YXnrHrnar1HCMtz4/a5dtp6CA3p18fkMmtTWxoWS7d/RYirn6Mc04m7VgS5NJ+PMCAru LxJ1kHiEg91OiE/ljb1zUz0CLEI58f46SJxS/Ihb1N4dUiXrykoQ2cF3/y7Ofq9BksX+ N/Ag== X-Gm-Message-State: AJcUukcv0oYLalzO3ri4T6caynlNvn0tHENzyqGOsWAjlOR7sPDFviPQ GzWp641EWW4mB0mpSnoTNR/iJg== X-Google-Smtp-Source: ALg8bN7Z8dYRtit2sL2LUWVz+ZpUfFqoxbjoUZvZXoWaPW8Jrx2O8e8yLhj0aaRhsoeWXlTNWeOwfw== X-Received: by 2002:a17:906:1c0c:: with SMTP id k12mr9288504ejg.39.1548813279586; Tue, 29 Jan 2019 17:54:39 -0800 (PST) Received: from localhost.localdomain ([2a02:aa12:a77f:2000:7285:c2ff:fe4e:b21b]) by smtp.gmail.com with ESMTPSA id l18sm117157edq.87.2019.01.29.17.54.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 17:54:38 -0800 (PST) From: Bas Nieuwenhuizen To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/4] drm/amdgpu: Add command to override the context priority. Date: Wed, 30 Jan 2019 02:53:22 +0100 Message-Id: <20190130015322.105870-4-bas@basnieuwenhuizen.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> References: <20190130015322.105870-1-bas@basnieuwenhuizen.nl> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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-Virus-Scanned: ClamAV using ClamSMTP Given a master fd we can then override the priority of the context in another fd. Using these overrides was recommended by Christian instead of trying to submit from a master fd, and I am adding a way to override a single context instead of the entire process so we can only upgrade a single Vulkan queue and not effectively the entire process. Reused the flags field as it was checked to be 0 anyways, so nothing used it. This is source-incompatible (due to the name change), but ABI compatible. Signed-off-by: Bas Nieuwenhuizen --- drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 41 ++++++++++++++++++++++- include/uapi/drm/amdgpu_drm.h | 3 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c index 0b70410488b6..0767a93e4d91 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c @@ -76,6 +76,39 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, return 0; } +static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev, + int fd, + unsigned ctx_id, + enum drm_sched_priority priority) +{ + struct file *filp = fget(fd); + struct amdgpu_fpriv *fpriv; + struct amdgpu_ctx *ctx; + int r; + + if (!filp) + return -EINVAL; + + r = amdgpu_file_to_fpriv(filp, &fpriv); + if (r) { + fput(filp); + return r; + } + + ctx = amdgpu_ctx_get(fpriv, ctx_id); + + if (!ctx) { + fput(filp); + return -EINVAL; + } + + amdgpu_ctx_priority_override(ctx, priority); + amdgpu_ctx_put(ctx); + fput(filp); + + return 0; +} + int amdgpu_sched_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) { @@ -85,7 +118,7 @@ int amdgpu_sched_ioctl(struct drm_device *dev, void *data, int r; priority = amdgpu_to_sched_priority(args->in.priority); - if (args->in.flags || priority == DRM_SCHED_PRIORITY_INVALID) + if (priority == DRM_SCHED_PRIORITY_INVALID) return -EINVAL; switch (args->in.op) { @@ -94,6 +127,12 @@ int amdgpu_sched_ioctl(struct drm_device *dev, void *data, args->in.fd, priority); break; + case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE: + r = amdgpu_sched_context_priority_override(adev, + args->in.fd, + args->in.ctx_id, + priority); + break; default: DRM_ERROR("Invalid sched op specified: %d\n", args->in.op); r = -EINVAL; diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index faaad04814e4..30fa340790b2 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -275,13 +275,14 @@ union drm_amdgpu_vm { /* sched ioctl */ #define AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE 1 +#define AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE 2 struct drm_amdgpu_sched_in { /* AMDGPU_SCHED_OP_* */ __u32 op; __u32 fd; __s32 priority; - __u32 flags; + __u32 ctx_id; }; union drm_amdgpu_sched {