From patchwork Tue Jul 26 17:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC615C00140 for ; Tue, 26 Jul 2022 17:50:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239656AbiGZRuU (ORCPT ); Tue, 26 Jul 2022 13:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239650AbiGZRuT (ORCPT ); Tue, 26 Jul 2022 13:50:19 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 348F01837C; Tue, 26 Jul 2022 10:50:18 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id v18so852687plo.8; Tue, 26 Jul 2022 10:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0sMFYlUXA/wvNrdz6yghIiBT/tIS2Mu/kejgpgcpcUk=; b=qKzbaVbj2FqDQNpoZXlQDXFmYvzhQt9kBkAgNM5HpdZcgiFRDhU0/4Qj7uc9AbTFzm LpCGdtiKh31TqhbhfY8oNi1QybojWeRNFmGtMP6QIMwLXqzlpFsCe1BrG5qPfoncZKJm FnWc7dWSDJpS4S1ulnwyyhO5mhakPmTr7k5oPC+ERKTlerG6uZ2yZzSsjxH4+YgytEAW zbF1LxjqA4Bu9u+OxhYGOpedTE4qXRHrzjgNt082tSsWNcCq1RE6R5qrLespsop+ifF+ CN40MpZ4Cvh3bPohGU4kswtdTihEhHPKJENdXb1bhcyqMOadR3ND5J19VZCAFdJwTeq5 pCRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0sMFYlUXA/wvNrdz6yghIiBT/tIS2Mu/kejgpgcpcUk=; b=M1/HH/ft2gBghLHPd2mp64vgRPbiu2E3kY9V8kaV13Ww6TvWISYwJLnw2sPalZR9Sm sS6ZkwyS/gnee7X9G0+S94WY1IEpK3yBt5EHjeHOUdoWCYGGnDqLiDTMijl+FZAXXMjB GETEjdLgIk+lqdyuUhip1lvJKeVUS7Rj9/i1evGS3B9p4/ePCWGzbPVtEAHneGmC2wAH 7svmCud073VTBBDkWG9NIzIeR/RujdQUzX6H2huwgpeVVTmFkZ8TevK3p9TpyfeulRhs rdZaAVoF86N7ORmDbyKK67jrBCDjKIKGcWBAb7IcOvR9PHVsvOvdmOqktbOnHoG88FGH 1aPg== X-Gm-Message-State: AJIora8LV5gqFyVwBkRT7ZGrAvFW49U5t5pOyUWWzIoaTMRP9+FucGV9 5pKBnRyVqlQv5avpNwFBTzg= X-Google-Smtp-Source: AGRyM1sZDbuBr9wwnSiGFXCobcSa90BEIVqoUlk917vKZ8OD+txMCJFw3yYMZvIZ7BBOke9bm4mE4A== X-Received: by 2002:a17:90b:3a8d:b0:1f2:bda7:da0d with SMTP id om13-20020a17090b3a8d00b001f2bda7da0dmr347806pjb.102.1658857817633; Tue, 26 Jul 2022 10:50:17 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id lp6-20020a17090b4a8600b001f2173d897asm371289pjb.43.2022.07.26.10.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:16 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 01/15] drm/msm: Reorder lock vs submit alloc Date: Tue, 26 Jul 2022 10:50:25 -0700 Message-Id: <20220726175043.1027731-2-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark This lets us drop the NORETRY. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem_submit.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index c9e4aeb14f4a..b7c61a99d274 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -36,7 +36,7 @@ static struct msm_gem_submit *submit_create(struct drm_device *dev, if (sz > SIZE_MAX) return ERR_PTR(-ENOMEM); - submit = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); + submit = kzalloc(sz, GFP_KERNEL); if (!submit) return ERR_PTR(-ENOMEM); @@ -771,25 +771,21 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, trace_msm_gpu_submit(pid_nr(pid), ring->id, submitid, args->nr_bos, args->nr_cmds); - ret = mutex_lock_interruptible(&queue->lock); - if (ret) - goto out_post_unlock; - if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) { out_fence_fd = get_unused_fd_flags(O_CLOEXEC); if (out_fence_fd < 0) { ret = out_fence_fd; - goto out_unlock; + return ret; } } - submit = submit_create(dev, gpu, queue, args->nr_bos, - args->nr_cmds); - if (IS_ERR(submit)) { - ret = PTR_ERR(submit); - submit = NULL; - goto out_unlock; - } + submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds); + if (IS_ERR(submit)) + return PTR_ERR(submit); + + ret = mutex_lock_interruptible(&queue->lock); + if (ret) + goto out_post_unlock; submit->pid = pid; submit->ident = submitid; @@ -965,9 +961,9 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, if (ret && (out_fence_fd >= 0)) put_unused_fd(out_fence_fd); mutex_unlock(&queue->lock); +out_post_unlock: if (submit) msm_gem_submit_put(submit); -out_post_unlock: if (!IS_ERR_OR_NULL(post_deps)) { for (i = 0; i < args->nr_out_syncobjs; ++i) { kfree(post_deps[i].chain); From patchwork Tue Jul 26 17:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9D5BC00144 for ; Tue, 26 Jul 2022 17:50:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239695AbiGZRug (ORCPT ); Tue, 26 Jul 2022 13:50:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239680AbiGZRuZ (ORCPT ); Tue, 26 Jul 2022 13:50:25 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15C042B61F; Tue, 26 Jul 2022 10:50:24 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 6so13726811pgb.13; Tue, 26 Jul 2022 10:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AwYCVdrGkHnM2D+4h4BxfmYuAccPj8wFXhKV37+GyLo=; b=d07ps/PxhGLVTQay3ZOMj+wOILdTIPfoaYbqxIjtMx0KUtWZQl1malmooufQqO0e49 ERbm62n+OGlKUrXWuE5FbiXGq198R9jlAdrxLPEdh7uX6M+SKPjr1hkIl6ptbM8kVio+ U7NfKTU6WjUonHvM5by8NfWmb7jx+y+Cbe/LDju3PmtbSXv31k7VWji+KQB3JEAlBCIc 44+pUVLvjT7NDW5ctkprIaBP28MpTimydDrs1SMV99kZsKtjqfRYLDztREVN9ZKBY9+r m6dYEnGJnEiwDDrreE2BBHvfamp+lDuL6JYnbqm2ovuE+ddhxTzFzdHgI4ukEMkL/7HP zdkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AwYCVdrGkHnM2D+4h4BxfmYuAccPj8wFXhKV37+GyLo=; b=mVGQeyACXSW+CcVuU2zEvCLoua2+FUlhWuymhhrAZg0sQQXoW+8w24p02jaB6ae2Sm rGLJl3YORSuiLNAux2N+LvxJ6cRd2UaQoN6jNBKS4QrsgTDRd6FZPBqsHcsL9YdojvVV RK2gEX2b58Qna/wditNlgLjUVjQ23ajGET4Qpoz+iQHAGtBkLdBOnhT+/DuZuUHiHTz9 kLjdZ6EWYbf4V919jdD1CwxfscNtot0QJy93Kick8YuA7UESjQodcMOskozv8D1bGsmS BwPaDSr3yIhsBmGL7NIzMGxcjFZydx2Nn+hUY0QCvRvokxYOJu95WTzyTJttKRYZMVSc eDyQ== X-Gm-Message-State: AJIora/PYxb7yaIENtUwhfcdLgt++iKWGX7kxO9w0asLAt5ePOQRGMj9 Zj/v6rz2eCkbhmB0yHQEtnOA3XBNb6Q= X-Google-Smtp-Source: AGRyM1vKma7jG+VAhlmr2RGqxxeVlHvtkFjPUXWcN4AIdM90MN87noNjNu1A+3O5qideJRIuVAuTsQ== X-Received: by 2002:a63:6b0a:0:b0:40d:ffa6:85c5 with SMTP id g10-20020a636b0a000000b0040dffa685c5mr15585780pgc.327.1658857823442; Tue, 26 Jul 2022 10:50:23 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id n3-20020a170902f60300b0016bdea07b9esm11775714plg.190.2022.07.26.10.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:22 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 03/15] drm/msm: Split out idr_lock Date: Tue, 26 Jul 2022 10:50:27 -0700 Message-Id: <20220726175043.1027731-4-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Otherwise if we hit reclaim pinning objects in the submit path, we'll be blocking retire_worker trying to free a submit. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_drv.c | 4 ++-- drivers/gpu/drm/msm/msm_gem_submit.c | 10 ++++++++-- drivers/gpu/drm/msm/msm_gpu.h | 4 +++- drivers/gpu/drm/msm/msm_submitqueue.c | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 1ed4cd09dbf8..d7ca025457b6 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -883,13 +883,13 @@ static int wait_fence(struct msm_gpu_submitqueue *queue, uint32_t fence_id, * retired, so if the fence is not found it means there is nothing * to wait for */ - ret = mutex_lock_interruptible(&queue->lock); + ret = mutex_lock_interruptible(&queue->idr_lock); if (ret) return ret; fence = idr_find(&queue->fence_idr, fence_id); if (fence) fence = dma_fence_get_rcu(fence); - mutex_unlock(&queue->lock); + mutex_unlock(&queue->idr_lock); if (!fence) return 0; diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index c7819781879c..16c662808522 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -72,9 +72,9 @@ void __msm_gem_submit_destroy(struct kref *kref) unsigned i; if (submit->fence_id) { - mutex_lock(&submit->queue->lock); + mutex_lock(&submit->queue->idr_lock); idr_remove(&submit->queue->fence_idr, submit->fence_id); - mutex_unlock(&submit->queue->lock); + mutex_unlock(&submit->queue->idr_lock); } dma_fence_put(submit->user_fence); @@ -881,6 +881,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, submit->nr_cmds = i; + mutex_lock(&queue->idr_lock); + /* * If using userspace provided seqno fence, validate that the id * is available before arming sched job. Since access to fence_idr @@ -889,6 +891,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, */ if ((args->flags & MSM_SUBMIT_FENCE_SN_IN) && idr_find(&queue->fence_idr, args->fence)) { + mutex_unlock(&queue->idr_lock); ret = -EINVAL; goto out; } @@ -921,6 +924,9 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, submit->user_fence, 1, INT_MAX, GFP_KERNEL); } + + mutex_unlock(&queue->idr_lock); + if (submit->fence_id < 0) { ret = submit->fence_id; submit->fence_id = 0; diff --git a/drivers/gpu/drm/msm/msm_gpu.h b/drivers/gpu/drm/msm/msm_gpu.h index 4d935fedd2ac..962d2070bcdf 100644 --- a/drivers/gpu/drm/msm/msm_gpu.h +++ b/drivers/gpu/drm/msm/msm_gpu.h @@ -466,7 +466,8 @@ static inline int msm_gpu_convert_priority(struct msm_gpu *gpu, int prio, * @node: node in the context's list of submitqueues * @fence_idr: maps fence-id to dma_fence for userspace visible fence * seqno, protected by submitqueue lock - * @lock: submitqueue lock + * @idr_lock: for serializing access to fence_idr + * @lock: submitqueue lock for serializing submits on a queue * @ref: reference count * @entity: the submit job-queue */ @@ -479,6 +480,7 @@ struct msm_gpu_submitqueue { struct msm_file_private *ctx; struct list_head node; struct idr fence_idr; + struct mutex idr_lock; struct mutex lock; struct kref ref; struct drm_sched_entity *entity; diff --git a/drivers/gpu/drm/msm/msm_submitqueue.c b/drivers/gpu/drm/msm/msm_submitqueue.c index f486a3cd4e55..c6929e205b51 100644 --- a/drivers/gpu/drm/msm/msm_submitqueue.c +++ b/drivers/gpu/drm/msm/msm_submitqueue.c @@ -200,6 +200,7 @@ int msm_submitqueue_create(struct drm_device *drm, struct msm_file_private *ctx, *id = queue->id; idr_init(&queue->fence_idr); + mutex_init(&queue->idr_lock); mutex_init(&queue->lock); list_add_tail(&queue->node, &ctx->submitqueues); From patchwork Tue Jul 26 17:50:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D712C00140 for ; Tue, 26 Jul 2022 17:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239759AbiGZRus (ORCPT ); Tue, 26 Jul 2022 13:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239722AbiGZRui (ORCPT ); Tue, 26 Jul 2022 13:50:38 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4562830545; Tue, 26 Jul 2022 10:50:30 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id c19-20020a17090ae11300b001f2f94ed5c6so1331577pjz.1; Tue, 26 Jul 2022 10:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mxFT+vmlgH8OMaHZf0MGM1sQcdQOD7qQazzf52IZIdo=; b=bgpjAJ5bBS4yugrwA8j1ZIBaDUjFu0nuPpsoqqylDTGzh/AiLFF3nvq0m75CMjU3kG anosJSMiZWd6K3C3JoUEVH7w3VQRuZ9+G/FzSdU2kuj5ooffiflfSeSWzILo3Wibcfut Nj/x4x7CVsFbkD0UviZTxWrAhp4+2JYVE/RKUBa1cXXXNbSoNWcWvLLr1vhtT0eaT96V X011xdhwcop32fBWDQH4NOzdjuBtJTLDihz4W6Aft1OOKBBYQtJx92JWyG2nmSpR542V GUGTpdLJfUreMLgG/sDXRsSz6HJx+21R5SqR7KkQckSbFVbZWQODVuYJ+BvQAu3fuoAx WHTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mxFT+vmlgH8OMaHZf0MGM1sQcdQOD7qQazzf52IZIdo=; b=4GDKHgwBVJ8kiKqQa9TEBCYo0tI0MxQfxXN9pGCFT8XQUij5EWaHNS5jphehIVZ4sC 1kK7SmcCDHEX+a42eTSWHChdlCI5wl8mAS21p6WsziRO0Bs8xyPc1t1qOPQkvaohsku9 9mojGDnpsv9f8hFnvIDaZ9Yz/SYhHeekkgPowNjoBD6feGIcn2i9zAVlnTo1M8dRea8X UxaSVexLnMT0MBTNhIVdbI0g3wFEyocQqwOwxUbCxb5NR91mglz2MjXqgz7wn4bCCawj sIgquexDiyV3uqtaYjNhzpXS0Cs1BA+bvxgrgPgWU4bUrw2MWyFg+6Hu2i/Fuz0AeN+h BGAQ== X-Gm-Message-State: AJIora/tneYlCnAro+3gFmns4AnhyLOGxWibD4Nx00Bi59FqA9RKWYVP CT1W+laNqiQRIBTGtrLjEFw= X-Google-Smtp-Source: AGRyM1tV+bWtmoiT21D47kprb3MRO/XsTGS8Bp7nBZWAPLvP49tQtJQP2nRjjtaDwhyIpPZsba+LcQ== X-Received: by 2002:a17:902:a616:b0:16c:d74e:4654 with SMTP id u22-20020a170902a61600b0016cd74e4654mr17881448plq.4.1658857829138; Tue, 26 Jul 2022 10:50:29 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id 125-20020a621883000000b005289a50e4c2sm11933021pfy.23.2022.07.26.10.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:27 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 05/15] drm/msm/gem: Rename update_inactive Date: Tue, 26 Jul 2022 10:50:29 -0700 Message-Id: <20220726175043.1027731-6-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Really what this is doing is updating various LRU lists. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index b55d252aef17..97467364dc0a 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -19,7 +19,7 @@ #include "msm_gpu.h" #include "msm_mmu.h" -static void update_inactive(struct msm_gem_object *msm_obj); +static void update_lru(struct drm_gem_object *obj); static dma_addr_t physaddr(struct drm_gem_object *obj) { @@ -132,7 +132,7 @@ static struct page **get_pages(struct drm_gem_object *obj) if (msm_obj->flags & MSM_BO_WC) sync_for_device(msm_obj); - update_inactive(msm_obj); + update_lru(obj); } return msm_obj->pages; @@ -193,7 +193,7 @@ struct page **msm_gem_get_pages(struct drm_gem_object *obj) if (!IS_ERR(p)) { msm_obj->pin_count++; - update_inactive(msm_obj); + update_lru(obj); } msm_gem_unlock(obj); @@ -207,7 +207,7 @@ void msm_gem_put_pages(struct drm_gem_object *obj) msm_gem_lock(obj); msm_obj->pin_count--; GEM_WARN_ON(msm_obj->pin_count < 0); - update_inactive(msm_obj); + update_lru(obj); msm_gem_unlock(obj); } @@ -449,7 +449,7 @@ void msm_gem_unpin_locked(struct drm_gem_object *obj) msm_obj->pin_count--; GEM_WARN_ON(msm_obj->pin_count < 0); - update_inactive(msm_obj); + update_lru(obj); } struct msm_gem_vma *msm_gem_get_vma_locked(struct drm_gem_object *obj, @@ -658,7 +658,7 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv) goto fail; } - update_inactive(msm_obj); + update_lru(obj); } return msm_obj->vaddr; @@ -730,7 +730,7 @@ int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv) * between inactive lists */ if (msm_obj->active_count == 0) - update_inactive(msm_obj); + update_lru(obj); msm_gem_unlock(obj); @@ -757,7 +757,7 @@ void msm_gem_purge(struct drm_gem_object *obj) put_iova_vmas(obj); msm_obj->madv = __MSM_MADV_PURGED; - update_inactive(msm_obj); + update_lru(obj); drm_gem_free_mmap_offset(obj); @@ -792,7 +792,7 @@ void msm_gem_evict(struct drm_gem_object *obj) put_pages(obj); - update_inactive(msm_obj); + update_lru(obj); } void msm_gem_vunmap(struct drm_gem_object *obj) @@ -835,13 +835,14 @@ void msm_gem_active_put(struct drm_gem_object *obj) GEM_WARN_ON(!msm_gem_is_locked(obj)); if (--msm_obj->active_count == 0) { - update_inactive(msm_obj); + update_lru(obj); } } -static void update_inactive(struct msm_gem_object *msm_obj) +static void update_lru(struct drm_gem_object *obj) { - struct msm_drm_private *priv = msm_obj->base.dev->dev_private; + struct msm_drm_private *priv = obj->dev->dev_private; + struct msm_gem_object *msm_obj = to_msm_bo(obj); GEM_WARN_ON(!msm_gem_is_locked(&msm_obj->base)); From patchwork Tue Jul 26 17:50:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6360C00140 for ; Tue, 26 Jul 2022 17:50:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239678AbiGZRu5 (ORCPT ); Tue, 26 Jul 2022 13:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239719AbiGZRuq (ORCPT ); Tue, 26 Jul 2022 13:50:46 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3050B3134E; Tue, 26 Jul 2022 10:50:35 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id o12so13846794pfp.5; Tue, 26 Jul 2022 10:50:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UVam+OtTXmVRJOOFcNCglGVq9lRc/LFnzlVeuJ/h90Y=; b=oFM3qcef0UrtwoUQpFLwuAqGgPddV/OrqybzZuPT93TR2DT36gdpEczUOyjwvntM1w 9GHBp0hS4jsevM/OOdFK1ksSanwvcayuLU3p1y37o1c5CqkEoIM87qXwiKQl8mc98yE5 I/9f9rUx6tUu4B2JrwbAO9tg+7ZwXmLRssZEvhWkOGS5EEmas/iGJLnx8ZaW/DpZoGRs 2sn0Yb+J/I0tm9IUF79FwOC+0+kT1UEkLrp668+L+Py9mxDqfRNx+EcNLydL1c1Z8KP7 m4jSOf3FsiRsVh+cKAsxEukBSeSoyY8lFuF9Ho6YqbzRIT6XQy6zs8NOgoPIFzuFA7ET fkoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UVam+OtTXmVRJOOFcNCglGVq9lRc/LFnzlVeuJ/h90Y=; b=d4f1AbAZCFcSG7eXVGwnoZaiiL/w74J0OuYhU2yincqg9xRgh/GyifbpZdVhsIijOV Tgv4Qe34TX6s+Tg8ysb3hvRuxP9ISEowdi+yCqJcjU8G951PCxt+51ZyFVmKcCmkeDSG ixQT+U0exd3xL2fs/AxKysyjpSimQZChOb35T/vqXsdmYB4b9FiivPwG0AgDbuPFh8WT 1rVLOtq7fAe3m5GTLdfFbZ0XcwA10HtYtJw/ZJtKlVV8zJYqz7TB+wQFIM3kCqW8BvcH 4DE46X1lDAvhnzyilAkb6rDO5zGFFFELfUnP/XEikX8jh744+UUXW/SdOoxb4s1NyPqO Q+9A== X-Gm-Message-State: AJIora9o1OxtUSzo/7liLraQTjC39LZU5TIImaS+Q5wYCnizGaZzPqqH i6Nh4vFP7NHcHDKBV/vFsS8= X-Google-Smtp-Source: AGRyM1thoGmetx5EzT1Yghxen/ubJ8Ysu0MSl3NADJmMTKowzZ5lzxTdb1KgOzIFyqMqC/S5LQqzAA== X-Received: by 2002:a63:6a89:0:b0:419:d863:321a with SMTP id f131-20020a636a89000000b00419d863321amr15870269pgc.9.1658857835302; Tue, 26 Jul 2022 10:50:35 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id n7-20020a056a00212700b0052ab0a73752sm11989037pfj.198.2022.07.26.10.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:34 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 07/15] drm/msm/gem: Consolidate pin/unpin paths Date: Tue, 26 Jul 2022 10:50:31 -0700 Message-Id: <20220726175043.1027731-8-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Avoid having multiple spots where we increment/decrement pin_count (and associated LRU updating) Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 3da64c7f65a2..407b18a24dc4 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -190,7 +190,7 @@ static struct page **msm_gem_pin_pages_locked(struct drm_gem_object *obj) p = get_pages(obj); if (!IS_ERR(p)) { - msm_obj->pin_count++; + to_msm_bo(obj)->pin_count++; update_lru(obj); } @@ -213,9 +213,7 @@ void msm_gem_unpin_pages(struct drm_gem_object *obj) struct msm_gem_object *msm_obj = to_msm_bo(obj); msm_gem_lock(obj); - msm_obj->pin_count--; - GEM_WARN_ON(msm_obj->pin_count < 0); - update_lru(obj); + msm_gem_unpin_locked(obj); msm_gem_unlock(obj); } @@ -436,14 +434,13 @@ int msm_gem_pin_vma_locked(struct drm_gem_object *obj, struct msm_gem_vma *vma) if (GEM_WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED)) return -EBUSY; - pages = get_pages(obj); + pages = msm_gem_pin_pages_locked(obj); if (IS_ERR(pages)) return PTR_ERR(pages); ret = msm_gem_map_vma(vma->aspace, vma, prot, msm_obj->sgt, obj->size); - - if (!ret) - msm_obj->pin_count++; + if (ret) + msm_gem_unpin_locked(obj); return ret; } From patchwork Tue Jul 26 17:50:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77149C3F6B0 for ; Tue, 26 Jul 2022 17:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239774AbiGZRvU (ORCPT ); Tue, 26 Jul 2022 13:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239770AbiGZRut (ORCPT ); Tue, 26 Jul 2022 13:50:49 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 514CD30547; Tue, 26 Jul 2022 10:50:41 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id w205so10539078pfc.8; Tue, 26 Jul 2022 10:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U846p3xo+1d02tXgmQbx7VHsQitXar7JD/0ho5uYEv8=; b=CJcojqB4YzxNFXWwWIMbEHrBT2UEFC8IbOP8IlYypKP7MOfBqRCYBFe0RH0C8aa1vs m1zqovck2uuUCSQF5PdrFzZI+qj/l611PsaaY/aptNavTMXI4OZj7Xp27DNzx1Rtbbcd qZwGimKlZf8DBgWObgjzoR/F/8jlupYHraM+RD5IBVh8x+7UEHiB7wv4uP2P7YUv0VAY Bg49fasGI8sXtoJMApp2jfhDockmKm2lxhAbVSpYB8gj8gdE6PEEaU2KDSHyv0POm+f2 653o7eKaJEv7oK2LkOE7/mbsAluvWw9lGdjy4MUTwRd3T/Zn4rg4FnEKxghBk+3xKn3C PzQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U846p3xo+1d02tXgmQbx7VHsQitXar7JD/0ho5uYEv8=; b=y6fU/8aGfbqqauwudywR+7frNzdbdJYanyqBcxK01ZavzdltXdxi2keZCUOE0itRu7 qvZPSr2NbYi0F5J0bZwt71sgJZl7pkcmhtUP2pF5BMcA4R/rM8fc2CsFPKPyKg6h1bQC wEeO0kuejt55MFZcgi/cxyOm29ZF2Y8ALAK++3UiJnI36mn8BQQUWxu0mRW6fIfNGiej zTXw5Ew9hypBH60tBDFlmPUGnoflsfNmvUnNg7a0QUxG2KOIA0Ruia2sdB1QYLbOg3RO Wfz9i+QZjIkGWDJz/cV3BjXMegOTbSRrbEw/GoUcrrS7VfismStrNI9fVaDSW8WaviuM B9gQ== X-Gm-Message-State: AJIora+vawAa6pStMKOFNr9s9euf5SV0R55GjgffSjpP2Iz7pNyx9LVC urt8FBql3ZBtI3F6qILcYP0= X-Google-Smtp-Source: AGRyM1sVPimc6a3NKpX1iuF0RKDyWE6zPQ5GBdK5fgId0QCqGwNiYOt30+GzPdxsaMCyuLtNrKcLBw== X-Received: by 2002:aa7:82ca:0:b0:51b:cf43:d00a with SMTP id f10-20020aa782ca000000b0051bcf43d00amr18339481pfn.58.1658857840672; Tue, 26 Jul 2022 10:50:40 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id b14-20020a631b4e000000b004088f213f68sm719018pgm.56.2022.07.26.10.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:39 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Daniel Vetter , Thomas Zimmermann , Dmitry Osipenko , Maarten Lankhorst , Maxime Ripard , David Airlie , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 09/15] drm/gem: Add LRU/shrinker helper Date: Tue, 26 Jul 2022 10:50:33 -0700 Message-Id: <20220726175043.1027731-10-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Add a simple LRU helper to assist with driver's shrinker implementation. It handles tracking the number of backing pages associated with a given LRU, and provides a helper to implement shrinker_scan. A driver can use multiple LRU instances to track objects in various states, for example a dontneed LRU for purgeable objects, a willneed LRU for evictable objects, and an unpinned LRU for objects without backing pages. All LRUs that the object can be moved between must share a single lock. v2: lockdep_assert_held() instead of WARN_ON(!mutex_is_locked()) Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Dmitry Osipenko Signed-off-by: Rob Clark Reviewed-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem.c | 183 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_gem.h | 56 ++++++++++++ 2 files changed, 239 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index eb0c2d041f13..f0526aaf013a 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -165,6 +165,7 @@ void drm_gem_private_object_init(struct drm_device *dev, obj->resv = &obj->_resv; drm_vma_node_reset(&obj->vma_node); + INIT_LIST_HEAD(&obj->lru_node); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -951,6 +952,7 @@ drm_gem_object_release(struct drm_gem_object *obj) dma_resv_fini(&obj->_resv); drm_gem_free_mmap_offset(obj); + drm_gem_lru_remove(obj); } EXPORT_SYMBOL(drm_gem_object_release); @@ -1274,3 +1276,184 @@ drm_gem_unlock_reservations(struct drm_gem_object **objs, int count, ww_acquire_fini(acquire_ctx); } EXPORT_SYMBOL(drm_gem_unlock_reservations); + +/** + * drm_gem_lru_init - initialize a LRU + * + * @lru: The LRU to initialize + * @lock: The lock protecting the LRU + */ +void +drm_gem_lru_init(struct drm_gem_lru *lru, struct mutex *lock) +{ + lru->lock = lock; + lru->count = 0; + INIT_LIST_HEAD(&lru->list); +} +EXPORT_SYMBOL(drm_gem_lru_init); + +static void +lru_remove(struct drm_gem_object *obj) +{ + obj->lru->count -= obj->size >> PAGE_SHIFT; + WARN_ON(obj->lru->count < 0); + list_del(&obj->lru_node); + obj->lru = NULL; +} + +/** + * drm_gem_lru_remove - remove object from whatever LRU it is in + * + * If the object is currently in any LRU, remove it. + * + * @obj: The GEM object to remove from current LRU + */ +void +drm_gem_lru_remove(struct drm_gem_object *obj) +{ + struct drm_gem_lru *lru = obj->lru; + + if (!lru) + return; + + mutex_lock(lru->lock); + lru_remove(obj); + mutex_unlock(lru->lock); +} +EXPORT_SYMBOL(drm_gem_lru_remove); + +/** + * drm_gem_lru_move_tail - move the object to the tail of the LRU + * + * If the object is already in this LRU it will be moved to the + * tail. Otherwise it will be removed from whichever other LRU + * it is in (if any) and moved into this LRU. + * + * @lru: The LRU to move the object into. + * @obj: The GEM object to move into this LRU + */ +void +drm_gem_lru_move_tail(struct drm_gem_lru *lru, struct drm_gem_object *obj) +{ + mutex_lock(lru->lock); + drm_gem_lru_move_tail_locked(lru, obj); + mutex_unlock(lru->lock); +} +EXPORT_SYMBOL(drm_gem_lru_move_tail); + +/** + * drm_gem_lru_move_tail_locked - move the object to the tail of the LRU + * + * If the object is already in this LRU it will be moved to the + * tail. Otherwise it will be removed from whichever other LRU + * it is in (if any) and moved into this LRU. + * + * Call with LRU lock held. + * + * @lru: The LRU to move the object into. + * @obj: The GEM object to move into this LRU + */ +void +drm_gem_lru_move_tail_locked(struct drm_gem_lru *lru, struct drm_gem_object *obj) +{ + lockdep_assert_held_once(lru->lock); + + if (obj->lru) + lru_remove(obj); + + lru->count += obj->size >> PAGE_SHIFT; + list_add_tail(&obj->lru_node, &lru->list); + obj->lru = lru; +} +EXPORT_SYMBOL(drm_gem_lru_move_tail_locked); + +/** + * drm_gem_lru_scan - helper to implement shrinker.scan_objects + * + * If the shrink callback succeeds, it is expected that the driver + * move the object out of this LRU. + * + * If the LRU possibly contain active buffers, it is the responsibility + * of the shrink callback to check for this (ie. dma_resv_test_signaled()) + * or if necessary block until the buffer becomes idle. + * + * @lru: The LRU to scan + * @nr_to_scan: The number of pages to try to reclaim + * @shrink: Callback to try to shrink/reclaim the object. + */ +unsigned long +drm_gem_lru_scan(struct drm_gem_lru *lru, unsigned nr_to_scan, + bool (*shrink)(struct drm_gem_object *obj)) +{ + struct drm_gem_lru still_in_lru; + struct drm_gem_object *obj; + unsigned freed = 0; + + drm_gem_lru_init(&still_in_lru, lru->lock); + + mutex_lock(lru->lock); + + while (freed < nr_to_scan) { + obj = list_first_entry_or_null(&lru->list, typeof(*obj), lru_node); + + if (!obj) + break; + + drm_gem_lru_move_tail_locked(&still_in_lru, obj); + + /* + * If it's in the process of being freed, gem_object->free() + * may be blocked on lock waiting to remove it. So just + * skip it. + */ + if (!kref_get_unless_zero(&obj->refcount)) + continue; + + /* + * Now that we own a reference, we can drop the lock for the + * rest of the loop body, to reduce contention with other + * code paths that need the LRU lock + */ + mutex_unlock(lru->lock); + + /* + * Note that this still needs to be trylock, since we can + * hit shrinker in response to trying to get backing pages + * for this obj (ie. while it's lock is already held) + */ + if (!dma_resv_trylock(obj->resv)) + goto tail; + + if (shrink(obj)) { + freed += obj->size >> PAGE_SHIFT; + + /* + * If we succeeded in releasing the object's backing + * pages, we expect the driver to have moved the object + * out of this LRU + */ + WARN_ON(obj->lru == &still_in_lru); + WARN_ON(obj->lru == lru); + } + + dma_resv_unlock(obj->resv); + +tail: + drm_gem_object_put(obj); + mutex_lock(lru->lock); + } + + /* + * Move objects we've skipped over out of the temporary still_in_lru + * back into this LRU + */ + list_for_each_entry (obj, &still_in_lru.list, lru_node) + obj->lru = lru; + list_splice_tail(&still_in_lru.list, &lru->list); + lru->count += still_in_lru.count; + + mutex_unlock(lru->lock); + + return freed; +} +EXPORT_SYMBOL(drm_gem_lru_scan); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 87cffc9efa85..f13a9080af37 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -174,6 +174,41 @@ struct drm_gem_object_funcs { const struct vm_operations_struct *vm_ops; }; +/** + * struct drm_gem_lru - A simple LRU helper + * + * A helper for tracking GEM objects in a given state, to aid in + * driver's shrinker implementation. Tracks the count of pages + * for lockless &shrinker.count_objects, and provides + * &drm_gem_lru_scan for driver's &shrinker.scan_objects + * implementation. + */ +struct drm_gem_lru { + /** + * @lock: + * + * Lock protecting movement of GEM objects between LRUs. All + * LRUs that the object can move between should be protected + * by the same lock. + */ + struct mutex *lock; + + /** + * @count: + * + * The total number of backing pages of the GEM objects in + * this LRU. + */ + long count; + + /** + * @list: + * + * The LRU list. + */ + struct list_head list; +}; + /** * struct drm_gem_object - GEM buffer object * @@ -312,6 +347,20 @@ struct drm_gem_object { * */ const struct drm_gem_object_funcs *funcs; + + /** + * @lru_node: + * + * List node in a &drm_gem_lru. + */ + struct list_head lru_node; + + /** + * @lru: + * + * The current LRU list that the GEM object is on. + */ + struct drm_gem_lru *lru; }; /** @@ -420,4 +469,11 @@ void drm_gem_unlock_reservations(struct drm_gem_object **objs, int count, int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev, u32 handle, u64 *offset); +void drm_gem_lru_init(struct drm_gem_lru *lru, struct mutex *lock); +void drm_gem_lru_remove(struct drm_gem_object *obj); +void drm_gem_lru_move_tail(struct drm_gem_lru *lru, struct drm_gem_object *obj); +void drm_gem_lru_move_tail_locked(struct drm_gem_lru *lru, struct drm_gem_object *obj); +unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru, unsigned nr_to_scan, + bool (*shrink)(struct drm_gem_object *obj)); + #endif /* __DRM_GEM_H__ */ From patchwork Tue Jul 26 17:50:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593496 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95075C04A68 for ; Tue, 26 Jul 2022 17:51:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239717AbiGZRvj (ORCPT ); Tue, 26 Jul 2022 13:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239713AbiGZRuw (ORCPT ); Tue, 26 Jul 2022 13:50:52 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E63A831359; Tue, 26 Jul 2022 10:50:46 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id x24-20020a17090ab01800b001f21556cf48so17956245pjq.4; Tue, 26 Jul 2022 10:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FzvQD1BdX2RVx+fHXlbnajcgEgfcaBeelT02bqIAfkE=; b=C3rcsNLGUDjPRxfROWRdoZEqoPkKn1/Htx7zNkExFevmAr6cVYFPDwZk4cJHQuOjHg 7zp1XEPvH9pdrPAIHxwIRBSeD9v/q5BEq8SzErK351H9HEU9UjEYJB3U7dLDRJUOeo/C fzsPnfbr7GciGNhhETTtlx5iIyPnhqwJepjcHeqov4vLVlLC//PFuwmy5n4ZBfFdQwEU 9rqlJsrjcQNNRVjXyyh962ue2QdUjvI7uk/DpyP28VihilgKjyn49nDzVN43FIEUdCrW AeI+KADu9MKjjJHjevG34Z4qEh1wv1KPXw7Iox6VhZtIFn90D0TTjfQreasf/G7ISIij GpOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FzvQD1BdX2RVx+fHXlbnajcgEgfcaBeelT02bqIAfkE=; b=SyrNCgcVwVDdUh1IvtluALE97SUTrfqnUcZ2aG+eT1AvKzTgp8/lb9pXcIHYbgi7K1 SVEwDj3Hnt0VcU/1EuJ2ub02qFwT7wEEEEwCQ23wJjtrqOU7MusRIwcCFaFr1uLq9Exr OIfpfTeAUKQ7I3UaQMxDtCWEcZ6+MZisJJA7lEtM2Jurwz1vdhMs0/D09Vw4Po6oVf22 RCsc0RJviePW4+8L98Zdt4dUwTJXLo4UK0oQO1aVr3TNWomRyJtsHiShLMPN0qZ2v3ds 92D1ufIXpSIF/7CGTaNL7Tvvy1Dqv+yP+Is8ajkDP3/G3kuJldpvVB7WZR1CBZhKt23k u3/w== X-Gm-Message-State: AJIora8+KL/DmKyxU7Cdbjlk7iBunmXE01JIHyuY0SoBG+xhxBM/yUG2 ja3QlhyXGI7zH4WwhYNV12l5Uff41Uc= X-Google-Smtp-Source: AGRyM1sv575TC+lxA2u2e7voRIevFC2jb9zeRMsA6HFThlboaFzIal5t6kaH6LzWzhGEUpQTPqbR/w== X-Received: by 2002:a17:90b:343:b0:1ef:b65d:f4d8 with SMTP id fh3-20020a17090b034300b001efb65df4d8mr306192pjb.187.1658857846082; Tue, 26 Jul 2022 10:50:46 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id 13-20020a170902c10d00b0016bfe9ab1f3sm11868299pli.36.2022.07.26.10.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:45 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 11/15] drm/msm/gem: Unpin buffers earlier Date: Tue, 26 Jul 2022 10:50:35 -0700 Message-Id: <20220726175043.1027731-12-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark We've already attached the fences, so obj->resv (which shrinker checks) tells us whether they are still active. So we can unpin sooner, before we drop the queue lock. This also avoids the need to grab the obj lock in the retire path, avoiding potential for lock contention between submit and retire. Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem_submit.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index adf358fb8e9d..5599d93ec0d2 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -501,11 +501,11 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob */ static void submit_cleanup(struct msm_gem_submit *submit, bool error) { - unsigned cleanup_flags = BO_LOCKED; + unsigned cleanup_flags = BO_LOCKED | BO_OBJ_PINNED; unsigned i; if (error) - cleanup_flags |= BO_VMA_PINNED | BO_OBJ_PINNED; + cleanup_flags |= BO_VMA_PINNED; for (i = 0; i < submit->nr_bos; i++) { struct msm_gem_object *msm_obj = submit->bos[i].obj; @@ -522,10 +522,6 @@ void msm_submit_retire(struct msm_gem_submit *submit) for (i = 0; i < submit->nr_bos; i++) { struct drm_gem_object *obj = &submit->bos[i].obj->base; - msm_gem_lock(obj); - /* Note, VMA already fence-unpinned before submit: */ - submit_cleanup_bo(submit, i, BO_OBJ_PINNED); - msm_gem_unlock(obj); drm_gem_object_put(obj); } } From patchwork Tue Jul 26 17:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593495 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 666A5C00140 for ; Tue, 26 Jul 2022 17:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239868AbiGZRvv (ORCPT ); Tue, 26 Jul 2022 13:51:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239632AbiGZRvB (ORCPT ); Tue, 26 Jul 2022 13:51:01 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC20326DA; Tue, 26 Jul 2022 10:50:51 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id x24-20020a17090ab01800b001f21556cf48so17956404pjq.4; Tue, 26 Jul 2022 10:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kFWCPQ026Vm0ssc92OEIjelADHl+en2PNRs5WLmvYxM=; b=lCObkp9FE/21z/4v9sqKAMNyMrxnHTOC23HtKuVK1mUngMduut8t8o/S3WKSeIOy9q eOlJRPs8F7E+i6nsg9nRMcJTCai8vcnwrzcZBxYF/Z3qn/VtJanzwNbpjEzObQtluAnG cvaxFJ9Z/ZAvgcFSEbc76zlxwESJ1sarQZque5u7Ok3yxgXLm0uQ+ovtlDiDG7vEeda7 twvXxFztsy9B5W5ogZPesgArzSflQVKrbpjZmbeiFhHnGKVEgAEcq9bk9giNnA0JT0Oh 7CfydKTvC7Tj/VlKrmjgWi7V5T846lIR9Odh71D7mv9h1eIkVBz9kA5JUKw0uUVWuiZk xOUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kFWCPQ026Vm0ssc92OEIjelADHl+en2PNRs5WLmvYxM=; b=clf2MP6Fp1pTUXs4FMdXN2slmQAjVdNeXcXj2oHD8Zja5LxfHXVa+Q80DlgejXB+Qy TJpKnl5KHZyKiVdJExooe3h8R5O+w1iQmzt+J+ekKT5FDniFzqgWg9c8/hD3nIsZhwHY ZrB1oamQiKjJD29dK0Hc/t+maqxMzBofmKOuS1drj0frw5miJIudyHgQzXaKFfRqEQFt GJwHYRDblRXjvS3pctE0rT9xp+NBKnzJOT1BCuaapAGhqIVsAk0kXQO/tx52zpq20mhh HiptGq0SUacDFPd2/+TBE4LNk9qxIHuM66F+c4bEKhE9pB/yA31fw4r7iTenG7D1RrUC dihw== X-Gm-Message-State: AJIora9Bs6B7HDXTXuR6qVybN/D7nmcfqVBFxMH4QynL5vKEPSjOasJX LdNernWoVt28UfH8SI+TSVA= X-Google-Smtp-Source: AGRyM1tdh2qvuDkY5DLeIQHdWIquHQp5nCdXcLA0KqZYZtlIaOgeg6179jN5Fe39m4gSJU6SvicfjQ== X-Received: by 2002:a17:902:ea0d:b0:16d:80f9:da54 with SMTP id s13-20020a170902ea0d00b0016d80f9da54mr8481066plg.150.1658857850964; Tue, 26 Jul 2022 10:50:50 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id h13-20020a170902680d00b00168c52319c3sm12015432plk.149.2022.07.26.10.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:50 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 13/15] drm/msm/gem: Evict active GEM objects when necessary Date: Tue, 26 Jul 2022 10:50:37 -0700 Message-Id: <20220726175043.1027731-14-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark If we are under enough memory pressure, we should stall waiting for active buffers to become idle in order to evict. v2: Check for __GFP_ATOMIC before blocking Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem_shrinker.c | 70 +++++++++++++++++++++----- drivers/gpu/drm/msm/msm_gpu_trace.h | 16 +++--- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_shrinker.c b/drivers/gpu/drm/msm/msm_gem_shrinker.c index 5cc05d669a08..f31054d25314 100644 --- a/drivers/gpu/drm/msm/msm_gem_shrinker.c +++ b/drivers/gpu/drm/msm/msm_gem_shrinker.c @@ -24,6 +24,13 @@ static bool can_swap(void) return enable_eviction && get_nr_swap_pages() > 0; } +static bool can_block(struct shrink_control *sc) +{ + if (sc->gfp_mask & __GFP_ATOMIC) + return false; + return current_is_kswapd() || (sc->gfp_mask & __GFP_RECLAIM); +} + static unsigned long msm_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { @@ -65,26 +72,65 @@ evict(struct drm_gem_object *obj) return true; } +static bool +wait_for_idle(struct drm_gem_object *obj) +{ + enum dma_resv_usage usage = dma_resv_usage_rw(true); + return dma_resv_wait_timeout(obj->resv, usage, false, 1000) > 0; +} + +static bool +active_purge(struct drm_gem_object *obj) +{ + if (!wait_for_idle(obj)) + return false; + + return purge(obj); +} + +static bool +active_evict(struct drm_gem_object *obj) +{ + if (!wait_for_idle(obj)) + return false; + + return evict(obj); +} + static unsigned long msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { struct msm_drm_private *priv = container_of(shrinker, struct msm_drm_private, shrinker); + struct { + struct drm_gem_lru *lru; + bool (*shrink)(struct drm_gem_object *obj); + bool cond; + unsigned long freed; + } stages[] = { + /* Stages of progressively more aggressive/expensive reclaim: */ + { &priv->lru.dontneed, purge, true }, + { &priv->lru.willneed, evict, can_swap() }, + { &priv->lru.dontneed, active_purge, can_block(sc) }, + { &priv->lru.willneed, active_evict, can_swap() && can_block(sc) }, + }; long nr = sc->nr_to_scan; - unsigned long freed, purged, evicted = 0; - - purged = drm_gem_lru_scan(&priv->lru.dontneed, nr, purge); - nr -= purged; - - if (can_swap() && nr > 0) { - evicted = drm_gem_lru_scan(&priv->lru.willneed, nr, evict); - nr -= evicted; + unsigned long freed = 0; + + for (unsigned i = 0; (nr > 0) && (i < ARRAY_SIZE(stages)); i++) { + if (!stages[i].cond) + continue; + stages[i].freed = + drm_gem_lru_scan(stages[i].lru, nr, stages[i].shrink); + nr -= stages[i].freed; + freed += stages[i].freed; } - freed = purged + evicted; - - if (freed) - trace_msm_gem_shrink(sc->nr_to_scan, purged, evicted); + if (freed) { + trace_msm_gem_shrink(sc->nr_to_scan, stages[0].freed, + stages[1].freed, stages[2].freed, + stages[3].freed); + } return (freed > 0) ? freed : SHRINK_STOP; } diff --git a/drivers/gpu/drm/msm/msm_gpu_trace.h b/drivers/gpu/drm/msm/msm_gpu_trace.h index 8867fa0a0306..ac40d857bc45 100644 --- a/drivers/gpu/drm/msm/msm_gpu_trace.h +++ b/drivers/gpu/drm/msm/msm_gpu_trace.h @@ -116,22 +116,26 @@ TRACE_EVENT(msm_gmu_freq_change, TRACE_EVENT(msm_gem_shrink, - TP_PROTO(u32 nr_to_scan, u32 purged, u32 evicted), - TP_ARGS(nr_to_scan, purged, evicted), + TP_PROTO(u32 nr_to_scan, u32 purged, u32 evicted, + u32 active_purged, u32 active_evicted), + TP_ARGS(nr_to_scan, purged, evicted, active_purged, active_evicted), TP_STRUCT__entry( __field(u32, nr_to_scan) __field(u32, purged) __field(u32, evicted) + __field(u32, active_purged) + __field(u32, active_evicted) ), TP_fast_assign( __entry->nr_to_scan = nr_to_scan; __entry->purged = purged; __entry->evicted = evicted; + __entry->active_purged = active_purged; + __entry->active_evicted = active_evicted; ), - TP_printk("nr_to_scan=%u pages, purged=%u pages, evicted=%u pages", - __entry->nr_to_scan, - __entry->purged, - __entry->evicted) + TP_printk("nr_to_scan=%u pg, purged=%u pg, evicted=%u pg, active_purged=%u pg, active_evicted=%u pg", + __entry->nr_to_scan, __entry->purged, __entry->evicted, + __entry->active_purged, __entry->active_evicted) ); From patchwork Tue Jul 26 17:50:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 593494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2326CC04A68 for ; Tue, 26 Jul 2022 17:52:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239769AbiGZRwF (ORCPT ); Tue, 26 Jul 2022 13:52:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239767AbiGZRvU (ORCPT ); Tue, 26 Jul 2022 13:51:20 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0786C32D96; Tue, 26 Jul 2022 10:50:57 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id bf13so13735661pgb.11; Tue, 26 Jul 2022 10:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tv9XZJtMf2UZGPK9r5daZO8lAjNs4ugv43Of9czCQIM=; b=n6N05FO3A/857gPBbDiuof2GwBfUn9kG0puB7kE8lFbQKIRgt5AHPZzAAaOh3dGaw+ I0qC2WcECj1kdPZjXnWb2ynEpT0VEDMaY6F4290Haflq9ssHlBMTUon11dWEoP73dzhf QATtcmH9W6axNlapK/asy95XPOrDO5j6fV3PCqKz1+u+uvnOrCaQ36QvvRXKMZYLcL43 fxhdUO4uzY6xfRvqsDmJ3lxyZnCuMuY4gEPFRh+lNZfpo6IBoOhjVOlWDypeT/R1l8cv jpP2SBPbKIuFLlqXbE7uv92AFhfT34u/Sku5aJTW7yANKYxCyAwXSjbjTzttH8HfRATU 7XRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tv9XZJtMf2UZGPK9r5daZO8lAjNs4ugv43Of9czCQIM=; b=ssA/VGIpvllEGPV7qMEIR8IofMX4tp/nv48XeEgrl/BTWfH/gVcfiFbXk8obo98bRp vdEjirfoL6owVY401eo9PvLemHVgZFbcmVmDpSxkzGNd4OOMPc/iI886F0MyR36gHJUV KF31XOQu3dQslqni1uUEeiTOU2PZrz9nfg8tuIOgRmeDB4C/2d8yIViQcxJj5UGy7z+T mnrA6qhvB6ajjR/ctvBl4JSNvAPQh+HpW6G2NQgaAuUrZKL3zWnuOKm2i8SuRCi6mwIS 4teSm5f79nSPjyfDqFIxa9W5EDRvUKtjbo10YnRSAjsqoR13X5Zx1Y8Nr6TpYM9Qxzly n0nw== X-Gm-Message-State: AJIora80onsBO0VghDSFLS0j7V3ylsrsfqYCsfadsa3nNQ1KnAacRrup FxC/iv9uG/P2QNNdOKPnZRE= X-Google-Smtp-Source: AGRyM1t4eqbPaP3I7M4Q4a8CREAJGaFkgWHmK7O/ZXpR+tC19xQ9DUEs+FBui8DB+uQCfvsd4JVx/A== X-Received: by 2002:a05:6a00:1590:b0:52a:eb00:71dc with SMTP id u16-20020a056a00159000b0052aeb0071dcmr18652289pfk.64.1658857856554; Tue, 26 Jul 2022 10:50:56 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id 202-20020a6302d3000000b003db7de758besm10637529pgc.5.2022.07.26.10.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 10:50:55 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Rob Clark , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 15/15] drm/msm/gem: Convert to lockdep assert Date: Tue, 26 Jul 2022 10:50:39 -0700 Message-Id: <20220726175043.1027731-16-robdclark@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220726175043.1027731-1-robdclark@gmail.com> References: <20220726175043.1027731-1-robdclark@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Rob Clark Signed-off-by: Rob Clark --- drivers/gpu/drm/msm/msm_gem.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h index 3c6add51d13b..c4844cf3a585 100644 --- a/drivers/gpu/drm/msm/msm_gem.h +++ b/drivers/gpu/drm/msm/msm_gem.h @@ -197,8 +197,8 @@ msm_gem_unlock(struct drm_gem_object *obj) dma_resv_unlock(obj->resv); } -static inline bool -msm_gem_is_locked(struct drm_gem_object *obj) +static inline void +msm_gem_assert_locked(struct drm_gem_object *obj) { /* * Destroying the object is a special case.. msm_gem_free_object() @@ -212,13 +212,10 @@ msm_gem_is_locked(struct drm_gem_object *obj) * Unfortunately lockdep is not aware of this detail. So when the * refcount drops to zero, we pretend it is already locked. */ - return dma_resv_is_locked(obj->resv) || (kref_read(&obj->refcount) == 0); -} - -static inline void -msm_gem_assert_locked(struct drm_gem_object *obj) -{ - GEM_WARN_ON(!msm_gem_is_locked(obj)); + lockdep_assert_once( + (kref_read(&obj->refcount) == 0) || + (lockdep_is_held(&obj->resv->lock.base) != LOCK_STATE_NOT_HELD) + ); } /* imported/exported objects are not purgeable: */