Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1418510pxb; Wed, 6 Apr 2022 18:23:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpKx5V4vzmQOKKVXxd+JkR4FYeFILZ+Xxp22vnTwOwPgPCMUrDOBioaxFFRC5hMrdjo6OZ X-Received: by 2002:a17:907:c02:b0:6df:fb64:2770 with SMTP id ga2-20020a1709070c0200b006dffb642770mr11262061ejc.221.1649294604635; Wed, 06 Apr 2022 18:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649294604; cv=none; d=google.com; s=arc-20160816; b=kyzUQ7L0sOuxsNpJNyxInECz3ryxVPKiNoqyhLfOtyBE2g/+F2nnHapK/o5Km6KNeR 57UtdOhJpzVHkp86t/+tkEPt91AShP5KvkKuRmKRriYI83ntm95lp3CvNcIbNKDhYJn+ OpsX5zAd/t93QobqwX1bbl1x/U6gi+k/G2oT8KvzECoQPVu66DLjKjeF/tSDpbELBxbq w2VsW0srxDAmC4KtyRVcd5qkfrOo5/XMikZs8fuucAyCSN5FMMh5UnVCx2B7cW3mfbq6 PglYdfkz43fv9mPXiMBwOIdXdbUtH0F+O5luHWQFBjlcQUpA357hN7bfw8QBo2yUd/b5 npfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FOiXrhcG6D/pgTVrD2sfYvvtxc1rOGgLTAX3yAXgAyg=; b=lUlxziW9Mi2wsg+CmKKrG9qWe32sttMJHl23+jr9ntGzG8SgQZDX9OfIMo0l4VwRij OYsw4AsNdK6xKU0DdiB+dodV5qx8y+KAh1E9ULXQ9RLLo0vNtbGJGb0Se/QIBpKyUCE/ bf6y/Bwikoyk22onblv1v9VhCwn9qLjc1dQSgN+p4ADKabJh3GgtyIU7z1jVrTgoa/jW 8SRNfyElwcTguGO/dwavPV0rNTc4HRU0yHY+c94pesysW9rRwU5yCzkLjDDJ7bJV8CUu yuHKs1x4ny9iP2wb2v7I/Vlt2QGwveGArbfbYCgJd3h21a/yPCptpu1+BfAsNLuzxtQi YaQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="dzhEs0/G"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a056402275200b00418d6d7b866si17390032edd.161.2022.04.06.18.22.37; Wed, 06 Apr 2022 18:23:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="dzhEs0/G"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236719AbiDFVyN (ORCPT + 99 others); Wed, 6 Apr 2022 17:54:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236813AbiDFVwg (ORCPT ); Wed, 6 Apr 2022 17:52:36 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1469514003; Wed, 6 Apr 2022 14:46:46 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id j20-20020a17090ae61400b001ca9553d073so4147189pjy.5; Wed, 06 Apr 2022 14:46: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=FOiXrhcG6D/pgTVrD2sfYvvtxc1rOGgLTAX3yAXgAyg=; b=dzhEs0/Gl46vON03WgC0ZE+tJJnHFz9sOIIZfvGENgGRO0GqIcBBN/dfm+oCnvlIqR /00inBjjRrLQfPz5MEC4skO8ScF9B8JXM+sEwOYaXVqESCz2o/RO9bpF2tTEV7ePSEbT gsXQRrUIAk4BMh81ovZsbldkulHgB2VNgM4aD8ILvwQRAufJPnBFfgNvoh3hVsRoLYsj qLlsIvF9F4wcKGLWto//Jns+P36RmkP0o0k/ysx+HYlP1fVJO00xWV4dVimWPlOvsb1u Z4+W9WNyeu37d/LyoBAr4FoC42YRvGgAqgHxEuHnMyAXmCH+Kff0nGmXzRx0ksyKX9sV 9S1Q== 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=FOiXrhcG6D/pgTVrD2sfYvvtxc1rOGgLTAX3yAXgAyg=; b=vo0Ux4ZURbxYrXXb7+E1ilnWImd2GTyccNBZdwqtjsQb+ocscBdO/7LmTHRsJhJ6tJ ESIGlZVCy27CN288NEgTSVWrXpHI1/LVax5guqqSM/eYTjh6aTzevZ0Fj1KZqVxHq+x5 DgLBrflINGJrFmJRD3XJR85vQu9MRuw5hgKBEiLywyJ2L0YSPl1uxt5xSQDmtnsBOZrU +IV7+pCkDpkwaR6zAZK+EIlJAeIbJIC4orJo359bntTbmkgQFjdu8j3oSMeP8SR8hKmf /LEsNJ3ROkK36PvncRL5nkRaQTqspIy7VoUcwVrT5KbEwbEF72be3AlwOu4suTXlKNNG XE4g== X-Gm-Message-State: AOAM530/gHdPzCpHzUNwYFbSJnvKK7j/H8NRtvUtbKEW+V7o7gzXzUZM QQIHF0KfCubTptpQuC0v5Nw= X-Received: by 2002:a17:902:b183:b0:153:59db:f860 with SMTP id s3-20020a170902b18300b0015359dbf860mr10552529plr.19.1649281605624; Wed, 06 Apr 2022 14:46:45 -0700 (PDT) Received: from localhost ([2a00:79e1:abd:4a00:2703:3c72:eb1a:cffd]) by smtp.gmail.com with ESMTPSA id w4-20020a056a0014c400b004fb0c7b3813sm20854671pfu.134.2022.04.06.14.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 14:46:44 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Dmitry Baryshkov , Dmitry Osipenko , Rob Clark , Rob Clark , Sean Paul , Abhinav Kumar , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 07/10] drm/msm/gem: Rework vma lookup and pin Date: Wed, 6 Apr 2022 14:46:23 -0700 Message-Id: <20220406214636.1156978-8-robdclark@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220406214636.1156978-1-robdclark@gmail.com> References: <20220406214636.1156978-1-robdclark@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rob Clark Combines duplicate vma lookup in the get_and_pin path. Signed-off-by: Rob Clark Reviewed-by: Dmitry Osipenko --- drivers/gpu/drm/msm/msm_gem.c | 50 ++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index deafae6feaa8..218744a490a4 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -376,39 +376,40 @@ put_iova_vmas(struct drm_gem_object *obj) } } -static int get_iova_locked(struct drm_gem_object *obj, - struct msm_gem_address_space *aspace, uint64_t *iova, +static struct msm_gem_vma *get_vma_locked(struct drm_gem_object *obj, + struct msm_gem_address_space *aspace, u64 range_start, u64 range_end) { struct msm_gem_vma *vma; - int ret = 0; GEM_WARN_ON(!msm_gem_is_locked(obj)); vma = lookup_vma(obj, aspace); if (!vma) { + int ret; + vma = add_vma(obj, aspace); if (IS_ERR(vma)) - return PTR_ERR(vma); + return vma; ret = msm_gem_init_vma(aspace, vma, obj->size, range_start, range_end); if (ret) { del_vma(vma); - return ret; + return ERR_PTR(ret); } + } else { + GEM_WARN_ON(vma->iova < range_start); + GEM_WARN_ON((vma->iova + obj->size) > range_end); } - *iova = vma->iova; - return 0; + return vma; } -static int msm_gem_pin_iova(struct drm_gem_object *obj, - struct msm_gem_address_space *aspace) +static int msm_gem_pin_iova(struct drm_gem_object *obj, struct msm_gem_vma *vma) { struct msm_gem_object *msm_obj = to_msm_bo(obj); - struct msm_gem_vma *vma; struct page **pages; int ret, prot = IOMMU_READ; @@ -426,15 +427,11 @@ static int msm_gem_pin_iova(struct drm_gem_object *obj, if (GEM_WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED)) return -EBUSY; - vma = lookup_vma(obj, aspace); - if (GEM_WARN_ON(!vma)) - return -EINVAL; - pages = get_pages(obj); if (IS_ERR(pages)) return PTR_ERR(pages); - ret = msm_gem_map_vma(aspace, vma, prot, msm_obj->sgt, obj->size); + ret = msm_gem_map_vma(vma->aspace, vma, prot, msm_obj->sgt, obj->size); if (!ret) msm_obj->pin_count++; @@ -446,19 +443,18 @@ static int get_and_pin_iova_range_locked(struct drm_gem_object *obj, struct msm_gem_address_space *aspace, uint64_t *iova, u64 range_start, u64 range_end) { - u64 local; + struct msm_gem_vma *vma; int ret; GEM_WARN_ON(!msm_gem_is_locked(obj)); - ret = get_iova_locked(obj, aspace, &local, - range_start, range_end); - - if (!ret) - ret = msm_gem_pin_iova(obj, aspace); + vma = get_vma_locked(obj, aspace, range_start, range_end); + if (IS_ERR(vma)) + return PTR_ERR(vma); + ret = msm_gem_pin_iova(obj, vma); if (!ret) - *iova = local; + *iova = vma->iova; return ret; } @@ -500,10 +496,16 @@ int msm_gem_get_and_pin_iova(struct drm_gem_object *obj, int msm_gem_get_iova(struct drm_gem_object *obj, struct msm_gem_address_space *aspace, uint64_t *iova) { - int ret; + struct msm_gem_vma *vma; + int ret = 0; msm_gem_lock(obj); - ret = get_iova_locked(obj, aspace, iova, 0, U64_MAX); + vma = get_vma_locked(obj, aspace, 0, U64_MAX); + if (IS_ERR(vma)) { + ret = PTR_ERR(vma); + } else { + *iova = vma->iova; + } msm_gem_unlock(obj); return ret; -- 2.35.1