From patchwork Wed Mar 29 00:55:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 669031 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 BF5D7C6FD18 for ; Wed, 29 Mar 2023 00:55:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbjC2Azg (ORCPT ); Tue, 28 Mar 2023 20:55:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjC2Azf (ORCPT ); Tue, 28 Mar 2023 20:55:35 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A9501BFD for ; Tue, 28 Mar 2023 17:55:34 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id 20so14472174lju.0 for ; Tue, 28 Mar 2023 17:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680051332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B3QWtwCpJWCtNwbopMCBhlb/eX5Lt6OWuzbQyL+529U=; b=vi6NQbtWRKOHnONykj6hYunJ45FGrQc/U+pXgje1r8U/v24mBupjNskP85Nbn9Hir2 B9ZhhHMSTZCuV2X3UzNQJKQMLShuKLAVcCvW6Ro3oUgjqYjEn2i2vjMVjII6BXPG1RtV ZBmH+YdZ1jTJ3cU0pMOkwEFjB3ReUiKvEWGB2RTCPPynKIZcf+vyYIFBsjK5zQMp+xpt b8Zd5QAd1LTib2xpuCkcg+daSSqhkVBgMMvzlhshBMmcNSYZ0TDQap7uHvZitiWANwT5 zMQFvvJb/c+zjaMZis0L4yOxbf3fI8nFFhNM09p9xMF3isY0xPqGgvTaJHS7LfPUkqdG /4Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680051332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B3QWtwCpJWCtNwbopMCBhlb/eX5Lt6OWuzbQyL+529U=; b=x6CniNRLSYJWbimyLS8l8dmtMnqDjYhbZtyys2BU0EePOHp5UP+9ItLkpNmY0J7H3q +mAofGnHV9ayr5YlliKYIIz9ccwhACUKda90kJTnNJMPGTDclp8k7124CtBQ5q84PUvi CPEvySK7TrawJjrTM9EsWmaGij3lKAsBv0a0P6ufrKObrr0H1C18gpQnM1dsan1E0VGa 9romoHXHEJD8JTFS/J8oo67j6Obulmo7ghL1SOfF0T5RDO8ZNr5ZvZhi8Gy+bk131Pxg ZibJx4fBi/Kfe8nP/FLeQe1KimqXI7uxw3IuzTWAwsthLVeeMS6gNX7Dd6OupGh4kcOp hKxA== X-Gm-Message-State: AAQBX9exoIo18On6JAYBT1KAKi+aFss1YQY8noyV4y0rYVCIs83jCyV9 /eDlN0qf7qIQcMCmduCbDnkgnA== X-Google-Smtp-Source: AKy350boACpnTgN9FtbnZSYhmXfWiLUrmwJjIKp0oD59NFvzwtfWOEcN8QobmftFmb5nwehjacLh6w== X-Received: by 2002:a2e:9193:0:b0:293:34f1:73f9 with SMTP id f19-20020a2e9193000000b0029334f173f9mr5683044ljg.13.1680051332456; Tue, 28 Mar 2023 17:55:32 -0700 (PDT) Received: from eriador.lan (dzccz6yyyyyyyyyyybcwt-3.rev.dnainternet.fi. [2001:14ba:a085:4d00::8a5]) by smtp.gmail.com with ESMTPSA id a4-20020a2e9804000000b002a03f9ffecesm3007181ljj.89.2023.03.28.17.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 17:55:32 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Abhinav Kumar Cc: Stephen Boyd , David Airlie , Daniel Vetter , Bjorn Andersson , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [PATCH v3 1/2] drm/msm: drop unused ring variable in msm_ioctl_gem_submit() Date: Wed, 29 Mar 2023 03:55:29 +0300 Message-Id: <20230329005530.1077468-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329005530.1077468-1-dmitry.baryshkov@linaro.org> References: <20230329005530.1077468-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The variable ring is not used by msm_parse_deps() and msm_ioctl_gem_submit() and thus can be dropped. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_gem_submit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index 514ff5245c8a..f2a6775a10eb 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -550,8 +550,7 @@ static struct drm_syncobj **msm_parse_deps(struct msm_gem_submit *submit, struct drm_file *file, uint64_t in_syncobjs_addr, uint32_t nr_in_syncobjs, - size_t syncobj_stride, - struct msm_ringbuffer *ring) + size_t syncobj_stride) { struct drm_syncobj **syncobjs = NULL; struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; @@ -798,7 +797,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, syncobjs_to_reset = msm_parse_deps(submit, file, args->in_syncobjs, args->nr_in_syncobjs, - args->syncobj_stride, ring); + args->syncobj_stride); if (IS_ERR(syncobjs_to_reset)) { ret = PTR_ERR(syncobjs_to_reset); goto out_unlock; From patchwork Wed Mar 29 00:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 669030 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 C06E4C77B6C for ; Wed, 29 Mar 2023 00:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229560AbjC2Azh (ORCPT ); Tue, 28 Mar 2023 20:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjC2Azg (ORCPT ); Tue, 28 Mar 2023 20:55:36 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6B801FDD for ; Tue, 28 Mar 2023 17:55:34 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id e11so14416737lji.8 for ; Tue, 28 Mar 2023 17:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680051333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=in8ArGj/MjOCuYtjGXU364Xb4blRHvT/jqnaOCwqO0Y=; b=M3MM+Qg9Cv6BOSAfgZZEwYmFcqjhE78OPapA6APrZ3dGZlpIuytFFk7c0DK9FbzOuC JW6MLG0xp83HLM8vxs4W4/zzIKZp5pnh26+thN3UBQ0OcHXwl2iOIdO2yHl96uYrT1Da F+nCtRS5lsXkqk8bg2TT4N50oQKMo0+sIScMIjK/CMlxlXBnPOB2vRM4aTWPgy/daKAB PgNuPHBhJMIj8aAtNOWYmnZXtNP+RLsb8OatAR7cxJd+PppuFSA4CB9d88ddgvcvpb1w /pCJ+dI8y4of/NsvqsyMBJiky1XS7pwoKDStCWfCZPmBr3X/4RAEBgbZiogHEeqibMUr oH8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680051333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=in8ArGj/MjOCuYtjGXU364Xb4blRHvT/jqnaOCwqO0Y=; b=g8X5nE+yJ4oXlGy68CuHPgFV+tDOdtwAe/rjVb0m0CQmUqyXJ/dXUjXfVQh934zPz9 iJSlv86mGtxG0FyaE0iHKMf6koE0QVQGgr/DroSA1nfYApjM8U/vu9TtZdvAC0EtM4KO A2DKCPCBguIMdoNxEI3SE1kYwHQJqhM1uZx+ivehCZU6upyS1N03/k+dtvdxL/C36ECD ko99mTv1P/Qwtc0N3yly8YJJLqjEx2tv+Qkx6YrMvHcH+kIAyYKgyrt+RquPm5qk4knu VSjg8rUl/KrgHknIKDExAF8eb+3E6UJ1l52lvHleAIGnY8NUYXTnyultEj6Er+sUo73q zs5A== X-Gm-Message-State: AAQBX9e95V4YeUYRwELGra3hRk6g982xCnEmrnSulYHIvPaXX9CvrbL4 J1RAjHkWFT72+DmS2xJ7HqIOdw== X-Google-Smtp-Source: AKy350aiEMfV+RnPTVp/XKBb4bfbyqxyg6KXZ4MH7N+jaTze/pu1y9TBWSJUGk0tvMNSvQTDuY/0kw== X-Received: by 2002:a2e:944a:0:b0:295:b95f:1b28 with SMTP id o10-20020a2e944a000000b00295b95f1b28mr6061024ljh.14.1680051333168; Tue, 28 Mar 2023 17:55:33 -0700 (PDT) Received: from eriador.lan (dzccz6yyyyyyyyyyybcwt-3.rev.dnainternet.fi. [2001:14ba:a085:4d00::8a5]) by smtp.gmail.com with ESMTPSA id a4-20020a2e9804000000b002a03f9ffecesm3007181ljj.89.2023.03.28.17.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 17:55:32 -0700 (PDT) From: Dmitry Baryshkov To: Rob Clark , Sean Paul , Abhinav Kumar Cc: Stephen Boyd , David Airlie , Daniel Vetter , Bjorn Andersson , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org Subject: [PATCH v3 2/2] drm/msm: simplify msm_parse_deps() and msm_parse_post_deps() Date: Wed, 29 Mar 2023 03:55:30 +0300 Message-Id: <20230329005530.1077468-3-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329005530.1077468-1-dmitry.baryshkov@linaro.org> References: <20230329005530.1077468-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Simplify two functions msm_parse_deps() and msm_parse_post_deps(): extract single item parsing function and clean up error path. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_gem_submit.c | 186 +++++++++++++++------------ 1 file changed, 101 insertions(+), 85 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c index f2a6775a10eb..da5fcd65f8b6 100644 --- a/drivers/gpu/drm/msm/msm_gem_submit.c +++ b/drivers/gpu/drm/msm/msm_gem_submit.c @@ -546,6 +546,41 @@ struct msm_submit_post_dep { struct dma_fence_chain *chain; }; +static struct drm_syncobj *msm_parse_dep_one(struct msm_gem_submit *submit, + struct drm_file *file, + uint64_t address, + size_t syncobj_stride) +{ + struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; + struct drm_syncobj *syncobj = NULL; + int ret; + + if (copy_from_user(&syncobj_desc, + u64_to_user_ptr(address), + min(syncobj_stride, sizeof(syncobj_desc)))) + return ERR_PTR(-EFAULT); + + if (syncobj_desc.point && + !drm_core_check_feature(submit->dev, DRIVER_SYNCOBJ_TIMELINE)) + return ERR_PTR(-EOPNOTSUPP); + + if (syncobj_desc.flags & ~MSM_SUBMIT_SYNCOBJ_FLAGS) + return ERR_PTR(-EINVAL); + + ret = drm_sched_job_add_syncobj_dependency(&submit->base, file, + syncobj_desc.handle, syncobj_desc.point); + if (ret) + return ERR_PTR(ret); + + if (syncobj_desc.flags & MSM_SUBMIT_SYNCOBJ_RESET) { + syncobj = drm_syncobj_find(file, syncobj_desc.handle); + if (!syncobj) + return ERR_PTR(-EINVAL); + } + + return syncobj; +} + static struct drm_syncobj **msm_parse_deps(struct msm_gem_submit *submit, struct drm_file *file, uint64_t in_syncobjs_addr, @@ -553,9 +588,8 @@ static struct drm_syncobj **msm_parse_deps(struct msm_gem_submit *submit, size_t syncobj_stride) { struct drm_syncobj **syncobjs = NULL; - struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; - int ret = 0; - uint32_t i, j; + int ret; + int i; syncobjs = kcalloc(nr_in_syncobjs, sizeof(*syncobjs), GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); @@ -564,49 +598,26 @@ static struct drm_syncobj **msm_parse_deps(struct msm_gem_submit *submit, for (i = 0; i < nr_in_syncobjs; ++i) { uint64_t address = in_syncobjs_addr + i * syncobj_stride; + struct drm_syncobj *syncobj; - if (copy_from_user(&syncobj_desc, - u64_to_user_ptr(address), - min(syncobj_stride, sizeof(syncobj_desc)))) { - ret = -EFAULT; - break; - } - - if (syncobj_desc.point && - !drm_core_check_feature(submit->dev, DRIVER_SYNCOBJ_TIMELINE)) { - ret = -EOPNOTSUPP; - break; - } - - if (syncobj_desc.flags & ~MSM_SUBMIT_SYNCOBJ_FLAGS) { - ret = -EINVAL; - break; + syncobj = msm_parse_dep_one(submit, file, address, syncobj_stride); + if (IS_ERR(syncobj)) { + ret = PTR_ERR(syncobj); + goto err; } - ret = drm_sched_job_add_syncobj_dependency(&submit->base, file, - syncobj_desc.handle, syncobj_desc.point); - if (ret) - break; - - if (syncobj_desc.flags & MSM_SUBMIT_SYNCOBJ_RESET) { - syncobjs[i] = - drm_syncobj_find(file, syncobj_desc.handle); - if (!syncobjs[i]) { - ret = -EINVAL; - break; - } - } + syncobjs[i] = syncobj; } - if (ret) { - for (j = 0; j <= i; ++j) { - if (syncobjs[j]) - drm_syncobj_put(syncobjs[j]); - } - kfree(syncobjs); - return ERR_PTR(ret); - } return syncobjs; + +err: + while (--i >= 0) + if (syncobjs[i]) + drm_syncobj_put(syncobjs[i]); + kfree(syncobjs); + + return ERR_PTR(ret); } static void msm_reset_syncobjs(struct drm_syncobj **syncobjs, @@ -620,6 +631,43 @@ static void msm_reset_syncobjs(struct drm_syncobj **syncobjs, } } +static int msm_parse_post_dep_one(struct drm_device *dev, + struct drm_file *file, + uint64_t address, + size_t syncobj_stride, + struct msm_submit_post_dep *post_dep) +{ + struct msm_submit_post_dep *post_deps; + struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; + + if (copy_from_user(&syncobj_desc, + u64_to_user_ptr(address), + min(syncobj_stride, sizeof(syncobj_desc)))) + return -EFAULT; + + post_dep->point = syncobj_desc.point; + + if (syncobj_desc.flags) + return -EINVAL; + + if (syncobj_desc.point) { + if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE)) + return -EOPNOTSUPP; + + post_dep->chain = dma_fence_chain_alloc(); + if (!post_dep->chain) + return -ENOMEM; + } + + post_dep->syncobj = drm_syncobj_find(file, syncobj_desc.handle); + if (!post_dep->syncobj) { + dma_fence_chain_free(post_deps->chain); + return -EINVAL; + } + + return 0; +} + static struct msm_submit_post_dep *msm_parse_post_deps(struct drm_device *dev, struct drm_file *file, uint64_t syncobjs_addr, @@ -627,9 +675,8 @@ static struct msm_submit_post_dep *msm_parse_post_deps(struct drm_device *dev, size_t syncobj_stride) { struct msm_submit_post_dep *post_deps; - struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; int ret = 0; - uint32_t i, j; + int i; post_deps = kcalloc(nr_syncobjs, sizeof(*post_deps), GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); @@ -639,54 +686,23 @@ static struct msm_submit_post_dep *msm_parse_post_deps(struct drm_device *dev, for (i = 0; i < nr_syncobjs; ++i) { uint64_t address = syncobjs_addr + i * syncobj_stride; - if (copy_from_user(&syncobj_desc, - u64_to_user_ptr(address), - min(syncobj_stride, sizeof(syncobj_desc)))) { - ret = -EFAULT; - break; - } - - post_deps[i].point = syncobj_desc.point; - - if (syncobj_desc.flags) { - ret = -EINVAL; - break; - } - - if (syncobj_desc.point) { - if (!drm_core_check_feature(dev, - DRIVER_SYNCOBJ_TIMELINE)) { - ret = -EOPNOTSUPP; - break; - } - - post_deps[i].chain = dma_fence_chain_alloc(); - if (!post_deps[i].chain) { - ret = -ENOMEM; - break; - } - } - - post_deps[i].syncobj = - drm_syncobj_find(file, syncobj_desc.handle); - if (!post_deps[i].syncobj) { - ret = -EINVAL; - break; - } + ret = msm_parse_post_dep_one(dev, file, address, syncobj_stride, &post_deps[i]); + if (ret) + goto err; } - if (ret) { - for (j = 0; j <= i; ++j) { - dma_fence_chain_free(post_deps[j].chain); - if (post_deps[j].syncobj) - drm_syncobj_put(post_deps[j].syncobj); - } + return post_deps; - kfree(post_deps); - return ERR_PTR(ret); +err: + while (--i >= 0) { + dma_fence_chain_free(post_deps[i].chain); + if (post_deps[i].syncobj) + drm_syncobj_put(post_deps[i].syncobj); } - return post_deps; + kfree(post_deps); + + return ERR_PTR(ret); } static void msm_process_post_deps(struct msm_submit_post_dep *post_deps,